My Project
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 
32 #include "WaterPvtThermal.hpp"
33 
34 #if HAVE_ECL_INPUT
35 #include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
36 #include <opm/parser/eclipse/EclipseState/Runspec.hpp>
37 #endif
38 
39 #define OPM_WATER_PVT_MULTIPLEXER_CALL(codeToCall) \
40  switch (approach_) { \
41  case WaterPvtApproach::ConstantCompressibilityWaterPvt: { \
42  auto& pvtImpl = getRealPvt<WaterPvtApproach::ConstantCompressibilityWaterPvt>(); \
43  codeToCall; \
44  break; \
45  } \
46  case WaterPvtApproach::ConstantCompressibilityBrinePvt: { \
47  auto& pvtImpl = getRealPvt<WaterPvtApproach::ConstantCompressibilityBrinePvt>(); \
48  codeToCall; \
49  break; \
50  } \
51  case WaterPvtApproach::ThermalWaterPvt: { \
52  auto& pvtImpl = getRealPvt<WaterPvtApproach::ThermalWaterPvt>(); \
53  codeToCall; \
54  break; \
55  } \
56  case WaterPvtApproach::NoWaterPvt: \
57  throw std::logic_error("Not implemented: Water PVT of this deck!"); \
58  }
59 
60 namespace Opm {
61 
62 enum class WaterPvtApproach {
63  NoWaterPvt,
64  ConstantCompressibilityBrinePvt,
65  ConstantCompressibilityWaterPvt,
66  ThermalWaterPvt
67 };
68 
73 template <class Scalar, bool enableThermal = true, bool enableBrine = true>
75 {
76 public:
78  {
79  approach_ = WaterPvtApproach::NoWaterPvt;
80  realWaterPvt_ = nullptr;
81  }
82 
83  WaterPvtMultiplexer(WaterPvtApproach approach, void* realWaterPvt)
84  : approach_(approach)
85  , realWaterPvt_(realWaterPvt)
86  { }
87 
89  {
90  *this = data;
91  }
92 
94  {
95  switch (approach_) {
96  case WaterPvtApproach::ConstantCompressibilityWaterPvt: {
97  delete &getRealPvt<WaterPvtApproach::ConstantCompressibilityWaterPvt>();
98  break;
99  }
100  case WaterPvtApproach::ConstantCompressibilityBrinePvt: {
101  delete &getRealPvt<WaterPvtApproach::ConstantCompressibilityBrinePvt>();
102  break;
103  }
104  case WaterPvtApproach::ThermalWaterPvt: {
105  delete &getRealPvt<WaterPvtApproach::ThermalWaterPvt>();
106  break;
107  }
108  case WaterPvtApproach::NoWaterPvt:
109  break;
110  }
111  }
112 
113 #if HAVE_ECL_INPUT
119  void initFromState(const EclipseState& eclState, const Schedule& schedule)
120  {
121  if (!eclState.runspec().phases().active(Phase::WATER))
122  return;
123 
124  if (enableThermal && eclState.getSimulationConfig().isThermal())
125  setApproach(WaterPvtApproach::ThermalWaterPvt);
126  else if (!eclState.getTableManager().getPvtwTable().empty())
127  setApproach(WaterPvtApproach::ConstantCompressibilityWaterPvt);
128  else if (enableBrine && !eclState.getTableManager().getPvtwSaltTables().empty())
129  setApproach(WaterPvtApproach::ConstantCompressibilityBrinePvt);
130 
131  OPM_WATER_PVT_MULTIPLEXER_CALL(pvtImpl.initFromState(eclState, schedule));
132  }
133 #endif // HAVE_ECL_INPUT
134 
135  void initEnd()
136  { OPM_WATER_PVT_MULTIPLEXER_CALL(pvtImpl.initEnd()); }
137 
141  unsigned numRegions() const
142  { OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.numRegions()); return 1; }
143 
147  const Scalar waterReferenceDensity(unsigned regionIdx)
148  { OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.waterReferenceDensity(regionIdx)); return 1000.; }
149 
153  template <class Evaluation>
154  Evaluation internalEnergy(unsigned regionIdx,
155  const Evaluation& temperature,
156  const Evaluation& pressure) const
157  { OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.internalEnergy(regionIdx, temperature, pressure)); return 0; }
158 
162  template <class Evaluation>
163  Evaluation viscosity(unsigned regionIdx,
164  const Evaluation& temperature,
165  const Evaluation& pressure,
166  const Evaluation& saltconcentration) const
167  {
168  OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.viscosity(regionIdx, temperature, pressure, saltconcentration));
169  return 0;
170  }
171 
175  template <class Evaluation>
176  Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
177  const Evaluation& temperature,
178  const Evaluation& pressure,
179  const Evaluation& saltconcentration) const
180  { OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.inverseFormationVolumeFactor(regionIdx, temperature, pressure, saltconcentration));
181  return 0;
182  }
183 
184  void setApproach(WaterPvtApproach appr)
185  {
186  switch (appr) {
187  case WaterPvtApproach::ConstantCompressibilityWaterPvt:
188  realWaterPvt_ = new ConstantCompressibilityWaterPvt<Scalar>;
189  break;
190 
191  case WaterPvtApproach::ConstantCompressibilityBrinePvt:
192  realWaterPvt_ = new ConstantCompressibilityBrinePvt<Scalar>;
193  break;
194 
195  case WaterPvtApproach::ThermalWaterPvt:
196  realWaterPvt_ = new WaterPvtThermal<Scalar, enableBrine>;
197  break;
198 
199  case WaterPvtApproach::NoWaterPvt:
200  throw std::logic_error("Not implemented: Water PVT of this deck!");
201  }
202 
203  approach_ = appr;
204  }
205 
211  WaterPvtApproach approach() const
212  { return approach_; }
213 
214  // get the concrete parameter object for the water phase
215  template <WaterPvtApproach approachV>
216  typename std::enable_if<approachV == WaterPvtApproach::ConstantCompressibilityWaterPvt, ConstantCompressibilityWaterPvt<Scalar> >::type& getRealPvt()
217  {
218  assert(approach() == approachV);
219  return *static_cast<ConstantCompressibilityWaterPvt<Scalar>* >(realWaterPvt_);
220  }
221 
222  template <WaterPvtApproach approachV>
223  typename std::enable_if<approachV == WaterPvtApproach::ConstantCompressibilityWaterPvt, const ConstantCompressibilityWaterPvt<Scalar> >::type& getRealPvt() const
224  {
225  assert(approach() == approachV);
226  return *static_cast<ConstantCompressibilityWaterPvt<Scalar>* >(realWaterPvt_);
227  }
228 
229  template <WaterPvtApproach approachV>
230  typename std::enable_if<approachV == WaterPvtApproach::ConstantCompressibilityBrinePvt, ConstantCompressibilityBrinePvt<Scalar> >::type& getRealPvt()
231  {
232  assert(approach() == approachV);
233  return *static_cast<ConstantCompressibilityBrinePvt<Scalar>* >(realWaterPvt_);
234  }
235 
236  template <WaterPvtApproach approachV>
237  typename std::enable_if<approachV == WaterPvtApproach::ConstantCompressibilityBrinePvt, const ConstantCompressibilityBrinePvt<Scalar> >::type& getRealPvt() const
238  {
239  assert(approach() == approachV);
240  return *static_cast<ConstantCompressibilityBrinePvt<Scalar>* >(realWaterPvt_);
241  }
242 
243  template <WaterPvtApproach approachV>
244  typename std::enable_if<approachV == WaterPvtApproach::ThermalWaterPvt, WaterPvtThermal<Scalar, enableBrine> >::type& getRealPvt()
245  {
246  assert(approach() == approachV);
247  return *static_cast<WaterPvtThermal<Scalar, enableBrine>* >(realWaterPvt_);
248  }
249 
250  template <WaterPvtApproach approachV>
251  typename std::enable_if<approachV == WaterPvtApproach::ThermalWaterPvt, const WaterPvtThermal<Scalar, enableBrine> >::type& getRealPvt() const
252  {
253  assert(approach() == approachV);
254  return *static_cast<WaterPvtThermal<Scalar, enableBrine>* >(realWaterPvt_);
255  }
256 
257  const void* realWaterPvt() const { return realWaterPvt_; }
258 
259  bool operator==(const WaterPvtMultiplexer<Scalar,enableThermal,enableBrine>& data) const
260  {
261  if (this->approach() != data.approach())
262  return false;
263 
264  switch (approach_) {
265  case WaterPvtApproach::ConstantCompressibilityWaterPvt:
266  return *static_cast<const ConstantCompressibilityWaterPvt<Scalar>*>(realWaterPvt_) ==
267  *static_cast<const ConstantCompressibilityWaterPvt<Scalar>*>(data.realWaterPvt_);
268  case WaterPvtApproach::ConstantCompressibilityBrinePvt:
269  return *static_cast<const ConstantCompressibilityBrinePvt<Scalar>*>(realWaterPvt_) ==
270  *static_cast<const ConstantCompressibilityBrinePvt<Scalar>*>(data.realWaterPvt_);
271  case WaterPvtApproach::ThermalWaterPvt:
272  return *static_cast<const WaterPvtThermal<Scalar, enableBrine>*>(realWaterPvt_) ==
273  *static_cast<const WaterPvtThermal<Scalar, enableBrine>*>(data.realWaterPvt_);
274  default:
275  return true;
276  }
277  }
278 
279  WaterPvtMultiplexer<Scalar,enableThermal,enableBrine>& operator=(const WaterPvtMultiplexer<Scalar,enableThermal,enableBrine>& data)
280  {
281  approach_ = data.approach_;
282  switch (approach_) {
283  case WaterPvtApproach::ConstantCompressibilityWaterPvt:
284  realWaterPvt_ = new ConstantCompressibilityWaterPvt<Scalar>(*static_cast<const ConstantCompressibilityWaterPvt<Scalar>*>(data.realWaterPvt_));
285  break;
286  case WaterPvtApproach::ConstantCompressibilityBrinePvt:
287  realWaterPvt_ = new ConstantCompressibilityBrinePvt<Scalar>(*static_cast<const ConstantCompressibilityBrinePvt<Scalar>*>(data.realWaterPvt_));
288  break;
289  case WaterPvtApproach::ThermalWaterPvt:
290  realWaterPvt_ = new WaterPvtThermal<Scalar, enableBrine>(*static_cast<const WaterPvtThermal<Scalar, enableBrine>*>(data.realWaterPvt_));
291  break;
292  default:
293  break;
294  }
295 
296  return *this;
297  }
298 
299 private:
300  WaterPvtApproach approach_;
301  void* realWaterPvt_;
302 };
303 
304 #undef OPM_WATER_PVT_MULTIPLEXER_CALL
305 
306 } // namespace Opm
307 
308 #endif
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...
This class implements temperature dependence of the PVT properties of water.
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Definition: ConstantCompressibilityBrinePvt.hpp:49
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Definition: ConstantCompressibilityWaterPvt.hpp:45
This class represents the Pressure-Volume-Temperature relations of the water phase in the black-oil m...
Definition: WaterPvtMultiplexer.hpp:75
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: WaterPvtMultiplexer.hpp:141
const Scalar waterReferenceDensity(unsigned regionIdx)
Return the reference density which are considered by this PVT-object.
Definition: WaterPvtMultiplexer.hpp:147
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &saltconcentration) const
Returns the formation volume factor [-] of the fluid phase.
Definition: WaterPvtMultiplexer.hpp:176
Evaluation viscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &saltconcentration) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: WaterPvtMultiplexer.hpp:163
Evaluation internalEnergy(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the specific enthalpy [J/kg] of gas given a set of parameters.
Definition: WaterPvtMultiplexer.hpp:154
WaterPvtApproach approach() const
Returns the concrete approach for calculating the PVT relations.
Definition: WaterPvtMultiplexer.hpp:211
This class implements temperature dependence of the PVT properties of water.
Definition: WaterPvtThermal.hpp:55