Loading...
Searching...
No Matches
diffusionmodule.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 OPM_DIFFUSION_MODULE_HH
#define OPM_DIFFUSION_MODULE_HH
#include <dune/common/fvector.hh>
#include <opm/material/common/Valgrind.hpp>
#include <opm/models/common/multiphasebaseproperties.hh>
#include <opm/models/common/quantitycallbacks.hh>
#include <opm/models/discretization/common/fvbaseproperties.hh>
#include <array>
#include <stdexcept>
namespace Opm {
template <class TypeTag, bool enableDiffusion>
class DiffusionModule;
template <class TypeTag>
class DiffusionModule<TypeTag, /*enableDiffusion=*/false>
{
using RateVector = GetPropType<TypeTag, Properties::RateVector>;
public:
static void registerParameters()
{}
template <class Context>
static void addDiffusiveFlux(RateVector&,
const Context&,
unsigned,
unsigned)
{}
};
template <class TypeTag>
class DiffusionModule<TypeTag, /*enableDiffusion=*/true>
{
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using Evaluation = GetPropType<TypeTag, Properties::Evaluation>;
using RateVector = GetPropType<TypeTag, Properties::RateVector>;
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
using Indices = GetPropType<TypeTag, Properties::Indices>;
enum { numPhases = FluidSystem::numPhases };
enum { numComponents = FluidSystem::numComponents };
enum { conti0EqIdx = Indices::conti0EqIdx };
using Toolbox = Opm::MathToolbox<Evaluation>;
public:
static void registerParameters()
{}
template <class Context>
static void addDiffusiveFlux(RateVector& flux, const Context& context,
unsigned spaceIdx, unsigned timeIdx)
{
const auto& extQuants = context.extensiveQuantities(spaceIdx, timeIdx);
const auto& fluidStateI = context.intensiveQuantities(extQuants.interiorIndex(), timeIdx).fluidState();
const auto& fluidStateJ = context.intensiveQuantities(extQuants.exteriorIndex(), timeIdx).fluidState();
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
// arithmetic mean of the phase's molar density
Evaluation rhoMolar = fluidStateI.molarDensity(phaseIdx);
rhoMolar += Toolbox::value(fluidStateJ.molarDensity(phaseIdx));
rhoMolar /= 2;
for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
// mass flux due to molecular diffusion
flux[conti0EqIdx + compIdx] +=
-rhoMolar
* extQuants.moleFractionGradientNormal(phaseIdx, compIdx)
* extQuants.effectiveDiffusionCoefficient(phaseIdx, compIdx);
}
}
}
};
template <class TypeTag, bool enableDiffusion>
class DiffusionIntensiveQuantities;
template <class TypeTag>
class DiffusionIntensiveQuantities<TypeTag, /*enableDiffusion=*/false>
{
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
public:
Scalar tortuosity(unsigned) const
{
throw std::logic_error("Method tortuosity() does not make sense "
"if diffusion is disabled");
}
Scalar diffusionCoefficient(unsigned, unsigned) const
{
throw std::logic_error("Method diffusionCoefficient() does not "
"make sense if diffusion is disabled");
}
Scalar effectiveDiffusionCoefficient(unsigned, unsigned) const
{
throw std::logic_error("Method effectiveDiffusionCoefficient() "
"does not make sense if diffusion is disabled");
}
protected:
template <class FluidState>
void update_(FluidState&,
typename FluidSystem::template ParameterCache<typename FluidState::Scalar>&,
const ElementContext&,
unsigned,
unsigned)
{ }
};
template <class TypeTag>
class DiffusionIntensiveQuantities<TypeTag, /*enableDiffusion=*/true>
{
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using Evaluation = GetPropType<TypeTag, Properties::Evaluation>;
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
enum { numPhases = FluidSystem::numPhases };
enum { numComponents = FluidSystem::numComponents };
public:
Evaluation diffusionCoefficient(unsigned phaseIdx, unsigned compIdx) const
{ return diffusionCoefficient_[phaseIdx][compIdx]; }
Evaluation tortuosity(unsigned phaseIdx) const
{ return tortuosity_[phaseIdx]; }
Evaluation effectiveDiffusionCoefficient(unsigned phaseIdx, unsigned compIdx) const
{ return tortuosity_[phaseIdx] * diffusionCoefficient_[phaseIdx][compIdx]; }
protected:
template <class FluidState>
void update_(FluidState& fluidState,
typename FluidSystem::template ParameterCache<typename FluidState::Scalar>& paramCache,
const ElementContext& elemCtx,
unsigned dofIdx,
unsigned timeIdx)
{
using Toolbox = Opm::MathToolbox<Evaluation>;
const auto& intQuants = elemCtx.intensiveQuantities(dofIdx, timeIdx);
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
if (!elemCtx.model().phaseIsConsidered(phaseIdx)) {
continue;
}
// TODO: let the problem do this (this is a constitutive
// relation of which the model should be free of from the
// abstraction POV!)
// Based on Millington, R. J., & Quirk, J. P. (1961).
const Evaluation& base =
Toolbox::max(0.0001,
intQuants.porosity()
* intQuants.fluidState().saturation(phaseIdx));
tortuosity_[phaseIdx] =
1.0 / (intQuants.porosity() * intQuants.porosity())
* Toolbox::pow(base, 10.0/3.0);
for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
diffusionCoefficient_[phaseIdx][compIdx] =
FluidSystem::diffusionCoefficient(fluidState,
paramCache,
phaseIdx,
compIdx);
}
}
}
private:
std::array<Evaluation, numPhases> tortuosity_;
std::array<std::array<Evaluation, numComponents>, numPhases> diffusionCoefficient_;
};
template <class TypeTag, bool enableDiffusion>
class DiffusionExtensiveQuantities;
template <class TypeTag>
class DiffusionExtensiveQuantities<TypeTag, /*enableDiffusion=*/false>
{
using Evaluation = GetPropType<TypeTag, Properties::Evaluation>;
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
protected:
void update_(const ElementContext&,
unsigned,
unsigned)
{}
template <class Context, class FluidState>
void updateBoundary_(const Context&,
unsigned,
unsigned,
const FluidState&)
{}
public:
const Evaluation& moleFractionGradientNormal(unsigned,
unsigned) const
{
throw std::logic_error("The method moleFractionGradient() does not "
"make sense if diffusion is disabled.");
}
const Evaluation& effectiveDiffusionCoefficient(unsigned,
unsigned) const
{
throw std::logic_error("The method effectiveDiffusionCoefficient() "
"does not make sense if diffusion is disabled.");
}
};
template <class TypeTag>
class DiffusionExtensiveQuantities<TypeTag, /*enableDiffusion=*/true>
{
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using Evaluation = GetPropType<TypeTag, Properties::Evaluation>;
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using GridView = GetPropType<TypeTag, Properties::GridView>;
enum { dimWorld = GridView::dimensionworld };
enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
using DimVector = Dune::FieldVector<Scalar, dimWorld>;
using DimEvalVector = Dune::FieldVector<Evaluation, dimWorld>;
protected:
void update_(const ElementContext& elemCtx, unsigned faceIdx, unsigned timeIdx)
{
const auto& gradCalc = elemCtx.gradientCalculator();
Opm::MoleFractionCallback<TypeTag> moleFractionCallback(elemCtx);
const auto& face = elemCtx.stencil(timeIdx).interiorFace(faceIdx);
const auto& normal = face.normal();
const auto& extQuants = elemCtx.extensiveQuantities(faceIdx, timeIdx);
const auto& intQuantsInside = elemCtx.intensiveQuantities(extQuants.interiorIndex(), timeIdx);
const auto& intQuantsOutside = elemCtx.intensiveQuantities(extQuants.exteriorIndex(), timeIdx);
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
if (!elemCtx.model().phaseIsConsidered(phaseIdx)) {
continue;
}
moleFractionCallback.setPhaseIndex(phaseIdx);
for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
moleFractionCallback.setComponentIndex(compIdx);
DimEvalVector moleFractionGradient(0.0);
gradCalc.calculateGradient(moleFractionGradient,
elemCtx,
faceIdx,
moleFractionCallback);
moleFractionGradientNormal_[phaseIdx][compIdx] = 0.0;
for (unsigned i = 0; i < normal.size(); ++i) {
moleFractionGradientNormal_[phaseIdx][compIdx] +=
normal[i]*moleFractionGradient[i];
}
Opm::Valgrind::CheckDefined(moleFractionGradientNormal_[phaseIdx][compIdx]);
// use the arithmetic average for the effective
// diffusion coefficients.
effectiveDiffusionCoefficient_[phaseIdx][compIdx] =
(intQuantsInside.effectiveDiffusionCoefficient(phaseIdx, compIdx)
+
intQuantsOutside.effectiveDiffusionCoefficient(phaseIdx, compIdx))
/ 2;
Opm::Valgrind::CheckDefined(effectiveDiffusionCoefficient_[phaseIdx][compIdx]);
}
}
}
template <class Context, class FluidState>
void updateBoundary_(const Context& context,
unsigned bfIdx,
unsigned timeIdx,
const FluidState& fluidState)
{
const auto& stencil = context.stencil(timeIdx);
const auto& face = stencil.boundaryFace(bfIdx);
const auto& elemCtx = context.elementContext();
const unsigned insideScvIdx = face.interiorIndex();
const auto& insideScv = stencil.subControlVolume(insideScvIdx);
const auto& intQuantsInside = elemCtx.intensiveQuantities(insideScvIdx, timeIdx);
const auto& fluidStateInside = intQuantsInside.fluidState();
// distance between the center of the SCV and center of the boundary face
DimVector distVec = face.integrationPos();
distVec -= context.element().geometry().global(insideScv.localGeometry().center());
const Scalar dist = distVec * face.normal();
// if the following assertation triggers, the center of the
// center of the interior SCV was not inside the element!
assert(dist > 0);
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
if (!elemCtx.model().phaseIsConsidered(phaseIdx)) {
continue;
}
for (unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
// calculate mole fraction gradient using two-point
// gradients
moleFractionGradientNormal_[phaseIdx][compIdx] =
(fluidState.moleFraction(phaseIdx, compIdx)
-
fluidStateInside.moleFraction(phaseIdx, compIdx))
/ dist;
Opm::Valgrind::CheckDefined(moleFractionGradientNormal_[phaseIdx][compIdx]);
// use effective diffusion coefficients of the interior finite
// volume.
effectiveDiffusionCoefficient_[phaseIdx][compIdx] =
intQuantsInside.effectiveDiffusionCoefficient(phaseIdx, compIdx);
Opm::Valgrind::CheckDefined(effectiveDiffusionCoefficient_[phaseIdx][compIdx]);
}
}
}
public:
const Evaluation& moleFractionGradientNormal(unsigned phaseIdx, unsigned compIdx) const
{ return moleFractionGradientNormal_[phaseIdx][compIdx]; }
const Evaluation& effectiveDiffusionCoefficient(unsigned phaseIdx, unsigned compIdx) const
{ return effectiveDiffusionCoefficient_[phaseIdx][compIdx]; }
private:
std::array<std::array<Evaluation, numComponents>, numPhases> moleFractionGradientNormal_;
std::array<std::array<Evaluation, numComponents>, numPhases> effectiveDiffusionCoefficient_;
};
} // namespace Opm
#endif
Opm::DiffusionExtensiveQuantities< TypeTag, false >::update_
void update_(const ElementContext &, unsigned, unsigned)
Update the quantities required to calculate the diffusive mass fluxes.
Definition diffusionmodule.hh:306
Opm::DiffusionExtensiveQuantities< TypeTag, false >::effectiveDiffusionCoefficient
const Evaluation & effectiveDiffusionCoefficient(unsigned, unsigned) const
The effective diffusion coeffcient of a component in a fluid phase at the face's integration point.
Definition diffusionmodule.hh:339
Opm::DiffusionExtensiveQuantities< TypeTag, false >::moleFractionGradientNormal
const Evaluation & moleFractionGradientNormal(unsigned, unsigned) const
The the gradient of the mole fraction times the face normal.
Definition diffusionmodule.hh:325
Opm::DiffusionExtensiveQuantities< TypeTag, true >::moleFractionGradientNormal
const Evaluation & moleFractionGradientNormal(unsigned phaseIdx, unsigned compIdx) const
The the gradient of the mole fraction times the face normal.
Definition diffusionmodule.hh:475
Opm::DiffusionExtensiveQuantities< TypeTag, true >::effectiveDiffusionCoefficient
const Evaluation & effectiveDiffusionCoefficient(unsigned phaseIdx, unsigned compIdx) const
The effective diffusion coeffcient of a component in a fluid phase at the face's integration point.
Definition diffusionmodule.hh:485
Opm::DiffusionExtensiveQuantities< TypeTag, true >::update_
void update_(const ElementContext &elemCtx, unsigned faceIdx, unsigned timeIdx)
Update the quantities required to calculate the diffusive mass fluxes.
Definition diffusionmodule.hh:370
Opm::DiffusionExtensiveQuantities
Provides the quantities required to calculate diffusive mass fluxes.
Definition diffusionmodule.hh:290
Opm::DiffusionIntensiveQuantities< TypeTag, false >::diffusionCoefficient
Scalar diffusionCoefficient(unsigned, unsigned) const
Returns the molecular diffusion coefficient for a component in a phase.
Definition diffusionmodule.hh:170
Opm::DiffusionIntensiveQuantities< TypeTag, false >::effectiveDiffusionCoefficient
Scalar effectiveDiffusionCoefficient(unsigned, unsigned) const
Returns the effective molecular diffusion coefficient of the porous medium for a component in a phase...
Definition diffusionmodule.hh:180
Opm::DiffusionIntensiveQuantities< TypeTag, false >::update_
void update_(FluidState &, typename FluidSystem::template ParameterCache< typename FluidState::Scalar > &, const ElementContext &, unsigned, unsigned)
Update the quantities required to calculate diffusive mass fluxes.
Definition diffusionmodule.hh:192
Opm::DiffusionIntensiveQuantities< TypeTag, false >::tortuosity
Scalar tortuosity(unsigned) const
Returns the tortuousity of the sub-domain of a fluid phase in the porous medium.
Definition diffusionmodule.hh:160
Opm::DiffusionIntensiveQuantities< TypeTag, true >::tortuosity
Evaluation tortuosity(unsigned phaseIdx) const
Returns the tortuousity of the sub-domain of a fluid phase in the porous medium.
Definition diffusionmodule.hh:226
Opm::DiffusionIntensiveQuantities< TypeTag, true >::update_
void update_(FluidState &fluidState, typename FluidSystem::template ParameterCache< typename FluidState::Scalar > &paramCache, const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Update the quantities required to calculate diffusive mass fluxes.
Definition diffusionmodule.hh:242
Opm::DiffusionIntensiveQuantities< TypeTag, true >::effectiveDiffusionCoefficient
Evaluation effectiveDiffusionCoefficient(unsigned phaseIdx, unsigned compIdx) const
Returns the effective molecular diffusion coefficient of the porous medium for a component in a phase...
Definition diffusionmodule.hh:233
Opm::DiffusionIntensiveQuantities< TypeTag, true >::diffusionCoefficient
Evaluation diffusionCoefficient(unsigned phaseIdx, unsigned compIdx) const
Returns the molecular diffusion coefficient for a component in a phase.
Definition diffusionmodule.hh:219
Opm::DiffusionIntensiveQuantities
Provides the volumetric quantities required for the calculation of molecular diffusive fluxes.
Definition diffusionmodule.hh:143
Opm::DiffusionModule< TypeTag, false >::addDiffusiveFlux
static void addDiffusiveFlux(RateVector &, const Context &, unsigned, unsigned)
Adds the diffusive mass flux flux to the flux vector over a flux integration point.
Definition diffusionmodule.hh:73
Opm::DiffusionModule< TypeTag, false >::registerParameters
static void registerParameters()
Register all run-time parameters for the diffusion module.
Definition diffusionmodule.hh:65
Opm::DiffusionModule< TypeTag, true >::addDiffusiveFlux
static void addDiffusiveFlux(RateVector &flux, const Context &context, unsigned spaceIdx, unsigned timeIdx)
Adds the mass flux due to molecular diffusion to the flux vector over the flux integration point.
Definition diffusionmodule.hh:110
Opm::DiffusionModule< TypeTag, true >::registerParameters
static void registerParameters()
Register all run-time parameters for the diffusion module.
Definition diffusionmodule.hh:102
Opm::DiffusionModule
Provides the auxiliary methods required for consideration of the diffusion equation.
Definition diffusionmodule.hh:51
Opm::MoleFractionCallback
Callback class for a mole fraction of a component in a phase.
Definition quantitycallbacks.hh:422
Opm::MoleFractionCallback::setComponentIndex
void setComponentIndex(unsigned compIdx)
Set the index of the component for which the mole fraction should be returned.
Definition quantitycallbacks.hh:457
Opm::MoleFractionCallback::setPhaseIndex
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which a mole fraction should be returned.
Definition quantitycallbacks.hh:450
fvbaseproperties.hh
Declare the properties used by the infrastructure code of the finite volume discretizations.
multiphasebaseproperties.hh
Defines the common properties required by the porous medium multi-phase models.
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
quantitycallbacks.hh
This method contains all callback classes for quantities that are required by some extensive quantiti...