All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OilPvtThermal.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_OIL_PVT_THERMAL_HPP
28 #define OPM_OIL_PVT_THERMAL_HPP
29 
31 
36 
37 #if HAVE_OPM_PARSER
38 #include <opm/parser/eclipse/Deck/Deck.hpp>
39 #include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
40 #include <opm/parser/eclipse/EclipseState/Tables/SimpleTable.hpp>
41 #include <opm/parser/eclipse/EclipseState/Tables/TableManager.hpp>
42 #endif
43 
44 namespace Opm {
45 template <class Scalar, bool enableThermal>
46 class OilPvtMultiplexer;
47 
54 template <class Scalar>
56 {
58  typedef OilPvtMultiplexer<Scalar, /*enableThermal=*/false> IsothermalPvt;
59 
60 public:
61  ~OilPvtThermal()
62  { delete isothermalPvt_; }
63 
64 #if HAVE_OPM_PARSER
65 
68  void initFromDeck(const Deck& deck,
69  const EclipseState& eclState)
70  {
72  // initialize the isothermal part
74  isothermalPvt_ = new IsothermalPvt;
75  isothermalPvt_->initFromDeck(deck, eclState);
76 
78  // initialize the thermal part
80  const auto& tables = eclState.getTableManager();
81 
82  enableThermalDensity_ = deck.hasKeyword("THERMEX1");
83  enableThermalViscosity_ = deck.hasKeyword("VISCREF");
84 
85  unsigned numRegions = isothermalPvt_->numRegions();
86  setNumRegions(numRegions);
87 
88  // viscosity
89  if (deck.hasKeyword("VISCREF")) {
90  const auto& oilvisctTables = tables.getOilvisctTables();
91  const auto& viscrefKeyword = deck.getKeyword("VISCREF");
92 
93  assert(oilvisctTables.size() == numRegions);
94  assert(viscrefKeyword.size() == numRegions);
95 
96  for (unsigned regionIdx = 0; regionIdx < numRegions; ++regionIdx) {
97  const auto& TCol = oilvisctTables[regionIdx].getColumn("Temperature").vectorCopy();
98  const auto& muCol = oilvisctTables[regionIdx].getColumn("Viscosity").vectorCopy();
99  oilvisctCurves_[regionIdx].setXYContainers(TCol, muCol);
100 
101  const auto& viscrefRecord = viscrefKeyword.getRecord(regionIdx);
102  viscrefPress_[regionIdx] = viscrefRecord.getItem("REFERENCE_PRESSURE").getSIDouble(0);
103  viscrefRs_[regionIdx] = viscrefRecord.getItem("REFERENCE_RS").getSIDouble(0);
104 
105  // temperature used to calculate the reference viscosity [K]. the
106  // value does not really matter if the underlying PVT object really
107  // is isothermal...
108  Scalar Tref = 273.15 + 20;
109 
110  // compute the reference viscosity using the isothermal PVT object.
111  viscRef_[regionIdx] =
112  isothermalPvt_->viscosity(regionIdx,
113  Tref,
114  viscrefPress_[regionIdx],
115  viscrefRs_[regionIdx]);
116  }
117  }
118 
119  // quantities required for density. note that we just always use the values
120  // for the first EOS. (since EOS != PVT region.)
121  refTemp_ = 0.0;
122  if (deck.hasKeyword("THERMEX1")) {
123  int oilCompIdx = deck.getKeyword("OCOMPIDX").getRecord(0).getItem("OIL_COMPONENT_INDEX").get< int >(0) - 1;
124 
125  // always use the values of the first EOS
126  refTemp_ = deck.getKeyword("TREF").getRecord(0).getItem("TEMPERATURE").getSIDouble(oilCompIdx);
127  refPress_ = deck.getKeyword("PREF").getRecord(0).getItem("PRESSURE").getSIDouble(oilCompIdx);
128  refC_ = deck.getKeyword("CREF").getRecord(0).getItem("COMPRESSIBILITY").getSIDouble(oilCompIdx);
129  thermex1_ = deck.getKeyword("THERMEX1").getRecord(0).getItem("EXPANSION_COEFF").getSIDouble(oilCompIdx);
130  }
131  }
132 #endif // HAVE_OPM_PARSER
133 
137  void setNumRegions(size_t numRegions)
138  {
139  oilvisctCurves_.resize(numRegions);
140  viscrefPress_.resize(numRegions);
141  viscrefRs_.resize(numRegions);
142  viscRef_.resize(numRegions);
143  }
144 
148  void initEnd()
149  { }
150 
154  bool enableThermalDensity() const
155  { return enableThermalDensity_; }
156 
161  { return enableThermalViscosity_; }
162 
163  size_t numRegions() const
164  { return viscrefRs_.size(); }
165 
169  template <class Evaluation>
170  Evaluation viscosity(unsigned regionIdx,
171  const Evaluation& temperature,
172  const Evaluation& pressure,
173  const Evaluation& Rs) const
174  {
175  const auto& isothermalMu = isothermalPvt_->viscosity(regionIdx, temperature, pressure, Rs);
176  if (!enableThermalViscosity())
177  return isothermalMu;
178 
179  // compute the viscosity deviation due to temperature
180  const auto& muOilvisct = oilvisctCurves_[regionIdx].eval(temperature);
181  return muOilvisct/viscRef_[regionIdx]*isothermalMu;
182  }
183 
187  template <class Evaluation>
188  Evaluation saturatedViscosity(unsigned regionIdx,
189  const Evaluation& temperature,
190  const Evaluation& pressure) const
191  {
192  const auto& isothermalMu = isothermalPvt_->saturatedViscosity(regionIdx, temperature, pressure);
193  if (!enableThermalViscosity())
194  return isothermalMu;
195 
196  // compute the viscosity deviation due to temperature
197  const auto& muOilvisct = oilvisctCurves_[regionIdx].eval(temperature);
198  return muOilvisct/viscRef_[regionIdx]*isothermalMu;
199  }
200 
201 
205  template <class Evaluation>
206  Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
207  const Evaluation& temperature,
208  const Evaluation& pressure,
209  const Evaluation& Rs) const
210  {
211  const auto& b =
212  isothermalPvt_->inverseFormationVolumeFactor(regionIdx, temperature, pressure, Rs);
213  if (!enableThermalDensity())
214  return b;
215 
216  // we use equation (3.208) from the Eclipse 2011.1 Reference Manual, but we
217  // calculate rho_ref using the isothermal keyword instead of using the value for
218  // the components, so the oil compressibility is already dealt with there. Note
219  // that we only do the part for the oil component here, the part for dissolved
220  // gas is ignored so far.
221  const auto& alpha = 1.0/(1 + thermex1_*(temperature - refTemp_));
222  return alpha*b;
223  }
224 
228  template <class Evaluation>
229  Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
230  const Evaluation& temperature,
231  const Evaluation& pressure) const
232  {
233  const auto& b =
234  isothermalPvt_->saturatedInverseFormationVolumeFactor(regionIdx, temperature, pressure);
235  if (!enableThermalDensity())
236  return b;
237 
238  // we use equation (3.208) from the Eclipse 2011.1 Reference Manual, but we
239  // calculate rho_ref using the isothermal keyword instead of using the value for
240  // the components, so the oil compressibility is already dealt with there. Note
241  // that we only do the part for the oil component here, the part for dissolved
242  // gas is ignored so far.
243  const auto& alpha = 1.0/(1 + thermex1_*(temperature - refTemp_));
244  return alpha*b;
245  }
246 
254  template <class Evaluation>
255  Evaluation saturatedGasDissolutionFactor(unsigned regionIdx,
256  const Evaluation& temperature,
257  const Evaluation& pressure) const
258  { return isothermalPvt_->saturatedGasDissolutionFactor(regionIdx, temperature, pressure); }
259 
267  template <class Evaluation>
268  Evaluation saturatedGasDissolutionFactor(unsigned regionIdx,
269  const Evaluation& temperature,
270  const Evaluation& pressure,
271  const Evaluation& oilSaturation,
272  Scalar maxOilSaturation) const
273  { return isothermalPvt_->saturatedGasDissolutionFactor(regionIdx, temperature, pressure, oilSaturation, maxOilSaturation); }
274 
282  template <class Evaluation>
283  Evaluation saturationPressure(unsigned regionIdx,
284  const Evaluation& temperature,
285  const Evaluation& pressure) const
286  { return isothermalPvt_->saturationPressure(regionIdx, temperature, pressure); }
287 
288 private:
289  IsothermalPvt* isothermalPvt_;
290 
291  // The PVT properties needed for temperature dependence of the viscosity. We need
292  // to store one value per PVT region.
293  std::vector<TabulatedOneDFunction> oilvisctCurves_;
294  std::vector<Scalar> viscrefPress_;
295  std::vector<Scalar> viscrefRs_;
296  std::vector<Scalar> viscRef_;
297 
298  // The PVT properties needed for temperature dependence of the density. This is
299  // specified as one value per EOS in the manual, but we unconditionally use the
300  // expansion coefficient of the first EOS...
301  Scalar refTemp_;
302  Scalar refPress_;
303  Scalar refC_;
304  Scalar thermex1_;
305 
306  bool enableThermalDensity_;
307  bool enableThermalViscosity_;
308 };
309 
310 } // namespace Opm
311 
312 #endif
Evaluation viscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rs) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: OilPvtThermal.hpp:170
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the formation volume factor [-] of the fluid phase.
Definition: OilPvtMultiplexer.hpp:188
Implements a scalar function that depends on two variables and which is sampled uniformly in the X di...
Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &oilSaturation, Scalar maxOilSaturation) const
Returns the gas dissolution factor [m^3/m^3] of the oil phase.
Definition: OilPvtThermal.hpp:268
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the formation volume factor [-] of gas-saturated oil phase.
Definition: OilPvtThermal.hpp:229
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &temperature, const Evaluation &Rs) const
Returns the saturation pressure [Pa] of oil given the mass fraction of the gas component in the oil p...
Definition: OilPvtMultiplexer.hpp:221
bool enableThermalDensity() const
Returns true iff the density of the oil phase is temperature dependent.
Definition: OilPvtThermal.hpp:154
Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the gas dissolution factor [m^3/m^3] of the oil phase.
Definition: OilPvtThermal.hpp:255
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rs) const
Returns the formation volume factor [-] of the fluid phase.
Definition: OilPvtMultiplexer.hpp:178
Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the gas dissolution factor [m^3/m^3] of saturated oil.
Definition: OilPvtMultiplexer.hpp:197
Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: OilPvtThermal.hpp:188
Class implementing cubic splines.
Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: OilPvtMultiplexer.hpp:169
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: OilPvtMultiplexer.hpp:152
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the saturation pressure of the oil phase [Pa].
Definition: OilPvtThermal.hpp:283
Evaluation viscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rs) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: OilPvtMultiplexer.hpp:159
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rs) const
Returns the formation volume factor [-] of the fluid phase.
Definition: OilPvtThermal.hpp:206
This class represents the Pressure-Volume-Temperature relations of the oil phase in the black-oil mod...
Definition: OilPvtMultiplexer.hpp:75
Implements a linearly interpolated scalar function that depends on one variable.
A central place for various physical constants occuring in some equations.
bool enableThermalViscosity() const
Returns true iff the viscosity of the oil phase is temperature dependent.
Definition: OilPvtThermal.hpp:160
void setNumRegions(size_t numRegions)
Set the number of PVT-regions considered by this object.
Definition: OilPvtThermal.hpp:137
This class implements temperature dependence of the PVT properties of oil.
Definition: OilPvtThermal.hpp:55
This file provides a wrapper around the &quot;final&quot; C++-2011 statement.
Implements a linearly interpolated scalar function that depends on one variable.
Definition: Tabulated1DFunction.hpp:47
void initEnd()
Finish initializing the thermal part of the oil phase PVT properties.
Definition: OilPvtThermal.hpp:148