opm-common
Common.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  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 2 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 
19  Consult the COPYING file in the top-level source directory of this
20  module for the precise wording of the license and the list of
21  copyright holders.
22 */
27 #ifndef OPM_IAPWS_COMMON_HPP
28 #define OPM_IAPWS_COMMON_HPP
29 
32 #include <opm/common/utility/gpuDecorators.hpp>
33 
34 #include <cmath>
35 
36 namespace Opm {
37 namespace IAPWS {
38 
54 template <class Scalar>
55 class Common
56 {
57 public:
59  static constexpr Scalar molarMass = Scalar(18.01518e-3);
60 
62  static constexpr Scalar Rs = Constants<Scalar>::R / molarMass;
63 
65  static constexpr Scalar criticalTemperature = Scalar(647.096);
66 
68  static constexpr Scalar criticalPressure = Scalar(22.064e6);
69 
71  static constexpr Scalar criticalDensity = Scalar(322.0);
72 
74  static constexpr Scalar criticalVolume = Scalar(5.595e-2);
75 
77  static constexpr Scalar criticalMolarVolume = molarMass / criticalDensity;
78 
80  static constexpr Scalar acentricFactor = Scalar(0.344);
81 
83  static constexpr Scalar tripleTemperature = Scalar(273.16);
84 
86  static constexpr Scalar triplePressure = Scalar(611.657);
87 
102  template <class Evaluation>
103  OPM_HOST_DEVICE static Evaluation viscosity(const Evaluation& temperature, const Evaluation& rho)
104  {
105  Evaluation rhoBar = rho/322.0;
106  // I do not know why, but NVCC will not allow writing out temperature/criticalTemperature
107  // HIPCC does this perfectly fine, should be allowed since it is static constexpr, but for
108  // now I'll have to write out the scalar here instead...
109  Evaluation TBar = temperature/Scalar(647.096);
110 
111  // muBar = muBar_1
112  const Scalar Hij[6][7] = {
113  { 5.20094e-1, 2.22531e-1,-2.81378e-1, 1.61913e-1,-3.25372e-2, 0, 0 },
114  { 8.50895e-2, 9.99115e-1,-9.06851e-1, 2.57399e-1, 0, 0, 0 },
115  { -1.08374, 1.88797 ,-7.72479e-1, 0, 0, 0, 0 },
116  { -2.89555e-1, 1.26613 ,-4.89837e-1, 0, 6.98452e-2, 0,-4.35673e-3 },
117  { 0, 0,-2.57040e-1, 0, 0, 8.72102e-3, 0 },
118  { 0, 1.20573e-1, 0, 0, 0, 0,-5.93264e-4 }
119  };
120 
121  Evaluation tmp, tmp2, tmp3 = 1;
122  Evaluation muBar = 0;
123  for (int i = 0; i <= 5; ++i) {
124  tmp = 0;
125  tmp2 = 1;
126  for (int j = 0; j <= 6; ++j) {
127  tmp += Hij[i][j]*tmp2;
128  tmp2 *= (rhoBar - 1);
129  };
130  muBar += tmp3 * tmp;
131  tmp3 *= 1.0/TBar - 1;
132  };
133  muBar *= rhoBar;
134  muBar = exp(muBar);
135 
136  // muBar *= muBar_0
137  muBar *= 100*sqrt(TBar);
138  const Scalar H[4] = {
139  1.67752, 2.20462, 0.6366564, -0.241605
140  };
141 
142  tmp = 0, tmp2 = 1;
143  for (int i = 0; i < 4; ++i) {
144  tmp += H[i]/tmp2;
145  tmp2 *= TBar;
146  };
147  muBar /= tmp;
148 
149  return 1e-6*muBar;
150  }
151 
165  template <class Evaluation>
166  OPM_HOST_DEVICE static Evaluation thermalConductivityIAPWS(const Evaluation& T, const Evaluation& rho)
167  {
168  static const Scalar thcond_tstar = 647.26 ;
169  static const Scalar thcond_rhostar = 317.7 ;
170  /*static const Scalar thcond_kstar = 1.0 ;*/
171 
172  static const Scalar thcond_b0 = -0.397070 ;
173  static const Scalar thcond_b1 = 0.400302 ;
174  static const Scalar thcond_b2 = 1.060000 ;
175  static const Scalar thcond_B1 = -0.171587 ;
176  static const Scalar thcond_B2 = 2.392190 ;
177 
178  static const Scalar thcond_c1 = 0.642857 ;
179  static const Scalar thcond_c2 = -4.11717 ;
180  static const Scalar thcond_c3 = -6.17937 ;
181  static const Scalar thcond_c4 = 0.00308976 ;
182  static const Scalar thcond_c5 = 0.0822994 ;
183  static const Scalar thcond_c6 = 10.0932 ;
184 
185  static const Scalar thcond_d1 = 0.0701309 ;
186  static const Scalar thcond_d2 = 0.0118520 ;
187  static const Scalar thcond_d3 = 0.00169937 ;
188  static const Scalar thcond_d4 = -1.0200 ;
189  static const int thcond_a_count = 4;
190  static const Scalar thcond_a[thcond_a_count] = {
191  0.0102811
192  ,0.0299621
193  ,0.0156146
194  ,-0.00422464
195  };
196 
197  Evaluation Tbar = T / thcond_tstar;
198  Evaluation rhobar = rho / thcond_rhostar;
199 
200  /* fast implementation... minimised calls to 'pow' routine... */
201  Evaluation Troot = sqrt(Tbar);
202  Evaluation Tpow = Troot;
203  Evaluation lam = 0;
204 
205  for(int k = 0; k < thcond_a_count; ++k) {
206  lam += thcond_a[k] * Tpow;
207  Tpow *= Tbar;
208  }
209 
210  lam +=
211  thcond_b0 + thcond_b1
212  * rhobar + thcond_b2
213  * exp(thcond_B1 * ((rhobar + thcond_B2)*(rhobar + thcond_B2)));
214 
215  Evaluation DTbar = abs(Tbar - 1) + thcond_c4;
216  Evaluation DTbarpow = pow(DTbar, 3./5);
217  Evaluation Q = 2. + thcond_c5 / DTbarpow;
218 
219  Evaluation S;
220  if(Tbar >= 1)
221  S = 1. / DTbar;
222  else
223  S = thcond_c6 / DTbarpow;
224 
225  Evaluation rhobar18 = pow(rhobar, 1.8);
226  Evaluation rhobarQ = pow(rhobar, Q);
227 
228  lam +=
229  (thcond_d1 / pow(Tbar,10.0) + thcond_d2) * rhobar18 *
230  exp(thcond_c1 * (1 - rhobar * rhobar18))
231  + thcond_d3 * S * rhobarQ *
232  exp((Q/(1+Q))*(1 - rhobar*rhobarQ))
233  + thcond_d4 *
234  exp(thcond_c2 * pow(Troot,3.0) + thcond_c3 / pow(rhobar,5.0));
235  return /*thcond_kstar * */ lam;
236  }
237 };
238 
239 } // namespace IAPWS
240 } // namespace Opm
241 
242 #endif
static constexpr Scalar acentricFactor
The acentric factor of water .
Definition: Common.hpp:80
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
static OPM_HOST_DEVICE Evaluation thermalConductivityIAPWS(const Evaluation &T, const Evaluation &rho)
Thermal conductivity water (IAPWS) .
Definition: Common.hpp:166
Definition: Constants.hpp:41
static constexpr Scalar tripleTemperature
Triple temperature of water .
Definition: Common.hpp:83
static constexpr Scalar criticalTemperature
Critical temperature of water .
Definition: Common.hpp:65
static constexpr Scalar criticalMolarVolume
Critical molar volume of water .
Definition: Common.hpp:77
static OPM_HOST_DEVICE Evaluation viscosity(const Evaluation &temperature, const Evaluation &rho)
The dynamic viscosity of pure water.
Definition: Common.hpp:103
Implements relations which are common for all regions of the IAPWS &#39;97 formulation.
Definition: Common.hpp:55
static constexpr Scalar criticalDensity
Density of water at the critical point .
Definition: Common.hpp:71
static constexpr Scalar criticalVolume
Critical volume of water .
Definition: Common.hpp:74
static constexpr Scalar Rs
Specific gas constant of water .
Definition: Common.hpp:62
static constexpr Scalar criticalPressure
Critical pressure of water .
Definition: Common.hpp:68
static constexpr Scalar molarMass
The molar mass of water .
Definition: Common.hpp:59
static constexpr Scalar triplePressure
Triple pressure of water .
Definition: Common.hpp:86