Skip to content
Snippets Groups Projects
Commit cf7550b4 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[T/MPL] Extract common central diff derivative

parent 1de971be
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,23 @@ ...@@ -17,6 +17,23 @@
#include "MaterialLib/MPL/Properties/Density/CreateWaterVapourDensity.h" #include "MaterialLib/MPL/Properties/Density/CreateWaterVapourDensity.h"
#include "TestMPL.h" #include "TestMPL.h"
static double centralDifferencesDerivative(
double const value, double MaterialPropertyLib::VariableArray::*variable,
double const value_increment, MaterialPropertyLib::Property const& property,
MaterialPropertyLib::VariableArray variable_array, const auto& pos,
double const t, double const dt)
{
variable_array.*variable = value - value_increment;
double const value_minus =
property.template value<double>(variable_array, pos, t, dt);
variable_array.*variable = value + value_increment;
double const value_plus =
property.template value<double>(variable_array, pos, t, dt);
return 0.5 * (value_plus - value_minus) / value_increment;
}
TEST(MaterialPropertyLib, WaterVapourDensity) TEST(MaterialPropertyLib, WaterVapourDensity)
{ {
char const xml[] = char const xml[] =
...@@ -62,17 +79,9 @@ TEST(MaterialPropertyLib, WaterVapourDensity) ...@@ -62,17 +79,9 @@ TEST(MaterialPropertyLib, WaterVapourDensity)
<< "for expected water vapour density " << rho_vw_expected[i] << "for expected water vapour density " << rho_vw_expected[i]
<< " and for computed water vapour density " << rho_vw; << " and for computed water vapour density " << rho_vw;
double const dT = 1.0e-4; double const approximated_drho_wv_dT = centralDifferencesDerivative(
variable_array.temperature = T_i - dT; T_i, &MaterialPropertyLib::VariableArray::temperature, 1e-4,
double const rho_vw0 = property, variable_array, pos, t, dt);
property.template value<double>(variable_array, pos, t, dt);
variable_array.temperature = T_i + dT;
double const rho_vw1 =
property.template value<double>(variable_array, pos, t, dt);
double const approximated_drho_wv_dT =
0.5 * (rho_vw1 - rho_vw0) / dT;
double const analytic_drho_wv_dT = property.template dValue<double>( double const analytic_drho_wv_dT = property.template dValue<double>(
variable_array, MaterialPropertyLib::Variable::temperature, pos, variable_array, MaterialPropertyLib::Variable::temperature, pos,
...@@ -111,18 +120,9 @@ TEST(MaterialPropertyLib, WaterVapourDensity) ...@@ -111,18 +120,9 @@ TEST(MaterialPropertyLib, WaterVapourDensity)
<< "for expected water vapour density " << rho_vw_expected[i] << "for expected water vapour density " << rho_vw_expected[i]
<< " and for computed water vapour density " << rho_vw; << " and for computed water vapour density " << rho_vw;
double const dp = 1.0e-3; double const approximated_drho_wv_dp = centralDifferencesDerivative(
variable_array.liquid_phase_pressure = p_i - dp; p_i, &MaterialPropertyLib::VariableArray::liquid_phase_pressure,
1e-3, property, variable_array, pos, t, dt);
double const rho_vw0 =
property.template value<double>(variable_array, pos, t, dt);
variable_array.liquid_phase_pressure = p_i + dp;
double const rho_vw1 =
property.template value<double>(variable_array, pos, t, dt);
double const approximated_drho_wv_dp =
0.5 * (rho_vw1 - rho_vw0) / dp;
double const analytic_drho_wv_dp = property.template dValue<double>( double const analytic_drho_wv_dp = property.template dValue<double>(
variable_array, variable_array,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment