All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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_OPM_PARSER
35 #include <opm/parser/eclipse/Deck/Deck.hpp>
36 #include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
37 #include <opm/parser/eclipse/EclipseState/Tables/TableManager.hpp>
38 #include <opm/parser/eclipse/EclipseState/Tables/PvdgTable.hpp>
39 #include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
40 #include <opm/parser/eclipse/Deck/DeckRecord.hpp>
41 #endif
42 
43 #include <vector>
44 
45 namespace Opm {
50 template <class Scalar>
51 class DryGasPvt
52 {
54  typedef std::vector<std::pair<Scalar, Scalar> > SamplingPoints;
55 
56 public:
57 #if HAVE_OPM_PARSER
58 
63  void initFromDeck(const Deck& deck, const EclipseState& eclState)
64  {
65  const auto& pvdgTables = eclState.getTableManager().getPvdgTables();
66  const auto& densityKeyword = deck.getKeyword("DENSITY");
67 
68  assert(pvdgTables.size() == densityKeyword.size());
69 
70  size_t numRegions = pvdgTables.size();
71  setNumRegions(numRegions);
72 
73  for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
74  Scalar rhoRefO = densityKeyword.getRecord(regionIdx).getItem("OIL").getSIDouble(0);
75  Scalar rhoRefG = densityKeyword.getRecord(regionIdx).getItem("GAS").getSIDouble(0);
76  Scalar rhoRefW = densityKeyword.getRecord(regionIdx).getItem("WATER").getSIDouble(0);
77 
78  setReferenceDensities(regionIdx, rhoRefO, rhoRefG, rhoRefW);
79 
80  // determine the molar masses of the components
81  Scalar p = 1.01325e5; // surface pressure, [Pa]
82  Scalar T = 273.15 + 15.56; // surface temperature, [K]
83  Scalar MO = 175e-3; // [kg/mol]
84  Scalar MG = Opm::Constants<Scalar>::R*T*rhoRefG / p; // [kg/mol], consequence of the ideal gas law
85  Scalar MW = 18.0e-3; // [kg/mol]
86  // TODO (?): the molar mass of the components can possibly specified
87  // explicitly in the deck.
88  setMolarMasses(regionIdx, MO, MG, MW);
89 
90  const auto& pvdgTable = pvdgTables.getTable<PvdgTable>(regionIdx);
91 
92  // say 99.97% of all time: "premature optimization is the root of all
93  // evil". Eclipse does this "optimization" for apparently no good reason!
94  std::vector<Scalar> invB(pvdgTable.numRows());
95  const auto& Bg = pvdgTable.getFormationFactorColumn();
96  for (unsigned i = 0; i < Bg.size(); ++ i) {
97  invB[i] = 1.0/Bg[i];
98  }
99 
100  size_t numSamples = invB.size();
101  inverseGasB_[regionIdx].setXYArrays(numSamples, pvdgTable.getPressureColumn(), invB);
102  gasMu_[regionIdx].setXYArrays(numSamples, pvdgTable.getPressureColumn(), pvdgTable.getViscosityColumn());
103  }
104 
105  initEnd();
106  }
107 #endif
108 
109  void setNumRegions(size_t numRegions)
110  {
111  gasReferenceDensity_.resize(numRegions);
112  inverseGasB_.resize(numRegions);
113  inverseGasBMu_.resize(numRegions);
114  gasMu_.resize(numRegions);
115  }
116 
117 
121  void setReferenceDensities(unsigned regionIdx,
122  Scalar /*rhoRefOil*/,
123  Scalar rhoRefGas,
124  Scalar /*rhoRefWater*/)
125  {
126  gasReferenceDensity_[regionIdx] = rhoRefGas;
127  }
128 
132  void setMolarMasses(unsigned /*regionIdx*/,
133  Scalar /*MOil*/,
134  Scalar /*MGas*/,
135  Scalar /*MWater*/)
136  { }
137 
143  void setGasViscosity(unsigned regionIdx, const TabulatedOneDFunction& mug)
144  { gasMu_[regionIdx] = mug; }
145 
151  void setGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints& samplePoints)
152  {
153  SamplingPoints tmp(samplePoints);
154  auto it = tmp.begin();
155  const auto& endIt = tmp.end();
156  for (; it != endIt; ++ it)
157  std::get<1>(*it) = 1.0/std::get<1>(*it);
158 
159  inverseGasB_[regionIdx].setContainerOfTuples(tmp);
160  assert(inverseGasB_[regionIdx].monotonic());
161  }
162 
166  void initEnd()
167  {
168  // calculate the final 2D functions which are used for interpolation.
169  size_t numRegions = gasMu_.size();
170  for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
171  // calculate the table which stores the inverse of the product of the gas
172  // formation volume factor and the gas viscosity
173  const auto& gasMu = gasMu_[regionIdx];
174  const auto& invGasB = inverseGasB_[regionIdx];
175  assert(gasMu.numSamples() == invGasB.numSamples());
176 
177  std::vector<Scalar> pressureValues(gasMu.numSamples());
178  std::vector<Scalar> invGasBMuValues(gasMu.numSamples());
179  for (unsigned pIdx = 0; pIdx < gasMu.numSamples(); ++pIdx) {
180  pressureValues[pIdx] = invGasB.xAt(pIdx);
181  invGasBMuValues[pIdx] = invGasB.valueAt(pIdx) * (1.0/gasMu.valueAt(pIdx));
182  }
183 
184  inverseGasBMu_[regionIdx].setXYContainers(pressureValues, invGasBMuValues);
185  }
186  }
187 
191  unsigned numRegions() const
192  { return gasReferenceDensity_.size(); }
193 
197  template <class Evaluation>
198  Evaluation viscosity(unsigned regionIdx,
199  const Evaluation& temperature,
200  const Evaluation& pressure,
201  const Evaluation& /*Rv*/) const
202  { return saturatedViscosity(regionIdx, temperature, pressure); }
203 
207  template <class Evaluation>
208  Evaluation saturatedViscosity(unsigned regionIdx,
209  const Evaluation& /*temperature*/,
210  const Evaluation& pressure) const
211  {
212  const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
213  const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
214 
215  return invBg/invMugBg;
216  }
217 
221  template <class Evaluation>
222  Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
223  const Evaluation& temperature,
224  const Evaluation& pressure,
225  const Evaluation& /*Rv*/) const
226  { return saturatedInverseFormationVolumeFactor(regionIdx, temperature, pressure); }
227 
231  template <class Evaluation>
232  Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
233  const Evaluation& /*temperature*/,
234  const Evaluation& pressure) const
235  { return inverseGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
236 
243  template <class Evaluation>
244  Evaluation saturationPressure(unsigned /*regionIdx*/,
245  const Evaluation& /*temperature*/,
246  const Evaluation& /*Rv*/) const
247  { return 0.0; /* this is dry gas! */ }
248 
252  template <class Evaluation>
253  Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
254  const Evaluation& /*temperature*/,
255  const Evaluation& /*pressure*/,
256  const Evaluation& /*oilSaturation*/,
257  Scalar /*maxOilSaturation*/) const
258  { return 0.0; /* this is dry gas! */ }
259 
263  template <class Evaluation>
264  Evaluation saturatedOilVaporizationFactor(unsigned /*regionIdx*/,
265  const Evaluation& /*temperature*/,
266  const Evaluation& /*pressure*/) const
267  { return 0.0; /* this is dry gas! */ }
268 
269 private:
270  std::vector<Scalar> gasReferenceDensity_;
271  std::vector<TabulatedOneDFunction> inverseGasB_;
272  std::vector<TabulatedOneDFunction> gasMu_;
273  std::vector<TabulatedOneDFunction> inverseGasBMu_;
274 };
275 
276 } // namespace Opm
277 
278 #endif
void initEnd()
Finish initializing the oil phase PVT properties.
Definition: DryGasPvt.hpp:166
void setGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the formation volume factor of dry gas.
Definition: DryGasPvt.hpp:151
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:244
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:198
void setMolarMasses(unsigned, Scalar, Scalar, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition: DryGasPvt.hpp:132
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:222
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:232
A central place for various physical constants occuring in some equations.
Definition: Constants.hpp:40
void setReferenceDensities(unsigned regionIdx, Scalar, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition: DryGasPvt.hpp:121
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:208
Implements a linearly interpolated scalar function that depends on one variable.
A central place for various physical constants occuring in some equations.
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Definition: DryGasPvt.hpp:51
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: DryGasPvt.hpp:191
Evaluation saturatedOilVaporizationFactor(unsigned, const Evaluation &, const Evaluation &, const Evaluation &, Scalar) const
Returns the oil vaporization factor [m^3/m^3] of the oil phase.
Definition: DryGasPvt.hpp:253
Implements a linearly interpolated scalar function that depends on one variable.
Definition: Tabulated1DFunction.hpp:47
void setGasViscosity(unsigned regionIdx, const TabulatedOneDFunction &mug)
Initialize the viscosity of the gas phase.
Definition: DryGasPvt.hpp:143
Evaluation saturatedOilVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the oil vaporization factor [m^3/m^3] of the oil phase.
Definition: DryGasPvt.hpp:264