28#ifndef EWOMS_BLACK_OIL_INTENSIVE_QUANTITIES_HH
29#define EWOMS_BLACK_OIL_INTENSIVE_QUANTITIES_HH
42#include <opm/common/TimingMacros.hpp>
43#include <opm/common/OpmLog/OpmLog.hpp>
45#include <opm/input/eclipse/EclipseState/Grid/FaceDir.hpp>
47#include <opm/material/fluidstates/BlackOilFluidState.hpp>
48#include <opm/material/common/Valgrind.hpp>
52#include <opm/utility/CopyablePtr.hpp>
54#include <dune/common/fmatrix.hh>
59#include <fmt/format.h>
69template <
class TypeTag>
71 :
public GetPropType<TypeTag, Properties::DiscIntensiveQuantities>
72 ,
public GetPropType<TypeTag, Properties::FluxModule>::FluxIntensiveQuantities
96 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
97 enum { enableSolvent = getPropValue<TypeTag, Properties::EnableSolvent>() };
98 enum { enableExtbo = getPropValue<TypeTag, Properties::EnableExtbo>() };
99 enum { enablePolymer = getPropValue<TypeTag, Properties::EnablePolymer>() };
100 enum { enableFoam = getPropValue<TypeTag, Properties::EnableFoam>() };
101 enum { enableBrine = getPropValue<TypeTag, Properties::EnableBrine>() };
102 enum { enableVapwat = getPropValue<TypeTag, Properties::EnableVapwat>() };
103 enum { has_disgas_in_water = getPropValue<TypeTag, Properties::EnableDisgasInWater>() };
104 enum { enableSaltPrecipitation = getPropValue<TypeTag, Properties::EnableSaltPrecipitation>() };
105 enum { enableTemperature = getPropValue<TypeTag, Properties::EnableTemperature>() };
106 enum { enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>() };
107 enum { enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>() };
108 enum { enableDispersion = getPropValue<TypeTag, Properties::EnableDispersion>() };
109 enum { enableMICP = getPropValue<TypeTag, Properties::EnableMICP>() };
110 enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
111 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
112 enum { waterCompIdx = FluidSystem::waterCompIdx };
113 enum { oilCompIdx = FluidSystem::oilCompIdx };
114 enum { gasCompIdx = FluidSystem::gasCompIdx };
115 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
116 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
117 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
118 enum { dimWorld = GridView::dimensionworld };
119 enum { compositionSwitchIdx = Indices::compositionSwitchIdx };
121 static constexpr bool compositionSwitchEnabled = Indices::compositionSwitchIdx >= 0;
122 static constexpr bool waterEnabled = Indices::waterEnabled;
123 static constexpr bool gasEnabled = Indices::gasEnabled;
124 static constexpr bool oilEnabled = Indices::oilEnabled;
126 using Toolbox = MathToolbox<Evaluation>;
127 using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
128 using FluxIntensiveQuantities =
typename FluxModule::FluxIntensiveQuantities;
132 using DirectionalMobilityPtr = Opm::Utility::CopyablePtr<DirectionalMobility<TypeTag, Evaluation>>;
141 compositionSwitchEnabled,
144 enableSaltPrecipitation,
151 compositionSwitchEnabled,
154 enableSaltPrecipitation,
161 if (compositionSwitchEnabled) {
162 fluidState_.setRs(0.0);
163 fluidState_.setRv(0.0);
166 fluidState_.setRvw(0.0);
168 if (has_disgas_in_water) {
169 fluidState_.setRsw(0.0);
179 void update(
const ElementContext& elemCtx,
unsigned dofIdx,
unsigned timeIdx)
181 ParentType::update(elemCtx, dofIdx, timeIdx);
182 OPM_TIMEBLOCK_LOCAL(blackoilIntensiveQuanititiesUpdate);
183 const auto& problem = elemCtx.problem();
184 const auto& priVars = elemCtx.primaryVars(dofIdx, timeIdx);
185 const auto& linearizationType = problem.model().linearizer().getLinearizationType();
186 unsigned globalSpaceIdx = elemCtx.globalSpaceIndex(dofIdx, timeIdx);
187 Scalar RvMax = FluidSystem::enableVaporizedOil()
188 ? problem.maxOilVaporizationFactor(timeIdx, globalSpaceIdx)
190 Scalar RsMax = FluidSystem::enableDissolvedGas()
191 ? problem.maxGasDissolutionFactor(timeIdx, globalSpaceIdx)
193 Scalar RswMax = FluidSystem::enableDissolvedGasInWater()
194 ? problem.maxGasDissolutionFactor(timeIdx, globalSpaceIdx)
197 asImp_().updateTemperature_(elemCtx, dofIdx, timeIdx);
199 unsigned pvtRegionIdx = priVars.pvtRegionIndex();
200 fluidState_.setPvtRegionIndex(pvtRegionIdx);
202 asImp_().updateSaltConcentration_(elemCtx, dofIdx, timeIdx);
206 if constexpr (waterEnabled) {
207 if (priVars.primaryVarsMeaningWater() == PrimaryVariables::WaterMeaning::Sw) {
208 Sw = priVars.makeEvaluation(Indices::waterSwitchIdx, timeIdx);
209 }
else if(priVars.primaryVarsMeaningWater() == PrimaryVariables::WaterMeaning::Rsw ||
210 priVars.primaryVarsMeaningWater() == PrimaryVariables::WaterMeaning::Disabled) {
217 if constexpr (gasEnabled) {
218 if (priVars.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Sg) {
219 Sg = priVars.makeEvaluation(Indices::compositionSwitchIdx, timeIdx);
220 }
else if (priVars.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Rv) {
222 }
else if (priVars.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Disabled) {
223 if constexpr (waterEnabled) {
231 Valgrind::CheckDefined(Sg);
232 Valgrind::CheckDefined(Sw);
234 Evaluation So = 1.0 - Sw - Sg;
237 if constexpr (enableSolvent) {
238 if(priVars.primaryVarsMeaningSolvent() == PrimaryVariables::SolventMeaning::Ss) {
239 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
240 So -= priVars.makeEvaluation(Indices::solventSaturationIdx, timeIdx);
241 }
else if (FluidSystem::phaseIsActive(gasPhaseIdx)) {
242 Sg -= priVars.makeEvaluation(Indices::solventSaturationIdx, timeIdx);
247 if (FluidSystem::phaseIsActive(waterPhaseIdx))
248 fluidState_.setSaturation(waterPhaseIdx, Sw);
250 if (FluidSystem::phaseIsActive(gasPhaseIdx))
251 fluidState_.setSaturation(gasPhaseIdx, Sg);
253 if (FluidSystem::phaseIsActive(oilPhaseIdx))
254 fluidState_.setSaturation(oilPhaseIdx, So);
256 asImp_().solventPreSatFuncUpdate_(elemCtx, dofIdx, timeIdx);
259 std::array<Evaluation, numPhases> pC;
260 const auto& materialParams = problem.materialLawParams(globalSpaceIdx);
261 MaterialLaw::capillaryPressures(pC, materialParams, fluidState_);
262 problem.updateRelperms(mobility_, dirMob_, fluidState_, globalSpaceIdx);
266 unsigned satnumRegionIdx = elemCtx.problem().satnumRegionIndex(elemCtx, dofIdx, timeIdx);
267 const Evaluation Sp = priVars.makeEvaluation(Indices::saltConcentrationIdx, timeIdx);
268 const Evaluation porosityFactor = min(1.0 - Sp, 1.0);
270 const Evaluation pcFactor = pcfactTable.eval(porosityFactor,
true);
271 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
272 if (FluidSystem::phaseIsActive(phaseIdx)) {
273 pC[phaseIdx] *= pcFactor;
278 if (priVars.primaryVarsMeaningPressure() == PrimaryVariables::PressureMeaning::Pg) {
279 const Evaluation& pg = priVars.makeEvaluation(Indices::pressureSwitchIdx, timeIdx);
280 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
281 if (FluidSystem::phaseIsActive(phaseIdx))
282 fluidState_.setPressure(phaseIdx, pg + (pC[phaseIdx] - pC[gasPhaseIdx]));
283 }
else if (priVars.primaryVarsMeaningPressure() == PrimaryVariables::PressureMeaning::Pw) {
284 const Evaluation& pw = priVars.makeEvaluation(Indices::pressureSwitchIdx, timeIdx);
285 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
286 if (FluidSystem::phaseIsActive(phaseIdx))
287 fluidState_.setPressure(phaseIdx, pw + (pC[phaseIdx] - pC[waterPhaseIdx]));
289 assert(FluidSystem::phaseIsActive(oilPhaseIdx));
290 const Evaluation& po = priVars.makeEvaluation(Indices::pressureSwitchIdx, timeIdx);
291 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
292 if (FluidSystem::phaseIsActive(phaseIdx))
293 fluidState_.setPressure(phaseIdx, po + (pC[phaseIdx] - pC[oilPhaseIdx]));
297 asImp_().solventPostSatFuncUpdate_(elemCtx, dofIdx, timeIdx);
300 asImp_().zFractionUpdate_(elemCtx, dofIdx, timeIdx);
302 Evaluation SoMax = 0.0;
303 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
304 SoMax = max(fluidState_.saturation(oilPhaseIdx),
305 problem.maxOilSaturation(globalSpaceIdx));
309 if (priVars.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Rs) {
310 const auto& Rs = priVars.makeEvaluation(Indices::compositionSwitchIdx, timeIdx);
311 fluidState_.setRs(Rs);
313 if (FluidSystem::enableDissolvedGas()) {
314 const Evaluation& RsSat = enableExtbo ? asImp_().rs() :
315 FluidSystem::saturatedDissolutionFactor(fluidState_,
319 fluidState_.setRs(min(RsMax, RsSat));
321 else if constexpr (compositionSwitchEnabled)
322 fluidState_.setRs(0.0);
324 if (priVars.primaryVarsMeaningGas() == PrimaryVariables::GasMeaning::Rv) {
325 const auto& Rv = priVars.makeEvaluation(Indices::compositionSwitchIdx, timeIdx);
326 fluidState_.setRv(Rv);
328 if (FluidSystem::enableVaporizedOil() ) {
329 const Evaluation& RvSat = enableExtbo ? asImp_().rv() :
330 FluidSystem::saturatedDissolutionFactor(fluidState_,
334 fluidState_.setRv(min(RvMax, RvSat));
336 else if constexpr (compositionSwitchEnabled)
337 fluidState_.setRv(0.0);
340 if (priVars.primaryVarsMeaningWater() == PrimaryVariables::WaterMeaning::Rvw) {
341 const auto& Rvw = priVars.makeEvaluation(Indices::waterSwitchIdx, timeIdx);
342 fluidState_.setRvw(Rvw);
344 if (FluidSystem::enableVaporizedWater()) {
345 const Evaluation& RvwSat = FluidSystem::saturatedVaporizationFactor(fluidState_,
348 fluidState_.setRvw(RvwSat);
352 if (priVars.primaryVarsMeaningWater() == PrimaryVariables::WaterMeaning::Rsw) {
353 const auto& Rsw = priVars.makeEvaluation(Indices::waterSwitchIdx, timeIdx);
354 fluidState_.setRsw(Rsw);
356 if (FluidSystem::enableDissolvedGasInWater()) {
357 const Evaluation& RswSat = FluidSystem::saturatedDissolutionFactor(fluidState_,
360 fluidState_.setRsw(min(RswMax, RswSat));
364 typename FluidSystem::template ParameterCache<Evaluation> paramCache;
365 paramCache.setRegionIndex(pvtRegionIdx);
366 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
367 paramCache.setMaxOilSat(SoMax);
369 paramCache.updateAll(fluidState_);
373 std::vector<std::array<Evaluation,numPhases>*> mobilities = {&mobility_};
375 for (
int i=0; i<3; i++) {
377 mobilities.push_back(&(dirMob_->getArray(i)));
380 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
381 if (!FluidSystem::phaseIsActive(phaseIdx))
383 const auto& b = FluidSystem::inverseFormationVolumeFactor(fluidState_, phaseIdx, pvtRegionIdx);
384 fluidState_.setInvB(phaseIdx, b);
385 const auto& mu = FluidSystem::viscosity(fluidState_, paramCache, phaseIdx);
386 for (
int i = 0; i<nmobilities; i++) {
387 if (enableExtbo && phaseIdx == oilPhaseIdx) {
388 (*mobilities[i])[phaseIdx] /= asImp_().oilViscosity();
390 else if (enableExtbo && phaseIdx == gasPhaseIdx) {
391 (*mobilities[i])[phaseIdx] /= asImp_().gasViscosity();
394 (*mobilities[i])[phaseIdx] /= mu;
398 Valgrind::CheckDefined(mobility_);
402 if (FluidSystem::phaseIsActive(waterPhaseIdx)) {
403 rho = fluidState_.invB(waterPhaseIdx);
404 rho *= FluidSystem::referenceDensity(waterPhaseIdx, pvtRegionIdx);
405 if (FluidSystem::enableDissolvedGasInWater()) {
407 fluidState_.invB(waterPhaseIdx) *
409 FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx);
411 fluidState_.setDensity(waterPhaseIdx, rho);
414 if (FluidSystem::phaseIsActive(gasPhaseIdx)) {
415 rho = fluidState_.invB(gasPhaseIdx);
416 rho *= FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx);
417 if (FluidSystem::enableVaporizedOil()) {
419 fluidState_.invB(gasPhaseIdx) *
421 FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx);
423 if (FluidSystem::enableVaporizedWater()) {
425 fluidState_.invB(gasPhaseIdx) *
427 FluidSystem::referenceDensity(waterPhaseIdx, pvtRegionIdx);
429 fluidState_.setDensity(gasPhaseIdx, rho);
432 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
433 rho = fluidState_.invB(oilPhaseIdx);
434 rho *= FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx);
435 if (FluidSystem::enableDissolvedGas()) {
437 fluidState_.invB(oilPhaseIdx) *
439 FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx);
441 fluidState_.setDensity(oilPhaseIdx, rho);
445 referencePorosity_ = problem.porosity(elemCtx, dofIdx, timeIdx);
446 porosity_ = referencePorosity_;
450 Scalar rockCompressibility = problem.rockCompressibility(globalSpaceIdx);
451 if (rockCompressibility > 0.0) {
452 Scalar rockRefPressure = problem.rockReferencePressure(globalSpaceIdx);
454 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
455 x = rockCompressibility*(fluidState_.pressure(oilPhaseIdx) - rockRefPressure);
456 }
else if (FluidSystem::phaseIsActive(waterPhaseIdx)){
457 x = rockCompressibility*(fluidState_.pressure(waterPhaseIdx) - rockRefPressure);
459 x = rockCompressibility*(fluidState_.pressure(gasPhaseIdx) - rockRefPressure);
461 porosity_ *= 1.0 + x + 0.5*x*x;
465 porosity_ *= problem.template rockCompPoroMultiplier<Evaluation>(*
this, globalSpaceIdx);
468 if constexpr (enableMICP){
469 Evaluation biofilm_ = priVars.makeEvaluation(Indices::biofilmConcentrationIdx, timeIdx, linearizationType);
470 Evaluation calcite_ = priVars.makeEvaluation(Indices::calciteConcentrationIdx, timeIdx, linearizationType);
471 porosity_ += - biofilm_ - calcite_;
475 if (enableSaltPrecipitation && priVars.primaryVarsMeaningBrine() == PrimaryVariables::BrineMeaning::Sp) {
476 Evaluation Sp = priVars.makeEvaluation(Indices::saltConcentrationIdx, timeIdx);
477 porosity_ *= (1.0 - Sp);
480 rockCompTransMultiplier_ = problem.template rockCompTransMultiplier<Evaluation>(*
this, globalSpaceIdx);
482 asImp_().solventPvtUpdate_(elemCtx, dofIdx, timeIdx);
483 asImp_().zPvtUpdate_();
484 asImp_().polymerPropertiesUpdate_(elemCtx, dofIdx, timeIdx);
485 asImp_().updateEnergyQuantities_(elemCtx, dofIdx, timeIdx, paramCache);
486 asImp_().foamPropertiesUpdate_(elemCtx, dofIdx, timeIdx);
487 asImp_().MICPPropertiesUpdate_(elemCtx, dofIdx, timeIdx);
488 asImp_().saltPropertiesUpdate_(elemCtx, dofIdx, timeIdx);
492 FluxIntensiveQuantities::update_(elemCtx, dofIdx, timeIdx);
495 DiffusionIntensiveQuantities::update_(fluidState_, paramCache, elemCtx, dofIdx, timeIdx);
498 DispersionIntensiveQuantities::update_(elemCtx, dofIdx, timeIdx);
502 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) {
503 if (!FluidSystem::phaseIsActive(phaseIdx))
506 assert(isfinite(fluidState_.density(phaseIdx)));
507 assert(isfinite(fluidState_.saturation(phaseIdx)));
508 assert(isfinite(fluidState_.temperature(phaseIdx)));
509 assert(isfinite(fluidState_.pressure(phaseIdx)));
510 assert(isfinite(fluidState_.invB(phaseIdx)));
512 assert(isfinite(fluidState_.Rs()));
513 assert(isfinite(fluidState_.Rv()));
522 {
return fluidState_; }
527 const Evaluation&
mobility(
unsigned phaseIdx)
const
528 {
return mobility_[phaseIdx]; }
530 const Evaluation&
mobility(
unsigned phaseIdx, FaceDir::DirEnum facedir)
const
532 using Dir = FaceDir::DirEnum;
537 return dirMob_->mobilityX_[phaseIdx];
540 return dirMob_->mobilityY_[phaseIdx];
543 return dirMob_->mobilityZ_[phaseIdx];
545 throw std::runtime_error(
"Unexpected face direction");
549 return mobility_[phaseIdx];
558 {
return porosity_; }
564 {
return rockCompTransMultiplier_; }
575 {
return fluidState_.pvtRegionIndex(); }
583 return fluidState_.viscosity(phaseIdx)*
mobility(phaseIdx);
593 {
return referencePorosity_; }
604 Implementation& asImp_()
605 {
return *
static_cast<Implementation*
>(
this); }
608 Scalar referencePorosity_;
609 Evaluation porosity_;
610 Evaluation rockCompTransMultiplier_;
611 std::array<Evaluation,numPhases> mobility_;
628 DirectionalMobilityPtr dirMob_;
Contains the classes required to extend the black-oil model by brine.
Classes required for molecular diffusion.
Classes required for mechanical dispersion.
Contains the classes required to extend the black-oil model by energy.
Contains the classes required to extend the black-oil model by solvent component. For details,...
Contains the classes required to extend the black-oil model to include the effects of foam.
Contains the classes required to extend the black-oil model by MICP.
Contains the classes required to extend the black-oil model by polymer.
Declares the properties required by the black oil model.
Contains the classes required to extend the black-oil model by solvents.
Definition: blackoilbrinemodules.hh:416
Contains the high level supplements required to extend the black oil model by brine.
Definition: blackoilbrinemodules.hh:58
static const TabulatedFunction & pcfactTable(unsigned satnumRegionIdx)
Definition: blackoilbrinemodules.hh:342
static bool hasPcfactTables()
Definition: blackoilbrinemodules.hh:386
Provides the volumetric quantities required for the calculation of molecular diffusive fluxes.
Definition: blackoildiffusionmodule.hh:274
Provides the volumetric quantities required for the calculation of dispersive fluxes.
Definition: blackoildispersionmodule.hh:278
Provides the volumetric quantities required for the equations needed by the energys extension of the ...
Definition: blackoilenergymodules.hh:333
Provides the volumetric quantities required for the equations needed by the solvents extension of the...
Definition: blackoilextbomodules.hh:562
Provides the volumetric quantities required for the equations needed by the polymers extension of the...
Definition: blackoilfoammodules.hh:462
Contains the quantities which are are constant within a finite volume in the black-oil model.
Definition: blackoilintensivequantities.hh:82
const Evaluation & porosity() const
Returns the average porosity within the control volume.
Definition: blackoilintensivequantities.hh:557
const Evaluation & mobility(unsigned phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: blackoilintensivequantities.hh:527
void update(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Definition: blackoilintensivequantities.hh:179
Evaluation relativePermeability(unsigned phaseIdx) const
Returns the relative permeability of a given phase within the control volume.
Definition: blackoilintensivequantities.hh:580
auto pvtRegionIndex() const -> decltype(std::declval< FluidState >().pvtRegionIndex())
Returns the index of the PVT region used to calculate the thermodynamic quantities.
Definition: blackoilintensivequantities.hh:573
const FluidState & fluidState() const
Returns the phase state for the control-volume.
Definition: blackoilintensivequantities.hh:521
BlackOilIntensiveQuantities & operator=(const BlackOilIntensiveQuantities &other)=default
const Evaluation & rockCompTransMultiplier() const
Definition: blackoilintensivequantities.hh:563
BlackOilIntensiveQuantities(const BlackOilIntensiveQuantities &other)=default
BlackOilIntensiveQuantities()
Definition: blackoilintensivequantities.hh:159
BlackOilFluidState< Scalar, FluidSystem, enableTemperature, enableEnergy, compositionSwitchEnabled, enableVapwat, enableBrine, enableSaltPrecipitation, has_disgas_in_water, Indices::numPhases > ScalarFluidState
Definition: blackoilintensivequantities.hh:156
const Evaluation & mobility(unsigned phaseIdx, FaceDir::DirEnum facedir) const
Definition: blackoilintensivequantities.hh:530
Scalar referencePorosity() const
Returns the porosity of the rock at reference conditions.
Definition: blackoilintensivequantities.hh:592
BlackOilFluidState< Evaluation, FluidSystem, enableTemperature, enableEnergy, compositionSwitchEnabled, enableVapwat, enableBrine, enableSaltPrecipitation, has_disgas_in_water, Indices::numPhases > FluidState
Definition: blackoilintensivequantities.hh:146
Provides the volumetric quantities required for the equations needed by the MICP extension of the bla...
Definition: blackoilmicpmodules.hh:465
Provides the volumetric quantities required for the equations needed by the polymers extension of the...
Definition: blackoilpolymermodules.hh:807
Provides the volumetric quantities required for the equations needed by the solvents extension of the...
Definition: blackoilsolventmodules.hh:780
This file contains definitions related to directional mobilities.
Definition: blackoilboundaryratevector.hh:37
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:235