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  Copyright (C) 2015 by Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
25 #ifndef OPM_DRY_GAS_PVT_HPP
26 #define OPM_DRY_GAS_PVT_HPP
27 
29 
31 
32 #if HAVE_OPM_PARSER
33 #include <opm/parser/eclipse/Deck/Deck.hpp>
34 #include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
35 #include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
36 #include <opm/parser/eclipse/Deck/DeckRecord.hpp>
37 #endif
38 
39 #include <vector>
40 
41 namespace Opm {
42 
43 template <class Scalar>
45 
50 template <class Scalar>
51 class DryGasPvt
52 {
55  typedef std::vector<std::pair<Scalar, Scalar> > SamplingPoints;
56 
57 public:
58 #if HAVE_OPM_PARSER
59 
64  void initFromDeck(DeckConstPtr deck, EclipseStateConstPtr eclState)
65  {
66  const auto& pvdgTables = eclState->getTableManager()->getPvdgTables();
67  DeckKeywordConstPtr densityKeyword = deck->getKeyword("DENSITY");
68 
69  assert(pvdgTables.size() == densityKeyword->size());
70 
71  size_t numRegions = pvdgTables.size();
72  setNumRegions(numRegions);
73 
74  for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
75  Scalar rhoRefO = densityKeyword->getRecord(regionIdx)->getItem("OIL")->getSIDouble(0);
76  Scalar rhoRefG = densityKeyword->getRecord(regionIdx)->getItem("GAS")->getSIDouble(0);
77  Scalar rhoRefW = densityKeyword->getRecord(regionIdx)->getItem("WATER")->getSIDouble(0);
78 
79  setReferenceDensities(regionIdx, rhoRefO, rhoRefG, rhoRefW);
80 
81  // determine the molar masses of the components
82  Scalar p = 1.01325e5; // surface pressure, [Pa]
83  Scalar T = 273.15 + 15.56; // surface temperature, [K]
84  Scalar MO = 175e-3; // [kg/mol]
85  Scalar MG = Opm::Constants<Scalar>::R*T*rhoRefG / p; // [kg/mol], consequence of the ideal gas law
86  Scalar MW = 18.0e-3; // [kg/mol]
87  // TODO (?): the molar mass of the components can possibly specified
88  // explicitly in the deck.
89  setMolarMasses(regionIdx, MO, MG, MW);
90 
91  const auto& pvdgTable = pvdgTables.getTable<PvdgTable>(regionIdx);
92 
93  // say 99.97% of all time: "premature optimization is the root of all
94  // evil". Eclipse does this "optimization" for apparently no good reason!
95  std::vector<Scalar> invB(pvdgTable.numRows());
96  const auto& Bg = pvdgTable.getFormationFactorColumn();
97  for (unsigned i = 0; i < Bg.size(); ++ i) {
98  invB[i] = 1.0/Bg[i];
99  }
100 
101  size_t numSamples = invB.size();
102  inverseGasB_[regionIdx].setXYArrays(numSamples, pvdgTable.getPressureColumn(), invB);
103  gasMu_[regionIdx].setXYArrays(numSamples, pvdgTable.getPressureColumn(), pvdgTable.getViscosityColumn());
104  }
105  }
106 #endif
107 
108  void setNumRegions(size_t numRegions)
109  {
110  gasReferenceDensity_.resize(numRegions);
111  inverseGasB_.resize(numRegions);
112  inverseGasBMu_.resize(numRegions);
113  gasMu_.resize(numRegions);
114  }
115 
116 
120  void setReferenceDensities(unsigned regionIdx,
121  Scalar /*rhoRefOil*/,
122  Scalar rhoRefGas,
123  Scalar /*rhoRefWater*/)
124  {
125  gasReferenceDensity_[regionIdx] = rhoRefGas;
126  }
127 
131  void setMolarMasses(unsigned /*regionIdx*/,
132  Scalar /*MOil*/,
133  Scalar /*MGas*/,
134  Scalar /*MWater*/)
135  { }
136 
142  void setGasViscosity(unsigned regionIdx, const TabulatedOneDFunction& mug)
143  { gasMu_[regionIdx] = mug; }
144 
150  void setGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
151  {
152  SamplingPoints tmp(samplePoints);
153  auto it = tmp.begin();
154  const auto& endIt = tmp.end();
155  for (; it != endIt; ++ it)
156  std::get<1>(*it) = 1.0/std::get<1>(*it);
157 
158  inverseGasB_[regionIdx].setContainerOfTuples(tmp);
159  assert(inverseGasB_[regionIdx].monotonic());
160  }
161 
165  void initEnd(const OilPvtMultiplexer *oilPvt)
166  {
167  oilPvt_ = oilPvt;
168 
169  // calculate the final 2D functions which are used for interpolation.
170  size_t numRegions = gasMu_.size();
171  for (unsigned regionIdx = 0; regionIdx < numRegions; ++ regionIdx) {
172  // calculate the table which stores the inverse of the product of the gas
173  // formation volume factor and the gas viscosity
174  const auto& gasMu = gasMu_[regionIdx];
175  const auto& invGasB = inverseGasB_[regionIdx];
176  assert(gasMu.numSamples() == invGasB.numSamples());
177 
178  std::vector<Scalar> pressureValues(gasMu.numSamples());
179  std::vector<Scalar> invGasBMuValues(gasMu.numSamples());
180  for (unsigned pIdx = 0; pIdx < gasMu.numSamples(); ++pIdx) {
181  pressureValues[pIdx] = invGasB.xAt(pIdx);
182  invGasBMuValues[pIdx] = invGasB.valueAt(pIdx) * (1.0/gasMu.valueAt(pIdx));
183  }
184 
185  inverseGasBMu_[regionIdx].setXYContainers(pressureValues, invGasBMuValues);
186  }
187  }
188 
192  template <class Evaluation>
193  Evaluation viscosity(unsigned regionIdx,
194  const Evaluation& /*temperature*/,
195  const Evaluation& pressure,
196  const Evaluation& /*XgO*/) const
197  {
198  const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, /*extrapolate=*/true);
199  const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, /*extrapolate=*/true);
200 
201  return invBg/invMugBg;
202  }
203 
207  template <class Evaluation>
208  Evaluation density(unsigned regionIdx,
209  const Evaluation& temperature,
210  const Evaluation& pressure,
211  const Evaluation& XgO) const
212  {
213  // gas formation volume factor at reservoir pressure
214  const Evaluation& Bg = formationVolumeFactor(regionIdx, temperature, pressure, XgO);
215  return gasReferenceDensity_[regionIdx]/Bg;
216  }
217 
221  template <class Evaluation>
222  Evaluation formationVolumeFactor(unsigned regionIdx,
223  const Evaluation& /*temperature*/,
224  const Evaluation& pressure,
225  const Evaluation& /*XgO*/) const
226  { return 1.0/inverseGasB_[regionIdx].eval(pressure, /*extrapolate=*/true); }
227 
232  template <class Evaluation>
233  Evaluation fugacityCoefficientGas(unsigned /*regionIdx*/,
234  const Evaluation& /*temperature*/,
235  const Evaluation& /*pressure*/) const
236  {
237  // make the gas component more affine to the gas phase than the other components
238  return 1.0;
239  }
240 
245  template <class Evaluation>
246  Evaluation fugacityCoefficientOil(unsigned /*regionIdx*/,
247  const Evaluation& /*temperature*/,
248  const Evaluation& /*pressure*/) const
249  { return 1.0e6; }
250 
255  template <class Evaluation>
256  Evaluation fugacityCoefficientWater(unsigned /*regionIdx*/,
257  const Evaluation& /*temperature*/,
258  const Evaluation& /*pressure*/) const
259  { return 1.1e6; }
260 
267  template <class Evaluation>
268  Evaluation gasSaturationPressure(unsigned /*regionIdx*/,
269  const Evaluation& /*temperature*/,
270  const Evaluation& /*XgO*/) const
271  { return 0.0; /* this is dry gas! */ }
272 
276  template <class Evaluation>
277  Evaluation oilVaporizationFactor(unsigned /*regionIdx*/,
278  const Evaluation& /*temperature*/,
279  const Evaluation& /*pressure*/) const
280  { return 0.0; /* this is dry gas! */ }
281 
282  template <class Evaluation>
283  Evaluation saturatedGasOilMassFraction(unsigned /*regionIdx*/,
284  const Evaluation& /*temperature*/,
285  const Evaluation& /*pressure*/) const
286  { return 0.0; /* this is dry gas! */ }
287 
288  template <class Evaluation>
289  Evaluation saturatedGasOilMoleFraction(unsigned /*regionIdx*/,
290  const Evaluation& /*temperature*/,
291  const Evaluation& /*pressure*/) const
292  { return 0.0; /* this is dry gas! */ }
293 
294 private:
295  const OilPvtMultiplexer *oilPvt_;
296 
297  std::vector<Scalar> gasReferenceDensity_;
298  std::vector<TabulatedOneDFunction> inverseGasB_;
299  std::vector<TabulatedOneDFunction> gasMu_;
300  std::vector<TabulatedOneDFunction> inverseGasBMu_;
301 };
302 
303 } // namespace Opm
304 
305 #endif
Evaluation fugacityCoefficientWater(unsigned, const Evaluation &, const Evaluation &) const
Returns the fugacity coefficient [Pa] of a component in the fluid phase given a set of parameters...
Definition: DryGasPvt.hpp:256
This class represents the Pressure-Volume-Temperature relations of the oil phase in the black-oil mod...
Definition: DryGasPvt.hpp:44
void setReferenceDensities(unsigned regionIdx, Scalar, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition: DryGasPvt.hpp:120
Evaluation saturatedGasOilMoleFraction(unsigned, const Evaluation &, const Evaluation &) const
Definition: DryGasPvt.hpp:289
Definition: Air_Mesitylene.hpp:31
Evaluation oilVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the gas dissolution factor [m^3/m^3] of the oil phase.
Definition: DryGasPvt.hpp:277
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Definition: DryGasPvt.hpp:51
Implements a linearly interpolated scalar function that depends on one variable.
void setGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the formation volume factor of dry gas.
Definition: DryGasPvt.hpp:150
void initEnd(const OilPvtMultiplexer *oilPvt)
Finish initializing the oil phase PVT properties.
Definition: DryGasPvt.hpp:165
A central place for various physical constants occuring in some equations.
Evaluation saturatedGasOilMassFraction(unsigned, const Evaluation &, const Evaluation &) const
Definition: DryGasPvt.hpp:283
Evaluation fugacityCoefficientOil(unsigned, const Evaluation &, const Evaluation &) const
Returns the fugacity coefficient [Pa] of a component in the fluid phase given a set of parameters...
Definition: DryGasPvt.hpp:246
Evaluation viscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: DryGasPvt.hpp:193
Evaluation formationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &) const
Returns the formation volume factor [-] of the fluid phase.
Definition: DryGasPvt.hpp:222
Evaluation fugacityCoefficientGas(unsigned, const Evaluation &, const Evaluation &) const
Returns the fugacity coefficient [Pa] of a component in the fluid phase given a set of parameters...
Definition: DryGasPvt.hpp:233
Evaluation density(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &XgO) const
Returns the density [kg/m^3] of the fluid phase given a set of parameters.
Definition: DryGasPvt.hpp:208
Implements a linearly interpolated scalar function that depends on one variable.
Definition: Tabulated1DFunction.hpp:44
void setNumRegions(size_t numRegions)
Definition: DryGasPvt.hpp:108
A central place for various physical constants occuring in some equations.
Definition: Constants.hpp:39
void setGasViscosity(unsigned regionIdx, const TabulatedOneDFunction &mug)
Initialize the viscosity of the gas phase.
Definition: DryGasPvt.hpp:142
void setMolarMasses(unsigned, Scalar, Scalar, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition: DryGasPvt.hpp:131
Evaluation gasSaturationPressure(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:268