version 3.9
porousmediumflow/nonequilibrium/thermal/localresidual.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
14#ifndef DUMUX_ENERGY_NONEQUILIBRIUM_LOCAL_RESIDUAL_HH
15#define DUMUX_ENERGY_NONEQUILIBRIUM_LOCAL_RESIDUAL_HH
16
17#include <cmath>
23
24namespace Dumux {
25
31// forward declaration
32template <class TypeTag, int numEnergyEqFluid>
34
35template<class TypeTag>
36class EnergyLocalResidualNonEquilibrium<TypeTag, 1/*numEnergyEqFluid*/>
37{
42 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
43 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
47 using Element = typename GridView::template Codim<0>::Entity;
48 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
49 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
50
52 using Indices = typename ModelTraits::Indices;
53
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;
58
59 static constexpr auto numPhases = ModelTraits::numFluidPhases();
60 static constexpr auto numComponents = ModelTraits::numFluidComponents();
61
62public:
63 static void fluidPhaseStorage(NumEqVector& storage,
64 const SubControlVolume& scv,
65 const VolumeVariables& volVars,
66 int phaseIdx)
67 {
68 static_assert("Deprecated interface that has been removed!");
69 }
70
72 static void fluidPhaseStorage(NumEqVector& storage,
73 const Problem&,
74 const SubControlVolume& scv,
75 const VolumeVariables& volVars,
76 int phaseIdx)
77 {
78 // in case we have one energy equation for more than one fluid phase,
79 // add up parts on the one energy equation
80 storage[energyEq0Idx] += volVars.porosity()
81 * volVars.density(phaseIdx)
82 * volVars.internalEnergy(phaseIdx)
83 * volVars.saturation(phaseIdx);
84
85 }
86
87
89 static void solidPhaseStorage(NumEqVector& storage,
90 const SubControlVolume& scv,
91 const VolumeVariables& volVars)
92 {
93 // heat conduction for the fluid phases
94 for(int sPhaseIdx = 0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
95 {
96 storage[energyEqSolidIdx+sPhaseIdx] += volVars.temperatureSolid()
97 * volVars.solidHeatCapacity()
98 * volVars.solidDensity()
99 * (1.0 - volVars.porosity());
100 }
101 }
102
109 static void heatDispersionFlux(NumEqVector& flux,
110 FluxVariables& fluxVars)
111 {}
112
114 static void heatConvectionFlux(NumEqVector& flux,
115 FluxVariables& fluxVars,
116 int phaseIdx)
117 {
118 auto upwindTerm = [phaseIdx](const auto& volVars)
119 { return volVars.density(phaseIdx)*volVars.mobility(phaseIdx)*volVars.enthalpy(phaseIdx); };
120
121 //in case we have one energy equation for more than one fluid phase, add up advective parts on the one energy equation
122 flux[energyEq0Idx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
123
124 //now add the diffusive part
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()];
130
131 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
132 {
133 //no diffusion of the main component, this is a hack to use normal fick's law which computes both diffusions (main and component). We only add the part from the component here
134 if (phaseIdx == compIdx)
135 continue;
136 //we need the upwind enthalpy. Even better would be the componentEnthalpy
137 auto enthalpy = 0.0;
138 if (diffusiveFluxes[compIdx] > 0)
139 enthalpy += insideVolVars.enthalpy(phaseIdx);
140 else
141 enthalpy += outsideVolVars.enthalpy(phaseIdx);
142
143 //check for the reference system and adapt units of the diffusive flux accordingly.
144 if (FluxVariables::MolecularDiffusionType::referenceSystemFormulation() == ReferenceSystemFormulation::massAveraged)
145 flux[energyEq0Idx] += diffusiveFluxes[compIdx]*enthalpy;
146 else
147 flux[energyEq0Idx] += diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx)*enthalpy;
148 }
149 }
150
152 static void heatConductionFlux(NumEqVector& flux,
153 FluxVariables& fluxVars)
154 {
155 //in case we have one energy equation for more than one fluid phase we use an effective law in the nonequilibrium fourierslaw
156 flux[energyEq0Idx] += fluxVars.heatConductionFlux(0);
157 //heat conduction for the solid phases
158 for(int sPhaseIdx = 0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
159 flux[energyEqSolidIdx+sPhaseIdx] += fluxVars.heatConductionFlux(numPhases + sPhaseIdx);
160 }
161
171 static void computeSourceEnergy(NumEqVector& source,
172 const Element& element,
173 const FVElementGeometry& fvGeometry,
174 const ElementVolumeVariables& elemVolVars,
175 const SubControlVolume &scv)
176 {
177 // specialization for 2 fluid phases
178 const auto& volVars = elemVolVars[scv];
179 const Scalar characteristicLength = volVars.characteristicLength() ;
180
181 // interfacial area
182 // Shi & Wang, Transport in porous media (2011)
183 const Scalar as = volVars.fluidSolidInterfacialArea();
184
185 // temperature fluid is the same for both fluids
186 const Scalar TFluid = volVars.temperatureFluid(0);
187 const Scalar TSolid = volVars.temperatureSolid();
188
189 Scalar solidToFluidEnergyExchange ;
190
191 const Scalar fluidConductivity = volVars.fluidThermalConductivity(0) ;
192
193 const Scalar factorEnergyTransfer = volVars.factorEnergyTransfer() ;
194
195 solidToFluidEnergyExchange = factorEnergyTransfer * (TSolid - TFluid) / characteristicLength * as * fluidConductivity;
196
197 solidToFluidEnergyExchange *= volVars.nusseltNumber(0);
198
199 for(int energyEqIdx = 0; energyEqIdx < numEnergyEqFluid+numEnergyEqSolid; ++energyEqIdx)
200 {
201 switch (energyEqIdx)
202 {
203 case 0 :
204 source[energyEq0Idx + energyEqIdx] += solidToFluidEnergyExchange;
205 break;
206 case 1 :
207 source[energyEq0Idx + energyEqIdx] -= solidToFluidEnergyExchange;
208 break;
209 default:
210 DUNE_THROW(Dune::NotImplemented,
211 "wrong index");
212 } // end switch
213 } // end energyEqIdx
214 } // end source
215};
216
221template<class TypeTag>
222class EnergyLocalResidualNonEquilibrium<TypeTag, 2/*numEnergyEqFluid*/>
223: public EnergyLocalResidualNonEquilibrium<TypeTag, 1/*numEnergyEqFluid*/>
224{
229 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
230 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
235 using Element = typename GridView::template Codim<0>::Entity;
236 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
237 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
238
240 using Indices = typename ModelTraits::Indices;
241
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 };
248
249 enum { numComponents = ModelTraits::numFluidComponents() };
250 enum { phase0Idx = FluidSystem::phase0Idx};
251 enum { phase1Idx = FluidSystem::phase1Idx};
252 enum { sPhaseIdx = numPhases};
253
254 static constexpr bool enableChemicalNonEquilibrium = ModelTraits::enableChemicalNonEquilibrium();
255
256public:
257 static void fluidPhaseStorage(NumEqVector& storage,
258 const SubControlVolume& scv,
259 const VolumeVariables& volVars,
260 int phaseIdx)
261 {
262 static_assert("Deprecated interface that has been removed!");
263 }
264
266 static void fluidPhaseStorage(NumEqVector& storage,
267 const Problem&,
268 const SubControlVolume& scv,
269 const VolumeVariables& volVars,
270 int phaseIdx)
271 {
272 storage[energyEq0Idx+phaseIdx] += volVars.porosity()
273 * volVars.density(phaseIdx)
274 * volVars.internalEnergy(phaseIdx)
275 * volVars.saturation(phaseIdx);
276
277 }
278
280 static void heatConvectionFlux(NumEqVector& flux,
281 FluxVariables& fluxVars,
282 int phaseIdx)
283 {
284 auto upwindTerm = [phaseIdx](const auto& volVars)
285 { return volVars.density(phaseIdx)*volVars.mobility(phaseIdx)*volVars.enthalpy(phaseIdx); };
286
287 // in case we have one energy equation for more than one fluid phase, add up advective parts on the one energy equation
288 flux[energyEq0Idx+phaseIdx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
289
290 // add the diffusiv part
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()];
296
297 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
298 {
299 // no diffusion of the main component, this is a hack to use normal fick's law which computes both diffusions (main and component). We only add the part from the component here
300 if (phaseIdx == compIdx)
301 continue;
302 // we need the upwind enthalpy. Even better would be the componentEnthalpy
303 auto enthalpy = 0.0;
304 if (diffusiveFluxes[compIdx] > 0)
305 enthalpy += insideVolVars.enthalpy(phaseIdx);
306 else
307 enthalpy += outsideVolVars.enthalpy(phaseIdx);
308 flux[energyEq0Idx+phaseIdx] += diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx)*enthalpy;
309 }
310 }
311
313 static void heatConductionFlux(NumEqVector& flux,
314 FluxVariables& fluxVars)
315 {
316 for(int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
317 {
318 flux[energyEq0Idx+phaseIdx] += fluxVars.heatConductionFlux(phaseIdx);
319 }
320 for(int sPhaseIdx=0; sPhaseIdx<numEnergyEqSolid; ++sPhaseIdx)
321 {
322 flux[energyEqSolidIdx+sPhaseIdx] += fluxVars.heatConductionFlux(numPhases + sPhaseIdx);
323 }
324 }
325
332 static void heatDispersionFlux(NumEqVector& flux,
333 FluxVariables& fluxVars)
334 {}
335
345 static void computeSourceEnergy(NumEqVector& source,
346 const Element& element,
347 const FVElementGeometry& fvGeometry,
348 const ElementVolumeVariables& elemVolVars,
349 const SubControlVolume &scv)
350 {
351 // specialization for 2 fluid phases
352 const auto &volVars = elemVolVars[scv];
353
354 const Scalar areaWN = volVars.interfacialArea(phase0Idx, phase1Idx);
355 const Scalar areaWS = volVars.interfacialArea(phase0Idx, sPhaseIdx);
356 const Scalar areaNS = volVars.interfacialArea(phase1Idx, sPhaseIdx);
357
358 const Scalar Tw = volVars.temperatureFluid(phase0Idx);
359 const Scalar Tn = volVars.temperatureFluid(phase1Idx);
360 const Scalar Ts = volVars.temperatureSolid();
361
362 const Scalar lambdaWetting = volVars.fluidThermalConductivity(phase0Idx);
363 const Scalar lambdaNonwetting = volVars.fluidThermalConductivity(phase1Idx);
364 const Scalar lambdaSolid = volVars.solidThermalConductivity();
365
366 const Scalar lambdaWN = harmonicMean(lambdaWetting, lambdaNonwetting);
367 const Scalar lambdaWS = harmonicMean(lambdaWetting, lambdaSolid);
368 const Scalar lambdaNS = harmonicMean(lambdaNonwetting, lambdaSolid);
369
370 const Scalar characteristicLength = volVars.characteristicLength() ;
371 const Scalar factorEnergyTransfer = volVars.factorEnergyTransfer() ;
372
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);
376
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 ;
380
381 for(int phaseIdx = 0; phaseIdx < numEnergyEqFluid+numEnergyEqSolid; ++phaseIdx)
382 {
383 switch (phaseIdx)
384 {
385 case phase0Idx:
386 source[energyEq0Idx + phaseIdx] += ( - wettingToNonwettingEnergyExchange - wettingToSolidEnergyExchange);
387 break;
388 case phase1Idx:
389 source[energyEq0Idx + phaseIdx] += (+ wettingToNonwettingEnergyExchange - nonwettingToSolidEnergyExchange);
390 break;
391 case sPhaseIdx:
392 source[energyEq0Idx + phaseIdx] += (+ wettingToSolidEnergyExchange + nonwettingToSolidEnergyExchange);
393 break;
394 default:
395 DUNE_THROW(Dune::NotImplemented,
396 "wrong index");
397 } // end switch
398
399
400 using std::isfinite;
401 if (!isfinite(source[energyEq0Idx + phaseIdx]))
402 DUNE_THROW(NumericalProblem, "Calculated non-finite source, " << "Tw="<< Tw << " Tn="<< Tn<< " Ts="<< Ts);
403 }// end phases
404
405 // we only need to do this for when there is more than 1 fluid phase
406 if (enableChemicalNonEquilibrium)
407 {
408 // Here comes the catch: We are not doing energy conservation for the whole
409 // system, but rather for each individual phase.
410 // -> Therefore the energy fluxes over each phase boundary need be
411 // individually accounted for.
412 // -> Each particle crossing a phase boundary does carry some mass and
413 // thus energy!
414 // -> Therefore, this contribution needs to be added.
415 // -> the particle always brings the energy of the originating phase.
416 // -> Energy advectivly transported into a phase = the moles of a component that go into a phase
417 // * molMass * enthalpy of the component in the *originating* phase
418
419 const auto& fluidState = volVars.fluidState();
420
421 for(int phaseIdx = 0; phaseIdx < numEnergyEqFluid+numEnergyEqSolid; ++phaseIdx)
422 {
423 switch (phaseIdx)
424 {
425 case phase0Idx:
426 // sum up the transferred energy by the components into the wetting phase
427 for(int compIdx = 0; compIdx < numComponents; ++compIdx)
428 {
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) );
433 }
434 break;
435 case phase1Idx:
436 // sum up the transferred energy by the components into the nonwetting phase
437 for(int compIdx =0; compIdx<numComponents; ++compIdx)
438 {
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));
443 }
444 break;
445 case sPhaseIdx:
446 break; // no sorption
447 default:
448 DUNE_THROW(Dune::NotImplemented,
449 "wrong index");
450 } // end switch
451 } // end phases
452 } // EnableChemicalNonEquilibrium
453 } // end source
454};
455} // end namespace Dumux
456
457#endif
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
Definition: adapt.hh:17
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...
Provides 3rd order polynomial splines.