25#ifndef DUMUX_ENERGY_NONEQUILIBRIUM_LOCAL_RESIDUAL_HH
26#define DUMUX_ENERGY_NONEQUILIBRIUM_LOCAL_RESIDUAL_HH
43template <
class TypeTag,
int numEnergyEqFlu
id>
46template<
class TypeTag>
53 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
57 using Element =
typename GridView::template Codim<0>::Entity;
59 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
62 using Indices =
typename ModelTraits::Indices;
64 static constexpr auto numEnergyEqFluid = ModelTraits::numEnergyEqFluid();
65 static constexpr auto numEnergyEqSolid = ModelTraits::numEnergyEqSolid();
66 static constexpr auto energyEq0Idx = Indices::energyEq0Idx;
67 static constexpr auto energyEqSolidIdx = Indices::energyEqSolidIdx;
69 static constexpr auto numPhases = ModelTraits::numFluidPhases();
70 static constexpr auto numComponents = ModelTraits::numFluidComponents();
75 const SubControlVolume& scv,
76 const VolumeVariables& volVars,
80 storage[energyEq0Idx] += volVars.porosity()
81 * volVars.density(phaseIdx)
82 * volVars.internalEnergy(phaseIdx)
83 * volVars.saturation(phaseIdx);
90 const SubControlVolume& scv,
91 const VolumeVariables& volVars)
94 for(
int sPhaseIdx = 0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
96 storage[energyEqSolidIdx+sPhaseIdx] += volVars.temperatureSolid()
97 * volVars.solidHeatCapacity()
98 * volVars.solidDensity()
99 * (1.0 - volVars.porosity());
106 FluxVariables& fluxVars,
109 auto upwindTerm = [phaseIdx](
const auto& volVars)
110 {
return volVars.density(phaseIdx)*volVars.mobility(phaseIdx)*volVars.enthalpy(phaseIdx); };
113 flux[energyEq0Idx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
116 const auto diffusiveFluxes = fluxVars.molecularDiffusionFlux(phaseIdx);
117 const auto& elemVolVars = fluxVars.elemVolVars();
118 const auto& scvf = fluxVars.scvFace();
119 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
120 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
122 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
125 if (phaseIdx == compIdx)
129 if (diffusiveFluxes[compIdx] > 0)
130 enthalpy += insideVolVars.enthalpy(phaseIdx);
132 enthalpy += outsideVolVars.enthalpy(phaseIdx);
136 flux[energyEq0Idx] += diffusiveFluxes[compIdx]*enthalpy;
138 flux[energyEq0Idx] += diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx)*enthalpy;
144 FluxVariables& fluxVars)
147 flux[energyEq0Idx] += fluxVars.heatConductionFlux(0);
149 for(
int sPhaseIdx = 0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
150 flux[energyEqSolidIdx+sPhaseIdx] += fluxVars.heatConductionFlux(numPhases + sPhaseIdx);
163 const Element& element,
164 const FVElementGeometry& fvGeometry,
165 const ElementVolumeVariables& elemVolVars,
166 const SubControlVolume &scv)
169 const auto& volVars = elemVolVars[scv];
170 const Scalar characteristicLength = volVars.characteristicLength() ;
174 const Scalar as = volVars.fluidSolidInterfacialArea();
177 const Scalar TFluid = volVars.temperatureFluid(0);
178 const Scalar TSolid = volVars.temperatureSolid();
180 Scalar solidToFluidEnergyExchange ;
182 const Scalar fluidConductivity = volVars.fluidThermalConductivity(0) ;
184 const Scalar factorEnergyTransfer = volVars.factorEnergyTransfer() ;
186 solidToFluidEnergyExchange = factorEnergyTransfer * (TSolid - TFluid) / characteristicLength * as * fluidConductivity;
188 solidToFluidEnergyExchange *= volVars.nusseltNumber(0);
190 for(
int energyEqIdx = 0; energyEqIdx < numEnergyEqFluid+numEnergyEqSolid; ++energyEqIdx)
195 source[energyEq0Idx + energyEqIdx] += solidToFluidEnergyExchange;
198 source[energyEq0Idx + energyEqIdx] -= solidToFluidEnergyExchange;
201 DUNE_THROW(Dune::NotImplemented,
208template<
class TypeTag>
216 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
221 using Element =
typename GridView::template Codim<0>::Entity;
223 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
226 using Indices =
typename ModelTraits::Indices;
228 enum { numPhases = ModelTraits::numFluidPhases() };
229 enum { numEnergyEqFluid = ModelTraits::numEnergyEqFluid() };
230 enum { numEnergyEqSolid = ModelTraits::numEnergyEqSolid() };
231 enum { energyEq0Idx = Indices::energyEq0Idx };
232 enum { energyEqSolidIdx = Indices::energyEqSolidIdx};
233 enum { conti0EqIdx = Indices::conti0EqIdx };
235 enum { numComponents = ModelTraits::numFluidComponents() };
236 enum { phase0Idx = FluidSystem::phase0Idx};
237 enum { phase1Idx = FluidSystem::phase1Idx};
238 enum { sPhaseIdx = numPhases};
240 static constexpr bool enableChemicalNonEquilibrium = ModelTraits::enableChemicalNonEquilibrium();
246 const SubControlVolume& scv,
247 const VolumeVariables& volVars,
250 storage[energyEq0Idx+phaseIdx] += volVars.porosity()
251 * volVars.density(phaseIdx)
252 * volVars.internalEnergy(phaseIdx)
253 * volVars.saturation(phaseIdx);
258 FluxVariables& fluxVars,
261 auto upwindTerm = [phaseIdx](
const auto& volVars)
262 {
return volVars.density(phaseIdx)*volVars.mobility(phaseIdx)*volVars.enthalpy(phaseIdx); };
265 flux[energyEq0Idx+phaseIdx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
268 const auto diffusiveFluxes = fluxVars.molecularDiffusionFlux(phaseIdx);
269 const auto& elemVolVars = fluxVars.elemVolVars();
270 const auto& scvf = fluxVars.scvFace();
271 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
272 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
274 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
277 if (phaseIdx == compIdx)
281 if (diffusiveFluxes[compIdx] > 0)
282 enthalpy += insideVolVars.enthalpy(phaseIdx);
284 enthalpy += outsideVolVars.enthalpy(phaseIdx);
285 flux[energyEq0Idx+phaseIdx] += diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx)*enthalpy;
291 FluxVariables& fluxVars)
293 for(
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
295 flux[energyEq0Idx+phaseIdx] += fluxVars.heatConductionFlux(phaseIdx);
297 for(
int sPhaseIdx=0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
299 flux[energyEqSolidIdx+sPhaseIdx] += fluxVars.heatConductionFlux(numPhases + sPhaseIdx);
312 const Element& element,
313 const FVElementGeometry& fvGeometry,
314 const ElementVolumeVariables& elemVolVars,
315 const SubControlVolume &scv)
318 const auto &volVars = elemVolVars[scv];
320 const Scalar awn = volVars.interfacialArea(phase0Idx, phase1Idx);
321 const Scalar aws = volVars.interfacialArea(phase0Idx, sPhaseIdx);
322 const Scalar ans = volVars.interfacialArea(phase1Idx, sPhaseIdx);
324 const Scalar Tw = volVars.temperatureFluid(phase0Idx);
325 const Scalar Tn = volVars.temperatureFluid(phase1Idx);
326 const Scalar Ts = volVars.temperatureSolid();
328 const Scalar lambdaWetting = volVars.fluidThermalConductivity(phase0Idx);
329 const Scalar lambdaNonwetting = volVars.fluidThermalConductivity(phase1Idx);
330 const Scalar lambdaSolid = volVars.solidThermalConductivity();
332 const Scalar lambdaWN =
harmonicMean(lambdaWetting, lambdaNonwetting);
333 const Scalar lambdaWS =
harmonicMean(lambdaWetting, lambdaSolid);
334 const Scalar lambdaNS =
harmonicMean(lambdaNonwetting, lambdaSolid);
336 const Scalar characteristicLength = volVars.characteristicLength() ;
337 const Scalar factorEnergyTransfer = volVars.factorEnergyTransfer() ;
339 const Scalar nusseltWN =
harmonicMean(volVars.nusseltNumber(phase0Idx), volVars.nusseltNumber(phase1Idx));
340 const Scalar nusseltWS = volVars.nusseltNumber(phase0Idx);
341 const Scalar nusseltNS = volVars.nusseltNumber(phase1Idx);
343 const Scalar wettingToNonwettingEnergyExchange = factorEnergyTransfer * (Tw - Tn) / characteristicLength * awn * lambdaWN * nusseltWN ;
344 const Scalar wettingToSolidEnergyExchange = factorEnergyTransfer * (Tw - Ts) / characteristicLength * aws * lambdaWS * nusseltWS ;
345 const Scalar nonwettingToSolidEnergyExchange = factorEnergyTransfer * (Tn - Ts) / characteristicLength * ans * lambdaNS * nusseltNS ;
347 for(
int phaseIdx = 0; phaseIdx < numEnergyEqFluid+numEnergyEqSolid; ++phaseIdx)
352 source[energyEq0Idx + phaseIdx] += ( - wettingToNonwettingEnergyExchange - wettingToSolidEnergyExchange);
355 source[energyEq0Idx + phaseIdx] += (+ wettingToNonwettingEnergyExchange - nonwettingToSolidEnergyExchange);
358 source[energyEq0Idx + phaseIdx] += (+ wettingToSolidEnergyExchange + nonwettingToSolidEnergyExchange);
361 DUNE_THROW(Dune::NotImplemented,
367 if (!isfinite(source[energyEq0Idx + phaseIdx]))
368 DUNE_THROW(
NumericalProblem,
"Calculated non-finite source, " <<
"Tw="<< Tw <<
" Tn="<< Tn<<
" Ts="<< Ts);
372 if (enableChemicalNonEquilibrium)
385 const auto& fluidState = volVars.fluidState();
387 for(
int phaseIdx = 0; phaseIdx < numEnergyEqFluid+numEnergyEqSolid; ++phaseIdx)
393 for(
int compIdx = 0; compIdx < numComponents; ++compIdx)
395 const unsigned int eqIdx = conti0EqIdx + compIdx + phaseIdx*numComponents;
396 source[energyEq0Idx + phaseIdx] += (source[eqIdx]
397 * FluidSystem::molarMass(compIdx)
398 * FluidSystem::componentEnthalpy(fluidState, phase1Idx, compIdx) );
403 for(
int compIdx =0; compIdx<numComponents; ++compIdx)
405 const unsigned int eqIdx = conti0EqIdx + compIdx + phaseIdx*numComponents;
406 source[energyEq0Idx + phaseIdx] += (source[eqIdx]
407 * FluidSystem::molarMass(compIdx)
408 *FluidSystem::componentEnthalpy(fluidState, phase0Idx, compIdx));
414 DUNE_THROW(Dune::NotImplemented,
Some exceptions thrown in DuMux
Provides 3rd order polynomial splines.
A helper to deduce a vector with the same size as numbers of equations.
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
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:150
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:44
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:162
static void solidPhaseStorage(NumEqVector &storage, const SubControlVolume &scv, const VolumeVariables &volVars)
The energy storage in the solid matrix.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:89
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:74
static void heatConductionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The diffusive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:143
static void heatConvectionFlux(NumEqVector &flux, FluxVariables &fluxVars, int phaseIdx)
The advective phase energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:105
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:311
static void heatConvectionFlux(NumEqVector &flux, FluxVariables &fluxVars, int phaseIdx)
The advective phase energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:257
static void heatConductionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The diffusive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:290
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:245
Declares all properties used in Dumux.