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