Skip to content

Commit

Permalink
-- reorginced
Browse files Browse the repository at this point in the history
  • Loading branch information
hnil committed Feb 7, 2024
1 parent 89f753e commit bcbe7c2
Showing 1 changed file with 140 additions and 102 deletions.
242 changes: 140 additions & 102 deletions opm/material/fluidsystems/BlackOilFluidSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,11 +1077,60 @@ class BlackOilFluidSystem : public BaseFluidSystem<Scalar, BlackOilFluidSystem<S
throw std::logic_error("Unhandled phase index "+std::to_string(phaseIdx));
}

template <class FluidState, class LhsEval = typename FluidState::Scalar>
static LhsEval internalEnergy(const FluidState& fluidState,
unsigned phaseIdx,
unsigned regionIdx){
bool is_mixing = false;
const LhsEval& p = decay<LhsEval>(fluidState.pressure(phaseIdx));
const LhsEval& T = decay<LhsEval>(fluidState.temperature(phaseIdx));

template <class FluidState, class LhsEval = typename FluidState::Scalar>
static LhsEval internalEnergy(const FluidState& fluidState,
unsigned phaseIdx,
unsigned regionIdx)
switch (phaseIdx) {
case oilPhaseIdx: {
if(!oilPvt_->mixingEnergy()){
const auto& oilEnergy =
oilPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));

return oilEnergy;
}
is_mixing = true;
}
case waterPhaseIdx: {
if(!waterPvt_->mixingEnergy()){
const auto waterEnergy =
waterPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRsw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx),
BlackOil::template getSaltConcentration_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));

return waterEnergy;
}
is_mixing = true;

}
case gasPhaseIdx: {
if(!gasPvt_->mixingEnergy()){
const auto gasEnergy =
gasPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx),
BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));

return gasEnergy;
}
is_mixing = true;
}
}
assert(is_mixing==true);
const auto& energy = internalMixingTotalEnergy<FluidState,LhsEval>(fluidState, phaseIdx, regionIdx);
const auto& phase_density = density<FluidState,LhsEval>(fluidState, phaseIdx, regionIdx);
return energy/phase_density;
}


template <class FluidState, class LhsEval = typename FluidState::Scalar>
static LhsEval internalMixingTotalEnergy(const FluidState& fluidState,
unsigned phaseIdx,
unsigned regionIdx)
{
assert(phaseIdx <= numPhases);
assert(regionIdx <= numRegions());
Expand All @@ -1091,125 +1140,114 @@ static LhsEval internalEnergy(const FluidState& fluidState,
// to avoid putting all thermal into the interface of the multiplexer
switch (phaseIdx) {
case oilPhaseIdx: {
const auto& oilEnergy =
oilPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
if(!oilPvt_->mixingEnergy()){
return oilEnergy;
}else{
//mixing energy adsed
if (enableDissolvedGas()) {
// miscible oil
const LhsEval& Rs = BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
const LhsEval& bo = oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs);
const auto& gasEnergy =
gasPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx),
BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
const auto hVapG = gasPvt_->hVap(regionIdx);// pressure correction ? assume equal to energy change
return
oilEnergy*bo*referenceDensity(oilPhaseIdx, regionIdx)
+ (gasEnergy-hVapG)*Rs*bo*referenceDensity(gasPhaseIdx, regionIdx);
}
auto oilEnergy = oilPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
assert(oilPvt_->mixingEnergy());
//mixing energy adsed
if (enableDissolvedGas()) {
// miscible oil
const LhsEval& Rs = BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
const LhsEval& bo = oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs);
const auto& gasEnergy =
gasPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx),
BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
const auto hVapG = gasPvt_->hVap(regionIdx);// pressure correction ? assume equal to energy change
return
oilEnergy*bo*referenceDensity(oilPhaseIdx, regionIdx)
+ (gasEnergy-hVapG)*Rs*bo*referenceDensity(gasPhaseIdx, regionIdx);
}

// immiscible oil
const LhsEval Rs(0.0);
const auto& bo = oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs);
// immiscible oil
const LhsEval Rs(0.0);
const auto& bo = oilPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rs);

return oilEnergy*referenceDensity(phaseIdx, regionIdx)*bo;
}
return oilEnergy*referenceDensity(phaseIdx, regionIdx)*bo;
}

case gasPhaseIdx: {
const auto& gasEnergy =
gasPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx),
BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
if(!gasPvt_->mixingEnergy()){
return gasEnergy;
}else{
if (enableVaporizedOil() && enableVaporizedWater()) {
const auto& oilEnergy =
oilPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
const auto waterEnergy =
waterPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRsw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx),
BlackOil::template getSaltConcentration_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
// gas containing vaporized oil and vaporized water
const LhsEval& Rv = BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
const LhsEval& Rvw = BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv, Rvw);
const auto hVapO = oilPvt_->hVap(regionIdx);
const auto hVapW = waterPvt_->hVap(regionIdx);
return
gasEnergy*bg*referenceDensity(gasPhaseIdx, regionIdx)
+ (oilEnergy+hVapO)*Rv*bg*referenceDensity(oilPhaseIdx, regionIdx)
+ (waterEnergy+hVapW)*Rvw*bg*referenceDensity(waterPhaseIdx, regionIdx);
}
if (enableVaporizedOil()) {
const auto& oilEnergy =
oilPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
// miscible gas
const LhsEval Rvw(0.0);
const LhsEval& Rv = BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv, Rvw);
const auto hVapO = oilPvt_->hVap(regionIdx);
return
gasEnergy*bg*referenceDensity(gasPhaseIdx, regionIdx)
+ (oilEnergy+hVapO)*Rv*bg*referenceDensity(oilPhaseIdx, regionIdx);
}
if (enableVaporizedWater()) {
// gas containing vaporized water
const LhsEval Rv(0.0);
const LhsEval& Rvw = BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv, Rvw);
const auto waterEnergy =
waterPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRsw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx),
BlackOil::template getSaltConcentration_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
const auto hVapW = waterPvt_->hVap(regionIdx);
return
gasEnergy*bg*referenceDensity(gasPhaseIdx, regionIdx)
+ (waterEnergy+hVapW)*Rvw*bg*referenceDensity(waterPhaseIdx, regionIdx);
}

// immiscible gas
const LhsEval Rv(0.0);
assert(gasPvt_->mixingEnergy());
if (enableVaporizedOil() && enableVaporizedWater()) {
const auto& oilEnergy =
oilPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
const auto waterEnergy =
waterPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRsw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx),
BlackOil::template getSaltConcentration_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
// gas containing vaporized oil and vaporized water
const LhsEval& Rv = BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
const LhsEval& Rvw = BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv, Rvw);
const auto hVapO = oilPvt_->hVap(regionIdx);
const auto hVapW = waterPvt_->hVap(regionIdx);
return
gasEnergy*bg*referenceDensity(gasPhaseIdx, regionIdx)
+ (oilEnergy+hVapO)*Rv*bg*referenceDensity(oilPhaseIdx, regionIdx)
+ (waterEnergy+hVapW)*Rvw*bg*referenceDensity(waterPhaseIdx, regionIdx);
}
if (enableVaporizedOil()) {
const auto& oilEnergy =
oilPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRs_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
// miscible gas
const LhsEval Rvw(0.0);
const auto& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv, Rvw);
return gasEnergy*bg*referenceDensity(phaseIdx, regionIdx);
const LhsEval& Rv = BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv, Rvw);
const auto hVapO = oilPvt_->hVap(regionIdx);
return
gasEnergy*bg*referenceDensity(gasPhaseIdx, regionIdx)
+ (oilEnergy+hVapO)*Rv*bg*referenceDensity(oilPhaseIdx, regionIdx);
}
if (enableVaporizedWater()) {
// gas containing vaporized water
const LhsEval Rv(0.0);
const LhsEval& Rvw = BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx);
const LhsEval& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv, Rvw);
const auto waterEnergy =
waterPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRsw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx),
BlackOil::template getSaltConcentration_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
const auto hVapW = waterPvt_->hVap(regionIdx);
return
gasEnergy*bg*referenceDensity(gasPhaseIdx, regionIdx)
+ (waterEnergy+hVapW)*Rvw*bg*referenceDensity(waterPhaseIdx, regionIdx);
}

// immiscible gas
const LhsEval Rv(0.0);
const LhsEval Rvw(0.0);
const auto& bg = gasPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rv, Rvw);
return gasEnergy*bg*referenceDensity(phaseIdx, regionIdx);
}

case waterPhaseIdx:
const auto waterEnergy =
waterPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRsw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx),
BlackOil::template getSaltConcentration_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
if(!waterPvt_->mixingEnergy()){
return waterEnergy;
}else{
if (enableDissolvedGasInWater()) {
const auto& gasEnergy =
gasPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx),
BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
// gas miscible in water
const LhsEval& Rsw = saturatedDissolutionFactor<FluidState, LhsEval>(fluidState, waterPhaseIdx, regionIdx);
const LhsEval& bw = waterPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rsw, saltConcentration);
return
waterEnergy*bw*referenceDensity(waterPhaseIdx, regionIdx)
+ gasEnergy*Rsw*bw*referenceDensity(gasPhaseIdx, regionIdx);
}
const LhsEval Rsw(0.0);
assert(waterPvt_->mixingEnergy());
if (enableDissolvedGasInWater()) {
const auto& gasEnergy =
gasPvt_->internalEnergy(regionIdx, T, p,
BlackOil::template getRv_<ThisType, FluidState, LhsEval>(fluidState, regionIdx),
BlackOil::template getRvw_<ThisType, FluidState, LhsEval>(fluidState, regionIdx));
// gas miscible in water
const LhsEval& Rsw = saturatedDissolutionFactor<FluidState, LhsEval>(fluidState, waterPhaseIdx, regionIdx);
const LhsEval& bw = waterPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rsw, saltConcentration);
return
waterEnergy*referenceDensity(waterPhaseIdx, regionIdx)
* waterPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rsw, saltConcentration);
waterEnergy*bw*referenceDensity(waterPhaseIdx, regionIdx)
+ gasEnergy*Rsw*bw*referenceDensity(gasPhaseIdx, regionIdx);
}
const LhsEval Rsw(0.0);
return
waterEnergy*referenceDensity(waterPhaseIdx, regionIdx)
* waterPvt_->inverseFormationVolumeFactor(regionIdx, T, p, Rsw, saltConcentration);
}

throw std::logic_error("Unhandled phase index " + std::to_string(phaseIdx));
}

Expand Down

0 comments on commit bcbe7c2

Please sign in to comment.