All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WaterPvtMultiplexer.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_WATER_PVT_MULTIPLEXER_HPP
28 #define OPM_WATER_PVT_MULTIPLEXER_HPP
29 
31 #include "WaterPvtThermal.hpp"
32 
33 #define OPM_WATER_PVT_MULTIPLEXER_CALL(codeToCall) \
34  switch (approach_) { \
35  case ConstantCompressibilityWaterPvt: { \
36  auto& pvtImpl = getRealPvt<ConstantCompressibilityWaterPvt>(); \
37  codeToCall; \
38  break; \
39  } \
40  case ThermalWaterPvt: { \
41  auto& pvtImpl = getRealPvt<ThermalWaterPvt>(); \
42  codeToCall; \
43  break; \
44  } \
45  case NoWaterPvt: \
46  OPM_THROW(std::logic_error, "Not implemented: Water PVT of this deck!"); \
47  }
48 
49 namespace Opm {
54 template <class Scalar, bool enableThermal = true>
56 {
57 public:
59 
60  enum WaterPvtApproach {
61  NoWaterPvt,
63  ThermalWaterPvt
64  };
65 
67  {
68  approach_ = NoWaterPvt;
69  }
70 
72  {
73  switch (approach_) {
75  delete &getRealPvt<ConstantCompressibilityWaterPvt>();
76  break;
77  }
78  case ThermalWaterPvt: {
79  delete &getRealPvt<ThermalWaterPvt>();
80  break;
81  }
82  case NoWaterPvt:
83  break;
84  }
85  }
86 
87 #if HAVE_OPM_PARSER
88 
93  void initFromDeck(const Deck& deck, const EclipseState& eclState)
94  {
95  bool enableWater = deck.hasKeyword("WATER");
96  if (!enableWater)
97  return;
98 
99  if (enableThermal
100  && (deck.hasKeyword("WATDENT")
101  || deck.hasKeyword("VISCREF")))
102  setApproach(ThermalWaterPvt);
103  else if (deck.hasKeyword("PVTW"))
104  setApproach(ConstantCompressibilityWaterPvt);
105 
106  OPM_WATER_PVT_MULTIPLEXER_CALL(pvtImpl.initFromDeck(deck, eclState));
107  }
108 #endif // HAVE_OPM_PARSER
109 
110  void initEnd()
111  { OPM_WATER_PVT_MULTIPLEXER_CALL(pvtImpl.initEnd()); }
112 
116  unsigned numRegions() const
117  { OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.numRegions()); return 1; }
118 
122  template <class Evaluation>
123  Evaluation viscosity(unsigned regionIdx,
124  const Evaluation& temperature,
125  const Evaluation& pressure) const
126  { OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.viscosity(regionIdx, temperature, pressure)); return 0; }
127 
131  template <class Evaluation>
132  Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
133  const Evaluation& temperature,
134  const Evaluation& pressure) const
135  { OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.inverseFormationVolumeFactor(regionIdx, temperature, pressure)); return 0; }
136 
137  void setApproach(WaterPvtApproach appr)
138  {
139  switch (appr) {
142  break;
143 
144  case ThermalWaterPvt:
145  realWaterPvt_ = new Opm::WaterPvtThermal<Scalar>;
146  break;
147 
148  case NoWaterPvt:
149  OPM_THROW(std::logic_error, "Not implemented: Water PVT of this deck!");
150  }
151 
152  approach_ = appr;
153  }
154 
160  WaterPvtApproach approach() const
161  { return approach_; }
162 
163  // get the concrete parameter object for the water phase
164  template <WaterPvtApproach approachV>
165  typename std::enable_if<approachV == ConstantCompressibilityWaterPvt, Opm::ConstantCompressibilityWaterPvt<Scalar> >::type& getRealPvt()
166  {
167  assert(approach() == approachV);
168  return *static_cast<Opm::ConstantCompressibilityWaterPvt<Scalar>* >(realWaterPvt_);
169  }
170 
171  template <WaterPvtApproach approachV>
172  typename std::enable_if<approachV == ConstantCompressibilityWaterPvt, const Opm::ConstantCompressibilityWaterPvt<Scalar> >::type& getRealPvt() const
173  {
174  assert(approach() == approachV);
175  return *static_cast<Opm::ConstantCompressibilityWaterPvt<Scalar>* >(realWaterPvt_);
176  }
177 
178  template <WaterPvtApproach approachV>
179  typename std::enable_if<approachV == ThermalWaterPvt, Opm::WaterPvtThermal<Scalar> >::type& getRealPvt()
180  {
181  assert(approach() == approachV);
182  return *static_cast<Opm::WaterPvtThermal<Scalar>* >(realWaterPvt_);
183  }
184 
185  template <WaterPvtApproach approachV>
186  typename std::enable_if<approachV == ThermalWaterPvt, const Opm::WaterPvtThermal<Scalar> >::type& getRealPvt() const
187  {
188  assert(approach() == approachV);
189  return *static_cast<Opm::WaterPvtThermal<Scalar>* >(realWaterPvt_);
190  }
191 
192 private:
193  WaterPvtApproach approach_;
194  void* realWaterPvt_;
195 };
196 
197 #undef OPM_WATER_PVT_MULTIPLEXER_CALL
198 
199 } // namespace Opm
200 
201 #endif
This class implements temperature dependence of the PVT properties of water.
Definition: WaterPvtThermal.hpp:55
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the formation volume factor [-] of the fluid phase.
Definition: WaterPvtMultiplexer.hpp:132
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: WaterPvtMultiplexer.hpp:116
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 without vaporized oi...
Definition: ConstantCompressibilityWaterPvt.hpp:48
Evaluation viscosity(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: WaterPvtMultiplexer.hpp:123
This class represents the Pressure-Volume-Temperature relations of the water phase in the black-oil m...
Definition: WaterPvtMultiplexer.hpp:55
WaterPvtApproach approach() const
Returns the concrete approach for calculating the PVT relations.
Definition: WaterPvtMultiplexer.hpp:160
This class implements temperature dependence of the PVT properties of water.