24#ifndef DUMUX_DISCRETIZATION_CC_TPFA_FICKS_LAW_HH
25#define DUMUX_DISCRETIZATION_CC_TPFA_FICKS_LAW_HH
27#include <dune/common/fvector.hh>
42template<
class TypeTag, DiscretizationMethod discMethod, ReferenceSystemFormulation referenceSystem>
43class FicksLawImplementation;
49template <
class TypeTag, ReferenceSystemFormulation referenceSystem>
56 using FVElementGeometry =
typename GridGeometry::LocalView;
57 using SubControlVolumeFace =
typename GridGeometry::SubControlVolumeFace;
59 using GridView =
typename GridGeometry::GridView;
61 using VolumeVariables =
typename ElementVolumeVariables::VolumeVariables;
62 using Element =
typename GridView::template Codim<0>::Entity;
68 static const int dim = GridView::dimension;
69 static const int dimWorld = GridView::dimensionworld;
70 static const int numPhases = ModelTraits::numFluidPhases();
71 static const int numComponents = ModelTraits::numFluidComponents();
73 using ComponentFluxVector = Dune::FieldVector<Scalar, numComponents>;
76 class TpfaFicksLawCacheFiller
81 template<
class FluxVariablesCacheFiller>
82 static void fill(FluxVariablesCache& scvfFluxVarsCache,
83 unsigned int phaseIdx,
unsigned int compIdx,
84 const Problem& problem,
85 const Element& element,
86 const FVElementGeometry& fvGeometry,
87 const ElementVolumeVariables& elemVolVars,
88 const SubControlVolumeFace& scvf,
89 const FluxVariablesCacheFiller& fluxVarsCacheFiller)
91 scvfFluxVarsCache.updateDiffusion(problem, element, fvGeometry, elemVolVars, scvf, phaseIdx, compIdx);
96 class TpfaFicksLawCache
99 using Filler = TpfaFicksLawCacheFiller;
101 void updateDiffusion(
const Problem& problem,
102 const Element& element,
103 const FVElementGeometry& fvGeometry,
104 const ElementVolumeVariables& elemVolVars,
105 const SubControlVolumeFace &scvf,
106 const unsigned int phaseIdx,
107 const unsigned int compIdx)
109 tij_[phaseIdx][compIdx] = Implementation::calculateTransmissibility(problem, element, fvGeometry, elemVolVars, scvf, phaseIdx, compIdx);
112 const Scalar& diffusionTij(
unsigned int phaseIdx,
unsigned int compIdx)
const
113 {
return tij_[phaseIdx][compIdx]; }
116 std::array< std::array<Scalar, numComponents>, numPhases> tij_;
124 {
return referenceSystem; }
141 static ComponentFluxVector
flux(
const Problem& problem,
142 const Element& element,
143 const FVElementGeometry& fvGeometry,
144 const VolumeVariables& insideVolVars,
145 const VolumeVariables& outsideVolVars,
146 const SubControlVolumeFace& scvf,
148 const ElementFluxVariablesCache& elemFluxVarsCache)
150 if constexpr (isMixedDimensional_)
151 if (scvf.numOutsideScv() != 1)
152 DUNE_THROW(Dune::Exception,
"This flux overload requires scvf.numOutsideScv() == 1");
155 const auto getOutsideX = [&](
const Scalar xInside,
const Scalar tij,
const int phaseIdx,
const int compIdx)
161 const auto getRho = [&](
const int phaseIdx,
const Scalar rhoInside,
const Scalar rhoOutside)
163 return 0.5*(rhoInside + rhoOutside);
166 return flux_(element, fvGeometry, insideVolVars, outsideVolVars, elemFluxVarsCache, scvf, phaseIdx, getOutsideX, getRho);
176 static ComponentFluxVector
flux(
const Problem& problem,
177 const Element& element,
178 const FVElementGeometry& fvGeometry,
179 const ElementVolumeVariables& elemVolVars,
180 const SubControlVolumeFace& scvf,
182 const ElementFluxVariablesCache& elemFluxVarsCache)
185 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
186 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
189 const auto getOutsideX = [&](
const Scalar xInside,
const Scalar tij,
const int phaseIdx,
const int compIdx)
191 const Scalar massOrMoleFractionOutside =
massOrMoleFraction(outsideVolVars, referenceSystem, phaseIdx, compIdx);
192 if constexpr (isMixedDimensional_)
194 return scvf.numOutsideScvs() == 1 ? massOrMoleFractionOutside
195 : branchingFacetX_(problem, element, fvGeometry, elemVolVars,
196 elemFluxVarsCache, scvf, xInside, tij, phaseIdx, compIdx);
199 return massOrMoleFractionOutside;
203 const auto getRho = [&](
const int phaseIdx,
const Scalar rhoInside,
const Scalar rhoOutside)
205 if constexpr (isMixedDimensional_)
207 return scvf.numOutsideScvs() == 1 ? 0.5*(rhoInside + rhoOutside)
208 : branchingFacetDensity_(elemVolVars, scvf, phaseIdx, rhoInside);
211 return 0.5*(rhoInside + rhoOutside);
214 return flux_(element, fvGeometry, insideVolVars, outsideVolVars, elemFluxVarsCache, scvf, phaseIdx, getOutsideX, getRho);
219 const Element& element,
220 const FVElementGeometry& fvGeometry,
221 const ElementVolumeVariables& elemVolVars,
222 const SubControlVolumeFace& scvf,
223 const int phaseIdx,
const int compIdx)
227 const auto insideScvIdx = scvf.insideScvIdx();
228 const auto& insideScv = fvGeometry.scv(insideScvIdx);
229 const auto& insideVolVars = elemVolVars[insideScvIdx];
230 const auto getDiffCoeff = [&](
const auto& vv)
232 using FluidSystem =
typename ElementVolumeVariables::VolumeVariables::FluidSystem;
233 if constexpr (FluidSystem::isTracerFluidSystem())
234 return vv.effectiveDiffusionCoefficient(0, 0, compIdx);
236 return vv.effectiveDiffusionCoefficient(phaseIdx, FluidSystem::getMainComponent(phaseIdx), compIdx);
239 const auto insideD = getDiffCoeff(insideVolVars);
245 if (scvf.boundary() || scvf.numOutsideScvs() > 1)
246 tij = Extrusion::area(scvf)*ti;
251 const auto outsideScvIdx = scvf.outsideScvIdx();
252 const auto& outsideScv = fvGeometry.scv(outsideScvIdx);
253 const auto& outsideVolVars = elemVolVars[outsideScvIdx];
254 const auto outsideD = getDiffCoeff(outsideVolVars);
257 if constexpr (dim == dimWorld)
264 outsideVolVars.extrusionFactor());
270 tij = Extrusion::area(scvf)*(ti * tj)/(ti + tj);
277 template<
class Outs
ideFractionHelper,
class DensityHelper>
278 static ComponentFluxVector flux_(
const Element& element,
279 const FVElementGeometry& fvGeometry,
280 const VolumeVariables& insideVolVars,
281 const VolumeVariables& outsideVolVars,
282 const ElementFluxVariablesCache& elemFluxVarsCache,
283 const SubControlVolumeFace& scvf,
285 const OutsideFractionHelper& getOutsideX,
286 const DensityHelper& getRho)
288 ComponentFluxVector componentFlux(0.0);
289 for (
int compIdx = 0; compIdx < numComponents; compIdx++)
291 using FluidSystem =
typename VolumeVariables::FluidSystem;
292 if constexpr (!FluidSystem::isTracerFluidSystem())
293 if (compIdx == FluidSystem::getMainComponent(phaseIdx))
297 const Scalar tij = elemFluxVarsCache[scvf].diffusionTij(phaseIdx, compIdx);
300 const Scalar xInside =
massOrMoleFraction(insideVolVars, referenceSystem, phaseIdx, compIdx);
301 const Scalar xOutside = getOutsideX(xInside, tij, phaseIdx, compIdx);
303 const Scalar rhoInside =
massOrMolarDensity(insideVolVars, referenceSystem, phaseIdx);
304 const Scalar rhoOutside =
massOrMolarDensity(outsideVolVars, referenceSystem, phaseIdx);
306 const Scalar rho = getRho(phaseIdx, rhoInside, rhoOutside);
308 componentFlux[compIdx] = rho*tij*(xInside - xOutside);
309 if constexpr (!FluidSystem::isTracerFluidSystem())
310 if (BalanceEqOpts::mainComponentIsBalanced(phaseIdx))
311 componentFlux[FluidSystem::getMainComponent(phaseIdx)] -= componentFlux[compIdx];
314 return componentFlux;
318 static Scalar branchingFacetX_(
const Problem& problem,
319 const Element& element,
320 const FVElementGeometry& fvGeometry,
321 const ElementVolumeVariables& elemVolVars,
322 const ElementFluxVariablesCache& elemFluxVarsCache,
323 const SubControlVolumeFace& scvf,
324 const Scalar insideX,
const Scalar insideTi,
325 const int phaseIdx,
const int compIdx)
327 Scalar sumTi(insideTi);
328 Scalar sumXTi(insideTi*insideX);
330 for (
unsigned int i = 0; i < scvf.numOutsideScvs(); ++i)
332 const auto outsideScvIdx = scvf.outsideScvIdx(i);
333 const auto& outsideVolVars = elemVolVars[outsideScvIdx];
334 const Scalar massOrMoleFractionOutside =
massOrMoleFraction(outsideVolVars, referenceSystem, phaseIdx, compIdx);
335 const auto& flippedScvf = fvGeometry.flipScvf(scvf.index(), i);
337 const Scalar outsideTi = elemFluxVarsCache[flippedScvf].diffusionTij(phaseIdx, compIdx);
339 sumXTi += outsideTi*massOrMoleFractionOutside;
342 return sumTi > 0 ? sumXTi/sumTi : 0;
346 static Scalar branchingFacetDensity_(
const ElementVolumeVariables& elemVolVars,
347 const SubControlVolumeFace& scvf,
349 const Scalar insideRho)
351 Scalar rho(insideRho);
352 for (
unsigned int i = 0; i < scvf.numOutsideScvs(); ++i)
354 const auto outsideScvIdx = scvf.outsideScvIdx(i);
355 const auto& outsideVolVars = elemVolVars[outsideScvIdx];
356 const Scalar rhoOutside =
massOrMolarDensity(outsideVolVars, referenceSystem, phaseIdx);
359 return rho/(scvf.numOutsideScvs()+1);
362 static constexpr bool isMixedDimensional_ =
static_cast<int>(GridView::dimension) <
static_cast<int>(GridView::dimensionworld);
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
The available discretization methods in Dumux.
Helper classes to compute the integration elements.
The reference frameworks and formulations available for splitting total fluxes into a advective and d...
Container storing the diffusion coefficients required by Fick's law. Uses the minimal possible contai...
DiscretizationMethod
The available discretization methods in Dumux.
Definition: method.hh:37
Tensor::field_type computeTpfaTransmissibility(const SubControlVolumeFace &scvf, const SubControlVolume &scv, const Tensor &T, typename SubControlVolume::Traits::Scalar extrusionFactor)
Free function to evaluate the Tpfa transmissibility associated with the flux (in the form of flux = T...
Definition: tpfa/computetransmissibility.hh:47
VolumeVariables::PrimaryVariables::value_type massOrMoleFraction(const VolumeVariables &volVars, ReferenceSystemFormulation referenceSys, const int phaseIdx, const int compIdx)
returns the mass or mole fraction to be used in Fick's law based on the reference system
Definition: referencesystemformulation.hh:66
VolumeVariables::PrimaryVariables::value_type massOrMolarDensity(const VolumeVariables &volVars, ReferenceSystemFormulation referenceSys, const int phaseIdx)
evaluates the density to be used in Fick's law based on the reference system
Definition: referencesystemformulation.hh:55
ReferenceSystemFormulation
The formulations available for Fick's law related to the reference system.
Definition: referencesystemformulation.hh:45
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition: extrusion.hh:177
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:150
forward declaration of the method-specific implemetation
Definition: flux/box/fickslaw.hh:43
Fick's law for cell-centered finite volume schemes with two-point flux approximation.
Definition: flux/cctpfa/fickslaw.hh:51
static Scalar calculateTransmissibility(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const int phaseIdx, const int compIdx)
compute diffusive transmissibilities
Definition: flux/cctpfa/fickslaw.hh:218
static constexpr ReferenceSystemFormulation referenceSystemFormulation()
Return the reference system.
Definition: flux/cctpfa/fickslaw.hh:123
static ComponentFluxVector flux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const VolumeVariables &insideVolVars, const VolumeVariables &outsideVolVars, const SubControlVolumeFace &scvf, const int phaseIdx, const ElementFluxVariablesCache &elemFluxVarsCache)
Returns the diffusive fluxes of all components within a fluid phase across the given sub-control volu...
Definition: flux/cctpfa/fickslaw.hh:141
TpfaFicksLawCache Cache
state the type for the corresponding cache and its filler
Definition: flux/cctpfa/fickslaw.hh:127
static ComponentFluxVector flux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const int phaseIdx, const ElementFluxVariablesCache &elemFluxVarsCache)
Returns the diffusive fluxes of all components within a fluid phase across the given sub-control volu...
Definition: flux/cctpfa/fickslaw.hh:176
Container storing the diffusion coefficients required by Fick's law. Uses the minimal possible contai...
Definition: fickiandiffusioncoefficients.hh:44
Declares all properties used in Dumux.
Free functions to evaluate the transmissibilities associated with flux evaluations across sub-control...