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