diff --git a/src/thermo/WaterPropsIAPWSphi.cpp b/src/thermo/WaterPropsIAPWSphi.cpp index 2b26610be2..3a12afaeb9 100644 --- a/src/thermo/WaterPropsIAPWSphi.cpp +++ b/src/thermo/WaterPropsIAPWSphi.cpp @@ -866,7 +866,7 @@ doublereal WaterPropsIAPWSphi::dfind(doublereal p_red, doublereal tau, doublerea doublereal dd = deltaGuess; bool conv = false; doublereal deldd = dd; - doublereal pcheck = 1.0E-30 + 1.0E-8 * p_red; + doublereal pcheck = 1.0E-30 + 1.0E-14 * p_red; for (int n = 0; n < 200; n++) { // Calculate the internal polynomials, and then calculate the phi deriv diff --git a/test/SConscript b/test/SConscript index 9439f9b5e8..fc65e02bca 100644 --- a/test/SConscript +++ b/test/SConscript @@ -287,6 +287,8 @@ addTestProgram('general', 'general') addTestProgram('kinetics', 'kinetics') addTestProgram('oneD', 'oneD') addTestProgram('thermo', 'thermo') +addTestProgram('thermo_consistency', 'thermo-consistency', + env_vars={'GTEST_BRIEF': '0' if env['verbose_tests'] else '1'}) addTestProgram('transport', 'transport') addTestProgram('zeroD', 'zeroD') diff --git a/test/data/consistency-cases.yaml b/test/data/consistency-cases.yaml index ff50a0a9b3..10c224d904 100644 --- a/test/data/consistency-cases.yaml +++ b/test/data/consistency-cases.yaml @@ -180,6 +180,19 @@ debye-huckel-dilute: molalities: {Na+: 9.3549, Cl-: 9.3549, H+: 1.05e-08, OH-: 1.3765e-06, NaCl(aq): 0.98492, NaOH(aq): 3.8836e-06}} +debye-huckel-dilute-IAPWS: + setup: + file: debye-huckel-all.yaml + phase: debye-huckel-dilute-IAPWS + rtol_fd: 1e-5 # Good finite difference results with IAPWS are challenging + known-failures: + cv_eq_.+: cv not implemented + activity_coeffs: "Activity coeffs are incorrect. See GitHub Issue #1311" + cp_eq_.+: "cp with variable A_Debye is incorrect. See GitHub Issue #1500" + dsdP_const_T_eq_minus_dV_dT_const_P.+: + "Error with dilute limit with variable A_Debye. See GitHub Issue #1502" + states: *debye-huckel-states + debye-huckel-B-dot-ak: setup: file: debye-huckel-all.yaml @@ -187,6 +200,17 @@ debye-huckel-B-dot-ak: known-failures: *debye-huckel-failures states: *debye-huckel-states +debye-huckel-B-dot-ak-IAPWS: + setup: + file: debye-huckel-all.yaml + phase: debye-huckel-B-dot-ak-IAPWS + rtol_fd: 1e-5 # Good finite difference results with IAPWS are challenging + known-failures: &debye-huckel-IAPWS-failures + cv_eq_.+: cv not implemented + activity_coeffs: "Activity coeffs are incorrect. See GitHub Issue #1311" + cp_eq_.+: "cp with variable A_debye is incorrect. See GitHub Issue #1500" + states: *debye-huckel-states + debye-huckel-B-dot-a: setup: file: debye-huckel-all.yaml @@ -194,6 +218,14 @@ debye-huckel-B-dot-a: known-failures: *debye-huckel-failures states: *debye-huckel-states +debye-huckel-B-dot-a-IAPWS: + setup: + file: debye-huckel-all.yaml + phase: debye-huckel-B-dot-a-IAPWS + rtol_fd: 1e-5 # Good finite difference results with IAPWS are challenging + known-failures: *debye-huckel-IAPWS-failures + states: *debye-huckel-states + debye-huckel-pitzer-beta_ij: setup: file: debye-huckel-all.yaml @@ -201,6 +233,14 @@ debye-huckel-pitzer-beta_ij: known-failures: *debye-huckel-failures states: *debye-huckel-states +debye-huckel-pitzer-beta_ij-IAPWS: + setup: + file: debye-huckel-all.yaml + phase: debye-huckel-pitzer-beta_ij-IAPWS + rtol_fd: 1e-5 # Good finite difference results with IAPWS are challenging + known-failures: *debye-huckel-IAPWS-failures + states: *debye-huckel-states + debye-huckel-beta_ij: setup: file: debye-huckel-all.yaml @@ -208,6 +248,14 @@ debye-huckel-beta_ij: known-failures: *debye-huckel-failures states: *debye-huckel-states +debye-huckel-beta_ij-IAPWS: + setup: + file: debye-huckel-all.yaml + phase: debye-huckel-beta_ij-IAPWS + rtol_fd: 1e-5 # Good finite difference results with IAPWS are challenging + known-failures: *debye-huckel-IAPWS-failures + states: *debye-huckel-states + margules: setup: file: LiKCl_liquid.yaml diff --git a/test/data/debye-huckel-all.yaml b/test/data/debye-huckel-all.yaml index 0e46c051d8..11e2093831 100644 --- a/test/data/debye-huckel-all.yaml +++ b/test/data/debye-huckel-all.yaml @@ -20,6 +20,24 @@ phases: state: {T: 300.0 K, P: 1.01325e+05 Pa, molalities: {Na+: 9.3549, Cl-: 9.3549, H+: 1.0499e-08, OH-: 1.3765e-06, NaCl(aq): 0.98492, NaOH(aq): 3.8836e-06, NaH3SiO4(aq): 6.8798e-05, SiO2(aq): 3.0179e-05, H3SiO4-: 1.0231e-06}} +- name: debye-huckel-dilute-IAPWS + elements: [O, H, C, E, Fe, Si, N, Na, Cl] + species: + species: + - water_IAPWS: [H2O(L)] + - species_waterSolution: [Na+, Cl-, H+, OH-, NaCl(aq), NaOH(aq), SiO2(aq), + NaH3SiO4(aq), H3SiO4-] + thermo: Debye-Huckel + activity-data: + model: dilute-limit + A_Debye: variable + B_Debye: 3.28640E9 kg^0.5/gmol^0.5/m + max-ionic-strength: 3.0 + use-Helgeson-fixed-form: true + default-ionic-radius: 3.5 angstrom + state: {T: 300.0 K, P: 1.01325e+05 Pa, molalities: {Na+: 9.3549, Cl-: 9.3549, H+: 1.0499e-08, + OH-: 1.3765e-06, NaCl(aq): 0.98492, NaOH(aq): 3.8836e-06, NaH3SiO4(aq): 6.8798e-05, + SiO2(aq): 3.0179e-05, H3SiO4-: 1.0231e-06}} - name: debye-huckel-B-dot-ak elements: [O, H, C, E, Fe, Si, N, Na, Cl] species: @@ -36,6 +54,23 @@ phases: state: {T: 300.0 K, P: 1.01325e+05 Pa, molalities: {Na+: 9.3549, Cl-: 9.3549, H+: 1.0499e-08, OH-: 1.3765e-06, NaCl(aq): 0.98492, NaOH(aq): 3.8836e-06, NaH3SiO4(aq): 6.8798e-05, SiO2(aq): 3.0179e-05, H3SiO4-: 1.0231e-06}} +- name: debye-huckel-B-dot-ak-IAPWS + elements: [O, H, C, E, Fe, Si, N, Na, Cl] + species: + - water_IAPWS: [H2O(L)] + - species_waterSolution: [Na+, Cl-, H+, OH-, NaCl(aq), NaOH(aq), SiO2(aq), + NaH3SiO4(aq), H3SiO4-] + thermo: Debye-Huckel + activity-data: + model: B-dot-with-variable-a + A_Debye: variable + B_Debye: 3.28640E9 kg^0.5/gmol^0.5/m + max-ionic-strength: 50.0 + B-dot: 0.041 + default-ionic-radius: 4.0 angstrom + state: {T: 300.0 K, P: 1.01325e+05 Pa, molalities: {Na+: 9.3549, Cl-: 9.3549, H+: 1.0499e-08, + OH-: 1.3765e-06, NaCl(aq): 0.98492, NaOH(aq): 3.8836e-06, NaH3SiO4(aq): 6.8798e-05, + SiO2(aq): 3.0179e-05, H3SiO4-: 1.0231e-06}} - name: debye-huckel-B-dot-a elements: [O, H, C, E, Fe, Si, N, Na, Cl] species: @@ -52,6 +87,23 @@ phases: state: {T: 300.0 K, P: 1.01325e+05 Pa, molalities: {Na+: 9.3549, Cl-: 9.3549, H+: 1.0499e-08, OH-: 1.3765e-06, NaCl(aq): 0.98492, NaOH(aq): 3.8836e-06, NaH3SiO4(aq): 6.8798e-05, SiO2(aq): 3.0179e-05, H3SiO4-: 1.0231e-06}} +- name: debye-huckel-B-dot-a-IAPWS + elements: [O, H, C, E, Fe, Si, N, Na, Cl] + species: + - water_IAPWS: [H2O(L)] + - species_waterSolution: [Na+, Cl-, H+, OH-, NaCl(aq), NaOH(aq), SiO2(aq), + NaH3SiO4(aq), H3SiO4-] + thermo: Debye-Huckel + activity-data: + model: B-dot-with-common-a + A_Debye: variable + B_Debye: 3.28640E9 kg^0.5/gmol^0.5/m + max-ionic-strength: 50.0 + B-dot: 0.0 + default-ionic-radius: 3.5 angstrom + state: {T: 300.0 K, P: 1.01325e+05 Pa, molalities: {Na+: 9.3549, Cl-: 9.3549, H+: 1.0499e-08, + OH-: 1.3765e-06, NaCl(aq): 0.98492, NaOH(aq): 3.8836e-06, NaH3SiO4(aq): 6.8798e-05, + SiO2(aq): 3.0179e-05, H3SiO4-: 1.0231e-06}} - name: debye-huckel-pitzer-beta_ij elements: [O, H, C, E, Fe, Si, N, Na, Cl] species: @@ -73,6 +125,28 @@ phases: state: {T: 300.0 K, P: 1.01325e+05 Pa, molalities: {Na+: 3.0, Cl-: 3.0, H+: 1.0499e-08, OH-: 1.3765e-06, NaCl(aq): 0.98492, NaOH(aq): 3.8836e-06, NaH3SiO4(aq): 6.8798e-05, SiO2(aq): 3.0179e-05, H3SiO4-: 1.0231e-06}} +- name: debye-huckel-pitzer-beta_ij-IAPWS + elements: [O, H, C, E, Fe, Si, N, Na, Cl] + species: + - water_IAPWS: [H2O(L)] + - species_waterSolution: [Na+, Cl-, H+, OH-, NaCl(aq), NaOH(aq), SiO2(aq), + NaH3SiO4(aq), H3SiO4-] + thermo: Debye-Huckel + activity-data: + model: Pitzer-with-beta_ij + A_Debye: variable + B_Debye: 3.28640E9 kg^0.5/gmol^0.5/m + default-ionic-radius: 3.042843 angstrom + beta: + - species: [H+, Cl-] + beta: 0.27 + - species: [Na+, Cl-] + beta: 0.15 + - species: [Na+, OH-] + beta: 0.06 + state: {T: 300.0 K, P: 1.01325e+05 Pa, molalities: {Na+: 3.0, Cl-: 3.0, H+: 1.0499e-08, + OH-: 1.3765e-06, NaCl(aq): 0.98492, NaOH(aq): 3.8836e-06, NaH3SiO4(aq): 6.8798e-05, + SiO2(aq): 3.0179e-05, H3SiO4-: 1.0231e-06}} - name: debye-huckel-beta_ij elements: [O, H, C, E, Fe, Si, N, Na, Cl] species: @@ -94,6 +168,28 @@ phases: state: {T: 300.0 K, P: 1.01325e+05 Pa, molalities: {Na+: 3.0, Cl-: 3.0, H+: 1.0499e-08, OH-: 1.3765e-06, NaCl(aq): 0.98492, NaOH(aq): 3.8836e-06, NaH3SiO4(aq): 6.8798e-05, SiO2(aq): 3.0179e-05, H3SiO4-: 1.0231e-06}} +- name: debye-huckel-beta_ij-IAPWS + elements: [O, H, C, E, Fe, Si, N, Na, Cl] + species: + - water_IAPWS: [H2O(L)] + - species_waterSolution: [Na+, Cl-, H+, OH-, NaCl(aq), NaOH(aq), SiO2(aq), + NaH3SiO4(aq), H3SiO4-] + thermo: Debye-Huckel + activity-data: + model: beta_ij + A_Debye: variable + B_Debye: 3.28640E9 kg^0.5/gmol^0.5/m + default-ionic-radius: 3.042843 angstrom + beta: + - species: [H+, Cl-] + beta: 0.27 + - species: [Na+, Cl-] + beta: 0.15 + - species: [Na+, OH-] + beta: 0.06 + state: {T: 300.0 K, P: 1.01325e+05 Pa, molalities: {Na+: 3.0, Cl-: 3.0, H+: 1.0499e-08, + OH-: 1.3765e-06, NaCl(aq): 0.98492, NaOH(aq): 3.8836e-06, NaH3SiO4(aq): 6.8798e-05, + SiO2(aq): 3.0179e-05, H3SiO4-: 1.0231e-06}} species_waterSolution: - name: H2O(L) @@ -266,3 +362,9 @@ species_waterSolution: Debye-Huckel: electrolyte-species-type: charged-species weak-acid-charge: -1.0 + +water_IAPWS: +- name: H2O(L) + composition: {H: 2, O: 1} + equation-of-state: + model: liquid-water-IAPWS95 diff --git a/test/thermo/water_iapws.cpp b/test/thermo/water_iapws.cpp index 8f5680fbae..e2db6491ba 100644 --- a/test/thermo/water_iapws.cpp +++ b/test/thermo/water_iapws.cpp @@ -104,11 +104,11 @@ TEST_F(WaterPropsIAPWS_Test, normal_boiling_point) rho = water.density(T, P, WATER_GAS); EXPECT_NEAR(rho, 0.597651, 2e-6); - EXPECT_NEAR(water.isothermalCompressibility(), 1.003322548320e-05, 2e-17); + EXPECT_NEAR(water.isothermalCompressibility(), 1.003322546019e-05, 2e-17); rho = water.density(T, P * 0.999, WATER_GAS); EXPECT_NEAR(rho, 0.597043, 2e-6); - EXPECT_NEAR(water.isothermalCompressibility(), 1.004307957351e-05, 2e-17); + EXPECT_NEAR(water.isothermalCompressibility(), 1.004307955057e-05, 2e-17); } TEST_F(WaterPropsIAPWS_Test, saturation_pressure_estimate) @@ -126,9 +126,9 @@ TEST_F(WaterPropsIAPWS_Test, expansion_coeffs) { vector_fp TT{300.0, 300.0, 700.0}; vector_fp PP{10.0, 10.0e6, 10.0e6}; - vector_fp alpha{0.003333433139236, -0.02277763412159, 0.002346416497423}; - vector_fp beta{1.000020308917, 1265.572840683, 1.240519801360}; - vector_fp beta_num{1.0000203087, 1265.46651311, 1.2405192825}; + vector_fp alpha{0.003333433139236, -0.02277763412159, 0.002346416506367}; + vector_fp beta{1.000020308917, 1265.572840683, 1.240519803181}; + vector_fp beta_num{1.0000203087, 1265.46651311, 1.2405192843}; for (size_t i = 0; i < TT.size(); i++) { double rho = water.density(TT[i], PP[i], WATER_GAS); water.setState_TD(TT[i], rho); diff --git a/test/thermo/consistency.cpp b/test/thermo_consistency/consistency.cpp similarity index 93% rename from test/thermo/consistency.cpp rename to test/thermo_consistency/consistency.cpp index 806bc09a50..8b3b1920ce 100644 --- a/test/thermo/consistency.cpp +++ b/test/thermo_consistency/consistency.cpp @@ -1,3 +1,6 @@ +// This file is part of Cantera. See License.txt in the top-level directory or +// at https://cantera.org/license.txt for license and copyright information. + #include "gtest/gtest.h" #include "cantera/thermo/ThermoPhase.h" #include "cantera/thermo/PlasmaPhase.h" @@ -27,9 +30,7 @@ // definition. using namespace std; - -namespace Cantera -{ +using namespace Cantera; // Helper functions to reduce code duplication in test suite instantiations vector getStates(const string& name) { @@ -42,6 +43,8 @@ AnyMap getSetup(const string& name) { return cases[name]["setup"].as(); } +namespace Cantera { + // For more informative output about failing test cases std::ostream& operator<<(std::ostream& s, const AnyMap& m) { @@ -59,6 +62,8 @@ std::ostream& operator<<(std::ostream& s, const AnyMap& m) return s; } +} // end namespace Cantera + class TestConsistency : public testing::TestWithParam> { public: @@ -351,24 +356,26 @@ TEST_P(TestConsistency, cv_eq_dsdT_const_v_times_T) TEST_P(TestConsistency, dsdP_const_T_eq_minus_dV_dT_const_P) { - double s1, P1, T1, v1; + double P0 = phase->pressure(); + double T0 = phase->temperature(); + double s1, v1; + double dP = 1e-4 * P0; + double dT = 1e-4 * T0; try { + phase->setState_TP(T0, P0 - dP); s1 = phase->entropy_mole(); - P1 = phase->pressure(); - T1 = phase->temperature(); + phase->setState_TP(T0 - dT, P0); v1 = phase->molarVolume(); } catch (NotImplementedError& err) { GTEST_SKIP() << err.getMethod() << " threw NotImplementedError"; } - double P2 = P1 * (1 + 1e-6); - phase->setState_TP(T1, P2); + phase->setState_TP(T0, P0 + dP); double s2 = phase->entropy_mole(); - double dsdP = (s2 - s1) / (P2 - P1); + double dsdP = (s2 - s1) / (2 * dP); - double T2 = T1 * (1 + 1e-6); - phase->setState_TP(T2, P1); + phase->setState_TP(T0 + dT, P0); double v2 = phase->molarVolume(); - double dvdT = (v2 - v1) / (T2 - T1); + double dvdT = (v2 - v1) / (2 * dT); double tol = rtol_fd * std::max(std::abs(dsdP), std::abs(dvdT)); EXPECT_NEAR(dsdP, -dvdT, tol); } @@ -730,30 +737,60 @@ INSTANTIATE_TEST_SUITE_P(DebyeHuckelDilute, TestConsistency, testing::ValuesIn(getStates("debye-huckel-dilute"))) ); +INSTANTIATE_TEST_SUITE_P(DebyeHuckelDilute_IAPWS, TestConsistency, + testing::Combine( + testing::Values(getSetup("debye-huckel-dilute-IAPWS")), + testing::ValuesIn(getStates("debye-huckel-dilute-IAPWS"))) +); + INSTANTIATE_TEST_SUITE_P(DebyeHuckel_b_dot_ak, TestConsistency, testing::Combine( testing::Values(getSetup("debye-huckel-B-dot-ak")), testing::ValuesIn(getStates("debye-huckel-B-dot-ak"))) ); +INSTANTIATE_TEST_SUITE_P(DebyeHuckel_b_dot_ak_IAPWS, TestConsistency, + testing::Combine( + testing::Values(getSetup("debye-huckel-B-dot-ak-IAPWS")), + testing::ValuesIn(getStates("debye-huckel-B-dot-ak-IAPWS"))) +); + INSTANTIATE_TEST_SUITE_P(DebyeHuckel_b_dot_a, TestConsistency, testing::Combine( testing::Values(getSetup("debye-huckel-B-dot-a")), testing::ValuesIn(getStates("debye-huckel-B-dot-a"))) ); +INSTANTIATE_TEST_SUITE_P(DebyeHuckel_b_dot_a_IAPWS, TestConsistency, + testing::Combine( + testing::Values(getSetup("debye-huckel-B-dot-a-IAPWS")), + testing::ValuesIn(getStates("debye-huckel-B-dot-a-IAPWS"))) +); + INSTANTIATE_TEST_SUITE_P(DebyeHuckel_pitzer_beta_ij, TestConsistency, testing::Combine( testing::Values(getSetup("debye-huckel-pitzer-beta_ij")), testing::ValuesIn(getStates("debye-huckel-pitzer-beta_ij"))) ); +INSTANTIATE_TEST_SUITE_P(DebyeHuckel_pitzer_beta_ij_IAPWS, TestConsistency, + testing::Combine( + testing::Values(getSetup("debye-huckel-pitzer-beta_ij-IAPWS")), + testing::ValuesIn(getStates("debye-huckel-pitzer-beta_ij-IAPWS"))) +); + INSTANTIATE_TEST_SUITE_P(DebyeHuckel_beta_ij, TestConsistency, testing::Combine( testing::Values(getSetup("debye-huckel-beta_ij")), testing::ValuesIn(getStates("debye-huckel-beta_ij"))) ); +INSTANTIATE_TEST_SUITE_P(DebyeHuckel_beta_ij_IAPWS, TestConsistency, + testing::Combine( + testing::Values(getSetup("debye-huckel-beta_ij-IAPWS")), + testing::ValuesIn(getStates("debye-huckel-beta_ij-IAPWS"))) +); + INSTANTIATE_TEST_SUITE_P(Margules, TestConsistency, testing::Combine( testing::Values(getSetup("margules")), @@ -844,4 +881,12 @@ INSTANTIATE_TEST_SUITE_P(HMWSoln, TestConsistency, testing::ValuesIn(getStates("HMW-electrolyte"))) ); +int main(int argc, char** argv) +{ + printf("Running main() from consistency.cpp\n"); + testing::InitGoogleTest(&argc, argv); + Cantera::make_deprecation_warnings_fatal(); + int result = RUN_ALL_TESTS(); + Cantera::appdelete(); + return result; }