GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/porousmediumflow/nonisothermal/localresidual.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 22 36 61.1%
Functions: 72 962 7.5%
Branches: 12 28 42.9%

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