3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
porousmediumflow/nonisothermal/volumevariables.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
26#ifndef DUMUX_ENERGY_VOLUME_VARIABLES_HH
27#define DUMUX_ENERGY_VOLUME_VARIABLES_HH
28
29#include <type_traits>
30#include <dune/common/std/type_traits.hh>
31
34
35namespace Dumux {
36
37#ifndef DOXYGEN
38namespace Detail {
39// helper structs and functions detecting if the user-defined spatial params class has user-specified functions
40// for solidHeatCapacity, solidDensity, and solidThermalConductivity.
41
42template <typename T, typename ...Ts>
43using SolidHeatCapacityDetector = decltype(std::declval<T>().solidHeatCapacity(std::declval<Ts>()...));
44
45template<class T, typename ...Args>
46static constexpr bool hasSolidHeatCapacity()
47{ return Dune::Std::is_detected<SolidHeatCapacityDetector, T, Args...>::value; }
48
49template <typename T, typename ...Ts>
50using SolidDensityDetector = decltype(std::declval<T>().solidDensity(std::declval<Ts>()...));
51
52template<class T, typename ...Args>
53static constexpr bool hasSolidDensity()
54{ return Dune::Std::is_detected<SolidDensityDetector, T, Args...>::value; }
55
56template <typename T, typename ...Ts>
57using SolidThermalConductivityDetector = decltype(std::declval<T>().solidThermalConductivity(std::declval<Ts>()...));
58
59template<class T, typename ...Args>
60static constexpr bool hasSolidThermalConductivity()
61{ return Dune::Std::is_detected<SolidThermalConductivityDetector, T, Args...>::value; }
62
63template<class SolidSystem>
64struct isInertSolidPhase : public std::false_type {};
65
66template<class Scalar, class Component>
67struct isInertSolidPhase<SolidSystems::InertSolidPhase<Scalar, Component>> : public std::true_type {};
68
69} // end namespace Detail
70#endif
71
72
73// forward declaration
74template <class IsothermalTraits, class Impl, bool enableEnergyBalance>
76
84template<class IsothermalTraits, class Impl>
85using EnergyVolumeVariables = EnergyVolumeVariablesImplementation<IsothermalTraits,Impl, IsothermalTraits::ModelTraits::enableEnergyBalance()>;
86
91template<class IsothermalTraits, class Impl>
92class EnergyVolumeVariablesImplementation<IsothermalTraits, Impl, false>
93{
94 using Scalar = typename IsothermalTraits::PrimaryVariables::value_type;
95
96public:
97 using FluidState = typename IsothermalTraits::FluidState;
98 using SolidState = typename IsothermalTraits::SolidState;
99 using FluidSystem = typename IsothermalTraits::FluidSystem;
100
102 template<class ElemSol, class Problem, class Element, class Scv>
103 void updateTemperature(const ElemSol& elemSol,
104 const Problem& problem,
105 const Element& element,
106 const Scv& scv,
107 FluidState& fluidState,
108 SolidState& solidState)
109 {
110 // retrieve temperature from solution vector, all phases have the same temperature
111 Scalar T = problem.temperatureAtPos(scv.dofPosition());
112 for(int phaseIdx=0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
113 {
114 fluidState.setTemperature(phaseIdx, T);
115 }
116 solidState.setTemperature(T);
117 }
118
119 template<class ElemSol, class Problem, class Element, class Scv>
120 void updateSolidEnergyParams(const ElemSol &elemSol,
121 const Problem& problem,
122 const Element &element,
123 const Scv &scv,
124 SolidState & solidState)
125 {}
126
129 template<class FluidState, class ParameterCache>
130 static Scalar enthalpy(const FluidState& fluidState,
131 const ParameterCache& paramCache,
132 const int phaseIdx)
133 {
134 return 0;
135 }
136
139 {}
140
141};
142
144template<class Traits, class Impl>
145class EnergyVolumeVariablesImplementation<Traits, Impl, true>
146{
147 using Scalar = typename Traits::PrimaryVariables::value_type;
148 using Idx = typename Traits::ModelTraits::Indices;
150 using EffCondModel = typename Traits::EffectiveThermalConductivityModel;
151
152 static constexpr int temperatureIdx = Idx::temperatureIdx;
153 static constexpr int numEnergyEq = Traits::ModelTraits::numEnergyEq();
154
155 static constexpr bool fullThermalEquilibrium = (numEnergyEq == 1);
156 static constexpr bool fluidThermalEquilibrium = (numEnergyEq == 2);
157
158public:
159 // export the fluidstate
160 using FluidState = typename Traits::FluidState;
161 using SolidState = typename Traits::SolidState;
163 using FluidSystem = typename Traits::FluidSystem;
164 using SolidSystem = typename Traits::SolidSystem;
165
167 template<class ElemSol, class Problem, class Element, class Scv>
168 void updateTemperature(const ElemSol& elemSol,
169 const Problem& problem,
170 const Element& element,
171 const Scv& scv,
172 FluidState& fluidState,
173 SolidState& solidState)
174 {
175 if constexpr (fullThermalEquilibrium)
176 {
177 // retrieve temperature from solution vector, all phases have the same temperature
178 const Scalar T = elemSol[scv.localDofIndex()][temperatureIdx];
179 for(int phaseIdx=0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
180 {
181 fluidState.setTemperature(phaseIdx, T);
182 }
183 solidState.setTemperature(T);
184 }
185
186 else
187 {
188 // this means we have 1 temp for fluid phase, one for solid
189 if constexpr (fluidThermalEquilibrium)
190 {
191 const Scalar T = elemSol[scv.localDofIndex()][temperatureIdx];
192 for(int phaseIdx=0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
193 {
194 fluidState.setTemperature(phaseIdx, T);
195 }
196 }
197 // this is for numEnergyEqFluid > 1
198 else
199 {
200 for(int phaseIdx=0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
201 {
202 // retrieve temperatures from solution vector, phases might have different temperature
203 const Scalar T = elemSol[scv.localDofIndex()][temperatureIdx + phaseIdx];
204 fluidState.setTemperature(phaseIdx, T);
205 }
206 }
207 const Scalar solidTemperature = elemSol[scv.localDofIndex()][temperatureIdx+numEnergyEq-1];
208 solidState.setTemperature(solidTemperature);
209 }
210 }
211
212 template<class ElemSol, class Problem, class Element, class Scv>
213 void updateSolidEnergyParams(const ElemSol &elemSol,
214 const Problem& problem,
215 const Element &element,
216 const Scv &scv,
217 SolidState & solidState)
218 {
219 Scalar cs = solidHeatCapacity_(elemSol, problem, element, scv, solidState);
220 solidState.setHeatCapacity(cs);
221
222 Scalar rhos = solidDensity_(elemSol, problem, element, scv, solidState);
223 solidState.setDensity(rhos);
224
225 Scalar lambdas = solidThermalConductivity_(elemSol, problem, element, scv, solidState);
226 solidState.setThermalConductivity(lambdas);
227 }
228
229 // updates the effective thermal conductivity
231 {
232 if constexpr (fullThermalEquilibrium)
233 {
234 // Full Thermal Equilibirum: One effectiveThermalConductivity value for all phases (solid & fluid).
235 lambdaEff_[0] = EffCondModel::effectiveThermalConductivity(asImp_());
236 }
237 else if constexpr (fluidThermalEquilibrium)
238 {
239 // Fluid Thermal Equilibrium (Partial Nonequilibrium): One effectiveThermalConductivity for the fluids, one for the solids.
240 Scalar fluidLambda = 0.0;
241 for (int phaseIdx = 0; phaseIdx < FluidSystem::numPhases; phaseIdx++)
242 fluidLambda += fluidThermalConductivity(phaseIdx) * asImp_().saturation(phaseIdx) * asImp_().porosity();
243
244 lambdaEff_[0] = fluidLambda;
245 lambdaEff_[numEnergyEq-1] = solidThermalConductivity() * (1.0 - asImp_().porosity());
246 }
247 else
248 {
249 // Full Thermal Nonequilibrium: One effectiveThermal Conductivity per phase (solid & fluid).
250 for (int phaseIdx = 0; phaseIdx < FluidSystem::numPhases; phaseIdx++)
251 lambdaEff_[phaseIdx] = fluidThermalConductivity(phaseIdx) * asImp_().saturation(phaseIdx) * asImp_().porosity();
252 lambdaEff_[numEnergyEq-1] = solidThermalConductivity() * (1.0 - asImp_().porosity());
253 }
254 }
255
262 Scalar internalEnergy(const int phaseIdx) const
263 { return asImp_().fluidState().internalEnergy(phaseIdx); }
264
271 Scalar enthalpy(const int phaseIdx) const
272 { return asImp_().fluidState().enthalpy(phaseIdx); }
273
278 Scalar temperatureSolid() const
279 { return asImp_().solidState().temperature(); }
280
281
287 Scalar temperatureFluid(const int phaseIdx) const
288 { return asImp_().fluidState().temperature(phaseIdx); }
289
294 Scalar solidHeatCapacity() const
295 { return asImp_().solidState().heatCapacity(); }
296
301 Scalar solidDensity() const
302 { return asImp_().solidState().density(); }
303
309 { return asImp_().solidState().thermalConductivity(); }
310
315 Scalar fluidThermalConductivity(const int phaseIdx) const
316 { return FluidSystem::thermalConductivity(asImp_().fluidState(), phaseIdx); }
317
322 template< bool enable = fullThermalEquilibrium,
323 std::enable_if_t<enable, int> = 0>
325 { return lambdaEff_[0]; }
326
331 template< bool enable = fluidThermalEquilibrium,
332 std::enable_if_t<enable, int> = 0>
334 { return lambdaEff_[0]; }
335
341 template< bool enable = fluidThermalEquilibrium,
342 std::enable_if_t<enable, int> = 0>
344 { return lambdaEff_[numEnergyEq-1]; }
345
351 template< bool enable = (!fullThermalEquilibrium && !fluidThermalEquilibrium),
352 std::enable_if_t<enable, int> = 0>
353 Scalar effectivePhaseThermalConductivity(const int phaseIdx) const
354 { return lambdaEff_[phaseIdx]; }
355
358 template<class ParameterCache>
359 static Scalar enthalpy(const FluidState& fluidState,
360 const ParameterCache& paramCache,
361 const int phaseIdx)
362 {
363 return FluidSystem::enthalpy(fluidState, paramCache, phaseIdx);
364 }
365
366protected:
367 const Impl &asImp_() const { return *static_cast<const Impl*>(this); }
368 Impl &asImp_() { return *static_cast<Impl*>(this); }
369
370private:
384 // \{
385
396 template<class ElemSol, class Problem, class Element, class Scv,
397 std::enable_if_t<!Detail::hasSolidHeatCapacity<typename Problem::SpatialParams, Element, Scv, ElemSol, SolidState>(), int> = 0>
398 Scalar solidHeatCapacity_(const ElemSol& elemSol,
399 const Problem& problem,
400 const Element& element,
401 const Scv& scv,
402 const SolidState& solidState)
403 {
404 return SolidSystem::heatCapacity(solidState);
405 }
406
417 template<class ElemSol, class Problem, class Element, class Scv,
418 std::enable_if_t<!Detail::hasSolidDensity<typename Problem::SpatialParams, Element, Scv, ElemSol, SolidState>(), int> = 0>
419 Scalar solidDensity_(const ElemSol& elemSol,
420 const Problem& problem,
421 const Element& element,
422 const Scv& scv,
423 const SolidState& solidState)
424 {
425 return SolidSystem::density(solidState);
426 }
427
438 template<class ElemSol, class Problem, class Element, class Scv,
439 std::enable_if_t<!Detail::hasSolidThermalConductivity<typename Problem::SpatialParams, Element, Scv, ElemSol, SolidState>(), int> = 0>
440 Scalar solidThermalConductivity_(const ElemSol& elemSol,
441 const Problem& problem,
442 const Element& element,
443 const Scv& scv,
444 const SolidState& solidState)
445 {
446 return SolidSystem::thermalConductivity(solidState);
447 }
448
449 // \}
450
455 // \{
456
468 template<class ElemSol, class Problem, class Element, class Scv,
469 std::enable_if_t<Detail::hasSolidHeatCapacity<typename Problem::SpatialParams, Element, Scv, ElemSol, SolidState>(), int> = 0>
470 Scalar solidHeatCapacity_(const ElemSol& elemSol,
471 const Problem& problem,
472 const Element& element,
473 const Scv& scv,
474 const SolidState& solidState)
475 {
476 static_assert(Detail::isInertSolidPhase<SolidSystem>::value,
477 "solidHeatCapacity can only be overwritten in the spatial params when the solid system is a simple InertSolidPhase\n"
478 "If you select a proper solid system, the solid heat capacity will be computed as stated in the solid system!");
479 return problem.spatialParams().solidHeatCapacity(element, scv, elemSol, solidState);
480 }
481
493 template<class ElemSol, class Problem, class Element, class Scv,
494 std::enable_if_t<Detail::hasSolidDensity<typename Problem::SpatialParams, Element, Scv, ElemSol, SolidState>(), int> = 0>
495 Scalar solidDensity_(const ElemSol& elemSol,
496 const Problem& problem,
497 const Element& element,
498 const Scv& scv,
499 const SolidState& solidState)
500 {
501 static_assert(Detail::isInertSolidPhase<SolidSystem>::value,
502 "solidDensity can only be overwritten in the spatial params when the solid system is a simple InertSolidPhase\n"
503 "If you select a proper solid system, the solid density will be computed as stated in the solid system!");
504 return problem.spatialParams().solidDensity(element, scv, elemSol, solidState);
505 }
506
518 template<class ElemSol, class Problem, class Element, class Scv,
519 std::enable_if_t<Detail::hasSolidThermalConductivity<typename Problem::SpatialParams, Element, Scv, ElemSol, SolidState>(), int> = 0>
520 Scalar solidThermalConductivity_(const ElemSol& elemSol,
521 const Problem& problem,
522 const Element& element,
523 const Scv& scv,
524 const SolidState& solidState)
525 {
526 static_assert(Detail::isInertSolidPhase<SolidSystem>::value,
527 "solidThermalConductivity can only be overwritten in the spatial params when the solid system is a simple InertSolidPhase\n"
528 "If you select a proper solid system, the solid thermal conductivity will be computed as stated in the solid system!");
529 return problem.spatialParams().solidThermalConductivity(element, scv, elemSol, solidState);
530 }
531
532 std::array<Scalar, numEnergyEq> lambdaEff_;
533 // \}
534
535};
536
537} // end namespace Dumux
538
539#endif
The simplest solid phase consisting of a single solid component.
OneCSolid< Scalar, ComponentT, true > InertSolidPhase
A solid phase consisting of a single inert solid component.
Definition: 1csolid.hh:137
Definition: adapt.hh:29
std::string solidTemperature() noexcept
I/O name of solid temperature for non-equilibrium models.
Definition: name.hh:60
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:65
Definition: porousmediumflow/nonisothermal/volumevariables.hh:75
void updateSolidEnergyParams(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, SolidState &solidState)
Definition: porousmediumflow/nonisothermal/volumevariables.hh:120
static Scalar enthalpy(const FluidState &fluidState, const ParameterCache &paramCache, const int phaseIdx)
Definition: porousmediumflow/nonisothermal/volumevariables.hh:130
typename IsothermalTraits::FluidSystem FluidSystem
Definition: porousmediumflow/nonisothermal/volumevariables.hh:99
typename IsothermalTraits::SolidState SolidState
Definition: porousmediumflow/nonisothermal/volumevariables.hh:98
typename IsothermalTraits::FluidState FluidState
Definition: porousmediumflow/nonisothermal/volumevariables.hh:97
void updateEffectiveThermalConductivity()
The effective thermal conductivity is zero for isothermal models.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:138
void updateTemperature(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
The temperature is obtained from the problem as a constant for isothermal models.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:103
Scalar temperatureFluid(const int phaseIdx) const
Returns the temperature of a fluid phase assuming thermal nonequilibrium the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:287
typename Traits::FluidSystem FluidSystem
export the underlying fluid system
Definition: porousmediumflow/nonisothermal/volumevariables.hh:163
Scalar solidDensity() const
Returns the mass density of the rock matrix in the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:301
const Impl & asImp_() const
Definition: porousmediumflow/nonisothermal/volumevariables.hh:367
Scalar enthalpy(const int phaseIdx) const
Returns the total enthalpy of a phase in the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:271
Scalar effectivePhaseThermalConductivity(const int phaseIdx) const
Returns the effective thermal conductivity per fluid phase in the sub-control volume....
Definition: porousmediumflow/nonisothermal/volumevariables.hh:353
Scalar fluidThermalConductivity(const int phaseIdx) const
Returns the thermal conductivity of a fluid phase in the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:315
Scalar temperatureSolid() const
Returns the temperature in fluid / solid phase(s) the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:278
Scalar internalEnergy(const int phaseIdx) const
Returns the total internal energy of a phase in the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:262
void updateEffectiveThermalConductivity()
Definition: porousmediumflow/nonisothermal/volumevariables.hh:230
typename Traits::FluidState FluidState
Definition: porousmediumflow/nonisothermal/volumevariables.hh:160
Scalar solidHeatCapacity() const
Returns the total heat capacity of the rock matrix in the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:294
void updateTemperature(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
The temperature is obtained from the problem as a constant for isothermal models.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:168
Scalar effectiveSolidThermalConductivity() const
Returns the effective thermal conductivity of the solid phase in the sub-control volume....
Definition: porousmediumflow/nonisothermal/volumevariables.hh:343
static Scalar enthalpy(const FluidState &fluidState, const ParameterCache &paramCache, const int phaseIdx)
Definition: porousmediumflow/nonisothermal/volumevariables.hh:359
typename Traits::SolidState SolidState
Definition: porousmediumflow/nonisothermal/volumevariables.hh:161
void updateSolidEnergyParams(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, SolidState &solidState)
Definition: porousmediumflow/nonisothermal/volumevariables.hh:213
Scalar effectiveThermalConductivity() const
Returns the effective thermal conductivity in the sub-control volume. Specific to equilibirum models...
Definition: porousmediumflow/nonisothermal/volumevariables.hh:324
Scalar solidThermalConductivity() const
Returns the thermal conductivity of the solid phase in the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:308
Scalar effectiveFluidThermalConductivity() const
Returns the effective thermal conductivity of the fluids in the sub-control volume....
Definition: porousmediumflow/nonisothermal/volumevariables.hh:333
Impl & asImp_()
Definition: porousmediumflow/nonisothermal/volumevariables.hh:368
typename Traits::SolidSystem SolidSystem
Definition: porousmediumflow/nonisothermal/volumevariables.hh:164
The isothermal base class.
Definition: porousmediumflow/volumevariables.hh:40
Base class for the model specific class which provides access to all volume averaged quantities.