GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/facecentered/staggered/gridfluxvariablescache.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 11 15 73.3%
Functions: 38 53 71.7%
Branches: 10 20 50.0%

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 FaceCenteredStaggeredDiscretization
10 * \brief Global flux variable cache
11 */
12 #ifndef DUMUX_DISCRETIZATION_FACECENTERED_STAGGERED_GRID_FLUXVARSCACHE_HH
13 #define DUMUX_DISCRETIZATION_FACECENTERED_STAGGERED_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/facecentered/staggered/elementfluxvariablescache.hh>
20
21 namespace Dumux {
22
23 /*!
24 * \ingroup FaceCenteredStaggeredDiscretization
25 * \brief Flux variable caches traits
26 */
27 template<class P, class FVC, class FVCF>
28 struct FaceCenteredStaggeredDefaultGridFVCTraits
29 {
30 using Problem = P;
31 using FluxVariablesCache = FVC;
32 using FluxVariablesCacheFiller = FVCF;
33
34 template<class GridFluxVariablesCache, bool cachingEnabled>
35 using LocalView = FaceCenteredStaggeredElementFluxVariablesCache<GridFluxVariablesCache, cachingEnabled>;
36 };
37
38 /*!
39 * \ingroup FaceCenteredStaggeredDiscretization
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 cachingEnabled = false,
47 class Traits = FaceCenteredStaggeredDefaultGridFVCTraits<Problem, FluxVariablesCache, FluxVariablesCacheFiller>>
48 class FaceCenteredStaggeredGridFluxVariablesCache;
49
50 /*!
51 * \ingroup FaceCenteredStaggeredDiscretization
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 Traits>
56 class FaceCenteredStaggeredGridFluxVariablesCache<P, FVC, FVCF, true, Traits>
57 {
58 using Problem = typename Traits::Problem;
59 using ThisType = FaceCenteredStaggeredGridFluxVariablesCache<P, FVC, FVCF, true, Traits>;
60 using FluxVariablesCacheFiller = typename Traits::FluxVariablesCacheFiller;
61
62 public:
63 //! export the flux variable cache type
64 using FluxVariablesCache = typename Traits::FluxVariablesCache;
65
66 //! make it possible to query if caching is enabled
67 static constexpr bool cachingEnabled = true;
68
69 //! export the type of the local view
70 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
71
72 FaceCenteredStaggeredGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
73
74 // When global caching is enabled, precompute transmissibilities and stencils for all the scv faces
75 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
76 758 void update(const GridGeometry& gridGeometry,
77 const GridVolumeVariables& gridVolVars,
78 const SolutionVector& sol,
79 bool forceUpdate = false)
80 {
81 // only do the update if fluxes are solution dependent or if update is forced
82
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 702 times.
758 if (FluxVariablesCacheFiller::isSolDependent || forceUpdate)
83 {
84 // instantiate helper class to fill the caches
85 56 FluxVariablesCacheFiller filler(problem());
86
87 112 fluxVarsCache_.resize(gridGeometry.numScvf());
88
89 329501 Dumux::parallelFor(gridGeometry.gridView().size(0), [&](const std::size_t eIdx)
90 {
91 // Prepare the geometries within the elements of the stencil
92 332924 const auto element = gridGeometry.element(eIdx);
93
2/4
✓ Branch 1 taken 1768 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1768 times.
✗ Branch 5 not taken.
662312 const auto fvGeometry = localView(gridGeometry).bind(element);
94
2/4
✓ Branch 1 taken 331156 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 331156 times.
✗ Branch 5 not taken.
993468 const auto elemVolVars = localView(gridVolVars).bind(element, fvGeometry, sol);
95
96
4/4
✓ Branch 1 taken 4004532 times.
✓ Branch 2 taken 331156 times.
✓ Branch 3 taken 4004532 times.
✓ Branch 4 taken 331156 times.
8340220 for (auto&& scvf : scvfs(fvGeometry))
97 {
98 4004532 filler.fill(*this, fluxVarsCache_[scvf.index()], element, fvGeometry, elemVolVars, scvf, forceUpdate);
99 }
100 });
101 }
102 758 }
103
104 const Problem& problem() const
105 { return *problemPtr_; }
106
107 template<class SubControlVolumeFace>
108 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
109 { return fluxVarsCache_[scvf.index()]; }
110
111 template<class SubControlVolumeFace>
112 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
113 { return fluxVarsCache_[scvf.index()]; }
114
115 private:
116 // currently bound element
117 const Problem* problemPtr_;
118 std::vector<FluxVariablesCache> fluxVarsCache_;
119 };
120
121 /*!
122 * \ingroup FaceCenteredStaggeredDiscretization
123 * \brief Flux variable caches on a gridview with grid caching disabled
124 */
125 template<class P, class FVC, class FVCF, class Traits>
126 class FaceCenteredStaggeredGridFluxVariablesCache<P, FVC, FVCF, false, Traits>
127 {
128 using Problem = typename Traits::Problem;
129 using ThisType = FaceCenteredStaggeredGridFluxVariablesCache<P, FVC, FVCF, false, Traits>;
130
131 public:
132 //! export the flux variable cache type
133 using FluxVariablesCache = typename Traits::FluxVariablesCache;
134
135 //! make it possible to query if caching is enabled
136 static constexpr bool cachingEnabled = false;
137
138 //! export the type of the local view
139 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
140
141 FaceCenteredStaggeredGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
142
143 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
144 void update(const GridGeometry& gridGeometry,
145 const GridVolumeVariables& gridVolVars,
146 const SolutionVector& sol,
147 bool forceUpdate = false) {}
148
149 const Problem& problem() const
150 { return *problemPtr_; }
151
152 private:
153 const Problem* problemPtr_;
154 };
155
156 } // end namespace Dumux
157
158 #endif
159