https://mooseframework.inl.gov
Classes | Public Member Functions | Private Attributes | List of all members
MaterialPropertyRegistry Class Reference

Registry class for material property IDs and names. More...

#include <MaterialPropertyRegistry.h>

Classes

class  WriteKey
 Key that restricts writing data to the registry. More...
 

Public Member Functions

bool hasProperty (const std::string &name) const
 
bool hasProperty (const unsigned int id) const
 
unsigned int addOrGetID (const std::string &name, const WriteKey)
 
unsigned int getID (const std::string &name) const
 
std::optional< unsigned intqueryID (const std::string &name) const
 
const std::string & getName (const unsigned int id) const
 
auto idsToNamesBegin () const
 
auto idsToNamesEnd () const
 
auto idsToNamesRange () const
 
std::size_t size () const
 

Private Attributes

std::unordered_map< std::string, unsigned int_name_to_id
 Map of material property name -> material property id. More...
 
std::vector< std::string > _id_to_name
 Map of material property id -> material property name. More...
 

Detailed Description

Registry class for material property IDs and names.

Not thread safe.

Definition at line 26 of file MaterialPropertyRegistry.h.

Member Function Documentation

◆ addOrGetID()

unsigned int MaterialPropertyRegistry::addOrGetID ( const std::string &  name,
const WriteKey   
)
Returns
The property ID for the given name, adding the property and creating a new ID if it hasn't already been created.

Protected with the MaterialPropertyRegistry::WriteKey.

Definition at line 15 of file MaterialPropertyRegistry.C.

Referenced by MaterialPropertyStorage::addProperty().

17 {
18  const auto it = _name_to_id.find(name);
19  if (it != _name_to_id.end())
20  return it->second;
21 
22  const auto id = _id_to_name.size();
23  _name_to_id.emplace(name, id);
24  _id_to_name.push_back(name);
25  return id;
26 }
std::vector< std::string > _id_to_name
Map of material property id -> material property name.
std::unordered_map< std::string, unsigned int > _name_to_id
Map of material property name -> material property id.

◆ getID()

unsigned int MaterialPropertyRegistry::getID ( const std::string &  name) const
Returns
The property ID for the property with the name name

Will not create an ID if one does not exist, unlike addOrGetPropertyId

Definition at line 29 of file MaterialPropertyRegistry.C.

Referenced by MaterialData::getPropertyId(), and MaterialPropertyStorage::isRestoredProperty().

30 {
31  const auto id = queryID(name);
32  if (!id)
33  mooseError("MaterialPropertyRegistry: Property '" + name + "' is not declared");
34  return *id;
35 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::optional< unsigned int > queryID(const std::string &name) const

◆ getName()

const std::string & MaterialPropertyRegistry::getName ( const unsigned int  id) const
Returns
The property name for the property with the ID id

Definition at line 47 of file MaterialPropertyRegistry.C.

Referenced by MaterialBase::checkStatefulSanity(), MaterialPropertyStorage::initStatefulProps(), and MaterialPropertyStorage::queryStatefulPropName().

48 {
49  if (!hasProperty(id))
50  mooseError("MaterialPropertyRegistry: Property with ID ", id, " is not declared");
51  return _id_to_name[id];
52 }
std::vector< std::string > _id_to_name
Map of material property id -> material property name.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
bool hasProperty(const std::string &name) const

◆ hasProperty() [1/2]

bool MaterialPropertyRegistry::hasProperty ( const std::string &  name) const
inline
Returns
True if a material property is registered with the name name

Definition at line 32 of file MaterialPropertyRegistry.h.

Referenced by getName(), and MaterialPropertyStorage::hasProperty().

32 { return _name_to_id.count(name); }
std::unordered_map< std::string, unsigned int > _name_to_id
Map of material property name -> material property id.

◆ hasProperty() [2/2]

bool MaterialPropertyRegistry::hasProperty ( const unsigned int  id) const
inline
Returns
True if a material property is registered with the ID id

Definition at line 37 of file MaterialPropertyRegistry.h.

37 { return id < _id_to_name.size(); }
std::vector< std::string > _id_to_name
Map of material property id -> material property name.

◆ idsToNamesBegin()

auto MaterialPropertyRegistry::idsToNamesBegin ( ) const
inline
Returns
A beginning iterator to the property ID to name map

Definition at line 78 of file MaterialPropertyRegistry.h.

Referenced by idsToNamesRange().

78 { return _id_to_name.begin(); }
std::vector< std::string > _id_to_name
Map of material property id -> material property name.

◆ idsToNamesEnd()

auto MaterialPropertyRegistry::idsToNamesEnd ( ) const
inline
Returns
An end iterator to the property ID to name map

Definition at line 82 of file MaterialPropertyRegistry.h.

Referenced by idsToNamesRange().

82 { return _id_to_name.end(); }
std::vector< std::string > _id_to_name
Map of material property id -> material property name.

◆ idsToNamesRange()

auto MaterialPropertyRegistry::idsToNamesRange ( ) const
inline
Returns
An iterator range to the property ID to name map

Definition at line 86 of file MaterialPropertyRegistry.h.

◆ queryID()

std::optional< unsigned int > MaterialPropertyRegistry::queryID ( const std::string &  name) const
Returns
The property ID for the property with the name name if a propery exists with the name, otherwise an empty optional

Definition at line 38 of file MaterialPropertyRegistry.C.

Referenced by getID().

39 {
40  const auto it = _name_to_id.find(name);
41  if (it == _name_to_id.end())
42  return {};
43  return it->second;
44 }
std::unordered_map< std::string, unsigned int > _name_to_id
Map of material property name -> material property id.

◆ size()

std::size_t MaterialPropertyRegistry::size ( ) const
inline
Returns
The number of registered properties

Definition at line 91 of file MaterialPropertyRegistry.h.

Referenced by MaterialPropertyStorage::addProperty().

91 { return _id_to_name.size(); }
std::vector< std::string > _id_to_name
Map of material property id -> material property name.

Member Data Documentation

◆ _id_to_name

std::vector<std::string> MaterialPropertyRegistry::_id_to_name
private

Map of material property id -> material property name.

Definition at line 97 of file MaterialPropertyRegistry.h.

Referenced by addOrGetID(), getName(), hasProperty(), idsToNamesBegin(), idsToNamesEnd(), and size().

◆ _name_to_id

std::unordered_map<std::string, unsigned int> MaterialPropertyRegistry::_name_to_id
private

Map of material property name -> material property id.

Definition at line 95 of file MaterialPropertyRegistry.h.

Referenced by addOrGetID(), hasProperty(), and queryID().


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