27#ifndef OPM_GAS_PVT_THERMAL_HPP
28#define OPM_GAS_PVT_THERMAL_HPP
39template <
class Scalar,
bool enableThermal>
48template <
class Scalar>
55 GasPvtThermal() =
default;
57 GasPvtThermal(IsothermalPvt* isothermalPvt,
58 const std::vector<TabulatedOneDFunction>& gasvisctCurves,
59 const std::vector<Scalar>& viscrefPress,
60 const std::vector<Scalar>& viscRef,
61 const std::vector<Scalar>& gasdentRefTemp,
62 const std::vector<Scalar>& gasdentCT1,
63 const std::vector<Scalar>& gasdentCT2,
64 const std::vector<Scalar>& gasJTRefPres,
65 const std::vector<Scalar>& gasJTC,
66 const std::vector<TabulatedOneDFunction>& internalEnergyCurves,
70 bool enableInternalEnergy)
71 : isothermalPvt_(isothermalPvt)
72 , gasvisctCurves_(gasvisctCurves)
73 , viscrefPress_(viscrefPress)
75 , gasdentRefTemp_(gasdentRefTemp)
76 , gasdentCT1_(gasdentCT1)
77 , gasdentCT2_(gasdentCT2)
78 , gasJTRefPres_(gasJTRefPres)
80 , internalEnergyCurves_(internalEnergyCurves)
84 , enableInternalEnergy_(enableInternalEnergy)
87 GasPvtThermal(
const GasPvtThermal& data)
91 {
delete isothermalPvt_; }
103 void setVapPars(
const Scalar par1,
const Scalar par2)
105 isothermalPvt_->setVapPars(par1, par2);
118 {
return enableThermalDensity_; }
124 {
return enableJouleThomson_; }
130 {
return enableThermalViscosity_; }
132 std::size_t numRegions()
const
133 {
return viscrefPress_.size(); }
138 template <
class Evaluation>
140 const Evaluation& temperature,
141 const Evaluation& pressure,
142 const Evaluation& Rv,
143 [[maybe_unused]]
const Evaluation& RvW)
const
145 if (!enableInternalEnergy_) {
146 throw std::runtime_error(
"Requested the internal energy of gas but it is disabled");
149 if (!enableJouleThomson_) {
153 return internalEnergyCurves_[regionIdx].eval(temperature,
true);
157 OpmLog::warning(
"Experimental code for jouleThomson: simulation will be slower");
158 Evaluation Tref = gasdentRefTemp_[regionIdx];
159 Evaluation Pref = gasJTRefPres_[regionIdx];
160 Scalar JTC = gasJTC_[regionIdx];
161 Evaluation Rvw = 0.0;
165 Evaluation Cp = (internalEnergyCurves_[regionIdx].eval(temperature,
true))/temperature;
166 Evaluation density = invB * (gasReferenceDensity(regionIdx) + Rv * rhoRefO_[regionIdx]);
168 Evaluation enthalpyPres;
170 enthalpyPres = -Cp * JTC * (pressure -Pref);
172 else if (enableThermalDensity_) {
173 Scalar c1T = gasdentCT1_[regionIdx];
174 Scalar c2T = gasdentCT2_[regionIdx];
176 Evaluation alpha = (c1T + 2 * c2T * (temperature - Tref)) /
177 (1 + c1T *(temperature - Tref) + c2T * (temperature - Tref) * (temperature - Tref));
179 constexpr const int N = 100;
180 Evaluation deltaP = (pressure - Pref)/N;
181 Evaluation enthalpyPresPrev = 0;
182 for (std::size_t i = 0; i < N; ++i) {
183 Evaluation Pnew = Pref + i * deltaP;
185 (gasReferenceDensity(regionIdx) + Rv * rhoRefO_[regionIdx]);
187 Evaluation jouleThomsonCoefficient = -(1.0/Cp) * (1.0 - alpha * temperature)/rho;
188 Evaluation deltaEnthalpyPres = -Cp * jouleThomsonCoefficient * deltaP;
189 enthalpyPres = enthalpyPresPrev + deltaEnthalpyPres;
190 enthalpyPresPrev = enthalpyPres;
194 throw std::runtime_error(
"Requested Joule-thomson calculation but thermal "
195 "gas density (GASDENT) is not provided");
198 Evaluation enthalpy = Cp * (temperature - Tref) + enthalpyPres;
200 return enthalpy - pressure/density;
207 template <
class Evaluation>
209 const Evaluation& temperature,
210 const Evaluation& pressure,
211 const Evaluation& Rv,
212 const Evaluation& Rvw)
const
214 const auto& isothermalMu = isothermalPvt_->viscosity(regionIdx, temperature, pressure, Rv, Rvw);
219 const auto& muGasvisct = gasvisctCurves_[regionIdx].eval(temperature,
true);
220 return muGasvisct/viscRef_[regionIdx]*isothermalMu;
226 template <
class Evaluation>
228 const Evaluation& temperature,
229 const Evaluation& pressure)
const
231 const auto& isothermalMu = isothermalPvt_->saturatedViscosity(regionIdx, temperature, pressure);
236 const auto& muGasvisct = gasvisctCurves_[regionIdx].eval(temperature,
true);
237 return muGasvisct/viscRef_[regionIdx]*isothermalMu;
243 template <
class Evaluation>
245 const Evaluation& temperature,
246 const Evaluation& pressure,
247 const Evaluation& Rv,
248 const Evaluation& )
const
250 const Evaluation& Rvw = 0.0;
252 isothermalPvt_->inverseFormationVolumeFactor(regionIdx, temperature,
266 Scalar TRef = gasdentRefTemp_[regionIdx];
267 Scalar cT1 = gasdentCT1_[regionIdx];
268 Scalar cT2 = gasdentCT2_[regionIdx];
269 const Evaluation& Y = temperature - TRef;
271 return b / (1 + (cT1 + cT2 * Y) * Y);
277 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::ValueType>
278 std::pair<LhsEval, LhsEval>
281 auto [b, mu] = isothermalPvt_->inverseFormationVolumeFactorAndViscosity(fluidState, regionIdx);
282 const LhsEval& temperature = decay<LhsEval>(fluidState.temperature(FluidState::gasPhaseIdx));
291 Scalar TRef = gasdentRefTemp_[regionIdx];
292 Scalar cT1 = gasdentCT1_[regionIdx];
293 Scalar cT2 = gasdentCT2_[regionIdx];
294 const LhsEval& Y = temperature - TRef;
295 b /= (1.0 + (cT1 + cT2 * Y) * Y);
299 const auto& muGasvisct = gasvisctCurves_[regionIdx].eval(temperature,
true);
300 mu *= (muGasvisct / viscRef_[regionIdx]);
308 template <
class Evaluation>
310 const Evaluation& temperature,
311 const Evaluation& pressure)
const
314 isothermalPvt_->saturatedInverseFormationVolumeFactor(regionIdx, temperature, pressure);
327 Scalar TRef = gasdentRefTemp_[regionIdx];
328 Scalar cT1 = gasdentCT1_[regionIdx];
329 Scalar cT2 = gasdentCT2_[regionIdx];
330 const Evaluation& Y = temperature - TRef;
332 return b / (1 + (cT1 + cT2 * Y) * Y);
338 template <
class Evaluation>
341 const Evaluation& )
const
347 template <
class Evaluation = Scalar>
351 const Evaluation& )
const
361 template <
class Evaluation>
363 const Evaluation& temperature,
364 const Evaluation& pressure)
const
365 {
return isothermalPvt_->saturatedOilVaporizationFactor(regionIdx, temperature, pressure); }
374 template <
class Evaluation>
376 const Evaluation& temperature,
377 const Evaluation& pressure,
378 const Evaluation& oilSaturation,
379 const Evaluation& maxOilSaturation)
const
381 return isothermalPvt_->saturatedOilVaporizationFactor(regionIdx, temperature,
382 pressure, oilSaturation,
393 template <
class Evaluation>
395 const Evaluation& temperature,
396 const Evaluation& pressure)
const
397 {
return isothermalPvt_->saturationPressure(regionIdx, temperature, pressure); }
399 template <
class Evaluation>
400 Evaluation diffusionCoefficient(
const Evaluation& temperature,
401 const Evaluation& pressure,
402 unsigned compIdx)
const
406 const IsothermalPvt* isoThermalPvt()
const
407 {
return isothermalPvt_; }
409 Scalar gasReferenceDensity(
unsigned regionIdx)
const
412 Scalar hVap(
unsigned regionIdx)
const
413 {
return this->hVap_[regionIdx]; }
415 const std::vector<TabulatedOneDFunction>& gasvisctCurves()
const
416 {
return gasvisctCurves_; }
418 const std::vector<Scalar>& viscrefPress()
const
419 {
return viscrefPress_; }
421 const std::vector<Scalar>& viscRef()
const
424 const std::vector<Scalar>& gasdentRefTemp()
const
425 {
return gasdentRefTemp_; }
427 const std::vector<Scalar>& gasdentCT1()
const
428 {
return gasdentCT1_; }
430 const std::vector<Scalar>& gasdentCT2()
const
431 {
return gasdentCT2_; }
433 const std::vector<TabulatedOneDFunction>& internalEnergyCurves()
const
434 {
return internalEnergyCurves_; }
436 bool enableInternalEnergy()
const
437 {
return enableInternalEnergy_; }
439 const std::vector<Scalar>& gasJTRefPres()
const
440 {
return gasJTRefPres_; }
442 const std::vector<Scalar>& gasJTC()
const
445 bool operator==(
const GasPvtThermal<Scalar>& data)
const;
447 GasPvtThermal<Scalar>& operator=(
const GasPvtThermal<Scalar>& data);
450 IsothermalPvt* isothermalPvt_{
nullptr};
454 std::vector<TabulatedOneDFunction> gasvisctCurves_{};
455 std::vector<Scalar> viscrefPress_{};
456 std::vector<Scalar> viscRef_{};
458 std::vector<Scalar> gasdentRefTemp_{};
459 std::vector<Scalar> gasdentCT1_{};
460 std::vector<Scalar> gasdentCT2_{};
462 std::vector<Scalar> gasJTRefPres_{};
463 std::vector<Scalar> gasJTC_{};
465 std::vector<Scalar> rhoRefO_{};
466 std::vector<Scalar> hVap_{};
469 std::vector<TabulatedOneDFunction> internalEnergyCurves_{};
471 bool enableThermalDensity_{
false};
472 bool enableJouleThomson_{
false};
473 bool enableThermalViscosity_{
false};
474 bool enableInternalEnergy_{
false};
Implements a linearly interpolated scalar function that depends on one variable.
Definition EclipseState.hpp:66
This class represents the Pressure-Volume-Temperature relations of the gas phase in the black-oil mod...
Definition GasPvtMultiplexer.hpp:109
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:279
bool enableThermalDensity() const
Returns true iff the density of the gas phase is temperature dependent.
Definition GasPvtThermal.hpp:117
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:208
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:375
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the formation volume factor [-] of oil-saturated gas.
Definition GasPvtThermal.hpp:309
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:362
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:348
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:139
void setNumRegions(std::size_t numRegions)
Set the number of PVT-regions considered by this object.
Definition GasPvtThermal.cpp:191
void initEnd()
Finish initializing the thermal part of the gas phase PVT properties.
Definition GasPvtThermal.hpp:111
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:244
bool enableJouleThomson() const
Returns true iff Joule-Thomson effect for the gas phase is active.
Definition GasPvtThermal.hpp:123
bool enableThermalViscosity() const
Returns true iff the viscosity of the gas phase is temperature dependent.
Definition GasPvtThermal.hpp:129
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition GasPvtThermal.hpp:339
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:279
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:227
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &temperature, const Evaluation &pressure) const
Returns the saturation pressure of the gas phase [Pa].
Definition GasPvtThermal.hpp:394
void initFromState(const EclipseState &eclState, const Schedule &schedule)
Implement the temperature part of the gas PVT properties.
Definition GasPvtThermal.cpp:42
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