10#ifdef MOOSE_MFEM_ENABLED
24#include "libmesh/utility.h"
34template <
class T,
class Tpw>
41 template <
class P,
class... Args>
42 std::shared_ptr<P>
make(Args &&... args)
44 auto result = std::make_shared<P>(args...);
54 this->_iterable_coefficients.cend(),
55 coeff) != this->_iterable_coefficients.cend(),
56 "Coefficient object was not created by this CoefficientMap.");
58 const auto [_, inserted] = this->
_coefficients.emplace(name, std::move(coeff));
60 mooseError(
"Coefficient with name '" + name +
"' already present in CoefficientMap object");
68 std::shared_ptr<T> coeff,
69 const std::vector<std::string> &
blocks)
84 mooseError(
"Global coefficient with name '" + name +
"' already present in CoefficientMap");
86 this->_iterable_coefficients.cend(),
87 coeff) != this->_iterable_coefficients.cend(),
88 "Coefficient object was not created by the appropriate coefficient manager.");
89 auto & [pw_coeff, coeff_map] = *data;
92 for (
const auto & block :
blocks)
94 if (coeff_map.count(block) > 0)
95 mooseError(
"Property with name '" + name +
"' already assigned to block " + block +
96 " in CoefficientMap object");
97 coeff_map[block] = coeff;
98 pw_coeff->UpdateCoefficient(std::stoi(block), *coeff);
111 return std::get<std::shared_ptr<T>>(coeff);
113 catch (
const std::bad_variant_access &)
115 return std::get<0>(std::get<PWData>(coeff));
118 catch (
const std::out_of_range &)
120 mooseError(
"Property with name '" + name +
"' has not been declared.");
134 if (std::holds_alternative<std::shared_ptr<T>>(coeff))
136 auto block_map = std::get<1>(std::get<PWData>(coeff));
137 return block_map.count(block) > 0;
155 using PWData = std::tuple<std::shared_ptr<Tpw>, std::map<const std::string, std::shared_ptr<T>>>;
161 return std::make_tuple(this->
template make<Tpw>(),
162 std::map<
const std::string, std::shared_ptr<T>>());
165 std::shared_ptr<Tpw> ,
166 const std::string & )
183 std::shared_ptr<mfem::PWVectorCoefficient> existing_pw,
184 const std::string & name);
188 std::shared_ptr<mfem::PWMatrixCoefficient> existing_pw,
189 const std::string & name);
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Class to manage MFEM coefficient objects representing material properties.
std::map< const std::string, std::variant< std::shared_ptr< T >, PWData > > _coefficients
std::shared_ptr< P > make(Args &&... args)
Make arbitrary coefficients which will be tracked by this object.
bool propertyDefinedOnBlock(const std::string &name, const std::string &block) const
std::vector< std::shared_ptr< T > > _iterable_coefficients
void addCoefficient(const std::string &name, std::shared_ptr< T > coeff)
Add a named global coefficient.
bool hasCoefficient(const std::string &name) const
void addPiecewiseBlocks(const std::string &name, std::shared_ptr< T > coeff, const std::vector< std::string > &blocks)
Add piecewise material property.
void checkPWData(std::shared_ptr< T >, std::shared_ptr< Tpw >, const std::string &)
std::shared_ptr< T > getCoefficientPtr(const std::string &name)
void setTime(const mfem::real_t time)
void apply(F &&func)
Apply a function to every coefficient created by this map.
T & getCoefficient(const std::string &name)
PWData emptyPWData(std::shared_ptr< T >)
std::tuple< std::shared_ptr< Tpw >, std::map< const std::string, std::shared_ptr< T > > > PWData
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).