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>
42 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
46 using Element =
typename GridView::template Codim<0>::Entity;
48 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
51 using Indices =
typename ModelTraits::Indices;
53 static constexpr auto numEnergyEqFluid = ModelTraits::numEnergyEqFluid();
54 static constexpr auto numEnergyEqSolid = ModelTraits::numEnergyEqSolid();
55 static constexpr auto energyEq0Idx = Indices::energyEq0Idx;
56 static constexpr auto energyEqSolidIdx = Indices::energyEqSolidIdx;
58 static constexpr auto numPhases = ModelTraits::numFluidPhases();
59 static constexpr auto numComponents = ModelTraits::numFluidComponents();
64 const SubControlVolume& scv,
65 const VolumeVariables& volVars,
69 storage[energyEq0Idx] += volVars.porosity()
70 * volVars.density(phaseIdx)
71 * volVars.internalEnergy(phaseIdx)
72 * volVars.saturation(phaseIdx);
79 const SubControlVolume& scv,
80 const VolumeVariables& volVars)
83 for(
int sPhaseIdx = 0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
85 storage[energyEqSolidIdx+sPhaseIdx] += volVars.temperatureSolid()
86 * volVars.solidHeatCapacity()
87 * volVars.solidDensity()
88 * (1.0 - volVars.porosity());
99 FluxVariables& fluxVars)
104 FluxVariables& fluxVars,
107 auto upwindTerm = [phaseIdx](
const auto& volVars)
108 {
return volVars.density(phaseIdx)*volVars.mobility(phaseIdx)*volVars.enthalpy(phaseIdx); };
111 flux[energyEq0Idx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
114 const auto diffusiveFluxes = fluxVars.molecularDiffusionFlux(phaseIdx);
115 const auto& elemVolVars = fluxVars.elemVolVars();
116 const auto& scvf = fluxVars.scvFace();
117 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
118 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
120 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
123 if (phaseIdx == compIdx)
127 if (diffusiveFluxes[compIdx] > 0)
128 enthalpy += insideVolVars.enthalpy(phaseIdx);
130 enthalpy += outsideVolVars.enthalpy(phaseIdx);
134 flux[energyEq0Idx] += diffusiveFluxes[compIdx]*enthalpy;
136 flux[energyEq0Idx] += diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx)*enthalpy;
142 FluxVariables& fluxVars)
145 flux[energyEq0Idx] += fluxVars.heatConductionFlux(0);
147 for(
int sPhaseIdx = 0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
148 flux[energyEqSolidIdx+sPhaseIdx] += fluxVars.heatConductionFlux(numPhases + sPhaseIdx);
161 const Element& element,
162 const FVElementGeometry& fvGeometry,
163 const ElementVolumeVariables& elemVolVars,
164 const SubControlVolume &scv)
167 const auto& volVars = elemVolVars[scv];
168 const Scalar characteristicLength = volVars.characteristicLength() ;
172 const Scalar as = volVars.fluidSolidInterfacialArea();
175 const Scalar TFluid = volVars.temperatureFluid(0);
176 const Scalar TSolid = volVars.temperatureSolid();
178 Scalar solidToFluidEnergyExchange ;
180 const Scalar fluidConductivity = volVars.fluidThermalConductivity(0) ;
182 const Scalar factorEnergyTransfer = volVars.factorEnergyTransfer() ;
184 solidToFluidEnergyExchange = factorEnergyTransfer * (TSolid - TFluid) / characteristicLength * as * fluidConductivity;
186 solidToFluidEnergyExchange *= volVars.nusseltNumber(0);
188 for(
int energyEqIdx = 0; energyEqIdx < numEnergyEqFluid+numEnergyEqSolid; ++energyEqIdx)
193 source[energyEq0Idx + energyEqIdx] += solidToFluidEnergyExchange;
196 source[energyEq0Idx + energyEqIdx] -= solidToFluidEnergyExchange;
199 DUNE_THROW(Dune::NotImplemented,
206template<
class TypeTag>
214 using SubControlVolume =
typename FVElementGeometry::SubControlVolume;
219 using Element =
typename GridView::template Codim<0>::Entity;
221 using SubControlVolumeFace =
typename FVElementGeometry::SubControlVolumeFace;
224 using Indices =
typename ModelTraits::Indices;
226 enum { numPhases = ModelTraits::numFluidPhases() };
227 enum { numEnergyEqFluid = ModelTraits::numEnergyEqFluid() };
228 enum { numEnergyEqSolid = ModelTraits::numEnergyEqSolid() };
229 enum { energyEq0Idx = Indices::energyEq0Idx };
230 enum { energyEqSolidIdx = Indices::energyEqSolidIdx};
231 enum { conti0EqIdx = Indices::conti0EqIdx };
233 enum { numComponents = ModelTraits::numFluidComponents() };
234 enum { phase0Idx = FluidSystem::phase0Idx};
235 enum { phase1Idx = FluidSystem::phase1Idx};
236 enum { sPhaseIdx = numPhases};
238 static constexpr bool enableChemicalNonEquilibrium = ModelTraits::enableChemicalNonEquilibrium();
244 const SubControlVolume& scv,
245 const VolumeVariables& volVars,
248 storage[energyEq0Idx+phaseIdx] += volVars.porosity()
249 * volVars.density(phaseIdx)
250 * volVars.internalEnergy(phaseIdx)
251 * volVars.saturation(phaseIdx);
256 FluxVariables& fluxVars,
259 auto upwindTerm = [phaseIdx](
const auto& volVars)
260 {
return volVars.density(phaseIdx)*volVars.mobility(phaseIdx)*volVars.enthalpy(phaseIdx); };
263 flux[energyEq0Idx+phaseIdx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
266 const auto diffusiveFluxes = fluxVars.molecularDiffusionFlux(phaseIdx);
267 const auto& elemVolVars = fluxVars.elemVolVars();
268 const auto& scvf = fluxVars.scvFace();
269 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
270 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
272 for (
int compIdx = 0; compIdx < numComponents; ++compIdx)
275 if (phaseIdx == compIdx)
279 if (diffusiveFluxes[compIdx] > 0)
280 enthalpy += insideVolVars.enthalpy(phaseIdx);
282 enthalpy += outsideVolVars.enthalpy(phaseIdx);
283 flux[energyEq0Idx+phaseIdx] += diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx)*enthalpy;
289 FluxVariables& fluxVars)
291 for(
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
293 flux[energyEq0Idx+phaseIdx] += fluxVars.heatConductionFlux(phaseIdx);
295 for(
int sPhaseIdx=0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
297 flux[energyEqSolidIdx+sPhaseIdx] += fluxVars.heatConductionFlux(numPhases + sPhaseIdx);
308 FluxVariables& fluxVars)
321 const Element& element,
322 const FVElementGeometry& fvGeometry,
323 const ElementVolumeVariables& elemVolVars,
324 const SubControlVolume &scv)
327 const auto &volVars = elemVolVars[scv];
329 const Scalar areaWN = volVars.interfacialArea(phase0Idx, phase1Idx);
330 const Scalar areaWS = volVars.interfacialArea(phase0Idx, sPhaseIdx);
331 const Scalar areaNS = volVars.interfacialArea(phase1Idx, sPhaseIdx);
333 const Scalar Tw = volVars.temperatureFluid(phase0Idx);
334 const Scalar Tn = volVars.temperatureFluid(phase1Idx);
335 const Scalar Ts = volVars.temperatureSolid();
337 const Scalar lambdaWetting = volVars.fluidThermalConductivity(phase0Idx);
338 const Scalar lambdaNonwetting = volVars.fluidThermalConductivity(phase1Idx);
339 const Scalar lambdaSolid = volVars.solidThermalConductivity();
341 const Scalar lambdaWN =
harmonicMean(lambdaWetting, lambdaNonwetting);
342 const Scalar lambdaWS =
harmonicMean(lambdaWetting, lambdaSolid);
343 const Scalar lambdaNS =
harmonicMean(lambdaNonwetting, lambdaSolid);
345 const Scalar characteristicLength = volVars.characteristicLength() ;
346 const Scalar factorEnergyTransfer = volVars.factorEnergyTransfer() ;
348 const Scalar nusseltWN =
harmonicMean(volVars.nusseltNumber(phase0Idx), volVars.nusseltNumber(phase1Idx));
349 const Scalar nusseltWS = volVars.nusseltNumber(phase0Idx);
350 const Scalar nusseltNS = volVars.nusseltNumber(phase1Idx);
352 const Scalar wettingToNonwettingEnergyExchange = factorEnergyTransfer * (Tw - Tn) / characteristicLength * areaWN * lambdaWN * nusseltWN ;
353 const Scalar wettingToSolidEnergyExchange = factorEnergyTransfer * (Tw - Ts) / characteristicLength * areaWS * lambdaWS * nusseltWS ;
354 const Scalar nonwettingToSolidEnergyExchange = factorEnergyTransfer * (Tn - Ts) / characteristicLength * areaNS * lambdaNS * nusseltNS ;
356 for(
int phaseIdx = 0; phaseIdx < numEnergyEqFluid+numEnergyEqSolid; ++phaseIdx)
361 source[energyEq0Idx + phaseIdx] += ( - wettingToNonwettingEnergyExchange - wettingToSolidEnergyExchange);
364 source[energyEq0Idx + phaseIdx] += (+ wettingToNonwettingEnergyExchange - nonwettingToSolidEnergyExchange);
367 source[energyEq0Idx + phaseIdx] += (+ wettingToSolidEnergyExchange + nonwettingToSolidEnergyExchange);
370 DUNE_THROW(Dune::NotImplemented,
376 if (!isfinite(source[energyEq0Idx + phaseIdx]))
377 DUNE_THROW(
NumericalProblem,
"Calculated non-finite source, " <<
"Tw="<< Tw <<
" Tn="<< Tn<<
" Ts="<< Ts);
381 if (enableChemicalNonEquilibrium)
394 const auto& fluidState = volVars.fluidState();
396 for(
int phaseIdx = 0; phaseIdx < numEnergyEqFluid+numEnergyEqSolid; ++phaseIdx)
402 for(
int compIdx = 0; compIdx < numComponents; ++compIdx)
404 const unsigned int eqIdx = conti0EqIdx + compIdx + phaseIdx*numComponents;
405 source[energyEq0Idx + phaseIdx] += (source[eqIdx]
406 * FluidSystem::molarMass(compIdx)
407 * FluidSystem::componentEnthalpy(fluidState, phase1Idx, compIdx) );
412 for(
int compIdx =0; compIdx<numComponents; ++compIdx)
414 const unsigned int eqIdx = conti0EqIdx + compIdx + phaseIdx*numComponents;
415 source[energyEq0Idx + phaseIdx] += (source[eqIdx]
416 * FluidSystem::molarMass(compIdx)
417 *FluidSystem::componentEnthalpy(fluidState, phase0Idx, compIdx));
423 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:160
static void solidPhaseStorage(NumEqVector &storage, const SubControlVolume &scv, const VolumeVariables &volVars)
The energy storage in the solid matrix.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:78
static void heatDispersionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The dispersive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:98
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:63
static void heatConductionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The diffusive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:141
static void heatConvectionFlux(NumEqVector &flux, FluxVariables &fluxVars, int phaseIdx)
The advective phase energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:103
static void heatDispersionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The dispersive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:307
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:320
static void heatConvectionFlux(NumEqVector &flux, FluxVariables &fluxVars, int phaseIdx)
The advective phase energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:255
static void heatConductionFlux(NumEqVector &flux, FluxVariables &fluxVars)
The diffusive energy fluxes.
Definition: porousmediumflow/nonequilibrium/thermal/localresidual.hh:288
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:243
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
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:267
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
A helper to deduce a vector with the same size as numbers of equations.
Provides 3rd order polynomial splines.