27 #ifndef OPM_LIVE_OIL_PVT_HPP 28 #define OPM_LIVE_OIL_PVT_HPP 31 #include <opm/common/OpmLog/OpmLog.hpp> 49 template <
class Scalar>
52 using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
64 void extendPvtoTable_(
unsigned regionIdx,
72 void setVapPars(
const Scalar,
const Scalar par2)
92 const SamplingPoints& samplePoints)
93 { saturatedGasDissolutionFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
105 const SamplingPoints& samplePoints);
121 { inverseOilBTable_[regionIdx] = invBo; }
129 { oilMuTable_[regionIdx] = muo; }
139 const SamplingPoints& samplePoints);
150 {
return inverseOilBMuTable_.size(); }
155 template <
class Evaluation>
159 const Evaluation&)
const 161 throw std::runtime_error(
"Requested the enthalpy of oil but the thermal " 162 "option is not enabled");
165 Scalar hVap(
unsigned)
const 167 throw std::runtime_error(
"Requested the hvap of oil but the thermal " 168 "option is not enabled");
174 template <
class Evaluation>
177 const Evaluation& pressure,
178 const Evaluation& Rs)
const 181 const Evaluation& invBo = inverseOilBTable_[regionIdx].eval(Rs, pressure,
true);
182 const Evaluation& invMuoBo = inverseOilBMuTable_[regionIdx].eval(Rs, pressure,
true);
184 return invBo / invMuoBo;
190 template <
class Evaluation>
193 const Evaluation& pressure)
const 196 const Evaluation& invBo = inverseSaturatedOilBTable_[regionIdx].eval(pressure,
true);
197 const Evaluation& invMuoBo = inverseSaturatedOilBMuTable_[regionIdx].eval(pressure,
true);
199 return invBo / invMuoBo;
205 template <
class Evaluation>
208 const Evaluation& pressure,
209 const Evaluation& Rs)
const 212 return inverseOilBTable_[regionIdx].eval(Rs, pressure,
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::oilPhaseIdx));
223 const LhsEval& Rs = decay<LhsEval>(fluidState.Rs());
225 const auto satSegIdx = this->saturatedGasDissolutionFactorTable_[regionIdx].findSegmentIndex(p,
true);
226 const auto RsSat = this->saturatedGasDissolutionFactorTable_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
227 const bool useSaturatedTables = (fluidState.saturation(FluidState::gasPhaseIdx) > 0.0) && (Rs >= (1.0 - 1e-10) * RsSat);
229 if (useSaturatedTables) {
230 const LhsEval b = this->inverseSaturatedOilBTable_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
231 const LhsEval invBMu = this->inverseSaturatedOilBMuTable_[regionIdx].eval(p,
SegmentIndex{satSegIdx});
232 const LhsEval mu = b / invBMu;
235 unsigned ii, jj1, jj2;
236 LhsEval alpha, beta1, beta2;
237 this->inverseOilBTable_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, Rs, p,
true);
238 const LhsEval b = this->inverseOilBTable_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
239 const LhsEval invBMu = this->inverseOilBMuTable_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
240 const LhsEval mu = b / invBMu;
248 template <
class Evaluation>
251 const Evaluation& pressure)
const 254 return inverseSaturatedOilBTable_[regionIdx].eval(pressure,
true);
260 template <
class Evaluation>
263 const Evaluation& pressure)
const 264 {
return saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure,
true); }
273 template <
class Evaluation>
276 const Evaluation& pressure,
277 const Evaluation& oilSaturation,
278 Evaluation maxOilSaturation)
const 281 saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure,
true);
285 maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
286 if (vapPar2_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
287 constexpr
const Scalar eps = 0.001;
288 const Evaluation& So = max(oilSaturation, eps);
289 tmp *= max(1e-3, pow(So / maxOilSaturation, vapPar2_));
302 template <
class Evaluation>
305 const Evaluation& Rs)
const 309 const auto& RsTable = saturatedGasDissolutionFactorTable_[regionIdx];
310 constexpr
const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
313 Evaluation pSat = saturationPressure_[regionIdx].eval(Rs,
true);
318 bool onProbation =
false;
319 for (
int i = 0; i < 20; ++i) {
320 const Evaluation& f = RsTable.eval(pSat,
true) - Rs;
321 const Evaluation& fPrime = RsTable.evalDerivative(pSat,
true);
325 if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
329 const Evaluation& delta = f / fPrime;
344 if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
349 const std::string msg =
350 "Finding saturation pressure did not converge: " 351 " pSat = " + std::to_string(getValue(pSat)) +
352 ", Rs = " + std::to_string(getValue(Rs));
353 OpmLog::debug(
"Live oil saturation pressure", msg);
357 template <
class Evaluation>
358 Evaluation diffusionCoefficient(
const Evaluation& ,
362 throw std::runtime_error(
"Not implemented: The PVT model does not provide " 363 "a diffusionCoefficient()");
366 Scalar gasReferenceDensity(
unsigned regionIdx)
const 367 {
return gasReferenceDensity_[regionIdx]; }
369 Scalar oilReferenceDensity(
unsigned regionIdx)
const 370 {
return oilReferenceDensity_[regionIdx]; }
372 const std::vector<TabulatedTwoDFunction>& inverseOilBTable()
const 373 {
return inverseOilBTable_; }
375 const std::vector<TabulatedTwoDFunction>& oilMuTable()
const 376 {
return oilMuTable_; }
378 const std::vector<TabulatedTwoDFunction>& inverseOilBMuTable()
const 379 {
return inverseOilBMuTable_; }
381 const std::vector<TabulatedOneDFunction>& saturatedOilMuTable()
const 382 {
return saturatedOilMuTable_; }
384 const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBTable()
const 385 {
return inverseSaturatedOilBTable_; }
387 const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBMuTable()
const 388 {
return inverseSaturatedOilBMuTable_; }
390 const std::vector<TabulatedOneDFunction>& saturatedGasDissolutionFactorTable()
const 391 {
return saturatedGasDissolutionFactorTable_; }
394 {
return saturationPressure_; }
396 Scalar vapPar2()
const 400 void updateSaturationPressure_(
unsigned regionIdx);
402 std::vector<Scalar> gasReferenceDensity_{};
403 std::vector<Scalar> oilReferenceDensity_{};
404 std::vector<TabulatedTwoDFunction> inverseOilBTable_{};
405 std::vector<TabulatedTwoDFunction> oilMuTable_{};
406 std::vector<TabulatedTwoDFunction> inverseOilBMuTable_{};
407 std::vector<TabulatedOneDFunction> saturatedOilMuTable_{};
408 std::vector<TabulatedOneDFunction> inverseSaturatedOilBTable_{};
409 std::vector<TabulatedOneDFunction> inverseSaturatedOilBMuTable_{};
410 std::vector<TabulatedOneDFunction> saturatedGasDissolutionFactorTable_{};
411 std::vector<TabulatedOneDFunction> saturationPressure_{};
413 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:303
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:175
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of the fluid phase.
Definition: LiveOilPvt.hpp:249
Definition: Schedule.hpp:102
Provides the OPM specific exception classes.
void setOilViscosity(unsigned regionIdx, const TabulatedTwoDFunction &muo)
Initialize the viscosity of the oil phase.
Definition: LiveOilPvt.hpp:128
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:220
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition: LiveOilPvt.hpp:149
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:206
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:36
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:156
This class represents the Pressure-Volume-Temperature relations of the oil phas with dissolved gas...
Definition: LiveOilPvt.hpp:50
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:261
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:91
void setInverseOilFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBo)
Initialize the function for the oil formation volume factor.
Definition: LiveOilPvt.hpp:119
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:51
Definition: Tabulated1DFunction.hpp:42
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:274
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:191