OilPvtMultiplexer.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_OIL_PVT_MULTIPLEXER_HPP
26 #define OPM_OIL_PVT_MULTIPLEXER_HPP
27 
29 #include "DeadOilPvt.hpp"
30 #include "LiveOilPvt.hpp"
31 
32 namespace Opm {
33 template <class Scalar>
34 class GasPvtMultiplexer;
35 
36 #define OPM_OIL_PVT_MULTIPLEXER_CALL(codeToCall) \
37  switch (oilPvtApproach_) { \
38  case ConstantCompressibilityOilPvt: { \
39  auto &pvtImpl = getRealOilPvt<ConstantCompressibilityOilPvt>(); \
40  codeToCall; \
41  break; \
42  } \
43  case DeadOilPvt: { \
44  auto &pvtImpl = getRealOilPvt<DeadOilPvt>(); \
45  codeToCall; \
46  break; \
47  } \
48  case LiveOilPvt: { \
49  auto &pvtImpl = getRealOilPvt<LiveOilPvt>(); \
50  codeToCall; \
51  break; \
52  } \
53  case NoOilPvt: \
54  OPM_THROW(std::logic_error, "Not implemented: Oil PVT of this deck!"); \
55  }
56 
69 template <class Scalar>
70 class OilPvtMultiplexer
71 {
72  typedef Opm::GasPvtMultiplexer<Scalar> GasPvtMultiplexer;
73 
74 public:
80  };
81 
83  {
84  oilPvtApproach_ = NoOilPvt;
85  }
86 
88  {
89  switch (oilPvtApproach_) {
91  delete &getRealOilPvt<ConstantCompressibilityOilPvt>();
92  break;
93  }
94  case DeadOilPvt: {
95  delete &getRealOilPvt<DeadOilPvt>();
96  break;
97  }
98  case LiveOilPvt: {
99  delete &getRealOilPvt<LiveOilPvt>();
100  break;
101  }
102 
103  case NoOilPvt:
104  break;
105  }
106  }
107 
108 #if HAVE_OPM_PARSER
109 
114  void initFromDeck(DeckConstPtr deck, EclipseStateConstPtr eclState)
115  {
116  if (deck->hasKeyword("PVCDO"))
118  else if (deck->hasKeyword("PVDO"))
120  else if (deck->hasKeyword("PVTO"))
122 
123  OPM_OIL_PVT_MULTIPLEXER_CALL(pvtImpl.initFromDeck(deck, eclState));
124  }
125 #endif // HAVE_OPM_PARSER
126 
127 
128  void initEnd(const GasPvtMultiplexer *gasPvt)
129  { OPM_OIL_PVT_MULTIPLEXER_CALL(pvtImpl.initEnd(gasPvt)); }
130 
134  template <class Evaluation>
135  Evaluation viscosity(unsigned regionIdx,
136  const Evaluation& temperature,
137  const Evaluation& pressure,
138  const Evaluation& XoG) const
139  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.viscosity(regionIdx, temperature, pressure, XoG)); return 0; }
140 
144  template <class Evaluation>
145  Evaluation formationVolumeFactor(unsigned regionIdx,
146  const Evaluation& temperature,
147  const Evaluation& pressure,
148  const Evaluation& XoG) const
149  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.formationVolumeFactor(regionIdx, temperature, pressure, XoG)); return 0; }
150 
154  template <class Evaluation>
155  Evaluation density(unsigned regionIdx,
156  const Evaluation& temperature,
157  const Evaluation& pressure,
158  const Evaluation& XoG) const
159  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.density(regionIdx, temperature, pressure, XoG)); return 0; }
160 
165  template <class Evaluation>
166  Evaluation fugacityCoefficientOil(unsigned regionIdx,
167  const Evaluation& temperature,
168  const Evaluation& pressure) const
169  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.fugacityCoefficientOil(regionIdx, temperature, pressure)); return 0; }
170 
175  template <class Evaluation>
176  Evaluation fugacityCoefficientGas(unsigned regionIdx,
177  const Evaluation& temperature,
178  const Evaluation& pressure) const
179  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.fugacityCoefficientGas(regionIdx, temperature, pressure)); return 0; }
180 
185  template <class Evaluation>
186  Evaluation fugacityCoefficientWater(unsigned regionIdx,
187  const Evaluation& temperature,
188  const Evaluation& pressure) const
189  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.fugacityCoefficientWater(regionIdx, temperature, pressure)); return 0; }
190 
194  template <class Evaluation>
195  Evaluation gasDissolutionFactor(unsigned regionIdx,
196  const Evaluation& temperature,
197  const Evaluation& pressure) const
198  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.gasDissolutionFactor(regionIdx, temperature, pressure)); return 0; }
199 
207  template <class Evaluation>
208  Evaluation oilSaturationPressure(unsigned regionIdx,
209  const Evaluation& temperature,
210  const Evaluation& XoG) const
211  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.oilSaturationPressure(regionIdx, temperature, XoG)); return 0; }
212 
220  template <class Evaluation>
221  Evaluation saturatedOilGasMassFraction(unsigned regionIdx,
222  const Evaluation& temperature,
223  const Evaluation& pressure) const
224  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedOilGasMassFraction(regionIdx, temperature, pressure)); return 0; }
225 
233  template <class Evaluation>
234  Evaluation saturatedOilGasMoleFraction(unsigned regionIdx,
235  const Evaluation& temperature,
236  const Evaluation& pressure) const
237  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedOilGasMoleFraction(regionIdx, temperature, pressure)); return 0; }
238 
240  {
241  switch (oilPvtApproach) {
244  break;
245 
246  case DeadOilPvt:
247  realOilPvt_ = new Opm::DeadOilPvt<Scalar>;
248  break;
249 
250  case LiveOilPvt:
251  realOilPvt_ = new Opm::LiveOilPvt<Scalar>;
252  break;
253 
254  case NoOilPvt:
255  OPM_THROW(std::logic_error, "Not implemented: Oil PVT of this deck!");
256  }
257 
258  oilPvtApproach_ = oilPvtApproach;
259  }
260 
262  { return oilPvtApproach_; }
263 
264  // get the parameter object for the dry oil case
265  template <OilPvtApproach approachV>
266  typename std::enable_if<approachV == LiveOilPvt, Opm::LiveOilPvt<Scalar> >::type& getRealOilPvt()
267  {
268  assert(oilPvtApproach() == approachV);
269  return *static_cast<Opm::LiveOilPvt<Scalar>* >(realOilPvt_);
270  }
271 
272  template <OilPvtApproach approachV>
273  typename std::enable_if<approachV == LiveOilPvt, const Opm::LiveOilPvt<Scalar> >::type& getRealOilPvt() const
274  {
275  assert(oilPvtApproach() == approachV);
276  return *static_cast<Opm::LiveOilPvt<Scalar>* >(realOilPvt_);
277  }
278 
279  template <OilPvtApproach approachV>
280  typename std::enable_if<approachV == DeadOilPvt, Opm::DeadOilPvt<Scalar> >::type& getRealOilPvt()
281  {
282  assert(oilPvtApproach() == approachV);
283  return *static_cast<Opm::DeadOilPvt<Scalar>* >(realOilPvt_);
284  }
285 
286  template <OilPvtApproach approachV>
287  typename std::enable_if<approachV == DeadOilPvt, const Opm::DeadOilPvt<Scalar> >::type& getRealOilPvt() const
288  {
289  assert(oilPvtApproach() == approachV);
290  return *static_cast<Opm::DeadOilPvt<Scalar>* >(realOilPvt_);
291  }
292 
293  template <OilPvtApproach approachV>
294  typename std::enable_if<approachV == ConstantCompressibilityOilPvt, Opm::ConstantCompressibilityOilPvt<Scalar> >::type& getRealOilPvt()
295  {
296  assert(oilPvtApproach() == approachV);
297  return *static_cast<Opm::ConstantCompressibilityOilPvt<Scalar>* >(realOilPvt_);
298  }
299 
300  template <OilPvtApproach approachV>
301  typename std::enable_if<approachV == ConstantCompressibilityOilPvt, const Opm::ConstantCompressibilityOilPvt<Scalar> >::type& getRealOilPvt() const
302  {
303  assert(oilPvtApproach() == approachV);
304  return *static_cast<Opm::ConstantCompressibilityOilPvt<Scalar>* >(realOilPvt_);
305  }
306 
307 private:
308  OilPvtApproach oilPvtApproach_;
309  void *realOilPvt_;
310 };
311 
312 } // namespace Opm
313 
314 #endif
std::enable_if< approachV==DeadOilPvt, const Opm::DeadOilPvt< Scalar > >::type & getRealOilPvt() const
Definition: OilPvtMultiplexer.hpp:287
Definition: OilPvtMultiplexer.hpp:77
#define OPM_OIL_PVT_MULTIPLEXER_CALL(codeToCall)
Definition: OilPvtMultiplexer.hpp:36
Evaluation fugacityCoefficientOil(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the fugacity coefficient [-] of the oil component in the oil phase given a pressure and a tem...
Definition: OilPvtMultiplexer.hpp:166
This class represents the Pressure-Volume-Temperature relations of the oil phas with dissolved gas...
OilPvtApproach
Definition: OilPvtMultiplexer.hpp:75
This class represents the Pressure-Volume-Temperature relations of the oil phas with dissolved gas...
Definition: LiveOilPvt.hpp:48
Definition: Air_Mesitylene.hpp:31
OilPvtApproach oilPvtApproach() const
Definition: OilPvtMultiplexer.hpp:261
std::enable_if< approachV==DeadOilPvt, Opm::DeadOilPvt< Scalar > >::type & getRealOilPvt()
Definition: OilPvtMultiplexer.hpp:280
Evaluation oilSaturationPressure(unsigned regionIdx, const Evaluation &temperature, const Evaluation &XoG) const
Returns the saturation pressure [Pa] of oil given the mass fraction of the gas component in the oil p...
Definition: OilPvtMultiplexer.hpp:208
This class represents the Pressure-Volume-Temperature relations of the gas phase in the black-oil mod...
Definition: ConstantCompressibilityOilPvt.hpp:39
This class represents the Pressure-Volume-Temperature relations of the oil phase without dissolved ga...
Definition: DeadOilPvt.hpp:45
void setApproach(OilPvtApproach oilPvtApproach)
Definition: OilPvtMultiplexer.hpp:239
Evaluation density(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &XoG) const
Returns the density [kg/m^3] of the fluid phase given a set of parameters.
Definition: OilPvtMultiplexer.hpp:155
Evaluation saturatedOilGasMassFraction(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the gas mass fraction of gas-saturated oil at a given temperatire and pressure [-]...
Definition: OilPvtMultiplexer.hpp:221
Evaluation saturatedOilGasMoleFraction(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the gas mole fraction of gas-saturated oil at a given temperatire and pressure [-]...
Definition: OilPvtMultiplexer.hpp:234
~OilPvtMultiplexer()
Definition: OilPvtMultiplexer.hpp:87
std::enable_if< approachV==LiveOilPvt, const Opm::LiveOilPvt< Scalar > >::type & getRealOilPvt() const
Definition: OilPvtMultiplexer.hpp:273
void initEnd(const GasPvtMultiplexer *gasPvt)
Definition: OilPvtMultiplexer.hpp:128
Evaluation gasDissolutionFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the gas dissolution factor [m^3/m^3] of saturated oil.
Definition: OilPvtMultiplexer.hpp:195
Evaluation formationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &XoG) const
Returns the formation volume factor [-] of the fluid phase.
Definition: OilPvtMultiplexer.hpp:145
Definition: OilPvtMultiplexer.hpp:76
Evaluation fugacityCoefficientWater(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the fugacity coefficient [-] of the water component in the oil phase given a pressure and a t...
Definition: OilPvtMultiplexer.hpp:186
This class represents the Pressure-Volume-Temperature relations of the oil phase without dissolved ga...
std::enable_if< approachV==LiveOilPvt, Opm::LiveOilPvt< Scalar > >::type & getRealOilPvt()
Definition: OilPvtMultiplexer.hpp:266
This class represents the Pressure-Volume-Temperature relations of the oil phase without dissolved ga...
std::enable_if< approachV==ConstantCompressibilityOilPvt, const Opm::ConstantCompressibilityOilPvt< Scalar > >::type & getRealOilPvt() const
Definition: OilPvtMultiplexer.hpp:301
Evaluation viscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &XoG) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: OilPvtMultiplexer.hpp:135
OilPvtMultiplexer()
Definition: OilPvtMultiplexer.hpp:82
Definition: OilPvtMultiplexer.hpp:78
Evaluation fugacityCoefficientGas(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the fugacity coefficient [-] of the gas component in the oil phase given a pressure and a tem...
Definition: OilPvtMultiplexer.hpp:176
This class represents the Pressure-Volume-Temperature relations of the oil phase without dissolved ga...
Definition: ConstantCompressibilityOilPvt.hpp:46
std::enable_if< approachV==ConstantCompressibilityOilPvt, Opm::ConstantCompressibilityOilPvt< Scalar > >::type & getRealOilPvt()
Definition: OilPvtMultiplexer.hpp:294