GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/cvfe/gridfluxvariablescache.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 14 21 66.7%
Functions: 59 203 29.1%
Branches: 41 90 45.6%

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 CVFEDiscretization
10 * \brief Global flux variable cache
11 */
12 #ifndef DUMUX_DISCRETIZATION_CVFE_GRID_FLUXVARSCACHE_HH
13 #define DUMUX_DISCRETIZATION_CVFE_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/cvfe/elementfluxvariablescache.hh>
20
21 namespace Dumux {
22
23 /*!
24 * \ingroup CVFEDiscretization
25 * \brief Flux variable caches traits
26 */
27 template<class P, class FVC>
28 struct CVFEDefaultGridFVCTraits
29 {
30 using Problem = P;
31 using FluxVariablesCache = FVC;
32
33 template<class GridFluxVariablesCache, bool cachingEnabled>
34 using LocalView = CVFEElementFluxVariablesCache<GridFluxVariablesCache, cachingEnabled>;
35 };
36
37 /*!
38 * \ingroup CVFEDiscretization
39 * \brief Flux variable caches on a gridview
40 * \note The class is specialized for a version with and without grid caching
41 */
42 template<class Problem,
43 class FluxVariablesCache,
44 bool cachingEnabled = false,
45 class Traits = CVFEDefaultGridFVCTraits<Problem, FluxVariablesCache> >
46 class CVFEGridFluxVariablesCache;
47
48 /*!
49 * \ingroup CVFEDiscretization
50 * \brief Flux variable caches on a gridview with grid caching enabled
51 * \note The flux caches of the gridview are stored which is memory intensive but faster
52 */
53 template<class P, class FVC, class Traits>
54 class CVFEGridFluxVariablesCache<P, FVC, true, Traits>
55 {
56 using Problem = typename Traits::Problem;
57 using ThisType = CVFEGridFluxVariablesCache<P, FVC, true, Traits>;
58
59 public:
60 //! export the flux variable cache type
61 using FluxVariablesCache = typename Traits::FluxVariablesCache;
62
63 //! make it possible to query if caching is enabled
64 static constexpr bool cachingEnabled = true;
65
66 //! export the type of the local view
67 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
68
69 CVFEGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
70
71 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
72 3644 void update(const GridGeometry& gridGeometry,
73 const GridVolumeVariables& gridVolVars,
74 const SolutionVector& sol,
75 bool forceUpdate = false)
76 {
77 // Here, we do not do anything unless it is a forced update
78
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 3510 times.
3644 if (forceUpdate)
79 {
80 152 fluxVarsCache_.resize(gridGeometry.gridView().size(0));
81 2172337 Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem()](const std::size_t eIdx)
82 {
83 // Prepare the geometries within the elements of the stencil
84 313503 const auto element = gridGeometry.element(eIdx);
85
8/20
✓ Branch 1 taken 34464 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 34464 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 34464 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 34464 times.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 15 taken 10400 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 10400 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 10400 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 10400 times.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
671870 const auto fvGeometry = localView(gridGeometry).bind(element);
86
4/8
✓ Branch 1 taken 34464 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 34464 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10400 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 10400 times.
✗ Branch 11 not taken.
537278 const auto elemVolVars = localView(gridVolVars).bind(element, fvGeometry, sol);
87
88 // only update shape functions for fluxes if update is forced
89
6/12
✓ Branch 1 taken 34464 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 34464 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 34464 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 10400 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 10400 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 10400 times.
✗ Branch 17 not taken.
805917 fluxVarsCache_[eIdx].resize(fvGeometry.numScvf());
90
8/8
✓ Branch 0 taken 1161170 times.
✓ Branch 1 taken 190368 times.
✓ Branch 2 taken 1161170 times.
✓ Branch 3 taken 190368 times.
✓ Branch 4 taken 378810 times.
✓ Branch 5 taken 78271 times.
✓ Branch 6 taken 378810 times.
✓ Branch 7 taken 78271 times.
3617238 for (const auto& scvf : scvfs(fvGeometry))
91 1539980 cache(eIdx, scvf.index()).update(problem, element, fvGeometry, elemVolVars, scvf);
92 });
93 }
94 3644 }
95
96 template<class FVElementGeometry, class ElementVolumeVariables>
97 void updateElement(const typename FVElementGeometry::Element& element,
98 const FVElementGeometry& fvGeometry,
99 const ElementVolumeVariables& elemVolVars)
100 {
101 if constexpr (FluxVariablesCache::isSolDependent)
102 {
103 const auto eIdx = fvGeometry.gridGeometry().elementMapper().index(element);
104 fluxVarsCache_[eIdx].resize(fvGeometry.numScvf());
105 for (const auto& scvf : scvfs(fvGeometry))
106 cache(eIdx, scvf.index()).update(problem(), element, fvGeometry, elemVolVars, scvf);
107 }
108 }
109
110 const Problem& problem() const
111 { return *problemPtr_; }
112
113 // access operator
114 const FluxVariablesCache& cache(std::size_t eIdx, std::size_t scvfIdx) const
115
6/12
✗ Branch 0 not taken.
✓ Branch 1 taken 138800268 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 138800268 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 138800268 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 740772 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 740772 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 740772 times.
983260794 { return fluxVarsCache_[eIdx][scvfIdx]; }
116
117 // access operator
118 FluxVariablesCache& cache(std::size_t eIdx, std::size_t scvfIdx)
119
6/12
✓ Branch 1 taken 158208 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 158208 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 158208 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 53640 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 53640 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 53640 times.
✗ Branch 17 not taken.
4619940 { return fluxVarsCache_[eIdx][scvfIdx]; }
120
121 private:
122 // currently bound element
123 const Problem* problemPtr_;
124 std::vector<std::vector<FluxVariablesCache>> fluxVarsCache_;
125 };
126
127 /*!
128 * \ingroup CVFEDiscretization
129 * \brief Flux variable caches on a gridview with grid caching disabled
130 */
131 template<class P, class FVC, class Traits>
132 class CVFEGridFluxVariablesCache<P, FVC, false, Traits>
133 {
134 using Problem = typename Traits::Problem;
135 using ThisType = CVFEGridFluxVariablesCache<P, FVC, false, Traits>;
136
137 public:
138 //! export the flux variable cache type
139 using FluxVariablesCache = typename Traits::FluxVariablesCache;
140
141 //! make it possible to query if caching is enabled
142 static constexpr bool cachingEnabled = false;
143
144 //! export the type of the local view
145 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
146
147
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.
5 CVFEGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
148
149 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
150 void update(const GridGeometry& gridGeometry,
151 const GridVolumeVariables& gridVolVars,
152 const SolutionVector& sol,
153 bool forceUpdate = false) {}
154
155 const Problem& problem() const
156 { return *problemPtr_; }
157
158 private:
159 const Problem* problemPtr_;
160 };
161
162 } // end namespace Dumux
163
164 #endif
165