diff --git a/Documentation/ProjectFile/properties/property/LinearProperty/c_LinearProperty.md b/Documentation/ProjectFile/properties/property/LinearProperty/c_LinearProperty.md new file mode 100644 index 0000000000000000000000000000000000000000..faa21dbd7738ba017ccaf26fb9fcef757f5681e9 --- /dev/null +++ b/Documentation/ProjectFile/properties/property/LinearProperty/c_LinearProperty.md @@ -0,0 +1,7 @@ +Definition of a linear property: +\f$y(x) = y_{\textrm{ref}} + m (x - x_{\textrm{ref}})\f$ +where + - \f$y_{\textrm{ref}}\f$ is a reference value, for instance reference density + - \f$m\f$ is the slope of the linear relationship + - \f$x_{\textrm{ref}}\f$ is a reference condition, for instance reference + temperatue diff --git a/Documentation/ProjectFile/properties/property/LinearProperty/independent_variable/i_independent_variable.md b/Documentation/ProjectFile/properties/property/LinearProperty/independent_variable/i_independent_variable.md new file mode 100644 index 0000000000000000000000000000000000000000..9d797ee1c8e60ecb58d074031ade4ec0bd23b91f --- /dev/null +++ b/Documentation/ProjectFile/properties/property/LinearProperty/independent_variable/i_independent_variable.md @@ -0,0 +1 @@ +A linear constitutive property. diff --git a/Documentation/ProjectFile/properties/property/LinearProperty/independent_variable/t_reference_condition.md b/Documentation/ProjectFile/properties/property/LinearProperty/independent_variable/t_reference_condition.md new file mode 100644 index 0000000000000000000000000000000000000000..fb5bc54c32e7ee9f400d6d6a985714ac6efa86e1 --- /dev/null +++ b/Documentation/ProjectFile/properties/property/LinearProperty/independent_variable/t_reference_condition.md @@ -0,0 +1,2 @@ +A numeric value for the reference condition \f$x_{\textrm{ref}}\f$ as one of +the implemented data types given in MaterialPropertyLib::PropertyDataType. diff --git a/Documentation/ProjectFile/properties/property/LinearProperty/independent_variable/t_slope.md b/Documentation/ProjectFile/properties/property/LinearProperty/independent_variable/t_slope.md new file mode 100644 index 0000000000000000000000000000000000000000..4d191455ba985fd606201453c7c13d1c5ab91b4d --- /dev/null +++ b/Documentation/ProjectFile/properties/property/LinearProperty/independent_variable/t_slope.md @@ -0,0 +1 @@ +The slope \f$m\f$ of the linear relation. diff --git a/Documentation/ProjectFile/properties/property/LinearProperty/independent_variable/t_variable_name.md b/Documentation/ProjectFile/properties/property/LinearProperty/independent_variable/t_variable_name.md new file mode 100644 index 0000000000000000000000000000000000000000..3feab6e4e326bcf331d40e9c2ab5460237567ce4 --- /dev/null +++ b/Documentation/ProjectFile/properties/property/LinearProperty/independent_variable/t_variable_name.md @@ -0,0 +1 @@ +The variable type the linear relation depends on. diff --git a/Documentation/ProjectFile/properties/property/LinearProperty/t_reference_value.md b/Documentation/ProjectFile/properties/property/LinearProperty/t_reference_value.md new file mode 100644 index 0000000000000000000000000000000000000000..53bc7bf18e568dc6eecc5248dc3223367332ecd4 --- /dev/null +++ b/Documentation/ProjectFile/properties/property/LinearProperty/t_reference_value.md @@ -0,0 +1,2 @@ +A numeric value for the reference value \f$y_{\textrm{ref}}\f$ as one of +the implemented data types given in MaterialPropertyLib::PropertyDataType. diff --git a/MaterialLib/MPL/Component.h b/MaterialLib/MPL/Component.h index 98c264760d265f5542697c74a4bb20f6de99397b..972dfbce0890f09050099acb5b4ea1ed48a7c53a 100644 --- a/MaterialLib/MPL/Component.h +++ b/MaterialLib/MPL/Component.h @@ -51,19 +51,19 @@ public: template <typename T> T dValue(PropertyType const p, VariableArray const& variable_array, - Variables const variables) const + Variable const variable) const { - return property(p).template dValue<T>(variable_array, variables); + return property(p).template dValue<T>(variable_array, variable); } template <typename T> T d2Value(PropertyType const p, VariableArray const& variable_array, - Variables const variables1, - Variables const variables2) const + Variable const variable1, + Variable const variable2) const { - return property(p).template d2Value<T>(variable_array, variables1, - variables2); + return property(p).template d2Value<T>(variable_array, variable1, + variable2); } std::string name() const; diff --git a/MaterialLib/MPL/CreateProperty.cpp b/MaterialLib/MPL/CreateProperty.cpp index 9113a8eb53f30ffb2071be6cca94e74a20c43cd2..0bffdcaf5ed40bde795d4d7ebb0a941d8b126c75 100644 --- a/MaterialLib/MPL/CreateProperty.cpp +++ b/MaterialLib/MPL/CreateProperty.cpp @@ -99,6 +99,40 @@ std::unique_ptr<MaterialPropertyLib::Property> createProperty( // Note that most property constructors (only those that request material // pointers) must be overloaded for any type of material. + if (property_type == "Linear") + { + double const reference_value = + //! \ogs_file_param{properties__property__LinearProperty__reference_value} + config.getConfigParameter<double>("reference_value"); + + auto const& independent_variable_config = + //! \ogs_file_param{properties__property__LinearProperty__independent_variable} + config.getConfigSubtree("independent_variable"); + + auto const& variable_name = + //! \ogs_file_param{properties__property__LinearProperty__independent_variable__variable_name} + independent_variable_config.getConfigParameter<std::string>( + "variable_name"); + double const reference_condition = + //! \ogs_file_param{properties__property__LinearProperty__independent_variable__reference_condition} + independent_variable_config.getConfigParameter<double>( + "reference_condition"); + double const slope = + //! \ogs_file_param{properties__property__LinearProperty__independent_variable__slope} + independent_variable_config.getConfigParameter<double>("slope"); + + MaterialPropertyLib::Variable ivt = + MaterialPropertyLib::convertStringToVariable(variable_name); + + MaterialPropertyLib::IndependentVariable const iv{ + ivt, reference_condition, slope}; + MaterialPropertyLib::LinearProperty linear_property{reference_value, + iv}; + + return std::make_unique<MaterialPropertyLib::LinearProperty>( + reference_value, iv); + } + /* TODO Additional properties go here, for example: if (boost::iequals(property_type, "BilinearTemperaturePressure")) { diff --git a/MaterialLib/MPL/Medium.h b/MaterialLib/MPL/Medium.h index 49c5eeec8e00b60cae395fb50d4ca3bfc83759fa..1bd7dad7a7f1def5a3bbde719997e678502d8305 100644 --- a/MaterialLib/MPL/Medium.h +++ b/MaterialLib/MPL/Medium.h @@ -62,19 +62,19 @@ public: template <typename T> T dValue(PropertyType const p, VariableArray const& variable_array, - Variables const variables) const + Variable const variable) const { - return property(p).template dValue<T>(variable_array, variables); + return property(p).template dValue<T>(variable_array, variable); } template <typename T> T d2Value(PropertyType const p, VariableArray const& variable_array, - Variables const variables1, - Variables const variables2) const + Variable const variable1, + Variable const variable2) const { - return property(p).template d2Value<T>(variable_array, variables1, - variables2); + return property(p).template d2Value<T>(variable_array, variable1, + variable2); } private: diff --git a/MaterialLib/MPL/Properties/LinearProperty.cpp b/MaterialLib/MPL/Properties/LinearProperty.cpp index a50d4aab9b909247e26945521c40970c9e7eab7a..a55af89e615b459a3914676cb952307ccdc536d9 100644 --- a/MaterialLib/MPL/Properties/LinearProperty.cpp +++ b/MaterialLib/MPL/Properties/LinearProperty.cpp @@ -25,12 +25,13 @@ PropertyDataType LinearProperty::value( { return boost::get<double>(_value) + boost::get<double>(_independent_variable.slope) * - (boost::get<double>(variable_array[_independent_variable.type]) - + (boost::get<double>(variable_array[static_cast<int>( + _independent_variable.type)]) - boost::get<double>(_independent_variable.reference_condition)); } PropertyDataType LinearProperty::dValue(VariableArray const& /*variable_array*/, - Variables const primary_variable) const + Variable const primary_variable) const { return _independent_variable.type == primary_variable ? _independent_variable.slope @@ -39,8 +40,8 @@ PropertyDataType LinearProperty::dValue(VariableArray const& /*variable_array*/, PropertyDataType LinearProperty::d2Value( VariableArray const& /*variable_array*/, - Variables const /*pv1*/, - Variables const /*pv2*/) const + Variable const /*pv1*/, + Variable const /*pv2*/) const { return decltype(_value){}; } diff --git a/MaterialLib/MPL/Properties/LinearProperty.h b/MaterialLib/MPL/Properties/LinearProperty.h index e2985dd736df4cfbec809392a3911f21c1fde30c..7ba5ebe49d31bbdc12f8aea2ebb46b7ba0e6bce6 100644 --- a/MaterialLib/MPL/Properties/LinearProperty.h +++ b/MaterialLib/MPL/Properties/LinearProperty.h @@ -18,7 +18,7 @@ namespace MaterialPropertyLib struct IndependentVariable { - Variables type; + Variable type; VariableType reference_condition; // scalar or vector VariableType slope; // scalar or matrix }; @@ -40,12 +40,12 @@ public: /// This method will compute the derivative of a property with respect to /// the given primary variable. PropertyDataType dValue(VariableArray const& variable_array, - Variables const primary_variable) const override; + Variable const primary_variable) const override; /// This method will compute the second derivative of a /// property with respect to the given primary variables pv1 and pv2. PropertyDataType d2Value(VariableArray const& variable_array, - Variables const pv1, - Variables const pv2) const override; + Variable const pv1, + Variable const pv2) const override; private: IndependentVariable const _independent_variable; diff --git a/MaterialLib/MPL/Property.cpp b/MaterialLib/MPL/Property.cpp index 53c0e46c072f6b7c2f927788345b0b2bf367bf80..10fca184d674b4f0309c5a6dbc3deb3e5d9fd79f 100644 --- a/MaterialLib/MPL/Property.cpp +++ b/MaterialLib/MPL/Property.cpp @@ -32,15 +32,15 @@ PropertyDataType Property::value(VariableArray const& /*variable_array*/) const /// The default implementation of this method only returns the /// property value derivative without altering it. PropertyDataType Property::dValue(VariableArray const& /*variable_array*/, - Variables const /*variables*/) const + Variable const /*variable*/) const { return _dvalue; } /// Default implementation: 2nd derivative of any constant property is zero. PropertyDataType Property::d2Value(VariableArray const& /*variable_array*/, - Variables const /*variables*/, - Variables const /*variables*/) const + Variable const /*variable*/, + Variable const /*variable*/) const { return 0.0; } diff --git a/MaterialLib/MPL/Property.h b/MaterialLib/MPL/Property.h index cc8f9c45f610d17d772043e5f300a37427aa122c..a086887db94e31532cf2653504c9b04d9e838e2b 100644 --- a/MaterialLib/MPL/Property.h +++ b/MaterialLib/MPL/Property.h @@ -55,14 +55,14 @@ public: /// variables that are passed as arguments. virtual PropertyDataType value(VariableArray const& variable_array) const; /// This virtual method will compute the derivative of a property - /// with respect to the given variables pv. + /// with respect to the given variable pv. virtual PropertyDataType dValue(VariableArray const& variable_array, - Variables const variables) const; + Variable const variable) const; /// This virtual method will compute the second derivative of a /// property with respect to the given variables pv1 and pv2. virtual PropertyDataType d2Value(VariableArray const& variable_array, - Variables const variables1, - Variables const variables2) const; + Variable const variable1, + Variable const variable2) const; template <typename T> T value() const @@ -76,16 +76,16 @@ public: } template <typename T> T dValue(VariableArray const& variable_array, - Variables const variables) const + Variable const variable) const { - return boost::get<T>(dValue(variable_array, variables)); + return boost::get<T>(dValue(variable_array, variable)); } template <typename T> T d2Value(VariableArray const& variable_array, - Variables const& variables1, - Variables const& variables2) const + Variable const& variable1, + Variable const& variable2) const { - return boost::get<T>(d2Value(variable_array, variables1, variables2)); + return boost::get<T>(d2Value(variable_array, variable1, variable2)); } protected: diff --git a/MaterialLib/MPL/VariableType.cpp b/MaterialLib/MPL/VariableType.cpp new file mode 100644 index 0000000000000000000000000000000000000000..37086e0b74f55ca8f7ac39a70b0a7414124631b2 --- /dev/null +++ b/MaterialLib/MPL/VariableType.cpp @@ -0,0 +1,51 @@ +/** + * \file + * + * \copyright + * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#include "VariableType.h" +#include <boost/algorithm/string/predicate.hpp> +#include "BaseLib/Error.h" + +namespace MaterialPropertyLib +{ +Variable convertStringToVariable(std::string const& input) +{ + if (boost::iequals(input, "phase_pressure")) + { + return Variable::phase_pressure; + } + if (boost::iequals(input, "capillary_pressure")) + { + return Variable::capillary_pressure; + } + if (boost::iequals(input, "density")) + { + return Variable::density; + } + if (boost::iequals(input, "temperature")) + { + return Variable::temperature; + } + if (boost::iequals(input, "liquid_saturation")) + { + return Variable::liquid_saturation; + } + if (boost::iequals(input, "displacement")) + { + return Variable::displacement; + } + + OGS_FATAL( + "The variable name '%s' does not correspond to any known variable", + input.c_str()); + + return Variable::number_of_variables; // to avoid the 'no return' warning +} +} // namespace MaterialPropertyLib diff --git a/MaterialLib/MPL/VariableType.h b/MaterialLib/MPL/VariableType.h index 539a94ca036e7b01210de8626904db1d1c456e7f..7ac721108cc6776bf5305eefe2f8b508c74aaa7e 100644 --- a/MaterialLib/MPL/VariableType.h +++ b/MaterialLib/MPL/VariableType.h @@ -34,18 +34,17 @@ using SymmTensor = std::array<double, 6>; /// tensor components. using Tensor = std::array<double, 9>; -/// Variables is simply a list of all commonly used variables that are used to -/// determine the size of the VariableArray. If the variable of your choice is -/// missing, simply add it somewhere at the list, but above the last entry. -enum Variables : int +/// Enum Variable is simply a list of all commonly used variables that are used +/// to determine the size of the VariableArray. If the variable of your choice +/// is missing, simply add it somewhere at the list, but above the last entry. +enum class Variable : int { phase_pressure, capillary_pressure, - gas_density, - liquid_density, + density, temperature, liquid_saturation, - u, + displacement, number_of_variables }; @@ -54,13 +53,16 @@ enum Variables : int using VariableType = boost::variant<double, Vector>; /// The VariableArray is a std::array of fixed size. Its size is determined by -/// the Variables enumerator list. Data type of that array is defined by the +/// the Variable enumerator list. Data type of that array is defined by the /// VariableType definition. -using VariableArray = std::array<VariableType, Variables::number_of_variables>; +using VariableArray = + std::array<VariableType, static_cast<int>(Variable::number_of_variables)>; /// This method returns a value of type double from the variables array inline double getScalar(VariableType pv) { return boost::get<double>(pv); } + +Variable convertStringToVariable(std::string const& input); } // namespace MaterialPropertyLib diff --git a/Tests/MaterialLib/TestMPLLinearProperty.cpp b/Tests/MaterialLib/TestMPLLinearProperty.cpp index 27dc0ddd63e878812ecdf85c2ead8c0f05ca43d7..16e19e7c43b97235ae5930986cae66b468b5ed06 100644 --- a/Tests/MaterialLib/TestMPLLinearProperty.cpp +++ b/Tests/MaterialLib/TestMPLLinearProperty.cpp @@ -18,29 +18,28 @@ TEST(MaterialPropertyLib, LinearProperty) double const m = 1.0; double const x_ref = 293.15; MaterialPropertyLib::IndependentVariable const iv{ - MaterialPropertyLib::Variables::temperature, x_ref, m}; + MaterialPropertyLib::Variable::temperature, x_ref, m}; MaterialPropertyLib::LinearProperty linear_property{y_ref, iv}; MaterialPropertyLib::VariableArray variable_array; - variable_array[MaterialPropertyLib::Variables::temperature] = 303.15; - ASSERT_NEAR( - boost::get<double>(linear_property.value(variable_array)), - y_ref + m * (boost::get<double>( - variable_array - [MaterialPropertyLib::Variables::temperature]) - - x_ref), - 1.e-10); + variable_array[static_cast<int>( + MaterialPropertyLib::Variable::temperature)] = 303.15; + ASSERT_NEAR(boost::get<double>(linear_property.value(variable_array)), + y_ref + m * (boost::get<double>(variable_array[static_cast<int>( + MaterialPropertyLib::Variable::temperature)]) - + x_ref), + 1.e-10); ASSERT_EQ( boost::get<double>(linear_property.dValue( - variable_array, MaterialPropertyLib::Variables::phase_pressure)), + variable_array, MaterialPropertyLib::Variable::phase_pressure)), 0.0); ASSERT_EQ(boost::get<double>(linear_property.dValue( - variable_array, MaterialPropertyLib::Variables::temperature)), + variable_array, MaterialPropertyLib::Variable::temperature)), m); ASSERT_EQ(boost::get<double>(linear_property.d2Value( variable_array, - MaterialPropertyLib::Variables::temperature, - MaterialPropertyLib::Variables::temperature)), + MaterialPropertyLib::Variable::temperature, + MaterialPropertyLib::Variable::temperature)), 0.0); }