GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/material/components/iapws/region1.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 57 59 96.6%
Functions: 8 9 88.9%
Branches: 21 34 61.8%

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-FileCopyrightInfo: 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 158429343 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 158429337 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 158429337 times.
✗ Branch 3 not taken.
158429343 if (temperature <= 623.15 && pressure <= 100e6)
57 158429337 return;
58
59
10/22
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 6 times.
✗ Branch 16 not taken.
✓ Branch 19 taken 6 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 6 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 6 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 6 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 6 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 6 times.
✗ Branch 35 not taken.
✓ Branch 38 taken 6 times.
✗ Branch 39 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
72 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 static constexpr Scalar tau(Scalar temperature)
70 13360659 { 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 static constexpr Scalar pi(Scalar pressure)
87 145916682 { 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 6093664 static Scalar dGamma_dTau(Scalar temperature, Scalar pressure)
143 {
144 12187328 Scalar tau_ = tau(temperature); /* reduced temperature */
145 12187328 Scalar pi_ = pi(pressure); /* reduced pressure */
146
147 using std::pow;
148 6093664 Scalar result = 0.0;
149
2/2
✓ Branch 0 taken 207184576 times.
✓ Branch 1 taken 6093664 times.
213278240 for (int i = 0; i < 34; i++) {
150 621553728 result += n(i) *
151 207184576 pow(7.1 - pi_, I(i)) *
152 207184576 pow(tau_ - 1.222, J(i)-1) *
153 207184576 J(i);
154 }
155
156 6093664 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 153644289 static Scalar dGamma_dPi(Scalar temperature, Scalar pressure)
171 {
172 307288578 Scalar tau_ = tau(temperature); /* reduced temperature */
173 307288578 Scalar pi_ = pi(pressure); /* reduced pressure */
174
175 using std::pow;
176 153644289 Scalar result = 0.0;
177
2/2
✓ Branch 0 taken 5223905826 times.
✓ Branch 1 taken 153644289 times.
5377550115 for (int i = 0; i < 34; i++) {
178 15671717478 result += -n(i) *
179 10447811652 I(i) *
180 5223905826 pow(7.1 - pi_, I(i) - 1) *
181 10447811652 pow(tau_ - 1.222, J(i));
182 }
183
184 153644289 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 81496 static Scalar ddGamma_dTaudPi(Scalar temperature, Scalar pressure)
200 {
201 162992 Scalar tau_ = tau(temperature); /* reduced temperature */
202 162992 Scalar pi_ = pi(pressure); /* reduced pressure */
203
204 using std::pow;
205 81496 Scalar result = 0.0;
206
2/2
✓ Branch 0 taken 2770864 times.
✓ Branch 1 taken 81496 times.
2852360 for (int i = 0; i < 34; i++) {
207 8312592 result += -n(i) *
208 5541728 I(i) *
209 5541728 J(i) *
210 2770864 pow(7.1 - pi_, I(i) - 1) *
211 5541728 pow(tau_ - 1.222, J(i) - 1);
212 }
213
214 81496 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 2765353 static Scalar ddGamma_ddTau(Scalar temperature, Scalar pressure)
259 {
260 5530706 Scalar tau_ = tau(temperature); /* reduced temperature */
261 5530706 Scalar pi_ = pi(pressure); /* reduced pressure */
262
263 using std::pow;
264 2765353 Scalar result = 0.0;
265
2/2
✓ Branch 0 taken 94022002 times.
✓ Branch 1 taken 2765353 times.
96787355 for (int i = 0; i < 34; i++) {
266 282066006 result += n(i) *
267 94022002 pow(7.1 - pi_, I(i)) *
268 188044004 J(i) *
269 188044004 (J(i) - 1) *
270 188044004 pow(tau_ - 1.222, J(i) - 2);
271 }
272
273 2765353 return result;
274 }
275
276 private:
277 5527883268 static Scalar n(int i)
278 {
279 5527883268 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 5527883268 return n[i];
294 }
295
296 5527883268 static short int I(int i)
297 {
298 5527883268 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 5527883268 return I[i];
313 }
314
315 5737838708 static short int J(int i)
316 {
317 5737838708 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 5737838708 return J[i];
332 }
333
334 };
335
336 } // end namespace IAPWS
337 } // end namespace Dumux
338
339 #endif
340