All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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  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_MULTIPLEXER_HPP
28 #define OPM_OIL_PVT_MULTIPLEXER_HPP
29 
31 #include "DeadOilPvt.hpp"
32 #include "LiveOilPvt.hpp"
33 #include "OilPvtThermal.hpp"
34 
35 namespace Opm {
36 #define OPM_OIL_PVT_MULTIPLEXER_CALL(codeToCall) \
37  switch (approach_) { \
38  case ConstantCompressibilityOilPvt: { \
39  auto& pvtImpl = getRealPvt<ConstantCompressibilityOilPvt>(); \
40  codeToCall; \
41  break; \
42  } \
43  case DeadOilPvt: { \
44  auto& pvtImpl = getRealPvt<DeadOilPvt>(); \
45  codeToCall; \
46  break; \
47  } \
48  case LiveOilPvt: { \
49  auto& pvtImpl = getRealPvt<LiveOilPvt>(); \
50  codeToCall; \
51  break; \
52  } \
53  case ThermalOilPvt: { \
54  auto& pvtImpl = getRealPvt<ThermalOilPvt>(); \
55  codeToCall; \
56  break; \
57  } \
58  case NoOilPvt: \
59  OPM_THROW(std::logic_error, "Not implemented: Oil PVT of this deck!"); \
60  }
61 
74 template <class Scalar, bool enableThermal = true>
76 {
77 public:
79 
80  enum OilPvtApproach {
81  NoOilPvt,
82  LiveOilPvt,
83  DeadOilPvt,
85  ThermalOilPvt
86  };
87 
89  {
90  approach_ = NoOilPvt;
91  }
92 
94  {
95  switch (approach_) {
96  case LiveOilPvt: {
97  delete &getRealPvt<LiveOilPvt>();
98  break;
99  }
100  case DeadOilPvt: {
101  delete &getRealPvt<DeadOilPvt>();
102  break;
103  }
105  delete &getRealPvt<ConstantCompressibilityOilPvt>();
106  break;
107  }
108  case ThermalOilPvt: {
109  delete &getRealPvt<ThermalOilPvt>();
110  break;
111  }
112 
113  case NoOilPvt:
114  break;
115  }
116  }
117 
118 #if HAVE_OPM_PARSER
119 
124  void initFromDeck(const Deck& deck, const EclipseState& eclState)
125  {
126  bool enableOil = deck.hasKeyword("OIL");
127  if (!enableOil)
128  return;
129 
130  if (enableThermal
131  && (deck.hasKeyword("THERMEX1")
132  || deck.hasKeyword("VISCREF")))
133  setApproach(ThermalOilPvt);
134  else if (deck.hasKeyword("PVCDO"))
135  setApproach(ConstantCompressibilityOilPvt);
136  else if (deck.hasKeyword("PVDO"))
137  setApproach(DeadOilPvt);
138  else if (deck.hasKeyword("PVTO"))
139  setApproach(LiveOilPvt);
140 
141  OPM_OIL_PVT_MULTIPLEXER_CALL(pvtImpl.initFromDeck(deck, eclState));
142  }
143 #endif // HAVE_OPM_PARSER
144 
145 
146  void initEnd()
147  { OPM_OIL_PVT_MULTIPLEXER_CALL(pvtImpl.initEnd()); }
148 
152  unsigned numRegions() const
153  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.numRegions()); return 1; }
154 
158  template <class Evaluation>
159  Evaluation viscosity(unsigned regionIdx,
160  const Evaluation& temperature,
161  const Evaluation& pressure,
162  const Evaluation& Rs) const
163  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.viscosity(regionIdx, temperature, pressure, Rs)); return 0; }
164 
168  template <class Evaluation>
169  Evaluation saturatedViscosity(unsigned regionIdx,
170  const Evaluation& temperature,
171  const Evaluation& pressure) const
172  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedViscosity(regionIdx, temperature, pressure)); return 0; }
173 
177  template <class Evaluation>
178  Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
179  const Evaluation& temperature,
180  const Evaluation& pressure,
181  const Evaluation& Rs) const
182  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.inverseFormationVolumeFactor(regionIdx, temperature, pressure, Rs)); return 0; }
183 
187  template <class Evaluation>
188  Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
189  const Evaluation& temperature,
190  const Evaluation& pressure) const
191  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedInverseFormationVolumeFactor(regionIdx, temperature, pressure)); return 0; }
192 
196  template <class Evaluation>
197  Evaluation saturatedGasDissolutionFactor(unsigned regionIdx,
198  const Evaluation& temperature,
199  const Evaluation& pressure) const
200  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedGasDissolutionFactor(regionIdx, temperature, pressure)); return 0; }
201 
205  template <class Evaluation>
206  Evaluation saturatedGasDissolutionFactor(unsigned regionIdx,
207  const Evaluation& temperature,
208  const Evaluation& pressure,
209  const Evaluation& oilSaturation,
210  Scalar maxOilSaturation) const
211  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedGasDissolutionFactor(regionIdx, temperature, pressure, oilSaturation, maxOilSaturation)); return 0; }
212 
220  template <class Evaluation>
221  Evaluation saturationPressure(unsigned regionIdx,
222  const Evaluation& temperature,
223  const Evaluation& Rs) const
224  { OPM_OIL_PVT_MULTIPLEXER_CALL(return pvtImpl.saturationPressure(regionIdx, temperature, Rs)); return 0; }
225 
226  void setApproach(OilPvtApproach appr)
227  {
228  switch (appr) {
229  case LiveOilPvt:
230  realOilPvt_ = new Opm::LiveOilPvt<Scalar>;
231  break;
232 
233  case DeadOilPvt:
234  realOilPvt_ = new Opm::DeadOilPvt<Scalar>;
235  break;
236 
239  break;
240 
241  case ThermalOilPvt:
242  realOilPvt_ = new Opm::OilPvtThermal<Scalar>;
243  break;
244 
245  case NoOilPvt:
246  OPM_THROW(std::logic_error, "Not implemented: Oil PVT of this deck!");
247  }
248 
249  approach_ = appr;
250  }
251 
257  OilPvtApproach approach() const
258  { return approach_; }
259 
260  // get the concrete parameter object for the oil phase
261  template <OilPvtApproach approachV>
262  typename std::enable_if<approachV == LiveOilPvt, Opm::LiveOilPvt<Scalar> >::type& getRealPvt()
263  {
264  assert(approach() == approachV);
265  return *static_cast<Opm::LiveOilPvt<Scalar>* >(realOilPvt_);
266  }
267 
268  template <OilPvtApproach approachV>
269  typename std::enable_if<approachV == LiveOilPvt, const Opm::LiveOilPvt<Scalar> >::type& getRealPvt() const
270  {
271  assert(approach() == approachV);
272  return *static_cast<Opm::LiveOilPvt<Scalar>* >(realOilPvt_);
273  }
274 
275  template <OilPvtApproach approachV>
276  typename std::enable_if<approachV == DeadOilPvt, Opm::DeadOilPvt<Scalar> >::type& getRealPvt()
277  {
278  assert(approach() == approachV);
279  return *static_cast<Opm::DeadOilPvt<Scalar>* >(realOilPvt_);
280  }
281 
282  template <OilPvtApproach approachV>
283  typename std::enable_if<approachV == DeadOilPvt, const Opm::DeadOilPvt<Scalar> >::type& getRealPvt() const
284  {
285  assert(approach() == approachV);
286  return *static_cast<Opm::DeadOilPvt<Scalar>* >(realOilPvt_);
287  }
288 
289  template <OilPvtApproach approachV>
290  typename std::enable_if<approachV == ConstantCompressibilityOilPvt, Opm::ConstantCompressibilityOilPvt<Scalar> >::type& getRealPvt()
291  {
292  assert(approach() == approachV);
293  return *static_cast<Opm::ConstantCompressibilityOilPvt<Scalar>* >(realOilPvt_);
294  }
295 
296  template <OilPvtApproach approachV>
297  typename std::enable_if<approachV == ConstantCompressibilityOilPvt, const Opm::ConstantCompressibilityOilPvt<Scalar> >::type& getRealPvt() const
298  {
299  assert(approach() == approachV);
300  return *static_cast<Opm::ConstantCompressibilityOilPvt<Scalar>* >(realOilPvt_);
301  }
302 
303  template <OilPvtApproach approachV>
304  typename std::enable_if<approachV == ThermalOilPvt, Opm::OilPvtThermal<Scalar> >::type& getRealPvt()
305  {
306  assert(approach() == approachV);
307  return *static_cast<Opm::OilPvtThermal<Scalar>* >(realOilPvt_);
308  }
309 
310  template <OilPvtApproach approachV>
311  typename std::enable_if<approachV == ThermalOilPvt, const Opm::OilPvtThermal<Scalar> >::type& getRealPvt() const
312  {
313  assert(approach() == approachV);
314  return *static_cast<const Opm::OilPvtThermal<Scalar>* >(realOilPvt_);
315  }
316 
317 private:
318  OilPvtApproach approach_;
319  void* realOilPvt_;
320 };
321 
322 #undef OPM_OIL_PVT_MULTIPLEXER_CALL
323 
324 } // namespace Opm
325 
326 #endif
This class represents the Pressure-Volume-Temperature relations of the oil phase without dissolved ga...
Definition: DeadOilPvt.hpp:46
OilPvtApproach approach() const
Returns the concrete approach for calculating the PVT relations.
Definition: OilPvtMultiplexer.hpp:257
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the formation volume factor [-] of the fluid phase.
Definition: OilPvtMultiplexer.hpp:188
This class represents the Pressure-Volume-Temperature relations of the oil phase without dissolved ga...
This class represents the Pressure-Volume-Temperature relations of the oil phas with dissolved gas...
This class represents the Pressure-Volume-Temperature relations of the oil phase without dissolved ga...
Definition: ConstantCompressibilityOilPvt.hpp:49
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
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
This class represents the Pressure-Volume-Temperature relations of the oil phase without dissolved ga...
This class implements temperature dependence of the PVT properties of oil.
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
This class represents the Pressure-Volume-Temperature relations of the oil phas with dissolved gas...
Definition: LiveOilPvt.hpp:49
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 saturated oil.
Definition: OilPvtMultiplexer.hpp:206
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
This class represents the Pressure-Volume-Temperature relations of the oil phase in the black-oil mod...
Definition: OilPvtMultiplexer.hpp:75
This class implements temperature dependence of the PVT properties of oil.
Definition: OilPvtThermal.hpp:55