https://mooseframework.inl.gov
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< P > make (Args &&... args)
 Make arbitrary coefficients which will be tracked by this object. More...
 
void addCoefficient (const std::string &name, std::shared_ptr< T > coeff)
 Add a named global coefficient. More...
 
void addPiecewiseBlocks (const std::string &name, std::shared_ptr< T > coeff, const std::vector< std::string > &blocks)
 Add piecewise material property. More...
 
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 double time)
 

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 38 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 150 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 54 of file CoefficientMap.h.

Referenced by Moose::MFEM::CoefficientMap< mfem::MatrixCoefficient, mfem::PWMatrixCoefficient >::addPiecewiseBlocks(), Moose::MFEM::CoefficientManager::declareMatrix(), Moose::MFEM::CoefficientManager::declareScalar(), and Moose::MFEM::CoefficientManager::declareVector().

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

◆ 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 70 of file CoefficientMap.h.

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

73  {
74  // If list of blocks is empty then treat as a global coefficient
75  if (blocks.size() == 0)
76  {
77  this->addCoefficient(name, coeff);
78  return;
79  }
80 
81  // Initialise property with empty coefficients, if it does not already exist
82  if (!this->hasCoefficient(name))
83  this->_coefficients.insert({name, this->emptyPWData(coeff)});
84  PWData * data = std::get_if<PWData>(&this->_coefficients[name]);
85  // Throw an exception if the data is not piecewise
86  if (!data)
87  mooseError("Global coefficient with name '" + name + "' already present in CoefficientMap");
88  mooseAssert(std::find(this->_iterable_coefficients.cbegin(),
89  this->_iterable_coefficients.cend(),
90  coeff) != this->_iterable_coefficients.cend(),
91  "Coefficient object was not created by the appropriate coefficient manager.");
92  auto & [pw_coeff, coeff_map] = *data;
93  this->checkPWData(coeff, pw_coeff, name);
94 
95  for (const auto & block : blocks)
96  {
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);
102  }
103  }
std::string name(const ElemQuality q)
PWData emptyPWData(std::shared_ptr< T >)
char ** blocks
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::tuple< std::shared_ptr< Tpw >, std::map< const std::string, std::shared_ptr< T > >> PWData
void addCoefficient(const std::string &name, std::shared_ptr< T > coeff)
Add a named global coefficient.
std::vector< std::shared_ptr< T > > _iterable_coefficients
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

◆ 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

◆ emptyPWData()

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

Definition at line 154 of file CoefficientMap.h.

Referenced by Moose::MFEM::CoefficientMap< mfem::MatrixCoefficient, mfem::PWMatrixCoefficient >::addPiecewiseBlocks().

155  {
156  return std::make_tuple(this->template make<Tpw>(),
157  std::map<const std::string, std::shared_ptr<T>>());
158  }

◆ getCoefficient()

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

Definition at line 105 of file CoefficientMap.h.

105 { 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 107 of file CoefficientMap.h.

Referenced by Moose::MFEM::CoefficientMap< mfem::MatrixCoefficient, mfem::PWMatrixCoefficient >::getCoefficient(), Moose::MFEM::CoefficientManager::getMatrixCoefficientPtr(), Moose::MFEM::CoefficientManager::getScalarCoefficientPtr(), and Moose::MFEM::CoefficientManager::getVectorCoefficientPtr().

108  {
109  try
110  {
111  auto & coeff = this->_coefficients.at(name);
112  try
113  {
114  return std::get<std::shared_ptr<T>>(coeff);
115  }
116  catch (const std::bad_variant_access &)
117  {
118  return std::get<0>(std::get<PWData>(coeff));
119  }
120  }
121  catch (const std::out_of_range &)
122  {
123  mooseError("Property with name '" + name + "' has not been declared.");
124  }
125  }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::map< const std::string, std::variant< std::shared_ptr< T >, PWData > > _coefficients

◆ 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

Make arbitrary coefficients which will be tracked by this object.

Definition at line 45 of file CoefficientMap.h.

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

46  {
47  auto result = std::make_shared<P>(args...);
48  this->_iterable_coefficients.push_back(result);
49  return result;
50  }
std::vector< std::shared_ptr< T > > _iterable_coefficients

◆ 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 132 of file CoefficientMap.h.

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

133  {
134  if (!this->hasCoefficient(name))
135  return false;
136  auto & coeff = libmesh_map_find(this->_coefficients, name);
137  if (std::holds_alternative<std::shared_ptr<T>>(coeff))
138  return true;
139  auto block_map = std::get<1>(std::get<PWData>(coeff));
140  return block_map.count(block) > 0;
141  }
std::map< const std::string, std::variant< std::shared_ptr< T >, PWData > > _coefficients
bool hasCoefficient(const std::string &name) const

◆ setTime()

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

Definition at line 143 of file CoefficientMap.h.

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

144  {
145  for (auto & coef : this->_iterable_coefficients)
146  coef->SetTime(time);
147  }
std::vector< std::shared_ptr< T > > _iterable_coefficients

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: