OGS
Medium.cpp
Go to the documentation of this file.
1
13#include "Medium.h"
14
15#include "BaseLib/Algorithm.h"
16#include "BaseLib/Error.h"
18
19namespace MaterialPropertyLib
20{
21Medium::Medium(int const material_id,
22 std::vector<std::unique_ptr<Phase>>&& phases,
23 std::unique_ptr<PropertyArray>&& properties)
24 : phases_(std::move(phases)), material_id_(material_id)
25{
26 if (properties)
27 {
28 overwriteExistingProperties(properties_, *properties, this);
29 }
31}
32
33Phase const& Medium::phase(std::size_t const index) const
34{
35 return *phases_[index];
36}
37
38Phase const& Medium::phase(std::string const& phase_name) const
39{
41 phases_,
42 [&phase_name](std::unique_ptr<MaterialPropertyLib::Phase> const& phase)
43 { return phase->name == phase_name; },
44 [&]() { OGS_FATAL("Could not find phase named '{:s}.'", phase_name); });
45}
46
47bool Medium::hasPhase(std::string const& phase_name) const
48{
49 return std::any_of(begin(phases_), end(phases_),
50 [&phase_name](auto const& phase)
51 { return phase->name == phase_name; });
52}
53
55{
56 Property const* const property = properties_[p].get();
57 if (property == nullptr)
58 {
59 OGS_FATAL("Trying to access undefined property '{:s}' of {:s}",
61 }
62 return *properties_[p];
63}
64
66{
67 return property(p);
68}
69
71{
72 return properties_[p] != nullptr;
73}
74
75std::size_t Medium::numberOfPhases() const
76{
77 return phases_.size();
78}
79
80std::string Medium::description() const
81{
82 return "medium " + std::to_string(material_id_);
83}
84
86 Medium const& medium,
87 std::span<PropertyType const> const required_properties)
88{
89 for (auto const& p : required_properties)
90 {
91 if (!medium.hasProperty(p))
92 {
94 "The property '{:s}' is missing in the medium definition.",
96 }
97 }
98}
99
100Phase const& fluidPhase(Medium const& medium)
101{
102 if (medium.hasPhase("Gas"))
103 {
104 return medium.phase("Gas");
105 }
106 if (medium.hasPhase("AqueousLiquid"))
107 {
108 return medium.phase("AqueousLiquid");
109 }
110 OGS_FATAL(
111 "Neither Gas nor AqueousLiquid phase is available for the medium, but "
112 "a fluid phase was requested.");
113}
114} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:26
std::size_t numberOfPhases() const
Definition Medium.cpp:75
Phase const & phase(std::size_t index) const
Definition Medium.cpp:33
Medium(int const material_id, std::vector< std::unique_ptr< Phase > > &&phases, std::unique_ptr< PropertyArray > &&properties)
Definition Medium.cpp:21
std::vector< std::unique_ptr< Phase > > const phases_
The vector that holds the phases.
Definition Medium.h:94
bool hasPhase(std::string const &phase_name) const
A query for a named phase.
Definition Medium.cpp:47
PropertyArray properties_
Definition Medium.h:101
Property const & property(PropertyType const &p) const
Definition Medium.cpp:54
bool hasProperty(PropertyType const &p) const
Definition Medium.cpp:70
Property const & operator[](PropertyType const &p) const
Definition Medium.cpp:65
std::string description() const
Short description of the medium.
Definition Medium.cpp:80
std::string const name
Definition Phase.h:62
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:77
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
void updatePropertiesForAllPhases(PropertyArray &properties, std::vector< std::unique_ptr< Phase > > const &phases)
Definition Property.h:338
static const std::array< std::string, PropertyType::number_of_properties > property_enum_to_string
Phase const & fluidPhase(Medium const &medium)
Returns a gas or aqueous liquid phase of the given medium.
Definition Medium.cpp:100