12 #include "axom/core.hpp"
20 axom::inlet::Inlet
initialize(axom::sidre::DataStore& datastore,
const std::string& input_file_path,
21 const Language language,
const std::string& sidre_path)
24 std::unique_ptr<axom::inlet::Reader> reader;
25 if (language == Language::Lua) {
26 reader = std::make_unique<axom::inlet::LuaReader>();
27 }
else if (language == Language::JSON) {
28 reader = std::make_unique<axom::inlet::JSONReader>();
29 }
else if (language == Language::YAML) {
30 reader = std::make_unique<axom::inlet::YAMLReader>();
33 if (axom::utilities::filesystem::pathExists(input_file_path)) {
34 reader->parseFile(input_file_path);
38 if (datastore.getRoot()->hasGroup(sidre_path)) {
40 datastore.getRoot()->destroyGroup(sidre_path);
42 axom::sidre::Group* inlet_root = datastore.getRoot()->createGroup(sidre_path);
43 return axom::inlet::Inlet(std::move(reader), inlet_root);
46 std::string
findMeshFilePath(
const std::string& mesh_path,
const std::string& input_file_path)
48 using namespace axom::utilities;
51 if (filesystem::pathExists(mesh_path)) {
57 std::string possible_path = filesystem::joinPath(input_file_dir, mesh_path);
58 if (filesystem::pathExists(possible_path)) {
63 std::string msg = axom::fmt::format(
"Input file: Given mesh file does not exist: '{0}'", mesh_path);
70 char actualpath[PATH_MAX + 1];
71 char* ptr = realpath(path.c_str(), actualpath);
73 SLIC_ERROR_ROOT(
"Failed to find absolute path from input file.");
76 axom::utilities::filesystem::getDirName(dir, std::string(actualpath));
82 axom::Path path(file_path);
83 std::string basename = path.baseName();
86 std::size_t index = basename.find_last_of(
".");
87 if (index != std::string::npos) {
88 name = basename.substr(0, index);
100 container.addDouble(
"x",
"x-component of vector");
101 container.addDouble(
"y",
"y-component of vector");
102 container.addDouble(
"z",
"z-component of vector");
107 container.addIntArray(
"attrs",
"Boundary attributes to which the BC should be applied");
118 SLIC_ERROR_ROOT_IF(!
isVector(),
"Cannot construct a vector coefficient from scalar input");
121 return std::make_unique<mfem::VectorFunctionCoefficient>(dim,
vector_function);
123 return std::make_unique<mfem::VectorConstantCoefficient>(*
vector_constant);
127 [](
auto a,
auto b) { return a.first < b.first; });
130 auto vec_pw_coeff = std::make_unique<mfem::VectorArrayCoefficient>(max_attr_elem->second.Size());
133 for (
int i = 0; i < max_attr_elem->second.Size(); ++i) {
136 mfem::Vector pw_constants(max_attr_elem->first);
140 pw_constants(entry.first - 1) = entry.second[i];
144 vec_pw_coeff->Set(i,
new mfem::PWConstCoefficient(pw_constants));
150 "Trying to build a vector coefficient without specifying a vector_function, vector_constant, or "
151 "vector_piecewise_constant.");
158 SLIC_ERROR_ROOT_IF(
isVector(),
"Cannot construct a scalar coefficient from vector input");
167 [](
auto a,
auto b) { return a.first < b.first; });
173 mfem::Vector pw_constants(max_attr_elem->first);
177 pw_constants(entry.first - 1) = entry.second;
181 return std::make_unique<mfem::PWConstCoefficient>(pw_constants);
186 "Trying to build a scalar coefficient without specifying a scalar_function, constant, or piecewise_constant.");
193 container.addFunction(
"vector_function", axom::inlet::FunctionTag::Vector,
194 {axom::inlet::FunctionTag::Vector, axom::inlet::FunctionTag::Double},
195 "The function to use for an mfem::VectorFunctionCoefficient");
196 container.addFunction(
"scalar_function", axom::inlet::FunctionTag::Double,
197 {axom::inlet::FunctionTag::Vector, axom::inlet::FunctionTag::Double},
198 "The function to use for an mfem::FunctionCoefficient");
199 container.addInt(
"component",
"The vector component to which the scalar coefficient should be applied");
201 container.addDouble(
"constant",
"The constant scalar value to use as the coefficient");
203 auto& vector_container = container.addStruct(
"vector_constant",
"The constant vector to use as the coefficient");
206 container.addDoubleArray(
"piecewise_constant",
207 "Map of mesh attributes to constant values to use as a piecewise coefficient");
209 auto& pw_vector_container = container.addStructArray(
210 "vector_piecewise_constant",
"Map of mesh attributes to constant vectors to use as a piecewise coefficient");
218 mfem::Vector result(3);
219 result[0] = base[
"x"];
220 if (base.contains(
"y")) {
221 result[1] = base[
"y"];
222 if (base.contains(
"z")) {
223 result[2] = base[
"z"];
234 const axom::inlet::Container& base)
239 auto bdr_attr_map = base[
"attrs"].get<std::unordered_map<int, int>>();
240 for (
const auto& [_, val] : bdr_attr_map) {
241 result.attrs.insert(val);
247 const axom::inlet::Container& base)
252 int coefficient_definitions = 0;
255 if (base.contains(
"vector_function")) {
256 auto func = base[
"vector_function"]
257 .get<std::function<axom::inlet::FunctionType::Vector(axom::inlet::FunctionType::Vector,
double)>>();
258 result.
vector_function = [func(std::move(func))](
const mfem::Vector& input,
double t, mfem::Vector& output) {
259 auto ret = func(axom::inlet::FunctionType::Vector{input.GetData(), input.Size()}, t);
261 std::copy(ret.vec.data(), ret.vec.data() + input.Size(), output.GetData());
263 coefficient_definitions++;
266 if (base.contains(
"scalar_function")) {
267 auto func = base[
"scalar_function"].get<std::function<double(axom::inlet::FunctionType::Vector,
double)>>();
268 result.
scalar_function = [func(std::move(func))](
const mfem::Vector& input,
double t) {
269 return func(axom::inlet::FunctionType::Vector{input.GetData(), input.Size()}, t);
271 coefficient_definitions++;
274 if (base.contains(
"constant")) {
276 coefficient_definitions++;
279 if (base.contains(
"vector_constant")) {
281 coefficient_definitions++;
284 if (base.contains(
"piecewise_constant")) {
285 result.
scalar_pw_const = base[
"piecewise_constant"].get<std::unordered_map<int, double>>();
286 coefficient_definitions++;
289 if (base.contains(
"vector_piecewise_constant")) {
290 result.
vector_pw_const = base[
"vector_piecewise_constant"].get<std::unordered_map<int, mfem::Vector>>();
291 coefficient_definitions++;
297 if (base.contains(
"component")) {
302 SLIC_ERROR_ROOT_IF(coefficient_definitions > 1,
303 "Coefficient has multiple definitions. Please use only one of (constant, vector_constant, "
304 "piecewise_constant, vector_piecewise_constant, scalar_function, vector_function");
305 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.
Helper functions for exiting Serac cleanly.