GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/material/components/iapws/region1.hh
Date: 2025-06-14 19:21:29
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 160666216 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 160666210 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 160666210 times.
✗ Branch 3 not taken.
160666216 if (temperature <= 623.15 && pressure <= 100e6)
57 160666210 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.
160666234 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 173823528 static constexpr Scalar tau(Scalar temperature)
70 13917193 { 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 320566957 static constexpr Scalar pi(Scalar pressure)
87 147914123 { 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 6193116 static Scalar dGamma_dTau(Scalar temperature, Scalar pressure)
143 {
144 6193116 Scalar tau_ = tau(temperature); /* reduced temperature */
145 6193116 Scalar pi_ = pi(pressure); /* reduced pressure */
146
147 using std::pow;
148 6193116 Scalar result = 0.0;
149
2/2
✓ Branch 0 taken 210565944 times.
✓ Branch 1 taken 6193116 times.
216759060 for (int i = 0; i < 34; i++) {
150 210565944 result += n(i) *
151 210565944 pow(7.1 - pi_, I(i)) *
152 210565944 pow(tau_ - 1.222, J(i)-1) *
153 J(i);
154 }
155
156 6193116 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 155742528 static Scalar dGamma_dPi(Scalar temperature, Scalar pressure)
171 {
172 155742528 Scalar tau_ = tau(temperature); /* reduced temperature */
173 155742528 Scalar pi_ = pi(pressure); /* reduced pressure */
174
175 using std::pow;
176 155742528 Scalar result = 0.0;
177
2/2
✓ Branch 0 taken 5295245952 times.
✓ Branch 1 taken 155742528 times.
5450988480 for (int i = 0; i < 34; i++) {
178 5295245952 result += -n(i) *
179 5295245952 I(i) *
180 5295245952 pow(7.1 - pi_, I(i) - 1) *
181 5295245952 pow(tau_ - 1.222, J(i));
182 }
183
184 155742528 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 82802 static Scalar ddGamma_dTaudPi(Scalar temperature, Scalar pressure)
200 {
201 82802 Scalar tau_ = tau(temperature); /* reduced temperature */
202 82802 Scalar pi_ = pi(pressure); /* reduced pressure */
203
204 using std::pow;
205 82802 Scalar result = 0.0;
206
2/2
✓ Branch 0 taken 2815268 times.
✓ Branch 1 taken 82802 times.
2898070 for (int i = 0; i < 34; i++) {
207 2815268 result += -n(i) *
208 2815268 I(i) *
209 2815268 J(i) *
210 2815268 pow(7.1 - pi_, I(i) - 1) *
211 2815268 pow(tau_ - 1.222, J(i) - 1);
212 }
213
214 82802 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 2805983 static Scalar ddGamma_ddTau(Scalar temperature, Scalar pressure)
259 {
260 2805983 Scalar tau_ = tau(temperature); /* reduced temperature */
261 2805983 Scalar pi_ = pi(pressure); /* reduced pressure */
262
263 using std::pow;
264 2805983 Scalar result = 0.0;
265
2/2
✓ Branch 0 taken 95403422 times.
✓ Branch 1 taken 2805983 times.
98209405 for (int i = 0; i < 34; i++) {
266 95403422 result += n(i) *
267 95403422 pow(7.1 - pi_, I(i)) *
268 95403422 J(i) *
269 95403422 (J(i) - 1) *
270 95403422 pow(tau_ - 1.222, J(i) - 2);
271 }
272
273 2805983 return result;
274 }
275
276 private:
277 5604030586 static Scalar n(int i)
278 {
279 5604030586 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 5604030586 return n[i];
294 }
295
296 5604030586 static short int I(int i)
297 {
298 5604030586 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 5604030586 return I[i];
313 }
314
315 5604030586 static short int J(int i)
316 {
317 5604030586 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 5604030586 return J[i];
332 }
333
334 };
335
336 } // end namespace IAPWS
337 } // end namespace Dumux
338
339 #endif
340