27#ifndef OPM_WET_GAS_PVT_HPP
28#define OPM_WET_GAS_PVT_HPP
31#include <opm/common/OpmLog/OpmLog.hpp>
49template <
class Scalar>
52 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
66 void extendPvtgTable_(
unsigned regionIdx,
74 void setVapPars(
const Scalar par1,
const Scalar)
94 const SamplingPoints& samplePoints)
95 { saturatedOilVaporizationFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
107 const SamplingPoints& samplePoints);
122 const TabulatedTwoDFunction& invBg)
123 { inverseGasB_[regionIdx] = invBg; }
131 { gasMu_[regionIdx] = mug; }
141 const SamplingPoints& samplePoints);
152 {
return gasReferenceDensity_.size(); }
157 template <
class Evaluation>
162 const Evaluation&)
const
164 throw std::runtime_error(
"Requested the enthalpy of gas but the thermal "
165 "option is not enabled");
168 Scalar hVap(
unsigned)
const
170 throw std::runtime_error(
"Requested the hvap of oil but the thermal "
171 "option is not enabled");
177 template <
class Evaluation>
180 const Evaluation& pressure,
181 const Evaluation& Rv,
182 const Evaluation& )
const
184 const Evaluation& invBg = inverseGasB_[regionIdx].eval(pressure, Rv,
true);
185 const Evaluation& invMugBg = inverseGasBMu_[regionIdx].eval(pressure, Rv,
true);
187 return invBg / invMugBg;
193 template <
class Evaluation>
196 const Evaluation& pressure)
const
198 const Evaluation& invBg = inverseSaturatedGasB_[regionIdx].eval(pressure,
true);
199 const Evaluation& invMugBg = inverseSaturatedGasBMu_[regionIdx].eval(pressure,
true);
201 return invBg / invMugBg;
207 template <
class Evaluation>
210 const Evaluation& pressure,
211 const Evaluation& Rv,
212 const Evaluation& )
const
213 {
return inverseGasB_[regionIdx].eval(pressure, Rv,
true); }
218 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::ValueType>
219 std::pair<LhsEval, LhsEval>
222 const LhsEval& p = decay<LhsEval>(fluidState.pressure(FluidState::gasPhaseIdx));
223 const LhsEval& Rv = decay<LhsEval>(fluidState.Rv());
225 const auto satSegIdx = this->saturatedOilVaporizationFactorTable_[regionIdx].findSegmentIndex(p,
true);
226 const auto RvSat = this->saturatedOilVaporizationFactorTable_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
227 const bool useSaturatedTables = (fluidState.saturation(FluidState::oilPhaseIdx) > 0.0) && (Rv >= (1.0 - 1e-10) * RvSat);
229 if (useSaturatedTables) {
230 const LhsEval b = this->inverseSaturatedGasB_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
231 const LhsEval invBMu = this->inverseSaturatedGasBMu_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
232 const LhsEval mu = b / invBMu;
235 unsigned ii, jj1, jj2;
236 LhsEval alpha, beta1, beta2;
237 this->inverseGasB_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, p, Rv,
true);
238 const LhsEval b = this->inverseGasB_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
239 const LhsEval invBMu = this->inverseGasBMu_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
240 const LhsEval mu = b / invBMu;
248 template <
class Evaluation>
251 const Evaluation& pressure)
const
252 {
return inverseSaturatedGasB_[regionIdx].eval(pressure,
true); }
257 template <
class Evaluation>
260 const Evaluation& )
const
266 template <
class Evaluation = Scalar>
270 const Evaluation& )
const
276 template <
class Evaluation>
279 const Evaluation& pressure)
const
281 return saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure,
true);
291 template <
class Evaluation>
294 const Evaluation& pressure,
295 const Evaluation& oilSaturation,
296 Evaluation maxOilSaturation)
const
299 saturatedOilVaporizationFactorTable_[regionIdx].eval(pressure,
true);
303 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
304 if (vapPar1_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
305 constexpr const Scalar eps = 0.001;
306 const Evaluation& So = max(oilSaturation, eps);
307 tmp *= max(1e-3, pow(So / maxOilSaturation, vapPar1_));
324 template <
class Evaluation>
327 const Evaluation& Rv)
const
331 const auto& RvTable = saturatedOilVaporizationFactorTable_[regionIdx];
332 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
335 Evaluation pSat = saturationPressure_[regionIdx].eval(Rv,
true);
340 bool onProbation =
false;
341 for (
unsigned i = 0; i < 20; ++i) {
342 const Evaluation& f = RvTable.eval(pSat,
true) - Rv;
343 const Evaluation& fPrime = RvTable.evalDerivative(pSat,
true);
347 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
351 const Evaluation& delta = f / fPrime;
366 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
371 const std::string msg =
372 "Finding saturation pressure did not converge: "
373 "pSat = " + std::to_string(getValue(pSat)) +
374 ", Rv = " + std::to_string(getValue(Rv));
375 OpmLog::debug(
"Wet gas saturation pressure", msg);
379 template <
class Evaluation>
380 Evaluation diffusionCoefficient(
const Evaluation& ,
384 throw std::runtime_error(
"Not implemented: The PVT model does not provide "
385 "a diffusionCoefficient()");
388 Scalar gasReferenceDensity(
unsigned regionIdx)
const
389 {
return gasReferenceDensity_[regionIdx]; }
391 Scalar oilReferenceDensity(
unsigned regionIdx)
const
392 {
return oilReferenceDensity_[regionIdx]; }
394 const std::vector<TabulatedTwoDFunction>& inverseGasB()
const
395 {
return inverseGasB_; }
397 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasB()
const
398 {
return inverseSaturatedGasB_; }
400 const std::vector<TabulatedTwoDFunction>& gasMu()
const
403 const std::vector<TabulatedTwoDFunction>& inverseGasBMu()
const
404 {
return inverseGasBMu_; }
406 const std::vector<TabulatedOneDFunction>& inverseSaturatedGasBMu()
const
407 {
return inverseSaturatedGasBMu_; }
409 const std::vector<TabulatedOneDFunction>& saturatedOilVaporizationFactorTable()
const
410 {
return saturatedOilVaporizationFactorTable_; }
413 {
return saturationPressure_; }
415 Scalar vapPar1()
const
419 void updateSaturationPressure_(
unsigned regionIdx);
421 std::vector<Scalar> gasReferenceDensity_{};
422 std::vector<Scalar> oilReferenceDensity_{};
423 std::vector<TabulatedTwoDFunction> inverseGasB_{};
424 std::vector<TabulatedOneDFunction> inverseSaturatedGasB_{};
425 std::vector<TabulatedTwoDFunction> gasMu_{};
426 std::vector<TabulatedTwoDFunction> inverseGasBMu_{};
427 std::vector<TabulatedOneDFunction> inverseSaturatedGasBMu_{};
428 std::vector<TabulatedOneDFunction> saturatedOilVaporizationFactorTable_{};
429 std::vector<TabulatedOneDFunction> saturationPressure_{};
431 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 phas with vaporized oil.
Definition WetGasPvt.hpp:51
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:249
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:277
void initEnd()
Finish initializing the gas phase PVT properties.
Definition WetGasPvt.cpp:327
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:325
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:158
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:292
void setGasViscosity(unsigned regionIdx, const TabulatedTwoDFunction &mug)
Initialize the viscosity of the gas phase.
Definition WetGasPvt.hpp:130
Evaluation saturatedWaterVaporizationFactor(unsigned, const Evaluation &, const Evaluation &) const
Returns the water vaporization factor [m^3/m^3] of the gasphase.
Definition WetGasPvt.hpp:258
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:267
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition WetGasPvt.hpp:151
void setSaturatedGasViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for oil saturated gas.
Definition WetGasPvt.cpp:293
void setSaturatedGasFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the gas formation volume factor.
Definition WetGasPvt.cpp:242
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:208
void setSaturatedGasOilVaporizationFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil vaporization factor .
Definition WetGasPvt.hpp:93
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:220
void setInverseGasFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBg)
Initialize the function for the gas formation volume factor.
Definition WetGasPvt.hpp:121
void initFromState(const EclipseState &eclState, const Schedule &schedule)
Initialize the parameters for wet gas using an ECL deck.
Definition WetGasPvt.cpp:40
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:194
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:178
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition WetGasPvt.cpp:231
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition Tabulated1DFunction.hpp:41