24 #include "libmesh/ignore_warnings.h" 26 #include "libmesh/restore_warnings.h" 27 #include "libmesh/utility.h" 37 template <
class T,
class Tpw>
44 template <
class P,
class... Args>
45 std::shared_ptr<P>
make(Args &&... args)
47 auto result = std::make_shared<P>(args...);
59 "Coefficient object was not created by this CoefficientMap.");
61 const auto [_, inserted] = this->
_coefficients.emplace(name, std::move(coeff));
63 mooseError(
"Coefficient with name '" +
name +
"' already present in CoefficientMap object");
71 std::shared_ptr<T> coeff,
72 const std::vector<std::string> &
blocks)
87 mooseError(
"Global coefficient with name '" +
name +
"' already present in CoefficientMap");
91 "Coefficient object was not created by the appropriate coefficient manager.");
92 auto & [pw_coeff, coeff_map] = *data;
95 for (
const auto & block :
blocks)
97 if (coeff_map.count(block) > 0)
98 mooseError(
"Property with name '" +
name +
"' already assigned to block " + block +
99 " in CoefficientMap object");
100 coeff_map[block] = coeff;
101 pw_coeff->UpdateCoefficient(std::stoi(block), *coeff);
114 return std::get<std::shared_ptr<T>>(coeff);
116 catch (
const std::bad_variant_access &)
118 return std::get<0>(std::get<PWData>(coeff));
121 catch (
const std::out_of_range &)
123 mooseError(
"Property with name '" +
name +
"' has not been declared.");
137 if (std::holds_alternative<std::shared_ptr<T>>(coeff))
139 auto block_map = std::get<1>(std::get<PWData>(coeff));
140 return block_map.count(block) > 0;
150 using PWData = std::tuple<std::shared_ptr<Tpw>, std::map<const std::string, std::shared_ptr<T>>>;
156 return std::make_tuple(this->
template make<Tpw>(),
157 std::map<
const std::string, std::shared_ptr<T>>());
160 std::shared_ptr<Tpw> ,
161 const std::string & )
178 std::shared_ptr<mfem::PWVectorCoefficient> existing_pw,
179 const std::string & name);
183 std::shared_ptr<mfem::PWMatrixCoefficient> existing_pw,
184 const std::string & name);
std::string name(const ElemQuality q)
bool propertyDefinedOnBlock(const std::string &name, const std::string &block) const
PWData emptyPWData(std::shared_ptr< T >)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
std::tuple< std::shared_ptr< mfem::PWMatrixCoefficient >, std::map< const std::string, std::shared_ptr< mfem::MatrixCoefficient > >> PWData
void addCoefficient(const std::string &name, std::shared_ptr< T > coeff)
Add a named global coefficient.
T & getCoefficient(const std::string &name)
void setTime(const double time)
std::shared_ptr< T > getCoefficientPtr(const std::string &name)
Class to manage MFEM coefficient objects representing material properties.
void addPiecewiseBlocks(const std::string &name, std::shared_ptr< T > coeff, const std::vector< std::string > &blocks)
Add piecewise material property.
std::vector< std::shared_ptr< T > > _iterable_coefficients
std::shared_ptr< P > make(Args &&... args)
Make arbitrary coefficients which will be tracked by this object.
std::map< const std::string, std::variant< std::shared_ptr< T >, PWData > > _coefficients
void checkPWData(std::shared_ptr< T >, std::shared_ptr< Tpw >, const std::string &)
bool hasCoefficient(const std::string &name) const