26#ifndef DUMUX_ENERGY_NONEQUILIBRIUM_LOCAL_RESIDUAL_HH
27#define DUMUX_ENERGY_NONEQUILIBRIUM_LOCAL_RESIDUAL_HH
44template <
class TypeTag,
int numEnergyEqFlu
id>
47template<
class TypeTag>
54 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
58 using Element =
typename GridView::template Codim<0>::Entity;
60 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
63 using Indices =
typename ModelTraits::Indices;
65 static constexpr auto numEnergyEqFluid = ModelTraits::numEnergyEqFluid();
66 static constexpr auto numEnergyEqSolid = ModelTraits::numEnergyEqSolid();
67 static constexpr auto energyEq0Idx = Indices::energyEq0Idx;
68 static constexpr auto energyEqSolidIdx = Indices::energyEqSolidIdx;
70 static constexpr auto numPhases = ModelTraits::numFluidPhases();
71 static constexpr auto numComponents = ModelTraits::numFluidComponents();
76 const SubControlVolume& scv,
77 const VolumeVariables& volVars,
81 storage[energyEq0Idx] += volVars.porosity()
82 * volVars.density(phaseIdx)
83 * volVars.internalEnergy(phaseIdx)
84 * volVars.saturation(phaseIdx);
91 const SubControlVolume& scv,
92 const VolumeVariables& volVars)
95 for(
int sPhaseIdx = 0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
97 storage[energyEqSolidIdx+sPhaseIdx] += volVars.temperatureSolid()
98 * volVars.solidHeatCapacity()
99 * volVars.solidDensity()
100 * (1.0 - volVars.porosity());
111 FluxVariables& fluxVars)
116 FluxVariables& fluxVars,
119 auto upwindTerm = [phaseIdx](
const auto& volVars)
120 {
return volVars.density(phaseIdx)*volVars.mobility(phaseIdx)*volVars.enthalpy(phaseIdx); };
123 flux[energyEq0Idx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
126 const auto diffusiveFluxes = fluxVars.molecularDiffusionFlux(phaseIdx);
127 const auto& elemVolVars = fluxVars.elemVolVars();
128 const auto& scvf = fluxVars.scvFace();
129 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
130 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
132 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
135 if (phaseIdx == compIdx)
139 if (diffusiveFluxes[compIdx] > 0)
140 enthalpy += insideVolVars.enthalpy(phaseIdx);
142 enthalpy += outsideVolVars.enthalpy(phaseIdx);
146 flux[energyEq0Idx] += diffusiveFluxes[compIdx]*enthalpy;
148 flux[energyEq0Idx] += diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx)*enthalpy;
154 FluxVariables& fluxVars)
157 flux[energyEq0Idx] += fluxVars.heatConductionFlux(0);
159 for(
int sPhaseIdx = 0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
160 flux[energyEqSolidIdx+sPhaseIdx] += fluxVars.heatConductionFlux(numPhases + sPhaseIdx);
173 const Element& element,
174 const FVElementGeometry& fvGeometry,
175 const ElementVolumeVariables& elemVolVars,
176 const SubControlVolume &scv)
179 const auto& volVars = elemVolVars[scv];
180 const Scalar characteristicLength = volVars.characteristicLength() ;
184 const Scalar as = volVars.fluidSolidInterfacialArea();
187 const Scalar TFluid = volVars.temperatureFluid(0);
188 const Scalar TSolid = volVars.temperatureSolid();
190 Scalar solidToFluidEnergyExchange ;
192 const Scalar fluidConductivity = volVars.fluidThermalConductivity(0) ;
194 const Scalar factorEnergyTransfer = volVars.factorEnergyTransfer() ;
196 solidToFluidEnergyExchange = factorEnergyTransfer * (TSolid - TFluid) / characteristicLength * as * fluidConductivity;
198 solidToFluidEnergyExchange *= volVars.nusseltNumber(0);
200 for(
int energyEqIdx = 0; energyEqIdx < numEnergyEqFluid+numEnergyEqSolid; ++energyEqIdx)
205 source[energyEq0Idx + energyEqIdx] += solidToFluidEnergyExchange;
208 source[energyEq0Idx + energyEqIdx] -= solidToFluidEnergyExchange;
211 DUNE_THROW(Dune::NotImplemented,
218template<
class TypeTag>
226 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
231 using Element =
typename GridView::template Codim<0>::Entity;
233 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
236 using Indices =
typename ModelTraits::Indices;
238 enum { numPhases = ModelTraits::numFluidPhases() };
239 enum { numEnergyEqFluid = ModelTraits::numEnergyEqFluid() };
240 enum { numEnergyEqSolid = ModelTraits::numEnergyEqSolid() };
241 enum { energyEq0Idx = Indices::energyEq0Idx };
242 enum { energyEqSolidIdx = Indices::energyEqSolidIdx};
243 enum { conti0EqIdx = Indices::conti0EqIdx };
245 enum { numComponents = ModelTraits::numFluidComponents() };
246 enum { phase0Idx = FluidSystem::phase0Idx};
247 enum { phase1Idx = FluidSystem::phase1Idx};
248 enum { sPhaseIdx = numPhases};
250 static constexpr bool enableChemicalNonEquilibrium = ModelTraits::enableChemicalNonEquilibrium();
256 const SubControlVolume& scv,
257 const VolumeVariables& volVars,
260 storage[energyEq0Idx+phaseIdx] += volVars.porosity()
261 * volVars.density(phaseIdx)
262 * volVars.internalEnergy(phaseIdx)
263 * volVars.saturation(phaseIdx);
268 FluxVariables& fluxVars,
271 auto upwindTerm = [phaseIdx](
const auto& volVars)
272 {
return volVars.density(phaseIdx)*volVars.mobility(phaseIdx)*volVars.enthalpy(phaseIdx); };
275 flux[energyEq0Idx+phaseIdx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
278 const auto diffusiveFluxes = fluxVars.molecularDiffusionFlux(phaseIdx);
279 const auto& elemVolVars = fluxVars.elemVolVars();
280 const auto& scvf = fluxVars.scvFace();
281 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
282 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
284 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
287 if (phaseIdx == compIdx)
291 if (diffusiveFluxes[compIdx] > 0)
292 enthalpy += insideVolVars.enthalpy(phaseIdx);
294 enthalpy += outsideVolVars.enthalpy(phaseIdx);
295 flux[energyEq0Idx+phaseIdx] += diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx)*enthalpy;
301 FluxVariables& fluxVars)
303 for(
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
305 flux[energyEq0Idx+phaseIdx] += fluxVars.heatConductionFlux(phaseIdx);
307 for(
int sPhaseIdx=0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
309 flux[energyEqSolidIdx+sPhaseIdx] += fluxVars.heatConductionFlux(numPhases + sPhaseIdx);
320 FluxVariables& fluxVars)
333 const Element& element,
334 const FVElementGeometry& fvGeometry,
335 const ElementVolumeVariables& elemVolVars,
336 const SubControlVolume &scv)
339 const auto &volVars = elemVolVars[scv];
341 const Scalar areaWN = volVars.interfacialArea(phase0Idx, phase1Idx);
342 const Scalar areaWS = volVars.interfacialArea(phase0Idx, sPhaseIdx);
343 const Scalar areaNS = volVars.interfacialArea(phase1Idx, sPhaseIdx);
345 const Scalar Tw = volVars.temperatureFluid(phase0Idx);
346 const Scalar Tn = volVars.temperatureFluid(phase1Idx);
347 const Scalar Ts = volVars.temperatureSolid();
349 const Scalar lambdaWetting = volVars.fluidThermalConductivity(phase0Idx);
350 const Scalar lambdaNonwetting = volVars.fluidThermalConductivity(phase1Idx);
351 const Scalar lambdaSolid = volVars.solidThermalConductivity();
353 const Scalar lambdaWN =
harmonicMean(lambdaWetting, lambdaNonwetting);
354 const Scalar lambdaWS =
harmonicMean(lambdaWetting, lambdaSolid);
355 const Scalar lambdaNS =
harmonicMean(lambdaNonwetting, lambdaSolid);
357 const Scalar characteristicLength = volVars.characteristicLength() ;
358 const Scalar factorEnergyTransfer = volVars.factorEnergyTransfer() ;
360 const Scalar nusseltWN =
harmonicMean(volVars.nusseltNumber(phase0Idx), volVars.nusseltNumber(phase1Idx));
361 const Scalar nusseltWS = volVars.nusseltNumber(phase0Idx);
362 const Scalar nusseltNS = volVars.nusseltNumber(phase1Idx);
364 const Scalar wettingToNonwettingEnergyExchange = factorEnergyTransfer * (Tw - Tn) / characteristicLength * areaWN * lambdaWN * nusseltWN ;
365 const Scalar wettingToSolidEnergyExchange = factorEnergyTransfer * (Tw - Ts) / characteristicLength * areaWS * lambdaWS * nusseltWS ;
366 const Scalar nonwettingToSolidEnergyExchange = factorEnergyTransfer * (Tn - Ts) / characteristicLength * areaNS * lambdaNS * nusseltNS ;
368 for(
int phaseIdx = 0; phaseIdx < numEnergyEqFluid+numEnergyEqSolid; ++phaseIdx)
373 source[energyEq0Idx + phaseIdx] += ( - wettingToNonwettingEnergyExchange - wettingToSolidEnergyExchange);
376 source[energyEq0Idx + phaseIdx] += (+ wettingToNonwettingEnergyExchange - nonwettingToSolidEnergyExchange);
379 source[energyEq0Idx + phaseIdx] += (+ wettingToSolidEnergyExchange + nonwettingToSolidEnergyExchange);
382 DUNE_THROW(Dune::NotImplemented,
388 if (!isfinite(source[energyEq0Idx + phaseIdx]))
389 DUNE_THROW(
NumericalProblem,
"Calculated non-finite source, " <<
"Tw="<< Tw <<
" Tn="<< Tn<<
" Ts="<< Ts);
393 if (enableChemicalNonEquilibrium)
406 const auto& fluidState = volVars.fluidState();
408 for(
int phaseIdx = 0; phaseIdx < numEnergyEqFluid+numEnergyEqSolid; ++phaseIdx)
414 for(
int compIdx = 0; compIdx < numComponents; ++compIdx)
416 const unsigned int eqIdx = conti0EqIdx + compIdx + phaseIdx*numComponents;
417 source[energyEq0Idx + phaseIdx] += (source[eqIdx]
418 * FluidSystem::molarMass(compIdx)
419 * FluidSystem::componentEnthalpy(fluidState, phase1Idx, compIdx) );
424 for(
int compIdx =0; compIdx<numComponents; ++compIdx)
426 const unsigned int eqIdx = conti0EqIdx + compIdx + phaseIdx*numComponents;
427 source[energyEq0Idx + phaseIdx] += (source[eqIdx]
428 * FluidSystem::molarMass(compIdx)
429 *FluidSystem::componentEnthalpy(fluidState, phase0Idx, compIdx));
435 DUNE_THROW(Dune::NotImplemented,
Some exceptions thrown in DuMux
A helper to deduce a vector with the same size as numbers of equations.
Provides 3rd order polynomial splines.
The reference frameworks and formulations available for splitting total fluxes into a advective and d...
constexpr Scalar harmonicMean(Scalar x, Scalar y, Scalar wx=1.0, Scalar wy=1.0) noexcept
Calculate the (weighted) harmonic mean of two scalar values.
Definition: math.hh:69
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
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:180
Exception thrown if a fixable numerical problem occurs.
Definition: exceptions.hh:39
This file contains the parts of the local residual to calculate the heat conservation in the thermal ...
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:45
static void computeSourceEnergy(NumEqVector &source, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv)
heat transfer between the phases for nonequilibrium models
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:172
static void solidPhaseStorage(NumEqVector &storage, const SubControlVolume &scv, const VolumeVariables &volVars)
The energy storage in the solid matrix.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:90
static void heatDispersionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The dispersive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:110
static void fluidPhaseStorage(NumEqVector &storage, const SubControlVolume &scv, const VolumeVariables &volVars, int phaseIdx)
The energy storage in the fluid phase with index phaseIdx.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:75
static void heatConductionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The diffusive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:153
static void heatConvectionFlux(NumEqVector &flux, FluxVariables &fluxVars, int phaseIdx)
The advective phase energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:115
static void heatDispersionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The dispersive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:319
static void computeSourceEnergy(NumEqVector &source, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolume &scv)
Calculates the source term of the equation.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:332
static void heatConvectionFlux(NumEqVector &flux, FluxVariables &fluxVars, int phaseIdx)
The advective phase energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:267
static void heatConductionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The diffusive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:300
static void fluidPhaseStorage(NumEqVector &storage, const SubControlVolume &scv, const VolumeVariables &volVars, int phaseIdx)
The energy storage in the fluid phase with index phaseIdx.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:255
Declares all properties used in Dumux.