opm-common
SimpleHuDuanH2O.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_SIMPLE_HU_DUAN_H2O_HPP
28 #define OPM_SIMPLE_HU_DUAN_H2O_HPP
29 
30 #include "Component.hpp"
31 #include "iapws/Common.hpp"
32 
34 #include <opm/common/TimingMacros.hpp>
35 #include <opm/common/OpmLog/OpmLog.hpp>
36 
39 
40 #include <cassert>
41 #include <cmath>
42 #include <string_view>
43 
44 namespace Opm {
45 
64 template <class Scalar>
65 class SimpleHuDuanH2O : public Component<Scalar, SimpleHuDuanH2O<Scalar>>
66 {
69 
70  static constexpr Scalar R = Constants<Scalar>::R / 18e-3; // specific gas constant of water
71 
72 public:
73  // OPM_HOST_DEVICE static Scalar R_()
74  // { return Scalar(R); }
75 
79  OPM_HOST_DEVICE static std::string_view name()
80  { return "H2O"; }
81 
85  OPM_HOST_DEVICE static bool gasIsCompressible()
86  { return true; }
87 
91  OPM_HOST_DEVICE static bool liquidIsCompressible()
92  { return false; }
93 
97  OPM_HOST_DEVICE static bool gasIsIdeal()
98  { return true; }
99 
103  OPM_HOST_DEVICE static Scalar molarMass()
104  { return 18e-3; }
105 
109  OPM_HOST_DEVICE static Scalar criticalTemperature()
110  { return 647.096; /* [K] */ }
111 
115  OPM_HOST_DEVICE static Scalar criticalPressure()
116  { return 22.064e6; /* [N/m^2] */ }
117 
121  OPM_HOST_DEVICE static Scalar tripleTemperature()
122  { return 273.16; /* [K] */ }
123 
127  OPM_HOST_DEVICE static Scalar triplePressure()
128  { return 611.657; /* [N/m^2] */ }
129 
142  template <class Evaluation>
143  OPM_HOST_DEVICE static Evaluation vaporPressure(const Evaluation& T)
144  {
145 
146  OPM_TIMEFUNCTION_LOCAL(Subsystem::PvtProps);
147  if (T > criticalTemperature())
148  return criticalPressure();
149  if (T < tripleTemperature())
150  return 0; // water is solid: We don't take sublimation into account
151 
152  static constexpr Scalar n[10] = {
153  0.11670521452767e4, -0.72421316703206e6, -0.17073846940092e2,
154  0.12020824702470e5, -0.32325550322333e7, 0.14915108613530e2,
155  -0.48232657361591e4, 0.40511340542057e6, -0.23855557567849,
156  0.65017534844798e3
157  };
158 
159  Evaluation sigma = T + n[8]/(T - n[9]);
160 
161  Evaluation A = (sigma + n[0])*sigma + n[1];
162  Evaluation B = (n[2]*sigma + n[3])*sigma + n[4];
163  Evaluation C = (n[5]*sigma + n[6])*sigma + n[7];
164 
165  Evaluation tmp = 2.0*C/(sqrt(B*B - 4.0*A*C) - B);
166  tmp *= tmp;
167  tmp *= tmp;
168 
169  return 1e6*tmp;
170  }
171 
178  template <class Evaluation>
179  OPM_HOST_DEVICE static Evaluation gasEnthalpy(const Evaluation& temperature,
180  const Evaluation& /*pressure*/)
181  { return 1.976e3*temperature + 40.65e3/molarMass(); }
182 
183 
187  template <class Evaluation>
188  OPM_HOST_DEVICE static Evaluation gasHeatCapacity(const Evaluation&,
189  const Evaluation&)
190  { return 1.976e3; }
191 
201  template <class Evaluation>
202  OPM_HOST_DEVICE static Evaluation liquidEnthalpy(const Evaluation& temperature,
203  const Evaluation& /*pressure*/)
204  { return (temperature - 288.71) * (4.18060737e+03 + 8.64644981e-02 * (temperature - 288.71)); }
205 
209  template <class Evaluation>
210  OPM_HOST_DEVICE static Evaluation liquidHeatCapacity(const Evaluation&,
211  const Evaluation&)
212  { return 4.184e3; }
213 
227  template <class Evaluation>
228  OPM_HOST_DEVICE static Evaluation gasInternalEnergy(const Evaluation& temperature,
229  const Evaluation& pressure)
230  {
231  return
232  gasEnthalpy(temperature, pressure) -
233  1/molarMass()* // conversion from [J/(mol K)] to [J/(kg K)]
234  IdealGas::R*temperature; // = pressure *spec. volume for an ideal gas
235  }
236 
244  template <class Evaluation>
245  OPM_HOST_DEVICE static Evaluation
246  liquidInternalEnergy(const Evaluation& temperature,
247  const Evaluation& pressure,
248  bool extrapolate)
249  {
250  return
251  liquidEnthalpy(temperature, pressure) -
252  pressure/liquidDensity(temperature, pressure, extrapolate);
253  }
254 
261  template <class Evaluation>
262  OPM_HOST_DEVICE static Evaluation liquidThermalConductivity(const Evaluation& /*temperature*/,
263  const Evaluation& /*pressure*/)
264  {
265  return 0.578078; // conductivity of liquid water [W / (m K ) ] IAPWS evaluated at p=.1 MPa, T=8°C
266  }
267 
274  template <class Evaluation>
275  OPM_HOST_DEVICE static Evaluation gasThermalConductivity(const Evaluation& /*temperature*/,
276  const Evaluation& /*pressure*/)
277  {
278  return 0.028224; // conductivity of steam [W / (m K ) ] IAPWS evaluated at p=.1 MPa, T=8°C
279  }
280 
287  template <class Evaluation>
288  OPM_HOST_DEVICE static Evaluation gasDensity(const Evaluation& temperature, const Evaluation& pressure)
289  {
290  // Assume an ideal gas
291  return molarMass()*IdealGas::molarDensity(temperature, pressure);
292  }
293 
300  template <class Evaluation>
301  OPM_HOST_DEVICE static Evaluation gasPressure(const Evaluation& temperature, const Evaluation& density)
302  {
303  // Assume an ideal gas
304  return IdealGas::pressure(temperature, density/molarMass());
305  }
306 
315  template <class Evaluation>
316  OPM_HOST_DEVICE static Evaluation liquidDensity(const Evaluation& temperature, const Evaluation& pressure,
317  bool extrapolate)
318  {
319  return liquidDensity_(temperature, pressure, extrapolate);
320  }
321 
328  template <class Evaluation>
329  OPM_HOST_DEVICE static Evaluation liquidPressure(const Evaluation& /*temperature*/, const Evaluation& /*density*/)
330  {
331 #if OPM_IS_INSIDE_DEVICE_FUNCTION
332  assert(false && "The liquid pressure is undefined for incompressible fluids");
333 #else
334  throw std::logic_error("The liquid pressure is undefined for incompressible fluids");
335 #endif
336  }
337 
345  template <class Evaluation>
346  OPM_HOST_DEVICE static Evaluation gasViscosity(const Evaluation& /*temperature*/,
347  const Evaluation& /*pressure*/)
348  {
349  return 1e-05;
350  }
351 
360  template <class Evaluation>
361  OPM_HOST_DEVICE static Evaluation liquidViscosity(const Evaluation& temperature, const Evaluation& pressure,
362  bool extrapolate)
363  {
364  if (temperature > 570) {
365 // This preprocessing statement loses this warning message
366 // But printing it possibly thousands of times inside a gpu function also seems problematic
367 #if !OPM_IS_INSIDE_DEVICE_FUNCTION
368  const std::string msg =
369  "Viscosity of water based on Hu et al is too "
370  "different from IAPWS for T above 570K and (T = " +
371  std::to_string(getValue(temperature)) + ")";
372  if (extrapolate)
373  {
374  OpmLog::warning(msg);
375  }
376  else
377  throw NumericalProblem(msg);
378 #else
379  // no warning on the GPU when using extrapolate is somewhat bad,
380  // but how does one tame warning output when encountered by thousands of threads?
381  if (!extrapolate) {
382  assert(false && "Viscosity of water based on Hu et al is too different from IAPWS for T above 570K");
383  }
384 #endif
385  }
386 
387  const Evaluation rho = liquidDensity(temperature, pressure, extrapolate);
388  return Common::viscosity(temperature, rho);
389  }
390 
391 private:
392 
401  template <class Evaluation>
402  OPM_HOST_DEVICE static Evaluation liquidDensity_(const Evaluation& T, const Evaluation& pressure, bool extrapolate) {
403  // Hu, Duan, Zhu and Chou: PVTx properties of the CO2-H2O and CO2-H2O-NaCl
404  // systems below 647 K: Assessment of experimental data and
405  // thermodynamics models, Chemical Geology, 2007.
406  OPM_TIMEBLOCK_LOCAL(liquidDensity_, Subsystem::PvtProps);
407  if (T > 647 || pressure > 100e6) {
408 #if !OPM_IS_INSIDE_DEVICE_FUNCTION
409  const std::string msg =
410  "Density of water is only implemented for temperatures "
411  "below 647K and pressures below 100MPa. (T = " +
412  std::to_string(getValue(T)) + ", p=" +
413  std::to_string(getValue(pressure)) + ")";
414  if (extrapolate)
415  {
416  OpmLog::warning(msg);
417  }
418  else
419  throw NumericalProblem(msg);
420 #else
421  // no warning on the GPU when using extrapolate is somewhat bad,
422  // but how does one tame warning output when encountered by thousands of threads?
423  if (!extrapolate) {
424  assert(false && "Density of water is only implemented for temperatures below 647K and pressures below 100MPa");
425  }
426 #endif
427  }
428 
429  Evaluation p = pressure / 1e6; // to MPa
430  Scalar Mw = molarMass() * 1e3; //kg/kmol
431 
432  static constexpr Scalar k0[5] = { 3.27225e-07, -4.20950e-04, 2.32594e-01, -4.16920e+01, 5.71292e+03 };
433  static constexpr Scalar k1[5] = { -2.32306e-10, 2.91138e-07, -1.49662e-04, 3.59860e-02, -3.55071 };
434  static constexpr Scalar k2[3] = { 2.57241e-14, -1.24336e-11, 5.42707e-07 };
435  static constexpr Scalar k3[3] = { -4.42028e-18, 2.10007e-15, -8.11491e-11 };
436  Evaluation k0_eval = 1e-3 * (((k0[0]*T + k0[1])*T + k0[2])*T + k0[3] + k0[4]/T);
437  Evaluation k1_eval = 1e-2 * (((k1[0]*T + k1[1])*T + k1[2])*T + k1[3] + k1[4]/T);
438  Evaluation k2_eval = 1e-1 * ((k2[0]*T + k2[1])*T*T + k2[2]);
439  Evaluation k3_eval = (k3[0]*T + k3[1])*T*T + k3[2];
440 
441  // molar volum (m³/kmol):
442  Evaluation vw = ((k3_eval*p + k2_eval)*p + k1_eval)*p + k0_eval;
443 
444  // density kg/m3
445  return Mw / vw;
446 
447  }
448 
449 };
450 
451 } // namespace Opm
452 
453 #endif
static OPM_HOST_DEVICE Evaluation gasHeatCapacity(const Evaluation &, const Evaluation &)
Specific isobaric heat capacity of the component [J/kg] as a gas.
Definition: SimpleHuDuanH2O.hpp:188
static OPM_HOST_DEVICE Evaluation pressure(const Evaluation &temperature, const Evaluation &rhoMolar)
The pressure of the gas in , depending on the molar density and temperature.
Definition: IdealGas.hpp:59
static OPM_HOST_DEVICE Evaluation gasViscosity(const Evaluation &, const Evaluation &)
The dynamic viscosity of steam.
Definition: SimpleHuDuanH2O.hpp:346
static OPM_HOST_DEVICE Evaluation liquidInternalEnergy(const Evaluation &temperature, const Evaluation &pressure, bool extrapolate)
Specific internal energy of liquid water .
Definition: SimpleHuDuanH2O.hpp:246
Definition: Exceptions.hpp:39
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
static OPM_HOST_DEVICE Evaluation vaporPressure(const Evaluation &T)
The vapor pressure in of pure water at a given temperature.
Definition: SimpleHuDuanH2O.hpp:143
Relations valid for an ideal gas.
Abstract base class of a pure chemical species.
Definition: Component.hpp:43
static OPM_HOST_DEVICE Scalar criticalTemperature()
Returns the critical temperature of water.
Definition: SimpleHuDuanH2O.hpp:109
static OPM_HOST_DEVICE Evaluation gasPressure(const Evaluation &temperature, const Evaluation &density)
The pressure of steam in at a given density and temperature.
Definition: SimpleHuDuanH2O.hpp:301
static OPM_HOST_DEVICE bool gasIsCompressible()
Returns true iff the gas phase is assumed to be compressible.
Definition: SimpleHuDuanH2O.hpp:85
static OPM_HOST_DEVICE Evaluation liquidViscosity(const Evaluation &temperature, const Evaluation &pressure, bool extrapolate)
The dynamic viscosity of pure water.
Definition: SimpleHuDuanH2O.hpp:361
static OPM_HOST_DEVICE Evaluation liquidEnthalpy(const Evaluation &temperature, const Evaluation &)
Specific enthalpy of liquid water .
Definition: SimpleHuDuanH2O.hpp:202
static OPM_HOST_DEVICE Scalar tripleTemperature()
Returns the temperature at water&#39;s triple point.
Definition: SimpleHuDuanH2O.hpp:121
static OPM_HOST_DEVICE Scalar molarMass()
The molar mass in of water.
Definition: SimpleHuDuanH2O.hpp:103
static constexpr Scalar R
The ideal gas constant .
Definition: IdealGas.hpp:42
Provides the OPM specific exception classes.
static OPM_HOST_DEVICE Evaluation liquidHeatCapacity(const Evaluation &, const Evaluation &)
Specific isobaric heat capacity of the component [J/kg] as a liquid.
Definition: SimpleHuDuanH2O.hpp:210
static OPM_HOST_DEVICE Evaluation liquidDensity(const Evaluation &temperature, const Evaluation &pressure, bool extrapolate)
The density of pure water at a given pressure and temperature .
Definition: SimpleHuDuanH2O.hpp:316
static OPM_HOST_DEVICE Scalar criticalPressure()
Returns the critical pressure of water.
Definition: SimpleHuDuanH2O.hpp:115
static OPM_HOST_DEVICE Evaluation gasDensity(const Evaluation &temperature, const Evaluation &pressure)
The density of steam at a given pressure and temperature.
Definition: SimpleHuDuanH2O.hpp:288
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
static OPM_HOST_DEVICE bool liquidIsCompressible()
Returns true iff the liquid phase is assumed to be compressible.
Definition: SimpleHuDuanH2O.hpp:91
static OPM_HOST_DEVICE Evaluation gasEnthalpy(const Evaluation &temperature, const Evaluation &)
Specific enthalpy of water steam .
Definition: SimpleHuDuanH2O.hpp:179
Definition: Constants.hpp:41
Abstract base class of a pure chemical species.
Relations valid for an ideal gas.
Definition: IdealGas.hpp:38
static OPM_HOST_DEVICE bool gasIsIdeal()
Returns true iff the gas phase is assumed to be ideal.
Definition: SimpleHuDuanH2O.hpp:97
static OPM_HOST_DEVICE Evaluation gasThermalConductivity(const Evaluation &, const Evaluation &)
Specific heat conductivity of steam .
Definition: SimpleHuDuanH2O.hpp:275
static OPM_HOST_DEVICE Evaluation viscosity(const Evaluation &temperature, const Evaluation &rho)
The dynamic viscosity of pure water.
Definition: Common.hpp:103
static OPM_HOST_DEVICE Evaluation gasInternalEnergy(const Evaluation &temperature, const Evaluation &pressure)
Specific internal energy of steam .
Definition: SimpleHuDuanH2O.hpp:228
A simple version of pure water with density from Hu et al.
Definition: SimpleHuDuanH2O.hpp:65
Implements relations which are common for all regions of the IAPWS &#39;97 formulation.
Definition: Common.hpp:55
static OPM_HOST_DEVICE std::string_view name()
A human readable name for the water.
Definition: SimpleHuDuanH2O.hpp:79
static OPM_HOST_DEVICE Evaluation molarDensity(const Evaluation &temperature, const Evaluation &pressure)
The molar density of the gas , depending on pressure and temperature.
Definition: IdealGas.hpp:68
static OPM_HOST_DEVICE Evaluation liquidPressure(const Evaluation &, const Evaluation &)
The pressure of water in at a given density and temperature.
Definition: SimpleHuDuanH2O.hpp:329
Implements relations which are common for all regions of the IAPWS &#39;97 formulation.
static OPM_HOST_DEVICE Evaluation liquidThermalConductivity(const Evaluation &, const Evaluation &)
Specific heat conductivity of liquid water .
Definition: SimpleHuDuanH2O.hpp:262
static OPM_HOST_DEVICE Scalar triplePressure()
Returns the pressure at water&#39;s triple point.
Definition: SimpleHuDuanH2O.hpp:127