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

Lightweight adaptor over an std::map from strings to pointer to T. More...

#include <MFEMContainers.h>

Public Types

using MapType = std::map< std::string, std::shared_ptr< T > >
 
using const_iterator = typename MapType::const_iterator
 

Public Member Functions

 NamedFieldsMap ()=default
 Default initializer.
 
 ~NamedFieldsMap ()
 Destructor.
 
template<class FieldType , class... FieldArgs>
void Register (const std::string &field_name, FieldArgs &&... args)
 Construct new field with name field_name and register.
 
void Register (const std::string &field_name, std::shared_ptr< T > field)
 Register association between field and field_name.
 
void Deregister (const std::string &field_name)
 Unregister association between a field and the field_name.
 
bool Has (const std::string &field_name) const
 Predicate to check if a field is registered with name field_name.
 
std::shared_ptr< T > GetShared (const std::string &field_name) const
 Returns a shared pointer to the field. This is guaranteed to return a non-null shared pointer.
 
T & GetRef (const std::string &field_name) const
 Returns a reference to a field.
 
T * Get (const std::string &field_name) const
 Returns a non-owning pointer to the field. This is guaranteed to return a non-null pointer.
 
template<typename TDerived >
TDerived * Get (const std::string &field_name) const
 Returns a non-owning pointer to the field where TDerived is a derived class of class T.
 
std::vector< T * > Get (const std::vector< std::string > &keys) const
 Returns a vector containing all values for supplied keys.
 
const_iterator begin () const
 Returns a begin const iterator to the registered fields.
 
const_iterator end () const
 Returns an end const iterator to the registered fields.
 
int size ()
 Returns the number of elements in the map.
 

Protected Member Functions

const_iterator FindField (const std::string &field_name) const
 Returns a const iterator to the field.
 
void CheckFieldIsRegistrable (const std::string &field_name, T *field) const
 Check that the field pointer is valid and the field has not already been registered.
 
void CheckFieldIsRegistered (const std::string &field_name) const
 Check that a field exists in the map.
 
std::shared_ptr< T > EnsureFieldPointerIsNonNull (const_iterator &iterator) const
 Ensure that a returned shared pointer is valid.
 
template<typename TDerived >
TDerived * EnsurePointerCastIsNonNull (T *ptr) const
 Ensure that a dynamic cast is successful.
 
void DeregisterAll ()
 Clear all associations between names and fields.
 

Private Attributes

MapType _field_map {}
 

Detailed Description

template<typename T>
class Moose::MFEM::NamedFieldsMap< T >

Lightweight adaptor over an std::map from strings to pointer to T.

Definition at line 35 of file MFEMContainers.h.

Member Typedef Documentation

◆ const_iterator

template<typename T >
using Moose::MFEM::NamedFieldsMap< T >::const_iterator = typename MapType::const_iterator

Definition at line 39 of file MFEMContainers.h.

◆ MapType

template<typename T >
using Moose::MFEM::NamedFieldsMap< T >::MapType = std::map<std::string, std::shared_ptr<T> >

Definition at line 38 of file MFEMContainers.h.

Constructor & Destructor Documentation

◆ NamedFieldsMap()

template<typename T >
Moose::MFEM::NamedFieldsMap< T >::NamedFieldsMap ( )
default

Default initializer.

◆ ~NamedFieldsMap()

template<typename T >
Moose::MFEM::NamedFieldsMap< T >::~NamedFieldsMap ( )
inline

Destructor.

Definition at line 45 of file MFEMContainers.h.

45{ DeregisterAll(); }
void DeregisterAll()
Clear all associations between names and fields.

Member Function Documentation

◆ begin()

template<typename T >
const_iterator Moose::MFEM::NamedFieldsMap< T >::begin ( ) const
inline

Returns a begin const iterator to the registered fields.

Definition at line 120 of file MFEMContainers.h.

120{ return _field_map.begin(); }

◆ CheckFieldIsRegistered()

template<typename T >
void Moose::MFEM::NamedFieldsMap< T >::CheckFieldIsRegistered ( const std::string &  field_name) const
inlineprotected

Check that a field exists in the map.

Definition at line 146 of file MFEMContainers.h.

147 {
148 if (!Has(field_name))
149 mooseError("The field '" + field_name + "' has not been registered.");
150 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
bool Has(const std::string &field_name) const
Predicate to check if a field is registered with name field_name.

Referenced by Moose::MFEM::NamedFieldsMap< T >::GetShared().

◆ CheckFieldIsRegistrable()

template<typename T >
void Moose::MFEM::NamedFieldsMap< T >::CheckFieldIsRegistrable ( const std::string &  field_name,
T *  field 
) const
inlineprotected

Check that the field pointer is valid and the field has not already been registered.

Definition at line 137 of file MFEMContainers.h.

139 {
140 mooseAssert(field, "Cannot register NULL field with name '" + field_name + "'.");
141 mooseAssert(!Has(field_name) || Get(field_name) != field,
142 "The field '" + field_name + "' is already registered.");
143 }
T * Get(const std::string &field_name) const
Returns a non-owning pointer to the field. This is guaranteed to return a non-null pointer.

Referenced by Moose::MFEM::NamedFieldsMap< T >::Register().

◆ Deregister()

template<typename T >
void Moose::MFEM::NamedFieldsMap< T >::Deregister ( const std::string &  field_name)
inline

Unregister association between a field and the field_name.

Definition at line 65 of file MFEMContainers.h.

65{ _field_map.erase(field_name); }

Referenced by Moose::MFEM::NamedFieldsMap< T >::Register().

◆ DeregisterAll()

template<typename T >
void Moose::MFEM::NamedFieldsMap< T >::DeregisterAll ( )
inlineprotected

Clear all associations between names and fields.

Definition at line 170 of file MFEMContainers.h.

170{ _field_map.clear(); }

Referenced by Moose::MFEM::NamedFieldsMap< T >::~NamedFieldsMap().

◆ end()

template<typename T >
const_iterator Moose::MFEM::NamedFieldsMap< T >::end ( ) const
inline

Returns an end const iterator to the registered fields.

Definition at line 124 of file MFEMContainers.h.

124{ return _field_map.end(); }

Referenced by Moose::MFEM::NamedFieldsMap< T >::Has().

◆ EnsureFieldPointerIsNonNull()

template<typename T >
std::shared_ptr< T > Moose::MFEM::NamedFieldsMap< T >::EnsureFieldPointerIsNonNull ( const_iterator iterator) const
inlineprotected

Ensure that a returned shared pointer is valid.

Definition at line 153 of file MFEMContainers.h.

154 {
155 auto owned_ptr = iterator->second;
156 mooseAssert(owned_ptr, "The field '" + iterator->first + "' is NULL.");
157 return owned_ptr;
158 }

Referenced by Moose::MFEM::NamedFieldsMap< T >::GetShared().

◆ EnsurePointerCastIsNonNull()

template<typename T >
template<typename TDerived >
TDerived * Moose::MFEM::NamedFieldsMap< T >::EnsurePointerCastIsNonNull ( T *  ptr) const
inlineprotected

Ensure that a dynamic cast is successful.

Definition at line 162 of file MFEMContainers.h.

163 {
164 auto derived_ptr = dynamic_cast<TDerived *>(ptr);
165 mooseAssert(derived_ptr, "The dynamic cast performed on the field pointer failed.");
166 return derived_ptr;
167 }

◆ FindField()

template<typename T >
const_iterator Moose::MFEM::NamedFieldsMap< T >::FindField ( const std::string &  field_name) const
inlineprotected

Returns a const iterator to the field.

Definition at line 131 of file MFEMContainers.h.

132 {
133 return _field_map.find(field_name);
134 }

Referenced by Moose::MFEM::NamedFieldsMap< T >::GetShared(), and Moose::MFEM::NamedFieldsMap< T >::Has().

◆ Get() [1/3]

template<typename T >
T * Moose::MFEM::NamedFieldsMap< T >::Get ( const std::string &  field_name) const
inline

Returns a non-owning pointer to the field. This is guaranteed to return a non-null pointer.

Definition at line 90 of file MFEMContainers.h.

91 {
92 return GetShared(field_name).get();
93 }
std::shared_ptr< T > GetShared(const std::string &field_name) const
Returns a shared pointer to the field. This is guaranteed to return a non-null shared pointer.

Referenced by Moose::MFEM::TimeDependentEquationSystem::AddKernel(), Moose::MFEM::NamedFieldsMap< T >::CheckFieldIsRegistrable(), Moose::MFEM::EquationSystem::EliminateCoupledVariables(), Moose::MFEM::TimeDependentEquationSystem::EliminateCoupledVariables(), Moose::MFEM::EigenproblemEquationSystem::FormEigenproblemMatrix(), Moose::MFEM::EquationSystem::FormJacobianMatrix(), Moose::MFEM::EquationSystem::FormSystemMatrix(), Moose::MFEM::ComplexEquationSystem::FormSystemMatrix(), Moose::MFEM::EquationSystem::FormSystemOperator(), Moose::MFEM::ComplexEquationSystem::FormSystemOperator(), Moose::MFEM::NamedFieldsMap< T >::Get(), Moose::MFEM::NamedFieldsMap< T >::Get(), MFEMProblem::getMeshDisplacementGridFunction(), MFEMProblem::getMFEMVariableMesh(), Moose::MFEM::EquationSystem::Init(), Moose::MFEM::ComplexEquationSystem::Init(), Moose::MFEM::EigenproblemESProblemOperator::RecoverEigenproblemSolution(), Moose::MFEM::ProblemOperatorBase::SetGridFunctions(), Moose::MFEM::ComplexEquationSystemProblemOperator::SetGridFunctions(), Moose::MFEM::EquationSystem::SetTrialVariablesFromTrueVectors(), and Moose::MFEM::ComplexEquationSystem::SetTrialVariablesFromTrueVectors().

◆ Get() [2/3]

template<typename T >
template<typename TDerived >
TDerived * Moose::MFEM::NamedFieldsMap< T >::Get ( const std::string &  field_name) const
inline

Returns a non-owning pointer to the field where TDerived is a derived class of class T.

Definition at line 97 of file MFEMContainers.h.

98 {
99 auto ptr = Get(field_name);
100
101 return EnsurePointerCastIsNonNull<TDerived>(ptr);
102 }

◆ Get() [3/3]

template<typename T >
std::vector< T * > Moose::MFEM::NamedFieldsMap< T >::Get ( const std::vector< std::string > &  keys) const
inline

Returns a vector containing all values for supplied keys.

Definition at line 105 of file MFEMContainers.h.

106 {
107 std::vector<T *> values;
108
109 for (const auto & key : keys)
110 {
111 values.push_back(Get(key));
112 }
113
114 values.shrink_to_fit();
115 return values;
116 }
std::array< Real, 2 > values
Definition MortarUtils.C:52

◆ GetRef()

template<typename T >
T & Moose::MFEM::NamedFieldsMap< T >::GetRef ( const std::string &  field_name) const
inline

◆ GetShared()

template<typename T >
std::shared_ptr< T > Moose::MFEM::NamedFieldsMap< T >::GetShared ( const std::string &  field_name) const
inline

Returns a shared pointer to the field. This is guaranteed to return a non-null shared pointer.

Definition at line 74 of file MFEMContainers.h.

75 {
76 CheckFieldIsRegistered(field_name);
77
78 auto it = FindField(field_name);
79
81 }
std::shared_ptr< T > EnsureFieldPointerIsNonNull(const_iterator &iterator) const
Ensure that a returned shared pointer is valid.
void CheckFieldIsRegistered(const std::string &field_name) const
Check that a field exists in the map.
const_iterator FindField(const std::string &field_name) const
Returns a const iterator to the field.

Referenced by Moose::MFEM::EquationSystem::BuildBilinearForms(), Moose::MFEM::ComplexEquationSystem::BuildBilinearForms(), Moose::MFEM::TimeDependentEquationSystem::BuildBilinearForms(), Moose::MFEM::EquationSystem::BuildLinearForms(), Moose::MFEM::ComplexEquationSystem::BuildLinearForms(), Moose::MFEM::EquationSystem::BuildNonlinearForms(), Moose::MFEM::TimeDependentEquationSystem::BuildNonlinearForms(), Moose::MFEM::EquationSystem::ComputeNonlinearResidual(), Moose::MFEM::NamedFieldsMap< T >::Get(), MFEMProblem::getComplexGridFunction(), MFEMProblem::getGridFunction(), Moose::MFEM::NamedFieldsMap< T >::GetRef(), Moose::MFEM::EquationSystem::Init(), Moose::MFEM::ComplexEquationSystem::Init(), and MFEMVariable::MFEMVariable().

◆ Has()

template<typename T >
bool Moose::MFEM::NamedFieldsMap< T >::Has ( const std::string &  field_name) const
inline

◆ Register() [1/2]

template<typename T >
template<class FieldType , class... FieldArgs>
void Moose::MFEM::NamedFieldsMap< T >::Register ( const std::string &  field_name,
FieldArgs &&...  args 
)
inline

◆ Register() [2/2]

template<typename T >
void Moose::MFEM::NamedFieldsMap< T >::Register ( const std::string &  field_name,
std::shared_ptr< T >  field 
)
inline

Register association between field and field_name.

Definition at line 55 of file MFEMContainers.h.

56 {
57 CheckFieldIsRegistrable(field_name, field.get());
58
59 Deregister(field_name);
60
61 _field_map[field_name] = std::move(field);
62 }
void CheckFieldIsRegistrable(const std::string &field_name, T *field) const
Check that the field pointer is valid and the field has not already been registered.
void Deregister(const std::string &field_name)
Unregister association between a field and the field_name.

◆ size()

template<typename T >
int Moose::MFEM::NamedFieldsMap< T >::size ( )
inline

Returns the number of elements in the map.

Definition at line 127 of file MFEMContainers.h.

127{ return _field_map.size(); }

Referenced by dataStore(), and Moose::MFEM::ComplexEquationSystem::Init().

Member Data Documentation

◆ _field_map

template<typename T >
MapType Moose::MFEM::NamedFieldsMap< T >::_field_map {}
private

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