1 #include "gtest/gtest.h"
2 #include "cantera/base/ct_defs.h"
3 #include "cantera/thermo/WaterPropsIAPWSphi.h"
4 #include "cantera/thermo/WaterPropsIAPWS.h"
5 
6 using namespace Cantera;
7 
8 const double T_c = 647.096;
9 const double Rho_c = 322.0;
10 
11 class WaterPropsIAPWSphi_Test : public testing::Test, public WaterPropsIAPWSphi
12 {
13 };
14 
15 // Test agreement with values given in Table 6.6 of: W. Wagner, A. Pruss, "The
16 // IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water
17 // Substance for General and Scientific Use," J. Phys. Chem. Ref. Dat, 31, 387,
18 // 2002.
19 
TEST_F(WaterPropsIAPWSphi_Test,check1)20 TEST_F(WaterPropsIAPWSphi_Test, check1) {
21     tdpolycalc(T_c / 500.0, 838.025 / Rho_c);
22     EXPECT_NEAR(phi0(), 2.047977334796e+00, 1e-11);
23     EXPECT_NEAR(phiR(), -3.426932056816e+00, 1e-11);
24     EXPECT_NEAR(phi0_d(), 3.842367471137e-01, 1e-11);
25     EXPECT_NEAR(phiR_d(), -3.643666503639e-01, 1e-11);
26     EXPECT_NEAR(phi0_dd(), -1.476378778326e-01, 1e-11);
27     EXPECT_NEAR(phiR_dd(), 8.560637009746e-01, 1e-11);
28     EXPECT_NEAR(phi0_t(), 9.046111061752e+00, 1e-11);
29     EXPECT_NEAR(phiR_t(), -5.814034352384e+00, 1e-11);
30     EXPECT_NEAR(phi0_tt(), -1.932491850131e+00, 1e-11);
31     EXPECT_NEAR(phiR_tt(), -2.234407368843e+00, 1e-11);
32     EXPECT_NEAR(phi0_dt(), 0.000000000000e+00, 1e-11);
33     EXPECT_NEAR(phiR_dt(), -1.121769146703e+00, 1e-11);
34 }
35 
TEST_F(WaterPropsIAPWSphi_Test,check2)36 TEST_F(WaterPropsIAPWSphi_Test, check2) {
37     tdpolycalc(T_c / 647.0, 358.0 / Rho_c);
38     EXPECT_NEAR(phi0(), -1.563196050525e+00, 1e-11);
39     EXPECT_NEAR(phiR(), -1.212026565041e+00, 1e-11);
40     EXPECT_NEAR(phi0_d(), 8.994413407821e-01, 1e-11);
41     EXPECT_NEAR(phiR_d(), -7.140120243713e-01, 1e-11);
42     EXPECT_NEAR(phi0_dd(), -8.089947255079e-01, 1e-11);
43     EXPECT_NEAR(phiR_dd(), 4.757306956457e-01, 1e-11);
44     EXPECT_NEAR(phi0_t(), 9.803439179390e+00, 1e-11);
45     EXPECT_NEAR(phiR_t(), -3.217225007752e+00, 1e-11);
46     EXPECT_NEAR(phi0_tt(), -3.433163341431e+00, 1e-11);
47     EXPECT_NEAR(phiR_tt(), -9.960295065593e+00, 1e-11);
48     EXPECT_NEAR(phi0_dt(), 0.000000000000e+00, 1e-11);
49     EXPECT_NEAR(phiR_dt(), -1.332147204361e+00, 1e-11);
50 }
51 
52 class WaterPropsIAPWS_Test : public testing::Test
53 {
54 public:
dPdT(double T,double P)55     double dPdT(double T, double P) {
56         double rho = water.density(T, P);
57         water.setState_TR(T, rho);
58         double P1 = water.pressure();
59         double T2 = T + 0.001;
60         water.setState_TR(T2, rho);
61         double P2 = water.pressure();
62         return (P2 - P1) / 0.001;
63     }
64 
65     WaterPropsIAPWS water;
66 };
67 
68 // See values on p. 395 of Wagner & Pruss.
TEST_F(WaterPropsIAPWS_Test,triple_point_liquid)69 TEST_F(WaterPropsIAPWS_Test, triple_point_liquid)
70 {
71     double T = 273.16;
72     double pres = water.psat(T);
73     EXPECT_NEAR(pres, 611.655, 2e-3);
74     EXPECT_NEAR(water.density(T, pres, WATER_LIQUID), 999.793, 2e-3);
75     EXPECT_NEAR(water.intEnergy(), 0.0, 5e-7);
76     EXPECT_NEAR(water.entropy(), 0.0, 5e-9);
77     EXPECT_NEAR(water.enthalpy(), 11.0214, 2e-4);
78     EXPECT_NEAR(water.Gibbs(), 11.0214, 2e-4);
79     EXPECT_NEAR(water.cv(), 75978.2, 2e-1);
80     EXPECT_NEAR(water.cp(), 76022.8, 2e-1);
81 }
82 
TEST_F(WaterPropsIAPWS_Test,triple_point_gas)83 TEST_F(WaterPropsIAPWS_Test, triple_point_gas)
84 {
85     double T = 273.16;
86     double pres = water.psat(T);
87     EXPECT_NEAR(water.density(T, pres, WATER_GAS), 4.85458e-3, 2e-8);
88     EXPECT_NEAR(water.intEnergy(), 4.27848e7, 2e2);
89     EXPECT_NEAR(water.entropy(), 164939., 2e0);
90     EXPECT_NEAR(water.enthalpy(), 4.50547e7, 2e2);
91     EXPECT_NEAR(water.Gibbs(), 11.0214, 2e-4);
92     EXPECT_NEAR(water.cv(), 25552.6, 2e-1);
93     EXPECT_NEAR(water.cp(), 33947.1, 2e-1);
94 }
95 
TEST_F(WaterPropsIAPWS_Test,normal_boiling_point)96 TEST_F(WaterPropsIAPWS_Test, normal_boiling_point)
97 {
98     double T = 373.124;
99     double P = water.psat(T);
100     EXPECT_NEAR(P, 101324., 1e0);
101     double rho = water.density(T, P, WATER_LIQUID);
102     EXPECT_NEAR(rho, 958.368, 2e-3);
103     EXPECT_NEAR(water.isothermalCompressibility(), 4.901779037782e-10, 2e-21);
104 
105     water.density(T, 1.001 * P, WATER_LIQUID);
106     EXPECT_NEAR(water.isothermalCompressibility(), 4.901777340771e-10, 2e-21);
107 
108     rho = water.density(T, P, WATER_GAS);
109     EXPECT_NEAR(rho, 0.597651, 2e-6);
110     EXPECT_NEAR(water.isothermalCompressibility(), 1.003322591472e-05, 2e-17);
111 
112     rho = water.density(T, P * 0.999, WATER_GAS);
113     EXPECT_NEAR(rho, 0.597043, 2e-6);
114     EXPECT_NEAR(water.isothermalCompressibility(), 1.004308000545e-05, 2e-17);
115 }
116 
TEST_F(WaterPropsIAPWS_Test,saturation_pressure_estimate)117 TEST_F(WaterPropsIAPWS_Test, saturation_pressure_estimate)
118 {
119     vector_fp TT{273.15, 313.9999, 314.0001, 373.15, 647.25};
120     vector_fp psat{611.212, 7722.3, 7675.46, 101007, 2.2093e+07};
121 
122     for (size_t i = 0; i < TT.size(); i++) {
123         double P = water.psat_est(TT[i]);
124         EXPECT_NEAR(P, psat[i], 2e-6 * psat[i]);
125     }
126 }
127 
TEST_F(WaterPropsIAPWS_Test,expansion_coeffs)128 TEST_F(WaterPropsIAPWS_Test, expansion_coeffs)
129 {
130     vector_fp TT{300.0, 300.0, 700.0};
131     vector_fp PP{10.0, 10.0e6, 10.0e6};
132     vector_fp alpha{0.003333433139236, -0.02277763412159, 0.002346416555069};
133     vector_fp beta{1.000020308917, 1265.572840683, 1.240519813089};
134     vector_fp beta_num{1.0000203087, 1265.46651311, 1.240519294};
135     for (size_t i = 0; i < TT.size(); i++) {
136         double rho = water.density(TT[i], PP[i], WATER_GAS);
137         water.setState_TR(TT[i], rho);
138         EXPECT_NEAR(water.coeffThermExp(), alpha[i], 2e-14);
139         EXPECT_NEAR(water.coeffPresExp(), beta[i], beta[i] * 2e-12);
140         EXPECT_NEAR(dPdT(TT[i], PP[i]) * 18.015268 / (8.314371E3 * rho),
141                     beta_num[i], 2e-10 * beta_num[i]);
142     }
143 }
144