Skip to content

Commit

Permalink
Add consistency test for cp = dh/dT at constant P
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Jun 10, 2022
1 parent e23dddd commit bfb11e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/data/consistency-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ ideal-gas-h2o2:
- {T: 400, density: 5 g/cm^3 , X: {H2: 0.1, O2: 0.7, H2O2: 0.1}}

redlich-kwong:
setup: {file: co2_RK_example.yaml}
setup:
file: co2_RK_example.yaml
states:
- {T: 300, P: 101325, X: {CO2: 0.7, CH4: 0.2, H2O: 0.1}}
- {T: 320, P: 200 bar, X: {CO2: 0.3, CH4: 0.5, H2O: 0.2}}
- {T: 600, P: 200 bar, X: {CO2: 0.4, CH4: 0.2, H2O: 0.4}}

peng-robinson:
setup: {file: co2_PR_example.yaml}
setup:
file: co2_PR_example.yaml
states:
- {T: 300, P: 101325, X: {CO2: 0.7, CH4: 0.2, H2O: 0.1}}
- {T: 320, P: 200 bar, X: {CO2: 0.3, CH4: 0.5, H2O: 0.2}}
Expand Down Expand Up @@ -106,6 +108,7 @@ nitrogen-purefluid:
setup:
file: liquidvapor.yaml
phase: nitrogen
rtol_fd: 1e-5
states:
- {T: 300, P: 1 atm}
- {T: 70, P: 1 atm}
Expand All @@ -116,6 +119,8 @@ plasma:
setup:
file: oxygen-plasma.yaml
phase: discretized-electron-energy-plasma
known-failures:
cp_eq_dhdT/1: Test does not account for distinct electron temperature
states:
- {T: 300, P: 1 atm, X: {O2: 1.0, O2-: 1e-5, E: 1e-5}}
- {T: 300, P: 1 atm, X: {E: 1.0}}
Expand Down
16 changes: 16 additions & 0 deletions test/thermo/consistency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class TestConsistency : public testing::TestWithParam<std::tuple<AnyMap, AnyMap>
cache[key].reset(newPhase(key.first, key.second));
}
atol = setup.getDouble("atol", 1e-5);
rtol_fd = setup.getDouble("rtol_fd", 1e-6);
atol_v = setup.getDouble("atol_v", 1e-11);

phase = cache[key];
Expand Down Expand Up @@ -72,6 +73,7 @@ class TestConsistency : public testing::TestWithParam<std::tuple<AnyMap, AnyMap>
size_t nsp;
double T, p;
double atol, atol_v;
double rtol_fd; // relative tolerance for finite difference comparisons
};

map<pair<string, string>, shared_ptr<ThermoPhase>> TestConsistency::cache = {};
Expand Down Expand Up @@ -147,6 +149,20 @@ TEST_P(TestConsistency, v_eq_sum_vk_Xk)
EXPECT_NEAR(phase->molarVolume(), phase->mean_X(vk), atol_v);
}

TEST_P(TestConsistency, cp_eq_dhdT)
{
double h1 = phase->enthalpy_mole();
double cp1 = phase->cp_mole();
double T1 = phase->temperature();
double dT = 1e-5 * phase->temperature();
phase->setState_TP(T1 + dT, phase->pressure());
double h2 = phase->enthalpy_mole();
double cp2 = phase->cp_mole();
double cp_mid = 0.5 * (cp1 + cp2);
double cp_fd = (h2 - h1)/dT;
EXPECT_NEAR(cp_fd, cp_mid, max({rtol_fd * cp_mid, rtol_fd * cp_fd, atol}));
}

INSTANTIATE_TEST_SUITE_P(IdealGas, TestConsistency,
testing::Combine(
testing::Values(getSetup("ideal-gas-h2o2")),
Expand Down

0 comments on commit bfb11e6

Please sign in to comment.