GasPvtMultiplexer.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_GAS_PVT_MULTIPLEXER_HPP
28 #define OPM_GAS_PVT_MULTIPLEXER_HPP
29 
30 #include "DryGasPvt.hpp"
31 #include "WetGasPvt.hpp"
32 #include "GasPvtThermal.hpp"
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/Deck/DeckKeyword.hpp>
38 #include <opm/parser/eclipse/Deck/DeckRecord.hpp>
39 #endif
40 
41 namespace Opm {
42 #define OPM_GAS_PVT_MULTIPLEXER_CALL(codeToCall) \
43  switch (gasPvtApproach_) { \
44  case DryGasPvt: { \
45  auto& pvtImpl = getRealPvt<DryGasPvt>(); \
46  codeToCall; \
47  break; \
48  } \
49  case WetGasPvt: { \
50  auto& pvtImpl = getRealPvt<WetGasPvt>(); \
51  codeToCall; \
52  break; \
53  } \
54  case ThermalGasPvt: { \
55  auto& pvtImpl = getRealPvt<ThermalGasPvt>(); \
56  codeToCall; \
57  break; \
58  } \
59  case NoGasPvt: \
60  OPM_THROW(std::logic_error, "Not implemented: Gas PVT of this deck!"); \
61  }
62 
63 
74 template <class Scalar, bool enableThermal = true>
76 {
77 public:
79 
80  enum GasPvtApproach {
81  NoGasPvt,
82  DryGasPvt,
83  WetGasPvt,
84  ThermalGasPvt
85  };
86 
88  {
89  gasPvtApproach_ = NoGasPvt;
90  }
91 
93  {
94  switch (gasPvtApproach_) {
95  case DryGasPvt: {
96  delete &getRealPvt<DryGasPvt>();
97  break;
98  }
99  case WetGasPvt: {
100  delete &getRealPvt<WetGasPvt>();
101  break;
102  }
103  case ThermalGasPvt: {
104  delete &getRealPvt<ThermalGasPvt>();
105  break;
106  }
107  case NoGasPvt:
108  break;
109  }
110  }
111 
112 #if HAVE_OPM_PARSER
113 
118  void initFromDeck(const Deck& deck, const EclipseState& eclState)
119  {
120  bool enableGas = deck.hasKeyword("GAS");
121  if (!enableGas)
122  return;
123 
124  if (enableThermal
125  && (deck.hasKeyword("TREF")
126  || deck.hasKeyword("GASVISCT")))
127  setApproach(ThermalGasPvt);
128  else if (deck.hasKeyword("PVTG"))
129  setApproach(WetGasPvt);
130  else if (deck.hasKeyword("PVDG"))
131  setApproach(DryGasPvt);
132 
133  OPM_GAS_PVT_MULTIPLEXER_CALL(pvtImpl.initFromDeck(deck, eclState));
134  }
135 #endif // HAVE_OPM_PARSER
136 
137  void setApproach(GasPvtApproach gasPvtAppr)
138  {
139  switch (gasPvtAppr) {
140  case DryGasPvt:
141  realGasPvt_ = new Opm::DryGasPvt<Scalar>;
142  break;
143 
144  case WetGasPvt:
145  realGasPvt_ = new Opm::WetGasPvt<Scalar>;
146  break;
147 
148  case ThermalGasPvt:
149  realGasPvt_ = new Opm::GasPvtThermal<Scalar>;
150  break;
151 
152  case NoGasPvt:
153  OPM_THROW(std::logic_error, "Not implemented: Gas PVT of this deck!");
154  }
155 
156  gasPvtApproach_ = gasPvtAppr;
157  }
158 
159  void initEnd()
160  { OPM_GAS_PVT_MULTIPLEXER_CALL(pvtImpl.initEnd()); }
161 
165  unsigned numRegions() const
166  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.numRegions()); return 1; }
167 
171  template <class Evaluation = Scalar>
172  Evaluation viscosity(unsigned regionIdx,
173  const Evaluation& temperature,
174  const Evaluation& pressure,
175  const Evaluation& Rv) const
176  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.viscosity(regionIdx, temperature, pressure, Rv)); return 0; }
177 
181  template <class Evaluation = Scalar>
182  Evaluation saturatedViscosity(unsigned regionIdx,
183  const Evaluation& temperature,
184  const Evaluation& pressure) const
185  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedViscosity(regionIdx, temperature, pressure)); return 0; }
186 
190  template <class Evaluation = Scalar>
191  Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
192  const Evaluation& temperature,
193  const Evaluation& pressure,
194  const Evaluation& Rv) const
195  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.inverseFormationVolumeFactor(regionIdx, temperature, pressure, Rv)); return 0; }
196 
200  template <class Evaluation = Scalar>
201  Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
202  const Evaluation& temperature,
203  const Evaluation& pressure) const
204  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedInverseFormationVolumeFactor(regionIdx, temperature, pressure)); return 0; }
205 
209  template <class Evaluation = Scalar>
210  Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
211  const Evaluation& temperature,
212  const Evaluation& pressure) const
213  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedOilVaporizationFactor(regionIdx, temperature, pressure)); return 0; }
214 
218  template <class Evaluation = Scalar>
219  Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
220  const Evaluation& temperature,
221  const Evaluation& pressure,
222  const Evaluation& oilSaturation,
223  Scalar maxOilSaturation) const
224  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedOilVaporizationFactor(regionIdx, temperature, pressure, oilSaturation, maxOilSaturation)); return 0; }
225 
232  template <class Evaluation = Scalar>
233  Evaluation saturationPressure(unsigned regionIdx,
234  const Evaluation& temperature,
235  const Evaluation& Rv) const
236  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturationPressure(regionIdx, temperature, Rv)); return 0; }
237 
243  GasPvtApproach gasPvtApproach() const
244  { return gasPvtApproach_; }
245 
246  // get the parameter object for the dry gas case
247  template <GasPvtApproach approachV>
248  typename std::enable_if<approachV == DryGasPvt, Opm::DryGasPvt<Scalar> >::type& getRealPvt()
249  {
250  assert(gasPvtApproach() == approachV);
251  return *static_cast<Opm::DryGasPvt<Scalar>* >(realGasPvt_);
252  }
253 
254  template <GasPvtApproach approachV>
255  typename std::enable_if<approachV == DryGasPvt, const Opm::DryGasPvt<Scalar> >::type& getRealPvt() const
256  {
257  assert(gasPvtApproach() == approachV);
258  return *static_cast<const Opm::DryGasPvt<Scalar>* >(realGasPvt_);
259  }
260 
261  // get the parameter object for the wet gas case
262  template <GasPvtApproach approachV>
263  typename std::enable_if<approachV == WetGasPvt, Opm::WetGasPvt<Scalar> >::type& getRealPvt()
264  {
265  assert(gasPvtApproach() == approachV);
266  return *static_cast<Opm::WetGasPvt<Scalar>* >(realGasPvt_);
267  }
268 
269  template <GasPvtApproach approachV>
270  typename std::enable_if<approachV == WetGasPvt, const Opm::WetGasPvt<Scalar> >::type& getRealPvt() const
271  {
272  assert(gasPvtApproach() == approachV);
273  return *static_cast<const Opm::WetGasPvt<Scalar>* >(realGasPvt_);
274  }
275 
276  // get the parameter object for the thermal gas case
277  template <GasPvtApproach approachV>
278  typename std::enable_if<approachV == ThermalGasPvt, Opm::GasPvtThermal<Scalar> >::type& getRealPvt()
279  {
280  assert(gasPvtApproach() == approachV);
281  return *static_cast<Opm::GasPvtThermal<Scalar>* >(realGasPvt_);
282  }
283 
284  template <GasPvtApproach approachV>
285  typename std::enable_if<approachV == ThermalGasPvt, const Opm::GasPvtThermal<Scalar> >::type& getRealPvt() const
286  {
287  assert(gasPvtApproach() == approachV);
288  return *static_cast<const Opm::GasPvtThermal<Scalar>* >(realGasPvt_);
289  }
290 
291 private:
292  GasPvtApproach gasPvtApproach_;
293  void* realGasPvt_;
294 };
295 
296 #undef OPM_GAS_PVT_MULTIPLEXER_CALL
297 
298 } // namespace Opm
299 
300 #endif
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: GasPvtMultiplexer.hpp:165
Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of oil saturated gas given a set of parameters.
Definition: GasPvtMultiplexer.hpp:182
This class represents the Pressure-Volume-Temperature relations of the gas phas with vaporized oil...
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rv) const
Returns the formation volume factor [-] of the fluid phase.
Definition: GasPvtMultiplexer.hpp:191
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the formation volume factor [-] of oil saturated gas given a set of parameters.
Definition: GasPvtMultiplexer.hpp:201
GasPvtApproach gasPvtApproach() const
Returns the concrete approach for calculating the PVT relations.
Definition: GasPvtMultiplexer.hpp:243
Definition: Air_Mesitylene.hpp:33
This class represents the Pressure-Volume-Temperature relations of the gas phase in the black-oil mod...
Definition: GasPvtMultiplexer.hpp:75
This class implements temperature dependence of the PVT properties of gas.
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &oilSaturation, Scalar maxOilSaturation) const
Returns the oil vaporization factor [m^3/m^3] of oil saturated gas.
Definition: GasPvtMultiplexer.hpp:219
This class represents the Pressure-Volume-Temperature relations of the gas phas with vaporized oil...
Definition: WetGasPvt.hpp:47
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the oil vaporization factor [m^3/m^3] of oil saturated gas.
Definition: GasPvtMultiplexer.hpp:210
This class implements temperature dependence of the PVT properties of gas.
Definition: GasPvtThermal.hpp:55
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &temperature, const Evaluation &Rv) const
Returns the saturation pressure of the gas phase [Pa] depending on its mass fraction of the oil compo...
Definition: GasPvtMultiplexer.hpp:233
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Definition: DryGasPvt.hpp:51
Evaluation viscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rv) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: GasPvtMultiplexer.hpp:172
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...