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