My Project
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 "DryHumidGasPvt.hpp"
32 #include "WetGasPvt.hpp"
33 #include "GasPvtThermal.hpp"
34 #include "Co2GasPvt.hpp"
35 
36 #if HAVE_ECL_INPUT
37 #include <opm/input/eclipse/EclipseState/EclipseState.hpp>
38 #endif
39 
40 namespace Opm {
41 #define OPM_GAS_PVT_MULTIPLEXER_CALL(codeToCall) \
42  switch (gasPvtApproach_) { \
43  case GasPvtApproach::DryGasPvt: { \
44  auto& pvtImpl = getRealPvt<GasPvtApproach::DryGasPvt>(); \
45  codeToCall; \
46  break; \
47  } \
48  case GasPvtApproach::DryHumidGasPvt: { \
49  auto& pvtImpl = getRealPvt<GasPvtApproach::DryHumidGasPvt>(); \
50  codeToCall; \
51  break; \
52  } \
53  case GasPvtApproach::WetGasPvt: { \
54  auto& pvtImpl = getRealPvt<GasPvtApproach::WetGasPvt>(); \
55  codeToCall; \
56  break; \
57  } \
58  case GasPvtApproach::ThermalGasPvt: { \
59  auto& pvtImpl = getRealPvt<GasPvtApproach::ThermalGasPvt>(); \
60  codeToCall; \
61  break; \
62  } \
63  case GasPvtApproach::Co2GasPvt: { \
64  auto& pvtImpl = getRealPvt<GasPvtApproach::Co2GasPvt>(); \
65  codeToCall; \
66  break; \
67  } \
68  case GasPvtApproach::NoGasPvt: \
69  throw std::logic_error("Not implemented: Gas PVT of this deck!"); \
70  } \
71 
72 enum class GasPvtApproach {
73  NoGasPvt,
74  DryGasPvt,
75  DryHumidGasPvt,
76  WetGasPvt,
77  ThermalGasPvt,
78  Co2GasPvt
79 };
80 
91 template <class Scalar, bool enableThermal = true>
93 {
94 public:
96  {
97  gasPvtApproach_ = GasPvtApproach::NoGasPvt;
98  realGasPvt_ = nullptr;
99  }
100 
101  GasPvtMultiplexer(GasPvtApproach approach, void* realGasPvt)
102  : gasPvtApproach_(approach)
103  , realGasPvt_(realGasPvt)
104  { }
105 
107  {
108  *this = data;
109  }
110 
112  {
113  switch (gasPvtApproach_) {
114  case GasPvtApproach::DryGasPvt: {
115  delete &getRealPvt<GasPvtApproach::DryGasPvt>();
116  break;
117  }
118  case GasPvtApproach::DryHumidGasPvt: {
119  delete &getRealPvt<GasPvtApproach::DryHumidGasPvt>();
120  break;
121  }
122  case GasPvtApproach::WetGasPvt: {
123  delete &getRealPvt<GasPvtApproach::WetGasPvt>();
124  break;
125  }
126  case GasPvtApproach::ThermalGasPvt: {
127  delete &getRealPvt<GasPvtApproach::ThermalGasPvt>();
128  break;
129  }
130  case GasPvtApproach::Co2GasPvt: {
131  delete &getRealPvt<GasPvtApproach::Co2GasPvt>();
132  break;
133  }
134  case GasPvtApproach::NoGasPvt:
135  break;
136  }
137  }
138 
139 #if HAVE_ECL_INPUT
145  void initFromState(const EclipseState& eclState, const Schedule& schedule)
146  {
147  if (!eclState.runspec().phases().active(Phase::GAS))
148  return;
149  if (eclState.runspec().co2Storage())
150  setApproach(GasPvtApproach::Co2GasPvt);
151  else if (enableThermal && eclState.getSimulationConfig().isThermal())
152  setApproach(GasPvtApproach::ThermalGasPvt);
153  else if (!eclState.getTableManager().getPvtgTables().empty())
154  setApproach(GasPvtApproach::WetGasPvt);
155  else if (eclState.getTableManager().hasTables("PVDG"))
156  setApproach(GasPvtApproach::DryGasPvt);
157  else if (!eclState.getTableManager().getPvtgwTables().empty())
158  setApproach(GasPvtApproach::DryHumidGasPvt);
159 
160  OPM_GAS_PVT_MULTIPLEXER_CALL(pvtImpl.initFromState(eclState, schedule));
161  }
162 #endif // HAVE_ECL_INPUT
163 
164  void setApproach(GasPvtApproach gasPvtAppr)
165  {
166  switch (gasPvtAppr) {
167  case GasPvtApproach::DryGasPvt:
168  realGasPvt_ = new DryGasPvt<Scalar>;
169  break;
170 
171  case GasPvtApproach::DryHumidGasPvt:
172  realGasPvt_ = new DryHumidGasPvt<Scalar>;
173  break;
174 
175  case GasPvtApproach::WetGasPvt:
176  realGasPvt_ = new WetGasPvt<Scalar>;
177  break;
178 
179  case GasPvtApproach::ThermalGasPvt:
180  realGasPvt_ = new GasPvtThermal<Scalar>;
181  break;
182 
183  case GasPvtApproach::Co2GasPvt:
184  realGasPvt_ = new Co2GasPvt<Scalar>;
185  break;
186 
187  case GasPvtApproach::NoGasPvt:
188  throw std::logic_error("Not implemented: Gas PVT of this deck!");
189  }
190 
191  gasPvtApproach_ = gasPvtAppr;
192  }
193 
194  void initEnd()
195  { OPM_GAS_PVT_MULTIPLEXER_CALL(pvtImpl.initEnd()); }
196 
200  unsigned numRegions() const
201  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.numRegions()); return 1; }
202 
206  const Scalar gasReferenceDensity(unsigned regionIdx)
207  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.gasReferenceDensity(regionIdx)); return 2.; }
208 
212  template <class Evaluation>
213  Evaluation internalEnergy(unsigned regionIdx,
214  const Evaluation& temperature,
215  const Evaluation& pressure,
216  const Evaluation& Rv) const
217  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.internalEnergy(regionIdx, temperature, pressure, Rv)); return 0; }
218 
222  template <class Evaluation = Scalar>
223  Evaluation viscosity(unsigned regionIdx,
224  const Evaluation& temperature,
225  const Evaluation& pressure,
226  const Evaluation& Rv) const
227  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.viscosity(regionIdx, temperature, pressure, Rv)); return 0; }
228 
232  template <class Evaluation = Scalar>
233  Evaluation saturatedViscosity(unsigned regionIdx,
234  const Evaluation& temperature,
235  const Evaluation& pressure) const
236  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedViscosity(regionIdx, temperature, pressure)); return 0; }
237 
241  template <class Evaluation = Scalar>
242  Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
243  const Evaluation& temperature,
244  const Evaluation& pressure,
245  const Evaluation& Rv) const
246  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.inverseFormationVolumeFactor(regionIdx, temperature, pressure, Rv)); return 0; }
247 
251  template <class Evaluation = Scalar>
252  Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
253  const Evaluation& temperature,
254  const Evaluation& pressure) const
255  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedInverseFormationVolumeFactor(regionIdx, temperature, pressure)); return 0; }
256 
260  template <class Evaluation = Scalar>
261  Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
262  const Evaluation& temperature,
263  const Evaluation& pressure) const
264  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedOilVaporizationFactor(regionIdx, temperature, pressure)); return 0; }
265 
269  template <class Evaluation = Scalar>
270  Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
271  const Evaluation& temperature,
272  const Evaluation& pressure,
273  const Evaluation& oilSaturation,
274  const Evaluation& maxOilSaturation) const
275  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedOilVaporizationFactor(regionIdx, temperature, pressure, oilSaturation, maxOilSaturation)); return 0; }
276 
280  template <class Evaluation = Scalar>
281  Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
282  const Evaluation& temperature,
283  const Evaluation& pressure) const
284  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedWaterVaporizationFactor(regionIdx, temperature, pressure)); return 0; }
285 
292  template <class Evaluation = Scalar>
293  Evaluation saturationPressure(unsigned regionIdx,
294  const Evaluation& temperature,
295  const Evaluation& Rv) const
296  { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturationPressure(regionIdx, temperature, Rv)); return 0; }
297 
301  template <class Evaluation>
302  Evaluation diffusionCoefficient(const Evaluation& temperature,
303  const Evaluation& pressure,
304  unsigned compIdx) const
305  {
306  OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.diffusionCoefficient(temperature, pressure, compIdx)); return 0;
307  }
308 
314  GasPvtApproach gasPvtApproach() const
315  { return gasPvtApproach_; }
316 
317  // get the parameter object for the dry gas case
318  template <GasPvtApproach approachV>
319  typename std::enable_if<approachV == GasPvtApproach::DryGasPvt, DryGasPvt<Scalar> >::type& getRealPvt()
320  {
321  assert(gasPvtApproach() == approachV);
322  return *static_cast<DryGasPvt<Scalar>* >(realGasPvt_);
323  }
324 
325  template <GasPvtApproach approachV>
326  typename std::enable_if<approachV == GasPvtApproach::DryGasPvt, const DryGasPvt<Scalar> >::type& getRealPvt() const
327  {
328  assert(gasPvtApproach() == approachV);
329  return *static_cast<const DryGasPvt<Scalar>* >(realGasPvt_);
330  }
331 
332  // get the parameter object for the dry humid gas case
333  template <GasPvtApproach approachV>
334  typename std::enable_if<approachV == GasPvtApproach::DryHumidGasPvt, DryHumidGasPvt<Scalar> >::type& getRealPvt()
335  {
336  assert(gasPvtApproach() == approachV);
337  return *static_cast<DryHumidGasPvt<Scalar>* >(realGasPvt_);
338  }
339 
340  template <GasPvtApproach approachV>
341  typename std::enable_if<approachV == GasPvtApproach::DryHumidGasPvt, const DryHumidGasPvt<Scalar> >::type& getRealPvt() const
342  {
343  assert(gasPvtApproach() == approachV);
344  return *static_cast<const DryHumidGasPvt<Scalar>* >(realGasPvt_);
345  }
346 
347  // get the parameter object for the wet gas case
348  template <GasPvtApproach approachV>
349  typename std::enable_if<approachV == GasPvtApproach::WetGasPvt, WetGasPvt<Scalar> >::type& getRealPvt()
350  {
351  assert(gasPvtApproach() == approachV);
352  return *static_cast<WetGasPvt<Scalar>* >(realGasPvt_);
353  }
354 
355  template <GasPvtApproach approachV>
356  typename std::enable_if<approachV == GasPvtApproach::WetGasPvt, const WetGasPvt<Scalar> >::type& getRealPvt() const
357  {
358  assert(gasPvtApproach() == approachV);
359  return *static_cast<const WetGasPvt<Scalar>* >(realGasPvt_);
360  }
361 
362  // get the parameter object for the thermal gas case
363  template <GasPvtApproach approachV>
364  typename std::enable_if<approachV == GasPvtApproach::ThermalGasPvt, GasPvtThermal<Scalar> >::type& getRealPvt()
365  {
366  assert(gasPvtApproach() == approachV);
367  return *static_cast<GasPvtThermal<Scalar>* >(realGasPvt_);
368  }
369  template <GasPvtApproach approachV>
370  typename std::enable_if<approachV == GasPvtApproach::ThermalGasPvt, const GasPvtThermal<Scalar> >::type& getRealPvt() const
371  {
372  assert(gasPvtApproach() == approachV);
373  return *static_cast<const GasPvtThermal<Scalar>* >(realGasPvt_);
374  }
375 
376  template <GasPvtApproach approachV>
377  typename std::enable_if<approachV == GasPvtApproach::Co2GasPvt, Co2GasPvt<Scalar> >::type& getRealPvt()
378  {
379  assert(gasPvtApproach() == approachV);
380  return *static_cast<Co2GasPvt<Scalar>* >(realGasPvt_);
381  }
382 
383  template <GasPvtApproach approachV>
384  typename std::enable_if<approachV == GasPvtApproach::Co2GasPvt, const Co2GasPvt<Scalar> >::type& getRealPvt() const
385  {
386  assert(gasPvtApproach() == approachV);
387  return *static_cast<const Co2GasPvt<Scalar>* >(realGasPvt_);
388  }
389 
390  const void* realGasPvt() const { return realGasPvt_; }
391 
392  bool operator==(const GasPvtMultiplexer<Scalar,enableThermal>& data) const
393  {
394  if (this->gasPvtApproach() != data.gasPvtApproach())
395  return false;
396 
397  switch (gasPvtApproach_) {
398  case GasPvtApproach::DryGasPvt:
399  return *static_cast<const DryGasPvt<Scalar>*>(realGasPvt_) ==
400  *static_cast<const DryGasPvt<Scalar>*>(data.realGasPvt_);
401  case GasPvtApproach::DryHumidGasPvt:
402  return *static_cast<const DryHumidGasPvt<Scalar>*>(realGasPvt_) ==
403  *static_cast<const DryHumidGasPvt<Scalar>*>(data.realGasPvt_);
404  case GasPvtApproach::WetGasPvt:
405  return *static_cast<const WetGasPvt<Scalar>*>(realGasPvt_) ==
406  *static_cast<const WetGasPvt<Scalar>*>(data.realGasPvt_);
407  case GasPvtApproach::ThermalGasPvt:
408  return *static_cast<const GasPvtThermal<Scalar>*>(realGasPvt_) ==
409  *static_cast<const GasPvtThermal<Scalar>*>(data.realGasPvt_);
410  case GasPvtApproach::Co2GasPvt:
411  return *static_cast<const Co2GasPvt<Scalar>*>(realGasPvt_) ==
412  *static_cast<const Co2GasPvt<Scalar>*>(data.realGasPvt_);
413  default:
414  return true;
415  }
416  }
417 
418  GasPvtMultiplexer<Scalar,enableThermal>& operator=(const GasPvtMultiplexer<Scalar,enableThermal>& data)
419  {
420  gasPvtApproach_ = data.gasPvtApproach_;
421  switch (gasPvtApproach_) {
422  case GasPvtApproach::DryGasPvt:
423  realGasPvt_ = new DryGasPvt<Scalar>(*static_cast<const DryGasPvt<Scalar>*>(data.realGasPvt_));
424  break;
425  case GasPvtApproach::DryHumidGasPvt:
426  realGasPvt_ = new DryHumidGasPvt<Scalar>(*static_cast<const DryHumidGasPvt<Scalar>*>(data.realGasPvt_));
427  break;
428  case GasPvtApproach::WetGasPvt:
429  realGasPvt_ = new WetGasPvt<Scalar>(*static_cast<const WetGasPvt<Scalar>*>(data.realGasPvt_));
430  break;
431  case GasPvtApproach::ThermalGasPvt:
432  realGasPvt_ = new GasPvtThermal<Scalar>(*static_cast<const GasPvtThermal<Scalar>*>(data.realGasPvt_));
433  break;
434  case GasPvtApproach::Co2GasPvt:
435  realGasPvt_ = new Co2GasPvt<Scalar>(*static_cast<const Co2GasPvt<Scalar>*>(data.realGasPvt_));
436  break;
437  default:
438  break;
439  }
440 
441  return *this;
442  }
443 
444 private:
445  GasPvtApproach gasPvtApproach_;
446  void* realGasPvt_;
447 };
448 
449 #undef OPM_GAS_PVT_MULTIPLEXER_CALL
450 
451 } // namespace Opm
452 
453 #endif
This class represents the Pressure-Volume-Temperature relations of the gas phase for CO2.
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
This class represents the Pressure-Volume-Temperature relations of the gas phase with vaporized water...
This class implements temperature dependence of the PVT properties of gas.
This class represents the Pressure-Volume-Temperature relations of the gas phas with vaporized oil.
This class represents the Pressure-Volume-Temperature relations of the gas phase for CO2.
Definition: Co2GasPvt.hpp:54
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Definition: DryGasPvt.hpp:50
This class represents the Pressure-Volume-Temperature relations of the gas phase with vaporized water...
Definition: DryHumidGasPvt.hpp:54
This class represents the Pressure-Volume-Temperature relations of the gas phase in the black-oil mod...
Definition: GasPvtMultiplexer.hpp:93
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:242
GasPvtApproach gasPvtApproach() const
Returns the concrete approach for calculating the PVT relations.
Definition: GasPvtMultiplexer.hpp:314
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:252
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: GasPvtMultiplexer.hpp:200
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the water vaporization factor [m^3/m^3] of water saturated gas.
Definition: GasPvtMultiplexer.hpp:281
Evaluation diffusionCoefficient(const Evaluation &temperature, const Evaluation &pressure, unsigned compIdx) const
Calculate the binary molecular diffusion coefficient for a component in a fluid phase [mol^2 * s / (k...
Definition: GasPvtMultiplexer.hpp:302
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:261
const Scalar gasReferenceDensity(unsigned regionIdx)
Return the reference density which are considered by this PVT-object.
Definition: GasPvtMultiplexer.hpp:206
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:223
Evaluation internalEnergy(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rv) const
Returns the specific enthalpy [J/kg] of gas given a set of parameters.
Definition: GasPvtMultiplexer.hpp:213
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:293
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &oilSaturation, const Evaluation &maxOilSaturation) const
Returns the oil vaporization factor [m^3/m^3] of oil saturated gas.
Definition: GasPvtMultiplexer.hpp:270
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:233
This class implements temperature dependence of the PVT properties of gas.
Definition: GasPvtThermal.hpp:55
This class represents the Pressure-Volume-Temperature relations of the gas phas with vaporized oil.
Definition: WetGasPvt.hpp:54