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)
94 const SamplingPoints& samplePoints)
95 { saturatedGasDissolutionFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
107 const SamplingPoints& samplePoints);
123 { inverseOilBTable_[regionIdx] = invBo; }
131 { oilMuTable_[regionIdx] = muo; }
141 const SamplingPoints& samplePoints);
152 {
return inverseOilBMuTable_.size(); }
157 template <
class Evaluation>
161 const Evaluation&)
const
163 throw std::runtime_error(
"Requested the enthalpy of oil but the thermal "
164 "option is not enabled");
167 Scalar hVap(
unsigned)
const
169 throw std::runtime_error(
"Requested the hvap of oil but the thermal "
170 "option is not enabled");
176 template <
class Evaluation>
179 const Evaluation& pressure,
180 const Evaluation& Rs)
const
183 const Evaluation& invBo = inverseOilBTable_[regionIdx].eval(Rs, pressure,
true);
184 const Evaluation& invMuoBo = inverseOilBMuTable_[regionIdx].eval(Rs, pressure,
true);
186 return invBo / invMuoBo;
192 template <
class Evaluation>
195 const Evaluation& pressure)
const
198 const Evaluation& invBo = inverseSaturatedOilBTable_[regionIdx].eval(pressure,
true);
199 const Evaluation& invMuoBo = inverseSaturatedOilBMuTable_[regionIdx].eval(pressure,
true);
201 return invBo / invMuoBo;
207 template <
class Evaluation>
210 const Evaluation& pressure,
211 const Evaluation& Rs)
const
214 return inverseOilBTable_[regionIdx].eval(Rs, pressure,
true);
220 template <
class Evaluation>
223 const Evaluation& pressure)
const
226 return inverseSaturatedOilBTable_[regionIdx].eval(pressure,
true);
232 template <
class Evaluation>
235 const Evaluation& pressure)
const
236 {
return saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure,
true); }
245 template <
class Evaluation>
248 const Evaluation& pressure,
249 const Evaluation& oilSaturation,
250 Evaluation maxOilSaturation)
const
253 saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure,
true);
257 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
258 if (vapPar2_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
259 constexpr const Scalar eps = 0.001;
260 const Evaluation& So = max(oilSaturation, eps);
261 tmp *= max(1e-3, pow(So / maxOilSaturation, vapPar2_));
273 template <
class Evaluation>
276 const Evaluation& Rs)
const
280 const auto& RsTable = saturatedGasDissolutionFactorTable_[regionIdx];
281 constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
284 Evaluation pSat = saturationPressure_[regionIdx].eval(Rs,
true);
289 bool onProbation =
false;
290 for (
int i = 0; i < 20; ++i) {
291 const Evaluation& f = RsTable.eval(pSat,
true) - Rs;
292 const Evaluation& fPrime = RsTable.evalDerivative(pSat,
true);
296 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
300 const Evaluation& delta = f / fPrime;
315 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
320 const std::string msg =
321 "Finding saturation pressure did not converge: "
322 " pSat = " + std::to_string(getValue(pSat)) +
323 ", Rs = " + std::to_string(getValue(Rs));
324 OpmLog::debug(
"Live oil saturation pressure", msg);
328 template <
class Evaluation>
329 Evaluation diffusionCoefficient(
const Evaluation& ,
333 throw std::runtime_error(
"Not implemented: The PVT model does not provide "
334 "a diffusionCoefficient()");
337 Scalar gasReferenceDensity(
unsigned regionIdx)
const
338 {
return gasReferenceDensity_[regionIdx]; }
340 Scalar oilReferenceDensity(
unsigned regionIdx)
const
341 {
return oilReferenceDensity_[regionIdx]; }
343 const std::vector<TabulatedTwoDFunction>& inverseOilBTable()
const
344 {
return inverseOilBTable_; }
346 const std::vector<TabulatedTwoDFunction>& oilMuTable()
const
347 {
return oilMuTable_; }
349 const std::vector<TabulatedTwoDFunction>& inverseOilBMuTable()
const
350 {
return inverseOilBMuTable_; }
352 const std::vector<TabulatedOneDFunction>& saturatedOilMuTable()
const
353 {
return saturatedOilMuTable_; }
355 const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBTable()
const
356 {
return inverseSaturatedOilBTable_; }
358 const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBMuTable()
const
359 {
return inverseSaturatedOilBMuTable_; }
361 const std::vector<TabulatedOneDFunction>& saturatedGasDissolutionFactorTable()
const
362 {
return saturatedGasDissolutionFactorTable_; }
365 {
return saturationPressure_; }
367 Scalar vapPar2()
const
371 void updateSaturationPressure_(
unsigned regionIdx);
373 std::vector<Scalar> gasReferenceDensity_{};
374 std::vector<Scalar> oilReferenceDensity_{};
375 std::vector<TabulatedTwoDFunction> inverseOilBTable_{};
376 std::vector<TabulatedTwoDFunction> oilMuTable_{};
377 std::vector<TabulatedTwoDFunction> inverseOilBMuTable_{};
378 std::vector<TabulatedOneDFunction> saturatedOilMuTable_{};
379 std::vector<TabulatedOneDFunction> inverseSaturatedOilBTable_{};
380 std::vector<TabulatedOneDFunction> inverseSaturatedOilBMuTable_{};
381 std::vector<TabulatedOneDFunction> saturatedGasDissolutionFactorTable_{};
382 std::vector<TabulatedOneDFunction> saturationPressure_{};
384 Scalar vapPar2_ = 0.0;
Provides the OPM specific exception classes.
Implements a linearly interpolated scalar function that depends on one variable.
Definition EclipseState.hpp:63
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:158
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:208
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:246
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of the fluid phase.
Definition LiveOilPvt.hpp:221
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:274
void setSaturatedOilGasDissolutionFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the gas dissolution factor .
Definition LiveOilPvt.hpp:93
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:177
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:130
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:233
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:193
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition LiveOilPvt.hpp:151
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:121
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