Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ if(POLYSOLVE_LARGE_INDEX)
target_compile_definitions(polysolve_linear PUBLIC POLYSOLVE_LARGE_INDEX)
endif()

target_compile_definitions(polysolve_linear PRIVATE POLYSOLVE_LINEAR_SPEC="${PROJECT_SOURCE_DIR}/linear-solver-spec.json")
target_compile_definitions(polysolve PRIVATE POLYSOLVE_NON_LINEAR_SPEC="${PROJECT_SOURCE_DIR}/nonlinear-solver-spec.json")
target_compile_definitions(polysolve_linear PUBLIC POLYSOLVE_JSON_SPEC_DIR="${PROJECT_SOURCE_DIR}")


################################################################################
# Dependencies
Expand Down Expand Up @@ -358,10 +354,27 @@ target_link_libraries(polysolve PRIVATE polysolve::warnings)


################################################################################
# Compiler options
# Specs
################################################################################


jse_add_spec(linear_spec
ALIAS polysolve::linear::spec
INPUT "${PROJECT_SOURCE_DIR}/linear-solver-spec.json"
OUTPUT "${PROJECT_SOURCE_DIR}/src/polysolve/linear/solver-spec.hpp"
INCLUDE_DIRS "${PROJECT_SOURCE_DIR}"
)

jse_add_spec(non_linear_spec
ALIAS polysolve::polysolve::spec
INPUT "${PROJECT_SOURCE_DIR}/nonlinear-solver-spec.json"
OUTPUT "${PROJECT_SOURCE_DIR}/src/polysolve/nonlinear/solver-spec.hpp"
INCLUDE_DIRS "${PROJECT_SOURCE_DIR}"
)

target_link_libraries(polysolve_linear PUBLIC polysolve::linear::spec)
target_link_libraries(polysolve PUBLIC polysolve::polysolve::spec)

################################################################################
# Tests
################################################################################
Expand Down
2 changes: 1 addition & 1 deletion cmake/recipes/jse.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ endif()
message(STATUS "Third-party: creating target 'jse::jse'")

include(CPM)
CPMAddPackage("gh:geometryprocessing/json-spec-engine#11d028ebf54c3665e1a7c25d8ac622a8cb851223")
CPMAddPackage("gh:geometryprocessing/json-spec-engine#7c8330309d36746d8eedae763f492351a266c6d5")
27 changes: 12 additions & 15 deletions src/polysolve/linear/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
#include "Solver.hpp"
#include "EigenSolver.hpp"
#include "SaddlePointSolver.hpp"
#include "solver-spec.hpp"

#include <jse/jse.h>
#include <spdlog/spdlog.h>

#include <fstream>

// -----------------------------------------------------------------------------
//
//
// Subsequent macros assume a single template parameter and SparseQR fails due to requiring 2 parameters. this is because the OrderingType is not filled in.
// SparseLU has a default declaration of _OrderingType to use COLAMDOrdering but SparseQR doesn't - so this just mimics that behavior. If Eigen adds such a default in the future this line will need to be guarded to avoid multiple defaults
namespace Eigen {
template <typename _MatrixType, typename _OrderingType = COLAMDOrdering<typename _MatrixType::StorageIndex> > class SparseQR;
namespace Eigen
{
template <typename _MatrixType, typename _OrderingType = COLAMDOrdering<typename _MatrixType::StorageIndex>>
class SparseQR;
}
#include <Eigen/Sparse>
#ifdef POLYSOLVE_WITH_ACCELERATE
Expand All @@ -29,9 +32,11 @@ template <typename _MatrixType, typename _OrderingType = COLAMDOrdering<typename
#endif
#ifdef POLYSOLVE_WITH_SPQR
#include <Eigen/SPQRSupport>
namespace polysolve::linear {
namespace polysolve::linear
{
template <>
void EigenDirect<Eigen::SPQR<StiffnessMatrix>>::analyze_pattern(const StiffnessMatrix& A, const int precond_num) {
void EigenDirect<Eigen::SPQR<StiffnessMatrix>>::analyze_pattern(const StiffnessMatrix &A, const int precond_num)
{
m_Solver.compute(A);
}
template <>
Expand All @@ -43,7 +48,7 @@ namespace polysolve::linear {
throw std::runtime_error("[EigenDirect] NumericalIssue encountered.");
}
}
}
} // namespace polysolve::linear
#endif
#ifdef POLYSOLVE_WITH_SUPERLU
#include <Eigen/SuperLUSupport>
Expand Down Expand Up @@ -137,18 +142,10 @@ namespace polysolve::linear
{
json params = params_in; // mutable copy

json rules;
jse::JSE jse;

jse.strict = strict_validation;
const std::string input_spec = POLYSOLVE_LINEAR_SPEC;
std::ifstream file(input_spec);

if (file.is_open())
file >> rules;
else
log_and_throw_error(logger, "unable to open {} rules", input_spec);

json rules = jse::embed::linear_spec::solver_spec::spec();
apply_default_solver(rules);
select_valid_solver(params, logger);

Expand Down
750 changes: 750 additions & 0 deletions src/polysolve/linear/solver-spec.cpp

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/polysolve/linear/solver-spec.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <nlohmann/json.hpp>

namespace jse
{
namespace embed
{
namespace linear_spec
{
namespace solver_spec
{

const nlohmann::json &spec();

} // namespace solver_spec
} // namespace linear_spec
} // namespace embed
} // namespace jse
10 changes: 2 additions & 8 deletions src/polysolve/nonlinear/BoxConstraintSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "descent_strategies/box_constraints/LBFGSB.hpp"
#include "descent_strategies/box_constraints/MMA.hpp"
#include "solver-spec.hpp"

#include <jse/jse.h>
#include <polysolve/JSONUtils.hpp>
Expand All @@ -21,18 +22,11 @@ namespace polysolve::nonlinear
{
json solver_params = solver_params_in; // mutable copy

json rules;
jse::JSE jse;

jse.strict = strict_validation;
const std::string input_spec = POLYSOLVE_NON_LINEAR_SPEC;
std::ifstream file(input_spec);

if (file.is_open())
file >> rules;
else
log_and_throw_error(logger, "unable to open {} rules", input_spec);

json rules = jse::embed::non_linear_spec::solver_spec::spec();
const bool valid_input = jse.verify_json(solver_params, rules);

if (!valid_input)
Expand Down
14 changes: 4 additions & 10 deletions src/polysolve/nonlinear/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "PostStepData.hpp"

#include "solver-spec.hpp"

#include "descent_strategies/BFGS.hpp"
#include "descent_strategies/Newton.hpp"
#include "descent_strategies/ADAM.hpp"
Expand Down Expand Up @@ -129,18 +131,10 @@ namespace polysolve::nonlinear
{
json solver_params = solver_params_in; // mutable copy

json rules;
jse::JSE jse;

jse.strict = strict_validation;
const std::string input_spec = POLYSOLVE_NON_LINEAR_SPEC;
std::ifstream file(input_spec);

if (file.is_open())
file >> rules;
else
log_and_throw_error(logger, "unable to open {} rules", input_spec);

json rules = jse::embed::non_linear_spec::solver_spec::spec();
const bool valid_input = jse.verify_json(solver_params, rules);

if (!valid_input)
Expand Down Expand Up @@ -401,7 +395,7 @@ namespace polysolve::nonlinear
objFunc.hessian(x, hessian);
m_current.newtonDecrement = 0.5 * x.dot(hessian * x);
}
catch (const std::runtime_error& e)
catch (const std::runtime_error &e)
{
m_logger.error("Error computing Newton decrement: {}", e.what());
m_current.newtonDecrement = NaN;
Expand Down
Loading
Loading