Skip to content

Commit

Permalink
[Test] Switch real gas derivative tests to thermo consistency tests
Browse files Browse the repository at this point in the history
Removed `getIsothermalCompressibility` and `getThermalExpansionCoeff` from `PengRobinson_Test` and `RedlichKwongMFTP_Test`.
Add finite difference tests to `TestConsistency` as `betaT_eq_minus_dmv_dP_const_T_div_mv` and `alphaV_eq_dmv_dT_const_P_div_mv`.
  • Loading branch information
corykinney committed Jan 13, 2023
1 parent 74d7624 commit f323fa5
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/thermo/consistency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,56 @@ TEST_P(TestConsistency, dSdv_const_T_eq_dPdT_const_V) {
}
}

TEST_P(TestConsistency, betaT_eq_minus_dmv_dP_const_T_div_mv)
{
double betaT1;
try {
betaT1 = phase->isothermalCompressibility();
} catch (NotImplementedError& err) {
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}

double T = phase->temperature();
double P1 = phase->pressure();
double mv1 = phase->molarVolume();

double P2 = P1 * (1 + 1e-7);
phase->setState_TP(T, P2);
double betaT2 = phase->isothermalCompressibility();
double mv2 = phase->molarVolume();

double betaT_mid = 0.5 * (betaT1 + betaT2);
double mv_mid = 0.5 * (mv1 + mv2);
double betaT_fd = -1 / mv_mid * (mv2 - mv1) / (P2 - P1);

EXPECT_NEAR(betaT_fd, betaT_mid, max({rtol_fd * betaT_mid, rtol_fd * betaT_fd, atol}));
}

TEST_P(TestConsistency, alphaV_eq_dmv_dT_const_P_div_mv)
{
double alphaV1;
try {
alphaV1 = phase->thermalExpansionCoeff();
} catch (NotImplementedError& err) {
GTEST_SKIP() << err.getMethod() << " threw NotImplementedError";
}

double P = phase->pressure();
double T1 = phase->temperature();
double mv1 = phase->molarVolume();

double T2 = T1 * (1 + 1e-7);
phase->setState_TP(T2, P);
double alphaV2 = phase->thermalExpansionCoeff();
double mv2 = phase->molarVolume();

double alphaV_mid = 0.5 * (alphaV1 + alphaV2);
double mv_mid = 0.5 * (mv1 + mv2);
double alphaV_fd = 1 / mv_mid * (mv2 - mv1) / (T2 - T1);

EXPECT_NEAR(alphaV_fd, alphaV_mid, max({rtol_fd * alphaV_mid, rtol_fd * alphaV_fd, atol}));
}

// ---------- Tests for consistency of standard state properties ---------------

TEST_P(TestConsistency, hk0_eq_uk0_plus_p_vk0)
Expand Down

0 comments on commit f323fa5

Please sign in to comment.