27#ifndef OPM_WET_HUMID_GAS_PVT_HPP
28#define OPM_WET_HUMID_GAS_PVT_HPP
31#include <opm/common/OpmLog/OpmLog.hpp>
50template <
class Scalar>
53 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
67 void extendPvtgwTable_(
unsigned regionIdx,
72 void extendPvtgTable_(
unsigned regionIdx,
80 void setVapPars(
const Scalar par1,
const Scalar)
100 const SamplingPoints& samplePoints)
101 { saturatedWaterVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
110 const SamplingPoints& samplePoints)
111 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
122 {
return gasReferenceDensity_.size(); }
127 template <
class Evaluation>
132 const Evaluation&)
const
134 throw std::runtime_error(
"Requested the enthalpy of gas but the thermal "
135 "option is not enabled");
138 Scalar hVap(
unsigned)
const
140 throw std::runtime_error(
"Requested the hvap of oil but the thermal "
141 "option is not enabled");
147 template <
class Evaluation>
150 const Evaluation& pressure,
151 const Evaluation& Rv,
152 const Evaluation& Rvw)
const
154 const Evaluation& temperature = 1E30;
156 if (Rv >= (1.0 - 1e-10) * saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
157 const Evaluation& invBg = inverseGasBRvSat_[regionIdx].eval(pressure, Rvw,
true);
158 const Evaluation& invMugBg = inverseGasBMuRvSat_[regionIdx].eval(pressure, Rvw,
true);
159 return invBg / invMugBg;
163 const Evaluation& invBg = inverseGasBRvwSat_[regionIdx].eval(pressure, Rv,
true);
164 const Evaluation& invMugBg = inverseGasBMuRvwSat_[regionIdx].eval(pressure, Rv,
true);
165 return invBg / invMugBg;
172 template <
class Evaluation>
175 const Evaluation& pressure)
const
177 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure,
true);
178 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure,
true);
180 return invBg / invMugBg;
193 template <
class Evaluation>
196 const Evaluation& pressure,
197 const Evaluation& Rv,
198 const Evaluation& Rvw)
const
200 const Evaluation& temperature = 1E30;
202 if (Rv >= (1.0 - 1e-10) * saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
203 return inverseGasBRvSat_[regionIdx].eval(pressure, Rvw,
true);
207 return inverseGasBRvwSat_[regionIdx].eval(pressure, Rv,
true);
214 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::ValueType>
215 std::pair<LhsEval, LhsEval>
218 const LhsEval& p = decay<LhsEval>(fluidState.pressure(FluidState::gasPhaseIdx));
219 const LhsEval& Rv = decay<LhsEval>(fluidState.Rv());
220 const LhsEval& Rvw = decay<LhsEval>(fluidState.Rvw());
221 const LhsEval& saltConc
222 = BlackOil::template getSaltConcentration_<FluidState, LhsEval>(fluidState, regionIdx);
228 const auto RvSat = this->saturatedOilVaporizationFactorTable_[regionIdx].eval(p,
true);
230 const auto RvwSat = enableRwgSalt_
231 ? this->saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(p, saltConc,
true)
232 : this->saturatedWaterVaporizationFactorTable_[regionIdx].eval(p,
true);
234 const bool waterSaturated = (fluidState.saturation(FluidState::waterPhaseIdx) > 0.0) && (Rvw >= (1.0 - 1e-10) * RvwSat);
235 const bool oilSaturated = (fluidState.saturation(FluidState::oilPhaseIdx) > 0.0) && (Rv >= (1.0 - 1e-10) * RvSat);
237 if (waterSaturated && oilSaturated) {
238 const auto satSegIdx = this->inverseSaturatedGasB_[regionIdx].findSegmentIndex(p,
true);
239 const LhsEval b = this->inverseSaturatedGasB_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
240 const LhsEval invBMu = this->inverseSaturatedGasBMu_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
241 const LhsEval mu = b / invBMu;
243 }
else if (oilSaturated) {
244 unsigned ii, jj1, jj2;
245 LhsEval alpha, beta1, beta2;
246 this->inverseGasBRvSat_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, p, Rvw,
true);
247 const LhsEval b = this->inverseGasBRvSat_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
248 const LhsEval invBMu = this->inverseGasBMuRvSat_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
249 const LhsEval mu = b / invBMu;
253 unsigned ii, jj1, jj2;
254 LhsEval alpha, beta1, beta2;
255 this->inverseGasBRvwSat_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, p, Rv,
true);
256 const LhsEval b = this->inverseGasBRvwSat_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
257 const LhsEval invBMu = this->inverseGasBMuRvwSat_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
258 const LhsEval mu = b / invBMu;
266 template <
class Evaluation>
269 const Evaluation& pressure)
const
270 {
return inverseSaturatedGasB_[regionIdx].eval(pressure,
true); }
275 template <
class Evaluation>
278 const Evaluation& pressure)
const
280 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure,
true);
286 template <
class Evaluation>
289 const Evaluation& pressure,
290 const Evaluation& saltConcentration)
const
292 if (enableRwgSalt_) {
293 return saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(pressure, saltConcentration,
true);
296 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure,
true);
300 template <
class Evaluation>
301 Evaluation saturatedOilVaporizationFactor(
unsigned regionIdx,
303 const Evaluation& pressure)
const
305 return saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure,
true);
315 template <
class Evaluation>
318 const Evaluation& pressure,
319 const Evaluation& oilSaturation,
320 Evaluation maxOilSaturation)
const
323 saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure,
true);
327 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
328 if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
329 constexpr const Scalar eps = 0.001;
330 const Evaluation& So = max(oilSaturation, eps);
331 tmp *= max(1e-3, pow(So / maxOilSaturation, vapPar1_));
346 template <
class Evaluation>
349 const Evaluation& Rw)
const
353 const auto& RwTable = saturatedWaterVaporizationFactorTable_[regionIdx];
354 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
357 Evaluation pSat = saturationPressure_[regionIdx].eval(Rw,
true);
362 bool onProbation =
false;
363 for (
unsigned i = 0; i < 20; ++i) {
364 const Evaluation& f = RwTable.eval(pSat,
true) - Rw;
365 const Evaluation& fPrime = RwTable.evalDerivative(pSat,
true);
369 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
373 const Evaluation& delta = f / fPrime;
388 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
393 const std::string msg =
394 "Finding saturation pressure did not converge: "
395 "pSat = " + std::to_string(getValue(pSat)) +
396 ", Rw = " + std::to_string(getValue(Rw));
397 OpmLog::debug(
"Wet gas saturation pressure", msg);
401 template <
class Evaluation>
402 Evaluation diffusionCoefficient(
const Evaluation& ,
406 throw std::runtime_error(
"Not implemented: The PVT model does not provide "
407 "a diffusionCoefficient()");
410 Scalar gasReferenceDensity(
unsigned regionIdx)
const
411 {
return gasReferenceDensity_[regionIdx]; }
413 Scalar oilReferenceDensity(
unsigned regionIdx)
const
414 {
return oilReferenceDensity_[regionIdx]; }
416 Scalar waterReferenceDensity(
unsigned regionIdx)
const
417 {
return waterReferenceDensity_[regionIdx]; }
419 const std::vector<TabulatedTwoDFunction>& inverseGasB()
const
420 {
return inverseGasBRvSat_; }
422 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB()
const
423 {
return inverseSaturatedGasB_; }
425 const std::vector<TabulatedTwoDFunction>& gasMu()
const
426 {
return gasMuRvSat_; }
428 const std::vector<TabulatedTwoDFunction>& inverseGasBMu()
const
429 {
return inverseGasBMuRvSat_; }
431 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu()
const
432 {
return inverseSaturatedGasBMu_; }
434 const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable()
const
435 {
return saturatedWaterVaporizationFactorTable_; }
437 const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable()
const
438 {
return saturatedWaterVaporizationSaltFactorTable_; }
440 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable()
const
441 {
return saturatedOilVaporizationFactorTable_; }
444 {
return saturationPressure_; }
446 Scalar vapPar1()
const
450 void updateSaturationPressure_(
unsigned regionIdx);
452 std::vector<Scalar> gasReferenceDensity_{};
453 std::vector<Scalar> oilReferenceDensity_{};
454 std::vector<Scalar> waterReferenceDensity_{};
455 std::vector<TabulatedTwoDFunction> inverseGasBRvwSat_{};
456 std::vector<TabulatedTwoDFunction> inverseGasBRvSat_{};
457 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_{};
458 std::vector<TabulatedTwoDFunction> gasMuRvwSat_{};
459 std::vector<TabulatedTwoDFunction> gasMuRvSat_{};
460 std::vector<TabulatedTwoDFunction> inverseGasBMuRvwSat_{};
461 std::vector<TabulatedTwoDFunction> inverseGasBMuRvSat_{};
462 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_{};
463 std::vector<TabulatedOneDFunction> saturatedWaterVaporizationFactorTable_{};
464 std::vector<TabulatedTwoDFunction> saturatedWaterVaporizationSaltFactorTable_{};
465 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_{};
466 std::vector<TabulatedOneDFunction> saturationPressure_{};
468 bool enableRwgSalt_ =
false;
469 Scalar vapPar1_ = 0.0;
Provides the OPM specific exception classes.
Implements a linearly interpolated scalar function that depends on one variable.
Definition EclipseState.hpp:66
Definition Exceptions.hpp:40
Definition Schedule.hpp:101
Definition SimpleTable.hpp:35
Implements a linearly interpolated scalar function that depends on one variable.
Definition Tabulated1DFunction.hpp:51
This class represents the Pressure-Volume-Temperature relations of the gas phase with vaporized oil a...
Definition WetHumidGasPvt.hpp:52
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &, const Evaluation &Rw) const
Returns the saturation pressure of the gas phase [Pa] depending on its mass fraction of the water com...
Definition WetHumidGasPvt.hpp:347
std::pair< LhsEval, LhsEval > inverseFormationVolumeFactorAndViscosity(const FluidState &fluidState, unsigned regionIdx)
Returns the formation volume factor [-] and viscosity [Pa s] of the fluid phase.
Definition WetHumidGasPvt.hpp:216
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition WetHumidGasPvt.hpp:121
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition WetHumidGasPvt.hpp:109
Evaluation viscosity(unsigned regionIdx, const Evaluation &, 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 WetHumidGasPvt.hpp:148
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &saltConcentration) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition WetHumidGasPvt.hpp:287
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of water saturated gas at a given pressure.
Definition WetHumidGasPvt.hpp:267
Evaluation saturatedWaterVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the water vaporization factor [m^3/m^3] of the water phase.
Definition WetHumidGasPvt.hpp:276
Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of oil saturated gas at a given pressure.
Definition WetHumidGasPvt.hpp:173
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &oilSaturation, Evaluation maxOilSaturation) const
Returns the oil vaporization factor [m^3/m^3] of the gas phase.
Definition WetHumidGasPvt.hpp:316
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar rhoRefWater)
Initialize the reference densities of all fluids for a given PVT region.
Definition WetHumidGasPvt.cpp:418
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &Rvw) const
Returns the formation volume factor [-] of the fluid phase.
Definition WetHumidGasPvt.hpp:194
Evaluation internalEnergy(unsigned, const Evaluation &, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the specific enthalpy [J/kg] of gas given a set of parameters.
Definition WetHumidGasPvt.hpp:128
void initFromState(const EclipseState &eclState, const Schedule &schedule)
Initialize the parameters for wet gas using an ECL deck.
Definition WetHumidGasPvt.cpp:39
void initEnd()
Finish initializing the gas phase PVT properties.
Definition WetHumidGasPvt.cpp:429
void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the water vaporization factor .
Definition WetHumidGasPvt.hpp:99
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition Tabulated1DFunction.hpp:41