Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPL; Pass dt to property evaluations #2801

Merged
merged 3 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions MaterialLib/MPL/Components/GetThermalExpansivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ class Phase;
double getThermalExpansivity(Phase const& phase, VariableArray const& vars,
const double density,
ParameterLib::SpatialPosition const& pos,
double const t)
double const t, double const dt)
{
auto const thermal_expansivity_ptr =
&phase.property(MaterialPropertyLib::PropertyType::thermal_expansivity);

// The thermal expansivity is explicitly given in the project file.
if (thermal_expansivity_ptr)
{
return (*thermal_expansivity_ptr).template value<double>(vars, pos, t);
return (*thermal_expansivity_ptr)
.template value<double>(vars, pos, t, dt);
}

// The thermal expansivity calculated by the density model directly.
Expand All @@ -38,7 +39,7 @@ double getThermalExpansivity(Phase const& phase, VariableArray const& vars,
: -phase.property(MaterialPropertyLib::PropertyType::density)
.template dValue<double>(
vars, MaterialPropertyLib::Variable::temperature,
pos, t) /
pos, t, dt) /
density;
}
} // namespace MaterialPropertyLib
2 changes: 1 addition & 1 deletion MaterialLib/MPL/Components/GetThermalExpansivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ class Phase;
double getThermalExpansivity(Phase const& phase, VariableArray const& vars,
const double density,
ParameterLib::SpatialPosition const& pos,
double const t);
double const t, double const dt);
} // namespace MaterialPropertyLib
10 changes: 6 additions & 4 deletions MaterialLib/MPL/Properties/ExponentialProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ ExponentialProperty::ExponentialProperty(

PropertyDataType ExponentialProperty::value(
VariableArray const& variable_array,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const
ParameterLib::SpatialPosition const& /*pos*/, double const /*t*/,
double const /*dt*/) const
{
return std::get<double>(_value) *
std::exp(
Expand All @@ -37,7 +37,8 @@ PropertyDataType ExponentialProperty::value(

PropertyDataType ExponentialProperty::dValue(
VariableArray const& variable_array, Variable const primary_variable,
ParameterLib::SpatialPosition const& /*pos*/, double const /*t*/) const
ParameterLib::SpatialPosition const& /*pos*/, double const /*t*/,
double const /*dt*/) const
{
return _exponent_data.type == primary_variable
? -std::get<double>(_value) *
Expand All @@ -52,7 +53,8 @@ PropertyDataType ExponentialProperty::dValue(

PropertyDataType ExponentialProperty::d2Value(
VariableArray const& variable_array, Variable const pv1, Variable const pv2,
ParameterLib::SpatialPosition const& /*pos*/, double const /*t*/) const
ParameterLib::SpatialPosition const& /*pos*/, double const /*t*/,
double const /*dt*/) const
{
return _exponent_data.type == pv1 && _exponent_data.type == pv2
? std::get<double>(_value) *
Expand Down
11 changes: 6 additions & 5 deletions MaterialLib/MPL/Properties/ExponentialProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,21 @@ class ExponentialProperty final : public Property
/// exponentialy on the value of the given primary variable \f$\beta\f$.
PropertyDataType value(VariableArray const& variable_array,
ParameterLib::SpatialPosition const& pos,
double const t) const override;
double const t, double const dt) const override;
/// This method will compute the derivative of a property with respect
/// to the given primary variable.
PropertyDataType dValue(VariableArray const& variable_array,
Variable const primary_variable,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const override;
double const /*t*/,
double const /*dt*/) 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,
Variable const pv1,
Variable const pv2,
Variable const pv1, Variable const pv2,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const override;
double const /*t*/,
double const /*dt*/) const override;

private:
ExponentData const _exponent_data;
Expand Down
22 changes: 13 additions & 9 deletions MaterialLib/MPL/Properties/IdealGasLaw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ namespace MaterialPropertyLib
{
double molarMass(Phase* _phase, Component* _component,
VariableArray const& variable_array,
ParameterLib::SpatialPosition const& pos, double const t)
ParameterLib::SpatialPosition const& pos, double const t,
double const dt)
{
if (_phase) // IdealGasLaw of an entire phase
{
return _phase->property(PropertyType::molar_mass)
.template value<double>(variable_array, pos, t);
.template value<double>(variable_array, pos, t, dt);
}
if (_component) // IdealGasLaw of a single component
{
return _component->property(PropertyType::molar_mass)
.template value<double>(variable_array, pos, t);
.template value<double>(variable_array, pos, t, dt);
}
OGS_FATAL(
"Neither a phase nor a component are set for retrieving molar "
Expand All @@ -42,14 +43,15 @@ double molarMass(Phase* _phase, Component* _component,

PropertyDataType IdealGasLaw::value(VariableArray const& variable_array,
ParameterLib::SpatialPosition const& pos,
double const t) const
double const t, double const dt) const
{
const double gas_constant = MaterialLib::PhysicalConstant::IdealGasConstant;
const double pressure = std::get<double>(
variable_array[static_cast<int>(Variable::phase_pressure)]);
const double temperature = std::get<double>(
variable_array[static_cast<int>(Variable::temperature)]);
double molar_mass = molarMass(_phase, _component, variable_array, pos, t);
double molar_mass =
molarMass(_phase, _component, variable_array, pos, t, dt);

const double density = pressure * molar_mass / gas_constant / temperature;

Expand All @@ -59,14 +61,15 @@ PropertyDataType IdealGasLaw::value(VariableArray const& variable_array,
PropertyDataType IdealGasLaw::dValue(VariableArray const& variable_array,
Variable const primary_variable,
ParameterLib::SpatialPosition const& pos,
double const t) const
double const t, double const dt) const
{
const double gas_constant = MaterialLib::PhysicalConstant::IdealGasConstant;
const double pressure = std::get<double>(
variable_array[static_cast<int>(Variable::phase_pressure)]);
const double temperature = std::get<double>(
variable_array[static_cast<int>(Variable::temperature)]);
double molar_mass = molarMass(_phase, _component, variable_array, pos, t);
double molar_mass =
molarMass(_phase, _component, variable_array, pos, t, dt);

if (primary_variable == Variable::temperature)
{
Expand All @@ -90,14 +93,15 @@ PropertyDataType IdealGasLaw::d2Value(VariableArray const& variable_array,
Variable const primary_variable1,
Variable const primary_variable2,
ParameterLib::SpatialPosition const& pos,
double const t) const
double const t, double const dt) const
{
const double gas_constant = MaterialLib::PhysicalConstant::IdealGasConstant;
const double pressure = std::get<double>(
variable_array[static_cast<int>(Variable::phase_pressure)]);
const double temperature = std::get<double>(
variable_array[static_cast<int>(Variable::temperature)]);
double molar_mass = molarMass(_phase, _component, variable_array, pos, t);
double molar_mass =
molarMass(_phase, _component, variable_array, pos, t, dt);

if ((primary_variable1 == Variable::phase_pressure) &&
(primary_variable2 == Variable::phase_pressure))
Expand Down
11 changes: 6 additions & 5 deletions MaterialLib/MPL/Properties/IdealGasLaw.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,17 @@ class IdealGasLaw final : public Property
/// actually compute and set the property _values and _dValues.
PropertyDataType value(VariableArray const& variable_array,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const override;
double const /*t*/,
double const /*dt*/) const override;
PropertyDataType dValue(VariableArray const& variable_array,
Variable const variable,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const override;
double const /*t*/,
double const /*dt*/) const override;
PropertyDataType d2Value(VariableArray const& variable_array,
Variable const variable1,
Variable const variable2,
Variable const variable1, Variable const variable2,
ParameterLib::SpatialPosition const& pos,
double const t) const override;
double const t, double const dt) const override;

private:
Phase* _phase = nullptr;
Expand Down
19 changes: 8 additions & 11 deletions MaterialLib/MPL/Properties/LinearProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ LinearProperty::LinearProperty(PropertyDataType const& property_reference_value,

PropertyDataType LinearProperty::value(
VariableArray const& variable_array,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const
ParameterLib::SpatialPosition const& /*pos*/, double const /*t*/,
double const /*dt*/) const
{
auto calculate_linearized_ratio = [&variable_array](
double const initial_linearized_ratio,
Expand All @@ -46,10 +46,9 @@ PropertyDataType LinearProperty::value(
}

PropertyDataType LinearProperty::dValue(
VariableArray const& /*variable_array*/,
Variable const primary_variable,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const
VariableArray const& /*variable_array*/, Variable const primary_variable,
ParameterLib::SpatialPosition const& /*pos*/, double const /*t*/,
double const /*dt*/) const
{
auto const independent_variable =
std::find_if(_independent_variables.begin(),
Expand All @@ -65,11 +64,9 @@ PropertyDataType LinearProperty::dValue(
}

PropertyDataType LinearProperty::d2Value(
VariableArray const& /*variable_array*/,
Variable const /*pv1*/,
Variable const /*pv2*/,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const
VariableArray const& /*variable_array*/, Variable const /*pv1*/,
Variable const /*pv2*/, ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/, double const /*dt*/) const
{
return decltype(_value){};
}
Expand Down
12 changes: 7 additions & 5 deletions MaterialLib/MPL/Properties/LinearProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,24 @@ class LinearProperty final : public Property
/// the value of the given primary variable.
PropertyDataType value(VariableArray const& variable_array,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const override;
double const /*t*/,
double const /*dt*/) const override;

/// This method will compute the derivative of a property with respect to
/// the given primary variable.
PropertyDataType dValue(VariableArray const& variable_array,
Variable const primary_variable,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const override;
double const /*t*/,
double const /*dt*/) 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,
Variable const pv1,
Variable const pv2,
Variable const pv1, Variable const pv2,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const override;
double const /*t*/,
double const /*dt*/) const override;

private:
std::vector<IndependentVariable> const _independent_variables;
Expand Down
16 changes: 7 additions & 9 deletions MaterialLib/MPL/Properties/ParameterProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,25 @@ ParameterProperty::ParameterProperty(

PropertyDataType ParameterProperty::value(
VariableArray const& /*variable_array*/,
ParameterLib::SpatialPosition const& pos,
double const t) const
ParameterLib::SpatialPosition const& pos, double const t,
double const /*dt*/) const
{
return fromVector(_parameter(t, pos));
}

PropertyDataType ParameterProperty::dValue(
VariableArray const& /*variable_array*/,
Variable const /*primary_variable*/,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const
ParameterLib::SpatialPosition const& /*pos*/, double const /*t*/,
double const /*dt*/) const
{
return double{};
}

PropertyDataType ParameterProperty::d2Value(
VariableArray const& /*variable_array*/,
Variable const /*pv1*/,
Variable const /*pv2*/,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const
VariableArray const& /*variable_array*/, Variable const /*pv1*/,
Variable const /*pv2*/, ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/, double const /*dt*/) const
{
return double{};
}
Expand Down
11 changes: 6 additions & 5 deletions MaterialLib/MPL/Properties/ParameterProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@ class ParameterProperty final : public Property
/// the value of the given primary variable.
PropertyDataType value(VariableArray const& variable_array,
ParameterLib::SpatialPosition const& pos,
double const t) const override;
double const t, double const dt) const override;

/// This method will compute the derivative of a property with respect to
/// the given primary variable.
PropertyDataType dValue(VariableArray const& variable_array,
Variable const primary_variable,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const override;
double const /*t*/,
double const /*dt*/) 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,
Variable const pv1,
Variable const pv2,
Variable const pv1, Variable const pv2,
ParameterLib::SpatialPosition const& /*pos*/,
double const /*t*/) const override;
double const /*t*/,
double const /*dt*/) const override;

private:
ParameterLib::Parameter<double> const& _parameter;
Expand Down
11 changes: 6 additions & 5 deletions MaterialLib/MPL/Properties/RelPermBrooksCorey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ RelPermBrooksCorey::RelPermBrooksCorey(

PropertyDataType RelPermBrooksCorey::value(
VariableArray const& variable_array,
ParameterLib::SpatialPosition const& pos,
double const t) const
ParameterLib::SpatialPosition const& pos, double const t,
double const dt) const
{
/// here, an extra computation of saturation is forced, guaranteeing a
/// correct value. In order to speed up the computing time, saturation could
/// be insertred into the primary variable array after it is computed in the
/// FEM assembly.
auto const s_L = _medium->property(PropertyType::saturation)
.template value<double>(variable_array, pos, t);
.template value<double>(variable_array, pos, t, dt);

auto const s_L_res = _residual_liquid_saturation;
auto const s_L_max = 1. - _residual_gas_saturation;
Expand Down Expand Up @@ -73,14 +73,15 @@ PropertyDataType RelPermBrooksCorey::value(
}
PropertyDataType RelPermBrooksCorey::dValue(
VariableArray const& variable_array, Variable const primary_variable,
ParameterLib::SpatialPosition const& pos, double const t) const
ParameterLib::SpatialPosition const& pos, double const t,
double const dt) const
{
(void)primary_variable;
assert((primary_variable == Variable::liquid_saturation) &&
"RelPermBrooksCorey::dValue is implemented for "
" derivatives with respect to liquid saturation only.");
auto const s_L = _medium->property(PropertyType::saturation)
.template value<double>(variable_array, pos, t);
.template value<double>(variable_array, pos, t, dt);

auto const s_L_res = _residual_liquid_saturation;
auto const s_L_max = 1. - _residual_gas_saturation;
Expand Down
4 changes: 2 additions & 2 deletions MaterialLib/MPL/Properties/RelPermBrooksCorey.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ class RelPermBrooksCorey final : public Property
/// actually compute and set the property _values and _dValues.
PropertyDataType value(VariableArray const& variable_array,
ParameterLib::SpatialPosition const& pos,
double const t) const override;
double const t, double const dt) const override;
PropertyDataType dValue(VariableArray const& variable_array,
Variable const variable,
ParameterLib::SpatialPosition const& pos,
double const t) const override;
double const t, double const dt) const override;
};

} // namespace MaterialPropertyLib
Loading