My Project
Loading...
Searching...
No Matches
GasPvtMultiplexer.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_GAS_PVT_MULTIPLEXER_HPP
28#define OPM_GAS_PVT_MULTIPLEXER_HPP
29
37
38#include <functional>
39namespace Opm {
40
41#if HAVE_ECL_INPUT
42class EclipseState;
43class Schedule;
44#endif
45
46#define OPM_GAS_PVT_MULTIPLEXER_CALL(codeToCall, ...) \
47 switch (gasPvtApproach_) { \
48 case GasPvtApproach::DryGas: { \
49 auto& pvtImpl = getRealPvt<GasPvtApproach::DryGas>(); \
50 codeToCall; \
51 __VA_ARGS__; \
52 } \
53 case GasPvtApproach::DryHumidGas: { \
54 auto& pvtImpl = getRealPvt<GasPvtApproach::DryHumidGas>(); \
55 codeToCall; \
56 __VA_ARGS__; \
57 } \
58 case GasPvtApproach::WetHumidGas: { \
59 auto& pvtImpl = getRealPvt<GasPvtApproach::WetHumidGas>(); \
60 codeToCall; \
61 __VA_ARGS__; \
62 } \
63 case GasPvtApproach::WetGas: { \
64 auto& pvtImpl = getRealPvt<GasPvtApproach::WetGas>(); \
65 codeToCall; \
66 __VA_ARGS__; \
67 } \
68 case GasPvtApproach::ThermalGas: { \
69 auto& pvtImpl = getRealPvt<GasPvtApproach::ThermalGas>(); \
70 codeToCall; \
71 __VA_ARGS__; \
72 } \
73 case GasPvtApproach::Co2Gas: { \
74 auto& pvtImpl = getRealPvt<GasPvtApproach::Co2Gas>(); \
75 codeToCall; \
76 __VA_ARGS__; \
77 } \
78 case GasPvtApproach::H2Gas: { \
79 auto& pvtImpl = getRealPvt<GasPvtApproach::H2Gas>(); \
80 codeToCall; \
81 __VA_ARGS__; \
82 } \
83 default: \
84 case GasPvtApproach::NoGas: \
85 throw std::logic_error("Not implemented: Gas PVT of this deck!"); \
86 }
87
88enum class GasPvtApproach {
89 NoGas,
90 DryGas,
91 DryHumidGas,
92 WetHumidGas,
93 WetGas,
94 ThermalGas,
95 Co2Gas,
96 H2Gas
97};
98
109template <class Scalar, bool enableThermal = true>
111{
112public:
114 : gasPvtApproach_(GasPvtApproach::NoGas)
115 , realGasPvt_(nullptr, [](void*){})
116 {
117 }
118
119 GasPvtMultiplexer(GasPvtApproach approach, void* realGasPvt)
120 : gasPvtApproach_(approach)
121 , realGasPvt_(realGasPvt, [this](void* ptr){ deleter(ptr); })
122 { }
123
125 {
126 *this = data;
127 }
128
129 ~GasPvtMultiplexer() = default;
130
131 bool mixingEnergy() const
132 {
133 return gasPvtApproach_ == GasPvtApproach::ThermalGas;
134 }
135
136#if HAVE_ECL_INPUT
142 void initFromState(const EclipseState& eclState, const Schedule& schedule);
143#endif // HAVE_ECL_INPUT
144
145 void setApproach(GasPvtApproach gasPvtAppr);
146
147 void initEnd();
148
152 unsigned numRegions() const;
153
154 void setVapPars(const Scalar par1, const Scalar par2);
155
159 Scalar gasReferenceDensity(unsigned regionIdx);
160
164 template <class Evaluation>
165 Evaluation internalEnergy(unsigned regionIdx,
166 const Evaluation& temperature,
167 const Evaluation& pressure,
168 const Evaluation& Rv,
169 const Evaluation& Rvw) const
170 { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.internalEnergy(regionIdx, temperature, pressure, Rv, Rvw)); }
171
172 Scalar hVap(unsigned regionIdx) const;
173
177 template <class Evaluation = Scalar>
178 Evaluation viscosity(unsigned regionIdx,
179 const Evaluation& temperature,
180 const Evaluation& pressure,
181 const Evaluation& Rv,
182 const Evaluation& Rvw ) const
183 { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.viscosity(regionIdx, temperature, pressure, Rv, Rvw)); }
184
188 template <class Evaluation = Scalar>
189 Evaluation saturatedViscosity(unsigned regionIdx,
190 const Evaluation& temperature,
191 const Evaluation& pressure) const
192 { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedViscosity(regionIdx, temperature, pressure)); }
193
197 template <class Evaluation = Scalar>
198 Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
199 const Evaluation& temperature,
200 const Evaluation& pressure,
201 const Evaluation& Rv,
202 const Evaluation& Rvw) const
203 { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.inverseFormationVolumeFactor(regionIdx, temperature, pressure, Rv, Rvw)); }
204
208 template <class Evaluation = Scalar>
209 Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
210 const Evaluation& temperature,
211 const Evaluation& pressure) const
212 { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedInverseFormationVolumeFactor(regionIdx, temperature, pressure)); }
213
217 template <class Evaluation = Scalar>
218 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
219 const Evaluation& temperature,
220 const Evaluation& pressure) const
221 { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedOilVaporizationFactor(regionIdx, temperature, pressure)); }
222
226 template <class Evaluation = Scalar>
227 Evaluation saturatedOilVaporizationFactor(unsigned regionIdx,
228 const Evaluation& temperature,
229 const Evaluation& pressure,
230 const Evaluation& oilSaturation,
231 const Evaluation& maxOilSaturation) const
232 { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedOilVaporizationFactor(regionIdx, temperature, pressure, oilSaturation, maxOilSaturation)); }
233
237 template <class Evaluation = Scalar>
238 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
239 const Evaluation& temperature,
240 const Evaluation& pressure) const
241 { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedWaterVaporizationFactor(regionIdx, temperature, pressure)); }
242
246 template <class Evaluation = Scalar>
247 Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx,
248 const Evaluation& temperature,
249 const Evaluation& pressure,
250 const Evaluation& saltConcentration) const
251 { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturatedWaterVaporizationFactor(regionIdx, temperature, pressure, saltConcentration)); }
252
259 template <class Evaluation = Scalar>
260 Evaluation saturationPressure(unsigned regionIdx,
261 const Evaluation& temperature,
262 const Evaluation& Rv) const
263 { OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.saturationPressure(regionIdx, temperature, Rv)); }
264
268 template <class Evaluation>
269 Evaluation diffusionCoefficient(const Evaluation& temperature,
270 const Evaluation& pressure,
271 unsigned compIdx) const
272 {
273 OPM_GAS_PVT_MULTIPLEXER_CALL(return pvtImpl.diffusionCoefficient(temperature, pressure, compIdx));
274 }
275
281 GasPvtApproach gasPvtApproach() const
282 { return gasPvtApproach_; }
283
284 // get the parameter object for the dry gas case
285 template <GasPvtApproach approachV>
286 typename std::enable_if<approachV == GasPvtApproach::DryGas, DryGasPvt<Scalar> >::type& getRealPvt()
287 {
288 assert(gasPvtApproach() == approachV);
289 return *static_cast<DryGasPvt<Scalar>* >(realGasPvt_.get());
290 }
291
292 template <GasPvtApproach approachV>
293 typename std::enable_if<approachV == GasPvtApproach::DryGas, const DryGasPvt<Scalar> >::type& getRealPvt() const
294 {
295 assert(gasPvtApproach() == approachV);
296 return *static_cast<const DryGasPvt<Scalar>* >(realGasPvt_.get());
297 }
298
299 // get the parameter object for the dry humid gas case
300 template <GasPvtApproach approachV>
301 typename std::enable_if<approachV == GasPvtApproach::DryHumidGas, DryHumidGasPvt<Scalar> >::type& getRealPvt()
302 {
303 assert(gasPvtApproach() == approachV);
304 return *static_cast<DryHumidGasPvt<Scalar>* >(realGasPvt_.get());
305 }
306
307 template <GasPvtApproach approachV>
308 typename std::enable_if<approachV == GasPvtApproach::DryHumidGas, const DryHumidGasPvt<Scalar> >::type& getRealPvt() const
309 {
310 assert(gasPvtApproach() == approachV);
311 return *static_cast<const DryHumidGasPvt<Scalar>* >(realGasPvt_.get());
312 }
313
314 // get the parameter object for the wet humid gas case
315 template <GasPvtApproach approachV>
316 typename std::enable_if<approachV == GasPvtApproach::WetHumidGas, WetHumidGasPvt<Scalar> >::type& getRealPvt()
317 {
318 assert(gasPvtApproach() == approachV);
319 return *static_cast<WetHumidGasPvt<Scalar>* >(realGasPvt_.get());
320 }
321
322 template <GasPvtApproach approachV>
323 typename std::enable_if<approachV == GasPvtApproach::WetHumidGas, const WetHumidGasPvt<Scalar> >::type& getRealPvt() const
324 {
325 assert(gasPvtApproach() == approachV);
326 return *static_cast<const WetHumidGasPvt<Scalar>* >(realGasPvt_.get());
327 }
328
329 // get the parameter object for the wet gas case
330 template <GasPvtApproach approachV>
331 typename std::enable_if<approachV == GasPvtApproach::WetGas, WetGasPvt<Scalar> >::type& getRealPvt()
332 {
333 assert(gasPvtApproach() == approachV);
334 return *static_cast<WetGasPvt<Scalar>* >(realGasPvt_.get());
335 }
336
337 template <GasPvtApproach approachV>
338 typename std::enable_if<approachV == GasPvtApproach::WetGas, const WetGasPvt<Scalar> >::type& getRealPvt() const
339 {
340 assert(gasPvtApproach() == approachV);
341 return *static_cast<const WetGasPvt<Scalar>* >(realGasPvt_.get());
342 }
343
344 // get the parameter object for the thermal gas case
345 template <GasPvtApproach approachV>
346 typename std::enable_if<approachV == GasPvtApproach::ThermalGas, GasPvtThermal<Scalar> >::type& getRealPvt()
347 {
348 assert(gasPvtApproach() == approachV);
349 return *static_cast<GasPvtThermal<Scalar>* >(realGasPvt_.get());
350 }
351 template <GasPvtApproach approachV>
352 typename std::enable_if<approachV == GasPvtApproach::ThermalGas, const GasPvtThermal<Scalar> >::type& getRealPvt() const
353 {
354 assert(gasPvtApproach() == approachV);
355 return *static_cast<const GasPvtThermal<Scalar>* >(realGasPvt_.get());
356 }
357
358 template <GasPvtApproach approachV>
359 typename std::enable_if<approachV == GasPvtApproach::Co2Gas, Co2GasPvt<Scalar> >::type& getRealPvt()
360 {
361 assert(gasPvtApproach() == approachV);
362 return *static_cast<Co2GasPvt<Scalar>* >(realGasPvt_.get());
363 }
364
365 template <GasPvtApproach approachV>
366 typename std::enable_if<approachV == GasPvtApproach::Co2Gas, const Co2GasPvt<Scalar> >::type& getRealPvt() const
367 {
368 assert(gasPvtApproach() == approachV);
369 return *static_cast<const Co2GasPvt<Scalar>* >(realGasPvt_.get());
370 }
371
372 template <GasPvtApproach approachV>
373 typename std::enable_if<approachV == GasPvtApproach::H2Gas, H2GasPvt<Scalar> >::type& getRealPvt()
374 {
375 assert(gasPvtApproach() == approachV);
376 return *static_cast<H2GasPvt<Scalar>* >(realGasPvt_.get());
377 }
378
379 template <GasPvtApproach approachV>
380 typename std::enable_if<approachV == GasPvtApproach::H2Gas, const H2GasPvt<Scalar> >::type& getRealPvt() const
381 {
382 assert(gasPvtApproach() == approachV);
383 return *static_cast<const H2GasPvt<Scalar>* >(realGasPvt_.get());
384 }
385
386 const void* realGasPvt() const { return realGasPvt_.get(); }
387
388 GasPvtMultiplexer<Scalar,enableThermal>&
389 operator=(const GasPvtMultiplexer<Scalar,enableThermal>& data);
390
391private:
392 using UniqueVoidPtrWithDeleter = std::unique_ptr<void, std::function<void(void*)>>;
393
394 template <class ConcreteGasPvt> UniqueVoidPtrWithDeleter makeGasPvt();
395
396 template <class ConcretePvt> UniqueVoidPtrWithDeleter copyPvt(const UniqueVoidPtrWithDeleter&);
397
398 GasPvtApproach gasPvtApproach_{GasPvtApproach::NoGas};
399 UniqueVoidPtrWithDeleter realGasPvt_;
400
401 void deleter(void* ptr);
402};
403
404} // namespace Opm
405
406#endif
This class represents the Pressure-Volume-Temperature relations of the gas phase for CO2.
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 with vaporized water...
This class implements temperature dependence of the PVT properties of gas.
This class represents the Pressure-Volume-Temperature relations of the gas phase for H2.
This class represents the Pressure-Volume-Temperature relations of the gas phas with vaporized oil.
This class represents the Pressure-Volume-Temperature relations of the gas phase with vaporized oil a...
This class represents the Pressure-Volume-Temperature relations of the gas phase without vaporized oi...
Definition DryGasPvt.hpp:50
Definition EclipseState.hpp:62
This class represents the Pressure-Volume-Temperature relations of the gas phase in the black-oil mod...
Definition GasPvtMultiplexer.hpp:111
GasPvtApproach gasPvtApproach() const
Returns the concrete approach for calculating the PVT relations.
Definition GasPvtMultiplexer.hpp:281
Scalar gasReferenceDensity(unsigned regionIdx)
Return the reference density which are considered by this PVT-object.
Definition GasPvtMultiplexer.cpp:57
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the formation volume factor [-] of oil saturated gas given a set of parameters.
Definition GasPvtMultiplexer.hpp:209
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition GasPvtMultiplexer.cpp:41
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the water vaporization factor [m^3/m^3] of water saturated gas.
Definition GasPvtMultiplexer.hpp:238
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &Rvw) const
Returns the formation volume factor [-] of the fluid phase.
Definition GasPvtMultiplexer.hpp:198
Evaluation internalEnergy(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &Rvw) const
Returns the specific enthalpy [J/kg] of gas given a set of parameters.
Definition GasPvtMultiplexer.hpp:165
Evaluation viscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &Rvw) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition GasPvtMultiplexer.hpp:178
Evaluation diffusionCoefficient(const Evaluation &temperature, const Evaluation &pressure, unsigned compIdx) const
Calculate the binary molecular diffusion coefficient for a component in a fluid phase [mol^2 * s / (k...
Definition GasPvtMultiplexer.hpp:269
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &saltConcentration) const
Returns the water vaporization factor [m^3/m^3] of water saturated gas.
Definition GasPvtMultiplexer.hpp:247
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the oil vaporization factor [m^3/m^3] of oil saturated gas.
Definition GasPvtMultiplexer.hpp:218
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &temperature, const Evaluation &Rv) const
Returns the saturation pressure of the gas phase [Pa] depending on its mass fraction of the oil compo...
Definition GasPvtMultiplexer.hpp:260
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &oilSaturation, const Evaluation &maxOilSaturation) const
Returns the oil vaporization factor [m^3/m^3] of oil saturated gas.
Definition GasPvtMultiplexer.hpp:227
Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of oil saturated gas given a set of parameters.
Definition GasPvtMultiplexer.hpp:189
Definition Schedule.hpp:101
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30