Skip to content

Commit

Permalink
patch_input_json
Browse files Browse the repository at this point in the history
  • Loading branch information
teseoch committed Nov 20, 2023
1 parent df9cdc5 commit 8bf6ad4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/polysolve/linear/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,8 @@ namespace polysolve::linear
{
using polysolve::StiffnessMatrix;

std::unique_ptr<Solver> Solver::create(const json &params_in, spdlog::logger &logger, const bool strict_validation)
void Solver::patch_input_json(json &rules, json &params, spdlog::logger &logger)
{
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);

// set default wrt availability
for (int i = 0; i < rules.size(); i++)
{
Expand Down Expand Up @@ -118,6 +104,25 @@ namespace polysolve::linear
params[lin_solver_ptr] = Solver::default_solver();
}
}
}

std::unique_ptr<Solver> Solver::create(const json &params_in, spdlog::logger &logger, const bool strict_validation)
{
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);

patch_input_json(rules, params, logger);

const bool valid_input = jse.verify_json(params, rules);

Expand Down
11 changes: 11 additions & 0 deletions src/polysolve/linear/Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ namespace polysolve::linear
// Virtual destructor
virtual ~Solver() = default;

// Sets the default paramters to the rules (solver and precond are cmake dependent)
// and selects the correct solver based on params using the fallback or the list of solvers if necessary
static void patch_input_json(json &rules, json &params, spdlog::logger &logger);

// Static constructor
//
// @param[in] params Parameter of the solver, including name and preconditioner
// @param[in] logger Logger used for error
// @param[in] strict_validation strict validation of the input paraams
// @param[out] a pointer to a linear solver
//
static std::unique_ptr<Solver> create(const json &params,
spdlog::logger &logger,
const bool strict_validation = true);
Expand Down

0 comments on commit 8bf6ad4

Please sign in to comment.