OGS
Phase.cpp
Go to the documentation of this file.
1
13#include "Phase.h"
14
15#include "BaseLib/Algorithm.h"
16#include "BaseLib/Error.h"
17#include "Component.h"
19
20namespace MaterialPropertyLib
21{
22Phase::Phase(std::string&& phase_name,
23 std::vector<std::unique_ptr<Component>>&& components,
24 std::unique_ptr<PropertyArray>&& properties)
25 : name(std::move(phase_name)), components_(std::move(components))
26{
27 if (properties)
28 {
29 overwriteExistingProperties(properties_, *properties, this);
30 }
31}
32
33Component const& Phase::component(const std::size_t& index) const
34{
35 return *components_[index];
36}
37
38bool Phase::hasComponent(std::size_t const& index) const
39{
40 return components_[index] != nullptr;
41}
42
43Component const& Phase::component(std::string const& name) const
44{
47 [&name](
48 std::unique_ptr<MaterialPropertyLib::Component> const& component)
49 { return component->name == name; },
50 [&]() { OGS_FATAL("Could not find component named '{:s}.'", name); });
51}
52
54{
55 Property const* const property = properties_[p].get();
56 if (property == nullptr)
57 {
58 OGS_FATAL("Trying to access undefined property '{:s}' of {:s}",
60 }
61 return *properties_[p];
62}
63
65{
66 return property(p);
67}
68
69bool Phase::hasProperty(PropertyType const& p) const
70{
71 return properties_[p] != nullptr;
72}
73
74std::size_t Phase::numberOfComponents() const
75{
76 return components_.size();
77}
78
79std::string Phase::description() const
80{
81 return "phase '" + name + "'";
82}
83
85 Phase const& phase, std::span<PropertyType const> const required_properties)
86{
87 for (auto const& p : required_properties)
88 {
89 if (!phase.hasProperty(p))
90 {
91 OGS_FATAL("The property '{:s}' is missing in the {:s} phase.",
93 }
94 }
95}
96
97} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:26
This class defines components (substances).
Definition Component.h:26
Property const & property(PropertyType const &p) const
Definition Phase.cpp:53
PropertyArray properties_
Definition Phase.h:72
std::string const name
Definition Phase.h:62
std::string description() const
Short description of the phase with its name.
Definition Phase.cpp:79
std::size_t numberOfComponents() const
A get-function for retrieving the number of components in this phase.
Definition Phase.cpp:74
std::vector< std::unique_ptr< Component > > const components_
Definition Phase.h:65
Property const & operator[](PropertyType const &p) const
Definition Phase.cpp:64
bool hasProperty(PropertyType const &p) const
Definition Phase.cpp:69
Phase(std::string &&phase_name, std::vector< std::unique_ptr< Component > > &&components, std::unique_ptr< PropertyArray > &&properties)
The Phase constructor is called with the optional phase name.
Definition Phase.cpp:22
bool hasComponent(std::size_t const &index) const
Definition Phase.cpp:38
Component const & component(std::size_t const &index) const
Definition Phase.cpp:33
ranges::range_reference_t< Range > findElementOrError(Range &range, std::predicate< ranges::range_reference_t< Range > > auto &&predicate, std::invocable auto error_callback)
Definition Algorithm.h:81
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