https://mooseframework.inl.gov
MaterialPropertyRegistry.h
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 
10 #pragma once
11 
12 #include <string>
13 #include <unordered_map>
14 #include <vector>
15 #include <optional>
16 
17 #include "libmesh/simple_range.h"
18 
20 
27 {
28 public:
32  bool hasProperty(const std::string & name) const { return _name_to_id.count(name); }
33 
37  bool hasProperty(const unsigned int id) const { return id < _id_to_name.size(); }
38 
42  class WriteKey
43  {
45  WriteKey() {}
46  WriteKey(const WriteKey &) {}
47  };
48 
55  unsigned int addOrGetID(const std::string & name, const WriteKey);
56 
62  unsigned int getID(const std::string & name) const;
63 
68  std::optional<unsigned int> queryID(const std::string & name) const;
69 
73  const std::string & getName(const unsigned int id) const;
74 
78  auto idsToNamesBegin() const { return _id_to_name.begin(); }
82  auto idsToNamesEnd() const { return _id_to_name.end(); }
87 
91  std::size_t size() const { return _id_to_name.size(); }
92 
93 private:
95  std::unordered_map<std::string, unsigned int> _name_to_id;
97  std::vector<std::string> _id_to_name;
98 };
std::string name(const ElemQuality q)
std::vector< std::string > _id_to_name
Map of material property id -> material property name.
Registry class for material property IDs and names.
std::unordered_map< std::string, unsigned int > _name_to_id
Map of material property name -> material property id.
Stores the stateful material properties computed by materials.
bool hasProperty(const std::string &name) const
bool hasProperty(const unsigned int id) const
Key that restricts writing data to the registry.
unsigned int addOrGetID(const std::string &name, const WriteKey)
const std::string & getName(const unsigned int id) const
unsigned int getID(const std::string &name) const
std::optional< unsigned int > queryID(const std::string &name) const