https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MaterialPropertyRegistry.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
11
12#include "MooseError.h"
13
14unsigned int
15MaterialPropertyRegistry::addOrGetID(const std::string & name,
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}
27
28unsigned int
29MaterialPropertyRegistry::getID(const std::string & name) const
30{
31 const auto id = queryID(name);
32 if (!id)
33 mooseError("MaterialPropertyRegistry: Property '" + name + "' is not declared");
34 return *id;
35}
36
37std::optional<unsigned int>
38MaterialPropertyRegistry::queryID(const std::string & name) const
39{
40 const auto it = _name_to_id.find(name);
41 if (it == _name_to_id.end())
42 return {};
43 return it->second;
44}
45
46const std::string &
47MaterialPropertyRegistry::getName(const unsigned int id) const
48{
49 if (!hasProperty(id))
50 mooseError("MaterialPropertyRegistry: Property with ID ", id, " is not declared");
51 return _id_to_name[id];
52}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Key that restricts writing data to the registry.
unsigned int getID(const std::string &name) const
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.
std::optional< unsigned int > queryID(const std::string &name) const
unsigned int addOrGetID(const std::string &name, const WriteKey)
bool hasProperty(const std::string &name) const
const std::string & getName(const unsigned int id) const