27#ifndef OPM_WET_HUMID_GAS_PVT_HPP
28#define OPM_WET_HUMID_GAS_PVT_HPP
31#include <opm/common/OpmLog/OpmLog.hpp>
52template <
class Scalar>
55 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
70 void extendPvtgwTable_(
unsigned regionIdx,
75 void extendPvtgTable_(
unsigned regionIdx,
85 void setVapPars(
const Scalar par1,
const Scalar)
105 const SamplingPoints& samplePoints)
106 { saturatedWaterVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
115 const SamplingPoints& samplePoints)
116 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
127 {
return gasReferenceDensity_.size(); }
132 template <
class Evaluation>
137 const Evaluation&)
const
139 throw std::runtime_error(
"Requested the enthalpy of gas but the thermal "
140 "option is not enabled");
143 Scalar hVap(
unsigned)
const
145 throw std::runtime_error(
"Requested the hvap of oil but the thermal "
146 "option is not enabled");
152 template <
class Evaluation>
155 const Evaluation& pressure,
156 const Evaluation& Rv,
157 const Evaluation& Rvw)
const
159 const Evaluation& temperature = 1E30;
161 if (Rv >= (1.0 - 1e-10) * saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
162 const Evaluation& invBg = inverseGasBRvSat_[regionIdx].eval(pressure, Rvw,
true);
163 const Evaluation& invMugBg = inverseGasBMuRvSat_[regionIdx].eval(pressure, Rvw,
true);
164 return invBg / invMugBg;
168 const Evaluation& invBg = inverseGasBRvwSat_[regionIdx].eval(pressure, Rv,
true);
169 const Evaluation& invMugBg = inverseGasBMuRvwSat_[regionIdx].eval(pressure, Rv,
true);
170 return invBg / invMugBg;
177 template <
class Evaluation>
180 const Evaluation& pressure)
const
182 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure,
true);
183 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure,
true);
185 return invBg / invMugBg;
198 template <
class Evaluation>
201 const Evaluation& pressure,
202 const Evaluation& Rv,
203 const Evaluation& Rvw)
const
205 const Evaluation& temperature = 1E30;
207 if (Rv >= (1.0 - 1e-10) * saturatedOilVaporizationFactor(regionIdx, temperature, pressure)) {
208 return inverseGasBRvSat_[regionIdx].eval(pressure, Rvw,
true);
212 return inverseGasBRvwSat_[regionIdx].eval(pressure, Rv,
true);
219 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
220 std::pair<LhsEval, LhsEval>
223 const LhsEval& p = decay<LhsEval>(fluidState.pressure(FluidState::gasPhaseIdx));
224 const LhsEval& Rv = decay<LhsEval>(fluidState.Rv());
225 const LhsEval& Rvw = decay<LhsEval>(fluidState.Rvw());
226 const LhsEval& saltConc
227 = BlackOil::template getSaltConcentration_<FluidState, LhsEval>(fluidState, regionIdx);
233 const auto RvSat = this->saturatedOilVaporizationFactorTable_[regionIdx].eval(p,
true);
235 const auto RvwSat = enableRwgSalt_
236 ? this->saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(p, saltConc,
true)
237 : this->saturatedWaterVaporizationFactorTable_[regionIdx].eval(p,
true);
239 const bool waterSaturated = (fluidState.saturation(FluidState::waterPhaseIdx) > 0.0) && (Rvw >= (1.0 - 1e-10) * RvwSat);
240 const bool oilSaturated = (fluidState.saturation(FluidState::oilPhaseIdx) > 0.0) && (Rv >= (1.0 - 1e-10) * RvSat);
242 if (waterSaturated && oilSaturated) {
243 const auto satSegIdx = this->inverseSaturatedGasB_[regionIdx].findSegmentIndex(p,
true);
244 const LhsEval b = this->inverseSaturatedGasB_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
245 const LhsEval invBMu = this->inverseSaturatedGasBMu_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
246 const LhsEval mu = b / invBMu;
248 }
else if (oilSaturated) {
249 unsigned ii, jj1, jj2;
250 LhsEval alpha, beta1, beta2;
251 this->inverseGasBRvSat_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, p, Rvw,
true);
252 const LhsEval b = this->inverseGasBRvSat_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
253 const LhsEval invBMu = this->inverseGasBMuRvSat_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
254 const LhsEval mu = b / invBMu;
258 unsigned ii, jj1, jj2;
259 LhsEval alpha, beta1, beta2;
260 this->inverseGasBRvwSat_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, p, Rv,
true);
261 const LhsEval b = this->inverseGasBRvwSat_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
262 const LhsEval invBMu = this->inverseGasBMuRvwSat_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
263 const LhsEval mu = b / invBMu;
271 template <
class Evaluation>
274 const Evaluation& pressure)
const
275 {
return inverseSaturatedGasB_[regionIdx].eval(pressure,
true); }
280 template <
class Evaluation>
283 const Evaluation& pressure)
const
285 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure,
true);
291 template <
class Evaluation>
294 const Evaluation& pressure,
295 const Evaluation& saltConcentration)
const
297 if (enableRwgSalt_) {
298 return saturatedWaterVaporizationSaltFactorTable_[regionIdx].eval(pressure, saltConcentration,
true);
301 return saturatedWaterVaporizationFactorTable_[regionIdx].eval(pressure,
true);
305 template <
class Evaluation>
306 Evaluation saturatedOilVaporizationFactor(
unsigned regionIdx,
308 const Evaluation& pressure)
const
310 return saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure,
true);
320 template <
class Evaluation>
323 const Evaluation& pressure,
324 const Evaluation& oilSaturation,
325 Evaluation maxOilSaturation)
const
328 saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure,
true);
332 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
333 if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
334 constexpr const Scalar eps = 0.001;
335 const Evaluation& So = max(oilSaturation, eps);
336 tmp *= max(1e-3, pow(So / maxOilSaturation, vapPar1_));
351 template <
class Evaluation>
354 const Evaluation& Rw)
const
358 const auto& RwTable = saturatedWaterVaporizationFactorTable_[regionIdx];
359 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
362 Evaluation pSat = saturationPressure_[regionIdx].eval(Rw,
true);
367 bool onProbation =
false;
368 for (
unsigned i = 0; i < 20; ++i) {
369 const Evaluation& f = RwTable.eval(pSat,
true) - Rw;
370 const Evaluation& fPrime = RwTable.evalDerivative(pSat,
true);
374 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
378 const Evaluation& delta = f / fPrime;
393 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
398 const std::string msg =
399 "Finding saturation pressure did not converge: "
400 "pSat = " + std::to_string(getValue(pSat)) +
401 ", Rw = " + std::to_string(getValue(Rw));
402 OpmLog::debug(
"Wet gas saturation pressure", msg);
406 template <
class Evaluation>
407 Evaluation diffusionCoefficient(
const Evaluation& ,
411 throw std::runtime_error(
"Not implemented: The PVT model does not provide "
412 "a diffusionCoefficient()");
415 Scalar gasReferenceDensity(
unsigned regionIdx)
const
416 {
return gasReferenceDensity_[regionIdx]; }
418 Scalar oilReferenceDensity(
unsigned regionIdx)
const
419 {
return oilReferenceDensity_[regionIdx]; }
421 Scalar waterReferenceDensity(
unsigned regionIdx)
const
422 {
return waterReferenceDensity_[regionIdx]; }
424 const std::vector<TabulatedTwoDFunction>& inverseGasB()
const
425 {
return inverseGasBRvSat_; }
427 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB()
const
428 {
return inverseSaturatedGasB_; }
430 const std::vector<TabulatedTwoDFunction>& gasMu()
const
431 {
return gasMuRvSat_; }
433 const std::vector<TabulatedTwoDFunction>& inverseGasBMu()
const
434 {
return inverseGasBMuRvSat_; }
436 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu()
const
437 {
return inverseSaturatedGasBMu_; }
439 const std::vector<TabulatedOneDFunction>& saturatedWaterVaporizationFactorTable()
const
440 {
return saturatedWaterVaporizationFactorTable_; }
442 const std::vector<TabulatedTwoDFunction>& saturatedWaterVaporizationSaltFactorTable()
const
443 {
return saturatedWaterVaporizationSaltFactorTable_; }
445 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable()
const
446 {
return saturatedOilVaporizationFactorTable_; }
449 {
return saturationPressure_; }
451 Scalar vapPar1()
const
455 void updateSaturationPressure_(
unsigned regionIdx);
457 std::vector<Scalar> gasReferenceDensity_{};
458 std::vector<Scalar> oilReferenceDensity_{};
459 std::vector<Scalar> waterReferenceDensity_{};
460 std::vector<TabulatedTwoDFunction> inverseGasBRvwSat_{};
461 std::vector<TabulatedTwoDFunction> inverseGasBRvSat_{};
462 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_{};
463 std::vector<TabulatedTwoDFunction> gasMuRvwSat_{};
464 std::vector<TabulatedTwoDFunction> gasMuRvSat_{};
465 std::vector<TabulatedTwoDFunction> inverseGasBMuRvwSat_{};
466 std::vector<TabulatedTwoDFunction> inverseGasBMuRvSat_{};
467 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_{};
468 std::vector<TabulatedOneDFunction> saturatedWaterVaporizationFactorTable_{};
469 std::vector<TabulatedTwoDFunction> saturatedWaterVaporizationSaltFactorTable_{};
470 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_{};
471 std::vector<TabulatedOneDFunction> saturationPressure_{};
473 bool enableRwgSalt_ =
false;
474 Scalar vapPar1_ = 0.0;
Provides the OPM specific exception classes.
Implements a linearly interpolated scalar function that depends on one variable.
Definition EclipseState.hpp:62
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:54
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:352
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:221
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition WetHumidGasPvt.hpp:126
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition WetHumidGasPvt.hpp:114
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:153
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:292
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:272
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:281
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:178
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:321
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:422
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:199
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:133
void initEnd()
Finish initializing the gas phase PVT properties.
Definition WetHumidGasPvt.cpp:433
void setSaturatedGasWaterVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the water vaporization factor .
Definition WetHumidGasPvt.hpp:104
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition Tabulated1DFunction.hpp:41