Loading...
Searching...
No Matches
blackoillocalresidual.hh
Go to the documentation of this file.
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#ifndef EWOMS_BLACK_OIL_LOCAL_RESIDUAL_HH
#define EWOMS_BLACK_OIL_LOCAL_RESIDUAL_HH
#include <opm/material/common/MathToolbox.hpp>
#include <opm/material/fluidstates/BlackOilFluidState.hpp>
#include <opm/models/blackoil/blackoilbioeffectsmodules.hh>
#include <opm/models/blackoil/blackoilbrinemodules.hh>
#include <opm/models/blackoil/blackoilconvectivemixingmodule.hh>
#include <opm/models/blackoil/blackoildiffusionmodule.hh>
#include <opm/models/blackoil/blackoilenergymodules.hh>
#include <opm/models/blackoil/blackoilextbomodules.hh>
#include <opm/models/blackoil/blackoilfoammodules.hh>
#include <opm/models/blackoil/blackoilpolymermodules.hh>
#include <opm/models/blackoil/blackoilproperties.hh>
#include <opm/models/blackoil/blackoilsolventmodules.hh>
#include <cassert>
namespace Opm {
template <class TypeTag>
class BlackOilLocalResidual : public GetPropType<TypeTag, Properties::DiscLocalResidual>
{
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
using ExtensiveQuantities = GetPropType<TypeTag, Properties::ExtensiveQuantities>;
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using Indices = GetPropType<TypeTag, Properties::Indices>;
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using Evaluation = GetPropType<TypeTag, Properties::Evaluation>;
using RateVector = GetPropType<TypeTag, Properties::RateVector>;
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
enum { conti0EqIdx = Indices::conti0EqIdx };
enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
enum { gasCompIdx = FluidSystem::gasCompIdx };
enum { oilCompIdx = FluidSystem::oilCompIdx };
enum { waterCompIdx = FluidSystem::waterCompIdx };
enum { compositionSwitchIdx = Indices::compositionSwitchIdx };
static constexpr bool waterEnabled = Indices::waterEnabled;
static constexpr bool gasEnabled = Indices::gasEnabled;
static constexpr bool oilEnabled = Indices::oilEnabled;
static constexpr bool compositionSwitchEnabled = (compositionSwitchIdx >= 0);
static constexpr bool blackoilConserveSurfaceVolume = getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>();
static constexpr bool enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>();
static constexpr bool enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>();
static constexpr bool enableConvectiveMixing = getPropValue<TypeTag, Properties::EnableConvectiveMixing>();
using Toolbox = MathToolbox<Evaluation>;
using SolventModule = BlackOilSolventModule<TypeTag>;
using ExtboModule = BlackOilExtboModule<TypeTag>;
using PolymerModule = BlackOilPolymerModule<TypeTag>;
using EnergyModule = BlackOilEnergyModule<TypeTag>;
using FoamModule = BlackOilFoamModule<TypeTag>;
using BrineModule = BlackOilBrineModule<TypeTag>;
using DiffusionModule = BlackOilDiffusionModule<TypeTag, enableDiffusion>;
using BioeffectsModule = BlackOilBioeffectsModule<TypeTag>;
using ConvectiveMixingModule = BlackOilConvectiveMixingModule<TypeTag, enableConvectiveMixing>;
public:
template <class LhsEval>
void computeStorage(Dune::FieldVector<LhsEval, numEq>& storage,
const ElementContext& elemCtx,
unsigned dofIdx,
unsigned timeIdx) const
{
// retrieve the intensive quantities for the SCV at the specified point in time
const IntensiveQuantities& intQuants = elemCtx.intensiveQuantities(dofIdx, timeIdx);
const auto& fs = intQuants.fluidState();
storage = 0.0;
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
if (!FluidSystem::phaseIsActive(phaseIdx)) {
if (Indices::numPhases == 3) { // add trivial equation for the pseudo phase
const unsigned activeCompIdx =
FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
if (timeIdx == 0) {
storage[conti0EqIdx + activeCompIdx] = variable<LhsEval>(0.0, conti0EqIdx + activeCompIdx);
}
else {
storage[conti0EqIdx + activeCompIdx] = 0.0;
}
}
continue;
}
const unsigned activeCompIdx =
FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
const LhsEval surfaceVolume =
Toolbox::template decay<LhsEval>(fs.saturation(phaseIdx)) *
Toolbox::template decay<LhsEval>(fs.invB(phaseIdx)) *
Toolbox::template decay<LhsEval>(intQuants.porosity());
storage[conti0EqIdx + activeCompIdx] += surfaceVolume;
// account for dissolved gas
if (phaseIdx == oilPhaseIdx && FluidSystem::enableDissolvedGas()) {
const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(gasCompIdx);
storage[conti0EqIdx + activeGasCompIdx] +=
Toolbox::template decay<LhsEval>(intQuants.fluidState().Rs()) *
surfaceVolume;
}
// account for dissolved gas in water phase
if (phaseIdx == waterPhaseIdx && FluidSystem::enableDissolvedGasInWater()) {
const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(gasCompIdx);
storage[conti0EqIdx + activeGasCompIdx] +=
Toolbox::template decay<LhsEval>(intQuants.fluidState().Rsw()) *
surfaceVolume;
}
// account for vaporized oil
if (phaseIdx == gasPhaseIdx && FluidSystem::enableVaporizedOil()) {
const unsigned activeOilCompIdx = FluidSystem::canonicalToActiveCompIdx(oilCompIdx);
storage[conti0EqIdx + activeOilCompIdx] +=
Toolbox::template decay<LhsEval>(intQuants.fluidState().Rv()) *
surfaceVolume;
}
// account for vaporized water
if (phaseIdx == gasPhaseIdx && FluidSystem::enableVaporizedWater()) {
const unsigned activeWaterCompIdx = FluidSystem::canonicalToActiveCompIdx(waterCompIdx);
storage[conti0EqIdx + activeWaterCompIdx] +=
Toolbox::template decay<LhsEval>(intQuants.fluidState().Rvw()) *
surfaceVolume;
}
}
adaptMassConservationQuantities_(storage, intQuants.pvtRegionIndex());
// deal with solvents (if present)
SolventModule::addStorage(storage, intQuants);
// deal with zFracton (if present)
ExtboModule::addStorage(storage, intQuants);
// deal with polymer (if present)
PolymerModule::addStorage(storage, intQuants);
// deal with energy (if present)
EnergyModule::addStorage(storage, intQuants);
// deal with foam (if present)
FoamModule::addStorage(storage, intQuants);
// deal with salt (if present)
BrineModule::addStorage(storage, intQuants);
// deal with bioeffects (if present)
BioeffectsModule::addStorage(storage, intQuants);
}
void computeFlux(RateVector& flux,
const ElementContext& elemCtx,
unsigned scvfIdx,
unsigned timeIdx) const
{
assert(timeIdx == 0);
flux = 0.0;
const ExtensiveQuantities& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
unsigned focusDofIdx = elemCtx.focusDofIndex();
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
if (!FluidSystem::phaseIsActive(phaseIdx)) {
continue;
}
const unsigned upIdx = static_cast<unsigned>(extQuants.upstreamIndex(phaseIdx));
const IntensiveQuantities& up = elemCtx.intensiveQuantities(upIdx, timeIdx);
const unsigned pvtRegionIdx = up.pvtRegionIndex();
if (upIdx == focusDofIdx) {
evalPhaseFluxes_<Evaluation>(flux, phaseIdx, pvtRegionIdx, extQuants, up.fluidState());
}
else {
evalPhaseFluxes_<Scalar>(flux, phaseIdx, pvtRegionIdx, extQuants, up.fluidState());
}
}
// deal with solvents (if present)
SolventModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
// deal with zFracton (if present)
ExtboModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
// deal with polymer (if present)
PolymerModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
// deal with energy (if present)
EnergyModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
// deal with foam (if present)
FoamModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
// deal with salt (if present)
BrineModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
// deal with bioeffects (if present)
BioeffectsModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
// deal with diffusion (if present)
DiffusionModule::addDiffusiveFlux(flux, elemCtx, scvfIdx, timeIdx);
// deal with convective mixing (if enabled)
ConvectiveMixingModule::addConvectiveMixingFlux(flux, elemCtx, scvfIdx, timeIdx);
}
void computeSource(RateVector& source,
const ElementContext& elemCtx,
unsigned dofIdx,
unsigned timeIdx) const
{
// retrieve the source term intrinsic to the problem
elemCtx.problem().source(source, elemCtx, dofIdx, timeIdx);
// deal with MICP (if present)
BioeffectsModule::addSource(source, elemCtx, dofIdx, timeIdx);
// scale the source term of the energy equation
if constexpr (enableEnergy) {
source[Indices::contiEnergyEqIdx] *=
getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>();
}
}
template <class UpEval, class FluidState>
static void evalPhaseFluxes_(RateVector& flux,
unsigned phaseIdx,
unsigned pvtRegionIdx,
const ExtensiveQuantities& extQuants,
const FluidState& upFs)
{
const auto& invB = getInvB_<FluidSystem, FluidState, UpEval>(upFs, phaseIdx, pvtRegionIdx);
const auto& surfaceVolumeFlux = invB*extQuants.volumeFlux(phaseIdx);
const unsigned activeCompIdx =
FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
if constexpr (blackoilConserveSurfaceVolume) {
flux[conti0EqIdx + activeCompIdx] += surfaceVolumeFlux;
}
else {
flux[conti0EqIdx + activeCompIdx] += surfaceVolumeFlux *
FluidSystem::referenceDensity(phaseIdx, pvtRegionIdx);
}
if (phaseIdx == oilPhaseIdx) {
// dissolved gas (in the oil phase).
if (FluidSystem::enableDissolvedGas()) {
const auto& Rs = BlackOil::getRs_<FluidSystem, FluidState, UpEval>(upFs, pvtRegionIdx);
const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(gasCompIdx);
if constexpr (blackoilConserveSurfaceVolume) {
flux[conti0EqIdx + activeGasCompIdx] += Rs * surfaceVolumeFlux;
}
else {
flux[conti0EqIdx + activeGasCompIdx] +=
Rs * surfaceVolumeFlux *
FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx);
}
}
} else if (phaseIdx == waterPhaseIdx) {
// dissolved gas (in the water phase).
if (FluidSystem::enableDissolvedGasInWater()) {
const auto& Rsw = BlackOil::getRsw_<FluidSystem, FluidState, UpEval>(upFs, pvtRegionIdx);
const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(gasCompIdx);
if constexpr (blackoilConserveSurfaceVolume) {
flux[conti0EqIdx + activeGasCompIdx] += Rsw * surfaceVolumeFlux;
}
else {
flux[conti0EqIdx + activeGasCompIdx] +=
Rsw * surfaceVolumeFlux *
FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx);
}
}
}
else if (phaseIdx == gasPhaseIdx) {
// vaporized oil (in the gas phase).
if (FluidSystem::enableVaporizedOil()) {
const auto& Rv = BlackOil::getRv_<FluidSystem, FluidState, UpEval>(upFs, pvtRegionIdx);
const unsigned activeOilCompIdx = FluidSystem::canonicalToActiveCompIdx(oilCompIdx);
if constexpr (blackoilConserveSurfaceVolume) {
flux[conti0EqIdx + activeOilCompIdx] += Rv * surfaceVolumeFlux;
}
else {
flux[conti0EqIdx + activeOilCompIdx] +=
Rv * surfaceVolumeFlux *
FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx);
}
}
// vaporized water (in the gas phase).
if (FluidSystem::enableVaporizedWater()) {
const auto& Rvw = BlackOil::getRvw_<FluidSystem, FluidState, UpEval>(upFs, pvtRegionIdx);
const unsigned activeWaterCompIdx = FluidSystem::canonicalToActiveCompIdx(waterCompIdx);
if constexpr (blackoilConserveSurfaceVolume) {
flux[conti0EqIdx + activeWaterCompIdx] += Rvw * surfaceVolumeFlux;
}
else {
flux[conti0EqIdx + activeWaterCompIdx] +=
Rvw * surfaceVolumeFlux *
FluidSystem::referenceDensity(waterPhaseIdx, pvtRegionIdx);
}
}
}
}
template <class Scalar>
static void adaptMassConservationQuantities_(Dune::FieldVector<Scalar, numEq>& container,
unsigned pvtRegionIdx)
{
if constexpr (!blackoilConserveSurfaceVolume) {
// convert "surface volume" to mass. this is complicated a bit by the fact that
// not all phases are necessarily enabled. (we here assume that if a fluid phase
// is disabled, its respective "main" component is not considered as well.)
if constexpr (waterEnabled) {
const unsigned activeWaterCompIdx = FluidSystem::canonicalToActiveCompIdx(waterCompIdx);
container[conti0EqIdx + activeWaterCompIdx] *=
FluidSystem::referenceDensity(waterPhaseIdx, pvtRegionIdx);
}
if constexpr (gasEnabled) {
const unsigned activeGasCompIdx = FluidSystem::canonicalToActiveCompIdx(gasCompIdx);
container[conti0EqIdx + activeGasCompIdx] *=
FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx);
}
if constexpr (oilEnabled) {
const unsigned activeOilCompIdx = FluidSystem::canonicalToActiveCompIdx(oilCompIdx);
container[conti0EqIdx + activeOilCompIdx] *=
FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx);
}
}
}
};
} // namespace Opm
#endif
blackoilbioeffectsmodules.hh
Contains the classes required to extend the black-oil model by bioeffects.
blackoilbrinemodules.hh
Contains the classes required to extend the black-oil model by brine.
blackoilconvectivemixingmodule.hh
Classes required for dynamic convective mixing.
blackoildiffusionmodule.hh
Classes required for molecular diffusion.
blackoilenergymodules.hh
Contains the classes required to extend the black-oil model by energy.
blackoilextbomodules.hh
Contains the classes required to extend the black-oil model by solvent component.
blackoilfoammodules.hh
Contains the classes required to extend the black-oil model to include the effects of foam.
blackoilpolymermodules.hh
Contains the classes required to extend the black-oil model by polymer.
blackoilproperties.hh
Declares the properties required by the black oil model.
blackoilsolventmodules.hh
Contains the classes required to extend the black-oil model by solvents.
Opm::BlackOilBioeffectsModule
Contains the high level supplements required to extend the black oil model by bioeffects.
Definition blackoilbioeffectsmodules.hh:93
Opm::BlackOilBrineModule
Contains the high level supplements required to extend the black oil model by brine.
Definition blackoilbrinemodules.hh:56
Opm::BlackOilConvectiveMixingModule
Definition blackoilconvectivemixingmodule.hh:64
Opm::BlackOilDiffusionModule
Provides the auxiliary methods required for consideration of the diffusion equation.
Definition blackoildiffusionmodule.hh:50
Opm::BlackOilEnergyModule
Contains the high level supplements required to extend the black oil model by energy.
Definition blackoilenergymodules.hh:58
Opm::BlackOilExtboModule
Contains the high level supplements required to extend the black oil model.
Definition blackoilextbomodules.hh:62
Opm::BlackOilFoamModule
Contains the high level supplements required to extend the black oil model to include the effects of ...
Definition blackoilfoammodules.hh:58
Opm::BlackOilLocalResidual
Calculates the local residual of the black oil model.
Definition blackoillocalresidual.hh:56
Opm::BlackOilLocalResidual::computeFlux
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:201
Opm::BlackOilLocalResidual::computeSource
void computeSource(RateVector &source, const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx) const
Calculate the source term of the equation.
Definition blackoillocalresidual.hh:258
Opm::BlackOilLocalResidual::evalPhaseFluxes_
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:281
Opm::BlackOilLocalResidual::adaptMassConservationQuantities_
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:375
Opm::BlackOilLocalResidual::computeStorage
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:106
Opm::BlackOilPolymerModule
Contains the high level supplements required to extend the black oil model by polymer.
Definition blackoilpolymermodules.hh:64
Opm::BlackOilSolventModule
Contains the high level supplements required to extend the black oil model by solvents.
Definition blackoilsolventmodules.hh:68
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::GetPropType
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
Opm::getPropValue
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:240