OGS
Component.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "BaseLib/Error.h"
15 #include "Property.h"
16 
17 namespace MaterialPropertyLib
18 {
24 class Component
25 {
26 public:
29  Component();
30 
32  Component(std::string const& component_name,
33  std::unique_ptr<PropertyArray>&& properties);
34  virtual ~Component() = default;
35 
37  Property const& property(PropertyType const& /*p*/) const;
38 
39  Property const& operator[](PropertyType const& p) const;
40 
41  bool hasProperty(PropertyType const& p) const;
42 
43  template <typename T>
44  T value(PropertyType const p) const
45  {
46  return property(p).template value<T>();
47  }
48 
49  template <typename T>
50  T value(PropertyType const p, VariableArray const& variable_array) const
51  {
52  return property(p).template value<T>(variable_array);
53  }
54 
55  template <typename T>
56  T dValue(PropertyType const p,
57  VariableArray const& variable_array,
58  Variable const variable) const
59  {
60  return property(p).template dValue<T>(variable_array, variable);
61  }
62 
63  template <typename T>
64  T d2Value(PropertyType const p,
65  VariableArray const& variable_array,
66  Variable const variable1,
67  Variable const variable2) const
68  {
69  return property(p).template d2Value<T>(variable_array, variable1,
70  variable2);
71  }
72 
74  std::string description() const;
75 
76 public:
77  std::string const name;
78 
79 protected:
82 };
83 
92 std::unique_ptr<Component> newComponent(std::string const& component_name,
93  bool& isCustomComponent);
94 
95 template <typename Container>
97  Container const& required_properties)
98 {
99  for (auto const& p : required_properties)
100  {
101  if (!c.hasProperty(p))
102  {
103  OGS_FATAL("The property '{:s}' is missing in the component '{:s}'.",
104  property_enum_to_string[p], c.name);
105  }
106  }
107 }
108 
109 } // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition: Error.h:26
This class defines components (substances).
Definition: Component.h:25
T dValue(PropertyType const p, VariableArray const &variable_array, Variable const variable) const
Definition: Component.h:56
Property const & property(PropertyType const &) const
A get-function for retrieving a certain property.
Definition: Component.cpp:32
T d2Value(PropertyType const p, VariableArray const &variable_array, Variable const variable1, Variable const variable2) const
Definition: Component.h:64
Property const & operator[](PropertyType const &p) const
Definition: Component.cpp:44
std::string const name
Definition: Component.h:77
T value(PropertyType const p) const
Definition: Component.h:44
virtual ~Component()=default
T value(PropertyType const p, VariableArray const &variable_array) const
Definition: Component.h:50
PropertyArray properties_
The property array of the component.
Definition: Component.h:81
bool hasProperty(PropertyType const &p) const
Definition: Component.cpp:49
std::string description() const
Short description of the component with its name.
Definition: Component.cpp:54
std::array< std::unique_ptr< Property >, PropertyType::number_of_properties > PropertyArray
std::unique_ptr< Component > newComponent(std::string const &component_name, bool &isCustomComponent)
static const std::array< std::string, PropertyType::number_of_properties > property_enum_to_string
Definition: PropertyType.h:111
std::array< VariableType, static_cast< int >(Variable::number_of_variables)> VariableArray
Definition: VariableType.h:108
void checkRequiredProperties(Component const &c, Container const &required_properties)
Definition: Component.h:96