Loading...
Searching...
No Matches
LiveOilPvt.hpp
Go to the documentation of this file.
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#ifndef OPM_LIVE_OIL_PVT_HPP
#define OPM_LIVE_OIL_PVT_HPP
#include <opm/common/Exceptions.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/material/common/MathToolbox.hpp>
#include <opm/material/common/UniformXTabulated2DFunction.hpp>
#include <opm/material/common/Tabulated1DFunction.hpp>
namespace Opm {
#if HAVE_ECL_INPUT
class EclipseState;
class Schedule;
class SimpleTable;
#endif
template <class Scalar>
class LiveOilPvt
{
using SamplingPoints = std::vector<std::pair<Scalar, Scalar>>;
public:
using TabulatedTwoDFunction = UniformXTabulated2DFunction<Scalar>;
using TabulatedOneDFunction = Tabulated1DFunction<Scalar>;
#if HAVE_ECL_INPUT
void initFromState(const EclipseState& eclState, const Schedule& schedule);
private:
void extendPvtoTable_(unsigned regionIdx,
unsigned xIdx,
const SimpleTable& curTable,
const SimpleTable& masterTable);
public:
#endif // HAVE_ECL_INPUT
void setNumRegions(size_t numRegions);
void setVapPars(const Scalar, const Scalar par2)
{
vapPar2_ = par2;
}
void setReferenceDensities(unsigned regionIdx,
Scalar rhoRefOil,
Scalar rhoRefGas,
Scalar /*rhoRefWater*/);
void setSaturatedOilGasDissolutionFactor(unsigned regionIdx,
const SamplingPoints& samplePoints)
{ saturatedGasDissolutionFactorTable_[regionIdx].setContainerOfTuples(samplePoints); }
void setSaturatedOilFormationVolumeFactor(unsigned regionIdx,
const SamplingPoints& samplePoints);
void setInverseOilFormationVolumeFactor(unsigned regionIdx,
const TabulatedTwoDFunction& invBo)
{ inverseOilBTable_[regionIdx] = invBo; }
void setOilViscosity(unsigned regionIdx, const TabulatedTwoDFunction& muo)
{ oilMuTable_[regionIdx] = muo; }
void setSaturatedOilViscosity(unsigned regionIdx,
const SamplingPoints& samplePoints);
void initEnd();
unsigned numRegions() const
{ return inverseOilBMuTable_.size(); }
template <class Evaluation>
Evaluation internalEnergy(unsigned,
const Evaluation&,
const Evaluation&,
const Evaluation&) const
{
throw std::runtime_error("Requested the enthalpy of oil but the thermal "
"option is not enabled");
}
Scalar hVap(unsigned) const
{
throw std::runtime_error("Requested the hvap of oil but the thermal "
"option is not enabled");
}
template <class Evaluation>
Evaluation viscosity(unsigned regionIdx,
const Evaluation& /*temperature*/,
const Evaluation& pressure,
const Evaluation& Rs) const
{
// ATTENTION: Rs is the first axis!
const Evaluation& invBo = inverseOilBTable_[regionIdx].eval(Rs, pressure, /*extrapolate=*/true);
const Evaluation& invMuoBo = inverseOilBMuTable_[regionIdx].eval(Rs, pressure, /*extrapolate=*/true);
return invBo / invMuoBo;
}
template <class Evaluation>
Evaluation saturatedViscosity(unsigned regionIdx,
const Evaluation& /*temperature*/,
const Evaluation& pressure) const
{
// ATTENTION: Rs is the first axis!
const Evaluation& invBo = inverseSaturatedOilBTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
const Evaluation& invMuoBo = inverseSaturatedOilBMuTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
return invBo / invMuoBo;
}
template <class Evaluation>
Evaluation inverseFormationVolumeFactor(unsigned regionIdx,
const Evaluation& /*temperature*/,
const Evaluation& pressure,
const Evaluation& Rs) const
{
// ATTENTION: Rs is represented by the _first_ axis!
return inverseOilBTable_[regionIdx].eval(Rs, pressure, /*extrapolate=*/true);
}
template <class FluidState, class LhsEval = typename FluidState::Scalar>
std::pair<LhsEval, LhsEval>
inverseFormationVolumeFactorAndViscosity(const FluidState& fluidState, unsigned regionIdx)
{
const LhsEval& p = decay<LhsEval>(fluidState.pressure(FluidState::oilPhaseIdx));
const LhsEval& Rs = decay<LhsEval>(fluidState.Rs());
const auto satSegIdx = this->saturatedGasDissolutionFactorTable_[regionIdx].findSegmentIndex(p, /*extrapolate=*/ true);
const auto RsSat = this->saturatedGasDissolutionFactorTable_[regionIdx].eval(p, SegmentIndex{satSegIdx});
const bool useSaturatedTables = (fluidState.saturation(FluidState::gasPhaseIdx) > 0.0) && (Rs >= (1.0 - 1e-10) * RsSat);
if (useSaturatedTables) {
const LhsEval b = this->inverseSaturatedOilBTable_[regionIdx].eval(p, SegmentIndex{satSegIdx});
const LhsEval invBMu = this->inverseSaturatedOilBMuTable_[regionIdx].eval(p, SegmentIndex{satSegIdx});
const LhsEval mu = b / invBMu;
return { b, mu };
} else {
unsigned ii, jj1, jj2;
LhsEval alpha, beta1, beta2;
this->inverseOilBTable_[regionIdx].findPoints(ii, jj1, jj2, alpha, beta1, beta2, Rs, p, /*extrapolate =*/ true);
const LhsEval b = this->inverseOilBTable_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
const LhsEval invBMu = this->inverseOilBMuTable_[regionIdx].eval(ii, jj1, jj2, alpha, beta1, beta2);
const LhsEval mu = b / invBMu;
return { b, mu };
}
}
template <class Evaluation>
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx,
const Evaluation& /*temperature*/,
const Evaluation& pressure) const
{
// ATTENTION: Rs is represented by the _first_ axis!
return inverseSaturatedOilBTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
}
template <class Evaluation>
Evaluation saturatedGasDissolutionFactor(unsigned regionIdx,
const Evaluation& /*temperature*/,
const Evaluation& pressure) const
{ return saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true); }
template <class Evaluation>
Evaluation saturatedGasDissolutionFactor(unsigned regionIdx,
const Evaluation& /*temperature*/,
const Evaluation& pressure,
const Evaluation& oilSaturation,
Evaluation maxOilSaturation) const
{
Evaluation tmp =
saturatedGasDissolutionFactorTable_[regionIdx].eval(pressure, /*extrapolate=*/true);
// apply the vaporization parameters for the gas phase (cf. the Eclipse VAPPARS
// keyword)
maxOilSaturation = min(maxOilSaturation, Scalar(1.0));
if (vapPar2_ > 0.0 && maxOilSaturation > 0.01 && oilSaturation < maxOilSaturation) {
constexpr const Scalar eps = 0.001;
const Evaluation& So = max(oilSaturation, eps);
tmp *= max(1e-3, pow(So / maxOilSaturation, vapPar2_));
}
return tmp;
}
template <class Evaluation>
Evaluation saturationPressure(unsigned regionIdx,
const Evaluation&,
const Evaluation& Rs) const
{
using Toolbox = MathToolbox<Evaluation>;
const auto& RsTable = saturatedGasDissolutionFactorTable_[regionIdx];
constexpr const Scalar eps = std::numeric_limits<typename Toolbox::Scalar>::epsilon() * 1e6;
// use the saturation pressure function to get a pretty good initial value
Evaluation pSat = saturationPressure_[regionIdx].eval(Rs, /*extrapolate=*/true);
// Newton method to do the remaining work. If the initial
// value is good, this should only take two to three
// iterations...
bool onProbation = false;
for (int i = 0; i < 20; ++i) {
const Evaluation& f = RsTable.eval(pSat, /*extrapolate=*/true) - Rs;
const Evaluation& fPrime = RsTable.evalDerivative(pSat, /*extrapolate=*/true);
// If the derivative is "zero" Newton will not converge,
// so simply return our initial guess.
if (std::abs(scalarValue(fPrime)) < 1.0e-30) {
return pSat;
}
const Evaluation& delta = f / fPrime;
pSat -= delta;
if (pSat < 0.0) {
// if the pressure is lower than 0 Pascals, we set it back to 0. if this
// happens twice, we give up and just return 0 Pa...
if (onProbation) {
return 0.0;
}
onProbation = true;
pSat = 0.0;
}
if (std::abs(scalarValue(delta)) < std::abs(scalarValue(pSat))*eps) {
return pSat;
}
}
const std::string msg =
"Finding saturation pressure did not converge: "
" pSat = " + std::to_string(getValue(pSat)) +
", Rs = " + std::to_string(getValue(Rs));
OpmLog::debug("Live oil saturation pressure", msg);
throw NumericalProblem(msg);
}
template <class Evaluation>
Evaluation diffusionCoefficient(const Evaluation& /*temperature*/,
const Evaluation& /*pressure*/,
unsigned /*compIdx*/) const
{
throw std::runtime_error("Not implemented: The PVT model does not provide "
"a diffusionCoefficient()");
}
Scalar gasReferenceDensity(unsigned regionIdx) const
{ return gasReferenceDensity_[regionIdx]; }
Scalar oilReferenceDensity(unsigned regionIdx) const
{ return oilReferenceDensity_[regionIdx]; }
const std::vector<TabulatedTwoDFunction>& inverseOilBTable() const
{ return inverseOilBTable_; }
const std::vector<TabulatedTwoDFunction>& oilMuTable() const
{ return oilMuTable_; }
const std::vector<TabulatedTwoDFunction>& inverseOilBMuTable() const
{ return inverseOilBMuTable_; }
const std::vector<TabulatedOneDFunction>& saturatedOilMuTable() const
{ return saturatedOilMuTable_; }
const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBTable() const
{ return inverseSaturatedOilBTable_; }
const std::vector<TabulatedOneDFunction>& inverseSaturatedOilBMuTable() const
{ return inverseSaturatedOilBMuTable_; }
const std::vector<TabulatedOneDFunction>& saturatedGasDissolutionFactorTable() const
{ return saturatedGasDissolutionFactorTable_; }
const std::vector<TabulatedOneDFunction>& saturationPressure() const
{ return saturationPressure_; }
Scalar vapPar2() const
{ return vapPar2_; }
private:
void updateSaturationPressure_(unsigned regionIdx);
std::vector<Scalar> gasReferenceDensity_{};
std::vector<Scalar> oilReferenceDensity_{};
std::vector<TabulatedTwoDFunction> inverseOilBTable_{};
std::vector<TabulatedTwoDFunction> oilMuTable_{};
std::vector<TabulatedTwoDFunction> inverseOilBMuTable_{};
std::vector<TabulatedOneDFunction> saturatedOilMuTable_{};
std::vector<TabulatedOneDFunction> inverseSaturatedOilBTable_{};
std::vector<TabulatedOneDFunction> inverseSaturatedOilBMuTable_{};
std::vector<TabulatedOneDFunction> saturatedGasDissolutionFactorTable_{};
std::vector<TabulatedOneDFunction> saturationPressure_{};
Scalar vapPar2_ = 0.0;
};
} // namespace Opm
#endif
Exceptions.hpp
Provides the OPM specific exception classes.
MathToolbox.hpp
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
Tabulated1DFunction.hpp
Implements a linearly interpolated scalar function that depends on one variable.
UniformXTabulated2DFunction.hpp
Implements a scalar function that depends on two variables and which is sampled uniformly in the X di...
Opm::EclipseState
Definition EclipseState.hpp:62
Opm::LiveOilPvt
This class represents the Pressure-Volume-Temperature relations of the oil phas with dissolved gas.
Definition LiveOilPvt.hpp:51
Opm::LiveOilPvt::internalEnergy
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
Opm::LiveOilPvt::setSaturatedOilFormationVolumeFactor
void setSaturatedOilFormationVolumeFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the oil formation volume factor.
Definition LiveOilPvt.cpp:246
Opm::LiveOilPvt::inverseFormationVolumeFactor
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
Opm::LiveOilPvt::saturatedGasDissolutionFactor
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
Opm::LiveOilPvt::saturatedInverseFormationVolumeFactor
Evaluation saturatedInverseFormationVolumeFactor(unsigned regionIdx, const Evaluation &, const Evaluation &pressure) const
Returns the formation volume factor [-] of the fluid phase.
Definition LiveOilPvt.hpp:252
Opm::LiveOilPvt::setSaturatedOilViscosity
void setSaturatedOilViscosity(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the phase viscosity for gas saturated oil.
Definition LiveOilPvt.cpp:273
Opm::LiveOilPvt::saturationPressure
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
Opm::LiveOilPvt::setSaturatedOilGasDissolutionFactor
void setSaturatedOilGasDissolutionFactor(unsigned regionIdx, const SamplingPoints &samplePoints)
Initialize the function for the gas dissolution factor .
Definition LiveOilPvt.hpp:94
Opm::LiveOilPvt::viscosity
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
Opm::LiveOilPvt::setReferenceDensities
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
Opm::LiveOilPvt::setOilViscosity
void setOilViscosity(unsigned regionIdx, const TabulatedTwoDFunction &muo)
Initialize the viscosity of the oil phase.
Definition LiveOilPvt.hpp:131
Opm::LiveOilPvt::saturatedGasDissolutionFactor
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
Opm::LiveOilPvt::saturatedViscosity
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
Opm::LiveOilPvt::numRegions
unsigned numRegions() const
Return the number of PVT regions which are considered by this PVT-object.
Definition LiveOilPvt.hpp:152
Opm::LiveOilPvt::inverseFormationVolumeFactorAndViscosity
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
Opm::LiveOilPvt::initEnd
void initEnd()
Finish initializing the oil phase PVT properties.
Definition LiveOilPvt.cpp:300
Opm::LiveOilPvt::setInverseOilFormationVolumeFactor
void setInverseOilFormationVolumeFactor(unsigned regionIdx, const TabulatedTwoDFunction &invBo)
Initialize the function for the oil formation volume factor.
Definition LiveOilPvt.hpp:122
Opm::NumericalProblem
Definition Exceptions.hpp:40
Opm::Schedule
Definition Schedule.hpp:101
Opm::SimpleTable
Definition SimpleTable.hpp:35
Opm::Tabulated1DFunction
Implements a linearly interpolated scalar function that depends on one variable.
Definition Tabulated1DFunction.hpp:51
Opm::UniformXTabulated2DFunction
Implements a scalar function that depends on two variables and which is sampled uniformly in the X di...
Definition UniformXTabulated2DFunction.hpp:55
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Opm::MathToolbox
Definition MathToolbox.hpp:51
Opm::SegmentIndex
Definition Tabulated1DFunction.hpp:41