diff --git a/MaterialLib/MPL/Medium.cpp b/MaterialLib/MPL/Medium.cpp index 94669996766ffb316f21f2cacdc79655fbc3a341..d0dd4b59e8a37afde3fbd728a910021dcee7ecb6 100644 --- a/MaterialLib/MPL/Medium.cpp +++ b/MaterialLib/MPL/Medium.cpp @@ -40,6 +40,12 @@ Phase const& Medium::phase(std::string const& name) const return phase->name == name; }, "Could not find phase name '" + name + "'."); + +bool Medium::hasPhase(std::string const& phase_name) const +{ + return std::any_of( + begin(phases_), end(phases_), + [&phase_name](auto const& phase) { return phase->name == phase_name; }); } Property const& Medium::property(PropertyType const& p) const @@ -67,4 +73,19 @@ std::string Medium::description() { return "medium"; } + +Phase const& fluidPhase(Medium const& medium) +{ + if (medium.hasPhase("Gas")) + { + return medium.phase("Gas"); + } + if (medium.hasPhase("AqueousLiquid")) + { + return medium.phase("AqueousLiquid"); + } + OGS_FATAL( + "Neither Gas nor AqueousLiquid phase is available for the medium, but " + "a fluid phase was requested."); +} } // namespace MaterialPropertyLib diff --git a/MaterialLib/MPL/Medium.h b/MaterialLib/MPL/Medium.h index da4a99cc6cc378b1346efea7360de872126e2e00..bfc0d290b8506b4d1e2e87a3d07ff65170d94bf6 100644 --- a/MaterialLib/MPL/Medium.h +++ b/MaterialLib/MPL/Medium.h @@ -38,6 +38,10 @@ public: Phase const& phase(std::size_t index) const; /// A get-function for a particular phase by phase name. Phase const& phase(std::string const& phase_name) const; + + /// A query for a named phase. + bool hasPhase(std::string const& phase_name) const; + /// A get-function for a property. The argument refers to the name of the /// property. Property const& property(PropertyType const& p) const; @@ -107,4 +111,7 @@ void checkRequiredProperties(Medium const& medium, } } +/// Returns a gas or aqueous liquid phase of the given medium. +Phase const& fluidPhase(Medium const& medium); + } // namespace MaterialPropertyLib