GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/cellcentered/tpfa/gridfluxvariablescache.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 24 29 82.8%
Functions: 98 248 39.5%
Branches: 54 101 53.5%

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 CCTpfaDiscretization
10 * \brief Flux variable caches on a gridview
11 */
12 #ifndef DUMUX_DISCRETIZATION_CCTPFA_GRID_FLUXVARSCACHE_HH
13 #define DUMUX_DISCRETIZATION_CCTPFA_GRID_FLUXVARSCACHE_HH
14
15 #include <dumux/parallel/parallel_for.hh>
16
17 // make the local view function available whenever we use this class
18 #include <dumux/discretization/localview.hh>
19 #include <dumux/discretization/cellcentered/tpfa/elementfluxvariablescache.hh>
20
21 namespace Dumux {
22
23 /*!
24 * \ingroup CCTpfaDiscretization
25 * \brief Flux variable caches traits
26 */
27 template<class P, class FVC, class FVCF>
28 struct CCTpfaDefaultGridFVCTraits
29 {
30 using Problem = P;
31 using FluxVariablesCache = FVC;
32 using FluxVariablesCacheFiller = FVCF;
33
34 template<class GridFluxVariablesCache, bool cachingEnabled>
35 using LocalView = CCTpfaElementFluxVariablesCache<GridFluxVariablesCache, cachingEnabled>;
36 };
37
38 /*!
39 * \ingroup CCTpfaDiscretization
40 * \brief Flux variable caches on a gridview
41 * \note The class is specialized for a version with and without grid caching
42 */
43 template<class Problem,
44 class FluxVariablesCache,
45 class FluxVariablesCacheFiller,
46 bool EnableGridFluxVariablesCache = false,
47 class Traits = CCTpfaDefaultGridFVCTraits<Problem, FluxVariablesCache, FluxVariablesCacheFiller> >
48 class CCTpfaGridFluxVariablesCache;
49
50 /*!
51 * \ingroup CCTpfaDiscretization
52 * \brief Flux variable caches on a gridview with grid caching enabled
53 * \note The flux caches of the gridview are stored which is memory intensive but faster
54 */
55 template<class P, class FVC, class FVCF, class TheTraits>
56 class CCTpfaGridFluxVariablesCache<P, FVC, FVCF, true, TheTraits>
57 {
58 using Problem = typename TheTraits::Problem;
59 using ThisType = CCTpfaGridFluxVariablesCache<P, FVC, FVCF, true, TheTraits>;
60
61 //! the flux variable cache filler type
62 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
63 public:
64 //! the flux variables cache traits
65 using Traits = TheTraits;
66
67 //! export the flux variable cache type
68 using FluxVariablesCache = typename Traits::FluxVariablesCache;
69
70 //! make it possible to query if caching is enabled
71 static constexpr bool cachingEnabled = true;
72
73 //! export the type of the local view
74 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
75
76 // The constructor
77 CCTpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
78
79 // When global caching is enabled, precompute transmissibilities and stencils for all the scv faces
80 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
81 10632 void update(const GridGeometry& gridGeometry,
82 const GridVolumeVariables& gridVolVars,
83 const SolutionVector& sol,
84 bool forceUpdate = false)
85 {
86 // only do the update if fluxes are solution dependent or if update is forced
87
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 4345 times.
7608 if (FluxVariablesCacheFiller::isSolDependent || forceUpdate)
88 {
89 // instantiate helper class to fill the caches
90 3167 FluxVariablesCacheFiller filler(problem());
91
92 6334 fluxVarsCache_.resize(gridGeometry.numScvf());
93
94 7004323 Dumux::parallelFor(gridGeometry.gridView().size(0), [&](const std::size_t eIdx)
95 {
96 // Prepare the geometries within the elements of the stencil
97
2/4
✓ Branch 1 taken 1735 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1735 times.
✗ Branch 5 not taken.
7001524 const auto element = gridGeometry.element(eIdx);
98
5/9
✓ Branch 1 taken 3503 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3503 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1768 times.
✓ Branch 7 taken 1735 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1735 times.
✗ Branch 11 not taken.
14003048 const auto fvGeometry = localView(gridGeometry).bind(element);
99
7/14
✓ Branch 1 taken 6054915 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6054915 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1768 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 936841 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 936841 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 8000 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 8000 times.
✗ Branch 19 not taken.
20454109 const auto elemVolVars = localView(gridVolVars).bind(element, fvGeometry, sol);
100
101
16/18
✓ Branch 0 taken 22012488 times.
✓ Branch 1 taken 5507988 times.
✓ Branch 2 taken 22012488 times.
✓ Branch 3 taken 5507988 times.
✓ Branch 4 taken 83308 times.
✓ Branch 5 taken 5020340 times.
✓ Branch 6 taken 5588116 times.
✓ Branch 7 taken 953983 times.
✓ Branch 8 taken 5588116 times.
✓ Branch 9 taken 933643 times.
✓ Branch 10 taken 5564918 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 48000 times.
✓ Branch 13 taken 8000 times.
✓ Branch 14 taken 48000 times.
✓ Branch 15 taken 8000 times.
✓ Branch 16 taken 48000 times.
✗ Branch 17 not taken.
52908411 for (auto&& scvf : scvfs(fvGeometry))
102 {
103
8/12
✓ Branch 0 taken 83308 times.
✓ Branch 1 taken 5000000 times.
✓ Branch 2 taken 83308 times.
✓ Branch 3 taken 5000000 times.
✓ Branch 4 taken 5564918 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5564918 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 48000 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 48000 times.
✗ Branch 11 not taken.
61027718 filler.fill(*this, fluxVarsCache_[scvf.index()], element, fvGeometry, elemVolVars, scvf, forceUpdate);
104 }
105 });
106 }
107 10632 }
108
109 template<class FVElementGeometry, class ElementVolumeVariables>
110 2464026 void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
111 const FVElementGeometry& fvGeometry,
112 const ElementVolumeVariables& elemVolVars)
113 {
114 if (FluxVariablesCacheFiller::isSolDependent)
115 {
116 4928052 const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element);
117
118 // instantiate filler class
119 2464026 FluxVariablesCacheFiller filler(problem());
120
121 // update the caches inside this element
122
4/4
✓ Branch 0 taken 9589476 times.
✓ Branch 1 taken 2402826 times.
✓ Branch 2 taken 9589476 times.
✓ Branch 3 taken 2402826 times.
14517528 for (const auto& scvf : scvfs(fvGeometry))
123 19178952 filler.fill(*this, fluxVarsCache_[scvf.index()], element, fvGeometry, elemVolVars, scvf);
124
125 // update the caches in the neighbors
126
4/4
✓ Branch 0 taken 9502628 times.
✓ Branch 1 taken 2464026 times.
✓ Branch 2 taken 9502628 times.
✓ Branch 3 taken 2464026 times.
22059398 for (const auto& dataJ : fvGeometry.gridGeometry().connectivityMap()[globalI])
127 {
128 9502628 const auto elementJ = fvGeometry.gridGeometry().element(dataJ.globalJ);
129
2/2
✓ Branch 0 taken 9265988 times.
✓ Branch 1 taken 9265988 times.
37773872 for (const auto scvfIdxJ : dataJ.scvfsJ)
130 {
131 9265988 const auto& scvfJ = fvGeometry.scvf(scvfIdxJ);
132 18531976 filler.fill(*this, fluxVarsCache_[scvfJ.index()], elementJ, fvGeometry, elemVolVars, scvfJ);
133 }
134 }
135 }
136 2464026 }
137
138 // access operators in the case of caching
139 template<class SubControlVolumeFace>
140 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
141
3/6
✓ Branch 0 taken 9056254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20950878 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11894624 times.
✗ Branch 5 not taken.
615856184 { return fluxVarsCache_[scvf.index()]; }
142
143 template<class SubControlVolumeFace>
144 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
145 { return fluxVarsCache_[scvf.index()]; }
146
147 const Problem& problem() const
148 { return *problemPtr_; }
149
150 private:
151 const Problem* problemPtr_;
152
153 std::vector<FluxVariablesCache> fluxVarsCache_;
154 std::vector<std::size_t> globalScvfIndices_;
155 };
156
157 /*!
158 * \ingroup CCTpfaDiscretization
159 * \brief Flux variable caches on a gridview with grid caching disabled
160 */
161 template<class P, class FVC, class FVCF, class TheTraits>
162 class CCTpfaGridFluxVariablesCache<P, FVC, FVCF, false, TheTraits>
163 {
164 using Problem = typename TheTraits::Problem;
165 using ThisType = CCTpfaGridFluxVariablesCache<P, FVC, FVCF, false, TheTraits>;
166
167 //! the flux variable cache filler type
168 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
169 public:
170 //! the flux variables cache traits
171 using Traits = TheTraits;
172
173 //! export the flux variable cache type
174 using FluxVariablesCache = typename Traits::FluxVariablesCache;
175
176 //! make it possible to query if caching is enabled
177 static constexpr bool cachingEnabled = false;
178
179 //! export the type of the local view
180 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
181
182 // The constructor
183
1/8
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3 CCTpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
184
185 //! When global flux variables caching is disabled, we don't need to update the cache
186 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
187 void update(const GridGeometry& gridGeometry,
188 const GridVolumeVariables& gridVolVars,
189 const SolutionVector& sol,
190 bool forceUpdate = false) {}
191
192 //! When global flux variables caching is disabled, we don't need to update the cache
193 template<class FVElementGeometry, class ElementVolumeVariables>
194 void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
195 const FVElementGeometry& fvGeometry,
196 const ElementVolumeVariables& elemVolVars) {}
197
198 const Problem& problem() const
199 { return *problemPtr_; }
200
201 private:
202 const Problem* problemPtr_;
203 };
204
205 } // end namespace Dumux
206
207 #endif
208