14#ifndef DUMUX_NONEQUILIBRIUM_LOCAL_RESIDUAL_HH
15#define DUMUX_NONEQUILIBRIUM_LOCAL_RESIDUAL_HH
25template<
class TypeTag,
bool enableChemicalNonEquilibrium>
28template <
class TypeTag>
36template<
class TypeTag>
43 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
45 using Element =
typename GridView::template Codim<0>::Entity;
51 using ParentType::ParentType;
63 const Element& element,
64 const FVElementGeometry& fvGeometry,
65 const ElementVolumeVariables& elemVolVars,
66 const SubControlVolume &scv)
const
68 NumEqVector source(0.0);
71 source += problem.source(element, fvGeometry, elemVolVars, scv);
74 source += problem.scvPointSources(element, fvGeometry, elemVolVars, scv);
78 if constexpr(ModelTraits::enableThermalNonEquilibrium())
80 EnergyLocalResidual::computeSourceEnergy(source,
96template<
class TypeTag>
103 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
104 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
109 using Element =
typename GridView::template Codim<0>::Entity;
116 using Indices =
typename ModelTraits::Indices;
118 static constexpr int numPhases = ModelTraits::numFluidPhases();
119 static constexpr int numComponents = ModelTraits::numFluidComponents();
121 static constexpr auto conti0EqIdx = Indices::conti0EqIdx;
122 static constexpr auto comp0Idx = FluidSystem::comp0Idx;
123 static constexpr auto phase0Idx = FluidSystem::phase0Idx;
124 static constexpr auto phase1Idx = FluidSystem::phase1Idx;
126 static_assert(numPhases > 1,
127 "chemical non-equlibrium only makes sense for multiple phases");
128 static_assert(numPhases == numComponents,
129 "currently chemical non-equilibrium is only available when numPhases equals numComponents");
130 static_assert(ModelTraits::useMoles(),
131 "chemical nonequilibrium can only be calculated based on mole fractions not mass fractions");
134 using ParentType::ParentType;
143 const SubControlVolume& scv,
144 const VolumeVariables& volVars)
const
146 NumEqVector storage(0.0);
149 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
151 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
153 auto eqIdx = conti0EqIdx + phaseIdx*numComponents + compIdx;
154 storage[eqIdx] += volVars.porosity()
155 * volVars.saturation(phaseIdx)
156 * volVars.molarDensity(phaseIdx)
157 * volVars.moleFraction(phaseIdx, compIdx);
160 EnergyLocalResidual::fluidPhaseStorage(storage, problem, scv, volVars, phaseIdx);
163 EnergyLocalResidual::solidPhaseStorage(storage, scv, volVars);
178 const Element& element,
179 const FVElementGeometry& fvGeometry,
180 const ElementVolumeVariables& elemVolVars,
181 const SubControlVolumeFace& scvf,
182 const ElementFluxVariablesCache& elemFluxVarsCache)
const
184 FluxVariables fluxVars;
185 fluxVars.init(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);
186 NumEqVector flux(0.0);
189 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
191 const auto diffusiveFluxes = fluxVars.molecularDiffusionFlux(phaseIdx);
192 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
195 const auto eqIdx = conti0EqIdx + phaseIdx*numComponents + compIdx;
198 const auto upwindTerm = [phaseIdx, compIdx] (
const auto& volVars)
199 {
return volVars.molarDensity(phaseIdx)*volVars.moleFraction(phaseIdx, compIdx)*volVars.mobility(phaseIdx); };
201 flux[eqIdx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
204 if (compIdx == phaseIdx)
208 flux[eqIdx] += diffusiveFluxes[compIdx]/FluidSystem::molarMass(compIdx);
210 flux[eqIdx] += diffusiveFluxes[compIdx];
213 EnergyLocalResidual::heatConvectionFlux(flux, fluxVars, phaseIdx);
217 EnergyLocalResidual::heatConductionFlux(flux, fluxVars);
232 const Element& element,
233 const FVElementGeometry& fvGeometry,
234 const ElementVolumeVariables& elemVolVars,
235 const SubControlVolume &scv)
const
237 NumEqVector source(0.0);
241 const auto& volVars = elemVolVars[scv];
242 std::array<std::array<Scalar, numComponents>, numPhases> componentIntoPhaseMassTransfer = {{{0.0},{0.0}}};
245 const Scalar characteristicLength = volVars.characteristicLength() ;
246 const Scalar factorMassTransfer = volVars.factorMassTransfer() ;
248 const Scalar awn = volVars.interfacialArea(phase0Idx, phase1Idx);
250 for(
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
252 const Scalar sherwoodNumber = volVars.sherwoodNumber(phaseIdx);
254 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
256 if (compIdx <= numPhases)
259 if (phaseIdx == compIdx)
262 const Scalar xNonEquil = volVars.moleFraction(phaseIdx, compIdx);
265 const Scalar xEquil = volVars.xEquil(phaseIdx, compIdx);
267 const Scalar diffCoeff = volVars.diffusionCoefficient(phaseIdx, FluidSystem::getMainComponent(phaseIdx), compIdx);
270 const Scalar compFluxIntoOtherPhase = factorMassTransfer * (xEquil-xNonEquil)/characteristicLength * awn * volVars.molarDensity(phaseIdx) * diffCoeff * sherwoodNumber;
272 componentIntoPhaseMassTransfer[phaseIdx][compIdx] += compFluxIntoOtherPhase;
273 componentIntoPhaseMassTransfer[compIdx][compIdx] -= compFluxIntoOtherPhase;
280 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
282 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
284 const unsigned int eqIdx = conti0EqIdx + compIdx + phaseIdx*numComponents;
285 source[eqIdx] += componentIntoPhaseMassTransfer[phaseIdx][compIdx];
288 if (!isfinite(source[eqIdx]))
293 if constexpr (ModelTraits::enableThermalNonEquilibrium())
297 EnergyLocalResidual::computeSourceEnergy(source,
305 source += problem.source(element, fvGeometry, elemVolVars, scv);
308 source += problem.scvPointSources(element, fvGeometry, elemVolVars, scv);
NumEqVector computeSource(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv) const
Calculates the source term of the equation.
Definition: porousmediumflow/nonequilibrium/localresidual.hh:62
NumEqVector computeSource(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv) const
Calculates the source term of the equation.
Definition: porousmediumflow/nonequilibrium/localresidual.hh:231
NumEqVector computeStorage(const Problem &problem, const SubControlVolume &scv, const VolumeVariables &volVars) const
Calculates the storage for all mass balance equations.
Definition: porousmediumflow/nonequilibrium/localresidual.hh:142
NumEqVector computeFlux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const ElementFluxVariablesCache &elemFluxVarsCache) const
Calculates the flux for all mass balance equations.
Definition: porousmediumflow/nonequilibrium/localresidual.hh:177
Definition: porousmediumflow/nonequilibrium/localresidual.hh:26
Exception thrown if a fixable numerical problem occurs.
Definition: exceptions.hh:27
Defines all properties used in Dumux.
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
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
A helper to deduce a vector with the same size as numbers of equations.
This file contains the parts of the local residual to calculate the heat conservation in the thermal ...