26 if (!args.contains(
"common"))
28 const std::string common_path = args[
"common"].get<std::string>();
29 if (common_path.empty())
33 auto common_resources = resources.
with_root(logical_parent(common_path));
34 const bool has_explicit_root = common_params.contains(
"root_path")
35 && common_params[
"root_path"].is_string()
36 && !common_params[
"root_path"].get<std::string>().empty();
37 if (has_explicit_root)
38 common_resources = common_resources->with_root(common_params[
"root_path"].get<std::string>());
39 common_params.erase(
"root_path");
41 common_resources = std::move(nested_resources);
44 if (args.contains(
"patch"))
46 patch = args[
"patch"];
49 args.erase(
"root_path");
50 common_params.merge_patch(args);
52 common_params = common_params.patch(patch);
53 args = std::move(common_params);
59 return has_explicit_root ? std::move(common_resources) :
nullptr;
64 if (!args.contains(
"common"))
67 const std::string common_params_path =
resolve_path(args[
"common"], args[
"root_path"]);
69 if (common_params_path.empty())
72 const std::filesystem::path common_path(common_params_path);
74 json common_params = json::parse(resources.
read_string(common_path.filename().string()));
77 const bool has_root_path = common_params.contains(
"root_path");
79 common_params[
"root_path"] =
resolve_path(common_params[
"root_path"], common_params_path);
81 common_params[
"root_path"] = common_params_path;
88 args[
"root_path"] = common_params[
"root_path"];
91 if (args.contains(
"patch"))
93 patch = args[
"patch"];
97 common_params.merge_patch(args);
99 common_params = common_params.patch(patch);
100 args = common_params;
102 args.erase(
"common");
107 if (!args.contains(
"boundary_conditions"))
110 json &bcs = args[
"boundary_conditions"];
111 if (!bcs.contains(
"dirichlet_boundary") || !bcs[
"dirichlet_boundary"].is_array())
114 const json root_path = args.contains(
"root_path") ? args[
"root_path"] :
json(
"");
116 json expanded = json::array();
117 for (
const auto &entry : bcs[
"dirichlet_boundary"])
119 if (entry.is_string())
121 const std::string path =
resolve_path(entry, root_path);
122 if (std::filesystem::path(path).extension() ==
".json")
124 std::ifstream file(path);
133 catch (
const std::exception &e)
139 if (!sidecar.is_array())
143 for (
const auto &e : sidecar)
146 expanded.push_back(jse.inject_defaults(filled, rules));
151 expanded.push_back(entry);
153 bcs[
"dirichlet_boundary"] = expanded;
161 if (!args.contains(
"boundary_conditions"))
164 json &bcs = args[
"boundary_conditions"];
165 if (!bcs.contains(
"dirichlet_boundary") || !bcs[
"dirichlet_boundary"].is_array())
168 json expanded = json::array();
169 for (
const auto &entry : bcs[
"dirichlet_boundary"])
171 if (entry.is_string())
173 const std::string path = entry.get<std::string>();
174 if (std::filesystem::path(path).extension() ==
".json")
179 sidecar = json::parse(resources.
read_string(path));
181 catch (
const std::exception &e)
184 "Unable to read dirichlet_boundary resource {}: {}", path, e.what());
187 if (!sidecar.is_array())
191 for (
const auto &e : sidecar)
194 expanded.push_back(jse.inject_defaults(filled, rules));
199 expanded.push_back(entry);
201 bcs[
"dirichlet_boundary"] = expanded;
206 std::transform(mode.begin(), mode.end(), mode.begin(), ::tolower);
208 if (jr.is_array() && jr.empty())
210 return Eigen::Matrix3d::Identity(3, 3);
217 assert(mode.size() == 1);
218 int i = mode[0] -
'x';
219 assert(i >= 0 && i < 3);
220 r[i] = jr.get<
double>();
224 assert(jr.is_array());
228 if (mode ==
"axis_angle")
230 assert(r.size() == 4);
232 Eigen::Vector3d axis = r.tail<3>().normalized();
233 return Eigen::AngleAxisd(angle, axis).toRotationMatrix();
236 if (mode ==
"quaternion")
238 assert(r.size() == 4);
239 Eigen::Vector4d q = r.normalized();
240 return Eigen::Quaterniond(q).toRotationMatrix();
246 if (mode ==
"rotation_vector")
248 assert(r.size() == 3);
249 double angle = r.norm();
252 return Eigen::AngleAxisd(angle, r / angle).toRotationMatrix();
256 return Eigen::Matrix3d::Identity();
260 Eigen::Matrix3d R = Eigen::Matrix3d::Identity();
262 for (
int i = 0; i < mode.size(); i++)
264 int j = mode[i] -
'x';
265 assert(j >= 0 && j < 3);
266 Eigen::Vector3d axis = Eigen::Vector3d::Zero();
268 R = Eigen::AngleAxisd(r[j], axis).toRotationMatrix() * R;