diff --git a/MaterialLib/MPL/Component.cpp b/MaterialLib/MPL/Component.cpp index 6393d4a009ef8802ff2514bac0d9fe017f38ee27..52f5d79e659ec238e14237e84a0669bac2fa62c9 100644 --- a/MaterialLib/MPL/Component.cpp +++ b/MaterialLib/MPL/Component.cpp @@ -39,4 +39,9 @@ bool Component::hasProperty(PropertyType const& p) const { return properties_[p] != nullptr; } + +std::string Component::description() const +{ + return "component '" + name + "'"; +} } // namespace MaterialPropertyLib diff --git a/MaterialLib/MPL/Component.h b/MaterialLib/MPL/Component.h index 3e9774089a8ba744e9654641b6146c61295d22fa..68541fe00354037644cbaa334e71fee897a4ebc4 100644 --- a/MaterialLib/MPL/Component.h +++ b/MaterialLib/MPL/Component.h @@ -66,6 +66,9 @@ public: variable2); } + /// Short description of the component with its name. + std::string description() const; + public: std::string const name; diff --git a/MaterialLib/MPL/Medium.cpp b/MaterialLib/MPL/Medium.cpp index 1527c1372d2c4c5daf0690ef2109da12ac8bc23d..094bb66d2b473db2941a94a8fa65e2b51e04fcb3 100644 --- a/MaterialLib/MPL/Medium.cpp +++ b/MaterialLib/MPL/Medium.cpp @@ -56,4 +56,9 @@ std::size_t Medium::numberOfPhases() const { return phases_.size(); } + +std::string Medium::description() const +{ + return "medium"; +} } // namespace MaterialPropertyLib diff --git a/MaterialLib/MPL/Medium.h b/MaterialLib/MPL/Medium.h index 8cec072d86e66cb3b29dbfa4b85cc3887fadbc19..d060004a034b4519083dc04b26377280fba21743 100644 --- a/MaterialLib/MPL/Medium.h +++ b/MaterialLib/MPL/Medium.h @@ -47,6 +47,9 @@ public: /// consists of. std::size_t numberOfPhases() const; + /// Short description of the medium. + std::string description() const; + template <typename T> T value(PropertyType const p) const { diff --git a/MaterialLib/MPL/Phase.cpp b/MaterialLib/MPL/Phase.cpp index a729893bc6f8d8fd7ccf47d0ae6565ff952cb1d4..0349d737def52299e1c93e4c0ff2f3f9c0d4c3f2 100644 --- a/MaterialLib/MPL/Phase.cpp +++ b/MaterialLib/MPL/Phase.cpp @@ -54,8 +54,8 @@ Property const& Phase::property(PropertyType const& p) const Property const* const property = properties_[p].get(); if (property == nullptr) { - OGS_FATAL("Trying to access undefined property '{:s}' of phase {:s}", - property_enum_to_string[p], name); + OGS_FATAL("Trying to access undefined property '{:s}' of {:s}", + property_enum_to_string[p], description()); } return *properties_[p]; } @@ -70,4 +70,8 @@ std::size_t Phase::numberOfComponents() const return components_.size(); } +std::string Phase::description() const +{ + return "phase '" + name + "'"; +} } // namespace MaterialPropertyLib diff --git a/MaterialLib/MPL/Phase.h b/MaterialLib/MPL/Phase.h index 0efa37f6558727ea449f32c3d8f1332bd16cf131..f7c94bb7fd33992823bfe35d833a61888f5c1bc2 100644 --- a/MaterialLib/MPL/Phase.h +++ b/MaterialLib/MPL/Phase.h @@ -51,6 +51,9 @@ public: /// A get-function for retrieving the number of components in this phase. std::size_t numberOfComponents() const; + /// Short description of the phase with its name. + std::string description() const; + public: std::string const name; diff --git a/MaterialLib/MPL/Property.cpp b/MaterialLib/MPL/Property.cpp index 2754e8e2f39fa1dc8cb5432e39faa2bf37d8a3d1..6c500292442c7dde865df4a56c6a76081bbbc031 100644 --- a/MaterialLib/MPL/Property.cpp +++ b/MaterialLib/MPL/Property.cpp @@ -14,6 +14,10 @@ #include <string> +#include "Component.h" +#include "Medium.h" +#include "Phase.h" + namespace MaterialPropertyLib { PropertyDataType fromVector(std::vector<double> const& values) @@ -99,4 +103,12 @@ PropertyDataType Property::d2Value(VariableArray const& /*variable_array*/, { return 0.0; } + +std::string Property::description() const +{ + return "property '" + name_ + "' defined for " + + std::visit( + [](auto&& scale) -> std::string { return scale->description(); }, + scale_); +} } // namespace MaterialPropertyLib diff --git a/MaterialLib/MPL/Property.h b/MaterialLib/MPL/Property.h index 5c4c9420fd581fb720b6500717a5db65da96b735..84c2b75b9823e67434353606c431a3f97988dae4 100644 --- a/MaterialLib/MPL/Property.h +++ b/MaterialLib/MPL/Property.h @@ -14,6 +14,7 @@ #include <Eigen/Dense> #include <array> #include <string> +#include <typeinfo> #include <variant> #include "ParameterLib/SpatialPosition.h" @@ -82,13 +83,37 @@ public: T initialValue(ParameterLib::SpatialPosition const& pos, double const t) const { - return std::get<T>(initialValue(pos, t)); + try + { + return std::get<T>(initialValue(pos, t)); + } + catch (std::bad_variant_access const&) + { + OGS_FATAL( + "The initial value of {:s} does not hold requested type '{:s}' " + "but a {:s}.", + description(), + typeid(T).name(), + property_data_type_names_[initialValue(pos, t).index()]); + } } template <typename T> T value() const { - return std::get<T>(value()); + try + { + return std::get<T>(value()); + } + catch (std::bad_variant_access const&) + { + OGS_FATAL( + "The value of {:s} does not hold requested type '{:s}' but a " + "{:s}.", + description(), + typeid(T).name(), + property_data_type_names_[value().index()]); + } } template <typename T> @@ -96,7 +121,20 @@ public: ParameterLib::SpatialPosition const& pos, double const t, double const dt) const { - return std::get<T>(value(variable_array, pos, t, dt)); + try + { + return std::get<T>(value(variable_array, pos, t, dt)); + } + catch (std::bad_variant_access const&) + { + OGS_FATAL( + "The value of {:s} is not of the requested type '{:s}' but a " + "{:s}.", + description(), + typeid(T).name(), + property_data_type_names_[value(variable_array, pos, t, dt) + .index()]); + } } template <typename T> @@ -104,7 +142,20 @@ public: ParameterLib::SpatialPosition const& pos, double const t, double const dt) const { - return std::get<T>(dValue(variable_array, variable, pos, t, dt)); + try + { + return std::get<T>(dValue(variable_array, variable, pos, t, dt)); + } + catch (std::bad_variant_access const&) + { + OGS_FATAL( + "The first derivative value of {:s} is not of the requested " + "type '{:s}' but a {:s}.", + description(), + typeid(T).name(), + property_data_type_names_ + [dValue(variable_array, variable, pos, t, dt).index()]); + } } template <typename T> T d2Value(VariableArray const& variable_array, Variable const& variable1, @@ -112,8 +163,22 @@ public: ParameterLib::SpatialPosition const& pos, double const t, double const dt) const { - return std::get<T>( - d2Value(variable_array, variable1, variable2, pos, t, dt)); + try + { + return std::get<T>( + d2Value(variable_array, variable1, variable2, pos, t, dt)); + } + catch (std::bad_variant_access const&) + { + OGS_FATAL( + "The second derivative value of {:s} is not of the requested " + "type '{:s}' but a {:s}.", + description(), + typeid(T).name(), + property_data_type_names_[d2Value(variable_array, variable1, + variable2, pos, t, dt) + .index()]); + } } protected: @@ -132,6 +197,17 @@ private: // Empty check for properties which can be defined on every scale, // medium, phase or component } + std::string description() const; + +private: + /// Corresponds to the PropertyDataType + static constexpr std::array property_data_type_names_ = { + "scalar", "2-vector", "3-vector", "2x2-matrix", + "3x3-matrix", "2D-Kelvin vector", "3D-Kelvin vector"}; + static_assert(property_data_type_names_.size() == + std::variant_size_v<PropertyDataType>, + "The array of property data type names has different size " + "than the PropertyDataType variant type."); }; inline void overwriteExistingProperties(