My Project
DryGasPvt.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_GAS_PVT_HPP
28 #define OPM_DRY_GAS_PVT_HPP
29 
31 
33 
34 #if HAVE_ECL_INPUT
35 #include <opm/input/eclipse/EclipseState/EclipseState.hpp>
36 #include <opm/input/eclipse/Schedule/Schedule.hpp>
37 #include <opm/input/eclipse/EclipseState/Tables/TableManager.hpp>
38 #include <opm/input/eclipse/EclipseState/Tables/PvdgTable.hpp>
39 #endif
40 
41 #include <vector>
42 
43 namespace Opm {
48 template <class Scalar>
49 class DryGasPvt
50 {
51  typedef std::vector<std::pair<Scalar, Scalar> > SamplingPoints;
52 
53 public:
55 
56  explicit DryGasPvt() = default;
57  DryGasPvt(const std::vector<Scalar>& gasReferenceDensity,
58  const std::vector<TabulatedOneDFunction>& inverseGasB,
59  const std::vector<TabulatedOneDFunction>& gasMu,
60  const std::vector<TabulatedOneDFunction>& inverseGasBMu)
61  : gasReferenceDensity_(gasReferenceDensity)
62  , inverseGasB_(inverseGasB)
63  , gasMu_(gasMu)
64  , inverseGasBMu_(inverseGasBMu)
65  {
66  }
67 #if HAVE_ECL_INPUT
73  void initFromState(const EclipseState& eclState, const Schedule&)
74  {
75  const auto& pvdgTables = eclState.getTableManager().getPvdgTables();
76  const auto& densityTable = eclState.getTableManager().getDensityTable();
77 
78  assert(pvdgTables.size() == densityTable.size());
79 
80  size_t numRegions = pvdgTables.size();
81  setNumRegions(numRegions);
82 
83  for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
84  Scalar rhoRefO = densityTable[regionIdx].oil;
85  Scalar rhoRefG = densityTable[regionIdx].gas;
86  Scalar rhoRefW = densityTable[regionIdx].water;
87 
88  setReferenceDensities(regionIdx, rhoRefO, rhoRefG, rhoRefW);
89 
90  // determine the molar masses of the components
91  Scalar p = 1.01325e5; // surface pressure, [Pa]
92  Scalar T = 273.15 + 15.56; // surface temperature, [K]
93  Scalar MO = 175e-3; // [kg/mol]
94  Scalar MG = Constants<Scalar>::R*T*rhoRefG / p; // [kg/mol], consequence of the ideal gas law
95  Scalar MW = 18.0e-3; // [kg/mol]
96  // TODO (?): the molar mass of the components can possibly specified
97  // explicitly in the deck.
98  setMolarMasses(regionIdx, MO, MG, MW);
99 
100  const auto& pvdgTable = pvdgTables.getTable<PvdgTable>(regionIdx);
101 
102  // say 99.97% of all time: "premature optimization is the root of all
103  // evil". Eclipse does this "optimization" for apparently no good reason!
104  std::vector<Scalar> invB(pvdgTable.numRows());
105  const auto& Bg = pvdgTable.getFormationFactorColumn();
106  for (unsigned i = 0; i < Bg.size(); ++ i) {
107  invB[i] = 1.0/Bg[i];
108  }
109 
110  size_t numSamples = invB.size();
111  inverseGasB_[regionIdx].setXYArrays(numSamples, pvdgTable.getPressureColumn(), invB);
112  gasMu_[regionIdx].setXYArrays(numSamples, pvdgTable.getPressureColumn(), pvdgTable.getViscosityColumn());
113  }
114 
115  initEnd();
116  }
117 #endif
118 
119  void setNumRegions(size_t numRegions)
120  {
121  gasReferenceDensity_.resize(numRegions);
122  inverseGasB_.resize(numRegions);
123  inverseGasBMu_.resize(numRegions);
124  gasMu_.resize(numRegions);
125  }
126 
127 
131  void setReferenceDensities(unsigned regionIdx,
132  Scalar /*rhoRefOil*/,
133  Scalar rhoRefGas,
134  Scalar /*rhoRefWater*/)
135  {
136  gasReferenceDensity_[regionIdx] = rhoRefGas;
137  }
138 
142  void setMolarMasses(unsigned /*regionIdx*/,
143  Scalar /*MOil*/,
144  Scalar /*MGas*/,
145  Scalar /*MWater*/)
146  { }
147 
153  void setGasViscosity(unsigned regionIdx, const TabulatedOneDFunction& mug)
154  { gasMu_[regionIdx] = mug; }
155 
161  void setGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
162  {
163  SamplingPoints tmp(samplePoints);
164  auto it = tmp.begin();
165  const auto& endIt = tmp.end();
166  for (; it != endIt; ++ it)
167  std::get<1>(*it) = 1.0/std::get<1>(*it);
168 
169  inverseGasB_[regionIdx].setContainerOfTuples(tmp);
170  assert(inverseGasB_[regionIdx].monotonic());
171  }
172 
176  void initEnd()
177  {
178  // calculate the final 2D functions which are used for interpolation.
179  size_t numRegions = gasMu_.size();
180  for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
181  // calculate the table which stores the inverse of the product of the gas
182  // formation volume factor and the gas viscosity
183  const auto& gasMu = gasMu_[regionIdx];
184  const auto& invGasB = inverseGasB_[regionIdx];
185  assert(gasMu.numSamples() == invGasB.numSamples());
186 
187  std::vector<Scalar> pressureValues(gasMu.numSamples());
188  std::vector<Scalar> invGasBMuValues(gasMu.numSamples());
189  for (unsigned pIdx = 0; pIdx < gasMu.numSamples(); ++pIdx) {
190  pressureValues[pIdx] = invGasB.xAt(pIdx);
191  invGasBMuValues[pIdx] = invGasB.valueAt(pIdx) * (1.0/gasMu.valueAt(pIdx));
192  }
193 
194  inverseGasBMu_[regionIdx].setXYContainers(pressureValues, invGasBMuValues);
195  }
196  }
197 
201  unsigned numRegions() const
202  { return gasReferenceDensity_.size(); }
203 
207  template <class Evaluation>
208  Evaluation internalEnergy(unsigned,
209  const Evaluation&,
210  const Evaluation&,
211  const Evaluation&) const
212  {
213  throw std::runtime_error("Requested the enthalpy of gas but the thermal option is not enabled");
214  }
215 
219  template <class Evaluation>
220  Evaluation viscosity(unsigned regionIdx,
221  const Evaluation& temperature,
222  const Evaluation& pressure,
223  const Evaluation& /*Rv*/) const
224  { return saturatedViscosity(regionIdx, temperature, pressure); }
225 
229  template <class Evaluation>
230  Evaluation saturatedViscosity(unsigned regionIdx,
231  const Evaluation& /*temperature*/,
232  const Evaluation& pressure) const
233  {
234  const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
235  const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
236 
237  return invBg/invMugBg;
238  }
239 
243  template <class Evaluation>
244  Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
245  const Evaluation& temperature,
246  const Evaluation& pressure,
247  const Evaluation& /*Rv*/) const
248  { return saturatedInverseFormationVolumeFactor(regionIdx, temperature, pressure); }
249 
253  template <class Evaluation>
254  Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
255  const Evaluation& /*temperature*/,
256  const Evaluation& pressure) const
257  { return inverseGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
258 
265  template <class Evaluation>
266  Evaluation saturationPressure(unsigned /*regionIdx*/,
267  const Evaluation& /*temperature*/,
268  const Evaluation& /*Rv*/) const
269  { return 0.0; /* this is dry gas! */ }
270 
274  template <class Evaluation>
275  Evaluation saturatedWaterVaporizationFactor(unsigned /*regionIdx*/,
276  const Evaluation& /*temperature*/,
277  const Evaluation& /*pressure*/) const
278  { return 0.0; /* this is non-humid gas! */ }
279 
283  template <class Evaluation>
284  Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
285  const Evaluation& /*temperature*/,
286  const Evaluation& /*pressure*/,
287  const Evaluation& /*oilSaturation*/,
288  const Evaluation& /*maxOilSaturation*/) const
289  { return 0.0; /* this is dry gas! */ }
290 
294  template <class Evaluation>
295  Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
296  const Evaluation& /*temperature*/,
297  const Evaluation& /*pressure*/) const
298  { return 0.0; /* this is dry gas! */ }
299 
300  template <class Evaluation>
301  Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
302  const Evaluation& /*pressure*/,
303  unsigned /*compIdx*/) const
304  {
305  throw std::runtime_error("Not implemented: The PVT model does not provide a diffusionCoefficient()");
306  }
307 
308  const Scalar gasReferenceDensity(unsigned regionIdx) const
309  { return gasReferenceDensity_[regionIdx]; }
310 
311  const std::vector<TabulatedOneDFunction>& inverseGasB() const
312  { return inverseGasB_; }
313 
314  const std::vector<TabulatedOneDFunction>& gasMu() const
315  { return gasMu_; }
316 
317  const std::vector<TabulatedOneDFunction> inverseGasBMu() const
318  { return inverseGasBMu_; }
319 
320  bool operator==(const DryGasPvt<Scalar>& data) const
321  {
322  return gasReferenceDensity_ == data.gasReferenceDensity_ &&
323  inverseGasB_ == data.inverseGasB_ &&
324  gasMu_ == data.gasMu_ &&
325  inverseGasBMu_ == data.inverseGasBMu_;
326  }
327 
328 private:
329  std::vector<Scalar> gasReferenceDensity_;
330  std::vector<TabulatedOneDFunction> inverseGasB_;
331  std::vector<TabulatedOneDFunction> gasMu_;
332  std::vector<TabulatedOneDFunction> inverseGasBMu_;
333 };
334 
335 } // namespace Opm
336 
337 #endif
A central place for various physical constants occuring in some equations.
Implements a linearly interpolated scalar function that depends on one variable.
A central place for various physical constants occuring in some equations.
Definition: Constants.hpp:41
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Definition: DryGasPvt.hpp:50
Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of oil saturated gas at given pressure.
Definition: DryGasPvt.hpp:230
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: DryGasPvt.hpp:266
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: DryGasPvt.hpp:201
void setGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the formation volume factor of dry gas.
Definition: DryGasPvt.hpp:161
Evaluation internalEnergy(unsigned, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the specific enthalpy [J/kg] of gas given a set of parameters.
Definition: DryGasPvt.hpp:208
Evaluation saturatedOilVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the oil vaporization factor [m^3/m^3] of the oil phase.
Definition: DryGasPvt.hpp:295
Evaluation viscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: DryGasPvt.hpp:220
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of oil saturated gas at given pressure.
Definition: DryGasPvt.hpp:254
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &) const
Returns the formation volume factor [-] of the fluid phase.
Definition: DryGasPvt.hpp:244
void initEnd()
Finish initializing the oil phase PVT properties.
Definition: DryGasPvt.hpp:176
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition: DryGasPvt.hpp:275
void setMolarMasses(unsigned, Scalar, Scalar, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition: DryGasPvt.hpp:142
void setGasViscosity(unsigned regionIdx, const TabulatedOneDFunction &mug)
Initialize the viscosity of the gas phase.
Definition: DryGasPvt.hpp:153
void setReferenceDensities(unsigned regionIdx, Scalar, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition: DryGasPvt.hpp:131
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: DryGasPvt.hpp:284
Implements a linearly interpolated scalar function that depends on one variable.
Definition: Tabulated1DFunction.hpp:47