GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/flux/cctpfa/darcyslaw.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 142 142 100.0%
Functions: 258 286 90.2%
Branches: 120 139 86.3%

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 CCTpfaFlux
10 * \brief Darcy's law for cell-centered finite volume schemes with two-point flux approximation
11 */
12 #ifndef DUMUX_DISCRETIZATION_CC_TPFA_DARCYS_LAW_HH
13 #define DUMUX_DISCRETIZATION_CC_TPFA_DARCYS_LAW_HH
14
15 #include <dumux/common/math.hh>
16 #include <dumux/common/parameters.hh>
17 #include <dumux/common/properties.hh>
18
19 #include <dumux/discretization/method.hh>
20 #include <dumux/discretization/extrusion.hh>
21 #include <dumux/discretization/cellcentered/tpfa/computetransmissibility.hh>
22
23 namespace Dumux {
24
25 // forward declarations
26 template<class TypeTag, class DiscretizationMethod>
27 class DarcysLawImplementation;
28
29 /*!
30 * \ingroup CCTpfaFlux
31 * \brief Darcy's law for cell-centered finite volume schemes with two-point flux approximation
32 * \note Darcy's law is specialized for network and surface grids (i.e. if grid dim < dimWorld)
33 * \tparam Scalar the scalar type for scalar physical quantities
34 * \tparam GridGeometry the grid geometry
35 * \tparam isNetwork whether we are computing on a network grid embedded in a higher world dimension
36 */
37 template<class Scalar, class GridGeometry, bool isNetwork>
38 class CCTpfaDarcysLaw;
39
40 /*!
41 * \ingroup CCTpfaFlux
42 * \brief Darcy's law for cell-centered finite volume schemes with two-point flux approximation
43 * \note Darcy's law is specialized for network and surface grids (i.e. if grid dim < dimWorld)
44 */
45 template <class TypeTag>
46 class DarcysLawImplementation<TypeTag, DiscretizationMethods::CCTpfa>
47 : public CCTpfaDarcysLaw<GetPropType<TypeTag, Properties::Scalar>,
48 GetPropType<TypeTag, Properties::GridGeometry>,
49 (GetPropType<TypeTag, Properties::GridGeometry>::GridView::dimension < GetPropType<TypeTag, Properties::GridGeometry>::GridView::dimensionworld)>
50 {};
51
52 /*!
53 * \ingroup CCTpfaFlux
54 * \brief Class that fills the cache corresponding to tpfa Darcy's Law
55 */
56 template<class GridGeometry>
57 class TpfaDarcysLawCacheFiller
58 {
59 using FVElementGeometry = typename GridGeometry::LocalView;
60 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
61 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
62
63 public:
64 //! Function to fill a TpfaDarcysLawCache of a given scvf
65 //! This interface has to be met by any advection-related cache filler class
66 //! TODO: Probably get cache type out of the filler
67 template<class FluxVariablesCache, class Problem, class ElementVolumeVariables, class FluxVariablesCacheFiller>
68 208576029 static void fill(FluxVariablesCache& scvfFluxVarsCache,
69 const Problem& problem,
70 const Element& element,
71 const FVElementGeometry& fvGeometry,
72 const ElementVolumeVariables& elemVolVars,
73 const SubControlVolumeFace& scvf,
74 const FluxVariablesCacheFiller& fluxVarsCacheFiller)
75 {
76 406098944 scvfFluxVarsCache.updateAdvection(problem, element, fvGeometry, elemVolVars, scvf);
77 }
78 };
79
80 /*!
81 * \ingroup CCTpfaFlux
82 * \brief The cache corresponding to tpfa Darcy's Law
83 */
84 template<class AdvectionType, class GridGeometry>
85 2280 class TpfaDarcysLawCache
86 {
87 using Scalar = typename AdvectionType::Scalar;
88 using FVElementGeometry = typename GridGeometry::LocalView;
89 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
90 using Element = typename GridGeometry::GridView::template Codim<0>::Entity;
91
92 public:
93 using Filler = TpfaDarcysLawCacheFiller<GridGeometry>;
94
95 template<class Problem, class ElementVolumeVariables>
96 197696415 void updateAdvection(const Problem& problem,
97 const Element& element,
98 const FVElementGeometry& fvGeometry,
99 const ElementVolumeVariables& elemVolVars,
100 const SubControlVolumeFace &scvf)
101 {
102 197696415 tij_ = AdvectionType::calculateTransmissibility(problem, element, fvGeometry, elemVolVars, scvf);
103 }
104
105 39294082 const Scalar& advectionTij() const
106 530106200 { return tij_; }
107
108 private:
109 Scalar tij_;
110 };
111
112 /*!
113 * \ingroup CCTpfaFlux
114 * \brief Specialization of the CCTpfaDarcysLaw grids where dim=dimWorld
115 */
116 template<class ScalarType, class GridGeometry>
117 class CCTpfaDarcysLaw<ScalarType, GridGeometry, /*isNetwork*/ false>
118 {
119 using ThisType = CCTpfaDarcysLaw<ScalarType, GridGeometry, /*isNetwork*/ false>;
120 using FVElementGeometry = typename GridGeometry::LocalView;
121 using SubControlVolume = typename GridGeometry::SubControlVolume;
122 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
123 using Extrusion = Extrusion_t<GridGeometry>;
124 using GridView = typename GridGeometry::GridView;
125 using Element = typename GridView::template Codim<0>::Entity;
126
127 static constexpr int dim = GridView::dimension;
128 static constexpr int dimWorld = GridView::dimensionworld;
129
130 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
131
132 public:
133 //! state the scalar type of the law
134 using Scalar = ScalarType;
135
136 using DiscretizationMethod = DiscretizationMethods::CCTpfa;
137 //! state the discretization method this implementation belongs to
138 static constexpr DiscretizationMethod discMethod{};
139
140 //! state the type for the corresponding cache
141 using Cache = TpfaDarcysLawCache<ThisType, GridGeometry>;
142
143 /*!
144 * \brief Returns the advective flux of a fluid phase
145 * across the given sub-control volume face.
146 * \note This assembles the term
147 * \f$-|\sigma| \mathbf{n}^T \mathbf{K} \left( \nabla p - \rho \mathbf{g} \right)\f$,
148 * where \f$|\sigma|\f$ is the area of the face and \f$\mathbf{n}\f$ is the outer
149 * normal vector. Thus, the flux is given in N*m, and can be converted
150 * into a volume flux (m^3/s) or mass flux (kg/s) by applying an upwind scheme
151 * for the mobility or the product of density and mobility, respectively.
152 */
153 template<class Problem, class ElementVolumeVariables, class ElementFluxVarsCache>
154 582401360 static Scalar flux(const Problem& problem,
155 const Element& element,
156 const FVElementGeometry& fvGeometry,
157 const ElementVolumeVariables& elemVolVars,
158 const SubControlVolumeFace& scvf,
159 int phaseIdx,
160 const ElementFluxVarsCache& elemFluxVarsCache)
161 {
162
5/6
✓ Branch 0 taken 268 times.
✓ Branch 1 taken 578552964 times.
✓ Branch 3 taken 217 times.
✓ Branch 4 taken 51 times.
✓ Branch 6 taken 217 times.
✗ Branch 7 not taken.
582401360 static const bool enableGravity = getParamFromGroup<bool>(problem.paramGroup(), "Problem.EnableGravity");
163
164
2/2
✓ Branch 0 taken 132274327 times.
✓ Branch 1 taken 88901000 times.
582401360 const auto& fluxVarsCache = elemFluxVarsCache[scvf];
165
166 // Get the inside and outside volume variables
167
2/2
✓ Branch 0 taken 132274327 times.
✓ Branch 1 taken 88901000 times.
807424815 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
168 582401360 const auto& insideVolVars = elemVolVars[insideScv];
169 582401360 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
170
171
2/2
✓ Branch 0 taken 490971998 times.
✓ Branch 1 taken 87581234 times.
582401360 if (enableGravity)
172 {
173 // do averaging for the density over all neighboring elements
174
4/4
✓ Branch 0 taken 941265 times.
✓ Branch 1 taken 490030733 times.
✓ Branch 2 taken 30658732 times.
✓ Branch 3 taken 38532 times.
956985179 const auto rho = scvf.boundary() ? outsideVolVars.density(phaseIdx)
175 490039769 : (insideVolVars.density(phaseIdx) + outsideVolVars.density(phaseIdx))*0.5;
176
177 // Obtain inside and outside pressures
178
1/2
✓ Branch 0 taken 8100024 times.
✗ Branch 1 not taken.
490981214 const auto pInside = insideVolVars.pressure(phaseIdx);
179 490981214 const auto pOutside = outsideVolVars.pressure(phaseIdx);
180
181 490981214 const auto& tij = fluxVarsCache.advectionTij();
182
2/2
✓ Branch 0 taken 22558708 times.
✓ Branch 1 taken 38532 times.
490981214 const auto& g = problem.spatialParams().gravity(scvf.ipGlobal());
183
184 //! compute alpha := n^T*K*g
185
2/2
✓ Branch 0 taken 490030733 times.
✓ Branch 1 taken 941265 times.
959365188 const auto alpha_inside = vtmv(scvf.unitOuterNormal(), insideVolVars.permeability(), g)*insideVolVars.extrusionFactor();
186
187
2/2
✓ Branch 0 taken 490030733 times.
✓ Branch 1 taken 941265 times.
490981214 Scalar flux = tij*(pInside - pOutside) + rho*Extrusion::area(fvGeometry, scvf)*alpha_inside;
188
189 //! On interior faces we have to add K-weighted gravitational contributions
190
2/2
✓ Branch 0 taken 490030733 times.
✓ Branch 1 taken 941265 times.
490981214 if (!scvf.boundary())
191 {
192
2/2
✓ Branch 0 taken 67038768 times.
✓ Branch 1 taken 422991965 times.
490039709 const auto& outsideScv = fvGeometry.scv(scvf.outsideScvIdx());
193
2/2
✓ Branch 0 taken 160392 times.
✓ Branch 1 taken 157235284 times.
490039709 const auto outsideK = outsideVolVars.permeability();
194
2/2
✓ Branch 0 taken 160392 times.
✓ Branch 1 taken 489870341 times.
976123618 const auto outsideTi = fvGeometry.gridGeometry().isPeriodic()
195
2/2
✓ Branch 0 taken 160392 times.
✓ Branch 1 taken 489870341 times.
490039709 ? computeTpfaTransmissibility(fvGeometry, fvGeometry.flipScvf(scvf.index()), outsideScv, outsideK, outsideVolVars.extrusionFactor())
196 508483305 : -1.0*computeTpfaTransmissibility(fvGeometry, scvf, outsideScv, outsideK, outsideVolVars.extrusionFactor());
197 957520710 const auto alpha_outside = vtmv(scvf.unitOuterNormal(), outsideK, g)*outsideVolVars.extrusionFactor();
198
199 490039709 flux -= rho*tij/outsideTi*(alpha_inside - alpha_outside);
200 }
201
202 490822094 return flux;
203 }
204 else
205 {
206 // Obtain inside and outside pressures
207
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
91420146 const auto pInside = insideVolVars.pressure(phaseIdx);
208 90440946 const auto pOutside = outsideVolVars.pressure(phaseIdx);
209
210 // return flux
211 91420146 return fluxVarsCache.advectionTij()*(pInside - pOutside);
212 }
213 }
214
215 // The flux variables cache has to be bound to an element prior to flux calculations
216 // During the binding, the transmissibility will be computed and stored using the method below.
217 template<class Problem, class ElementVolumeVariables>
218
2/2
✓ Branch 0 taken 92914875 times.
✓ Branch 1 taken 83352498 times.
207148589 static Scalar calculateTransmissibility(const Problem& problem,
219 const Element& element,
220 const FVElementGeometry& fvGeometry,
221 const ElementVolumeVariables& elemVolVars,
222 const SubControlVolumeFace& scvf)
223 {
224
2/2
✓ Branch 0 taken 1200 times.
✓ Branch 1 taken 1080 times.
2280 Scalar tij;
225
226
2/2
✓ Branch 0 taken 92916075 times.
✓ Branch 1 taken 83353578 times.
207148589 const auto insideScvIdx = scvf.insideScvIdx();
227 207148589 const auto& insideScv = fvGeometry.scv(insideScvIdx);
228 207148589 const auto& insideVolVars = elemVolVars[insideScvIdx];
229
230
2/2
✓ Branch 0 taken 10009121 times.
✓ Branch 1 taken 193024432 times.
239891019 const Scalar ti = computeTpfaTransmissibility(fvGeometry, scvf, insideScv,
231 207148589 getPermeability_(problem, insideVolVars, scvf.ipGlobal()),
232
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 2160 times.
2280 insideVolVars.extrusionFactor());
233
234 // on the boundary (dirichlet) we only need ti
235
2/2
✓ Branch 0 taken 10009121 times.
✓ Branch 1 taken 193024432 times.
207148589 if (scvf.boundary())
236 10114757 tij = Extrusion::area(fvGeometry, scvf)*ti;
237
238 // otherwise we compute a tpfa harmonic mean
239 else
240 {
241
2/2
✓ Branch 0 taken 83353578 times.
✓ Branch 1 taken 83353578 times.
197033832 const auto outsideScvIdx = scvf.outsideScvIdx();
242 // as we assemble fluxes from the neighbor to our element the outside index
243 // refers to the scv of our element, so we use the scv method
244 197033832 const auto& outsideScv = fvGeometry.scv(outsideScvIdx);
245
2/2
✓ Branch 1 taken 320784 times.
✓ Branch 2 taken 166386372 times.
197033832 const auto& outsideVolVars = elemVolVars[outsideScvIdx];
246
2/2
✓ Branch 0 taken 320784 times.
✓ Branch 1 taken 192703648 times.
197033832 const Scalar tj = fvGeometry.gridGeometry().isPeriodic()
247
2/2
✓ Branch 0 taken 320784 times.
✓ Branch 1 taken 192703648 times.
197033832 ? computeTpfaTransmissibility(fvGeometry, fvGeometry.flipScvf(scvf.index()), outsideScv, getPermeability_(problem, outsideVolVars, scvf.ipGlobal()), outsideVolVars.extrusionFactor())
248 229416548 : -1.0*computeTpfaTransmissibility(fvGeometry, scvf, outsideScv, getPermeability_(problem, outsideVolVars, scvf.ipGlobal()), outsideVolVars.extrusionFactor());
249
250 // harmonic mean (check for division by zero!)
251 // TODO: This could lead to problems!? Is there a better way to do this?
252
1/2
✓ Branch 0 taken 193024432 times.
✗ Branch 1 not taken.
197033832 if (ti*tj <= 0.0)
253 tij = 0;
254 else
255 197033832 tij = Extrusion::area(fvGeometry, scvf)*(ti * tj)/(ti + tj);
256 }
257
258 207148589 return tij;
259 }
260
261 private:
262 template<class Problem, class VolumeVariables,
263 std::enable_if_t<!Problem::SpatialParams::evaluatePermeabilityAtScvfIP(), int> = 0>
264
2/2
✓ Branch 0 taken 196236 times.
✓ Branch 1 taken 25838920 times.
51874076 static decltype(auto) getPermeability_(const Problem& problem,
265 const VolumeVariables& volVars,
266 const GlobalPosition& scvfIpGlobal)
267
4/4
✓ Branch 0 taken 9896889 times.
✓ Branch 1 taken 157525088 times.
✓ Branch 3 taken 73302 times.
✓ Branch 4 taken 2795844 times.
396057985 { return volVars.permeability(); }
268
269 template<class Problem, class VolumeVariables,
270 std::enable_if_t<Problem::SpatialParams::evaluatePermeabilityAtScvfIP(), int> = 0>
271 static decltype(auto) getPermeability_(const Problem& problem,
272 const VolumeVariables& volVars,
273 const GlobalPosition& scvfIpGlobal)
274 { return problem.spatialParams().permeabilityAtPos(scvfIpGlobal); }
275 };
276
277 /*!
278 * \ingroup CCTpfaFlux
279 * \brief Specialization of the CCTpfaDarcysLaw grids where dim < dimWorld (network/surface grids)
280 */
281 template<class ScalarType, class GridGeometry>
282 class CCTpfaDarcysLaw<ScalarType, GridGeometry, /*isNetwork*/ true>
283 {
284 using ThisType = CCTpfaDarcysLaw<ScalarType, GridGeometry, /*isNetwork*/ true>;
285 using FVElementGeometry = typename GridGeometry::LocalView;
286 using SubControlVolume = typename GridGeometry::SubControlVolume;
287 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
288 using Extrusion = Extrusion_t<GridGeometry>;
289 using GridView = typename GridGeometry::GridView;
290 using Element = typename GridView::template Codim<0>::Entity;
291
292 static constexpr int dim = GridView::dimension;
293 static constexpr int dimWorld = GridView::dimensionworld;
294
295 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
296
297 public:
298 //! state the scalar type of the law
299 using Scalar = ScalarType;
300
301 using DiscretizationMethod = DiscretizationMethods::CCTpfa;
302 //! state the discretization method this implementation belongs to
303 static constexpr DiscretizationMethod discMethod{};
304
305 //! state the type for the corresponding cache
306 using Cache = TpfaDarcysLawCache<ThisType, GridGeometry>;
307
308 /*!
309 * \brief Returns the advective flux of a fluid phase
310 * across the given sub-control volume face.
311 * \note This assembles the term
312 * \f$-|\sigma| \mathbf{n}^T \mathbf{K} \left( \nabla p - \rho \mathbf{g} \right)\f$,
313 * where \f$|\sigma|\f$ is the area of the face and \f$\mathbf{n}\f$ is the outer
314 * normal vector. Thus, the flux is given in N*m, and can be converted
315 * into a volume flux (m^3/s) or mass flux (kg/s) by applying an upwind scheme
316 * for the mobility or the product of density and mobility, respectively.
317 */
318 template<class Problem, class ElementVolumeVariables, class ElementFluxVarsCache>
319 65759581 static Scalar flux(const Problem& problem,
320 const Element& element,
321 const FVElementGeometry& fvGeometry,
322 const ElementVolumeVariables& elemVolVars,
323 const SubControlVolumeFace& scvf,
324 int phaseIdx,
325 const ElementFluxVarsCache& elemFluxVarsCache)
326 {
327
5/6
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 62272638 times.
✓ Branch 3 taken 75 times.
✓ Branch 4 taken 44 times.
✓ Branch 6 taken 75 times.
✗ Branch 7 not taken.
65759581 static const bool gravity = getParamFromGroup<bool>(problem.paramGroup(), "Problem.EnableGravity");
328
329
2/2
✓ Branch 0 taken 1827198 times.
✓ Branch 1 taken 1796939 times.
65759581 const auto& fluxVarsCache = elemFluxVarsCache[scvf];
330
331 // Get the inside and outside volume variables
332
2/2
✓ Branch 0 taken 1827198 times.
✓ Branch 1 taken 1796939 times.
72870542 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
333 65759581 const auto& insideVolVars = elemVolVars[insideScv];
334 65759581 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
335
336
2/2
✓ Branch 0 taken 39373642 times.
✓ Branch 1 taken 22899115 times.
65759581 if (gravity)
337 {
338 // do averaging for the density over all neighboring elements
339 118280942 const auto rho = [&]()
340 {
341 // boundaries
342
3/4
✓ Branch 0 taken 72052 times.
✓ Branch 1 taken 39301142 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 448 times.
39373642 if (scvf.boundary())
343 72052 return outsideVolVars.density(phaseIdx);
344
345 // inner faces with two neighboring elements
346
3/4
✓ Branch 0 taken 36863818 times.
✓ Branch 1 taken 2437324 times.
✓ Branch 2 taken 448 times.
✗ Branch 3 not taken.
39301590 else if (scvf.numOutsideScvs() == 1)
347 36864266 return (insideVolVars.density(phaseIdx) + outsideVolVars.density(phaseIdx))*0.5;
348
349 // inner faces in networks (general case)
350 else
351 {
352 2437324 Scalar rho(insideVolVars.density(phaseIdx));
353
2/4
✓ Branch 0 taken 8353167 times.
✓ Branch 1 taken 2437324 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10790491 for (unsigned int i = 0; i < scvf.numOutsideScvs(); ++i)
354 {
355 8353167 const auto outsideScvIdx = scvf.outsideScvIdx(i);
356 8353167 const auto& outsideVolVars = elemVolVars[outsideScvIdx];
357 8353167 rho += outsideVolVars.density(phaseIdx);
358 }
359 2437324 return rho/(scvf.numOutsideScvs()+1);
360 }
361 39453650 }();
362
363 39453650 const auto& tij = fluxVarsCache.advectionTij();
364 39453650 const auto& g = problem.spatialParams().gravity(scvf.ipGlobal());
365
366 // Obtain inside and outside pressures
367 39453650 const auto pInside = insideVolVars.pressure(phaseIdx);
368 118280942 const auto pOutside = [&]()
369 {
370 // Dirichlet boundaries and inner faces with one neighbor
371
3/4
✓ Branch 0 taken 36935870 times.
✓ Branch 1 taken 2437324 times.
✓ Branch 2 taken 448 times.
✗ Branch 3 not taken.
39373642 if (scvf.numOutsideScvs() == 1)
372 36936318 return outsideVolVars.pressure(phaseIdx);
373
374 // inner faces in networks (general case)
375 else
376 {
377 2437324 Scalar sumTi(tij);
378 2437324 Scalar sumPTi(tij*pInside);
379
380 // add inside gravitational contribution
381 2437324 sumPTi += rho*Extrusion::area(fvGeometry, scvf)
382 2437324 *insideVolVars.extrusionFactor()
383 2437324 *vtmv(scvf.unitOuterNormal(), insideVolVars.permeability(), g);
384
385
2/4
✓ Branch 0 taken 8353167 times.
✓ Branch 1 taken 2437324 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10790491 for (unsigned int i = 0; i < scvf.numOutsideScvs(); ++i)
386 {
387 8353167 const auto outsideScvIdx = scvf.outsideScvIdx(i);
388 8353167 const auto& flippedScvf = fvGeometry.flipScvf(scvf.index(), i);
389 8353167 const auto& outsideVolVars = elemVolVars[outsideScvIdx];
390 8353167 const auto& outsideFluxVarsCache = elemFluxVarsCache[flippedScvf];
391 8353167 sumTi += outsideFluxVarsCache.advectionTij();
392 8353167 sumPTi += outsideFluxVarsCache.advectionTij()*outsideVolVars.pressure(phaseIdx);
393
394 // add outside gravitational contribution
395 8353167 sumPTi += rho*Extrusion::area(fvGeometry, scvf)
396 8353167 *outsideVolVars.extrusionFactor()
397 16706334 *vtmv(flippedScvf.unitOuterNormal(), outsideVolVars.permeability(), g);
398 }
399 2437324 return sumPTi/sumTi;
400 }
401 39453650 }();
402
403 //! precompute alpha := n^T*K*g
404
2/2
✓ Branch 0 taken 39301590 times.
✓ Branch 1 taken 72052 times.
78907300 const auto alpha_inside = vtmv(scvf.unitOuterNormal(), insideVolVars.permeability(), g)*insideVolVars.extrusionFactor();
405
406
2/2
✓ Branch 0 taken 39301590 times.
✓ Branch 1 taken 72052 times.
39453650 Scalar flux = tij*(pInside - pOutside) + Extrusion::area(fvGeometry, scvf)*rho*alpha_inside;
407
408 //! On interior faces with one neighbor we have to add K-weighted gravitational contributions
409
4/4
✓ Branch 0 taken 39301590 times.
✓ Branch 1 taken 72052 times.
✓ Branch 2 taken 36864266 times.
✓ Branch 3 taken 2437324 times.
39453650 if (!scvf.boundary() && scvf.numOutsideScvs() == 1)
410 {
411
2/2
✓ Branch 0 taken 41008 times.
✓ Branch 1 taken 41008 times.
36944042 const auto& outsideScv = fvGeometry.scv(scvf.outsideScvIdx());
412 36944042 const auto& outsideScvf = fvGeometry.flipScvf(scvf.index());
413 36944042 const auto outsideK = outsideVolVars.permeability();
414 36944042 const auto outsideTi = computeTpfaTransmissibility(fvGeometry, outsideScvf, outsideScv, outsideK, outsideVolVars.extrusionFactor());
415 36944042 const auto alpha_outside = vtmv(outsideScvf.unitOuterNormal(), outsideK, g)*outsideVolVars.extrusionFactor();
416
417 36944042 flux -= rho*tij/outsideTi*(alpha_inside + alpha_outside);
418 }
419
420 return flux;
421 }
422 else
423 {
424 // Obtain inside and outside pressures
425 26305931 const auto pInside = insideVolVars.pressure(phaseIdx);
426 75510977 const auto pOutside = [&]()
427 {
428 // Dirichlet boundaries and inner faces with two neighboring elements
429
3/4
✓ Branch 0 taken 21849410 times.
✓ Branch 1 taken 1019445 times.
✓ Branch 2 taken 30260 times.
✗ Branch 3 not taken.
22899115 if (scvf.numOutsideScvs() <= 1)
430 21879670 return outsideVolVars.pressure(phaseIdx);
431
432 // inner faces in networks (general case)
433 else
434 {
435 1019445 const auto& insideFluxVarsCache = elemFluxVarsCache[scvf];
436 1019445 Scalar sumTi(insideFluxVarsCache.advectionTij());
437 1019445 Scalar sumPTi(insideFluxVarsCache.advectionTij()*pInside);
438
439
2/4
✓ Branch 0 taken 3040045 times.
✓ Branch 1 taken 1019445 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4059490 for (unsigned int i = 0; i < scvf.numOutsideScvs(); ++i)
440 {
441 3040045 const auto outsideScvIdx = scvf.outsideScvIdx(i);
442 3040045 const auto& flippedScvf = fvGeometry.flipScvf(scvf.index(), i);
443 3040045 const auto& outsideVolVars = elemVolVars[outsideScvIdx];
444 3040045 const auto& outsideFluxVarsCache = elemFluxVarsCache[flippedScvf];
445 3040045 sumTi += outsideFluxVarsCache.advectionTij();
446 3040045 sumPTi += outsideFluxVarsCache.advectionTij()*outsideVolVars.pressure(phaseIdx);
447 }
448 1019445 return sumPTi/sumTi;
449 }
450 26305931 }();
451
452 // return flux
453 26305931 return fluxVarsCache.advectionTij()*(pInside - pOutside);
454 }
455 }
456
457 // The flux variables cache has to be bound to an element prior to flux calculations
458 // During the binding, the transmissibility will be computed and stored using the method below.
459 template<class Problem, class ElementVolumeVariables>
460
2/2
✓ Branch 0 taken 2557481 times.
✓ Branch 1 taken 2471149 times.
10097704 static Scalar calculateTransmissibility(const Problem& problem,
461 const Element& element,
462 const FVElementGeometry& fvGeometry,
463 const ElementVolumeVariables& elemVolVars,
464 const SubControlVolumeFace& scvf)
465 {
466 Scalar tij;
467
468
2/2
✓ Branch 0 taken 2557481 times.
✓ Branch 1 taken 2471149 times.
10097704 const auto insideScvIdx = scvf.insideScvIdx();
469 10097704 const auto& insideScv = fvGeometry.scv(insideScvIdx);
470 10097704 const auto& insideVolVars = elemVolVars[insideScvIdx];
471
472
2/2
✓ Branch 0 taken 5143674 times.
✓ Branch 1 taken 91376 times.
10097704 const Scalar ti = computeTpfaTransmissibility(fvGeometry, scvf, insideScv,
473 10097704 getPermeability_(problem, insideVolVars, scvf.ipGlobal()),
474 insideVolVars.extrusionFactor());
475
476 // for the boundary (dirichlet) or at branching points we only need ti
477
4/4
✓ Branch 0 taken 5143674 times.
✓ Branch 1 taken 91376 times.
✓ Branch 2 taken 8852 times.
✓ Branch 3 taken 5134822 times.
10097704 if (scvf.boundary() || scvf.numOutsideScvs() > 1)
478 183820 tij = Extrusion::area(fvGeometry, scvf)*ti;
479
480 // otherwise we compute a tpfa harmonic mean
481 else
482 {
483
2/2
✓ Branch 0 taken 2469709 times.
✓ Branch 1 taken 2469709 times.
9913884 const auto outsideScvIdx = scvf.outsideScvIdx();
484 // as we assemble fluxes from the neighbor to our element the outside index
485 // refers to the scv of our element, so we use the scv method
486 9913884 const auto& outsideScv = fvGeometry.scv(outsideScvIdx);
487 9913884 const auto& outsideVolVars = elemVolVars[outsideScvIdx];
488
1/2
✓ Branch 0 taken 195404 times.
✗ Branch 1 not taken.
9913884 const Scalar tj = computeTpfaTransmissibility(fvGeometry, fvGeometry.flipScvf(scvf.index()), outsideScv,
489 9913884 getPermeability_(problem, outsideVolVars, scvf.ipGlobal()),
490 outsideVolVars.extrusionFactor());
491
492 // harmonic mean (check for division by zero!)
493 // TODO: This could lead to problems!? Is there a better way to do this?
494
1/2
✓ Branch 0 taken 5134822 times.
✗ Branch 1 not taken.
9913884 if (ti*tj <= 0.0)
495 tij = 0;
496 else
497 9913884 tij = Extrusion::area(fvGeometry, scvf)*(ti * tj)/(ti + tj);
498 }
499
500 10097704 return tij;
501 }
502
503 private:
504 template<class Problem, class VolumeVariables,
505 std::enable_if_t<!Problem::SpatialParams::evaluatePermeabilityAtScvfIP(), int> = 0>
506 static decltype(auto) getPermeability_(const Problem& problem,
507 const VolumeVariables& volVars,
508 const GlobalPosition& scvfIpGlobal)
509
5/5
✓ Branch 0 taken 5103798 times.
✓ Branch 1 taken 89862 times.
✓ Branch 2 taken 194788 times.
✓ Branch 3 taken 39260 times.
✓ Branch 4 taken 1480 times.
10368606 { return volVars.permeability(); }
510
511 template<class Problem, class VolumeVariables,
512 std::enable_if_t<Problem::SpatialParams::evaluatePermeabilityAtScvfIP(), int> = 0>
513 650 static decltype(auto) getPermeability_(const Problem& problem,
514 const VolumeVariables& volVars,
515 const GlobalPosition& scvfIpGlobal)
516
3/4
✓ Branch 0 taken 616 times.
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 616 times.
✗ Branch 3 not taken.
1266 { return problem.spatialParams().permeabilityAtPos(scvfIpGlobal); }
517 };
518
519 } // end namespace Dumux
520
521 #endif
522