GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/discretization/cvfe/gridvariablescache.hh
Date: 2025-06-14 19:21:29
Exec Total Coverage
Lines: 22 22 100.0%
Functions: 10 10 100.0%
Branches: 12 22 54.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-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 CVFEDiscretization
10 * \brief The grid local variables class for control-volume finite element methods
11 */
12 #ifndef DUMUX_DISCRETIZATION_CVFE_GRID_LOCAL_VARIABLES_HH
13 #define DUMUX_DISCRETIZATION_CVFE_GRID_LOCAL_VARIABLES_HH
14
15 #include <vector>
16 #include <type_traits>
17
18 #include <dumux/parallel/parallel_for.hh>
19
20 // make the local view function available whenever we use this class
21 #include <dumux/discretization/localview.hh>
22 #include <dumux/discretization/cvfe/elementvariables.hh>
23 #include <dumux/discretization/cvfe/elementsolution.hh>
24
25 namespace Dumux::Detail::CVFE {
26
27 template<class P, class V>
28 struct CVFEDefaultGridVariablesCacheTraits
29 {
30 using Problem = P;
31 using Variables = V;
32
33 template<class GridVariablesCache, bool cachingEnabled>
34 using LocalView = CVFEElementVariables<GridVariablesCache, cachingEnabled>;
35 };
36
37 /*!
38 * \ingroup CVFEDiscretization
39 * \brief Base class for the grid local variables
40 */
41 template<class Traits, bool enableCaching>
42 class CVFEGridVariablesCache;
43
44 // specialization in case of storing the local variables
45 template<class Traits>
46 8 class CVFEGridVariablesCache<Traits, /*cachingEnabled*/true>
47 {
48 using ThisType = CVFEGridVariablesCache<Traits, true>;
49
50 public:
51 //! export the problem type
52 using Problem = typename Traits::Problem;
53
54 //! export the variables type
55 using Variables = typename Traits::Variables;
56
57 //! TODO: Delete after new variables concept has been implemented
58 //! this is currently needed to support old interface
59 using VolumeVariables = Variables;
60
61 //! make it possible to query if caching is enabled
62 static constexpr bool cachingEnabled = true;
63
64 //! export the type of the local view
65 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
66
67 //! export the type of the mutable local view
68 using MutableLocalView = LocalView::MutableView;
69
70
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 CVFEGridVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
71
72 template<class GridGeometry, class SolutionVector>
73 40 void update(const GridGeometry& gridGeometry, const SolutionVector& sol)
74 {
75 40 variables_.resize(gridGeometry.gridView().size(0));
76 40 Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem()](const std::size_t eIdx)
77 {
78 648072 const auto element = gridGeometry.element(eIdx);
79
2/4
✓ Branch 1 taken 36000 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36000 times.
✗ Branch 4 not taken.
684072 const auto fvGeometry = localView(gridGeometry).bindElement(element);
80
81 // get the element solution
82
1/2
✓ Branch 1 taken 36000 times.
✗ Branch 2 not taken.
648072 auto elemSol = elementSolution(element, sol, gridGeometry);
83
84
1/2
✓ Branch 1 taken 36000 times.
✗ Branch 2 not taken.
648072 variables_[eIdx].resize(Dumux::Detail::LocalDofs::numLocalDofs(fvGeometry));
85
2/2
✓ Branch 0 taken 2803888 times.
✓ Branch 1 taken 648072 times.
3451960 for (const auto& localDof : localDofs(fvGeometry))
86 2803888 variables_[eIdx][localDof.index()].update(elemSol, problem, fvGeometry, localDof);
87 36000 });
88 40 }
89
90 //! TODO: Rename the functions below after new variables concept has been implemented
91 //! this is currently needed to support old interface
92 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
93 const Variables& volVars(const ScvOrLocalDof& scvOrLocalDof) const
94 {
95 if constexpr (Dumux::Detail::LocalDofs::isLocalDofType<ScvOrLocalDof>())
96 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.index()];
97 else
98 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.indexInElement()];
99 }
100
101 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
102 Variables& volVars(const ScvOrLocalDof& scvOrLocalDof)
103 {
104 if constexpr (Dumux::Detail::LocalDofs::isLocalDofType<ScvOrLocalDof>())
105 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.index()];
106 else
107 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.indexInElement()];
108 }
109
110 370101382 const Variables& volVars(const std::size_t eIdx, const std::size_t localIdx) const
111
2/2
✓ Branch 0 taken 11427850 times.
✓ Branch 1 taken 13527990 times.
370101382 { return variables_[eIdx][localIdx]; }
112
113 6198080 Variables& volVars(const std::size_t eIdx, const std::size_t localIdx)
114 6198080 { return variables_[eIdx][localIdx]; }
115
116 40 const Problem& problem() const
117 40 { return *problemPtr_; }
118
119 private:
120 const Problem* problemPtr_;
121 std::vector<std::vector<Variables>> variables_;
122 };
123
124 // Specialization when the current local variables are not stored
125 template<class Traits>
126 class CVFEGridVariablesCache<Traits, /*cachingEnabled*/false>
127 {
128 using ThisType = CVFEGridVariablesCache<Traits, false>;
129
130 public:
131 //! export the problem type
132 using Problem = typename Traits::Problem;
133
134 //! export the variables type
135 using Variables = typename Traits::Variables;
136
137 //! TODO: Delete after new variables concept has been implemented
138 //! this is currently needed to support old interface
139 using VolumeVariables = Variables;
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 //! export the type of the mutable local view
148 using MutableLocalView = LocalView::MutableView;
149
150
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 CVFEGridVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
151
152 template<class GridGeometry, class SolutionVector>
153 void update(const GridGeometry& gridGeometry, const SolutionVector& sol) {}
154
155 6504 const Problem& problem() const
156
2/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
426504 { return *problemPtr_;}
157
158 private:
159 const Problem* problemPtr_;
160 };
161
162 } // end namespace Dumux
163
164 #endif
165