Skip to content

Commit

Permalink
Add unit tests for the new variable cp option
Browse files Browse the repository at this point in the history
refs #21245
Update regression test as cp expression changed
  • Loading branch information
GiudGiud committed Jan 4, 2025
1 parent 8842af4 commit ff25cfe
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
time,cp_avg,cv_diff,e_diff,h_avg,k_diff,mu_diff,rho_diff
0,0,0,0,0,0,0,0
1,3999.9944970494,0,0,1600065.0618087,0,0,0
1,4000.0190768956,0,0,1600065.0618087,0,0,0
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ class TemperaturePressureFunctionFluidPropertiesTest : public MooseObjectUnitTes
params.set<std::string>("_object_name") = "mu_function";
_fe_problem->addFunction("ParsedFunction", "mu_function", params);

params.set<std::string>("expression") = "3000. + 3*x + 5e-4*y";
params.set<std::string>("_object_name") = "cp_function";
_fe_problem->addFunction("ParsedFunction", "cp_function", params);

_fe_problem->getFunction("k_function").initialSetup();
_fe_problem->getFunction("rho_function").initialSetup();
_fe_problem->getFunction("mu_function").initialSetup();
_fe_problem->getFunction("cp_function").initialSetup();

buildObjects();
}
Expand All @@ -55,7 +60,21 @@ class TemperaturePressureFunctionFluidPropertiesTest : public MooseObjectUnitTes

_fe_problem->addUserObject("TemperaturePressureFunctionFluidProperties", "fp", uo_params);
_fp = &_fe_problem->getUserObject<TemperaturePressureFunctionFluidProperties>("fp");

InputParameters uo_params2 =
_factory.getValidParams("TemperaturePressureFunctionFluidProperties");
// Set the three functions and the specific isobaric heat capacity
uo_params2.set<FunctionName>("k") = "k_function";
uo_params2.set<FunctionName>("rho") = "rho_function";
uo_params2.set<FunctionName>("mu") = "mu_function";
uo_params2.set<FunctionName>("cp") = "cp_function";
uo_params2.set<Real>("T_initial_guess") = 250;
uo_params2.set<Real>("p_initial_guess") = 1e7;

_fe_problem->addUserObject("TemperaturePressureFunctionFluidProperties", "fp_cp", uo_params2);
_fp_cp = &_fe_problem->getUserObject<TemperaturePressureFunctionFluidProperties>("fp_cp");
}

TemperaturePressureFunctionFluidProperties * _fp;
TemperaturePressureFunctionFluidProperties * _fp_cp;
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ TEST_F(TemperaturePressureFunctionFluidPropertiesTest, fluidName)
}

/**
* Verify calculation of the fluid properties
* Verify calculation of the fluid properties with a constant cv
*/
TEST_F(TemperaturePressureFunctionFluidPropertiesTest, properties)
TEST_F(TemperaturePressureFunctionFluidPropertiesTest, properties_constant_cv)
{
const Real cv = 4186.0;

Expand All @@ -38,9 +38,11 @@ TEST_F(TemperaturePressureFunctionFluidPropertiesTest, properties)
Real thermal_cond = 14 + 2e-2 * T + 3e-5 * p;
Real visc = 1e-3 + 1e-5 * T - 3e-9 * p;
Real density = 1 / v;
Real dv_dT = -1 / density / density * 2.5;
Real cp = cv + p * dv_dT;
Real alpha = -1. / density * 2.5;
Real beta = -1. / density * 32e-5;
Real cp = cv + MathUtils::pow(alpha, 2) * T / density / beta;

// Testing the properties with a constant cv
ABS_TEST(_fp->cp_from_p_T(p, T), cp, tol);
ABS_TEST(_fp->cv_from_p_T(p, T), cv, tol);
ABS_TEST(_fp->k_from_p_T(p, T), thermal_cond, tol);
Expand Down Expand Up @@ -73,8 +75,9 @@ TEST_F(TemperaturePressureFunctionFluidPropertiesTest, properties)
thermal_cond = 14 + 2e-2 * T + 3e-5 * p;
visc = 1e-3 + 1e-5 * T - 3e-9 * p;
density = 1 / v;
dv_dT = -1 / density / density * 2.5;
cp = cv + p * dv_dT;
alpha = -1. / density * 2.5;
beta = -1. / density * 32e-5;
cp = cv + MathUtils::pow(alpha, 2) * T / density / beta;

ABS_TEST(_fp->cp_from_p_T(p, T), cp, tol);
ABS_TEST(_fp->cv_from_p_T(p, T), cv, tol);
Expand All @@ -98,16 +101,105 @@ TEST_F(TemperaturePressureFunctionFluidPropertiesTest, properties)
ABS_TEST(_fp->mu_from_v_e(v, e), visc, tol);
}

/**
* Verify calculation of the fluid properties with a function cp
*/
TEST_F(TemperaturePressureFunctionFluidPropertiesTest, properties_function_cp)
{
const Real tol = REL_TOL_CONSISTENCY;
// Simpson integration only does 1e-5
const Real simpson_tol = 2e5 * tol;
// any property post using Simpson to compute 'e'
const Real large_tol = 100 * tol;

{
Real p = 8.56E7;
Real T = 200.0;
Real cp = 3000. + 3 * T + 5e-4 * p;
Real e = 9220000.4605;
Real v = 1 / (1400 + 2.5 * T + 32e-5 * p);
Real h = e + p * v;

// See header for expressions
Real thermal_cond = 14 + 2e-2 * T + 3e-5 * p;
Real visc = 1e-3 + 1e-5 * T - 3e-9 * p;
Real density = 1 / v;
Real alpha = -1. / density * 2.5;
Real beta = -1. / density * 32e-5;
Real cv = cp - MathUtils::pow(alpha, 2) * T / density / beta;

ABS_TEST(_fp_cp->cp_from_p_T(p, T), cp, tol);
ABS_TEST(_fp_cp->cv_from_p_T(p, T), cv, tol);
ABS_TEST(_fp_cp->k_from_p_T(p, T), thermal_cond, tol);
ABS_TEST(_fp_cp->k_from_p_T(p, T), thermal_cond, tol);
ABS_TEST(_fp_cp->rho_from_p_T(p, T), density, tol);
ABS_TEST(_fp_cp->v_from_p_T(p, T), 1 / density, tol);
ABS_TEST(_fp_cp->e_from_p_T(p, T), e, simpson_tol);
ABS_TEST(_fp_cp->e_from_p_rho(p, 1. / v), e, simpson_tol);
ABS_TEST(_fp_cp->mu_from_p_T(p, T), visc, tol);
ABS_TEST(_fp_cp->h_from_p_T(p, T), h, simpson_tol);
ABS_TEST(_fp_cp->cp_from_v_e(v, e), cp, large_tol);
ABS_TEST(_fp_cp->cv_from_v_e(v, e), cv, large_tol);
ABS_TEST(_fp_cp->k_from_v_e(v, e), thermal_cond, large_tol);
ABS_TEST(_fp_cp->T_from_v_e(v, e), T, large_tol);
ABS_TEST(_fp_cp->T_from_p_h(p, _fp_cp->h_from_p_T(p, T)), T, large_tol);
ABS_TEST(_fp_cp->T_from_p_rho(p, 1. / v), T, large_tol);
ABS_TEST(_fp_cp->p_from_v_e(v, e),
p,
1.5 * simpson_tol); // uses a Newton solve for variable set inversion
ABS_TEST(_fp_cp->mu_from_v_e(v, e), visc, large_tol);
}

{
Real p = 1.06841E8;
Real T = 300.0;
Real cp = 3000. + 3 * T + 5e-4 * p;
Real e = 17061150.67487172;
Real v = 1 / (1400 + 2.5 * T + 32e-5 * p);
Real h = e + p * v;

// See header for expressions
Real thermal_cond = 14 + 2e-2 * T + 3e-5 * p;
Real visc = 1e-3 + 1e-5 * T - 3e-9 * p;
Real density = 1 / v;
Real alpha = -1. / density * 2.5;
Real beta = -1. / density * 32e-5;
Real cv = cp - MathUtils::pow(alpha, 2) * T / density / beta;

ABS_TEST(_fp_cp->cp_from_p_T(p, T), cp, tol);
ABS_TEST(_fp_cp->cv_from_p_T(p, T), cv, tol);
ABS_TEST(_fp_cp->k_from_p_T(p, T), thermal_cond, tol);
ABS_TEST(_fp_cp->k_from_p_T(p, T), thermal_cond, tol);
ABS_TEST(_fp_cp->rho_from_p_T(p, T), density, tol);
ABS_TEST(_fp_cp->v_from_p_T(p, T), 1 / density, tol);
ABS_TEST(_fp_cp->e_from_p_T(p, T), e, simpson_tol);
ABS_TEST(_fp_cp->e_from_p_rho(p, 1. / v), e, simpson_tol);
ABS_TEST(_fp_cp->mu_from_p_T(p, T), visc, tol);
ABS_TEST(_fp_cp->h_from_p_T(p, T), h, simpson_tol);
ABS_TEST(_fp_cp->cp_from_v_e(v, e), cp, 1.5 * large_tol);
ABS_TEST(_fp_cp->cv_from_v_e(v, e), cv, 1.5 * large_tol);
ABS_TEST(_fp_cp->k_from_v_e(v, e), thermal_cond, large_tol);
ABS_TEST(_fp_cp->T_from_v_e(v, e), T, 1.5 * large_tol);
ABS_TEST(_fp_cp->T_from_p_h(p, _fp_cp->h_from_p_T(p, T)), T, large_tol);
ABS_TEST(_fp_cp->T_from_p_rho(p, 1. / v), T, large_tol);
ABS_TEST(_fp_cp->p_from_v_e(v, e),
p,
10 * simpson_tol); // uses a Newton solve for variable set inversion
ABS_TEST(_fp_cp->mu_from_v_e(v, e), visc, large_tol);
}
}

/**
* Verify calculation of the derivatives by comparing with finite
* differences
*/
TEST_F(TemperaturePressureFunctionFluidPropertiesTest, derivatives)
{
const Real tol = REL_TOL_DERIVATIVE;
const Real large_tol = 30 * tol;
// Finite difference just does not get much
const Real large_tol = 1000 * tol;

// p, T and v,e are not consistent here but that's ok
// p, T and v, e are not consistent here but that's ok
Real p = 1.0E7;
Real T = 10.0;
Real e = 8.372E5;
Expand All @@ -120,13 +212,28 @@ TEST_F(TemperaturePressureFunctionFluidPropertiesTest, derivatives)
DERIV_TEST(_fp->e_from_p_T, p, T, tol);
DERIV_TEST(_fp->h_from_p_T, p, T, tol);
DERIV_TEST(_fp->k_from_p_T, p, T, tol);
DERIV_TEST(_fp->cp_from_p_T, p, T, large_tol); // uses finite differencing
DERIV_TEST(_fp->cp_from_p_T, p, T, 4 * large_tol); // uses finite differencing
DERIV_TEST(_fp->cv_from_p_T, p, T, tol);
DERIV_TEST(_fp->cp_from_v_e, v, e, large_tol); // uses finite differencing
DERIV_TEST(_fp->cv_from_v_e, v, e, tol);

e = 80150;
v = 2.16216E-4;

AD_DERIV_TEST(_fp_cp->rho_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->rho_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->v_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->mu_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->e_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->h_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->k_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->cp_from_p_T, p, T, large_tol); // uses finite differencing
DERIV_TEST(_fp_cp->cv_from_p_T, p, T, large_tol);
DERIV_TEST(_fp_cp->cp_from_v_e, v, e, large_tol); // uses finite differencing
DERIV_TEST(_fp_cp->cv_from_v_e, v, e, large_tol);

p = 5.0E7;
T = 90.0;
T = 190.0;
e = 1.6744E6;
v = 6.25E-4;

Expand All @@ -137,10 +244,25 @@ TEST_F(TemperaturePressureFunctionFluidPropertiesTest, derivatives)
DERIV_TEST(_fp->e_from_p_T, p, T, tol);
DERIV_TEST(_fp->h_from_p_T, p, T, tol);
DERIV_TEST(_fp->k_from_p_T, p, T, tol);
DERIV_TEST(_fp->cp_from_p_T, p, T, large_tol); // uses finite differencing
DERIV_TEST(_fp->cp_from_p_T, p, T, 2 * large_tol); // uses finite differencing
DERIV_TEST(_fp->cv_from_p_T, p, T, tol);
DERIV_TEST(_fp->cp_from_v_e, v, e, large_tol); // uses finite differencing
DERIV_TEST(_fp->cp_from_v_e, v, e, 2 * large_tol); // uses finite differencing
DERIV_TEST(_fp->cv_from_v_e, v, e, tol);

e = 5.37415e+06;
v = 5.59441e-05;

AD_DERIV_TEST(_fp_cp->rho_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->rho_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->v_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->mu_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->e_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->h_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->k_from_p_T, p, T, tol);
DERIV_TEST(_fp_cp->cp_from_p_T, p, T, large_tol); // uses finite differencing
DERIV_TEST(_fp_cp->cv_from_p_T, p, T, large_tol);
DERIV_TEST(_fp_cp->cp_from_v_e, v, e, large_tol); // uses finite differencing
DERIV_TEST(_fp_cp->cv_from_v_e, v, e, large_tol);
}

/**
Expand Down

0 comments on commit ff25cfe

Please sign in to comment.