opm-common
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 
35 
36 #define OPM_WATER_PVT_MULTIPLEXER_CALL(codeToCall, ...) \
37  switch (approach_) { \
38  case WaterPvtApproach::ConstantCompressibilityWater: { \
39  auto& pvtImpl = getRealPvt<WaterPvtApproach::ConstantCompressibilityWater>(); \
40  codeToCall; \
41  __VA_ARGS__; \
42  } \
43  case WaterPvtApproach::ConstantCompressibilityBrine: { \
44  auto& pvtImpl = getRealPvt<WaterPvtApproach::ConstantCompressibilityBrine>(); \
45  codeToCall; \
46  __VA_ARGS__; \
47  } \
48  case WaterPvtApproach::ThermalWater: { \
49  auto& pvtImpl = getRealPvt<WaterPvtApproach::ThermalWater>(); \
50  codeToCall; \
51  __VA_ARGS__; \
52  } \
53  case WaterPvtApproach::BrineCo2: { \
54  auto& pvtImpl = getRealPvt<WaterPvtApproach::BrineCo2>(); \
55  codeToCall; \
56  __VA_ARGS__; \
57  } \
58  case WaterPvtApproach::BrineH2: { \
59  auto& pvtImpl = getRealPvt<WaterPvtApproach::BrineH2>(); \
60  codeToCall; \
61  __VA_ARGS__; \
62  } \
63  default: \
64  case WaterPvtApproach::NoWater: \
65  throw std::logic_error("Not implemented: Water PVT of this deck!"); \
66  }
67 
68 namespace Opm {
69 
70 enum class WaterPvtApproach {
71  NoWater,
72  ConstantCompressibilityBrine,
73  ConstantCompressibilityWater,
74  ThermalWater,
75  BrineCo2,
76  BrineH2
77 };
78 
79 class EclipseState;
80 class Schedule;
81 
86 template <class Scalar, bool enableThermal = true, bool enableBrine = true>
87 class WaterPvtMultiplexer
88 {
89 public:
90  WaterPvtMultiplexer()
91  : approach_(WaterPvtApproach::NoWater)
92  , realWaterPvt_(nullptr)
93  {
94  }
95 
96  WaterPvtMultiplexer(WaterPvtApproach approach, void* realWaterPvt)
97  : approach_(approach)
98  , realWaterPvt_(realWaterPvt)
99  { }
100 
101  WaterPvtMultiplexer(const WaterPvtMultiplexer<Scalar,enableThermal,enableBrine>& data)
102  {
103  *this = data;
104  }
105 
106  ~WaterPvtMultiplexer();
107 
108  bool mixingEnergy() const
109  {
110  return approach_ == WaterPvtApproach::ThermalWater;
111  }
112 
118  void initFromState(const EclipseState& eclState, const Schedule& schedule);
119 
120  void initEnd();
121 
125  unsigned numRegions() const;
126 
127  void setVapPars(const Scalar par1, const Scalar par2);
128 
132  Scalar waterReferenceDensity(unsigned regionIdx) const;
133 
137  template <class Evaluation>
138  Evaluation internalEnergy(unsigned regionIdx,
139  const Evaluation& temperature,
140  const Evaluation& pressure,
141  const Evaluation& Rsw,
142  const Evaluation& saltconcentration) const
143  { OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.internalEnergy(regionIdx, temperature, pressure, Rsw, saltconcentration)); }
144 
145  Scalar hVap(unsigned regionIdx) const;
146 
150  template <class Evaluation>
151  Evaluation viscosity(unsigned regionIdx,
152  const Evaluation& temperature,
153  const Evaluation& pressure,
154  const Evaluation& Rsw,
155  const Evaluation& saltconcentration) const
156  {
157  OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.viscosity(regionIdx, temperature, pressure, Rsw, saltconcentration));
158  }
159 
160  bool isActive() const
161  {
162  return approach_ != WaterPvtApproach::NoWater;
163  }
164 
168  template <class Evaluation>
169  Evaluation saturatedViscosity(unsigned regionIdx,
170  const Evaluation& temperature,
171  const Evaluation& pressure,
172  const Evaluation& saltconcentration) const
173  {
174  OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedViscosity(regionIdx, temperature, pressure, saltconcentration));
175  }
176 
180  template <class Evaluation>
181  Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
182  const Evaluation& temperature,
183  const Evaluation& pressure,
184  const Evaluation& Rsw,
185  const Evaluation& saltconcentration) const
186  {
187  OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.inverseFormationVolumeFactor(regionIdx, temperature, pressure, Rsw, saltconcentration));
188  }
189 
193  template <class FluidState, class LhsEval = typename FluidState::ValueType>
194  std::pair<LhsEval, LhsEval>
195  inverseFormationVolumeFactorAndViscosity(const FluidState& fluidState, unsigned regionIdx)
196  { OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.inverseFormationVolumeFactorAndViscosity(fluidState, regionIdx)); }
197 
201  template <class Evaluation>
202  Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
203  const Evaluation& temperature,
204  const Evaluation& pressure,
205  const Evaluation& saltconcentration) const
206  {
207  OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedInverseFormationVolumeFactor(regionIdx, temperature, pressure, saltconcentration));
208  }
209 
213  template <class Evaluation>
214  Evaluation saturatedGasDissolutionFactor(unsigned regionIdx,
215  const Evaluation& temperature,
216  const Evaluation& pressure,
217  const Evaluation& saltconcentration) const
218  {
219  OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedGasDissolutionFactor(regionIdx, temperature, pressure, saltconcentration));
220  }
221 
229  template <class Evaluation>
230  Evaluation saturationPressure(unsigned regionIdx,
231  const Evaluation& temperature,
232  const Evaluation& Rs,
233  const Evaluation& saltconcentration) const
234  { OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.saturationPressure(regionIdx, temperature, Rs, saltconcentration)); }
235 
239  template <class Evaluation>
240  Evaluation diffusionCoefficient(const Evaluation& temperature,
241  const Evaluation& pressure,
242  unsigned compIdx,
243  unsigned regionIdx = 0) const
244  {
245  OPM_WATER_PVT_MULTIPLEXER_CALL(return pvtImpl.diffusionCoefficient(temperature, pressure, compIdx, regionIdx));
246  }
247 
248  void setApproach(WaterPvtApproach appr);
249 
255  WaterPvtApproach approach() const
256  { return approach_; }
257 
258  // get the concrete parameter object for the water phase
259  template <WaterPvtApproach approachV>
260  typename std::enable_if<approachV == WaterPvtApproach::ConstantCompressibilityWater, ConstantCompressibilityWaterPvt<Scalar> >::type& getRealPvt()
261  {
262  assert(approach() == approachV);
263  return *static_cast<ConstantCompressibilityWaterPvt<Scalar>* >(realWaterPvt_);
264  }
265 
266  template <WaterPvtApproach approachV>
267  typename std::enable_if<approachV == WaterPvtApproach::ConstantCompressibilityWater, const ConstantCompressibilityWaterPvt<Scalar> >::type& getRealPvt() const
268  {
269  assert(approach() == approachV);
270  return *static_cast<ConstantCompressibilityWaterPvt<Scalar>* >(realWaterPvt_);
271  }
272 
273  template <WaterPvtApproach approachV>
274  typename std::enable_if<approachV == WaterPvtApproach::ConstantCompressibilityBrine, ConstantCompressibilityBrinePvt<Scalar> >::type& getRealPvt()
275  {
276  assert(approach() == approachV);
277  return *static_cast<ConstantCompressibilityBrinePvt<Scalar>* >(realWaterPvt_);
278  }
279 
280  template <WaterPvtApproach approachV>
281  typename std::enable_if<approachV == WaterPvtApproach::ConstantCompressibilityBrine, const ConstantCompressibilityBrinePvt<Scalar> >::type& getRealPvt() const
282  {
283  assert(approach() == approachV);
284  return *static_cast<ConstantCompressibilityBrinePvt<Scalar>* >(realWaterPvt_);
285  }
286 
287  template <WaterPvtApproach approachV>
288  typename std::enable_if<approachV == WaterPvtApproach::ThermalWater, WaterPvtThermal<Scalar, enableBrine> >::type& getRealPvt()
289  {
290  assert(approach() == approachV);
291  return *static_cast<WaterPvtThermal<Scalar, enableBrine>* >(realWaterPvt_);
292  }
293 
294  template <WaterPvtApproach approachV>
295  typename std::enable_if<approachV == WaterPvtApproach::ThermalWater, const WaterPvtThermal<Scalar, enableBrine> >::type& getRealPvt() const
296  {
297  assert(approach() == approachV);
298  return *static_cast<WaterPvtThermal<Scalar, enableBrine>* >(realWaterPvt_);
299  }
300 
301  template <WaterPvtApproach approachV>
302  typename std::enable_if<approachV == WaterPvtApproach::BrineCo2, BrineCo2Pvt<Scalar> >::type& getRealPvt()
303  {
304  assert(approach() == approachV);
305  return *static_cast<BrineCo2Pvt<Scalar>* >(realWaterPvt_);
306  }
307 
308  template <WaterPvtApproach approachV>
309  typename std::enable_if<approachV == WaterPvtApproach::BrineCo2, const BrineCo2Pvt<Scalar> >::type& getRealPvt() const
310  {
311  assert(approach() == approachV);
312  return *static_cast<const BrineCo2Pvt<Scalar>* >(realWaterPvt_);
313  }
314 
315  template <WaterPvtApproach approachV>
316  typename std::enable_if<approachV == WaterPvtApproach::BrineH2, BrineH2Pvt<Scalar> >::type& getRealPvt()
317  {
318  assert(approach() == approachV);
319  return *static_cast<BrineH2Pvt<Scalar>* >(realWaterPvt_);
320  }
321 
322  template <WaterPvtApproach approachV>
323  typename std::enable_if<approachV == WaterPvtApproach::BrineH2, const BrineH2Pvt<Scalar> >::type& getRealPvt() const
324  {
325  assert(approach() == approachV);
326  return *static_cast<const BrineH2Pvt<Scalar>* >(realWaterPvt_);
327  }
328 
329  const void* realWaterPvt() const { return realWaterPvt_; }
330 
331  WaterPvtMultiplexer<Scalar,enableThermal,enableBrine>&
332  operator=(const WaterPvtMultiplexer<Scalar,enableThermal,enableBrine>& data);
333 
334 private:
335  WaterPvtApproach approach_{WaterPvtApproach::NoWater};
336  void* realWaterPvt_{nullptr};
337 };
338 
339 } // namespace Opm
340 
341 #endif
This class represents the Pressure-Volume-Temperature relations of the liquid phase for a CO2-Brine s...
std::pair< LhsEval, LhsEval > inverseFormationVolumeFactorAndViscosity(const FluidState &fluidState, unsigned regionIdx)
Returns the formation volume factor [-] and viscosity [Pa s] of the fluid phase.
Definition: WaterPvtMultiplexer.hpp:195
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rsw, const Evaluation &saltconcentration) const
Returns the formation volume factor [-] of the fluid phase.
Definition: WaterPvtMultiplexer.hpp:181
Evaluation internalEnergy(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rsw, const Evaluation &saltconcentration) const
Returns the specific enthalpy [J/kg] of gas given a set of parameters.
Definition: WaterPvtMultiplexer.hpp:138
Evaluation viscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rsw, const Evaluation &saltconcentration) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition: WaterPvtMultiplexer.hpp:151
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Evaluation diffusionCoefficient(const Evaluation &temperature, const Evaluation &pressure, unsigned compIdx, unsigned regionIdx=0) const
Calculate the binary molecular diffusion coefficient for a component in a fluid phase [mol^2 * s / (k...
Definition: WaterPvtMultiplexer.hpp:240
WaterPvtApproach approach() const
Returns the concrete approach for calculating the PVT relations.
Definition: WaterPvtMultiplexer.hpp:255
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Definition: ConstantCompressibilityWaterPvt.hpp:46
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: WaterPvtMultiplexer.cpp:95
void initFromState(const EclipseState &eclState, const Schedule &schedule)
Initialize the parameters for water using an ECL deck.
Definition: WaterPvtMultiplexer.cpp:64
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &temperature, const Evaluation &Rs, const Evaluation &saltconcentration) const
Returns the saturation pressure [Pa] of water given the mass fraction of the gas component in the wat...
Definition: WaterPvtMultiplexer.hpp:230
Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &saltconcentration) const
Returns the gas dissolution factor [m^3/m^3] of saturated water.
Definition: WaterPvtMultiplexer.hpp:214
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Scalar waterReferenceDensity(unsigned regionIdx) const
Return the reference density which are considered by this PVT-object.
Definition: WaterPvtMultiplexer.cpp:109
Evaluation saturatedViscosity(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:169
This class implements temperature dependence of the PVT properties of water.
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &saltconcentration) const
Returns the formation volume factor [-] of the fluid phase.
Definition: WaterPvtMultiplexer.hpp:202
This class represents the Pressure-Volume-Temperature relations of the liquid phase for a H2-Brine sy...