opm-common
DryHumidGasPvt.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_DRY_HUMID_GAS_PVT_HPP
28 #define OPM_DRY_HUMID_GAS_PVT_HPP
29 
31 #include <opm/common/OpmLog/OpmLog.hpp>
32 
37 
38 #include <cstddef>
39 
40 namespace Opm {
41 
42 class EclipseState;
43 class Schedule;
44 class SimpleTable;
45 
50 template <class Scalar>
52 {
53  using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
54 
55 public:
58 
64  void initFromState(const EclipseState& eclState, const Schedule&);
65 
66 private:
67  void extendPvtgwTable_(unsigned regionIdx,
68  unsigned xIdx,
69  const SimpleTable& curTable,
70  const SimpleTable& masterTable);
71 
72 public:
73  void setNumRegions(std::size_t numRegions);
74 
75  void setVapPars(const Scalar par1, const Scalar)
76  {
77  vapPar1_ = par1;
78  }
79 
83  void setReferenceDensities(unsigned regionIdx,
84  Scalar /*rhoRefOil*/,
85  Scalar rhoRefGas,
86  Scalar rhoRefWater);
87 
94  void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx,
95  const SamplingPoints& samplePoints)
96  { saturatedWaterVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
97 
110  void setInverseGasFormationVolumeFactor(unsigned regionIdx,
111  const TabulatedTwoDFunction& invBg)
112  { inverseGasB_[regionIdx] = invBg; }
113 
119  void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction& mug)
120  { gasMu_[regionIdx] = mug; }
121 
129  void setSaturatedGasViscosity(unsigned regionIdx,
130  const SamplingPoints& samplePoints);
131 
135  void initEnd();
136 
140  unsigned numRegions() const
141  { return gasReferenceDensity_.size(); }
142 
146  template <class Evaluation>
147  Evaluation internalEnergy(unsigned,
148  const Evaluation&,
149  const Evaluation&,
150  const Evaluation&,
151  const Evaluation&) const
152  {
153  throw std::runtime_error("Requested the enthalpy of gas but the thermal "
154  "option is not enabled");
155  }
156 
157  Scalar hVap(unsigned) const
158  {
159  throw std::runtime_error("Requested the hvap of oil but the thermal "
160  "option is not enabled");
161  }
162 
166  template <class Evaluation>
167  Evaluation viscosity(unsigned regionIdx,
168  const Evaluation& /*temperature*/,
169  const Evaluation& pressure,
170  const Evaluation& /*Rv*/,
171  const Evaluation& Rvw) const
172  {
173  const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
174  const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true);
175 
176  return invBg / invMugBg;
177  }
178 
182  template <class Evaluation>
183  Evaluation saturatedViscosity(unsigned regionIdx,
184  const Evaluation& /*temperature*/,
185  const Evaluation& pressure) const
186  {
187  const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
188  const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
189 
190  return invBg / invMugBg;
191  }
192 
196  template <class Evaluation>
197  Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
198  const Evaluation& /*temperature*/,
199  const Evaluation& pressure,
200  const Evaluation& /*Rv*/,
201  const Evaluation& Rvw) const
202  { return inverseGasB_[regionIdx].eval(pressure, Rvw, /*extrapolate=*/true); }
203 
207  template <class FluidState, class LhsEval = typename FluidState::ValueType>
208  std::pair<LhsEval, LhsEval>
209  inverseFormationVolumeFactorAndViscosity(const FluidState& fluidState, unsigned regionIdx)
210  {
211  const LhsEval& p = decay<LhsEval>(fluidState.pressure(FluidState::gasPhaseIdx));
212  const LhsEval& Rvw = decay<LhsEval>(fluidState.Rvw());
213 
214  const auto satSegIdx = this->saturatedWaterVaporizationFactorTable_[regionIdx].findSegmentIndex(p, /*extrapolate=*/ true);
215  const auto RvwSat = this->saturatedWaterVaporizationFactorTable_[regionIdx].eval(p, SegmentIndex{satSegIdx});
216  const bool useSaturatedTables = (fluidState.saturation(FluidState::waterPhaseIdx) > 0.0) && (Rvw >= (1.0 - 1e-10) * RvwSat);
217 
218  if (useSaturatedTables) {
219  const LhsEval b = this->inverseSaturatedGasB_[regionIdx].eval(p, SegmentIndex{satSegIdx});
220  const LhsEval invBMu = this->inverseSaturatedGasBMu_[regionIdx].eval(p, SegmentIndex{satSegIdx});
221  const LhsEval mu = b / invBMu;
222  return { b, mu };
223  } else {
224  unsigned ii, jj1, jj2;
225  LhsEval alpha, beta1, beta2;
226  this->inverseGasB_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, p, Rvw, /*extrapolate =*/ true);
227  const LhsEval b = this->inverseGasB_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
228  const LhsEval invBMu = this->inverseGasBMu_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
229  const LhsEval mu = b / invBMu;
230  return { b, mu };
231  }
232  }
233 
237  template <class Evaluation>
238  Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
239  const Evaluation& /*temperature*/,
240  const Evaluation& pressure) const
241  { return inverseSaturatedGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
242 
246  template <class Evaluation>
247  Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
248  const Evaluation& /*temperature*/,
249  const Evaluation& pressure) const
250  {
251  return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure,
252  /*extrapolate=*/true);
253  }
254 
258  template <class Evaluation>
259  Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
260  const Evaluation& /*temperature*/,
261  const Evaluation& pressure,
262  const Evaluation& saltConcentration) const
263  {
264  if (enableRwgSalt_) {
265  return saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(pressure,
266  saltConcentration,
267  /*extrapolate=*/true);
268  }
269  else {
270  return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure,
271  /*extrapolate=*/true);
272  }
273  }
274 
278  template <class Evaluation>
279  Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
280  const Evaluation& /*temperature*/,
281  const Evaluation& /*pressure*/,
282  const Evaluation& /*oilSaturation*/,
283  const Evaluation& /*maxOilSaturation*/) const
284  { return 0.0; /* this is dry humid gas! */ }
285 
289  template <class Evaluation>
290  Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
291  const Evaluation& /*temperature*/,
292  const Evaluation& /*pressure*/) const
293  { return 0.0; /* this is dry humid gas! */ }
294 
303  template <class Evaluation>
304  Evaluation saturationPressure(unsigned regionIdx,
305  const Evaluation&,
306  const Evaluation& Rw) const
307  {
308  typedef MathToolbox<Evaluation> Toolbox;
309 
310  const auto& RwTable = saturatedWaterVaporizationFactorTable_[regionIdx];
311  const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
312 
313  // use the tabulated saturation pressure function to get a pretty good initial value
314  Evaluation pSat = saturationPressure_[regionIdx].eval(Rw, /*extrapolate=*/true);
315 
316  // Newton method to do the remaining work. If the initial
317  // value is good, this should only take two to three
318  // iterations...
319  bool onProbation = false;
320  for (unsigned i = 0; i < 20; ++i) {
321  const Evaluation& f = RwTable.eval(pSat, /*extrapolate=*/true) - Rw;
322  const Evaluation& fPrime = RwTable.evalDerivative(pSat, /*extrapolate=*/true);
323 
324  // If the derivative is "zero" Newton will not converge,
325  // so simply return our initial guess.
326  if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
327  return pSat;
328  }
329 
330  const Evaluation& delta = f / fPrime;
331 
332  pSat -= delta;
333 
334  if (pSat < 0.0) {
335  // if the pressure is lower than 0 Pascals, we set it back to 0. if this
336  // happens twice, we give up and just return 0 Pa...
337  if (onProbation) {
338  return 0.0;
339  }
340 
341  onProbation = true;
342  pSat = 0.0;
343  }
344 
345  if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat)) * eps) {
346  return pSat;
347  }
348  }
349 
350  const std::string msg =
351  "Finding saturation pressure did not converge: "
352  " pSat = " + std::to_string(getValue(pSat)) +
353  ", Rw = " + std::to_string(getValue(Rw));
354  OpmLog::debug("Wet gas saturation pressure", msg);
355  throw NumericalProblem(msg);
356  }
357 
358  template <class Evaluation>
359  Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
360  const Evaluation& /*pressure*/,
361  unsigned /*compIdx*/) const
362  {
363  throw std::runtime_error("Not implemented: The PVT model does not provide "
364  "a diffusionCoefficient()");
365  }
366 
367  Scalar gasReferenceDensity(unsigned regionIdx) const
368  { return gasReferenceDensity_[regionIdx]; }
369 
370  Scalar waterReferenceDensity(unsigned regionIdx) const
371  { return waterReferenceDensity_[regionIdx]; }
372 
373  const std::vector<TabulatedTwoDFunction>& inverseGasB() const
374  { return inverseGasB_; }
375 
376  const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB() const
377  { return inverseSaturatedGasB_; }
378 
379  const std::vector<TabulatedTwoDFunction>& gasMu() const
380  { return gasMu_; }
381 
382  const std::vector<TabulatedTwoDFunction>& inverseGasBMu() const
383  { return inverseGasBMu_; }
384 
385  const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu() const
386  { return inverseSaturatedGasBMu_; }
387 
388  const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable() const
389  { return saturatedWaterVaporizationFactorTable_; }
390 
391  const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable() const
392  { return saturatedWaterVaporizationSaltFactorTable_; }
393 
394  const std::vector<TabulatedOneDFunction>& saturationPressure() const
395  { return saturationPressure_; }
396 
397  Scalar vapPar1() const
398  { return vapPar1_; }
399 
400 private:
401  void updateSaturationPressure_(unsigned regionIdx);
402 
403  std::vector<Scalar> gasReferenceDensity_{};
404  std::vector<Scalar> waterReferenceDensity_{};
405  std::vector<TabulatedTwoDFunction> inverseGasB_{};
406  std::vector<TabulatedOneDFunction> inverseSaturatedGasB_{};
407  std::vector<TabulatedTwoDFunction> gasMu_{};
408  std::vector<TabulatedTwoDFunction> inverseGasBMu_{};
409  std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_{};
410  std::vector<TabulatedOneDFunction> saturatedWaterVaporizationFactorTable_{};
411  std::vector<TabulatedTwoDFunction> saturatedWaterVaporizationSaltFactorTable_{};
412  std::vector<TabulatedOneDFunction> saturationPressure_{};
413 
414  bool enableRwgSalt_ = false;
415  Scalar vapPar1_ = 0.0;
416 };
417 
418 } // namespace Opm
419 
420 #endif
Evaluation saturatedOilVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the oil vaporization factor [m^3/m^3] of the oil phase.
Definition: DryHumidGasPvt.hpp:290
Definition: Exceptions.hpp:39
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &saltConcentration) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition: DryHumidGasPvt.hpp:259
Evaluation viscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &, const Evaluation &Rvw) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: DryHumidGasPvt.hpp:167
Implements a scalar function that depends on two variables and which is sampled uniformly in the X di...
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition: DryHumidGasPvt.hpp:247
Definition: Schedule.hpp:100
void setReferenceDensities(unsigned regionIdx, Scalar, Scalar rhoRefGas, Scalar rhoRefWater)
Initialize the reference densities of all fluids for a given PVT region.
Definition: DryHumidGasPvt.cpp:253
Provides the OPM specific exception classes.
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &, const Evaluation &Rw) const
Returns the saturation pressure of the gas phase [Pa] depending on its mass fraction of the water com...
Definition: DryHumidGasPvt.hpp:304
void setSaturatedGasViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for oil saturated gas.
Definition: DryHumidGasPvt.cpp:264
Implements a scalar function that depends on two variables and which is sampled uniformly in the X di...
Definition: UniformXTabulated2DFunction.hpp:54
This class represents the Pressure-Volume-Temperature relations of the gas phase with vaporized water...
Definition: DryHumidGasPvt.hpp:51
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: EclipseState.hpp:66
Definition: SimpleTable.hpp:35
void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBg)
Initialize the function for the gas formation volume factor.
Definition: DryHumidGasPvt.hpp:110
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of water saturated gas at a given pressure.
Definition: DryHumidGasPvt.hpp:238
Evaluation saturatedOilVaporizationFactor(unsigned, const Evaluation &, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the oil vaporization factor [m^3/m^3] of the oil phase.
Definition: DryHumidGasPvt.hpp:279
void initFromState(const EclipseState &eclState, const Schedule &)
Initialize the parameters for wet gas using an ECL deck.
Definition: DryHumidGasPvt.cpp:38
Definition: MathToolbox.hpp:50
Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of oil saturated gas at a given pressure.
Definition: DryHumidGasPvt.hpp:183
Implements a linearly interpolated scalar function that depends on one variable.
std::pair< LhsEval, LhsEval > inverseFormationVolumeFactorAndViscosity(const FluidState &fluidState, unsigned regionIdx)
Returns the formation volume factor [-] and viscosity [Pa s] of the fluid phase.
Definition: DryHumidGasPvt.hpp:209
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: DryHumidGasPvt.hpp:140
Implements a linearly interpolated scalar function that depends on one variable.
Definition: Tabulated1DFunction.hpp:50
Definition: Tabulated1DFunction.hpp:41
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &, const Evaluation &Rvw) const
Returns the formation volume factor [-] of the fluid phase.
Definition: DryHumidGasPvt.hpp:197
void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition: DryHumidGasPvt.hpp:94
Evaluation internalEnergy(unsigned, const Evaluation &, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the specific enthalpy [J/kg] of gas given a set of parameters.
Definition: DryHumidGasPvt.hpp:147
void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction &mug)
Initialize the viscosity of the gas phase.
Definition: DryHumidGasPvt.hpp:119
void initEnd()
Finish initializing the gas phase PVT properties.
Definition: DryHumidGasPvt.cpp:298