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,
89 { saturatedGasDissolutionFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
101 const SamplingPoints& samplePoints);
116 { inverseOilBTable_[regionIdx] = invBo; }
124 { oilMuTable_[regionIdx] = muo; }
134 const SamplingPoints& samplePoints);
145 {
return inverseOilBMuTable_.size(); }
150 template <
class Evaluation>
154 const Evaluation&)
const
156 throw std::runtime_error(
"Requested the enthalpy of oil but the thermal option is not enabled");
162 template <
class Evaluation>
165 const Evaluation& pressure,
166 const Evaluation& Rs)
const
169 const Evaluation& invBo = inverseOilBTable_[regionIdx].eval(Rs, pressure,
true);
170 const Evaluation& invMuoBo = inverseOilBMuTable_[regionIdx].eval(Rs, pressure,
true);
172 return invBo/invMuoBo;
178 template <
class Evaluation>
181 const Evaluation& pressure)
const
184 const Evaluation& invBo = inverseSaturatedOilBTable_[regionIdx].eval(pressure,
true);
185 const Evaluation& invMuoBo = inverseSaturatedOilBMuTable_[regionIdx].eval(pressure,
true);
187 return invBo/invMuoBo;
193 template <
class Evaluation>
196 const Evaluation& pressure,
197 const Evaluation& Rs)
const
200 return inverseOilBTable_[regionIdx].eval(Rs, pressure,
true);
206 template <
class Evaluation>
209 const Evaluation& pressure)
const
212 return inverseSaturatedOilBTable_[regionIdx].eval(pressure,
true);
218 template <
class Evaluation>
221 const Evaluation& pressure)
const
222 {
return saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure,
true); }
231 template <
class Evaluation>
234 const Evaluation& pressure,
235 const Evaluation& oilSaturation,
236 Evaluation maxOilSaturation)
const
239 saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure,
true);
243 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
244 if (vapPar2_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
245 constexpr const Scalar eps = 0.001;
246 const Evaluation& So = max(oilSaturation, eps);
247 tmp *= max(1e-3, pow(So/maxOilSaturation, vapPar2_));
259 template <
class Evaluation>
262 const Evaluation& Rs)
const
266 const auto& RsTable = saturatedGasDissolutionFactorTable_[regionIdx];
267 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon()*1e6;
270 Evaluation pSat = saturationPressure_[regionIdx].eval(Rs,
true);
275 bool onProbation =
false;
276 for (
int i = 0; i < 20; ++i) {
277 const Evaluation& f = RsTable.eval(pSat,
true) - Rs;
278 const Evaluation& fPrime = RsTable.evalDerivative(pSat,
true);
282 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
286 const Evaluation& delta = f/fPrime;
300 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps)
304 const std::string msg =
305 "Finding saturation pressure did not converge: "
306 " pSat = " + std::to_string(getValue(pSat)) +
307 ", Rs = " + std::to_string(getValue(Rs));
308 OpmLog::debug(
"Live oil saturation pressure", msg);
312 template <
class Evaluation>
313 Evaluation diffusionCoefficient(
const Evaluation& ,
317 throw std::runtime_error(
"Not implemented: The PVT model does not provide a diffusionCoefficient()");
320 Scalar gasReferenceDensity(
unsigned regionIdx)
const
321 {
return gasReferenceDensity_[regionIdx]; }
323 Scalar oilReferenceDensity(
unsigned regionIdx)
const
324 {
return oilReferenceDensity_[regionIdx]; }
326 const std::vector<TabulatedTwoDFunction>& inverseOilBTable()
const
327 {
return inverseOilBTable_; }
329 const std::vector<TabulatedTwoDFunction>& oilMuTable()
const
330 {
return oilMuTable_; }
332 const std::vector<TabulatedTwoDFunction>& inverseOilBMuTable()
const
333 {
return inverseOilBMuTable_; }
335 const std::vector<TabulatedOneDFunction>& saturatedOilMuTable()
const
336 {
return saturatedOilMuTable_; }
338 const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBTable()
const
339 {
return inverseSaturatedOilBTable_; }
341 const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBMuTable()
const
342 {
return inverseSaturatedOilBMuTable_; }
344 const std::vector<TabulatedOneDFunction>& saturatedGasDissolutionFactorTable()
const
345 {
return saturatedGasDissolutionFactorTable_; }
348 {
return saturationPressure_; }
350 Scalar vapPar2()
const
354 void updateSaturationPressure_(
unsigned regionIdx);
356 std::vector<Scalar> gasReferenceDensity_;
357 std::vector<Scalar> oilReferenceDensity_;
358 std::vector<TabulatedTwoDFunction> inverseOilBTable_;
359 std::vector<TabulatedTwoDFunction> oilMuTable_;
360 std::vector<TabulatedTwoDFunction> inverseOilBMuTable_;
361 std::vector<TabulatedOneDFunction> saturatedOilMuTable_;
362 std::vector<TabulatedOneDFunction> inverseSaturatedOilBTable_;
363 std::vector<TabulatedOneDFunction> inverseSaturatedOilBMuTable_;
364 std::vector<TabulatedOneDFunction> saturatedGasDissolutionFactorTable_;
365 std::vector<TabulatedOneDFunction> saturationPressure_;
367 Scalar vapPar2_ = 0.0;
Provides the OPM specific exception classes.
Definition: EclipseState.hpp:55
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:151
void setSaturatedOilFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil formation volume factor.
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:194
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:232
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of the fluid phase.
Definition: LiveOilPvt.hpp:207
void setSaturatedOilViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for gas saturated oil.
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:260
void setSaturatedOilGasDissolutionFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the gas dissolution factor .
Definition: LiveOilPvt.hpp:88
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:163
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
void setOilViscosity(unsigned regionIdx, const TabulatedTwoDFunction &muo)
Initialize the viscosity of the oil phase.
Definition: LiveOilPvt.hpp:123
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:219
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:179
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: LiveOilPvt.hpp:144
void initEnd()
Finish initializing the oil phase PVT properties.
void setInverseOilFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBo)
Initialize the function for the oil formation volume factor.
Definition: LiveOilPvt.hpp:115
Definition: Exceptions.hpp:40
Definition: Schedule.hpp:130
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