45 NLOHMANN_JSON_SERIALIZE_ENUM(
46 spdlog::level::level_enum,
47 {{spdlog::level::level_enum::trace,
"trace"},
48 {spdlog::level::level_enum::debug,
"debug"},
49 {spdlog::level::level_enum::info,
"info"},
50 {spdlog::level::level_enum::warn,
"warning"},
51 {spdlog::level::level_enum::err,
"error"},
52 {spdlog::level::level_enum::critical,
"critical"},
53 {spdlog::level::level_enum::off,
"off"},
54 {spdlog::level::level_enum::trace, 0},
55 {spdlog::level::level_enum::debug, 1},
56 {spdlog::level::level_enum::info, 2},
57 {spdlog::level::level_enum::warn, 3},
58 {spdlog::level::level_enum::err, 3},
59 {spdlog::level::level_enum::critical, 4},
60 {spdlog::level::level_enum::off, 5}})
68 auto names = polysolve::nonlinear::Solver::available_solvers();
69 if (std::find(names.begin(), names.end(), solver_params[
"solver"]) != names.end())
70 return polysolve::nonlinear::Solver::create(solver_params, linear_solver_params, characteristic_length,
adjoint_logger());
72 names = polysolve::nonlinear::BoxConstraintSolver::available_solvers();
73 if (std::find(names.begin(), names.end(), solver_params[
"solver"]) != names.end())
74 return polysolve::nonlinear::BoxConstraintSolver::create(solver_params, linear_solver_params, characteristic_length,
adjoint_logger());
85 for (
const auto &arg : args)
87 const auto &arg_initial = arg[
"initial"];
88 Eigen::VectorXd tmp(variable_sizes[var]);
89 if (arg_initial.is_array() && arg_initial.size() > 0)
92 x.segment(accumulative, tmp.size()) = tmp;
94 else if (arg_initial.is_number())
96 tmp.setConstant(arg_initial.get<
double>());
97 x.segment(accumulative, tmp.size()) = tmp;
100 x += var2sim.
data[var]->inverse_eval();
102 accumulative += tmp.size();
147 json args_in = input_args;
153 jse.strict = strict_validation;
154 std::ifstream file(POLYFEM_OPT_INPUT_SPEC);
160 logger().error(
"unable to open {} rules", POLYFEM_OPT_INPUT_SPEC);
161 throw std::runtime_error(
"Invald spec file");
164 jse.include_directories.push_back(POLYFEM_JSON_SPEC_DIR);
165 jse.include_directories.push_back(POLYSOLVE_JSON_SPEC_DIR);
166 rules = jse.inject_include(rules);
173 const bool valid_input = jse.verify_json(args_in, rules);
177 logger().error(
"invalid input json:\n{}", jse.log2str());
178 throw std::runtime_error(
"Invald input json file");
181 json args = jse.inject_defaults(args_in, rules);
185 const std::string polyfem_objective_spec = POLYFEM_OBJECTIVE_INPUT_SPEC;
186 std::ifstream file(polyfem_objective_spec);
192 logger().error(
"unable to open {} rules", polyfem_objective_spec);
193 throw std::runtime_error(
"Invald spec file");
198 if (args.contains(
"stopping_conditions"))
206 if (args[
"number"].is_number())
208 return args[
"number"].get<
int>();
210 else if (args[
"number"].is_null() && args[
"initial"].size() > 0)
212 return args[
"initial"].size();
214 else if (args[
"number"].is_object())
216 auto selection = args[
"number"];
217 if (selection.contains(
"surface_selection"))
219 auto surface_selection = selection[
"surface_selection"].get<std::vector<int>>();
220 auto state_id = selection[
"state"];
221 std::set<int> node_ids = {};
222 for (
const auto &surface : surface_selection)
224 std::vector<int> ids;
226 for (
const auto &i : ids)
229 return node_ids.size() * states[state_id]->mesh->dimension();
231 else if (selection.contains(
"volume_selection"))
233 auto volume_selection = selection[
"volume_selection"].get<std::vector<int>>();
234 auto state_id = selection[
"state"];
235 std::set<int> node_ids = {};
236 for (
const auto &volume : volume_selection)
238 std::vector<int> ids;
240 for (
const auto &i : ids)
244 if (selection[
"exclude_boundary_nodes"])
246 std::vector<int> ids;
248 for (
const auto &i : ids)
252 return node_ids.size() * states[state_id]->mesh->dimension();