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  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_GAS_PVT_MULTIPLEXER_HPP
26 #define OPM_GAS_PVT_MULTIPLEXER_HPP
27 
28 #include "DryGasPvt.hpp"
29 #include "WetGasPvt.hpp"
30 
31 #if HAVE_OPM_PARSER
32 #include <opm/parser/eclipse/Deck/Deck.hpp>
33 #include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
34 #include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
35 #include <opm/parser/eclipse/Deck/DeckRecord.hpp>
36 #endif
37 
38 namespace Opm {
39 template <class Scalar>
40 class OilPvtMultiplexer;
41 
42 #define OPM_GAS_PVT_MULTIPLEXER_CALL(codeToCall) \
43  switch (gasPvtApproach_) { \
44  case DryGasPvt: { \
45  auto &pvtImpl = getRealGasPvt<DryGasPvt>(); \
46  codeToCall; \
47  break; \
48  } \
49  case WetGasPvt: { \
50  auto &pvtImpl = getRealGasPvt<WetGasPvt>(); \
51  codeToCall; \
52  break; \
53  } \
54  case NoGasPvt: \
55  OPM_THROW(std::logic_error, "Not implemented: Gas PVT of this deck!"); \
56  }
57 
58 
69 template <class Scalar>
70 class GasPvtMultiplexer
71 {
72  typedef Opm::OilPvtMultiplexer<Scalar> OilPvtMultiplexer;
73 
74 public:
79  };
80 
82  {
83  gasPvtApproach_ = NoGasPvt;
84  }
85 
87  {
88  switch (gasPvtApproach_) {
89  case DryGasPvt: {
90  delete &getRealGasPvt<DryGasPvt>();
91  break;
92  }
93  case WetGasPvt: {
94  delete &getRealGasPvt<WetGasPvt>();
95  break;
96  }
97  case NoGasPvt:
98  break;
99  }
100  }
101 
102 #if HAVE_OPM_PARSER
103 
108  void initFromDeck(DeckConstPtr deck, EclipseStateConstPtr eclState)
109  {
110  if (deck->hasKeyword("PVTG"))
112  else if (deck->hasKeyword("PVDG"))
114 
115  OPM_GAS_PVT_MULTIPLEXER_CALL(pvtImpl.initFromDeck(deck, eclState));
116  }
117 #endif // HAVE_OPM_PARSER
118 
120  {
121  switch (gasPvtApproach) {
122  case DryGasPvt:
123  realGasPvt_ = new Opm::DryGasPvt<Scalar>;
124  break;
125 
126  case WetGasPvt:
127  realGasPvt_ = new Opm::WetGasPvt<Scalar>;
128  break;
129 
130  case NoGasPvt:
131  OPM_THROW(std::logic_error, "Not implemented: Gas PVT of this deck!");
132  }
133 
134  gasPvtApproach_ = gasPvtApproach;
135  }
136 
137  void initEnd(const OilPvtMultiplexer *oilPvt)
138  { OPM_GAS_PVT_MULTIPLEXER_CALL(pvtImpl.initEnd(oilPvt)); }
139 
143  template <class Evaluation = Scalar>
144  Evaluation viscosity(unsigned regionIdx,
145  const Evaluation& temperature,
146  const Evaluation& pressure,
147  const Evaluation& XgO) const
148  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.viscosity(regionIdx, temperature, pressure, XgO)); return 0; }
149 
153  template <class Evaluation = Scalar>
154  Evaluation formationVolumeFactor(unsigned regionIdx,
155  const Evaluation& temperature,
156  const Evaluation& pressure,
157  const Evaluation& XgO) const
158  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.formationVolumeFactor(regionIdx, temperature, pressure, XgO)); return 0; }
159 
163  template <class Evaluation = Scalar>
164  Evaluation density(unsigned regionIdx,
165  const Evaluation& temperature,
166  const Evaluation& pressure,
167  const Evaluation& XgO) const
168  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.density(regionIdx, temperature, pressure, XgO)); return 0; }
169 
174  template <class Evaluation = Scalar>
175  Evaluation fugacityCoefficientGas(unsigned regionIdx,
176  const Evaluation& temperature,
177  const Evaluation& pressure) const
178  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.fugacityCoefficientGas(regionIdx, temperature, pressure)); return 0; }
179 
180  template <class Evaluation = Scalar>
181  Evaluation fugacityCoefficientOil(unsigned regionIdx,
182  const Evaluation& temperature,
183  const Evaluation& pressure) const
184  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.fugacityCoefficientOil(regionIdx, temperature, pressure)); return 0; }
185 
186  template <class Evaluation = Scalar>
187  Evaluation fugacityCoefficientWater(unsigned regionIdx,
188  const Evaluation& temperature,
189  const Evaluation& pressure) const
190  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.fugacityCoefficientWater(regionIdx, temperature, pressure)); return 0; }
191 
195  template <class Evaluation = Scalar>
196  Evaluation oilVaporizationFactor(unsigned regionIdx,
197  const Evaluation& temperature,
198  const Evaluation& pressure) const
199  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.oilVaporizationFactor(regionIdx, temperature, pressure)); return 0; }
200 
207  template <class Evaluation = Scalar>
208  Evaluation gasSaturationPressure(unsigned regionIdx,
209  const Evaluation& temperature,
210  const Evaluation& XgO) const
211  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.gasSaturationPressure(regionIdx, temperature, XgO)); return 0; }
212 
217  template <class Evaluation = Scalar>
218  Evaluation saturatedGasOilMassFraction(unsigned regionIdx,
219  const Evaluation& temperature,
220  const Evaluation& pressure) const
221  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedGasOilMassFraction(regionIdx, temperature, pressure)); return 0; }
222 
227  template <class Evaluation = Scalar>
228  Evaluation saturatedGasOilMoleFraction(unsigned regionIdx,
229  const Evaluation& temperature,
230  const Evaluation& pressure) const
231  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedGasOilMoleFraction(regionIdx, temperature, pressure)); return 0; }
232 
233 
235  { return gasPvtApproach_; }
236 
237  // get the parameter object for the dry gas case
238  template <GasPvtApproach approachV>
239  typename std::enable_if<approachV == DryGasPvt, Opm::DryGasPvt<Scalar> >::type& getRealGasPvt()
240  {
241  assert(gasPvtApproach() == approachV);
242  return *static_cast<Opm::DryGasPvt<Scalar>* >(realGasPvt_);
243  }
244 
245  template <GasPvtApproach approachV>
246  typename std::enable_if<approachV == DryGasPvt, const Opm::DryGasPvt<Scalar> >::type& getRealGasPvt() const
247  {
248  assert(gasPvtApproach() == approachV);
249  return *static_cast<const Opm::DryGasPvt<Scalar>* >(realGasPvt_);
250  }
251 
252  // get the parameter object for the wet gas case
253  template <GasPvtApproach approachV>
254  typename std::enable_if<approachV == WetGasPvt, Opm::WetGasPvt<Scalar> >::type& getRealGasPvt()
255  {
256  assert(gasPvtApproach() == approachV);
257  return *static_cast<Opm::WetGasPvt<Scalar>* >(realGasPvt_);
258  }
259 
260  template <GasPvtApproach approachV>
261  typename std::enable_if<approachV == WetGasPvt, const Opm::WetGasPvt<Scalar> >::type& getRealGasPvt() const
262  {
263  assert(gasPvtApproach() == approachV);
264  return *static_cast<const Opm::WetGasPvt<Scalar>* >(realGasPvt_);
265  }
266 
267 private:
268  GasPvtApproach gasPvtApproach_;
269  void *realGasPvt_;
270 };
271 
272 #undef OPM_GAS_MULTIPLEXER_CALL
273 
274 } // namespace Opm
275 
276 #endif
GasPvtApproach gasPvtApproach() const
Definition: GasPvtMultiplexer.hpp:234
This class represents the Pressure-Volume-Temperature relations of the oil phase in the black-oil mod...
Definition: DryGasPvt.hpp:44
GasPvtApproach
Definition: GasPvtMultiplexer.hpp:75
void initEnd(const OilPvtMultiplexer *oilPvt)
Definition: GasPvtMultiplexer.hpp:137
Evaluation oilVaporizationFactor(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:196
Definition: Air_Mesitylene.hpp:31
std::enable_if< approachV==DryGasPvt, Opm::DryGasPvt< Scalar > >::type & getRealGasPvt()
Definition: GasPvtMultiplexer.hpp:239
void setApproach(GasPvtApproach gasPvtApproach)
Definition: GasPvtMultiplexer.hpp:119
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: GasPvtMultiplexer.hpp:164
std::enable_if< approachV==DryGasPvt, const Opm::DryGasPvt< Scalar > >::type & getRealGasPvt() const
Definition: GasPvtMultiplexer.hpp:246
Evaluation fugacityCoefficientGas(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the fugacity coefficient [Pa] of the gas component in the gas phase given a set of parameters...
Definition: GasPvtMultiplexer.hpp:175
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Definition: DryGasPvt.hpp:51
Definition: GasPvtMultiplexer.hpp:76
Evaluation saturatedGasOilMassFraction(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the gas mass fraction of oil-saturated gas at a given temperatire and pressure [-]...
Definition: GasPvtMultiplexer.hpp:218
Evaluation saturatedGasOilMoleFraction(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the gas mole fraction of oil-saturated gas at a given temperatire and pressure [-]...
Definition: GasPvtMultiplexer.hpp:228
GasPvtMultiplexer()
Definition: GasPvtMultiplexer.hpp:81
This class represents the Pressure-Volume-Temperature relations of the gas phas with vaporized oil...
Definition: WetGasPvt.hpp:49
Evaluation fugacityCoefficientOil(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Definition: GasPvtMultiplexer.hpp:181
#define OPM_GAS_PVT_MULTIPLEXER_CALL(codeToCall)
Definition: GasPvtMultiplexer.hpp:42
Evaluation viscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &XgO) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: GasPvtMultiplexer.hpp:144
~GasPvtMultiplexer()
Definition: GasPvtMultiplexer.hpp:86
This class represents the Pressure-Volume-Temperature relations of the gas phas with vaporized oil...
Definition: GasPvtMultiplexer.hpp:77
Evaluation fugacityCoefficientWater(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Definition: GasPvtMultiplexer.hpp:187
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
std::enable_if< approachV==WetGasPvt, const Opm::WetGasPvt< Scalar > >::type & getRealGasPvt() const
Definition: GasPvtMultiplexer.hpp:261
std::enable_if< approachV==WetGasPvt, Opm::WetGasPvt< Scalar > >::type & getRealGasPvt()
Definition: GasPvtMultiplexer.hpp:254
Evaluation gasSaturationPressure(unsigned regionIdx, const Evaluation &temperature, const Evaluation &XgO) const
Returns the saturation pressure of the gas phase [Pa] depending on its mass fraction of the oil compo...
Definition: GasPvtMultiplexer.hpp:208
Evaluation formationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &XgO) const
Returns the formation volume factor [-] of the fluid phase.
Definition: GasPvtMultiplexer.hpp:154