Skip to content

Commit

Permalink
Add option to not use saturated tables
Browse files Browse the repository at this point in the history
For co2storage and h2storage we dont have a concept of tables and should not spend time on
checking if we are at the saturated front
  • Loading branch information
Tor Harald Sandve committed Jun 26, 2024
1 parent 870f45d commit 7f37b16
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
8 changes: 8 additions & 0 deletions opm/material/fluidsystems/BlackOilFluidSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ initFromState(const EclipseState& eclState, const Schedule& schedule)
}
}

// For co2storage and h2storage we dont have a concept of tables and should not spend time on
// checking if we are at the saturated front
setUseSaturatedTables(!(eclState.runspec().h2Storage() || eclState.runspec().co2Storage()));

setEnableDiffusion(eclState.getSimulationConfig().isDiffusive());
if (enableDiffusion()) {
const auto& diffCoeffTables = eclState.getTableManager().getDiffusionCoefficientTable();
Expand Down Expand Up @@ -220,6 +224,7 @@ void BlackOilFluidSystem<Scalar,IndexTraits>::
initBegin(std::size_t numPvtRegions)
{
isInitialized_ = false;
useSaturatedTables_ = true;

enableDissolvedGas_ = true;
enableDissolvedGasInWater_ = false;
Expand Down Expand Up @@ -450,6 +455,9 @@ template <> std::vector<std::array<float, 9>> BlackOilFluidSystem<float, BlackOi
template <> bool BlackOilFluidSystem<double, BlackOilDefaultIndexTraits>::isInitialized_ = false;
template <> bool BlackOilFluidSystem<float, BlackOilDefaultIndexTraits>::isInitialized_ = false;

template <> bool BlackOilFluidSystem<double, BlackOilDefaultIndexTraits>::useSaturatedTables_ = false;
template <> bool BlackOilFluidSystem<float, BlackOilDefaultIndexTraits>::useSaturatedTables_ = false;

// IMPORTANT: The following two lines must come after the template specializations above
// or else the static variable above will appear as undefined in the generated object file.
template class BlackOilFluidSystem<double,BlackOilDefaultIndexTraits>;
Expand Down
42 changes: 30 additions & 12 deletions opm/material/fluidsystems/BlackOilFluidSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
static void setEnableDiffusion(bool yesno)
{ enableDiffusion_ = yesno; }

/*!
* \brief Specify whether the saturated tables should be used
*
* By default, saturated tables are used
*/
static void setUseSaturatedTables(bool yesno)
{ useSaturatedTables_ = yesno; }

/*!
* \brief Set the pressure-volume-saturation (PVT) relations for the gas phase.
Expand Down Expand Up @@ -486,6 +493,14 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
static bool enableDiffusion()
{ return enableDiffusion_; }

/*!
* \brief Returns whether the saturated tables should be used
*
* By default, saturated tables are used. If false the unsaturated tables are extrapolated
*/
static bool useSaturatedTables()
{ return useSaturatedTables_; }

/*!
* \brief Returns the density of a fluid phase at surface pressure [kg/m^3]
*
Expand Down Expand Up @@ -751,7 +766,7 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
case oilPhaseIdx: {
if (enableDissolvedGas()) {
const auto& Rs = BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
if (fluidState.saturation(gasPhaseIdx) > 0.0
if (useSaturatedTables() && fluidState.saturation(gasPhaseIdx) > 0.0
&& Rs >= (1.0 - 1e-10)*oilPvt_->saturatedGasDissolutionFactor(regionIdx, scalarValue(T), scalarValue(p)))
{
return oilPvt_->saturatedInverseFormationVolumeFactor(regionIdx, T, p);
Expand All @@ -767,20 +782,20 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
if (enableVaporizedOil() && enableVaporizedWater()) {
const auto& Rvw = BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
const auto& Rv = BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
if (fluidState.saturation(waterPhaseIdx) > 0.0
if (useSaturatedTables() && fluidState.saturation(waterPhaseIdx) > 0.0
&& Rvw >= (1.0 - 1e-10)*gasPvt_->saturatedWaterVaporizationFactor(regionIdx, scalarValue(T), scalarValue(p))
&& fluidState.saturation(oilPhaseIdx) > 0.0
&& Rv >= (1.0 - 1e-10)*gasPvt_->saturatedOilVaporizationFactor(regionIdx, scalarValue(T), scalarValue(p)))
{
return gasPvt_->saturatedInverseFormationVolumeFactor(regionIdx, T, p);
} else {
return gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv, Rvw);
return gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv, Rvw);
}
}

if (enableVaporizedOil()) {
const auto& Rv = BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
if (fluidState.saturation(oilPhaseIdx) > 0.0
if (useSaturatedTables() && fluidState.saturation(oilPhaseIdx) > 0.0
&& Rv >= (1.0 - 1e-10)*gasPvt_->saturatedOilVaporizationFactor(regionIdx, scalarValue(T), scalarValue(p)))
{
return gasPvt_->saturatedInverseFormationVolumeFactor(regionIdx, T, p);
Expand All @@ -792,7 +807,7 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S

if (enableVaporizedWater()) {
const auto& Rvw = BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
if (fluidState.saturation(waterPhaseIdx) > 0.0
if (useSaturatedTables() && fluidState.saturation(waterPhaseIdx) > 0.0
&& Rvw >= (1.0 - 1e-10)*gasPvt_->saturatedWaterVaporizationFactor(regionIdx, scalarValue(T), scalarValue(p)))
{
return gasPvt_->saturatedInverseFormationVolumeFactor(regionIdx, T, p);
Expand All @@ -811,7 +826,7 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
const auto& saltConcentration = BlackOil::template getSaltConcentration_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
if (enableDissolvedGasInWater()) {
const auto& Rsw = BlackOil::template getRsw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
if (fluidState.saturation(gasPhaseIdx) > 0.0
if (useSaturatedTables() && fluidState.saturation(gasPhaseIdx) > 0.0
&& Rsw >= (1.0 - 1e-10)*waterPvt_->saturatedGasDissolutionFactor(regionIdx, scalarValue(T), scalarValue(p), scalarValue(saltConcentration)))
{
return waterPvt_->saturatedInverseFormationVolumeFactor(regionIdx, T, p, saltConcentration);
Expand Down Expand Up @@ -995,7 +1010,7 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
case oilPhaseIdx: {
if (enableDissolvedGas()) {
const auto& Rs = BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
if (fluidState.saturation(gasPhaseIdx) > 0.0
if (useSaturatedTables() && fluidState.saturation(gasPhaseIdx) > 0.0
&& Rs >= (1.0 - 1e-10)*oilPvt_->saturatedGasDissolutionFactor(regionIdx, scalarValue(T), scalarValue(p)))
{
return oilPvt_->saturatedViscosity(regionIdx, T, p);
Expand All @@ -1012,7 +1027,7 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
if (enableVaporizedOil() && enableVaporizedWater()) {
const auto& Rvw = BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
const auto& Rv = BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
if (fluidState.saturation(waterPhaseIdx) > 0.0
if (useSaturatedTables() && fluidState.saturation(waterPhaseIdx) > 0.0
&& Rvw >= (1.0 - 1e-10)*gasPvt_->saturatedWaterVaporizationFactor(regionIdx, scalarValue(T), scalarValue(p))
&& fluidState.saturation(oilPhaseIdx) > 0.0
&& Rv >= (1.0 - 1e-10)*gasPvt_->saturatedOilVaporizationFactor(regionIdx, scalarValue(T), scalarValue(p)))
Expand All @@ -1024,7 +1039,7 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
}
if (enableVaporizedOil()) {
const auto& Rv = BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
if (fluidState.saturation(oilPhaseIdx) > 0.0
if (useSaturatedTables() && fluidState.saturation(oilPhaseIdx) > 0.0
&& Rv >= (1.0 - 1e-10)*gasPvt_->saturatedOilVaporizationFactor(regionIdx, scalarValue(T), scalarValue(p)))
{
return gasPvt_->saturatedViscosity(regionIdx, T, p);
Expand All @@ -1035,7 +1050,7 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
}
if (enableVaporizedWater()) {
const auto& Rvw = BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
if (fluidState.saturation(waterPhaseIdx) > 0.0
if (useSaturatedTables() && fluidState.saturation(waterPhaseIdx) > 0.0
&& Rvw >= (1.0 - 1e-10)*gasPvt_->saturatedWaterVaporizationFactor(regionIdx, scalarValue(T), scalarValue(p)))
{
return gasPvt_->saturatedViscosity(regionIdx, T, p);
Expand All @@ -1055,7 +1070,7 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
const LhsEval& saltConcentration = BlackOil::template getSaltConcentration_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
if (enableDissolvedGasInWater()) {
const auto& Rsw = BlackOil::template getRsw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
if (fluidState.saturation(gasPhaseIdx) > 0.0
if (useSaturatedTables() && fluidState.saturation(gasPhaseIdx) > 0.0
&& Rsw >= (1.0 - 1e-10)*waterPvt_->saturatedGasDissolutionFactor(regionIdx, scalarValue(T), scalarValue(p), scalarValue(saltConcentration)))
{
return waterPvt_->saturatedViscosity(regionIdx, T, p, saltConcentration);
Expand Down Expand Up @@ -1541,6 +1556,8 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
static std::array<short, numPhases> canonicalToActivePhaseIdx_;

static bool isInitialized_;

static bool useSaturatedTables_;
};

template <typename T> using BOFS = BlackOilFluidSystem<T, BlackOilDefaultIndexTraits>;
Expand All @@ -1564,7 +1581,8 @@ template<> std::shared_ptr<WaterPvtMultiplexer<T>> BOFS<T>::waterPvt_; \
template<> std::vector<std::array<T, 3>> BOFS<T>::referenceDensity_; \
template<> std::vector<std::array<T, 3>> BOFS<T>::molarMass_; \
template<> std::vector<std::array<T, 9>> BOFS<T>::diffusionCoefficients_; \
template<> bool BOFS<T>::isInitialized_;
template<> bool BOFS<T>::isInitialized_; \
template<> bool BOFS<T>::useSaturatedTables_;

DECLARE_INSTANCE(float)
DECLARE_INSTANCE(double)
Expand Down

0 comments on commit 7f37b16

Please sign in to comment.