GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/porousmediumflow/nonisothermal/localresidual.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 25 25 100.0%
Functions: 138 141 97.9%
Branches: 8 14 57.1%

Line Branch Exec Source
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-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 /*!
8 * \file
9 * \ingroup NIModel
10 * \brief Element-wise calculation of the local residual for non-isothermal
11 * fully implicit models. See NIModel for the detailed description.
12 */
13
14 #ifndef DUMUX_ENERGY_LOCAL_RESIDUAL_HH
15 #define DUMUX_ENERGY_LOCAL_RESIDUAL_HH
16
17 #include <dumux/common/properties.hh>
18 #include <dumux/common/typetraits/typetraits.hh>
19 #include <dumux/common/numeqvector.hh>
20
21 namespace Dumux {
22
23 // forward declaration
24 template<class TypeTag, bool enableEneryBalance>
25 class EnergyLocalResidualImplementation;
26
27 template<class TypeTag>
28 using EnergyLocalResidual = EnergyLocalResidualImplementation<TypeTag, GetPropType<TypeTag, Properties::ModelTraits>::enableEnergyBalance()>;
29
30 /*!
31 * \ingroup NIModel
32 * \brief Element-wise calculation of the energy residual for isothermal problems.
33 */
34 template<class TypeTag>
35 class EnergyLocalResidualImplementation<TypeTag, false>
36 {
37 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
38 using NumEqVector = Dumux::NumEqVector<GetPropType<TypeTag, Properties::PrimaryVariables>>;
39 using Problem = GetPropType<TypeTag, Properties::Problem>;
40 using VolumeVariables = GetPropType<TypeTag, Properties::VolumeVariables>;
41 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
42 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
43 using FluxVariables = GetPropType<TypeTag, Properties::FluxVariables>;
44
45 public:
46 template <typename T = void>
47 static void fluidPhaseStorage(NumEqVector& storage,
48 const SubControlVolume& scv,
49 const VolumeVariables& volVars,
50 int phaseIdx)
51 {
52 static_assert(AlwaysFalse<T>::value, "Deprecated interface that has been removed! Use new interface with additional argument problem instead. Will be entirely removed after release 3.10.");
53 }
54
55 /*!
56 * \brief The energy storage in the fluid phase with index phaseIdx.
57 */
58 static void fluidPhaseStorage(NumEqVector& storage,
59 const Problem& problem,
60 const SubControlVolume& scv,
61 const VolumeVariables& volVars,
62 int phaseIdx)
63 {}
64
65 /*!
66 * \brief The energy storage in the solid matrix.
67 *
68 * \param storage The mass of the component within the sub-control volume
69 * \param scv The sub-control volume
70 * \param volVars The volume variables
71 */
72 static void solidPhaseStorage(NumEqVector& storage,
73 const SubControlVolume& scv,
74 const VolumeVariables& volVars)
75 {}
76
77 /*!
78 * \brief The advective phase energy fluxes.
79 *
80 * \param flux The flux
81 * \param fluxVars The flux variables.
82 * \param phaseIdx The phase index
83 */
84 static void heatConvectionFlux(NumEqVector& flux,
85 FluxVariables& fluxVars,
86 int phaseIdx)
87 {}
88
89 /*!
90 * \brief The diffusive energy fluxes
91 *
92 * \param flux The flux
93 * \param fluxVars The flux variables.
94 */
95 static void heatConductionFlux(NumEqVector& flux,
96 FluxVariables& fluxVars)
97 {}
98
99 /*!
100 * \brief The dispersive energy fluxes
101 *
102 * \param flux The flux
103 * \param fluxVars The flux variables.
104 */
105 static void heatDispersionFlux(NumEqVector& flux,
106 FluxVariables& fluxVars)
107 {}
108 };
109
110 /*!
111 * \ingroup NIModel
112 * \brief Element-wise calculation of the energy residual for non-isothermal problems.
113 */
114 template<class TypeTag>
115 class EnergyLocalResidualImplementation<TypeTag, true>
116 {
117 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
118 using NumEqVector = Dumux::NumEqVector<GetPropType<TypeTag, Properties::PrimaryVariables>>;
119 using Problem = GetPropType<TypeTag, Properties::Problem>;
120 using VolumeVariables = GetPropType<TypeTag, Properties::VolumeVariables>;
121 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
122 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
123 using FluxVariables = GetPropType<TypeTag, Properties::FluxVariables>;
124 using GridView = typename GetPropType<TypeTag, Properties::GridGeometry>::GridView;
125 using Element = typename GridView::template Codim<0>::Entity;
126 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
127 using ModelTraits = GetPropType<TypeTag, Properties::ModelTraits>;
128 using Indices = typename ModelTraits::Indices;
129
130 static constexpr int numPhases = ModelTraits::numFluidPhases();
131 enum { energyEqIdx = Indices::energyEqIdx };
132
133 public:
134
135 /*!
136 * \brief The energy storage in the fluid phase with index phaseIdx.
137 */
138 598485348 static void fluidPhaseStorage(NumEqVector& storage,
139 const Problem& problem,
140 const SubControlVolume& scv,
141 const VolumeVariables& volVars,
142 int phaseIdx)
143 {
144 // this implementation of the potential energy contribution is only correct
145 // if gravity vector is constant in space and time
146 598485348 const auto& x = scv.dofPosition();
147
2/2
✓ Branch 0 taken 1526400 times.
✓ Branch 1 taken 763200 times.
600774948 const auto gravityPotential = x*problem.spatialParams().gravity(x);
148
149 598485348 storage[energyEqIdx] += volVars.porosity()
150 598485348 * volVars.density(phaseIdx)
151 559018084 * volVars.saturation(phaseIdx)
152 598485348 * (volVars.internalEnergy(phaseIdx) - gravityPotential);
153 598070308 }
154
155 template <typename T = void>
156 static void fluidPhaseStorage(NumEqVector& storage,
157 const SubControlVolume& scv,
158 const VolumeVariables& volVars,
159 int phaseIdx)
160 {
161 static_assert(AlwaysFalse<T>::value, "Deprecated interface that has been removed! Use new interface with additional argument problem instead. Will be entirely removed after release 3.10.");
162 }
163
164 /*!
165 * \brief The energy storage in the solid matrix
166 *
167 * \param storage The mass of the component within the sub-control volume
168 * \param scv The sub-control volume
169 * \param volVars The volume variables
170 */
171 288215932 static void solidPhaseStorage(NumEqVector& storage,
172 const SubControlVolume& scv,
173 const VolumeVariables& volVars)
174 {
175 288215932 storage[energyEqIdx] += volVars.temperature()
176 288215932 * volVars.solidHeatCapacity()
177 288215932 * volVars.solidDensity()
178 288215932 * (1.0 - volVars.porosity());
179 }
180
181 /*!
182 * \brief The advective phase energy fluxes
183 *
184 * \param flux The flux
185 * \param fluxVars The flux variables.
186 * \param phaseIdx The phase index
187 */
188 433170327 static void heatConvectionFlux(NumEqVector& flux,
189 FluxVariables& fluxVars,
190 int phaseIdx)
191 {
192 // this implementation of the potential energy contribution is only correct
193 // if gravity vector is constant in space and time
194 433170327 const auto& x = fluxVars.scvFace().ipGlobal();
195 433170327 const auto gravityPotential = x*fluxVars.problem().spatialParams().gravity(x);
196
197
2/4
✓ Branch 0 taken 849821 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1135459 times.
✗ Branch 3 not taken.
840477358 auto upwindTerm = [=](const auto& volVars){
198
2/4
✓ Branch 0 taken 849821 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1135459 times.
✗ Branch 3 not taken.
409292311 return volVars.density(phaseIdx)*volVars.mobility(phaseIdx)
199
2/4
✓ Branch 0 taken 849821 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1135459 times.
✗ Branch 3 not taken.
411277591 * (volVars.enthalpy(phaseIdx) - gravityPotential);
200 };
201
202 433170327 flux[energyEqIdx] += fluxVars.advectiveFlux(phaseIdx, upwindTerm);
203 433170327 }
204
205 /*!
206 * \brief The diffusive energy fluxes
207 *
208 * \param flux The flux
209 * \param fluxVars The flux variables.
210 */
211 212437125 static void heatConductionFlux(NumEqVector& flux,
212 FluxVariables& fluxVars)
213 {
214 212437125 flux[energyEqIdx] += fluxVars.heatConductionFlux();
215 }
216
217 /*!
218 * \brief The dispersive energy fluxes
219 *
220 * \param flux The flux
221 * \param fluxVars The flux variables.
222 */
223 5622400 static void heatDispersionFlux(NumEqVector& flux,
224 FluxVariables& fluxVars)
225 {
226
227 if constexpr (ModelTraits::enableThermalDispersion())
228 {
229 5622400 flux[energyEqIdx] += fluxVars.thermalDispersionFlux();
230 }
231 }
232
233
234 /*!
235 * \brief heat transfer between the phases for nonequilibrium models
236 *
237 * \param source The source which ought to be simulated
238 * \param element An element which contains part of the control volume
239 * \param fvGeometry The finite-volume geometry
240 * \param elemVolVars The volume variables of the current element
241 * \param scv The sub-control volume over which we integrate the source term
242 */
243 static void computeSourceEnergy(NumEqVector& source,
244 const Element& element,
245 const FVElementGeometry& fvGeometry,
246 const ElementVolumeVariables& elemVolVars,
247 const SubControlVolume &scv)
248 {}
249 };
250
251 } // end namespace Dumux
252
253 #endif
254