From 4c451582c8c8baebf8aabaec5596473a8585fe16 Mon Sep 17 00:00:00 2001 From: hnil Date: Wed, 17 Oct 2018 15:09:41 +0200 Subject: [PATCH 1/4] changes to make black oil energy model less dependent not gennereting temperature without entalpy term enabled --- .../fluidstates/BlackOilFluidState.hpp | 6 +- .../fluidsystems/BlackOilFluidSystem.hpp | 104 +++++++++++++----- 2 files changed, 83 insertions(+), 27 deletions(-) diff --git a/opm/material/fluidstates/BlackOilFluidState.hpp b/opm/material/fluidstates/BlackOilFluidState.hpp index 17560a5f6..967fcdc5a 100644 --- a/opm/material/fluidstates/BlackOilFluidState.hpp +++ b/opm/material/fluidstates/BlackOilFluidState.hpp @@ -321,7 +321,11 @@ class BlackOilFluidState * exception! */ Scalar internalEnergy(unsigned phaseIdx OPM_UNUSED) const - { return (*enthalpy_)[phaseIdx] - pressure(phaseIdx)/density(phaseIdx); } + { + double ent_fac=0.0; + //double ent_fac=0; + return (*enthalpy_)[phaseIdx] - ent_fac*pressure(phaseIdx)/density(phaseIdx); + } ////// // slow methods diff --git a/opm/material/fluidsystems/BlackOilFluidSystem.hpp b/opm/material/fluidsystems/BlackOilFluidSystem.hpp index fde559f88..ba29ae177 100644 --- a/opm/material/fluidsystems/BlackOilFluidSystem.hpp +++ b/opm/material/fluidsystems/BlackOilFluidSystem.hpp @@ -551,7 +551,7 @@ class BlackOilFluidSystem : public BaseFluidSystem(fluidState, regionIdx); - const LhsEval& bo = oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs); + const LhsEval& bo = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); return bo*referenceDensity(oilPhaseIdx, regionIdx) @@ -560,7 +560,7 @@ class BlackOilFluidSystem : public BaseFluidSysteminverseFormationVolumeFactor(regionIdx, T, p, Rs); + const auto& bo = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); return referenceDensity(phaseIdx, regionIdx)*bo; } @@ -569,8 +569,7 @@ class BlackOilFluidSystem : public BaseFluidSystem(fluidState, regionIdx); - const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv); - + const LhsEval& bg = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); return bg*referenceDensity(gasPhaseIdx, regionIdx) + Rv*bg*referenceDensity(oilPhaseIdx, regionIdx); @@ -578,7 +577,7 @@ class BlackOilFluidSystem : public BaseFluidSysteminverseFormationVolumeFactor(regionIdx, T, p, Rv); + const auto& bg = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); return bg*referenceDensity(phaseIdx, regionIdx); } @@ -655,6 +654,74 @@ class BlackOilFluidSystem : public BaseFluidSystem + static LhsEval energy(const FluidState& fluidState, + unsigned phaseIdx, + unsigned regionIdx) + { + assert(0 <= phaseIdx && phaseIdx <= numPhases); + assert(0 <= regionIdx && regionIdx <= numRegions()); + + //const auto& p = fluidState.pressure(phaseIdx); + //const auto& T = fluidState.temperature(phaseIdx); + const auto& p = Opm::decay(fluidState.pressure(phaseIdx)); + const auto& T = Opm::decay(fluidState.temperature(phaseIdx)); + switch (phaseIdx) { + case oilPhaseIdx: { + if (enableDissolvedGas()) { + // miscible oil + const LhsEval& Rs = Opm::BlackOil::template getRs_(fluidState, regionIdx); + //const LhsEval& bo = oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs); + const LhsEval& bo = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); + //const LhsEval& bo = Opm::decay(fluidState.invB(phaseIdx)); + const LhsEval& Rv = Opm::BlackOil::template getRv_(fluidState, regionIdx); + LhsEval energy = + bo*referenceDensity(oilPhaseIdx, regionIdx) + *oilPvt_->internalEnergy(regionIdx, T, p, Rs) + + Rs*bo*referenceDensity(gasPhaseIdx, regionIdx) + *gasPvt_->internalEnergy(regionIdx, T, p, Rv);//this a to simple model + return energy/density(fluidState, phaseIdx, regionIdx); + } + + // immiscible oil + const LhsEval Rs(0.0); + //const LhsEval& bo = oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs); + //const LhsEval& bo = Opm::decay(fluidState.invB(phaseIdx)); + return oilPvt_->internalEnergy(regionIdx, T, p, Rs); + } + + case gasPhaseIdx: { + if (enableVaporizedOil()) { + // miscible gas + const LhsEval& Rs = Opm::BlackOil::template getRs_(fluidState, regionIdx); + const LhsEval& Rv = Opm::BlackOil::template getRv_(fluidState, regionIdx); + const LhsEval& bg = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); + //const LhsEval& bg = Opm::decay(fluidState.invB(phaseIdx)); + LhsEval energy = + bg*referenceDensity(gasPhaseIdx, regionIdx) + *gasPvt_->internalEnergy(regionIdx, T, p, Rv) + + Rv*bg*referenceDensity(oilPhaseIdx, regionIdx) + *oilPvt_->internalEnergy(regionIdx, T, p, Rs);// this is a to simple model + return energy/density(fluidState, phaseIdx, regionIdx); + } + + // immiscible gas + const LhsEval Rv(0.0); + // const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv); + + return gasPvt_->internalEnergy(regionIdx, T, p, Rv); + + } + + case waterPhaseIdx: + return waterPvt_->internalEnergy(regionIdx, T, p); + + } + + throw std::logic_error("Unhandled phase index "+std::to_string(phaseIdx)); + } + + /*! * \brief Returns the formation volume factor \f$B_\alpha\f$ of an "undersaturated" * fluid phase @@ -963,28 +1030,13 @@ class BlackOilFluidSystem : public BaseFluidSystem(fluidState.pressure(phaseIdx)); - const auto& T = Opm::decay(fluidState.temperature(phaseIdx)); - - switch (phaseIdx) { - case oilPhaseIdx: - return - oilPvt_->internalEnergy(regionIdx, T, p, Opm::BlackOil::template getRs_(fluidState, regionIdx)) - + p/density(fluidState, phaseIdx, regionIdx); - - case gasPhaseIdx: - return - gasPvt_->internalEnergy(regionIdx, T, p, Opm::BlackOil::template getRv_(fluidState, regionIdx)) - + p/density(fluidState, phaseIdx, regionIdx); + //const auto& T = Opm::decay(fluidState.temperature(phaseIdx)); + double ent_fac=0; + //double ent_fac = 1; + return energy(fluidState, phaseIdx, regionIdx) + + ent_fac*p/density(fluidState, phaseIdx, regionIdx); - case waterPhaseIdx: - return - waterPvt_->internalEnergy(regionIdx, T, p) - + p/density(fluidState, phaseIdx, regionIdx); - - default: throw std::logic_error("Unhandled phase index "+std::to_string(phaseIdx)); - } - - throw std::logic_error("Unhandled phase index "+std::to_string(phaseIdx)); + //return energy; } /*! From 1bc7c51d2c90cf022a5520dcad48f1a64c1422b8 Mon Sep 17 00:00:00 2001 From: hnil Date: Wed, 17 Oct 2018 15:17:14 +0200 Subject: [PATCH 2/4] moved back to include enthapy --- opm/material/fluidstates/BlackOilFluidState.hpp | 4 ++-- opm/material/fluidsystems/BlackOilFluidSystem.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/opm/material/fluidstates/BlackOilFluidState.hpp b/opm/material/fluidstates/BlackOilFluidState.hpp index 967fcdc5a..7c4cec5e3 100644 --- a/opm/material/fluidstates/BlackOilFluidState.hpp +++ b/opm/material/fluidstates/BlackOilFluidState.hpp @@ -322,8 +322,8 @@ class BlackOilFluidState */ Scalar internalEnergy(unsigned phaseIdx OPM_UNUSED) const { - double ent_fac=0.0; - //double ent_fac=0; + //double ent_fac=0.0; + double ent_fac=1.0; return (*enthalpy_)[phaseIdx] - ent_fac*pressure(phaseIdx)/density(phaseIdx); } diff --git a/opm/material/fluidsystems/BlackOilFluidSystem.hpp b/opm/material/fluidsystems/BlackOilFluidSystem.hpp index ba29ae177..f8cdd637c 100644 --- a/opm/material/fluidsystems/BlackOilFluidSystem.hpp +++ b/opm/material/fluidsystems/BlackOilFluidSystem.hpp @@ -1031,8 +1031,8 @@ class BlackOilFluidSystem : public BaseFluidSystem(fluidState.pressure(phaseIdx)); //const auto& T = Opm::decay(fluidState.temperature(phaseIdx)); - double ent_fac=0; - //double ent_fac = 1; + //double ent_fac=0; + double ent_fac = 1.0; return energy(fluidState, phaseIdx, regionIdx) + ent_fac*p/density(fluidState, phaseIdx, regionIdx); From f261e12360f7146162f641589d919501bed426af Mon Sep 17 00:00:00 2001 From: hnil Date: Tue, 6 Nov 2018 22:15:10 +0100 Subject: [PATCH 3/4] changed according to pullrequest comments --- opm/material/fluidstates/BlackOilFluidState.hpp | 8 +++++--- opm/material/fluidsystems/BlackOilFluidSystem.hpp | 8 ++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/opm/material/fluidstates/BlackOilFluidState.hpp b/opm/material/fluidstates/BlackOilFluidState.hpp index 7c4cec5e3..1593be4be 100644 --- a/opm/material/fluidstates/BlackOilFluidState.hpp +++ b/opm/material/fluidstates/BlackOilFluidState.hpp @@ -322,9 +322,11 @@ class BlackOilFluidState */ Scalar internalEnergy(unsigned phaseIdx OPM_UNUSED) const { - //double ent_fac=0.0; - double ent_fac=1.0; - return (*enthalpy_)[phaseIdx] - ent_fac*pressure(phaseIdx)/density(phaseIdx); + //double entFac=0.0; + double entFac=1.0; + // this may be setting which for entFac =1 make this probably E100 compatible + // however this has to be consitent with call to enthalpy + return (*enthalpy_)[phaseIdx] - entFac*pressure(phaseIdx)/density(phaseIdx); } ////// diff --git a/opm/material/fluidsystems/BlackOilFluidSystem.hpp b/opm/material/fluidsystems/BlackOilFluidSystem.hpp index f8cdd637c..8fc583bf4 100644 --- a/opm/material/fluidsystems/BlackOilFluidSystem.hpp +++ b/opm/material/fluidsystems/BlackOilFluidSystem.hpp @@ -1030,13 +1030,9 @@ class BlackOilFluidSystem : public BaseFluidSystem(fluidState.pressure(phaseIdx)); - //const auto& T = Opm::decay(fluidState.temperature(phaseIdx)); - //double ent_fac=0; - double ent_fac = 1.0; + double entFac = 1.0; return energy(fluidState, phaseIdx, regionIdx) - + ent_fac*p/density(fluidState, phaseIdx, regionIdx); - - //return energy; + + entFac*p/density(fluidState, phaseIdx, regionIdx); } /*! From df1d0a712ca5252ceccad40c8c3155fdc41c3661 Mon Sep 17 00:00:00 2001 From: hnil Date: Wed, 7 Nov 2018 19:47:17 +0100 Subject: [PATCH 4/4] fixed error with template conversion --- opm/material/fluidsystems/BlackOilFluidSystem.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/opm/material/fluidsystems/BlackOilFluidSystem.hpp b/opm/material/fluidsystems/BlackOilFluidSystem.hpp index f8cdd637c..bcddf1d66 100644 --- a/opm/material/fluidsystems/BlackOilFluidSystem.hpp +++ b/opm/material/fluidsystems/BlackOilFluidSystem.hpp @@ -551,7 +551,7 @@ class BlackOilFluidSystem : public BaseFluidSystem(fluidState, regionIdx); - const LhsEval& bo = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); + const LhsEval& bo = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); return bo*referenceDensity(oilPhaseIdx, regionIdx) @@ -560,7 +560,7 @@ class BlackOilFluidSystem : public BaseFluidSystem(fluidState, phaseIdx, regionIdx); return referenceDensity(phaseIdx, regionIdx)*bo; } @@ -569,7 +569,7 @@ class BlackOilFluidSystem : public BaseFluidSystem(fluidState, regionIdx); - const LhsEval& bg = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); + const LhsEval& bg = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); return bg*referenceDensity(gasPhaseIdx, regionIdx) + Rv*bg*referenceDensity(oilPhaseIdx, regionIdx); @@ -577,7 +577,7 @@ class BlackOilFluidSystem : public BaseFluidSystem(fluidState, phaseIdx, regionIdx); return bg*referenceDensity(phaseIdx, regionIdx); } @@ -672,7 +672,7 @@ class BlackOilFluidSystem : public BaseFluidSystem(fluidState, regionIdx); //const LhsEval& bo = oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs); - const LhsEval& bo = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); + const LhsEval& bo = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); //const LhsEval& bo = Opm::decay(fluidState.invB(phaseIdx)); const LhsEval& Rv = Opm::BlackOil::template getRv_(fluidState, regionIdx); LhsEval energy = @@ -695,7 +695,7 @@ class BlackOilFluidSystem : public BaseFluidSystem(fluidState, regionIdx); const LhsEval& Rv = Opm::BlackOil::template getRv_(fluidState, regionIdx); - const LhsEval& bg = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); + const LhsEval& bg = inverseFormationVolumeFactor(fluidState, phaseIdx, regionIdx); //const LhsEval& bg = Opm::decay(fluidState.invB(phaseIdx)); LhsEval energy = bg*referenceDensity(gasPhaseIdx, regionIdx)