15 #include "axom/core.hpp"
22 axom::inlet::Inlet
initialize(axom::sidre::DataStore& datastore,
const std::string& input_file_path,
23 const Language language,
const std::string& sidre_path)
26 std::unique_ptr<axom::inlet::Reader> reader;
27 if (language == Language::Lua) {
28 reader = std::make_unique<axom::inlet::LuaReader>();
29 }
else if (language == Language::JSON) {
30 reader = std::make_unique<axom::inlet::JSONReader>();
31 }
else if (language == Language::YAML) {
32 reader = std::make_unique<axom::inlet::YAMLReader>();
35 if (axom::utilities::filesystem::pathExists(input_file_path)) {
36 reader->parseFile(input_file_path);
40 if (datastore.getRoot()->hasGroup(sidre_path)) {
42 datastore.getRoot()->destroyGroup(sidre_path);
44 axom::sidre::Group* inlet_root = datastore.getRoot()->createGroup(sidre_path);
45 return axom::inlet::Inlet(std::move(reader), inlet_root);
48 std::string
findMeshFilePath(
const std::string& mesh_path,
const std::string& input_file_path)
50 using namespace axom::utilities;
53 if (filesystem::pathExists(mesh_path)) {
59 std::string possible_path = filesystem::joinPath(input_file_dir, mesh_path);
60 if (filesystem::pathExists(possible_path)) {
65 std::string msg = axom::fmt::format(
"Input file: Given mesh file does not exist: '{0}'", mesh_path);
72 char actualpath[PATH_MAX + 1];
73 char* ptr = realpath(path.c_str(), actualpath);
75 SLIC_ERROR_ROOT(
"Failed to find absolute path from input file.");
78 axom::utilities::filesystem::getDirName(dir, std::string(actualpath));
84 axom::Path path(file_path);
85 std::string basename = path.baseName();
88 std::size_t index = basename.find_last_of(
".");
89 if (index != std::string::npos) {
90 name = basename.substr(0, index);
102 container.addDouble(
"x",
"x-component of vector");
103 container.addDouble(
"y",
"y-component of vector");
104 container.addDouble(
"z",
"z-component of vector");
109 container.addIntArray(
"attrs",
"Boundary attributes to which the BC should be applied");
120 SLIC_ERROR_ROOT_IF(!
isVector(),
"Cannot construct a vector coefficient from scalar input");
123 return std::make_unique<mfem::VectorFunctionCoefficient>(dim,
vector_function);
125 return std::make_unique<mfem::VectorConstantCoefficient>(*
vector_constant);
129 [](
auto a,
auto b) { return a.first < b.first; });
132 auto vec_pw_coeff = std::make_unique<mfem::VectorArrayCoefficient>(max_attr_elem->second.Size());
135 for (
int i = 0; i < max_attr_elem->second.Size(); ++i) {
138 mfem::Vector pw_constants(max_attr_elem->first);
142 pw_constants(entry.first - 1) = entry.second[i];
146 vec_pw_coeff->Set(i,
new mfem::PWConstCoefficient(pw_constants));
152 "Trying to build a vector coefficient without specifying a vector_function, vector_constant, or "
153 "vector_piecewise_constant.");
160 SLIC_ERROR_ROOT_IF(
isVector(),
"Cannot construct a scalar coefficient from vector input");
169 [](
auto a,
auto b) { return a.first < b.first; });
175 mfem::Vector pw_constants(max_attr_elem->first);
179 pw_constants(entry.first - 1) = entry.second;
183 return std::make_unique<mfem::PWConstCoefficient>(pw_constants);
188 "Trying to build a scalar coefficient without specifying a scalar_function, constant, or piecewise_constant.");
195 container.addFunction(
"vector_function", axom::inlet::FunctionTag::Vector,
196 {axom::inlet::FunctionTag::Vector, axom::inlet::FunctionTag::Double},
197 "The function to use for an mfem::VectorFunctionCoefficient");
198 container.addFunction(
"scalar_function", axom::inlet::FunctionTag::Double,
199 {axom::inlet::FunctionTag::Vector, axom::inlet::FunctionTag::Double},
200 "The function to use for an mfem::FunctionCoefficient");
201 container.addInt(
"component",
"The vector component to which the scalar coefficient should be applied");
203 container.addDouble(
"constant",
"The constant scalar value to use as the coefficient");
205 auto& vector_container = container.addStruct(
"vector_constant",
"The constant vector to use as the coefficient");
208 container.addDoubleArray(
"piecewise_constant",
209 "Map of mesh attributes to constant values to use as a piecewise coefficient");
211 auto& pw_vector_container = container.addStructArray(
212 "vector_piecewise_constant",
"Map of mesh attributes to constant vectors to use as a piecewise coefficient");
220 mfem::Vector result(3);
221 result[0] = base[
"x"];
222 if (base.contains(
"y")) {
223 result[1] = base[
"y"];
224 if (base.contains(
"z")) {
225 result[2] = base[
"z"];
236 const axom::inlet::Container& base)
241 auto bdr_attr_map = base[
"attrs"].get<std::unordered_map<int, int>>();
242 for (
const auto& [_, val] : bdr_attr_map) {
243 result.attrs.insert(val);
249 const axom::inlet::Container& base)
254 int coefficient_definitions = 0;
257 if (base.contains(
"vector_function")) {
258 auto func = base[
"vector_function"]
259 .get<std::function<axom::inlet::FunctionType::Vector(axom::inlet::FunctionType::Vector,
double)>>();
260 result.
vector_function = [func(std::move(func))](
const mfem::Vector& input,
double t, mfem::Vector& output) {
261 auto ret = func(axom::inlet::FunctionType::Vector{input.GetData(), input.Size()}, t);
263 std::copy(ret.vec.data(), ret.vec.data() + input.Size(), output.GetData());
265 coefficient_definitions++;
268 if (base.contains(
"scalar_function")) {
269 auto func = base[
"scalar_function"].get<std::function<double(axom::inlet::FunctionType::Vector,
double)>>();
270 result.
scalar_function = [func(std::move(func))](
const mfem::Vector& input,
double t) {
271 return func(axom::inlet::FunctionType::Vector{input.GetData(), input.Size()}, t);
273 coefficient_definitions++;
276 if (base.contains(
"constant")) {
278 coefficient_definitions++;
281 if (base.contains(
"vector_constant")) {
283 coefficient_definitions++;
286 if (base.contains(
"piecewise_constant")) {
287 result.
scalar_pw_const = base[
"piecewise_constant"].get<std::unordered_map<int, double>>();
288 coefficient_definitions++;
291 if (base.contains(
"vector_piecewise_constant")) {
292 result.
vector_pw_const = base[
"vector_piecewise_constant"].get<std::unordered_map<int, mfem::Vector>>();
293 coefficient_definitions++;
299 if (base.contains(
"component")) {
304 SLIC_ERROR_ROOT_IF(coefficient_definitions > 1,
305 "Coefficient has multiple definitions. Please use only one of (constant, vector_constant, "
306 "piecewise_constant, vector_piecewise_constant, scalar_function, vector_function");
307 SLIC_ERROR_ROOT_IF(coefficient_definitions == 0,
"Coefficient definition does not contain known type.");
This file contains the all the necessary functions and macros required for logging as well as a helpe...
This file contains enumerations and record types for physics solver configuration.
mfem::Vector operator()(const axom::inlet::Container &base)
Returns created object from Inlet container.