26#ifndef DUMUX_COMPOSITIONAL_LOCAL_RESIDUAL_HH
27#define DUMUX_COMPOSITIONAL_LOCAL_RESIDUAL_HH
30#include <dune/common/exceptions.hh>
44template<
class TypeTag>
52 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
53 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
58 using Element =
typename GridView::template Codim<0>::Entity;
64 using Indices =
typename ModelTraits::Indices;
66 static constexpr int numPhases = ModelTraits::numFluidPhases();
67 static constexpr int numComponents = ModelTraits::numFluidComponents();
68 static constexpr bool useMoles = ModelTraits::useMoles();
70 enum { conti0EqIdx = Indices::conti0EqIdx };
73 static constexpr int replaceCompEqIdx = ModelTraits::replaceCompEqIdx();
74 static constexpr bool useTotalMoleOrMassBalance = replaceCompEqIdx < numComponents;
77 using ParentType::ParentType;
91 const SubControlVolume& scv,
92 const VolumeVariables& volVars)
const
94 NumEqVector storage(0.0);
96 const auto massOrMoleDensity = [](
const auto& volVars,
const int phaseIdx)
97 {
return useMoles ? volVars.molarDensity(phaseIdx) : volVars.density(phaseIdx); };
99 const auto massOrMoleFraction= [](
const auto& volVars,
const int phaseIdx,
const int compIdx)
100 {
return useMoles ? volVars.moleFraction(phaseIdx, compIdx) : volVars.massFraction(phaseIdx, compIdx); };
103 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
105 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
107 auto eqIdx = conti0EqIdx + compIdx;
108 if (eqIdx != replaceCompEqIdx)
109 storage[eqIdx] += volVars.porosity()
110 * volVars.saturation(phaseIdx)
111 * massOrMoleDensity(volVars, phaseIdx)
116 if (useTotalMoleOrMassBalance)
117 storage[replaceCompEqIdx] += massOrMoleDensity(volVars, phaseIdx)
119 * volVars.saturation(phaseIdx);
122 EnergyLocalResidual::fluidPhaseStorage(storage, scv, volVars, phaseIdx);
126 EnergyLocalResidual::solidPhaseStorage(storage, scv, volVars);
143 const Element& element,
144 const FVElementGeometry& fvGeometry,
145 const ElementVolumeVariables& elemVolVars,
146 const SubControlVolumeFace& scvf,
147 const ElementFluxVariablesCache& elemFluxVarsCache)
const
149 FluxVariables fluxVars;
150 fluxVars.init(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
151 static constexpr auto referenceSystemFormulation = FluxVariables::MolecularDiffusionType::referenceSystemFormulation();
153 NumEqVector flux(0.0);
155 const auto massOrMoleDensity = [](
const auto& volVars,
const int phaseIdx)
156 {
return useMoles ? volVars.molarDensity(phaseIdx) : volVars.density(phaseIdx); };
158 const auto massOrMoleFraction= [](
const auto& volVars,
const int phaseIdx,
const int compIdx)
159 {
return useMoles ? volVars.moleFraction(phaseIdx, compIdx) : volVars.massFraction(phaseIdx, compIdx); };
162 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
164 const auto diffusiveFluxes = fluxVars.molecularDiffusionFlux(phaseIdx);
165 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
168 const auto eqIdx = conti0EqIdx + compIdx;
171 const auto upwindTerm = [&massOrMoleDensity, &
massOrMoleFraction, phaseIdx, compIdx] (
const auto& volVars)
172 {
return massOrMoleDensity(volVars, phaseIdx)*
massOrMoleFraction(volVars, phaseIdx, compIdx)*volVars.mobility(phaseIdx); };
174 if (eqIdx != replaceCompEqIdx)
175 flux[eqIdx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
178 if(eqIdx != replaceCompEqIdx)
182 flux[eqIdx] += useMoles ? diffusiveFluxes[compIdx]/FluidSystem::molarMass(compIdx)
183 : diffusiveFluxes[compIdx];
185 flux[eqIdx] += useMoles ? diffusiveFluxes[compIdx]
186 : diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx);
188 DUNE_THROW(Dune::NotImplemented,
"other reference systems than mass and molar averaged are not implemented");
193 if (useTotalMoleOrMassBalance)
196 const auto upwindTerm = [&massOrMoleDensity, phaseIdx] (
const auto& volVars)
197 {
return massOrMoleDensity(volVars, phaseIdx)*volVars.mobility(phaseIdx); };
199 flux[replaceCompEqIdx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
201 for(
int compIdx = 0; compIdx < numComponents; ++compIdx)
205 flux[replaceCompEqIdx] += useMoles ? diffusiveFluxes[compIdx]/FluidSystem::molarMass(compIdx) : diffusiveFluxes[compIdx];
207 flux[replaceCompEqIdx] += useMoles ? diffusiveFluxes[compIdx]
208 : diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx);
210 DUNE_THROW(Dune::NotImplemented,
"other reference systems than mass and molar averaged are not implemented");
215 EnergyLocalResidual::heatConvectionFlux(flux, fluxVars, phaseIdx);
217 if constexpr (Deprecated::hasEnableCompositionalDispersion<ModelTraits>())
219 if constexpr (ModelTraits::enableCompositionalDispersion())
223 const auto dispersionFluxes = fluxVars.compositionalDispersionFlux(phaseIdx);
224 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
226 flux[compIdx] += dispersionFluxes[compIdx];
230 DUNE_THROW(Dune::NotImplemented,
"Dispersion Fluxes are only implemented for single phase flows using the Box method.");
234 enableCompositionalDispersionMissing_<ModelTraits>();
238 EnergyLocalResidual::heatConductionFlux(flux, fluxVars);
239 EnergyLocalResidual::heatDispersionFlux(flux, fluxVars);
246 {
return static_cast<Implementation *
> (
this); }
249 {
return static_cast<const Implementation *
> (
this); }
251 template <
class T = ModelTraits>
252 [[deprecated(
"All compositional models must specifiy if dispersion is enabled."
253 "Please add enableCompositionalDispersion to the ModelTraits in your model header.")]]
A helper to deduce a vector with the same size as numbers of equations.
The available discretization methods in Dumux.
The reference frameworks and formulations available for splitting total fluxes into a advective and d...
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
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:46
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:150
constexpr Box box
Definition: method.hh:139
Element-wise calculation of the local residual for problems using compositional fully implicit model.
Definition: porousmediumflow/compositional/localresidual.hh:46
void enableCompositionalDispersionMissing_() const
Definition: porousmediumflow/compositional/localresidual.hh:254
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:142
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:90
Implementation * asImp_()
Definition: porousmediumflow/compositional/localresidual.hh:245
const Implementation * asImp_() const
Definition: porousmediumflow/compositional/localresidual.hh:248
Declares all properties used in Dumux.