Skip to content

Commit f807a01

Browse files
committed
[Test] Add thermo consistency tests for compressibility functions
Add finite difference checks for `isothermalCompressibility` and `thermalExpansionCoeff` for thermo models.
1 parent 2ce92ea commit f807a01

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/thermo/consistency.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class TestConsistency : public testing::TestWithParam<std::tuple<AnyMap, AnyMap>
7474
atol = setup.getDouble("atol", 1e-5);
7575
rtol_fd = setup.getDouble("rtol_fd", 1e-6);
7676
atol_v = setup.getDouble("atol_v", 1e-11);
77+
atol_c = setup.getDouble("atol_c", 1e-14);
78+
atol_e = setup.getDouble("atol_e", 1e-18);
7779

7880
phase = cache[key];
7981
phase->setState(state);
@@ -104,6 +106,8 @@ class TestConsistency : public testing::TestWithParam<std::tuple<AnyMap, AnyMap>
104106
double T, p, RT;
105107
double atol; // absolute tolerance for molar energy comparisons
106108
double atol_v; // absolute tolerance for molar volume comparisons
109+
double atol_c; // absolute tolerance for compressibility comparison
110+
double atol_e; // absolute tolerance for expansion comparison
107111
double rtol_fd; // relative tolerance for finite difference comparisons
108112
};
109113

@@ -345,6 +349,58 @@ TEST_P(TestConsistency, dSdv_const_T_eq_dPdT_const_V) {
345349
}
346350
}
347351

352+
TEST_P(TestConsistency, betaT_eq_minus_dmv_dP_const_T_div_mv)
353+
{
354+
double betaT1;
355+
try {
356+
betaT1 = phase->isothermalCompressibility();
357+
} catch (NotImplementedError& err) {
358+
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
359+
}
360+
361+
double T = phase->temperature();
362+
double P1 = phase->pressure();
363+
double mv1 = phase->molarVolume();
364+
365+
double P2 = P1 * (1 + 1e-6);
366+
phase->setState_TP(T, P2);
367+
double betaT2 = phase->isothermalCompressibility();
368+
double mv2 = phase->molarVolume();
369+
370+
double betaT_mid = 0.5 * (betaT1 + betaT2);
371+
double mv_mid = 0.5 * (mv1 + mv2);
372+
double betaT_fd = -1 / mv_mid * (mv2 - mv1) / (P2 - P1);
373+
374+
EXPECT_NEAR(betaT_fd, betaT_mid,
375+
max({rtol_fd * betaT_mid, rtol_fd * betaT_fd, atol_c}));
376+
}
377+
378+
TEST_P(TestConsistency, alphaV_eq_dmv_dT_const_P_div_mv)
379+
{
380+
double alphaV1;
381+
try {
382+
alphaV1 = phase->thermalExpansionCoeff();
383+
} catch (NotImplementedError& err) {
384+
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
385+
}
386+
387+
double P = phase->pressure();
388+
double T1 = phase->temperature();
389+
double mv1 = phase->molarVolume();
390+
391+
double T2 = T1 * (1 + 1e-6);
392+
phase->setState_TP(T2, P);
393+
double alphaV2 = phase->thermalExpansionCoeff();
394+
double mv2 = phase->molarVolume();
395+
396+
double alphaV_mid = 0.5 * (alphaV1 + alphaV2);
397+
double mv_mid = 0.5 * (mv1 + mv2);
398+
double alphaV_fd = 1 / mv_mid * (mv2 - mv1) / (T2 - T1);
399+
400+
EXPECT_NEAR(alphaV_fd, alphaV_mid,
401+
max({rtol_fd * alphaV_mid, rtol_fd * alphaV_fd, atol_e}));
402+
}
403+
348404
// ---------- Tests for consistency of standard state properties ---------------
349405

350406
TEST_P(TestConsistency, hk0_eq_uk0_plus_p_vk0)

0 commit comments

Comments
 (0)