14#ifndef DUMUX_COMPOSITIONAL_LOCAL_RESIDUAL_HH
15#define DUMUX_COMPOSITIONAL_LOCAL_RESIDUAL_HH
18#include <dune/common/exceptions.hh>
32template<
class TypeTag>
40 using FVElementGeometry =
typename GridGeometry::LocalView;
41 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
42 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
46 using GridView =
typename GridGeometry::GridView;
47 using Element =
typename GridView::template Codim<0>::Entity;
53 using Indices =
typename ModelTraits::Indices;
55 static constexpr int numPhases = ModelTraits::numFluidPhases();
56 static constexpr int numComponents = ModelTraits::numFluidComponents();
57 static constexpr bool useMoles = ModelTraits::useMoles();
59 enum { conti0EqIdx = Indices::conti0EqIdx };
62 static constexpr int replaceCompEqIdx = ModelTraits::replaceCompEqIdx();
63 static constexpr bool useTotalMoleOrMassBalance = replaceCompEqIdx < numComponents;
66 using ParentType::ParentType;
80 const SubControlVolume& scv,
81 const VolumeVariables& volVars)
const
83 NumEqVector storage(0.0);
85 const auto massOrMoleDensity = [](
const auto& volVars,
const int phaseIdx)
86 {
return useMoles ? volVars.molarDensity(phaseIdx) : volVars.density(phaseIdx); };
88 const auto massOrMoleFraction= [](
const auto& volVars,
const int phaseIdx,
const int compIdx)
89 {
return useMoles ? volVars.moleFraction(phaseIdx, compIdx) : volVars.massFraction(phaseIdx, compIdx); };
92 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
94 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
96 auto eqIdx = conti0EqIdx + compIdx;
97 if (eqIdx != replaceCompEqIdx)
98 storage[eqIdx] += volVars.porosity()
99 * volVars.saturation(phaseIdx)
100 * massOrMoleDensity(volVars, phaseIdx)
105 if (useTotalMoleOrMassBalance)
106 storage[replaceCompEqIdx] += massOrMoleDensity(volVars, phaseIdx)
108 * volVars.saturation(phaseIdx);
111 EnergyLocalResidual::fluidPhaseStorage(storage, problem, scv, volVars, phaseIdx);
115 EnergyLocalResidual::solidPhaseStorage(storage, scv, volVars);
132 const Element& element,
133 const FVElementGeometry& fvGeometry,
134 const ElementVolumeVariables& elemVolVars,
135 const SubControlVolumeFace& scvf,
136 const ElementFluxVariablesCache& elemFluxVarsCache)
const
138 FluxVariables fluxVars;
139 fluxVars.init(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
140 static constexpr auto referenceSystemFormulationDiffusion = FluxVariables::MolecularDiffusionType::referenceSystemFormulation();
142 NumEqVector flux(0.0);
144 const auto massOrMoleDensity = [](
const auto& volVars,
const int phaseIdx)
145 {
return useMoles ? volVars.molarDensity(phaseIdx) : volVars.density(phaseIdx); };
147 const auto massOrMoleFraction = [](
const auto& volVars,
const int phaseIdx,
const int compIdx)
148 {
return useMoles ? volVars.moleFraction(phaseIdx, compIdx) : volVars.massFraction(phaseIdx, compIdx); };
151 const auto adaptFluxUnits = [](
const Scalar referenceFlux,
const Scalar molarMass,
155 return useMoles ? referenceFlux/molarMass
158 return useMoles ? referenceFlux
159 : referenceFlux*molarMass;
161 DUNE_THROW(Dune::NotImplemented,
"other reference systems than mass and molar averaged are not implemented");
164 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
166 const auto diffusiveFluxes = fluxVars.molecularDiffusionFlux(phaseIdx);
167 auto dispersiveFluxes =
decltype(diffusiveFluxes)(0.0);
168 if constexpr (ModelTraits::enableCompositionalDispersion())
169 dispersiveFluxes = fluxVars.compositionalDispersionFlux(phaseIdx);
171 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
174 const auto eqIdx = conti0EqIdx + compIdx;
177 const auto upwindTerm = [&massOrMoleDensity, &
massOrMoleFraction, phaseIdx, compIdx] (
const auto& volVars)
178 {
return massOrMoleDensity(volVars, phaseIdx)*
massOrMoleFraction(volVars, phaseIdx, compIdx)*volVars.mobility(phaseIdx); };
181 if (eqIdx != replaceCompEqIdx)
182 flux[eqIdx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
185 auto diffusiveAndDispersiveFluxes = adaptFluxUnits(diffusiveFluxes[compIdx],
186 FluidSystem::molarMass(compIdx),
187 referenceSystemFormulationDiffusion);
188 if constexpr (ModelTraits::enableCompositionalDispersion())
190 static constexpr auto referenceSystemFormulationDispersion =
191 FluxVariables::DispersionFluxType::referenceSystemFormulation();
192 diffusiveAndDispersiveFluxes += adaptFluxUnits(dispersiveFluxes[compIdx],
193 FluidSystem::molarMass(compIdx),
194 referenceSystemFormulationDispersion);
196 if(eqIdx != replaceCompEqIdx)
197 flux[eqIdx] += diffusiveAndDispersiveFluxes;
198 if (useTotalMoleOrMassBalance)
199 flux[replaceCompEqIdx] += diffusiveAndDispersiveFluxes;
203 if (useTotalMoleOrMassBalance)
206 const auto upwindTerm = [&massOrMoleDensity, phaseIdx] (
const auto& volVars)
207 {
return massOrMoleDensity(volVars, phaseIdx)*volVars.mobility(phaseIdx); };
209 flux[replaceCompEqIdx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
213 EnergyLocalResidual::heatConvectionFlux(flux, fluxVars, phaseIdx);
217 EnergyLocalResidual::heatConductionFlux(flux, fluxVars);
218 EnergyLocalResidual::heatDispersionFlux(flux, fluxVars);
Element-wise calculation of the local residual for problems using compositional fully implicit model.
Definition: porousmediumflow/compositional/localresidual.hh:35
NumEqVector computeFlux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const ElementFluxVariablesCache &elemFluxVarsCache) const
Evaluates the total flux of all conservation quantities over a face of a sub-control volume.
Definition: porousmediumflow/compositional/localresidual.hh:131
NumEqVector computeStorage(const Problem &problem, const SubControlVolume &scv, const VolumeVariables &volVars) const
Evaluates the amount of all conservation quantities (e.g. phase mass) within a sub-control volume.
Definition: porousmediumflow/compositional/localresidual.hh:79
Defines all properties used in Dumux.
The default local operator than can be specialized for each discretization scheme.
typename NumEqVectorTraits< PrimaryVariables >::type NumEqVector
A vector with the same size as numbers of equations This is the default implementation and has to be ...
Definition: numeqvector.hh:34
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:54
ReferenceSystemFormulation
The formulations available for Fick's law related to the reference system.
Definition: referencesystemformulation.hh:33
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
The available discretization methods in Dumux.
typename Detail::DiscretizationDefaultLocalOperator< TypeTag >::type DiscretizationDefaultLocalOperator
Definition: defaultlocaloperator.hh:27
A helper to deduce a vector with the same size as numbers of equations.