diff --git a/MaterialLib/MPL/Properties/LinearProperty.cpp b/MaterialLib/MPL/Properties/LinearProperty.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a50d4aab9b909247e26945521c40970c9e7eab7a --- /dev/null +++ b/MaterialLib/MPL/Properties/LinearProperty.cpp @@ -0,0 +1,48 @@ +/** + * \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 "MaterialLib/MPL/Properties/LinearProperty.h" + +namespace MaterialPropertyLib +{ +LinearProperty::LinearProperty(PropertyDataType const& property_reference_value, + IndependentVariable const& v) + : _independent_variable(v) +{ + _value = property_reference_value; +} + +PropertyDataType LinearProperty::value( + VariableArray const& variable_array) const +{ + return boost::get<double>(_value) + + boost::get<double>(_independent_variable.slope) * + (boost::get<double>(variable_array[_independent_variable.type]) - + boost::get<double>(_independent_variable.reference_condition)); +} + +PropertyDataType LinearProperty::dValue(VariableArray const& /*variable_array*/, + Variables const primary_variable) const +{ + return _independent_variable.type == primary_variable + ? _independent_variable.slope + : decltype(_value){}; +} + +PropertyDataType LinearProperty::d2Value( + VariableArray const& /*variable_array*/, + Variables const /*pv1*/, + Variables const /*pv2*/) const +{ + return decltype(_value){}; +} + +} // namespace MaterialPropertyLib diff --git a/MaterialLib/MPL/Properties/LinearProperty.h b/MaterialLib/MPL/Properties/LinearProperty.h new file mode 100644 index 0000000000000000000000000000000000000000..e2985dd736df4cfbec809392a3911f21c1fde30c --- /dev/null +++ b/MaterialLib/MPL/Properties/LinearProperty.h @@ -0,0 +1,53 @@ +/** + * \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 + * + */ +#pragma once + +#include "MaterialLib/MPL/Property.h" +#include "MaterialLib/MPL/VariableType.h" + +namespace MaterialPropertyLib +{ + +struct IndependentVariable +{ + Variables type; + VariableType reference_condition; // scalar or vector + VariableType slope; // scalar or matrix +}; + +/// The linear property class. This property calculates the linear relationship. +/// The current implementation accepts only the double datatype defined in +/// PropertyDataType. +class LinearProperty final : public Property +{ +public: + /// This constructor accepts single values of double data type defined in + /// the PropertyDataType definition and sets the protected attribute _value + /// of the base class Property to that value. + LinearProperty(PropertyDataType const& property_reference_value, + IndependentVariable const& v); + /// This method computes the value of a property depending linearly on + /// the value of the given primary variable. + PropertyDataType value(VariableArray const& variable_array) const override; + /// 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; + /// 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; + +private: + IndependentVariable const _independent_variable; +}; +} diff --git a/MaterialLib/MPL/Properties/Properties.h b/MaterialLib/MPL/Properties/Properties.h index d56c81083a7768eeca174ffcc0cbb64e6b5c7efc..8e4602a955346d3cf34bef5a0c063b08bbb8072e 100644 --- a/MaterialLib/MPL/Properties/Properties.h +++ b/MaterialLib/MPL/Properties/Properties.h @@ -13,3 +13,4 @@ #pragma once #include "Constant.h" +#include "LinearProperty.h"