27#ifndef OPM_LIVE_OIL_PVT_HPP
28#define OPM_LIVE_OIL_PVT_HPP
31#include <opm/common/OpmLog/OpmLog.hpp>
49template <
class Scalar>
52 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
65 void extendPvtoTable_(
unsigned regionIdx,
75 void setVapPars(
const Scalar,
const Scalar par2)
95 const SamplingPoints& samplePoints)
96 { saturatedGasDissolutionFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
108 const SamplingPoints& samplePoints);
123 const TabulatedTwoDFunction& invBo)
124 { inverseOilBTable_[regionIdx] = invBo; }
132 { oilMuTable_[regionIdx] = muo; }
142 const SamplingPoints& samplePoints);
153 {
return inverseOilBMuTable_.size(); }
158 template <
class Evaluation>
162 const Evaluation&)
const
164 throw std::runtime_error(
"Requested the enthalpy of oil 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& Rs)
const
184 const Evaluation& invBo = inverseOilBTable_[regionIdx].eval(Rs, pressure,
true);
185 const Evaluation& invMuoBo = inverseOilBMuTable_[regionIdx].eval(Rs, pressure,
true);
187 return invBo / invMuoBo;
193 template <
class Evaluation>
196 const Evaluation& pressure)
const
199 const Evaluation& invBo = inverseSaturatedOilBTable_[regionIdx].eval(pressure,
true);
200 const Evaluation& invMuoBo = inverseSaturatedOilBMuTable_[regionIdx].eval(pressure,
true);
202 return invBo / invMuoBo;
208 template <
class Evaluation>
211 const Evaluation& pressure,
212 const Evaluation& Rs)
const
215 return inverseOilBTable_[regionIdx].eval(Rs, pressure,
true);
221 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::Scalar>
222 std::pair<LhsEval, LhsEval>
225 const LhsEval& p = decay<LhsEval>(fluidState.pressure(FluidState::oilPhaseIdx));
226 const LhsEval& Rs = decay<LhsEval>(fluidState.Rs());
228 const auto satSegIdx = this->saturatedGasDissolutionFactorTable_[regionIdx].findSegmentIndex(p,
true);
229 const auto RsSat = this->saturatedGasDissolutionFactorTable_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
230 const bool useSaturatedTables = (fluidState.saturation(FluidState::gasPhaseIdx) > 0.0) && (Rs >= (1.0 - 1e-10) * RsSat);
232 if (useSaturatedTables) {
233 const LhsEval b = this->inverseSaturatedOilBTable_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
234 const LhsEval invBMu = this->inverseSaturatedOilBMuTable_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
235 const LhsEval mu = b / invBMu;
238 unsigned ii, jj1, jj2;
239 LhsEval alpha, beta1, beta2;
240 this->inverseOilBTable_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, Rs, p,
true);
241 const LhsEval b = this->inverseOilBTable_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
242 const LhsEval invBMu = this->inverseOilBMuTable_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
243 const LhsEval mu = b / invBMu;
251 template <
class Evaluation>
254 const Evaluation& pressure)
const
257 return inverseSaturatedOilBTable_[regionIdx].eval(pressure,
true);
263 template <
class Evaluation>
266 const Evaluation& pressure)
const
267 {
return saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure,
true); }
276 template <
class Evaluation>
279 const Evaluation& pressure,
280 const Evaluation& oilSaturation,
281 Evaluation maxOilSaturation)
const
284 saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure,
true);
288 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
289 if (vapPar2_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
290 constexpr const Scalar eps = 0.001;
291 const Evaluation& So = max(oilSaturation, eps);
292 tmp *= max(1e-3, pow(So / maxOilSaturation, vapPar2_));
305 template <
class Evaluation>
308 const Evaluation& Rs)
const
312 const auto& RsTable = saturatedGasDissolutionFactorTable_[regionIdx];
313 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
316 Evaluation pSat = saturationPressure_[regionIdx].eval(Rs,
true);
321 bool onProbation =
false;
322 for (
int i = 0; i < 20; ++i) {
323 const Evaluation& f = RsTable.eval(pSat,
true) - Rs;
324 const Evaluation& fPrime = RsTable.evalDerivative(pSat,
true);
328 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
332 const Evaluation& delta = f / fPrime;
347 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
352 const std::string msg =
353 "Finding saturation pressure did not converge: "
354 " pSat = " + std::to_string(getValue(pSat)) +
355 ", Rs = " + std::to_string(getValue(Rs));
356 OpmLog::debug(
"Live oil saturation pressure", msg);
360 template <
class Evaluation>
361 Evaluation diffusionCoefficient(
const Evaluation& ,
365 throw std::runtime_error(
"Not implemented: The PVT model does not provide "
366 "a diffusionCoefficient()");
369 Scalar gasReferenceDensity(
unsigned regionIdx)
const
370 {
return gasReferenceDensity_[regionIdx]; }
372 Scalar oilReferenceDensity(
unsigned regionIdx)
const
373 {
return oilReferenceDensity_[regionIdx]; }
375 const std::vector<TabulatedTwoDFunction>& inverseOilBTable()
const
376 {
return inverseOilBTable_; }
378 const std::vector<TabulatedTwoDFunction>& oilMuTable()
const
379 {
return oilMuTable_; }
381 const std::vector<TabulatedTwoDFunction>& inverseOilBMuTable()
const
382 {
return inverseOilBMuTable_; }
384 const std::vector<TabulatedOneDFunction>& saturatedOilMuTable()
const
385 {
return saturatedOilMuTable_; }
387 const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBTable()
const
388 {
return inverseSaturatedOilBTable_; }
390 const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBMuTable()
const
391 {
return inverseSaturatedOilBMuTable_; }
393 const std::vector<TabulatedOneDFunction>& saturatedGasDissolutionFactorTable()
const
394 {
return saturatedGasDissolutionFactorTable_; }
397 {
return saturationPressure_; }
399 Scalar vapPar2()
const
403 void updateSaturationPressure_(
unsigned regionIdx);
405 std::vector<Scalar> gasReferenceDensity_{};
406 std::vector<Scalar> oilReferenceDensity_{};
407 std::vector<TabulatedTwoDFunction> inverseOilBTable_{};
408 std::vector<TabulatedTwoDFunction> oilMuTable_{};
409 std::vector<TabulatedTwoDFunction> inverseOilBMuTable_{};
410 std::vector<TabulatedOneDFunction> saturatedOilMuTable_{};
411 std::vector<TabulatedOneDFunction> inverseSaturatedOilBTable_{};
412 std::vector<TabulatedOneDFunction> inverseSaturatedOilBMuTable_{};
413 std::vector<TabulatedOneDFunction> saturatedGasDissolutionFactorTable_{};
414 std::vector<TabulatedOneDFunction> saturationPressure_{};
416 Scalar vapPar2_ = 0.0;
Provides the OPM specific exception classes.
Implements a linearly interpolated scalar function that depends on one variable.
Definition EclipseState.hpp:62
This class represents the Pressure-Volume-Temperature relations of the oil phas with dissolved gas.
Definition LiveOilPvt.hpp:51
Evaluation internalEnergy(unsigned, const Evaluation &, const Evaluation &, const Evaluation &) const
Returns the specific enthalpy [J/kg] of oil given a set of parameters.
Definition LiveOilPvt.hpp:159
void setSaturatedOilFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil formation volume factor.
Definition LiveOilPvt.cpp:246
Evaluation inverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rs) const
Returns the formation volume factor [-] of the fluid phase.
Definition LiveOilPvt.hpp:209
Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &oilSaturation, Evaluation maxOilSaturation) const
Returns the gas dissolution factor [m^3/m^3] of the oil phase.
Definition LiveOilPvt.hpp:277
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of the fluid phase.
Definition LiveOilPvt.hpp:252
void setSaturatedOilViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for gas saturated oil.
Definition LiveOilPvt.cpp:273
Evaluation saturationPressure(unsigned regionIdx, const Evaluation &, const Evaluation &Rs) const
Returns the saturation pressure of the oil phase [Pa] depending on its mass fraction of the gas compo...
Definition LiveOilPvt.hpp:306
void setSaturatedOilGasDissolutionFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the gas dissolution factor .
Definition LiveOilPvt.hpp:94
Evaluation viscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure, const Evaluation &Rs) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition LiveOilPvt.hpp:178
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition LiveOilPvt.cpp:235
void setOilViscosity(unsigned regionIdx, const TabulatedTwoDFunction &muo)
Initialize the viscosity of the oil phase.
Definition LiveOilPvt.hpp:131
Evaluation saturatedGasDissolutionFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the gas dissolution factor [m^3/m^3] of the oil phase.
Definition LiveOilPvt.hpp:264
Evaluation saturatedViscosity(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the dynamic viscosity [Pa s] of the fluid phase given a set of parameters.
Definition LiveOilPvt.hpp:194
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition LiveOilPvt.hpp:152
std::pair< LhsEval, LhsEval > inverseFormationVolumeFactorAndViscosity(const FluidState &fluidState, unsigned regionIdx)
Returns the formation volume factor [-] and viscosity [Pa s] of the fluid phase.
Definition LiveOilPvt.hpp:223
void initEnd()
Finish initializing the oil phase PVT properties.
Definition LiveOilPvt.cpp:300
void setInverseOilFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBo)
Initialize the function for the oil formation volume factor.
Definition LiveOilPvt.hpp:122
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 implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition Tabulated1DFunction.hpp:41