28 #ifndef EWOMS_BLACK_OIL_LOCAL_RESIDUAL_HH 29 #define EWOMS_BLACK_OIL_LOCAL_RESIDUAL_HH 31 #include <opm/material/common/MathToolbox.hpp> 32 #include <opm/material/fluidstates/BlackOilFluidState.hpp> 49 template <
class TypeTag>
61 enum { conti0EqIdx = Indices::conti0EqIdx };
62 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
63 enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
64 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
66 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
67 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
68 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
70 enum { gasCompIdx = FluidSystem::gasCompIdx };
71 enum { oilCompIdx = FluidSystem::oilCompIdx };
72 enum { waterCompIdx = FluidSystem::waterCompIdx };
73 static constexpr
unsigned compositionSwitchIdx = Indices::compositionSwitchIdx;
75 static constexpr
bool waterEnabled = Indices::waterEnabled;
76 static constexpr
bool gasEnabled = Indices::gasEnabled;
77 static constexpr
bool oilEnabled = Indices::oilEnabled;
78 static constexpr
bool compositionSwitchEnabled =
79 compositionSwitchIdx != std::numeric_limits<unsigned>::max();
81 static constexpr
bool blackoilConserveSurfaceVolume =
82 getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>();
83 static constexpr
bool enableBioeffects = getPropValue<TypeTag, Properties::EnableBioeffects>();
84 static constexpr
bool enableBrine = getPropValue<TypeTag, Properties::EnableBrine>();
85 static constexpr
bool enableConvectiveMixing = getPropValue<TypeTag, Properties::EnableConvectiveMixing>();
86 static constexpr
bool enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>();
87 static constexpr
bool enableExtbo = getPropValue<TypeTag, Properties::EnableExtbo>();
88 static constexpr
bool enableFoam = getPropValue<TypeTag, Properties::EnableFoam>();
89 static constexpr EnergyModules energyModuleType = getPropValue<TypeTag, Properties::EnergyModuleType>();
90 static constexpr
bool enableFullyImplicitThermal = energyModuleType == EnergyModules::FullyImplicitThermal;
91 static constexpr
bool enablePolymer = getPropValue<TypeTag, Properties::EnablePolymer>();
92 static constexpr
bool enableSolvent = getPropValue<TypeTag, Properties::EnableSolvent>();
94 using Toolbox = MathToolbox<Evaluation>;
96 using BioeffectsModule = BlackOilBioeffectsModule<TypeTag, enableBioeffects>;
97 using BrineModule = BlackOilBrineModule<TypeTag, enableBrine>;
98 using ConvectiveMixingModule = BlackOilConvectiveMixingModule<TypeTag, enableConvectiveMixing>;
101 using ExtboModule = BlackOilExtboModule<TypeTag, enableExtbo>;
103 using PolymerModule = BlackOilPolymerModule<TypeTag, enablePolymer>;
104 using SolventModule = BlackOilSolventModule<TypeTag, enableSolvent>;
110 template <
class LhsEval>
112 const ElementContext& elemCtx,
114 unsigned timeIdx)
const 117 const IntensiveQuantities& intQuants = elemCtx.intensiveQuantities(dofIdx, timeIdx);
118 const auto& fs = intQuants.fluidState();
122 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
123 if (!FluidSystem::phaseIsActive(phaseIdx)) {
124 if (Indices::numPhases == 3) {
125 const unsigned activeCompIdx =
126 FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
128 storage[conti0EqIdx + activeCompIdx] = variable<LhsEval>(0.0, conti0EqIdx + activeCompIdx);
131 storage[conti0EqIdx + activeCompIdx] = 0.0;
137 const unsigned activeCompIdx =
138 FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
139 const LhsEval surfaceVolume =
140 Toolbox::template decay<LhsEval>(fs.saturation(phaseIdx)) *
141 Toolbox::template decay<LhsEval>(fs.invB(phaseIdx)) *
142 Toolbox::template decay<LhsEval>(intQuants.porosity());
144 storage[conti0EqIdx + activeCompIdx] += surfaceVolume;
147 if (phaseIdx == oilPhaseIdx && FluidSystem::enableDissolvedGas()) {
148 const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(gasCompIdx);
149 storage[conti0EqIdx + activeGasCompIdx] +=
150 Toolbox::template decay<LhsEval>(intQuants.fluidState().Rs()) *
155 if (phaseIdx == waterPhaseIdx && FluidSystem::enableDissolvedGasInWater()) {
156 const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(gasCompIdx);
157 storage[conti0EqIdx + activeGasCompIdx] +=
158 Toolbox::template decay<LhsEval>(intQuants.fluidState().Rsw()) *
163 if (phaseIdx == gasPhaseIdx && FluidSystem::enableVaporizedOil()) {
164 const unsigned activeOilCompIdx = FluidSystem::canonicalToActiveCompIdx(oilCompIdx);
165 storage[conti0EqIdx + activeOilCompIdx] +=
166 Toolbox::template decay<LhsEval>(intQuants.fluidState().Rv()) *
171 if (phaseIdx == gasPhaseIdx && FluidSystem::enableVaporizedWater()) {
172 const unsigned activeWaterCompIdx = FluidSystem::canonicalToActiveCompIdx(waterCompIdx);
173 storage[conti0EqIdx + activeWaterCompIdx] +=
174 Toolbox::template decay<LhsEval>(intQuants.fluidState().Rvw()) *
182 if constexpr (enableSolvent) {
183 SolventModule::addStorage(storage, intQuants);
187 if constexpr (enableExtbo) {
188 ExtboModule::addStorage(storage, intQuants);
192 if constexpr (enablePolymer) {
193 PolymerModule::addStorage(storage, intQuants);
197 if constexpr (enableFullyImplicitThermal) {
198 EnergyModule::addStorage(storage, intQuants);
202 if constexpr (enableFoam) {
203 FoamModule::addStorage(storage, intQuants);
207 if constexpr (enableBrine) {
208 BrineModule::addStorage(storage, intQuants);
212 if constexpr (enableBioeffects) {
213 BioeffectsModule::addStorage(storage, intQuants);
221 const ElementContext& elemCtx,
223 unsigned timeIdx)
const 225 assert(timeIdx == 0);
229 const ExtensiveQuantities& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
230 unsigned focusDofIdx = elemCtx.focusDofIndex();
231 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
232 if (!FluidSystem::phaseIsActive(phaseIdx)) {
236 const unsigned upIdx =
static_cast<unsigned>(extQuants.upstreamIndex(phaseIdx));
237 const IntensiveQuantities& up = elemCtx.intensiveQuantities(upIdx, timeIdx);
238 const unsigned pvtRegionIdx = up.pvtRegionIndex();
239 if (upIdx == focusDofIdx) {
240 evalPhaseFluxes_<Evaluation>(flux, phaseIdx, pvtRegionIdx, extQuants, up.fluidState());
243 evalPhaseFluxes_<Scalar>(flux, phaseIdx, pvtRegionIdx, extQuants, up.fluidState());
248 if constexpr (enableSolvent) {
249 SolventModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
253 if constexpr (enableExtbo) {
254 ExtboModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
258 if constexpr (enablePolymer) {
259 PolymerModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
263 if constexpr (enableFullyImplicitThermal) {
264 EnergyModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
268 if constexpr (enableFoam) {
269 FoamModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
273 if constexpr (enableBrine) {
274 BrineModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
278 if constexpr (enableBioeffects) {
279 BioeffectsModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
283 if constexpr (enableDiffusion) {
284 DiffusionModule::addDiffusiveFlux(flux, elemCtx, scvfIdx, timeIdx);
288 if constexpr (enableConvectiveMixing) {
289 ConvectiveMixingModule::addConvectiveMixingFlux(flux, elemCtx, scvfIdx, timeIdx);
297 const ElementContext& elemCtx,
299 unsigned timeIdx)
const 302 elemCtx.problem().source(source, elemCtx, dofIdx, timeIdx);
305 if constexpr (enableBioeffects) {
306 BioeffectsModule::addSource(source, elemCtx, dofIdx, timeIdx);
310 if constexpr (enableFullyImplicitThermal) {
311 source[Indices::contiEnergyEqIdx] *=
312 getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>();
320 template <
class UpEval,
class Flu
idState>
323 unsigned pvtRegionIdx,
324 const ExtensiveQuantities& extQuants,
325 const FluidState& upFs)
327 const auto& invB = getInvB_<FluidSystem, FluidState, UpEval>(upFs, phaseIdx, pvtRegionIdx);
328 const auto& surfaceVolumeFlux = invB*extQuants.volumeFlux(phaseIdx);
329 const unsigned activeCompIdx =
330 FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
332 if constexpr (blackoilConserveSurfaceVolume) {
333 flux[conti0EqIdx + activeCompIdx] += surfaceVolumeFlux;
336 flux[conti0EqIdx + activeCompIdx] += surfaceVolumeFlux *
337 FluidSystem::referenceDensity(phaseIdx, pvtRegionIdx);
340 if (phaseIdx == oilPhaseIdx) {
342 if (FluidSystem::enableDissolvedGas()) {
343 const auto& Rs = BlackOil::getRs_<FluidSystem, FluidState, UpEval>(upFs, pvtRegionIdx);
345 const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(gasCompIdx);
346 if constexpr (blackoilConserveSurfaceVolume) {
347 flux[conti0EqIdx + activeGasCompIdx] += Rs * surfaceVolumeFlux;
350 flux[conti0EqIdx + activeGasCompIdx] +=
351 Rs * surfaceVolumeFlux *
352 FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx);
355 }
else if (phaseIdx == waterPhaseIdx) {
357 if (FluidSystem::enableDissolvedGasInWater()) {
358 const auto& Rsw = BlackOil::getRsw_<FluidSystem, FluidState, UpEval>(upFs, pvtRegionIdx);
360 const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(gasCompIdx);
361 if constexpr (blackoilConserveSurfaceVolume) {
362 flux[conti0EqIdx + activeGasCompIdx] += Rsw * surfaceVolumeFlux;
365 flux[conti0EqIdx + activeGasCompIdx] +=
366 Rsw * surfaceVolumeFlux *
367 FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx);
371 else if (phaseIdx == gasPhaseIdx) {
373 if (FluidSystem::enableVaporizedOil()) {
374 const auto& Rv = BlackOil::getRv_<FluidSystem, FluidState, UpEval>(upFs, pvtRegionIdx);
376 const unsigned activeOilCompIdx = FluidSystem::canonicalToActiveCompIdx(oilCompIdx);
377 if constexpr (blackoilConserveSurfaceVolume) {
378 flux[conti0EqIdx + activeOilCompIdx] += Rv * surfaceVolumeFlux;
381 flux[conti0EqIdx + activeOilCompIdx] +=
382 Rv * surfaceVolumeFlux *
383 FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx);
387 if (FluidSystem::enableVaporizedWater()) {
388 const auto& Rvw = BlackOil::getRvw_<FluidSystem, FluidState, UpEval>(upFs, pvtRegionIdx);
390 const unsigned activeWaterCompIdx = FluidSystem::canonicalToActiveCompIdx(waterCompIdx);
391 if constexpr (blackoilConserveSurfaceVolume) {
392 flux[conti0EqIdx + activeWaterCompIdx] += Rvw * surfaceVolumeFlux;
395 flux[conti0EqIdx + activeWaterCompIdx] +=
396 Rvw * surfaceVolumeFlux *
397 FluidSystem::referenceDensity(waterPhaseIdx, pvtRegionIdx);
414 template <
class Scalar>
416 unsigned pvtRegionIdx)
418 if constexpr (!blackoilConserveSurfaceVolume) {
423 if constexpr (waterEnabled) {
424 const unsigned activeWaterCompIdx = FluidSystem::canonicalToActiveCompIdx(waterCompIdx);
425 container[conti0EqIdx + activeWaterCompIdx] *=
426 FluidSystem::referenceDensity(waterPhaseIdx, pvtRegionIdx);
429 if constexpr (gasEnabled) {
430 const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(gasCompIdx);
431 container[conti0EqIdx + activeGasCompIdx] *=
432 FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx);
435 if constexpr (oilEnabled) {
436 const unsigned activeOilCompIdx = FluidSystem::canonicalToActiveCompIdx(oilCompIdx);
437 container[conti0EqIdx + activeOilCompIdx] *=
438 FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx);
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:233
Definition: blackoilfoammodules.hh:57
void computeStorage(Dune::FieldVector< LhsEval, numEq > &storage, const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx) const
Evaluate the amount all conservation quantities (e.g.
Definition: blackoillocalresidual.hh:111
void computeFlux(RateVector &flux, const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx) const
Evaluates the total mass flux of all conservation quantities over a face of a sub-control volume...
Definition: blackoillocalresidual.hh:220
static void evalPhaseFluxes_(RateVector &flux, unsigned phaseIdx, unsigned pvtRegionIdx, const ExtensiveQuantities &extQuants, const FluidState &upFs)
Helper function to calculate the flux of mass in terms of conservation quantities via specific fluid ...
Definition: blackoillocalresidual.hh:321
static void adaptMassConservationQuantities_(Dune::FieldVector< Scalar, numEq > &container, unsigned pvtRegionIdx)
Helper function to convert the mass-related parts of a Dune::FieldVector that stores conservation qua...
Definition: blackoillocalresidual.hh:415
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Contains classes extending the black-oil model.
Definition: blackoilmodules.hpp:62
Declares the properties required by the black oil model.
Declare the properties used by the infrastructure code of the finite volume discretizations.
Calculates the local residual of the black oil model.
Definition: blackoillocalresidual.hh:50
void computeSource(RateVector &source, const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx) const
Calculate the source term of the equation.
Definition: blackoillocalresidual.hh:296
Provides the auxiliary methods required for consideration of the diffusion equation.