Region4.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) 2012 by Benjamin Faigle
6  Copyright (C) 2010 by Felix Bode
7 
8  This file is part of the Open Porous Media project (OPM).
9 
10  OPM is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 2 of the License, or
13  (at your option) any later version.
14 
15  OPM is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with OPM. If not, see <http://www.gnu.org/licenses/>.
22 */
27 #ifndef OPM_IAPWS_REGION4_HPP
28 #define OPM_IAPWS_REGION4_HPP
29 
31 
32 #include <cmath>
33 
34 namespace Opm {
35 namespace IAPWS {
36 
50 template <class Scalar>
51 class Region4
52 {
53 public:
62  template <class Evaluation>
63  static Evaluation saturationPressure(const Evaluation& temperature)
64  {
65  typedef MathToolbox<Evaluation> Toolbox;
66 
67  static const Scalar n[10] = {
68  0.11670521452767e4, -0.72421316703206e6, -0.17073846940092e2,
69  0.12020824702470e5, -0.32325550322333e7, 0.14915108613530e2,
70  -0.48232657361591e4, 0.40511340542057e6, -0.23855557567849,
71  0.65017534844798e3
72  };
73 
74  const Evaluation& sigma = temperature + n[8]/(temperature - n[9]);
75 
76  const Evaluation& A = (sigma + n[0])*sigma + n[1];
77  const Evaluation& B = (n[2]*sigma + n[3])*sigma + n[4];
78  const Evaluation& C = (n[5]*sigma + n[6])*sigma + n[7];
79 
80  Evaluation tmp = 2*C/(Toolbox::sqrt(B*B - 4*A*C) - B);
81  tmp *= tmp;
82  tmp *= tmp;
83 
84  return 1e6*tmp;
85  }
86 
95  template <class Evaluation>
96  static Evaluation vaporTemperature(const Evaluation& pressure)
97  {
98  typedef MathToolbox<Evaluation> Toolbox;
99 
100  static const Scalar n[10] = {
101  0.11670521452767e4, -0.72421316703206e6, -0.17073846940092e2,
102  0.12020824702470e5, -0.32325550322333e7, 0.14915108613530e2,
103  -0.48232657361591e4, 0.40511340542057e6, -0.23855557567849,
104  0.65017534844798e3
105  };
106  const Evaluation& beta = pow((pressure/1e6 /*from Pa to MPa*/), (1./4.));
107  const Evaluation& beta2 = pow(beta, 2.);
108  const Evaluation& E = beta2 + n[2] * beta + n[5];
109  const Evaluation& F = n[0]*beta2 + n[3]*beta + n[6];
110  const Evaluation& G = n[1]*beta2 + n[4]*beta + n[7];
111 
112  const Evaluation& D = ( 2.*G)/(-F -Toolbox::sqrt(pow(F,2.) - 4.*E*G));
113 
114  const Evaluation& temperature = (n[9] + D - Toolbox::sqrt(pow(n[9]+D , 2.) - 4.* (n[8] + n[9]*D)) ) * 0.5;
115 
116  return temperature;
117  }
118 };
119 
120 } // namespace IAPWS
121 } // namespace Opm
122 
123 #endif
Definition: MathToolbox.hpp:39
Definition: Air_Mesitylene.hpp:31
Evaluation< Scalar, VarSetTag, numVars > sqrt(const Evaluation< Scalar, VarSetTag, numVars > &x)
Definition: Math.hpp:278
Implements the equations for region 4 of the IAPWS '97 formulation.
Definition: Region4.hpp:51
static Evaluation saturationPressure(const Evaluation &temperature)
Returns the saturation pressure in of pure water at a given temperature.
Definition: Region4.hpp:63
static Evaluation vaporTemperature(const Evaluation &pressure)
Returns the saturation temperature in of pure water at a given pressure.
Definition: Region4.hpp:96
Evaluation< Scalar, VarSetTag, numVars > pow(const Evaluation< Scalar, VarSetTag, numVars > &base, Scalar exp)
Definition: Math.hpp:312
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...