14#ifndef DUMUX_ENERGY_NONEQUILIBRIUM_LOCAL_RESIDUAL_HH
15#define DUMUX_ENERGY_NONEQUILIBRIUM_LOCAL_RESIDUAL_HH
32template <
class TypeTag,
int numEnergyEqFlu
id>
35template<
class TypeTag>
43 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
47 using Element =
typename GridView::template Codim<0>::Entity;
49 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
52 using Indices =
typename ModelTraits::Indices;
54 static constexpr auto numEnergyEqFluid = ModelTraits::numEnergyEqFluid();
55 static constexpr auto numEnergyEqSolid = ModelTraits::numEnergyEqSolid();
56 static constexpr auto energyEq0Idx = Indices::energyEq0Idx;
57 static constexpr auto energyEqSolidIdx = Indices::energyEqSolidIdx;
59 static constexpr auto numPhases = ModelTraits::numFluidPhases();
60 static constexpr auto numComponents = ModelTraits::numFluidComponents();
64 const SubControlVolume& scv,
65 const VolumeVariables& volVars,
68 static_assert(
"Deprecated interface that has been removed!");
74 const SubControlVolume& scv,
75 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());
110 FluxVariables& fluxVars)
115 FluxVariables& fluxVars,
118 auto upwindTerm = [phaseIdx](
const auto& volVars)
119 {
return volVars.density(phaseIdx)*volVars.mobility(phaseIdx)*volVars.enthalpy(phaseIdx); };
122 flux[energyEq0Idx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
125 const auto diffusiveFluxes = fluxVars.molecularDiffusionFlux(phaseIdx);
126 const auto& elemVolVars = fluxVars.elemVolVars();
127 const auto& scvf = fluxVars.scvFace();
128 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
129 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
131 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
134 if (phaseIdx == compIdx)
138 if (diffusiveFluxes[compIdx] > 0)
139 enthalpy += insideVolVars.enthalpy(phaseIdx);
141 enthalpy += outsideVolVars.enthalpy(phaseIdx);
145 flux[energyEq0Idx] += diffusiveFluxes[compIdx]*enthalpy;
147 flux[energyEq0Idx] += diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx)*enthalpy;
153 FluxVariables& fluxVars)
156 flux[energyEq0Idx] += fluxVars.heatConductionFlux(0);
158 for(
int sPhaseIdx = 0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
159 flux[energyEqSolidIdx+sPhaseIdx] += fluxVars.heatConductionFlux(numPhases + sPhaseIdx);
172 const Element& element,
173 const FVElementGeometry& fvGeometry,
174 const ElementVolumeVariables& elemVolVars,
175 const SubControlVolume &scv)
178 const auto& volVars = elemVolVars[scv];
179 const Scalar characteristicLength = volVars.characteristicLength() ;
183 const Scalar as = volVars.fluidSolidInterfacialArea();
186 const Scalar TFluid = volVars.temperatureFluid(0);
187 const Scalar TSolid = volVars.temperatureSolid();
189 Scalar solidToFluidEnergyExchange ;
191 const Scalar fluidConductivity = volVars.fluidThermalConductivity(0) ;
193 const Scalar factorEnergyTransfer = volVars.factorEnergyTransfer() ;
195 solidToFluidEnergyExchange = factorEnergyTransfer * (TSolid - TFluid) / characteristicLength * as * fluidConductivity;
197 solidToFluidEnergyExchange *= volVars.nusseltNumber(0);
199 for(
int energyEqIdx = 0; energyEqIdx < numEnergyEqFluid+numEnergyEqSolid; ++energyEqIdx)
204 source[energyEq0Idx + energyEqIdx] += solidToFluidEnergyExchange;
207 source[energyEq0Idx + energyEqIdx] -= solidToFluidEnergyExchange;
210 DUNE_THROW(Dune::NotImplemented,
221template<
class TypeTag>
230 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
235 using Element =
typename GridView::template Codim<0>::Entity;
237 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
240 using Indices =
typename ModelTraits::Indices;
242 enum { numPhases = ModelTraits::numFluidPhases() };
243 enum { numEnergyEqFluid = ModelTraits::numEnergyEqFluid() };
244 enum { numEnergyEqSolid = ModelTraits::numEnergyEqSolid() };
245 enum { energyEq0Idx = Indices::energyEq0Idx };
246 enum { energyEqSolidIdx = Indices::energyEqSolidIdx};
247 enum { conti0EqIdx = Indices::conti0EqIdx };
249 enum { numComponents = ModelTraits::numFluidComponents() };
250 enum { phase0Idx = FluidSystem::phase0Idx};
251 enum { phase1Idx = FluidSystem::phase1Idx};
252 enum { sPhaseIdx = numPhases};
254 static constexpr bool enableChemicalNonEquilibrium = ModelTraits::enableChemicalNonEquilibrium();
258 const SubControlVolume& scv,
259 const VolumeVariables& volVars,
262 static_assert(
"Deprecated interface that has been removed!");
268 const SubControlVolume& scv,
269 const VolumeVariables& volVars,
272 storage[energyEq0Idx+phaseIdx] += volVars.porosity()
273 * volVars.density(phaseIdx)
274 * volVars.internalEnergy(phaseIdx)
275 * volVars.saturation(phaseIdx);
281 FluxVariables& fluxVars,
284 auto upwindTerm = [phaseIdx](
const auto& volVars)
285 {
return volVars.density(phaseIdx)*volVars.mobility(phaseIdx)*volVars.enthalpy(phaseIdx); };
288 flux[energyEq0Idx+phaseIdx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
291 const auto diffusiveFluxes = fluxVars.molecularDiffusionFlux(phaseIdx);
292 const auto& elemVolVars = fluxVars.elemVolVars();
293 const auto& scvf = fluxVars.scvFace();
294 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
295 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
297 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
300 if (phaseIdx == compIdx)
304 if (diffusiveFluxes[compIdx] > 0)
305 enthalpy += insideVolVars.enthalpy(phaseIdx);
307 enthalpy += outsideVolVars.enthalpy(phaseIdx);
308 flux[energyEq0Idx+phaseIdx] += diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx)*enthalpy;
314 FluxVariables& fluxVars)
316 for(
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
318 flux[energyEq0Idx+phaseIdx] += fluxVars.heatConductionFlux(phaseIdx);
320 for(
int sPhaseIdx=0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
322 flux[energyEqSolidIdx+sPhaseIdx] += fluxVars.heatConductionFlux(numPhases + sPhaseIdx);
333 FluxVariables& fluxVars)
346 const Element& element,
347 const FVElementGeometry& fvGeometry,
348 const ElementVolumeVariables& elemVolVars,
349 const SubControlVolume &scv)
352 const auto &volVars = elemVolVars[scv];
354 const Scalar areaWN = volVars.interfacialArea(phase0Idx, phase1Idx);
355 const Scalar areaWS = volVars.interfacialArea(phase0Idx, sPhaseIdx);
356 const Scalar areaNS = volVars.interfacialArea(phase1Idx, sPhaseIdx);
358 const Scalar Tw = volVars.temperatureFluid(phase0Idx);
359 const Scalar Tn = volVars.temperatureFluid(phase1Idx);
360 const Scalar Ts = volVars.temperatureSolid();
362 const Scalar lambdaWetting = volVars.fluidThermalConductivity(phase0Idx);
363 const Scalar lambdaNonwetting = volVars.fluidThermalConductivity(phase1Idx);
364 const Scalar lambdaSolid = volVars.solidThermalConductivity();
366 const Scalar lambdaWN =
harmonicMean(lambdaWetting, lambdaNonwetting);
367 const Scalar lambdaWS =
harmonicMean(lambdaWetting, lambdaSolid);
368 const Scalar lambdaNS =
harmonicMean(lambdaNonwetting, lambdaSolid);
370 const Scalar characteristicLength = volVars.characteristicLength() ;
371 const Scalar factorEnergyTransfer = volVars.factorEnergyTransfer() ;
373 const Scalar nusseltWN =
harmonicMean(volVars.nusseltNumber(phase0Idx), volVars.nusseltNumber(phase1Idx));
374 const Scalar nusseltWS = volVars.nusseltNumber(phase0Idx);
375 const Scalar nusseltNS = volVars.nusseltNumber(phase1Idx);
377 const Scalar wettingToNonwettingEnergyExchange = factorEnergyTransfer * (Tw - Tn) / characteristicLength * areaWN * lambdaWN * nusseltWN ;
378 const Scalar wettingToSolidEnergyExchange = factorEnergyTransfer * (Tw - Ts) / characteristicLength * areaWS * lambdaWS * nusseltWS ;
379 const Scalar nonwettingToSolidEnergyExchange = factorEnergyTransfer * (Tn - Ts) / characteristicLength * areaNS * lambdaNS * nusseltNS ;
381 for(
int phaseIdx = 0; phaseIdx < numEnergyEqFluid+numEnergyEqSolid; ++phaseIdx)
386 source[energyEq0Idx + phaseIdx] += ( - wettingToNonwettingEnergyExchange - wettingToSolidEnergyExchange);
389 source[energyEq0Idx + phaseIdx] += (+ wettingToNonwettingEnergyExchange - nonwettingToSolidEnergyExchange);
392 source[energyEq0Idx + phaseIdx] += (+ wettingToSolidEnergyExchange + nonwettingToSolidEnergyExchange);
395 DUNE_THROW(Dune::NotImplemented,
401 if (!isfinite(source[energyEq0Idx + phaseIdx]))
402 DUNE_THROW(
NumericalProblem,
"Calculated non-finite source, " <<
"Tw="<< Tw <<
" Tn="<< Tn<<
" Ts="<< Ts);
406 if (enableChemicalNonEquilibrium)
419 const auto& fluidState = volVars.fluidState();
421 for(
int phaseIdx = 0; phaseIdx < numEnergyEqFluid+numEnergyEqSolid; ++phaseIdx)
427 for(
int compIdx = 0; compIdx < numComponents; ++compIdx)
429 const unsigned int eqIdx = conti0EqIdx + compIdx + phaseIdx*numComponents;
430 source[energyEq0Idx + phaseIdx] += (source[eqIdx]
431 * FluidSystem::molarMass(compIdx)
432 * FluidSystem::componentEnthalpy(fluidState, phase1Idx, compIdx) );
437 for(
int compIdx =0; compIdx<numComponents; ++compIdx)
439 const unsigned int eqIdx = conti0EqIdx + compIdx + phaseIdx*numComponents;
440 source[energyEq0Idx + phaseIdx] += (source[eqIdx]
441 * FluidSystem::molarMass(compIdx)
442 *FluidSystem::componentEnthalpy(fluidState, phase0Idx, compIdx));
448 DUNE_THROW(Dune::NotImplemented,
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:171
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 heatDispersionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The dispersive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:109
static void fluidPhaseStorage(NumEqVector &storage, const SubControlVolume &scv, const VolumeVariables &volVars, int phaseIdx)
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:63
static void fluidPhaseStorage(NumEqVector &storage, const Problem &, const SubControlVolume &scv, const VolumeVariables &volVars, int phaseIdx)
The energy storage in the fluid phase with index phaseIdx.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:72
static void heatConductionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The diffusive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:152
static void heatConvectionFlux(NumEqVector &flux, FluxVariables &fluxVars, int phaseIdx)
The advective phase energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:114
static void heatDispersionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The dispersive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:332
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:345
static void heatConvectionFlux(NumEqVector &flux, FluxVariables &fluxVars, int phaseIdx)
The advective phase energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:280
static void fluidPhaseStorage(NumEqVector &storage, const Problem &, const SubControlVolume &scv, const VolumeVariables &volVars, int phaseIdx)
The energy storage in the fluid phase with index phaseIdx.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:266
static void heatConductionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The diffusive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:313
static void fluidPhaseStorage(NumEqVector &storage, const SubControlVolume &scv, const VolumeVariables &volVars, int phaseIdx)
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:257
This file contains the parts of the local residual to calculate the heat conservation in the thermal ...
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:33
Exception thrown if a fixable numerical problem occurs.
Definition: exceptions.hh:27
Defines all properties used in Dumux.
Some exceptions thrown in DuMux
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:57
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.
Provides 3rd order polynomial splines.