27#ifndef OPM_GAS_PVT_THERMAL_HPP
28#define OPM_GAS_PVT_THERMAL_HPP
41template <
class Scalar,
bool enableThermal>
50template <
class Scalar>
57 GasPvtThermal() =
default;
59 GasPvtThermal(IsothermalPvt* isothermalPvt,
60 const std::vector<TabulatedOneDFunction>& gasvisctCurves,
61 const std::vector<Scalar>& viscrefPress,
62 const std::vector<Scalar>& viscRef,
63 const std::vector<Scalar>& gasdentRefTemp,
64 const std::vector<Scalar>& gasdentCT1,
65 const std::vector<Scalar>& gasdentCT2,
66 const std::vector<Scalar>& gasJTRefPres,
67 const std::vector<Scalar>& gasJTC,
68 const std::vector<TabulatedOneDFunction>& internalEnergyCurves,
72 bool enableInternalEnergy)
73 : isothermalPvt_(isothermalPvt)
74 , gasvisctCurves_(gasvisctCurves)
75 , viscrefPress_(viscrefPress)
77 , gasdentRefTemp_(gasdentRefTemp)
78 , gasdentCT1_(gasdentCT1)
79 , gasdentCT2_(gasdentCT2)
80 , gasJTRefPres_(gasJTRefPres)
82 , internalEnergyCurves_(internalEnergyCurves)
86 , enableInternalEnergy_(enableInternalEnergy)
89 GasPvtThermal(
const GasPvtThermal& data)
93 {
delete isothermalPvt_; }
107 void setVapPars(
const Scalar par1,
const Scalar par2)
109 isothermalPvt_->setVapPars(par1, par2);
122 {
return enableThermalDensity_; }
128 {
return enableJouleThomson_; }
134 {
return enableThermalViscosity_; }
136 std::size_t numRegions()
const
137 {
return viscrefPress_.size(); }
142 template <
class Evaluation>
144 const Evaluation& temperature,
145 const Evaluation& pressure,
146 const Evaluation& Rv,
147 [[maybe_unused]]
const Evaluation& RvW)
const
149 if (!enableInternalEnergy_) {
150 throw std::runtime_error(
"Requested the internal energy of gas but it is disabled");
153 if (!enableJouleThomson_) {
157 return internalEnergyCurves_[regionIdx].eval(temperature,
true);
161 OpmLog::warning(
"Experimental code for jouleThomson: simulation will be slower");
162 Evaluation Tref = gasdentRefTemp_[regionIdx];
163 Evaluation Pref = gasJTRefPres_[regionIdx];
164 Scalar JTC = gasJTC_[regionIdx];
165 Evaluation Rvw = 0.0;
169 Evaluation Cp = (internalEnergyCurves_[regionIdx].eval(temperature,
true))/temperature;
170 Evaluation density = invB * (gasReferenceDensity(regionIdx) + Rv * rhoRefO_[regionIdx]);
172 Evaluation enthalpyPres;
174 enthalpyPres = -Cp * JTC * (pressure -Pref);
176 else if (enableThermalDensity_) {
177 Scalar c1T = gasdentCT1_[regionIdx];
178 Scalar c2T = gasdentCT2_[regionIdx];
180 Evaluation alpha = (c1T + 2 * c2T * (temperature - Tref)) /
181 (1 + c1T *(temperature - Tref) + c2T * (temperature - Tref) * (temperature - Tref));
183 constexpr const int N = 100;
184 Evaluation deltaP = (pressure - Pref)/N;
185 Evaluation enthalpyPresPrev = 0;
186 for (std::size_t i = 0; i < N; ++i) {
187 Evaluation Pnew = Pref + i * deltaP;
189 (gasReferenceDensity(regionIdx) + Rv * rhoRefO_[regionIdx]);
191 Evaluation jouleThomsonCoefficient = -(1.0/Cp) * (1.0 - alpha * temperature)/rho;
192 Evaluation deltaEnthalpyPres = -Cp * jouleThomsonCoefficient * deltaP;
193 enthalpyPres = enthalpyPresPrev + deltaEnthalpyPres;
194 enthalpyPresPrev = enthalpyPres;
198 throw std::runtime_error(
"Requested Joule-thomson calculation but thermal "
199 "gas density (GASDENT) is not provided");
202 Evaluation enthalpy = Cp * (temperature - Tref) + enthalpyPres;
204 return enthalpy - pressure/density;
211 template <
class Evaluation>
213 const Evaluation& temperature,
214 const Evaluation& pressure,
215 const Evaluation& Rv,
216 const Evaluation& Rvw)
const
218 const auto& isothermalMu = isothermalPvt_->viscosity(regionIdx, temperature, pressure, Rv, Rvw);
223 const auto& muGasvisct = gasvisctCurves_[regionIdx].eval(temperature,
true);
224 return muGasvisct/viscRef_[regionIdx]*isothermalMu;
230 template <
class Evaluation>
232 const Evaluation& temperature,
233 const Evaluation& pressure)
const
235 const auto& isothermalMu = isothermalPvt_->saturatedViscosity(regionIdx, temperature, pressure);
240 const auto& muGasvisct = gasvisctCurves_[regionIdx].eval(temperature,
true);
241 return muGasvisct/viscRef_[regionIdx]*isothermalMu;
247 template <
class Evaluation>
249 const Evaluation& temperature,
250 const Evaluation& pressure,
251 const Evaluation& Rv,
252 const Evaluation& )
const
254 const Evaluation& Rvw = 0.0;
256 isothermalPvt_->inverseFormationVolumeFactor(regionIdx, temperature,
270 Scalar TRef = gasdentRefTemp_[regionIdx];
271 Scalar cT1 = gasdentCT1_[regionIdx];
272 Scalar cT2 = gasdentCT2_[regionIdx];
273 const Evaluation& Y = temperature - TRef;
275 return b / (1 + (cT1 + cT2 * Y) * Y);
281 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
282 std::pair<LhsEval, LhsEval>
285 auto [b, mu] = isothermalPvt_->inverseFormationVolumeFactorAndViscosity(fluidState, regionIdx);
286 const LhsEval& temperature = decay<LhsEval>(fluidState.temperature(FluidState::gasPhaseIdx));
295 Scalar TRef = gasdentRefTemp_[regionIdx];
296 Scalar cT1 = gasdentCT1_[regionIdx];
297 Scalar cT2 = gasdentCT2_[regionIdx];
298 const LhsEval& Y = temperature - TRef;
299 b /= (1.0 + (cT1 + cT2 * Y) * Y);
303 const auto& muGasvisct = gasvisctCurves_[regionIdx].eval(temperature,
true);
304 mu *= (muGasvisct / viscRef_[regionIdx]);
312 template <
class Evaluation>
314 const Evaluation& temperature,
315 const Evaluation& pressure)
const
318 isothermalPvt_->saturatedInverseFormationVolumeFactor(regionIdx, temperature, pressure);
331 Scalar TRef = gasdentRefTemp_[regionIdx];
332 Scalar cT1 = gasdentCT1_[regionIdx];
333 Scalar cT2 = gasdentCT2_[regionIdx];
334 const Evaluation& Y = temperature - TRef;
336 return b / (1 + (cT1 + cT2 * Y) * Y);
342 template <
class Evaluation>
345 const Evaluation& )
const
351 template <
class Evaluation = Scalar>
355 const Evaluation& )
const
365 template <
class Evaluation>
367 const Evaluation& temperature,
368 const Evaluation& pressure)
const
369 {
return isothermalPvt_->saturatedOilVaporizationFactor(regionIdx, temperature, pressure); }
378 template <
class Evaluation>
380 const Evaluation& temperature,
381 const Evaluation& pressure,
382 const Evaluation& oilSaturation,
383 const Evaluation& maxOilSaturation)
const
385 return isothermalPvt_->saturatedOilVaporizationFactor(regionIdx, temperature,
386 pressure, oilSaturation,
397 template <
class Evaluation>
399 const Evaluation& temperature,
400 const Evaluation& pressure)
const
401 {
return isothermalPvt_->saturationPressure(regionIdx, temperature, pressure); }
403 template <
class Evaluation>
404 Evaluation diffusionCoefficient(
const Evaluation& temperature,
405 const Evaluation& pressure,
406 unsigned compIdx)
const
410 const IsothermalPvt* isoThermalPvt()
const
411 {
return isothermalPvt_; }
413 Scalar gasReferenceDensity(
unsigned regionIdx)
const
416 Scalar hVap(
unsigned regionIdx)
const
417 {
return this->hVap_[regionIdx]; }
419 const std::vector<TabulatedOneDFunction>& gasvisctCurves()
const
420 {
return gasvisctCurves_; }
422 const std::vector<Scalar>& viscrefPress()
const
423 {
return viscrefPress_; }
425 const std::vector<Scalar>& viscRef()
const
428 const std::vector<Scalar>& gasdentRefTemp()
const
429 {
return gasdentRefTemp_; }
431 const std::vector<Scalar>& gasdentCT1()
const
432 {
return gasdentCT1_; }
434 const std::vector<Scalar>& gasdentCT2()
const
435 {
return gasdentCT2_; }
437 const std::vector<TabulatedOneDFunction>& internalEnergyCurves()
const
438 {
return internalEnergyCurves_; }
440 bool enableInternalEnergy()
const
441 {
return enableInternalEnergy_; }
443 const std::vector<Scalar>& gasJTRefPres()
const
444 {
return gasJTRefPres_; }
446 const std::vector<Scalar>& gasJTC()
const
449 bool operator==(
const GasPvtThermal<Scalar>& data)
const;
451 GasPvtThermal<Scalar>& operator=(
const GasPvtThermal<Scalar>& data);
454 IsothermalPvt* isothermalPvt_{
nullptr};
458 std::vector<TabulatedOneDFunction> gasvisctCurves_{};
459 std::vector<Scalar> viscrefPress_{};
460 std::vector<Scalar> viscRef_{};
462 std::vector<Scalar> gasdentRefTemp_{};
463 std::vector<Scalar> gasdentCT1_{};
464 std::vector<Scalar> gasdentCT2_{};
466 std::vector<Scalar> gasJTRefPres_{};
467 std::vector<Scalar> gasJTC_{};
469 std::vector<Scalar> rhoRefO_{};
470 std::vector<Scalar> hVap_{};
473 std::vector<TabulatedOneDFunction> internalEnergyCurves_{};
475 bool enableThermalDensity_{
false};
476 bool enableJouleThomson_{
false};
477 bool enableThermalViscosity_{
false};
478 bool enableInternalEnergy_{
false};
Implements a linearly interpolated scalar function that depends on one variable.
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
Scalar gasReferenceDensity(unsigned regionIdx) const
Return the reference density which are considered by this PVT-object.
Definition GasPvtMultiplexer.cpp:57
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:283
bool enableThermalDensity() const
Returns true iff the density of the gas phase is temperature dependent.
Definition GasPvtThermal.hpp:121
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 GasPvtThermal.hpp:212
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 the gas phase.
Definition GasPvtThermal.hpp:379
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the formation volume factor [-] of oil-saturated gas.
Definition GasPvtThermal.hpp:313
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the oil vaporization factor [m^3/m^3] of the gas phase.
Definition GasPvtThermal.hpp:366
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of water saturated gas.
Definition GasPvtThermal.hpp:352
Evaluation internalEnergy(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &RvW) const
Returns the specific internal energy [J/kg] of gas given a set of parameters.
Definition GasPvtThermal.hpp:143
void setNumRegions(std::size_t numRegions)
Set the number of PVT-regions considered by this object.
Definition GasPvtThermal.cpp:193
void initEnd()
Finish initializing the thermal part of the gas phase PVT properties.
Definition GasPvtThermal.hpp:115
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &) const
Returns the formation volume factor [-] of the fluid phase.
Definition GasPvtThermal.hpp:248
bool enableJouleThomson() const
Returns true iff Joule-Thomson effect for the gas phase is active.
Definition GasPvtThermal.hpp:127
bool enableThermalViscosity() const
Returns true iff the viscosity of the gas phase is temperature dependent.
Definition GasPvtThermal.hpp:133
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition GasPvtThermal.hpp:343
std::pair< LhsEval, LhsEval > inverseFormationVolumeFactorAndViscosity(const FluidState &fluidState, unsigned regionIdx)
Returns the formation volume factor [-] and viscosity [Pa s] of the fluid phase.
Definition GasPvtThermal.hpp:283
Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of the oil-saturated gas phase given a set of parameters.
Definition GasPvtThermal.hpp:231
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the saturation pressure of the gas phase [Pa].
Definition GasPvtThermal.hpp:398
Definition Schedule.hpp:101
Implements a linearly interpolated scalar function that depends on one variable.
Definition Tabulated1DFunction.hpp:51
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30