opm-common
H2GasPvt.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_H2_GAS_PVT_HPP
28 #define OPM_H2_GAS_PVT_HPP
29 
35 
36 #include <cstddef>
37 #include <vector>
38 
39 namespace Opm {
40 
41 class EclipseState;
42 class Schedule;
43 
47 template <class Scalar>
48 class H2GasPvt
49 {
52  using H2 = ::Opm::H2<Scalar>;
53  static const bool extrapolate = true;
54 
55 public:
56  // The binary coefficients for brine and H2 used by this fluid system
58 
59  explicit H2GasPvt() = default;
60 
61  explicit H2GasPvt(const std::vector<Scalar>& salinity,
62  Scalar T_ref = 288.71, //(273.15 + 15.56)
63  Scalar P_ref = 101325);
64 
68  void initFromState(const EclipseState& eclState, const Schedule&);
69 
70  void setNumRegions(std::size_t numRegions);
71 
72  void setVapPars(const Scalar, const Scalar)
73  {
74  }
75 
79  void setReferenceDensities(unsigned regionIdx,
80  Scalar rhoRefBrine,
81  Scalar rhoRefGas,
82  Scalar /*rhoRefWater*/);
83 
90  void setEnableVaporizationWater(bool yesno)
91  { enableVaporization_ = yesno; }
92 
96  void initEnd()
97  {
98  }
99 
103  unsigned numRegions() const
104  { return gasReferenceDensity_.size(); }
105 
106  Scalar hVap(unsigned ) const
107  { return 0.0; }
108 
113  template <class Evaluation>
114  Evaluation internalEnergy(unsigned /*regionIdx*/,
115  const Evaluation& temperature,
116  const Evaluation& pressure,
117  const Evaluation& /*rv*/,
118  const Evaluation& /*rvw*/) const
119  {
120  // use the gasInternalEnergy of H2
121  return H2::gasInternalEnergy(temperature, pressure, extrapolate);
122 
123  // TODO: account for H2O in the gas phase
124  // Init output
125  //Evaluation result = 0;
126 
127  // We have to check that one of RV and RVW is zero since H2STORE works with either GAS/WATER or GAS/OIL system
128  //assert(rv == 0.0 || rvw == 0.0);
129 
130  // Calculate each component contribution and return weighted sum
131  //const Evaluation xBrine = convertRvwToXgW_(max(rvw, rv), regionIdx);
132  //result += xBrine * H2O::gasInternalEnergy(temperature, pressure);
133  //result += (1 - xBrine) * H2::gasInternalEnergy(temperature, pressure, extrapolate);
134  //return result;
135  }
136 
140  template <class Evaluation>
141  Evaluation viscosity(unsigned regionIdx,
142  const Evaluation& temperature,
143  const Evaluation& pressure,
144  const Evaluation& /*Rv*/,
145  const Evaluation& /*Rvw*/) const
146  {
147  return saturatedViscosity(regionIdx, temperature, pressure);
148  }
149 
153  template <class Evaluation>
154  Evaluation saturatedViscosity(unsigned /*regionIdx*/,
155  const Evaluation& temperature,
156  const Evaluation& pressure) const
157  {
158  return H2::gasViscosity(temperature, pressure, extrapolate);
159  }
160 
164  template <class Evaluation>
165  Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
166  const Evaluation& temperature,
167  const Evaluation& pressure,
168  const Evaluation& rv,
169  const Evaluation& rvw) const
170  {
171  // If vaporization is disabled, return H2 gas volume factor
172  if (!enableVaporization_) {
173  return H2::gasDensity(temperature, pressure, extrapolate) /
174  gasReferenceDensity_[regionIdx];
175  }
176 
177  // Use CO2 density for the gas phase.
178  const auto& rhoH2 = H2::gasDensity(temperature, pressure, extrapolate);
179  //const auto& rhoH2O = H2O::gasDensity(temperature, pressure);
180  //The H2STORE option both works for GAS/WATER and GAS/OIL systems
181  //Either rv og rvw should be zero
182  //assert(rv == 0.0 || rvw == 0.0);
183  //const Evaluation xBrine = convertRvwToXgW_(max(rvw,rv),regionIdx);
184  //const auto rho = 1.0/(xBrine/rhoH2O + (1.0 - xBrine)/rhoH2);
185  return rhoH2 / (gasReferenceDensity_[regionIdx] +
186  max(rvw,rv) * brineReferenceDensity_[regionIdx]);
187  }
188 
192  template <class FluidState, class LhsEval = typename FluidState::ValueType>
193  std::pair<LhsEval, LhsEval>
194  inverseFormationVolumeFactorAndViscosity(const FluidState& fluidState, unsigned regionIdx)
195  {
196  const LhsEval& T = decay<LhsEval>(fluidState.temperature(FluidState::gasPhaseIdx));
197  const LhsEval& p = decay<LhsEval>(fluidState.pressure(FluidState::gasPhaseIdx));
198  const LhsEval& Rv = decay<LhsEval>(fluidState.Rv());
199  const LhsEval& Rvw = decay<LhsEval>(fluidState.Rvw());
200  return { this->inverseFormationVolumeFactor(regionIdx, T, p, Rv, Rvw),
201  this->viscosity(regionIdx, T, p, Rv, Rvw) };
202  }
203 
207  template <class Evaluation>
208  Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
209  const Evaluation& temperature,
210  const Evaluation& pressure) const
211  {
212  const Evaluation rvw = rvwSat_(regionIdx, temperature, pressure,
213  Evaluation(salinity_[regionIdx]));
214  return inverseFormationVolumeFactor(regionIdx, temperature, pressure,
215  Evaluation(0.0), rvw);
216  }
217 
225  template <class Evaluation>
226  Evaluation saturationPressure(unsigned /*regionIdx*/,
227  const Evaluation& /*temperature*/,
228  const Evaluation& /*Rv*/) const
229  { return 0.0; /* Not implemented! */ }
230 
234  template <class Evaluation>
235  Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
236  const Evaluation& temperature,
237  const Evaluation& pressure) const
238  {
239  return rvwSat_(regionIdx, temperature, pressure, Evaluation(salinity_[regionIdx]));
240  }
241 
245  template <class Evaluation = Scalar>
246  Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
247  const Evaluation& temperature,
248  const Evaluation& pressure,
249  const Evaluation& saltConcentration) const
250  {
251  const Evaluation salinity = salinityFromConcentration(temperature, pressure,
252  saltConcentration);
253  return rvwSat_(regionIdx, temperature, pressure, salinity);
254  }
255 
259  template <class Evaluation>
260  Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
261  const Evaluation& temperature,
262  const Evaluation& pressure,
263  const Evaluation& /*oilSaturation*/,
264  const Evaluation& /*maxOilSaturation*/) const
265  {
266  return rvwSat_(regionIdx, temperature, pressure, Evaluation(salinity_[regionIdx]));
267  }
268 
272  template <class Evaluation>
273  Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
274  const Evaluation& temperature,
275  const Evaluation& pressure) const
276  {
277  return rvwSat_(regionIdx, temperature, pressure, Evaluation(salinity_[regionIdx]));
278  }
279 
280  template <class Evaluation>
281  Evaluation diffusionCoefficient(const Evaluation& temperature,
282  const Evaluation& pressure,
283  unsigned /*compIdx*/) const
284  {
285  return BinaryCoeffBrineH2::gasDiffCoeff(temperature, pressure);
286  }
287 
288  Scalar gasReferenceDensity(unsigned regionIdx) const
289  { return gasReferenceDensity_[regionIdx]; }
290 
291  Scalar oilReferenceDensity(unsigned regionIdx) const
292  { return brineReferenceDensity_[regionIdx]; }
293 
294  Scalar waterReferenceDensity(unsigned regionIdx) const
295  { return brineReferenceDensity_[regionIdx]; }
296 
297  Scalar salinity(unsigned regionIdx) const
298  { return salinity_[regionIdx]; }
299 
300 private:
301  template <class LhsEval>
302  LhsEval rvwSat_(unsigned regionIdx,
303  const LhsEval& temperature,
304  const LhsEval& pressure,
305  const LhsEval& salinity) const
306  {
307  // If water vaporization is disabled, we return zero
308  if (!enableVaporization_) {
309  return 0.0;
310  }
311 
312  // From Li et al., Int. J. Hydrogen Energ., 2018, water mole fraction is calculated assuming ideal mixing
313  LhsEval pw_sat = H2O::vaporPressure(temperature);
314  LhsEval yH2O = pw_sat / pressure;
315 
316  // normalize the phase compositions
317  yH2O = max(0.0, min(1.0, yH2O));
318  return convertXgWToRvw(convertxgWToXgW(yH2O, salinity), regionIdx);
319  }
320 
325  template <class LhsEval>
326  LhsEval convertXgWToRvw(const LhsEval& XgW, unsigned regionIdx) const
327  {
328  Scalar rho_wRef = brineReferenceDensity_[regionIdx];
329  Scalar rho_gRef = gasReferenceDensity_[regionIdx];
330 
331  return XgW / (1.0 - XgW) * (rho_gRef / rho_wRef);
332  }
333 
338  template <class LhsEval>
339  LhsEval convertRvwToXgW_(const LhsEval& Rvw, unsigned regionIdx) const
340  {
341  Scalar rho_wRef = brineReferenceDensity_[regionIdx];
342  Scalar rho_gRef = gasReferenceDensity_[regionIdx];
343 
344  const LhsEval& rho_wG = Rvw * rho_wRef;
345  return rho_wG / (rho_gRef + rho_wG);
346  }
347 
351  template <class LhsEval>
352  LhsEval convertxgWToXgW(const LhsEval& xgW, const LhsEval& salinity) const
353  {
354  Scalar M_H2 = H2::molarMass();
355  LhsEval M_Brine = Brine::molarMass(salinity);
356 
357  return xgW * M_Brine / (xgW * (M_Brine - M_H2) + M_H2);
358  }
359 
360  template <class LhsEval>
361  const LhsEval salinityFromConcentration(const LhsEval&T, const LhsEval& P,
362  const LhsEval& saltConcentration) const
363  {
364  return saltConcentration / H2O::liquidDensity(T, P, true);
365  }
366 
367  std::vector<Scalar> gasReferenceDensity_{};
368  std::vector<Scalar> brineReferenceDensity_{};
369  std::vector<Scalar> salinity_{};
370  bool enableVaporization_ = true;
371 }; // end class H2GasPvt
372 
373 } // end namspace Opm
374 
375 #endif
Properties of pure molecular hydrogen .
A class for the brine fluid properties.
Definition: BrineDynamic.hpp:48
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &, const Evaluation &) const
Returns the oil vaporization factor [m^3/m^3] of the oil phase.
Definition: H2GasPvt.hpp:260
void initFromState(const EclipseState &eclState, const Schedule &)
Initialize the parameters for H2 gas using an ECL deck.
Definition: H2GasPvt.cpp:51
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition: H2GasPvt.hpp:235
static OPM_HOST_DEVICE Evaluation vaporPressure(const Evaluation &T)
The vapor pressure in of pure water at a given temperature.
Definition: SimpleHuDuanH2O.hpp:143
static constexpr Scalar molarMass()
The molar mass in of molecular hydrogen.
Definition: H2.hpp:109
std::pair< LhsEval, LhsEval > inverseFormationVolumeFactorAndViscosity(const FluidState &fluidState, unsigned regionIdx)
Returns the formation volume factor [-] and viscosity [Pa s] of the fluid phase.
Definition: H2GasPvt.hpp:194
Definition: Schedule.hpp:102
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &rv, const Evaluation &rvw) const
Returns the formation volume factor [-] of the fluid phase.
Definition: H2GasPvt.hpp:165
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the formation volume factor [-] of oil saturated gas at given pressure.
Definition: H2GasPvt.hpp:208
This class represents the Pressure-Volume-Temperature relations of the gas phase for H2...
Definition: H2GasPvt.hpp:48
static Evaluation gasViscosity(const Evaluation &temperature, const Evaluation &pressure, bool extrapolate=false)
The dynamic viscosity of at a given pressure and temperature.
Definition: H2.hpp:285
void setEnableVaporizationWater(bool yesno)
Specify whether the PVT model should consider that the water component can vaporize in the gas phase...
Definition: H2GasPvt.hpp:90
void initEnd()
Finish initializing the oil phase PVT properties.
Definition: H2GasPvt.hpp:96
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
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefBrine, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition: H2GasPvt.cpp:91
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: H2GasPvt.hpp:103
Definition: EclipseState.hpp:66
Binary coefficients for brine and H2.
Definition: Brine_H2.hpp:41
A simple version of pure water with density from Hu et al.
static Evaluation gasDiffCoeff(const Evaluation &temperature, const Evaluation &pressure)
Binary diffusion coefficent [m^2/s] for molecular water and H2 as an approximation for brine-H2 diffu...
Definition: Brine_H2.hpp:187
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &saltConcentration) const
Returns the water vaporization factor [m^3/m^3] of water saturated gas.
Definition: H2GasPvt.hpp:246
Evaluation saturationPressure(unsigned, const Evaluation &, const Evaluation &) const
Returns the saturation pressure of the gas phase [Pa] depending on its mass fraction of the oil compo...
Definition: H2GasPvt.hpp:226
Implements a scalar function that depends on two variables and which is sampled on an uniform X-Y gri...
A simple version of pure water with density from Hu et al.
Definition: SimpleHuDuanH2O.hpp:65
Evaluation viscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &, const Evaluation &) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: H2GasPvt.hpp:141
Evaluation internalEnergy(unsigned, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &, const Evaluation &) const
Returns the specific enthalpy [J/kg] of gas given a set of parameters.
Definition: H2GasPvt.hpp:114
Evaluation saturatedViscosity(unsigned, const Evaluation &temperature, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of oil saturated gas at given pressure.
Definition: H2GasPvt.hpp:154
A class for the brine fluid properties.
Binary coefficients for brine and H2.
static Evaluation gasDensity(Evaluation temperature, Evaluation pressure, bool extrapolate=false)
The density of at a given pressure and temperature.
Definition: H2.hpp:200
static Scalar molarMass()
The molar mass in of the component.
Definition: Component.hpp:93
Properties of pure molecular hydrogen .
Definition: H2.hpp:89
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the oil vaporization factor [m^3/m^3] of the oil phase.
Definition: H2GasPvt.hpp:273
static Evaluation gasInternalEnergy(const Evaluation &temperature, const Evaluation &pressure, bool extrapolate=false)
Specific internal energy of H2 [J/kg].
Definition: H2.hpp:249