https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Moose::MFEM::CoefficientMap< T, Tpw > Class Template Reference

Class to manage MFEM coefficient objects representing material properties. More...

#include <CoefficientMap.h>

Public Member Functions

 CoefficientMap ()=default
 
template<class P , class... Args>
std::shared_ptr< Pmake (Args &&... args)
 Make arbitrary coefficients which will be tracked by this object.
 
void addCoefficient (const std::string &name, std::shared_ptr< T > coeff)
 Add a named global coefficient.
 
void addPiecewiseBlocks (const std::string &name, std::shared_ptr< T > coeff, const std::vector< std::string > &blocks)
 Add piecewise material property.
 
T & getCoefficient (const std::string &name)
 
std::shared_ptr< T > getCoefficientPtr (const std::string &name)
 
bool hasCoefficient (const std::string &name) const
 
bool propertyDefinedOnBlock (const std::string &name, const std::string &block) const
 
void setTime (const mfem::real_t time)
 
template<class F >
void apply (F &&func)
 Apply a function to every coefficient created by this map.
 

Private Types

using PWData = std::tuple< std::shared_ptr< Tpw >, std::map< const std::string, std::shared_ptr< T > > >
 

Private Member Functions

PWData emptyPWData (std::shared_ptr< T >)
 
void checkPWData (std::shared_ptr< T >, std::shared_ptr< Tpw >, const std::string &)
 

Private Attributes

std::map< const std::string, std::variant< std::shared_ptr< T >, PWData > > _coefficients
 
std::vector< std::shared_ptr< T > > _iterable_coefficients
 

Detailed Description

template<class T, class Tpw>
class Moose::MFEM::CoefficientMap< T, Tpw >

Class to manage MFEM coefficient objects representing material properties.

It can build up piecewise coefficients representing properties defined across multiple materials.

Definition at line 35 of file CoefficientMap.h.

Member Typedef Documentation

◆ PWData

template<class T , class Tpw >
using Moose::MFEM::CoefficientMap< T, Tpw >::PWData = std::tuple<std::shared_ptr<Tpw>, std::map<const std::string, std::shared_ptr<T> >>
private

Definition at line 155 of file CoefficientMap.h.

Constructor & Destructor Documentation

◆ CoefficientMap()

template<class T , class Tpw >
Moose::MFEM::CoefficientMap< T, Tpw >::CoefficientMap ( )
default

Member Function Documentation

◆ addCoefficient()

template<class T , class Tpw >
void Moose::MFEM::CoefficientMap< T, Tpw >::addCoefficient ( const std::string &  name,
std::shared_ptr< T >  coeff 
)
inline

Add a named global coefficient.

It must have been created with the make method on this object.

Definition at line 51 of file CoefficientMap.h.

52 {
53 mooseAssert(std::find(this->_iterable_coefficients.cbegin(),
54 this->_iterable_coefficients.cend(),
55 coeff) != this->_iterable_coefficients.cend(),
56 "Coefficient object was not created by this CoefficientMap.");
57
58 const auto [_, inserted] = this->_coefficients.emplace(name, std::move(coeff));
59 if (!inserted)
60 mooseError("Coefficient with name '" + name + "' already present in CoefficientMap object");
61 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
std::map< const std::string, std::variant< std::shared_ptr< T >, PWData > > _coefficients
std::vector< std::shared_ptr< T > > _iterable_coefficients

Referenced by Moose::MFEM::CoefficientMap< T, Tpw >::addPiecewiseBlocks(), Moose::MFEM::CoefficientManager::declareMatrix(), Moose::MFEM::CoefficientManager::declareScalar(), and Moose::MFEM::CoefficientManager::declareVector().

◆ addPiecewiseBlocks()

template<class T , class Tpw >
void Moose::MFEM::CoefficientMap< T, Tpw >::addPiecewiseBlocks ( const std::string &  name,
std::shared_ptr< T >  coeff,
const std::vector< std::string > &  blocks 
)
inline

Add piecewise material property.

The coefficient must have been created with the make method on this object.

Note: If you attempt to overwrite an existing block then an exception will be thrown and data for that property will be left in an undefined state.

Definition at line 67 of file CoefficientMap.h.

70 {
71 // If list of blocks is empty then treat as a global coefficient
72 if (blocks.size() == 0)
73 {
74 this->addCoefficient(name, coeff);
75 return;
76 }
77
78 // Initialise property with empty coefficients, if it does not already exist
79 if (!this->hasCoefficient(name))
80 this->_coefficients.insert({name, this->emptyPWData(coeff)});
81 PWData * data = std::get_if<PWData>(&this->_coefficients[name]);
82 // Throw an exception if the data is not piecewise
83 if (!data)
84 mooseError("Global coefficient with name '" + name + "' already present in CoefficientMap");
85 mooseAssert(std::find(this->_iterable_coefficients.cbegin(),
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;
90 this->checkPWData(coeff, pw_coeff, name);
91
92 for (const auto & block : blocks)
93 {
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);
99 }
100 }
char ** blocks
void addCoefficient(const std::string &name, std::shared_ptr< T > coeff)
Add a named global coefficient.
bool hasCoefficient(const std::string &name) const
void checkPWData(std::shared_ptr< T >, std::shared_ptr< Tpw >, const std::string &)
PWData emptyPWData(std::shared_ptr< T >)
std::tuple< std::shared_ptr< Tpw >, std::map< const std::string, std::shared_ptr< T > > > PWData
std::string name(const ElemQuality q)

Referenced by Moose::MFEM::CoefficientManager::declareMatrixProperty(), Moose::MFEM::CoefficientManager::declareScalarProperty(), and Moose::MFEM::CoefficientManager::declareVectorProperty().

◆ apply()

template<class T , class Tpw >
template<class F >
void Moose::MFEM::CoefficientMap< T, Tpw >::apply ( F &&  func)
inline

Apply a function to every coefficient created by this map.

Definition at line 148 of file CoefficientMap.h.

149 {
150 for (auto & coef : this->_iterable_coefficients)
151 func(*coef);
152 }

Referenced by Moose::MFEM::CoefficientManager::markSolutionChanged().

◆ checkPWData()

template<class T , class Tpw >
void Moose::MFEM::CoefficientMap< T, Tpw >::checkPWData ( std::shared_ptr< T >  ,
std::shared_ptr< Tpw >  ,
const std::string &   
)
inlineprivate

Definition at line 164 of file CoefficientMap.h.

167 {
168 }

Referenced by Moose::MFEM::CoefficientMap< T, Tpw >::addPiecewiseBlocks().

◆ emptyPWData()

template<class T , class Tpw >
PWData Moose::MFEM::CoefficientMap< T, Tpw >::emptyPWData ( std::shared_ptr< T >  )
inlineprivate

Definition at line 159 of file CoefficientMap.h.

160 {
161 return std::make_tuple(this->template make<Tpw>(),
162 std::map<const std::string, std::shared_ptr<T>>());
163 }

Referenced by Moose::MFEM::CoefficientMap< T, Tpw >::addPiecewiseBlocks().

◆ getCoefficient()

template<class T , class Tpw >
T & Moose::MFEM::CoefficientMap< T, Tpw >::getCoefficient ( const std::string &  name)
inline

Definition at line 102 of file CoefficientMap.h.

102{ return *this->getCoefficientPtr(name); }
std::shared_ptr< T > getCoefficientPtr(const std::string &name)

◆ getCoefficientPtr()

template<class T , class Tpw >
std::shared_ptr< T > Moose::MFEM::CoefficientMap< T, Tpw >::getCoefficientPtr ( const std::string &  name)
inline

Definition at line 104 of file CoefficientMap.h.

105 {
106 try
107 {
108 auto & coeff = this->_coefficients.at(name);
109 try
110 {
111 return std::get<std::shared_ptr<T>>(coeff);
112 }
113 catch (const std::bad_variant_access &)
114 {
115 return std::get<0>(std::get<PWData>(coeff));
116 }
117 }
118 catch (const std::out_of_range &)
119 {
120 mooseError("Property with name '" + name + "' has not been declared.");
121 }
122 }

Referenced by Moose::MFEM::CoefficientMap< T, Tpw >::getCoefficient(), Moose::MFEM::CoefficientManager::getMatrixCoefficientPtr(), Moose::MFEM::CoefficientManager::getScalarCoefficientPtr(), and Moose::MFEM::CoefficientManager::getVectorCoefficientPtr().

◆ hasCoefficient()

template<class T , class Tpw >
bool Moose::MFEM::CoefficientMap< T, Tpw >::hasCoefficient ( const std::string &  name) const
inline

◆ make()

template<class T , class Tpw >
template<class P , class... Args>
std::shared_ptr< P > Moose::MFEM::CoefficientMap< T, Tpw >::make ( Args &&...  args)
inline

◆ propertyDefinedOnBlock()

template<class T , class Tpw >
bool Moose::MFEM::CoefficientMap< T, Tpw >::propertyDefinedOnBlock ( const std::string &  name,
const std::string &  block 
) const
inline

Definition at line 129 of file CoefficientMap.h.

130 {
131 if (!this->hasCoefficient(name))
132 return false;
133 auto & coeff = libmesh_map_find(this->_coefficients, name);
134 if (std::holds_alternative<std::shared_ptr<T>>(coeff))
135 return true;
136 auto block_map = std::get<1>(std::get<PWData>(coeff));
137 return block_map.count(block) > 0;
138 }

Referenced by Moose::MFEM::CoefficientManager::matrixPropertyIsDefined(), Moose::MFEM::CoefficientManager::scalarPropertyIsDefined(), and Moose::MFEM::CoefficientManager::vectorPropertyIsDefined().

◆ setTime()

template<class T , class Tpw >
void Moose::MFEM::CoefficientMap< T, Tpw >::setTime ( const mfem::real_t  time)
inline

Definition at line 140 of file CoefficientMap.h.

141 {
142 for (auto & coef : this->_iterable_coefficients)
143 coef->SetTime(time);
144 }

Referenced by Moose::MFEM::CoefficientManager::setTime().

Member Data Documentation

◆ _coefficients

template<class T , class Tpw >
std::map<const std::string, std::variant<std::shared_ptr<T>, PWData> > Moose::MFEM::CoefficientMap< T, Tpw >::_coefficients
private

◆ _iterable_coefficients

template<class T , class Tpw >
std::vector<std::shared_ptr<T> > Moose::MFEM::CoefficientMap< T, Tpw >::_iterable_coefficients
private

The documentation for this class was generated from the following file: