OGS
Component.cpp
Go to the documentation of this file.
1
13#include "Component.h"
14
15#include "BaseLib/Error.h"
18
19namespace MaterialPropertyLib
20{
22
23Component::Component(std::string const& component_name,
24 std::unique_ptr<PropertyArray>&& properties)
25 : name(component_name)
26{
27 if (properties)
28 {
29 overwriteExistingProperties(properties_, *properties, this);
30 }
31}
32
34{
35 Property const* const property = properties_[p].get();
36 if (property == nullptr)
37 {
38 OGS_FATAL("Trying to access undefined property '{:s}' of {:s}",
40 }
41
42 return *properties_[p];
43}
44
46{
47 return property(p);
48}
49
51{
52 return properties_[p] != nullptr;
53}
54
55std::string Component::description() const
56{
57 return "component '" + name + "'";
58}
59
61 Component const& c, std::span<PropertyType const> const required_properties)
62{
63 for (auto const& p : required_properties)
64 {
65 if (!c.hasProperty(p))
66 {
67 OGS_FATAL("The property '{:s}' is missing in the component '{:s}'.",
68 property_enum_to_string[p], c.name);
69 }
70 }
71}
72
73} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:26
This class defines components (substances).
Definition Component.h:26
Property const & property(PropertyType const &) const
A get-function for retrieving a certain property.
Definition Component.cpp:33
Property const & operator[](PropertyType const &p) const
Definition Component.cpp:45
PropertyArray properties_
The property array of the component.
Definition Component.h:82
bool hasProperty(PropertyType const &p) const
Definition Component.cpp:50
std::string description() const
Short description of the component with its name.
Definition Component.cpp:55
void overwriteExistingProperties(PropertyArray &properties, PropertyArray &new_properties, std::variant< Medium *, Phase *, Component * > scale_pointer)
Definition Property.h:322
void checkRequiredProperties(Component const &c, std::span< PropertyType const > const required_properties)
Definition Component.cpp:60
static const std::array< std::string, PropertyType::number_of_properties > property_enum_to_string