OGS 6.2.2-330-gf48c72f61.dirty.20200225212913
Component.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "Property.h"
15 
16 namespace MaterialPropertyLib
17 {
23 class Component
24 {
25 public:
28  Component();
29 
31  Component(std::string const& component_name,
32  std::unique_ptr<PropertyArray>&& properties);
33  virtual ~Component() = default;
34 
36  Property const& property(PropertyType const& /*p*/) const;
37  bool hasProperty(PropertyType const& p) const;
38 
39  template <typename T>
40  T value(PropertyType const p) const
41  {
42  return property(p).template value<T>();
43  }
44 
45  template <typename T>
46  T value(PropertyType const p, VariableArray const& variable_array) const
47  {
48  return property(p).template value<T>(variable_array);
49  }
50 
51  template <typename T>
52  T dValue(PropertyType const p,
53  VariableArray const& variable_array,
54  Variable const variable) const
55  {
56  return property(p).template dValue<T>(variable_array, variable);
57  }
58 
59  template <typename T>
60  T d2Value(PropertyType const p,
61  VariableArray const& variable_array,
62  Variable const variable1,
63  Variable const variable2) const
64  {
65  return property(p).template d2Value<T>(variable_array, variable1,
66  variable2);
67  }
68 
69 public:
70  std::string const name;
71 
72 protected:
75 };
76 
85 std::unique_ptr<Component> newComponent(std::string const& component_name,
86  bool& isCustomComponent);
87 
88 template <typename Container>
90  Container const& required_properties)
91 {
92  for (auto const& p : required_properties)
93  {
94  if (!c.hasProperty(p))
95  {
96  OGS_FATAL("The property '%s' is missing in the component '%s'.",
97  property_enum_to_string[p].c_str(), c.name.c_str());
98  }
99  }
100 }
101 
102 } // namespace MaterialPropertyLib
bool hasProperty(PropertyType const &p) const
Definition: Component.cpp:38
Property const & property(PropertyType const &) const
A get-function for retrieving a certain property.
Definition: Component.cpp:33
static const std::array< std::string, PropertyType::number_of_properties > property_enum_to_string
Definition: PropertyType.h:261
T dValue(PropertyType const p, VariableArray const &variable_array, Variable const variable) const
Definition: Component.h:52
std::unique_ptr< Component > newComponent(std::string const &component_name, bool &isCustomComponent)
virtual ~Component()=default
T value(PropertyType const p) const
Definition: Component.h:40
This class defines components (substances).
Definition: Component.h:23
T d2Value(PropertyType const p, VariableArray const &variable_array, Variable const variable1, Variable const variable2) const
Definition: Component.h:60
T value(PropertyType const p, VariableArray const &variable_array) const
Definition: Component.h:46
std::array< VariableType, static_cast< int >(Variable::number_of_variables)> VariableArray
Definition: VariableType.h:68
std::array< std::unique_ptr< Property >, PropertyType::number_of_properties > PropertyArray
void checkRequiredProperties(Component const &c, Container const &required_properties)
Definition: Component.h:89
#define OGS_FATAL(fmt,...)
Definition: Error.h:64
PropertyArray _properties
The property array of the component.
Definition: Component.h:74
std::string const name
Definition: Component.h:70