opm-common
CO2.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 */
28 #ifndef OPM_CO2_HPP
29 #define OPM_CO2_HPP
30 
31 #include <opm/common/TimingMacros.hpp>
32 #include <opm/common/ErrorMacros.hpp>
33 #include <opm/common/utility/gpuDecorators.hpp>
39 #include <opm/material/components/CO2Tables.hpp>
40 
41 #include <cmath>
42 #include <string_view>
43 
44 namespace Opm {
45 
56 template <class Scalar, class ParamsT = Opm::CO2Tables<double, VectorWithDefaultAllocator>>
57 class CO2 : public Component<Scalar, CO2<Scalar>>
58 {
59 public:
60  using Params = ParamsT;
61 
62  static constexpr const Scalar brineSalinity = 1.000000000000000e-01;
63 
67  OPM_HOST_DEVICE static std::string_view name()
68  { return "CO2"; }
69 
73  OPM_HOST_DEVICE static Scalar molarMass()
74  { return 44e-3; }
75 
79  OPM_HOST_DEVICE static Scalar criticalTemperature()
80  { return 273.15 + 30.95; /* [K] */ }
81 
85  OPM_HOST_DEVICE static Scalar criticalPressure()
86  { return 73.8e5; /* [N/m^2] */ }
87 
91  OPM_HOST_DEVICE static Scalar tripleTemperature()
92  { return 273.15 - 56.35; /* [K] */ }
93 
97  OPM_HOST_DEVICE static Scalar triplePressure()
98  { return 5.11e5; /* [N/m^2] */ }
99 
103 // static Scalar minTabulatedPressure()
104 // { return tabulatedEnthalpy.minPress(); /* [N/m^2] */ }
105 
109 // static Scalar maxTabulatedPressure()
110 // { return tabulatedEnthalpy.maxPress(); /* [N/m^2] */ }
111 
115 // static Scalar minTabulatedTemperature()
116 // { return tabulatedEnthalpy.minTemp(); /* [N/m^2] */ }
117 
121 // static Scalar maxTabulatedTemperature()
122 // { return tabulatedEnthalpy.maxTemp(); /* [N/m^2] */ }
123 
136  template <class Evaluation>
137  OPM_HOST_DEVICE static Evaluation vaporPressure(const Evaluation& T)
138  {
139  static constexpr Scalar a[4] =
140  { -7.0602087, 1.9391218, -1.6463597, -3.2995634 };
141  static constexpr Scalar t[4] =
142  { 1.0, 1.5, 2.0, 4.0 };
143 
144  // this is on page 1524 of the reference
145  Evaluation exponent = 0;
146  Evaluation Tred = T/criticalTemperature();
147  for (int i = 0; i < 4; ++i)
148  exponent += a[i]*pow(1 - Tred, t[i]);
149  exponent *= 1.0/Tred;
150 
151  return exp(exponent)*criticalPressure();
152  }
153 
154 
158  OPM_HOST_DEVICE static bool gasIsCompressible()
159  { return true; }
160 
164  OPM_HOST_DEVICE static bool gasIsIdeal()
165  { return false; }
166 
170  template <class Evaluation>
171  OPM_HOST_DEVICE static Evaluation gasEnthalpy(const Params& params,
172  const Evaluation& temperature,
173  const Evaluation& pressure,
174  bool extrapolate = false)
175  {
176  return params.tabulatedEnthalpy.eval(temperature, pressure, extrapolate);
177  }
178 
183  template <class Evaluation>
184  OPM_HOST_DEVICE static Evaluation gasEnthalpy([[maybe_unused]] const Evaluation& temperature,
185  [[maybe_unused]] const Evaluation& pressure,
186  [[maybe_unused]] bool extrapolate = false)
187  {
188  OPM_THROW(std::runtime_error, "This function should not be called");
189  }
190 
194  template <class Evaluation>
195  OPM_HOST_DEVICE static Evaluation gasInternalEnergy(const Params& params,
196  const Evaluation& temperature,
197  const Evaluation& pressure,
198  bool extrapolate = false)
199  {
200  const Evaluation h = gasEnthalpy(params, temperature, pressure, extrapolate);
201  const Evaluation rho = gasDensity(params, temperature, pressure, extrapolate);
202 
203  return h - (pressure / rho);
204  }
205 
210  template <class Evaluation>
211  OPM_HOST_DEVICE static Evaluation gasInternalEnergy([[maybe_unused]] const Evaluation& temperature,
212  [[maybe_unused]] const Evaluation& pressure,
213  [[maybe_unused]] bool extrapolate = false)
214  {
215  OPM_THROW(std::runtime_error, "This function should not be called");
216  }
217 
221  template <class Evaluation>
222  OPM_HOST_DEVICE static Evaluation gasDensity(const Params& params,
223  const Evaluation& temperature,
224  const Evaluation& pressure,
225  bool extrapolate = false)
226  {
227  return params.tabulatedDensity.eval(temperature, pressure, extrapolate);
228  }
229 
234  template <class Evaluation>
235  OPM_HOST_DEVICE static Evaluation gasDensity([[maybe_unused]] const Evaluation& temperature,
236  [[maybe_unused]] const Evaluation& pressure,
237  [[maybe_unused]] bool extrapolate = false)
238  {
239  OPM_THROW(std::runtime_error, "This function should not be called");
240  }
241 
248  template <class Evaluation>
249  OPM_HOST_DEVICE static Evaluation gasViscosity(const Params& params,
250  Evaluation temperature,
251  const Evaluation& pressure,
252  bool extrapolate = false)
253  {
254  OPM_TIMEFUNCTION_LOCAL(Subsystem::PvtProps);
255  constexpr Scalar a0 = 0.235156;
256  constexpr Scalar a1 = -0.491266;
257  constexpr Scalar a2 = 5.211155e-2;
258  constexpr Scalar a3 = 5.347906e-2;
259  constexpr Scalar a4 = -1.537102e-2;
260 
261  constexpr Scalar d11 = 0.4071119e-2;
262  constexpr Scalar d21 = 0.7198037e-4;
263  constexpr Scalar d64 = 0.2411697e-16;
264  constexpr Scalar d81 = 0.2971072e-22;
265  constexpr Scalar d82 = -0.1627888e-22;
266 
267  constexpr Scalar ESP = 251.196;
268 
269  if(temperature < 275.) // regularization
270  temperature = 275.0;
271  Evaluation TStar = temperature/ESP;
272 
273  // mu0: viscosity in zero-density limit
274  const Evaluation logTStar = log(TStar);
275  Evaluation SigmaStar = exp(a0 + logTStar*(a1 + logTStar*(a2 + logTStar*(a3 + logTStar*a4))));
276 
277  Evaluation mu0 = 1.00697*sqrt(temperature) / SigmaStar;
278 
279  const Evaluation rho = gasDensity(params, temperature, pressure, extrapolate); // CO2 mass density [kg/m^3]
280 
281  // dmu : excess viscosity at elevated density
282  Evaluation dmu =
283  d11*rho
284  + d21*rho*rho
285  + d64*pow(rho, 6.0)/(TStar*TStar*TStar)
286  + d81*pow(rho, 8.0)
287  + d82*pow(rho, 8.0)/TStar;
288 
289  return (mu0 + dmu)/1.0e6; // conversion to [Pa s]
290  }
291 
297  template <class Evaluation>
298  OPM_HOST_DEVICE static Evaluation gasViscosity([[maybe_unused]] Evaluation temperature,
299  [[maybe_unused]] const Evaluation& pressure,
300  [[maybe_unused]] bool extrapolate = false)
301  {
302  OPM_THROW(std::runtime_error, "This function should not be called");
303  }
304 
316  template <class Evaluation>
317  OPM_HOST_DEVICE static Evaluation gasHeatCapacity(const Params& params,
318  const Evaluation& temperature,
319  const Evaluation& pressure)
320  {
321  OPM_TIMEFUNCTION_LOCAL(Subsystem::PvtProps);
322  constexpr Scalar eps = 1e-6;
323  // NB!! should be changed to using the derivative from the table (if piecwise linear double derivate is zero).
324  // use central differences here because one-sided methods do
325  // not come with a performance improvement. (central ones are
326  // more accurate, though...)
327  const Evaluation h1 = gasEnthalpy(params, temperature - eps, pressure);
328  const Evaluation h2 = gasEnthalpy(params, temperature + eps, pressure);
329 
330  return (h2 - h1) / (2*eps) ;
331  }
332 
338  template <class Evaluation>
339  OPM_HOST_DEVICE static Evaluation gasHeatCapacity([[maybe_unused]] const Evaluation& temperature, [[maybe_unused]] const Evaluation& pressure)
340  {
341  OPM_THROW(std::runtime_error, "This function should not be called");
342  }
343 };
344 
345 } // namespace Opm
346 
347 #endif
static OPM_HOST_DEVICE Evaluation gasInternalEnergy([[maybe_unused]] const Evaluation &temperature, [[maybe_unused]] const Evaluation &pressure, [[maybe_unused]] bool extrapolate=false)
Specific internal energy of CO2 [J/kg].
Definition: CO2.hpp:211
static OPM_HOST_DEVICE Scalar molarMass()
The mass in [kg] of one mole of CO2.
Definition: CO2.hpp:73
static OPM_HOST_DEVICE Evaluation gasViscosity(const Params &params, Evaluation temperature, const Evaluation &pressure, bool extrapolate=false)
The dynamic viscosity [Pa s] of CO2.
Definition: CO2.hpp:249
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
static OPM_HOST_DEVICE bool gasIsIdeal()
Returns true iff the gas phase is assumed to be ideal.
Definition: CO2.hpp:164
Relations valid for an ideal gas.
Abstract base class of a pure chemical species.
Definition: Component.hpp:43
static OPM_HOST_DEVICE Evaluation gasDensity(const Params &params, const Evaluation &temperature, const Evaluation &pressure, bool extrapolate=false)
The density of CO2 at a given pressure and temperature [kg/m^3].
Definition: CO2.hpp:222
static OPM_HOST_DEVICE Evaluation gasEnthalpy(const Params &params, const Evaluation &temperature, const Evaluation &pressure, bool extrapolate=false)
Specific enthalpy of gaseous CO2 [J/kg].
Definition: CO2.hpp:171
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
static OPM_HOST_DEVICE Evaluation gasViscosity([[maybe_unused]] Evaluation temperature, [[maybe_unused]] const Evaluation &pressure, [[maybe_unused]] bool extrapolate=false)
The dynamic viscosity [Pa s] of CO2.
Definition: CO2.hpp:298
static OPM_HOST_DEVICE Evaluation gasInternalEnergy(const Params &params, const Evaluation &temperature, const Evaluation &pressure, bool extrapolate=false)
Specific internal energy of CO2 [J/kg].
Definition: CO2.hpp:195
static OPM_HOST_DEVICE Evaluation gasDensity([[maybe_unused]] const Evaluation &temperature, [[maybe_unused]] const Evaluation &pressure, [[maybe_unused]] bool extrapolate=false)
The density of CO2 at a given pressure and temperature [kg/m^3].
Definition: CO2.hpp:235
static OPM_HOST_DEVICE bool gasIsCompressible()
Returns true iff the gas phase is assumed to be compressible.
Definition: CO2.hpp:158
static OPM_HOST_DEVICE std::string_view name()
A human readable name for the CO2.
Definition: CO2.hpp:67
Abstract base class of a pure chemical species.
A class for the CO2 fluid properties.
Definition: CO2.hpp:57
Implements a scalar function that depends on two variables and which is sampled on an uniform X-Y gri...
static OPM_HOST_DEVICE Scalar criticalTemperature()
Returns the critical temperature [K] of CO2.
Definition: CO2.hpp:79
static OPM_HOST_DEVICE Evaluation vaporPressure(const Evaluation &T)
Returns the pressure [Pa] at CO2&#39;s triple point.
Definition: CO2.hpp:137
static OPM_HOST_DEVICE Scalar tripleTemperature()
Returns the temperature [K]at CO2&#39;s triple point.
Definition: CO2.hpp:91
static OPM_HOST_DEVICE Evaluation gasHeatCapacity(const Params &params, const Evaluation &temperature, const Evaluation &pressure)
Specific isobaric heat capacity of the component [J/kg] as a liquid.
Definition: CO2.hpp:317
static OPM_HOST_DEVICE Scalar triplePressure()
Returns the pressure [Pa] at CO2&#39;s triple point.
Definition: CO2.hpp:97
static OPM_HOST_DEVICE Evaluation gasHeatCapacity([[maybe_unused]] const Evaluation &temperature, [[maybe_unused]] const Evaluation &pressure)
Specific isobaric heat capacity of the component [J/kg] as a liquid.
Definition: CO2.hpp:339
static OPM_HOST_DEVICE Evaluation gasEnthalpy([[maybe_unused]] const Evaluation &temperature, [[maybe_unused]] const Evaluation &pressure, [[maybe_unused]] bool extrapolate=false)
Specific enthalpy of gaseous CO2 [J/kg].
Definition: CO2.hpp:184
static OPM_HOST_DEVICE Scalar criticalPressure()
Returns the critical pressure [Pa] of CO2.
Definition: CO2.hpp:85