3.1-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
137};
138
140template<class IsothermalTraits, class Impl>
141class EnergyVolumeVariablesImplementation<IsothermalTraits, Impl, true>
142{
143 using Scalar = typename IsothermalTraits::PrimaryVariables::value_type;
144 using Idx = typename IsothermalTraits::ModelTraits::Indices;
146
147 static const int temperatureIdx = Idx::temperatureIdx;
148 static const int numEnergyEq = IsothermalTraits::ModelTraits::numEnergyEq();
149
150public:
151 // export the fluidstate
152 using FluidState = typename IsothermalTraits::FluidState;
153 using SolidState = typename IsothermalTraits::SolidState;
155 using FluidSystem = typename IsothermalTraits::FluidSystem;
156 using SolidSystem = typename IsothermalTraits::SolidSystem;
157
159 template<class ElemSol, class Problem, class Element, class Scv>
160 void updateTemperature(const ElemSol& elemSol,
161 const Problem& problem,
162 const Element& element,
163 const Scv& scv,
164 FluidState& fluidState,
165 SolidState& solidState)
166 {
167 if (numEnergyEq == 1)
168 {
169 // retrieve temperature from solution vector, all phases have the same temperature
170 const Scalar T = elemSol[scv.localDofIndex()][temperatureIdx];
171 for(int phaseIdx=0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
172 {
173 fluidState.setTemperature(phaseIdx, T);
174 }
175 solidState.setTemperature(T);
176 }
177
178 else
179 {
180 // if numEnergyEq == 2 this means we have 1 temp for fluid phase, one for solid
181 if (numEnergyEq == 2)
182 {
183 const Scalar T = elemSol[scv.localDofIndex()][temperatureIdx];
184 for(int phaseIdx=0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
185 {
186 fluidState.setTemperature(phaseIdx, T);
187 }
188 }
189 // this is for numEnergyEqFluid > 1
190 else
191 {
192 for(int phaseIdx=0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
193 {
194 // retrieve temperatures from solution vector, phases might have different temperature
195 const Scalar T = elemSol[scv.localDofIndex()][temperatureIdx + phaseIdx];
196 fluidState.setTemperature(phaseIdx, T);
197 }
198 }
199 const Scalar solidTemperature = elemSol[scv.localDofIndex()][temperatureIdx+numEnergyEq-1];
200 solidState.setTemperature(solidTemperature);
201 }
202 }
203
204 template<class ElemSol, class Problem, class Element, class Scv>
205 void updateSolidEnergyParams(const ElemSol &elemSol,
206 const Problem& problem,
207 const Element &element,
208 const Scv &scv,
209 SolidState & solidState)
210 {
211 Scalar cs = solidHeatCapacity_(elemSol, problem, element, scv, solidState);
212 solidState.setHeatCapacity(cs);
213
214 Scalar rhos = solidDensity_(elemSol, problem, element, scv, solidState);
215 solidState.setDensity(rhos);
216
217 Scalar lambdas = solidThermalConductivity_(elemSol, problem, element, scv, solidState);
218 solidState.setThermalConductivity(lambdas);
219 }
220
227 Scalar internalEnergy(const int phaseIdx) const
228 { return asImp_().fluidState().internalEnergy(phaseIdx); }
229
236 Scalar enthalpy(const int phaseIdx) const
237 { return asImp_().fluidState().enthalpy(phaseIdx); }
238
243 Scalar temperatureSolid() const
244 { return asImp_().solidState().temperature(); }
245
246
252 Scalar temperatureFluid(const int phaseIdx) const
253 { return asImp_().fluidState().temperature(phaseIdx); }
254
259 Scalar solidHeatCapacity() const
260 { return asImp_().solidState().heatCapacity(); }
261
266 Scalar solidDensity() const
267 { return asImp_().solidState().density(); }
268
273 { return asImp_().solidState().thermalConductivity(); }
274
279 Scalar fluidThermalConductivity(const int phaseIdx) const
280 { return FluidSystem::thermalConductivity(asImp_().fluidState(), phaseIdx); }
281
284 template<class ParameterCache>
285 static Scalar enthalpy(const FluidState& fluidState,
286 const ParameterCache& paramCache,
287 const int phaseIdx)
288 {
289 return FluidSystem::enthalpy(fluidState, paramCache, phaseIdx);
290 }
291
292protected:
293 const Impl &asImp_() const { return *static_cast<const Impl*>(this); }
294 Impl &asImp_() { return *static_cast<Impl*>(this); }
295
296private:
310 // \{
311
322 template<class ElemSol, class Problem, class Element, class Scv,
323 std::enable_if_t<!Detail::hasSolidHeatCapacity<typename Problem::SpatialParams, Element, Scv, ElemSol, SolidState>(), int> = 0>
324 Scalar solidHeatCapacity_(const ElemSol& elemSol,
325 const Problem& problem,
326 const Element& element,
327 const Scv& scv,
328 const SolidState& solidState)
329 {
330 return SolidSystem::heatCapacity(solidState);
331 }
332
343 template<class ElemSol, class Problem, class Element, class Scv,
344 std::enable_if_t<!Detail::hasSolidDensity<typename Problem::SpatialParams, Element, Scv, ElemSol, SolidState>(), int> = 0>
345 Scalar solidDensity_(const ElemSol& elemSol,
346 const Problem& problem,
347 const Element& element,
348 const Scv& scv,
349 const SolidState& solidState)
350 {
351 return SolidSystem::density(solidState);
352 }
353
364 template<class ElemSol, class Problem, class Element, class Scv,
365 std::enable_if_t<!Detail::hasSolidThermalConductivity<typename Problem::SpatialParams, Element, Scv, ElemSol, SolidState>(), int> = 0>
366 Scalar solidThermalConductivity_(const ElemSol& elemSol,
367 const Problem& problem,
368 const Element& element,
369 const Scv& scv,
370 const SolidState& solidState)
371 {
372 return SolidSystem::thermalConductivity(solidState);
373 }
374
375 // \}
376
381 // \{
382
394 template<class ElemSol, class Problem, class Element, class Scv,
395 std::enable_if_t<Detail::hasSolidHeatCapacity<typename Problem::SpatialParams, Element, Scv, ElemSol, SolidState>(), int> = 0>
396 Scalar solidHeatCapacity_(const ElemSol& elemSol,
397 const Problem& problem,
398 const Element& element,
399 const Scv& scv,
400 const SolidState& solidState)
401 {
402 static_assert(Detail::isInertSolidPhase<SolidSystem>::value,
403 "solidHeatCapacity can only be overwritten in the spatial params when the solid system is a simple InertSolidPhase\n"
404 "If you select a proper solid system, the solid heat capacity will be computed as stated in the solid system!");
405 return problem.spatialParams().solidHeatCapacity(element, scv, elemSol, solidState);
406 }
407
419 template<class ElemSol, class Problem, class Element, class Scv,
420 std::enable_if_t<Detail::hasSolidDensity<typename Problem::SpatialParams, Element, Scv, ElemSol, SolidState>(), int> = 0>
421 Scalar solidDensity_(const ElemSol& elemSol,
422 const Problem& problem,
423 const Element& element,
424 const Scv& scv,
425 const SolidState& solidState)
426 {
427 static_assert(Detail::isInertSolidPhase<SolidSystem>::value,
428 "solidDensity can only be overwritten in the spatial params when the solid system is a simple InertSolidPhase\n"
429 "If you select a proper solid system, the solid density will be computed as stated in the solid system!");
430 return problem.spatialParams().solidDensity(element, scv, elemSol, solidState);
431 }
432
444 template<class ElemSol, class Problem, class Element, class Scv,
445 std::enable_if_t<Detail::hasSolidThermalConductivity<typename Problem::SpatialParams, Element, Scv, ElemSol, SolidState>(), int> = 0>
446 Scalar solidThermalConductivity_(const ElemSol& elemSol,
447 const Problem& problem,
448 const Element& element,
449 const Scv& scv,
450 const SolidState& solidState)
451 {
452 static_assert(Detail::isInertSolidPhase<SolidSystem>::value,
453 "solidThermalConductivity can only be overwritten in the spatial params when the solid system is a simple InertSolidPhase\n"
454 "If you select a proper solid system, the solid thermal conductivity will be computed as stated in the solid system!");
455 return problem.spatialParams().solidThermalConductivity(element, scv, elemSol, solidState);
456 }
457
458 // \}
459
460};
461
462} // end namespace Dumux
463
464#endif
A solid phase consisting of a single inert solid component.
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
Property tag Indices
Definition: porousmediumflow/sequential/properties.hh:59
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 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
Impl & asImp_()
Definition: porousmediumflow/nonisothermal/volumevariables.hh:294
Scalar solidThermalConductivity() const
Returns the thermal conductivity of the solid phase in the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:272
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:252
Scalar solidDensity() const
Returns the mass density of the rock matrix in the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:266
Scalar solidHeatCapacity() const
Returns the total heat capacity of the rock matrix in the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:259
static Scalar enthalpy(const FluidState &fluidState, const ParameterCache &paramCache, const int phaseIdx)
Definition: porousmediumflow/nonisothermal/volumevariables.hh:285
Scalar fluidThermalConductivity(const int phaseIdx) const
Returns the thermal conductivity of a fluid phase in the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:279
const Impl & asImp_() const
Definition: porousmediumflow/nonisothermal/volumevariables.hh:293
void updateSolidEnergyParams(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, SolidState &solidState)
Definition: porousmediumflow/nonisothermal/volumevariables.hh:205
typename IsothermalTraits::SolidState SolidState
Definition: porousmediumflow/nonisothermal/volumevariables.hh:153
Scalar internalEnergy(const int phaseIdx) const
Returns the total internal energy of a phase in the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:227
typename IsothermalTraits::FluidSystem FluidSystem
export the underlying fluid system
Definition: porousmediumflow/nonisothermal/volumevariables.hh:155
Scalar temperatureSolid() const
Returns the temperature in fluid / solid phase(s) the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:243
Scalar enthalpy(const int phaseIdx) const
Returns the total enthalpy of a phase in the sub-control volume.
Definition: porousmediumflow/nonisothermal/volumevariables.hh:236
typename IsothermalTraits::FluidState FluidState
Definition: porousmediumflow/nonisothermal/volumevariables.hh:152
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:160
typename IsothermalTraits::SolidSystem SolidSystem
Definition: porousmediumflow/nonisothermal/volumevariables.hh:156
The isothermal base class.
Definition: porousmediumflow/volumevariables.hh:40
Base class for the model specific class which provides access to all volume averaged quantities.