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