27 #ifndef OPM_LIVE_OIL_PVT_HPP 28 #define OPM_LIVE_OIL_PVT_HPP 31 #include <opm/common/OpmLog/OpmLog.hpp> 47 template <
class Scalar>
50 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
62 void extendPvtoTable_(
unsigned regionIdx,
70 void setVapPars(
const Scalar,
const Scalar par2)
90 const SamplingPoints& samplePoints)
91 { saturatedGasDissolutionFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
103 const SamplingPoints& samplePoints);
119 { inverseOilBTable_[regionIdx] = invBo; }
127 { oilMuTable_[regionIdx] = muo; }
137 const SamplingPoints& samplePoints);
148 {
return inverseOilBMuTable_.size(); }
153 template <
class Evaluation>
157 const Evaluation&)
const 159 throw std::runtime_error(
"Requested the enthalpy of oil but the thermal " 160 "option is not enabled");
163 Scalar hVap(
unsigned)
const 165 throw std::runtime_error(
"Requested the hvap of oil but the thermal " 166 "option is not enabled");
172 template <
class Evaluation>
175 const Evaluation& pressure,
176 const Evaluation& Rs)
const 179 const Evaluation& invBo = inverseOilBTable_[regionIdx].eval(Rs, pressure,
true);
180 const Evaluation& invMuoBo = inverseOilBMuTable_[regionIdx].eval(Rs, pressure,
true);
182 return invBo / invMuoBo;
188 template <
class Evaluation>
191 const Evaluation& pressure)
const 194 const Evaluation& invBo = inverseSaturatedOilBTable_[regionIdx].eval(pressure,
true);
195 const Evaluation& invMuoBo = inverseSaturatedOilBMuTable_[regionIdx].eval(pressure,
true);
197 return invBo / invMuoBo;
203 template <
class Evaluation>
206 const Evaluation& pressure,
207 const Evaluation& Rs)
const 210 return inverseOilBTable_[regionIdx].eval(Rs, pressure,
true);
216 template <
class Flu
idState,
class LhsEval =
typename Flu
idState::ValueType>
217 std::pair<LhsEval, LhsEval>
220 const LhsEval& p = decay<LhsEval>(fluidState.pressure(FluidState::oilPhaseIdx));
221 const LhsEval& Rs = decay<LhsEval>(fluidState.Rs());
223 const auto satSegIdx = this->saturatedGasDissolutionFactorTable_[regionIdx].findSegmentIndex(p,
true);
224 const auto RsSat = this->saturatedGasDissolutionFactorTable_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
225 const bool useSaturatedTables = (fluidState.saturation(FluidState::gasPhaseIdx) > 0.0) && (Rs >= (1.0 - 1e-10) * RsSat);
227 if (useSaturatedTables) {
228 const LhsEval b = this->inverseSaturatedOilBTable_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
229 const LhsEval invBMu = this->inverseSaturatedOilBMuTable_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
230 const LhsEval mu = b / invBMu;
233 unsigned ii, jj1, jj2;
234 LhsEval alpha, beta1, beta2;
235 this->inverseOilBTable_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, Rs, p,
true);
236 const LhsEval b = this->inverseOilBTable_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
237 const LhsEval invBMu = this->inverseOilBMuTable_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
238 const LhsEval mu = b / invBMu;
246 template <
class Evaluation>
249 const Evaluation& pressure)
const 252 return inverseSaturatedOilBTable_[regionIdx].eval(pressure,
true);
258 template <
class Evaluation>
261 const Evaluation& pressure)
const 262 {
return saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure,
true); }
271 template <
class Evaluation>
274 const Evaluation& pressure,
275 const Evaluation& oilSaturation,
276 Evaluation maxOilSaturation)
const 279 saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure,
true);
283 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
284 if (vapPar2_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
285 constexpr
const Scalar eps = 0.001;
286 const Evaluation& So = max(oilSaturation, eps);
287 tmp *= max(1e-3, pow(So / maxOilSaturation, vapPar2_));
300 template <
class Evaluation>
303 const Evaluation& Rs)
const 307 const auto& RsTable = saturatedGasDissolutionFactorTable_[regionIdx];
308 constexpr
const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
311 Evaluation pSat = saturationPressure_[regionIdx].eval(Rs,
true);
316 bool onProbation =
false;
317 for (
int i = 0; i < 20; ++i) {
318 const Evaluation& f = RsTable.eval(pSat,
true) - Rs;
319 const Evaluation& fPrime = RsTable.evalDerivative(pSat,
true);
323 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
327 const Evaluation& delta = f / fPrime;
342 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
347 const std::string msg =
348 "Finding saturation pressure did not converge: " 349 " pSat = " + std::to_string(getValue(pSat)) +
350 ", Rs = " + std::to_string(getValue(Rs));
351 OpmLog::debug(
"Live oil saturation pressure", msg);
355 template <
class Evaluation>
356 Evaluation diffusionCoefficient(
const Evaluation& ,
360 throw std::runtime_error(
"Not implemented: The PVT model does not provide " 361 "a diffusionCoefficient()");
364 Scalar gasReferenceDensity(
unsigned regionIdx)
const 365 {
return gasReferenceDensity_[regionIdx]; }
367 Scalar oilReferenceDensity(
unsigned regionIdx)
const 368 {
return oilReferenceDensity_[regionIdx]; }
370 const std::vector<TabulatedTwoDFunction>& inverseOilBTable()
const 371 {
return inverseOilBTable_; }
373 const std::vector<TabulatedTwoDFunction>& oilMuTable()
const 374 {
return oilMuTable_; }
376 const std::vector<TabulatedTwoDFunction>& inverseOilBMuTable()
const 377 {
return inverseOilBMuTable_; }
379 const std::vector<TabulatedOneDFunction>& saturatedOilMuTable()
const 380 {
return saturatedOilMuTable_; }
382 const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBTable()
const 383 {
return inverseSaturatedOilBTable_; }
385 const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBMuTable()
const 386 {
return inverseSaturatedOilBMuTable_; }
388 const std::vector<TabulatedOneDFunction>& saturatedGasDissolutionFactorTable()
const 389 {
return saturatedGasDissolutionFactorTable_; }
392 {
return saturationPressure_; }
394 Scalar vapPar2()
const 398 void updateSaturationPressure_(
unsigned regionIdx);
400 std::vector<Scalar> gasReferenceDensity_{};
401 std::vector<Scalar> oilReferenceDensity_{};
402 std::vector<TabulatedTwoDFunction> inverseOilBTable_{};
403 std::vector<TabulatedTwoDFunction> oilMuTable_{};
404 std::vector<TabulatedTwoDFunction> inverseOilBMuTable_{};
405 std::vector<TabulatedOneDFunction> saturatedOilMuTable_{};
406 std::vector<TabulatedOneDFunction> inverseSaturatedOilBTable_{};
407 std::vector<TabulatedOneDFunction> inverseSaturatedOilBMuTable_{};
408 std::vector<TabulatedOneDFunction> saturatedGasDissolutionFactorTable_{};
409 std::vector<TabulatedOneDFunction> saturationPressure_{};
411 Scalar vapPar2_ = 0.0;
void initFromState(const EclipseState &eclState, const Schedule &schedule)
Initialize the oil parameters via the data specified by the PVTO ECL keyword.
Definition: LiveOilPvt.cpp:40
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:301
Definition: Exceptions.hpp:39
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:173
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of the fluid phase.
Definition: LiveOilPvt.hpp:247
Definition: Schedule.hpp:100
Provides the OPM specific exception classes.
void setOilViscosity(unsigned regionIdx, const TabulatedTwoDFunction &muo)
Initialize the viscosity of the oil phase.
Definition: LiveOilPvt.hpp:126
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:218
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: LiveOilPvt.hpp:147
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:204
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
void initEnd()
Finish initializing the oil phase PVT properties.
Definition: LiveOilPvt.cpp:296
Definition: EclipseState.hpp:66
Definition: SimpleTable.hpp:35
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:154
This class represents the Pressure-Volume-Temperature relations of the oil phas with dissolved gas...
Definition: LiveOilPvt.hpp:48
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:259
void setReferenceDensities(unsigned regionIdx, Scalar rhoRefOil, Scalar rhoRefGas, Scalar)
Initialize the reference densities of all fluids for a given PVT region.
Definition: LiveOilPvt.cpp:231
void setSaturatedOilViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for gas saturated oil.
Definition: LiveOilPvt.cpp:269
void setSaturatedOilFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil formation volume factor.
Definition: LiveOilPvt.cpp:242
void setSaturatedOilGasDissolutionFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the gas dissolution factor .
Definition: LiveOilPvt.hpp:89
void setInverseOilFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBo)
Initialize the function for the oil formation volume factor.
Definition: LiveOilPvt.hpp:117
Implements a linearly interpolated scalar function that depends on one variable.
Implements a linearly interpolated scalar function that depends on one variable.
Definition: Tabulated1DFunction.hpp:50
Definition: Tabulated1DFunction.hpp:41
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:272
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:189