OGS
Medium.cpp
Go to the documentation of this file.
1
13#include "Medium.h"
14
15#include "BaseLib/Algorithm.h"
17
18namespace MaterialPropertyLib
19{
20Medium::Medium(int const material_id,
21 std::vector<std::unique_ptr<Phase>>&& phases,
22 std::unique_ptr<PropertyArray>&& properties)
23 : phases_(std::move(phases)), material_id_(material_id)
24{
25 if (properties)
26 {
27 overwriteExistingProperties(properties_, *properties, this);
28 }
30}
31
32Phase const& Medium::phase(std::size_t const index) const
33{
34 return *phases_[index];
35}
36
37Phase const& Medium::phase(std::string const& phase_name) const
38{
40 phases_.begin(), phases_.end(),
41 [&phase_name](std::unique_ptr<MaterialPropertyLib::Phase> const& phase)
42 { return phase->name == phase_name; },
43 "Could not find phase name '" + phase_name + "'.");
44}
45
46bool Medium::hasPhase(std::string const& phase_name) const
47{
48 return std::any_of(begin(phases_), end(phases_),
49 [&phase_name](auto const& phase)
50 { return phase->name == phase_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
70{
71 return properties_[p] != nullptr;
72}
73
74std::size_t Medium::numberOfPhases() const
75{
76 return phases_.size();
77}
78
79std::string Medium::description() const
80{
81 return "medium " + std::to_string(material_id_);
82}
83
84Phase const& fluidPhase(Medium const& medium)
85{
86 if (medium.hasPhase("Gas"))
87 {
88 return medium.phase("Gas");
89 }
90 if (medium.hasPhase("AqueousLiquid"))
91 {
92 return medium.phase("AqueousLiquid");
93 }
95 "Neither Gas nor AqueousLiquid phase is available for the medium, but "
96 "a fluid phase was requested.");
97}
98} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition: Error.h:26
std::size_t numberOfPhases() const
Definition: Medium.cpp:74
Phase const & phase(std::size_t index) const
Definition: Medium.cpp:32
Medium(int const material_id, std::vector< std::unique_ptr< Phase > > &&phases, std::unique_ptr< PropertyArray > &&properties)
Definition: Medium.cpp:20
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:46
PropertyArray properties_
Definition: Medium.h:101
Property const & property(PropertyType const &p) const
Definition: Medium.cpp:53
bool hasProperty(PropertyType const &p) const
Definition: Medium.cpp:69
Property const & operator[](PropertyType const &p) const
Definition: Medium.cpp:64
std::string description() const
Short description of the medium.
Definition: Medium.cpp:79
std::string const name
Definition: Phase.h:61
std::iterator_traits< InputIt >::reference findElementOrError(InputIt begin, InputIt end, Predicate predicate, std::string const &error="")
Definition: Algorithm.h:69
constexpr bool any_of(List const &values)
Checks if any of the elements in the given list is true.
Definition: Algorithm.h:325
void overwriteExistingProperties(PropertyArray &properties, PropertyArray &new_properties, std::variant< Medium *, Phase *, Component * > scale_pointer)
Definition: Property.h:322
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
Definition: PropertyType.h:115
Phase const & fluidPhase(Medium const &medium)
Returns a gas or aqueous liquid phase of the given medium.
Definition: Medium.cpp:84