27#ifndef OPM_WET_GAS_PVT_HPP
28#define OPM_WET_GAS_PVT_HPP
31#include <opm/common/OpmLog/OpmLog.hpp>
51template <
class Scalar>
54 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
69 void extendPvtgTable_(
unsigned regionIdx,
79 void setVapPars(
const Scalar par1,
const Scalar)
99 const SamplingPoints& samplePoints)
100 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
112 const SamplingPoints& samplePoints);
127 const TabulatedTwoDFunction& invBg)
128 { inverseGasB_[regionIdx] = invBg; }
136 { gasMu_[regionIdx] = mug; }
146 const SamplingPoints& samplePoints);
157 {
return gasReferenceDensity_.size(); }
162 template <
class Evaluation>
167 const Evaluation&)
const
169 throw std::runtime_error(
"Requested the enthalpy of gas but the thermal "
170 "option is not enabled");
173 Scalar hVap(
unsigned)
const
175 throw std::runtime_error(
"Requested the hvap of oil but the thermal "
176 "option is not enabled");
182 template <
class Evaluation>
185 const Evaluation& pressure,
186 const Evaluation& Rv,
187 const Evaluation& )
const
189 const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, Rv,
true);
190 const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, Rv,
true);
192 return invBg / invMugBg;
198 template <
class Evaluation>
201 const Evaluation& pressure)
const
203 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure,
true);
204 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure,
true);
206 return invBg / invMugBg;
212 template <
class Evaluation>
215 const Evaluation& pressure,
216 const Evaluation& Rv,
217 const Evaluation& )
const
218 {
return inverseGasB_[regionIdx].eval(pressure, Rv,
true); }
223 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
224 std::pair<LhsEval, LhsEval>
227 const LhsEval& p = decay<LhsEval>(fluidState.pressure(FluidState::gasPhaseIdx));
228 const LhsEval& Rv = decay<LhsEval>(fluidState.Rv());
230 const auto satSegIdx = this->saturatedOilVaporizationFactorTable_[regionIdx].findSegmentIndex(p,
true);
231 const auto RvSat = this->saturatedOilVaporizationFactorTable_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
232 const bool useSaturatedTables = (fluidState.saturation(FluidState::oilPhaseIdx) > 0.0) && (Rv >= (1.0 - 1e-10) * RvSat);
234 if (useSaturatedTables) {
235 const LhsEval b = this->inverseSaturatedGasB_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
236 const LhsEval invBMu = this->inverseSaturatedGasBMu_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
237 const LhsEval mu = b / invBMu;
240 unsigned ii, jj1, jj2;
241 LhsEval alpha, beta1, beta2;
242 this->inverseGasB_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, p, Rv,
true);
243 const LhsEval b = this->inverseGasB_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
244 const LhsEval invBMu = this->inverseGasBMu_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
245 const LhsEval mu = b / invBMu;
253 template <
class Evaluation>
256 const Evaluation& pressure)
const
257 {
return inverseSaturatedGasB_[regionIdx].eval(pressure,
true); }
262 template <
class Evaluation>
265 const Evaluation& )
const
271 template <
class Evaluation = Scalar>
275 const Evaluation& )
const
281 template <
class Evaluation>
284 const Evaluation& pressure)
const
286 return saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure,
true);
296 template <
class Evaluation>
299 const Evaluation& pressure,
300 const Evaluation& oilSaturation,
301 Evaluation maxOilSaturation)
const
304 saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure,
true);
308 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
309 if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
310 constexpr const Scalar eps = 0.001;
311 const Evaluation& So = max(oilSaturation, eps);
312 tmp *= max(1e-3, pow(So / maxOilSaturation, vapPar1_));
329 template <
class Evaluation>
332 const Evaluation& Rv)
const
336 const auto& RvTable = saturatedOilVaporizationFactorTable_[regionIdx];
337 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
340 Evaluation pSat = saturationPressure_[regionIdx].eval(Rv,
true);
345 bool onProbation =
false;
346 for (
unsigned i = 0; i < 20; ++i) {
347 const Evaluation& f = RvTable.eval(pSat,
true) - Rv;
348 const Evaluation& fPrime = RvTable.evalDerivative(pSat,
true);
352 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
356 const Evaluation& delta = f / fPrime;
371 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
376 const std::string msg =
377 "Finding saturation pressure did not converge: "
378 "pSat = " + std::to_string(getValue(pSat)) +
379 ", Rv = " + std::to_string(getValue(Rv));
380 OpmLog::debug(
"Wet gas saturation pressure", msg);
384 template <
class Evaluation>
385 Evaluation diffusionCoefficient(
const Evaluation& ,
389 throw std::runtime_error(
"Not implemented: The PVT model does not provide "
390 "a diffusionCoefficient()");
393 Scalar gasReferenceDensity(
unsigned regionIdx)
const
394 {
return gasReferenceDensity_[regionIdx]; }
396 Scalar oilReferenceDensity(
unsigned regionIdx)
const
397 {
return oilReferenceDensity_[regionIdx]; }
399 const std::vector<TabulatedTwoDFunction>& inverseGasB()
const
400 {
return inverseGasB_; }
402 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB()
const
403 {
return inverseSaturatedGasB_; }
405 const std::vector<TabulatedTwoDFunction>& gasMu()
const
408 const std::vector<TabulatedTwoDFunction>& inverseGasBMu()
const
409 {
return inverseGasBMu_; }
411 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu()
const
412 {
return inverseSaturatedGasBMu_; }
414 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable()
const
415 {
return saturatedOilVaporizationFactorTable_; }
418 {
return saturationPressure_; }
420 Scalar vapPar1()
const
424 void updateSaturationPressure_(
unsigned regionIdx);
426 std::vector<Scalar> gasReferenceDensity_{};
427 std::vector<Scalar> oilReferenceDensity_{};
428 std::vector<TabulatedTwoDFunction> inverseGasB_{};
429 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_{};
430 std::vector<TabulatedTwoDFunction> gasMu_{};
431 std::vector<TabulatedTwoDFunction> inverseGasBMu_{};
432 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_{};
433 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_{};
434 std::vector<TabulatedOneDFunction> saturationPressure_{};
436 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 phas with vaporized oil.
Definition WetGasPvt.hpp:53
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of oil saturated gas at a given pressure.
Definition WetGasPvt.hpp:254
Evaluation saturatedOilVaporizationFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the oil vaporization factor [m^3/m^3] of the gas phase.
Definition WetGasPvt.hpp:282
void initEnd()
Finish initializing the gas phase PVT properties.
Definition WetGasPvt.cpp:331
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &, const Evaluation &Rv) const
Returns the saturation pressure of the gas phase [Pa] depending on its mass fraction of the oil compo...
Definition WetGasPvt.hpp:330
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 WetGasPvt.hpp:163
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 WetGasPvt.hpp:297
void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction &mug)
Initialize the viscosity of the gas phase.
Definition WetGasPvt.hpp:135
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of the gasphase.
Definition WetGasPvt.hpp:263
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of water saturated gas.
Definition WetGasPvt.hpp:272
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition WetGasPvt.hpp:156
void setSaturatedGasViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for oil saturated gas.
Definition WetGasPvt.cpp:297
void setSaturatedGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the gas formation volume factor.
Definition WetGasPvt.cpp:246
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &) const
Returns the formation volume factor [-] of the fluid phase.
Definition WetGasPvt.hpp:213
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition WetGasPvt.hpp:98
std::pair< LhsEval, LhsEval > inverseFormationVolumeFactorAndViscosity(const FluidState &fluidState, unsigned regionIdx)
Returns the formation volume factor [-] and viscosity [Pa s] of the fluid phase.
Definition WetGasPvt.hpp:225
void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBg)
Initialize the function for the gas formation volume factor.
Definition WetGasPvt.hpp:126
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 WetGasPvt.hpp:199
Evaluation viscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rv, const Evaluation &) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition WetGasPvt.hpp:183
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition WetGasPvt.cpp:235
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition Tabulated1DFunction.hpp:41