Skip to content

Commit 4c155a6

Browse files
committed
[Test] Add thermo consistency tests for compressibility functions
Add finite difference checks for `isothermalCompressibility` and `thermalExpansionCoeff` for thermo models.
1 parent 0ae1375 commit 4c155a6

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

test/thermo/consistency.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,56 @@ TEST_P(TestConsistency, dSdv_const_T_eq_dPdT_const_V) {
345345
}
346346
}
347347

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

350400
TEST_P(TestConsistency, hk0_eq_uk0_plus_p_vk0)

0 commit comments

Comments
 (0)