GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/material/components/iapws/region1.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 58 58 100.0%
Functions: 8 8 100.0%
Branches: 27 44 61.4%

Line Branch Exec Source
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 //
4 // SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 /*!
8 * \file
9 * \ingroup IAPWS
10 * \brief Implements the equations for region 1 of the IAPWS '97 formulation.
11 * See:
12 *
13 * IAPWS: "Revised Release on the IAPWS Industrial Formulation
14 * 1997 for the Thermodynamic Properties of Water and Steam",
15 * http://www.iapws.org/relguide/IF97-Rev.pdf
16 */
17 #ifndef DUMUX_IAPWS_REGION1_HH
18 #define DUMUX_IAPWS_REGION1_HH
19
20 #include <cmath>
21 #include <iostream>
22 #include <dumux/common/exceptions.hh>
23
24 namespace Dumux {
25 namespace IAPWS {
26 /*!
27 * \ingroup IAPWS
28 * \brief Implements the equations for region 1 of the IAPWS '97 formulation.
29 * \tparam Scalar The type used for scalar values
30 * See:
31 *
32 * IAPWS: "Revised Release on the IAPWS Industrial Formulation
33 * 1997 for the Thermodynamic Properties of Water and Steam",
34 * http://www.iapws.org/relguide/IF97-Rev.pdf
35 */
36 template <class Scalar>
37 class Region1
38 {
39 public:
40 /*!
41 * \brief Returns true if IAPWS region 1 applies for a
42 * (temperature in \f$\mathrm{[K]}\f$, pressure in \f$\mathrm{[Pa]}\f$) pair.
43 *
44 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
45 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
46 * \param propertyName the name for which property the check is performed
47 */
48 161417718 static void checkValidityRange(Scalar temperature, Scalar pressure,
49 const std::string& propertyName = "This property")
50 {
51 // actually this is:
52 /* 273.15 <= temperature &&
53 temperature <= 623.15 &&
54 pressure >= vaporPressure(temperature) &&
55 pressure <= 100e6 */
56
3/4
✓ Branch 0 taken 161417712 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 161417712 times.
✗ Branch 3 not taken.
161417718 if (temperature <= 623.15 && pressure <= 100e6)
57 161417712 return;
58
59
16/32
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 6 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 6 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 6 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 6 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 6 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 6 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 6 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 6 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 6 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 6 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 6 times.
✗ Branch 44 not taken.
✓ Branch 47 taken 6 times.
✗ Branch 48 not taken.
161417736 DUNE_THROW(NumericalProblem,
60 propertyName << " of water is only implemented for temperatures below 623.15K and "
61 "pressures below 100MPa. (T=" << temperature << ", p=" << pressure << ")");
62 }
63
64 /*!
65 * \brief Returns the reduced temperature for IAPWS region 1.
66 *
67 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
68 */
69 174645782 static constexpr Scalar tau(Scalar temperature)
70 13957193 { return 1386.0 / temperature; }
71
72 /*!
73 * \brief Returns the derivative of the reduced temperature to the
74 * temperature for IAPWS region 1 in \f$\mathrm{[1/K]}\f$.
75 *
76 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
77 */
78 static constexpr Scalar dTau_dt(Scalar temperature)
79 { return - 1386.0 / (temperature*temperature); }
80
81 /*!
82 * \brief Returns the reduced pressure for IAPWS region 1.
83 *
84 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
85 */
86 322090812 static constexpr Scalar pi(Scalar pressure)
87 148605625 { return pressure / 16.53e6; }
88
89 /*!
90 * \brief Returns the derivative of the reduced pressure to the
91 * pressure for IAPWS region 1 in \f$\mathrm{[1/Pa]}\f$.
92 *
93 * \param pressure temperature of component in \f$\mathrm{[Pa]}\f$
94 */
95 static constexpr Scalar dPi_dp(Scalar pressure)
96 { return 1.0 / 16.53e6; }
97
98 /*!
99 * \brief Returns the derivative of the pressure to the
100 * reduced pressure for IAPWS region 1 in \f$\mathrm{[Pa]}\f$.
101 *
102 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
103 */
104 static constexpr Scalar dp_dPi(Scalar pressure)
105 { return 16.53e6; }
106
107 /*!
108 * \brief The Gibbs free energy (dimensionless) for IAPWS region 1 (i.e. liquid)
109 *
110 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
111 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
112 *
113 * IAPWS: "Revised Release on the IAPWS Industrial Formulation
114 * 1997 for the Thermodynamic Properties of Water and Steam",
115 * http://www.iapws.org/relguide/IF97-Rev.pdf
116 */
117 static Scalar gamma(Scalar temperature, Scalar pressure)
118 {
119 Scalar tau_ = tau(temperature); /* reduced temperature */
120 Scalar pi_ = pi(pressure); /* reduced pressure */
121
122 Scalar result = 0;
123 for (int i = 0; i < 34; ++i) {
124 result += n(i)*pow(7.1 - pi_, I(i))*pow(tau_ - 1.222, J(i));
125 }
126
127 return result;
128 }
129
130
131 /*!
132 * \brief The partial derivative of the Gibbs free energy to the
133 * normalized temperature for IAPWS region 1 (i.e. liquid) (dimensionless).
134 *
135 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
136 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
137 *
138 * IAPWS: "Revised Release on the IAPWS Industrial Formulation
139 * 1997 for the Thermodynamic Properties of Water and Steam",
140 * http://www.iapws.org/relguide/IF97-Rev.pdf
141 */
142 6213116 static Scalar dGamma_dTau(Scalar temperature, Scalar pressure)
143 {
144 6213116 Scalar tau_ = tau(temperature); /* reduced temperature */
145 6213116 Scalar pi_ = pi(pressure); /* reduced pressure */
146
147 using std::pow;
148 6213116 Scalar result = 0.0;
149
2/2
✓ Branch 0 taken 211245944 times.
✓ Branch 1 taken 6213116 times.
217459060 for (int i = 0; i < 34; i++) {
150 211245944 result += n(i) *
151 211245944 pow(7.1 - pi_, I(i)) *
152 211245944 pow(tau_ - 1.222, J(i)-1) *
153 J(i);
154 }
155
156 6213116 return result;
157 }
158
159 /*!
160 * \brief The partial derivative of the Gibbs free energy to the
161 * normalized pressure for IAPWS region 1 (i.e. liquid) dimensionless).
162 *
163 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
164 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
165 *
166 * IAPWS: "Revised Release on the IAPWS Industrial Formulation
167 * 1997 for the Thermodynamic Properties of Water and Steam",
168 * http://www.iapws.org/relguide/IF97-Rev.pdf
169 */
170 156484129 static Scalar dGamma_dPi(Scalar temperature, Scalar pressure)
171 {
172 156484129 Scalar tau_ = tau(temperature); /* reduced temperature */
173 156484129 Scalar pi_ = pi(pressure); /* reduced pressure */
174
175 using std::pow;
176 156484129 Scalar result = 0.0;
177
2/2
✓ Branch 0 taken 5320460386 times.
✓ Branch 1 taken 156484129 times.
5476944515 for (int i = 0; i < 34; i++) {
178 5320460386 result += -n(i) *
179 5320460386 I(i) *
180 5320460386 pow(7.1 - pi_, I(i) - 1) *
181 5320460386 pow(tau_ - 1.222, J(i));
182 }
183
184 156484129 return result;
185 }
186
187 /*!
188 * \brief The partial derivative of the Gibbs free energy to the
189 * normalized pressure and to the normalized temperature
190 * for IAPWS region 1 (i.e. liquid water) (dimensionless).
191 *
192 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
193 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
194 *
195 * IAPWS: "Revised Release on the IAPWS Industrial Formulation
196 * 1997 for the Thermodynamic Properties of Water and Steam",
197 * http://www.iapws.org/relguide/IF97-Rev.pdf
198 */
199 83455 static Scalar ddGamma_dTaudPi(Scalar temperature, Scalar pressure)
200 {
201 83455 Scalar tau_ = tau(temperature); /* reduced temperature */
202 83455 Scalar pi_ = pi(pressure); /* reduced pressure */
203
204 using std::pow;
205 83455 Scalar result = 0.0;
206
2/2
✓ Branch 0 taken 2837470 times.
✓ Branch 1 taken 83455 times.
2920925 for (int i = 0; i < 34; i++) {
207 2837470 result += -n(i) *
208 2837470 I(i) *
209 2837470 J(i) *
210 2837470 pow(7.1 - pi_, I(i) - 1) *
211 2837470 pow(tau_ - 1.222, J(i) - 1);
212 }
213
214 83455 return result;
215 }
216
217 /*!
218 * \brief The second partial derivative of the Gibbs free energy
219 * to the normalized pressure for IAPWS region 1
220 * (i.e. liquid water) (dimensionless).
221 *
222 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
223 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
224 *
225 * IAPWS: "Revised Release on the IAPWS Industrial Formulation
226 * 1997 for the Thermodynamic Properties of Water and Steam",
227 * http://www.iapws.org/relguide/IF97-Rev.pdf
228 */
229 static Scalar ddGamma_ddPi(Scalar temperature, Scalar pressure)
230 {
231 Scalar tau_ = tau(temperature); /* reduced temperature */
232 Scalar pi_ = pi(pressure); /* reduced pressure */
233
234 using std::pow;
235 Scalar result = 0.0;
236 for (int i = 0; i < 34; i++) {
237 result += n(i) *
238 I(i) *
239 (I(i) - 1) *
240 pow(7.1 - pi_, I(i) - 2) *
241 pow(tau_ - 1.222, J(i));
242 }
243
244 return result;
245 }
246
247 /*!
248 * \brief The second partial derivative of the Gibbs free energy to the
249 * normalized temperature for IAPWS region 1 (i.e. liquid) (dimensionless).
250 *
251 * \param temperature temperature of component in \f$\mathrm{[K]}\f$
252 * \param pressure pressure of component in \f$\mathrm{[Pa]}\f$
253 *
254 * IAPWS: "Revised Release on the IAPWS Industrial Formulation
255 * 1997 for the Thermodynamic Properties of Water and Steam",
256 * http://www.iapws.org/relguide/IF97-Rev.pdf
257 */
258 2825983 static Scalar ddGamma_ddTau(Scalar temperature, Scalar pressure)
259 {
260 2825983 Scalar tau_ = tau(temperature); /* reduced temperature */
261 2825983 Scalar pi_ = pi(pressure); /* reduced pressure */
262
263 using std::pow;
264 2825983 Scalar result = 0.0;
265
2/2
✓ Branch 0 taken 96083422 times.
✓ Branch 1 taken 2825983 times.
98909405 for (int i = 0; i < 34; i++) {
266 96083422 result += n(i) *
267 96083422 pow(7.1 - pi_, I(i)) *
268 96083422 J(i) *
269 96083422 (J(i) - 1) *
270 96083422 pow(tau_ - 1.222, J(i) - 2);
271 }
272
273 2825983 return result;
274 }
275
276 private:
277 5630627222 static Scalar n(int i)
278 {
279 5630627222 constexpr Scalar n[34] = {
280 0.14632971213167, -0.84548187169114, -0.37563603672040e1,
281 0.33855169168385e1, -0.95791963387872, 0.15772038513228,
282 -0.16616417199501e-1, 0.81214629983568e-3, 0.28319080123804e-3,
283 -0.60706301565874e-3, -0.18990068218419e-1, -0.32529748770505e-1,
284 -0.21841717175414e-1, -0.52838357969930e-4, -0.47184321073267e-3,
285 -0.30001780793026e-3, 0.47661393906987e-4, -0.44141845330846e-5,
286 -0.72694996297594e-15,-0.31679644845054e-4, -0.28270797985312e-5,
287 -0.85205128120103e-9, -0.22425281908000e-5, -0.65171222895601e-6,
288 -0.14341729937924e-12,-0.40516996860117e-6, -0.12734301741641e-8,
289 -0.17424871230634e-9, -0.68762131295531e-18, 0.14478307828521e-19,
290 0.26335781662795e-22,-0.11947622640071e-22, 0.18228094581404e-23,
291 -0.93537087292458e-25
292 };
293 5630627222 return n[i];
294 }
295
296 5630627222 static short int I(int i)
297 {
298 5630627222 constexpr short int I[34] = {
299 0, 0, 0,
300 0, 0, 0,
301 0, 0, 1,
302 1, 1, 1,
303 1, 1, 2,
304 2, 2, 2,
305 2, 3, 3,
306 3, 4, 4,
307 4, 5, 8,
308 8, 21, 23,
309 29, 30, 31,
310 32
311 };
312 5630627222 return I[i];
313 }
314
315 5630627222 static short int J(int i)
316 {
317 5630627222 constexpr short int J[34] = {
318 -2, -1, 0,
319 1, 2, 3,
320 4, 5, -9,
321 -7, -1, 0,
322 1, 3, -3,
323 0, 1, 3,
324 17, -4, 0,
325 6, -5, -2,
326 10, -8, -11,
327 -6, -29, -31,
328 -38, -39, -40,
329 -41
330 };
331 5630627222 return J[i];
332 }
333
334 };
335
336 } // end namespace IAPWS
337 } // end namespace Dumux
338
339 #endif
340