Region1.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_REGION1_HPP
27 #define OPM_IAPWS_REGION1_HPP
28 
30 
31 #include <cmath>
32 
33 namespace Opm {
34 namespace IAPWS {
48 template <class Scalar>
49 class Region1
50 {
51 public:
59  template <class Evaluation>
60  static bool isValid(const Evaluation& temperature, const Evaluation& pressure)
61  {
62  typedef MathToolbox<Evaluation> Toolbox;
63 
64  return
65  Toolbox::value(temperature) <= 623.15 &&
66  Toolbox::value(pressure) <= 100e6;
67 
68  // actually this is:
69  /*
70  return
71  (
72  273.15 <= temperature &&
73  temperature <= 623.15 &&
74  pressure >= vaporPressure(temperature) &&
75  pressure <= 100e6
76  );
77  */
78  }
79 
85  template <class Evaluation>
86  static Evaluation tau(const Evaluation& temperature)
87  { return 1386.0 / temperature; }
88 
95  template <class Evaluation>
96  static Evaluation dtau_dT(const Evaluation& temperature)
97  { return - 1386.0 / (temperature*temperature); }
98 
104  template <class Evaluation>
105  static Evaluation pi(const Evaluation& pressure)
106  { return pressure / 16.53e6; }
107 
114  static Scalar dpi_dp(Scalar /*pressure*/)
115  { return 1.0 / 16.53e6; }
116 
123  static Scalar dp_dpi(Scalar /*pressure*/)
124  { return 16.53e6; }
125 
136  template <class Evaluation>
137  static Evaluation gamma(const Evaluation& temperature, const Evaluation& pressure)
138  {
139  typedef MathToolbox<Evaluation> Toolbox;
140 
141  const Evaluation tau_ = tau(temperature); /* reduced temperature */
142  const Evaluation pi_ = pi(pressure); /* reduced pressure */
143 
144  Evaluation result = 0;
145  for (int i = 0; i < 34; ++i) {
146  result += n(i)*Toolbox::pow(7.1 - pi_, I(i))*Toolbox::pow(tau_ - 1.222, J(i));
147  }
148 
149  return result;
150  }
151 
152 
164  template <class Evaluation>
165  static Evaluation dgamma_dtau(const Evaluation& temperature, const Evaluation& pressure)
166  {
167  typedef MathToolbox<Evaluation> Toolbox;
168 
169  const Evaluation tau_ = tau(temperature); /* reduced temperature */
170  const Evaluation pi_ = pi(pressure); /* reduced pressure */
171 
172  Evaluation result = Toolbox::createConstant(0.0);
173  for (int i = 0; i < 34; i++) {
174  result +=
175  n(i) *
176  Toolbox::pow(7.1 - pi_, static_cast<Scalar>(I(i))) *
177  Toolbox::pow(tau_ - 1.222, static_cast<Scalar>(J(i)-1)) *
178  J(i);
179  }
180 
181  return result;
182  }
183 
195  template <class Evaluation>
196  static Evaluation dgamma_dpi(const Evaluation& temperature, const Evaluation& pressure)
197  {
198  typedef MathToolbox<Evaluation> Toolbox;
199 
200  const Evaluation tau_ = tau(temperature); /* reduced temperature */
201  const Evaluation pi_ = pi(pressure); /* reduced pressure */
202 
203  Evaluation result = Toolbox::createConstant(0.0);
204  for (int i = 0; i < 34; i++) {
205  result +=
206  -n(i) *
207  I(i) *
208  Toolbox::pow(7.1 - pi_, static_cast<Scalar>(I(i) - 1)) *
209  Toolbox::pow(tau_ - 1.222, static_cast<Scalar>(J(i)));
210  }
211 
212  return result;
213  }
214 
227  template <class Evaluation>
228  static Evaluation ddgamma_dtaudpi(const Evaluation& temperature, const Evaluation& pressure)
229  {
230  typedef MathToolbox<Evaluation> Toolbox;
231 
232  const Evaluation tau_ = tau(temperature); /* reduced temperature */
233  const Evaluation pi_ = pi(pressure); /* reduced pressure */
234 
235  Evaluation result = Toolbox::createConstant(0.0);
236  for (int i = 0; i < 34; i++) {
237  result +=
238  -n(i) *
239  I(i) *
240  J(i) *
241  Toolbox::pow(7.1 - pi_, static_cast<Scalar>(I(i) - 1)) *
242  Toolbox::pow(tau_ - 1.222, static_cast<Scalar>(J(i) - 1));
243  }
244 
245  return result;
246  }
247 
260  template <class Evaluation>
261  static Evaluation ddgamma_ddpi(const Evaluation& temperature, const Evaluation& pressure)
262  {
263  typedef MathToolbox<Evaluation> Toolbox;
264 
265  const Evaluation tau_ = tau(temperature); /* reduced temperature */
266  const Evaluation pi_ = pi(pressure); /* reduced pressure */
267 
268  Evaluation result = Toolbox::createConstant(0.0);
269  for (int i = 0; i < 34; i++) {
270  result +=
271  n(i) *
272  I(i) *
273  (I(i) - 1) *
274  Toolbox::pow(7.1 - pi_, I(i) - 2) *
275  Toolbox::pow(tau_ - 1.222, J(i));
276  }
277 
278  return result;
279  }
280 
292  template <class Evaluation>
293  static Evaluation ddgamma_ddtau(const Evaluation& temperature, const Evaluation& pressure)
294  {
295  typedef MathToolbox<Evaluation> Toolbox;
296 
297  const Evaluation tau_ = tau(temperature); /* reduced temperature */
298  const Evaluation pi_ = pi(pressure); /* reduced pressure */
299 
300  Evaluation result = Toolbox::createConstant(0.0);
301  for (int i = 0; i < 34; i++) {
302  result +=
303  n(i) *
304  Toolbox::pow(7.1 - pi_, I(i)) *
305  J(i) *
306  (J(i) - 1) *
307  Toolbox::pow(tau_ - 1.222, J(i) - 2);
308  }
309 
310  return result;
311  }
312 
313 private:
314  static Scalar n(int i)
315  {
316  static const Scalar n[34] = {
317  0.14632971213167, -0.84548187169114, -0.37563603672040e1,
318  0.33855169168385e1, -0.95791963387872, 0.15772038513228,
319  -0.16616417199501e-1, 0.81214629983568e-3, 0.28319080123804e-3,
320  -0.60706301565874e-3, -0.18990068218419e-1, -0.32529748770505e-1,
321  -0.21841717175414e-1, -0.52838357969930e-4, -0.47184321073267e-3,
322  -0.30001780793026e-3, 0.47661393906987e-4, -0.44141845330846e-5,
323  -0.72694996297594e-15,-0.31679644845054e-4, -0.28270797985312e-5,
324  -0.85205128120103e-9, -0.22425281908000e-5, -0.65171222895601e-6,
325  -0.14341729937924e-12,-0.40516996860117e-6, -0.12734301741641e-8,
326  -0.17424871230634e-9, -0.68762131295531e-18, 0.14478307828521e-19,
327  0.26335781662795e-22,-0.11947622640071e-22, 0.18228094581404e-23,
328  -0.93537087292458e-25
329  };
330  return n[i];
331  }
332 
333  static Scalar I(int i)
334  {
335  static const short int I[34] = {
336  0, 0, 0,
337  0, 0, 0,
338  0, 0, 1,
339  1, 1, 1,
340  1, 1, 2,
341  2, 2, 2,
342  2, 3, 3,
343  3, 4, 4,
344  4, 5, 8,
345  8, 21, 23,
346  29, 30, 31,
347  32
348  };
349  return I[i];
350  }
351 
352  static Scalar J(int i)
353  {
354  static const short int J[34] = {
355  -2, -1, 0,
356  1, 2, 3,
357  4, 5, -9,
358  -7, -1, 0,
359  1, 3, -3,
360  0, 1, 3,
361  17, -4, 0,
362  6, -5, -2,
363  10, -8, -11,
364  -6, -29, -31,
365  -38, -39, -40,
366  -41
367  };
368  return J[i];
369  }
370 
371 };
372 
373 } // namespace IAPWS
374 } // namespace Opm
375 
376 #endif
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: Region1.hpp:293
static Scalar dp_dpi(Scalar)
Returns the derivative of the pressure to the reduced pressure for IAPWS region 1 in ...
Definition: Region1.hpp:123
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: Region1.hpp:228
Definition: MathToolbox.hpp:39
Definition: Air_Mesitylene.hpp:31
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 1 (i...
Definition: Region1.hpp:196
Implements the equations for region 1 of the IAPWS '97 formulation.
Definition: Region1.hpp:49
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 1 (i...
Definition: Region1.hpp:165
static Scalar dpi_dp(Scalar)
Returns the derivative of the reduced pressure to the pressure for IAPWS region 1 in ...
Definition: Region1.hpp:114
static Evaluation tau(const Evaluation &temperature)
Returns the reduced temperature for IAPWS region 1.
Definition: Region1.hpp:86
static Evaluation pi(const Evaluation &pressure)
Returns the reduced pressure for IAPWS region 1.
Definition: Region1.hpp:105
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 1 ...
Definition: Region1.hpp:261
Evaluation< Scalar, VarSetTag, numVars > pow(const Evaluation< Scalar, VarSetTag, numVars > &base, Scalar exp)
Definition: Math.hpp:312
static Evaluation gamma(const Evaluation &temperature, const Evaluation &pressure)
The Gibbs free energy (dimensionless) for IAPWS region 1 (i.e. liquid)
Definition: Region1.hpp:137
static bool isValid(const Evaluation &temperature, const Evaluation &pressure)
Returns true if IAPWS region 1 applies for a (temperature in , pressure in ) pair.
Definition: Region1.hpp:60
static Evaluation dtau_dT(const Evaluation &temperature)
Returns the derivative of the reduced temperature to the temperature for IAPWS region 1 in ...
Definition: Region1.hpp:96
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...