Region2.hpp
Go to the documentation of this file.
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  Copyright (C) 2009-2013 by Andreas Lauser
5  Copyright (C) 2010 by Felix Bode
6 
7  This file is part of the Open Porous Media project (OPM).
8 
9  OPM is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 2 of the License, or
12  (at your option) any later version.
13 
14  OPM is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OPM. If not, see <http://www.gnu.org/licenses/>.
21 */
26 #ifndef OPM_IAPWS_REGION2_HPP
27 #define OPM_IAPWS_REGION2_HPP
28 
30 
31 #include <cmath>
32 
33 namespace Opm {
34 namespace IAPWS {
49 template <class Scalar>
50 class Region2
51 {
52 public:
60  template <class Evaluation>
61  static bool isValid(const Evaluation& temperature, const Evaluation& pressure)
62  {
63  return
64  temperature <= 623.15 && pressure <= 100e6;
65 
66  // actually this is:
67  /*
68  return
69  (273.15 <= temperature && temperature <= 623.15 && pressure <= vaporPressure(temperature)) ||
70  (623.15 < temperature && temperature <= 863.15 && pressure <= auxPressure(temperature)) ||
71  (863.15 < temperature && temperature <= 1073.15 && pressure < 100e6);
72  */
73  }
74 
80  template <class Evaluation>
81  static Evaluation tau(const Evaluation& temperature)
82  { return 540.0 / temperature; }
83 
90  template <class Evaluation>
91  static Evaluation dtau_dT(const Evaluation& temperature)
92  { return - 540.0 / (temperature*temperature); }
93 
99  template <class Evaluation>
100  static Evaluation pi(const Evaluation& pressure)
101  { return pressure / 1e6; }
102 
109  template <class Evaluation>
110  static Scalar dpi_dp(const Evaluation& /*pressure*/)
111  { return 1.0 / 1e6; }
112 
119  template <class Evaluation>
120  static Evaluation dp_dpi(const Evaluation& /*pressure*/)
121  { return 1e6; }
122 
134  template <class Evaluation>
135  static Evaluation gamma(const Evaluation& temperature, const Evaluation& pressure)
136  {
137  typedef MathToolbox<Evaluation> Toolbox;
138 
139  const Evaluation& tau_ = tau(temperature); /* reduced temperature */
140  const Evaluation& pi_ = pi(pressure); /* reduced pressure */
141 
142  Evaluation result;
143 
144  // ideal gas part
145  result = Toolbox::ln(pi_);
146  for (int i = 0; i < 9; ++i)
147  result += n_g(i)*Toolbox::pow(tau_, J_g(i));
148 
149  // residual part
150  for (int i = 0; i < 43; ++i)
151  result +=
152  n_r(i)*
153  Toolbox::pow(pi_, I_r(i))*
154  Toolbox::pow(tau_ - 0.5, J_r(i));
155  return result;
156  }
157 
170  template <class Evaluation>
171  static Evaluation dgamma_dtau(const Evaluation& temperature, const Evaluation& pressure)
172  {
173  typedef MathToolbox<Evaluation> Toolbox;
174 
175  const Evaluation& tau_ = tau(temperature); /* reduced temperature */
176  const Evaluation& pi_ = pi(pressure); /* reduced pressure */
177 
178  // ideal gas part
179  Evaluation result = Toolbox::createConstant(0.0);
180  for (int i = 0; i < 9; i++) {
181  result +=
182  n_g(i) *
183  J_g(i) *
184  Toolbox::pow(tau_, static_cast<Scalar>(J_g(i) - 1));
185  }
186 
187  // residual part
188  for (int i = 0; i < 43; i++) {
189  result +=
190  n_r(i) *
191  Toolbox::pow(pi_, static_cast<Scalar>(I_r(i))) *
192  J_r(i) *
193  Toolbox::pow(tau_ - 0.5, static_cast<Scalar>(J_r(i) - 1));
194  }
195 
196  return result;
197  }
198 
211  template <class Evaluation>
212  static Evaluation dgamma_dpi(const Evaluation& temperature, const Evaluation& pressure)
213  {
214  typedef MathToolbox<Evaluation> Toolbox;
215 
216  const Evaluation& tau_ = tau(temperature); /* reduced temperature */
217  const Evaluation& pi_ = pi(pressure); /* reduced pressure */
218 
219  // ideal gas part
220  Evaluation result = 1/pi_;
221 
222  // residual part
223  for (int i = 0; i < 43; i++) {
224  result +=
225  n_r(i) *
226  I_r(i) *
227  Toolbox::pow(pi_, static_cast<Scalar>(I_r(i) - 1)) *
228  Toolbox::pow(tau_ - 0.5, static_cast<Scalar>(J_r(i)));
229  }
230 
231  return result;
232  }
233 
246  template <class Evaluation>
247  static Evaluation ddgamma_dtaudpi(const Evaluation& temperature, const Evaluation& pressure)
248  {
249  typedef MathToolbox<Evaluation> Toolbox;
250 
251  const Evaluation& tau_ = tau(temperature); /* reduced temperature */
252  const Evaluation& pi_ = pi(pressure); /* reduced pressure */
253 
254  // ideal gas part
255  Evaluation result = Toolbox::createConstant(0.0);
256 
257  // residual part
258  for (int i = 0; i < 43; i++) {
259  result +=
260  n_r(i) *
261  I_r(i) *
262  J_r(i) *
263  Toolbox::pow(pi_, static_cast<Scalar>(I_r(i) - 1)) *
264  Toolbox::pow(tau_ - 0.5, static_cast<Scalar>(J_r(i) - 1));
265  }
266 
267  return result;
268  }
269 
282  template <class Evaluation>
283  static Evaluation ddgamma_ddpi(const Evaluation& temperature, const Evaluation& pressure)
284  {
285  typedef MathToolbox<Evaluation> Toolbox;
286 
287  const Evaluation& tau_ = tau(temperature); /* reduced temperature */
288  const Evaluation& pi_ = pi(pressure); /* reduced pressure */
289 
290  // ideal gas part
291  Evaluation result = -1/(pi_*pi_);
292 
293  // residual part
294  for (int i = 0; i < 43; i++) {
295  result +=
296  n_r(i) *
297  I_r(i) *
298  (I_r(i) - 1) *
299  Toolbox::pow(pi_, static_cast<Scalar>(I_r(i) - 2)) *
300  Toolbox::pow(tau_ - 0.5, static_cast<Scalar>(J_r(i)));
301  }
302 
303  return result;
304  }
305 
318  template <class Evaluation>
319  static Evaluation ddgamma_ddtau(const Evaluation& temperature, const Evaluation& pressure)
320  {
321  typedef MathToolbox<Evaluation> Toolbox;
322 
323  const Evaluation& tau_ = tau(temperature); /* reduced temperature */
324  const Evaluation& pi_ = pi(pressure); /* reduced pressure */
325 
326  // ideal gas part
327  Evaluation result = Toolbox::createConstant(0.0);
328  for (int i = 0; i < 9; i++) {
329  result +=
330  n_g(i) *
331  J_g(i) *
332  (J_g(i) - 1) *
333  Toolbox::pow(tau_, static_cast<Scalar>(J_g(i) - 2));
334  }
335 
336  // residual part
337  for (int i = 0; i < 43; i++) {
338  result +=
339  n_r(i) *
340  Toolbox::pow(pi_, I_r(i)) *
341  J_r(i) *
342  (J_r(i) - 1.) *
343  Toolbox::pow(tau_ - 0.5, static_cast<Scalar>(J_r(i) - 2));
344  }
345 
346  return result;
347  }
348 
349 
350 private:
351  static Scalar n_g(int i)
352  {
353  static const Scalar n[9] = {
354  -0.96927686500217e1, 0.10086655968018e2, -0.56087911283020e-2,
355  0.71452738081455e-1, -0.40710498223928, 0.14240819171444e1,
356  -0.43839511319450e1, -0.28408632460772, 0.21268463753307e-1
357  };
358  return n[i];
359  }
360 
361  static Scalar n_r(int i)
362  {
363  static const Scalar n[43] = {
364  -0.17731742473213e-2, -0.17834862292358e-1, -0.45996013696365e-1,
365  -0.57581259083432e-1, -0.50325278727930e-1, -0.33032641670203e-4,
366  -0.18948987516315e-3, -0.39392777243355e-2, -0.43797295650573e-1,
367  -0.26674547914087e-4, 0.20481737692309e-7, 0.43870667284435e-6,
368  -0.32277677238570e-4, -0.15033924542148e-2, -0.40668253562649e-1,
369  -0.78847309559367e-9, 0.12790717852285e-7, 0.48225372718507e-6,
370  0.22922076337661e-5, -0.16714766451061e-10, -0.21171472321355e-2,
371  -0.23895741934104e2, -0.59059564324270e-17, -0.12621808899101e-5,
372  -0.38946842435739e-1, 0.11256211360459e-10, -0.82311340897998e1,
373  0.19809712802088e-7, 0.10406965210174e-18, -0.10234747095929e-12,
374  -0.10018179379511e-8, -0.80882908646985e-10, 0.10693031879409,
375  -0.33662250574171, 0.89185845355421e-24, 0.30629316876232e-12,
376  -0.42002467698208e-5, -0.59056029685639e-25, 0.37826947613457e-5,
377  -0.12768608934681e-14, 0.73087610595061e-28, 0.55414715350778e-16,
378  -0.94369707241210e-6
379  };
380  return n[i];
381  }
382 
383  static Scalar I_r(int i)
384  {
385  static const short int I[43] = {
386  1, 1, 1,
387  1, 1, 2,
388  2, 2, 2,
389  2, 3, 3,
390  3, 3, 3,
391  4, 4, 4,
392  5, 6, 6,
393  6, 7, 7,
394  7, 8, 8,
395  9, 10, 10,
396  10, 16, 16,
397  18, 20, 20,
398  20, 21, 22,
399  23, 24, 24,
400  24
401  };
402  return I[i];
403  }
404 
405  static Scalar J_g(int i)
406  {
407  static const short int J[9] = {
408  0, 1, -5,
409  -4, -3, -2,
410  -1, 2, 3
411  };
412  return J[i];
413  }
414 
415  static Scalar J_r(int i)
416  {
417  static const short int J[43] = {
418  0, 1, 2,
419  3, 6, 1,
420  2, 4, 7,
421  36, 0, 1,
422  3, 6, 35,
423  1, 2, 3,
424  7, 3, 16,
425  35, 0, 11,
426  25, 8, 36,
427  13, 4, 10,
428  14, 29, 50,
429  57, 20, 35,
430  48, 21, 53,
431  39, 26, 40,
432  58
433  };
434  return J[i];
435  }
436 
437 };
438 
439 } // namespace IAPWS
440 } // namespace Opm
441 
442 #endif
static Evaluation gamma(const Evaluation &temperature, const Evaluation &pressure)
The Gibbs free energy for IAPWS region 2 (i.e. sub-critical steam) (dimensionless).
Definition: Region2.hpp:135
static Evaluation ddgamma_dtaudpi(const Evaluation &temperature, const Evaluation &pressure)
The partial derivative of the Gibbs free energy to the normalized pressure and to the normalized temp...
Definition: Region2.hpp:247
Definition: MathToolbox.hpp:39
Definition: Air_Mesitylene.hpp:31
static Evaluation ddgamma_ddpi(const Evaluation &temperature, const Evaluation &pressure)
The second partial derivative of the Gibbs free energy to the normalized pressure for IAPWS region 2 ...
Definition: Region2.hpp:283
static Evaluation dtau_dT(const Evaluation &temperature)
Returns the derivative of the reduced temperature to the temperature for IAPWS region 2...
Definition: Region2.hpp:91
static Evaluation tau(const Evaluation &temperature)
Returns the reduced temperature (dimensionless) for IAPWS region 2.
Definition: Region2.hpp:81
static Scalar dpi_dp(const Evaluation &)
Returns the derivative of the reduced pressure to the pressure for IAPWS region 2 in ...
Definition: Region2.hpp:110
static bool isValid(const Evaluation &temperature, const Evaluation &pressure)
Returns true if IAPWS region 2 applies for a (temperature, pressure) pair.
Definition: Region2.hpp:61
static Evaluation dp_dpi(const Evaluation &)
Returns the derivative of the pressure to the reduced pressure for IAPWS region 2 (dimensionless)...
Definition: Region2.hpp:120
static Evaluation dgamma_dpi(const Evaluation &temperature, const Evaluation &pressure)
The partial derivative of the Gibbs free energy to the normalized pressure for IAPWS region 2 (i...
Definition: Region2.hpp:212
static Evaluation dgamma_dtau(const Evaluation &temperature, const Evaluation &pressure)
The partial derivative of the Gibbs free energy to the normalized temperature for IAPWS region 2 (i...
Definition: Region2.hpp:171
Evaluation< Scalar, VarSetTag, numVars > pow(const Evaluation< Scalar, VarSetTag, numVars > &base, Scalar exp)
Definition: Math.hpp:312
static Evaluation pi(const Evaluation &pressure)
Returns the reduced pressure (dimensionless) for IAPWS region 2.
Definition: Region2.hpp:100
Implements the equations for region 2 of the IAPWS '97 formulation.
Definition: Region2.hpp:50
static Evaluation ddgamma_ddtau(const Evaluation &temperature, const Evaluation &pressure)
The second partial derivative of the Gibbs free energy to the normalized temperature for IAPWS region...
Definition: Region2.hpp:319
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...