GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/discretization/staggered/elementfacevariables.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 3 11 27.3%
Functions: 0 255 0.0%
Branches: 39 40 97.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 StaggeredDiscretization
10 * \copydoc Dumux::StaggeredElementFaceVariables
11 */
12 #ifndef DUMUX_DISCRETIZATION_STAGGERED_ELEMENTFACEVARIABLES_HH
13 #define DUMUX_DISCRETIZATION_STAGGERED_ELEMENTFACEVARIABLES_HH
14
15 #include <algorithm>
16 #include <cassert>
17 #include <vector>
18 #include <utility>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup StaggeredDiscretization
24 * \brief Base class for the face variables vector
25 */
26 template<class GridFaceVariables, bool cachingEnabled>
27 class StaggeredElementFaceVariables
28 {};
29
30 /*!
31 * \ingroup StaggeredDiscretization
32 * \brief Class for the face variables vector. Specialization for the case of storing the face variables globally.
33 */
34 template<class GFV>
35 class StaggeredElementFaceVariables<GFV, /*cachingEnabled*/true>
36 {
37 public:
38 //! export type of the grid volume variables
39 using GridFaceVariables = GFV;
40
41 //! export type of the volume variables
42 using FaceVariables = typename GridFaceVariables::FaceVariables;
43
44 StaggeredElementFaceVariables(const GridFaceVariables& gridFaceVariables) : gridFaceVariablesPtr_(&gridFaceVariables) {}
45
46 //! operator for the access with an scvf
47 template<class SubControlVolumeFace, typename std::enable_if_t<!std::is_integral<SubControlVolumeFace>::value, int> = 0>
48 const FaceVariables& operator [](const SubControlVolumeFace& scvf) const
49
39/40
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 112029673 times.
✓ Branch 2 taken 14544905 times.
✓ Branch 3 taken 160158722 times.
✓ Branch 4 taken 38692817 times.
✓ Branch 5 taken 85048054 times.
✓ Branch 6 taken 148240454 times.
✓ Branch 7 taken 61199941 times.
✓ Branch 8 taken 192629677 times.
✓ Branch 9 taken 49788271 times.
✓ Branch 10 taken 96144257 times.
✓ Branch 11 taken 114250203 times.
✓ Branch 12 taken 33813601 times.
✓ Branch 13 taken 130823166 times.
✓ Branch 14 taken 11178212 times.
✓ Branch 15 taken 157746176 times.
✓ Branch 16 taken 5025600 times.
✓ Branch 17 taken 162475814 times.
✓ Branch 18 taken 29305243 times.
✓ Branch 19 taken 130379211 times.
✓ Branch 20 taken 31599193 times.
✓ Branch 21 taken 123859855 times.
✓ Branch 22 taken 73873402 times.
✓ Branch 23 taken 71457078 times.
✓ Branch 24 taken 99361176 times.
✓ Branch 25 taken 43156412 times.
✓ Branch 26 taken 120614380 times.
✓ Branch 27 taken 17290596 times.
✓ Branch 28 taken 131113248 times.
✓ Branch 29 taken 5354560 times.
✓ Branch 30 taken 107248214 times.
✓ Branch 31 taken 3730830 times.
✓ Branch 32 taken 105300618 times.
✓ Branch 33 taken 3730830 times.
✓ Branch 34 taken 62936494 times.
✓ Branch 35 taken 3614994 times.
✓ Branch 36 taken 37390978 times.
✓ Branch 37 taken 3614994 times.
✓ Branch 38 taken 10787488 times.
✗ Branch 39 not taken.
3625088450 { return gridFaceVariables().faceVars(scvf.index()); }
50
51 //! operator for the access with an index
52 //! needed for cc methods for the access to the boundary volume variables
53 const FaceVariables& operator [](const std::size_t scvfIdx) const
54 { return gridFaceVariables().faceVars(scvfIdx); }
55
56 /*!
57 * \brief bind the local view (r-value overload)
58 * This overload is called when an instance of this class is a temporary in the usage context
59 * This allows a usage like this: `const auto view = localView(...).bind(element);`
60 */
61 template<class FVElementGeometry, class SolutionVector>
62 StaggeredElementFaceVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
63 const FVElementGeometry& fvGeometry,
64 const SolutionVector& sol) &&
65 {
66 this->bind_(element, fvGeometry, sol);
67 return std::move(*this);
68 }
69
70 template<class FVElementGeometry, class SolutionVector>
71 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
72 const FVElementGeometry& fvGeometry,
73 const SolutionVector& sol) &
74 2643288 { this->bind_(element, fvGeometry, sol); }
75
76 /*!
77 * \brief bind the local view (r-value overload)
78 * This overload is called when an instance of this class is a temporary in the usage context
79 * This allows a usage like this: `const auto view = localView(...).bind(element);`
80 */
81 template<class FVElementGeometry, class SolutionVector>
82 StaggeredElementFaceVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
83 const FVElementGeometry& fvGeometry,
84 const SolutionVector& sol) &&
85 {
86 this->bindElement_(element, fvGeometry, sol);
87 return std::move(*this);
88 }
89
90 template<class FVElementGeometry, class SolutionVector>
91 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
92 const FVElementGeometry& fvGeometry,
93 const SolutionVector& sol) &
94 495236 { this->bindElement_(element, fvGeometry, sol); }
95
96 //! The global volume variables object we are a restriction of
97 const GridFaceVariables& gridFaceVariables() const
98 { return *gridFaceVariablesPtr_; }
99
100 private:
101
102 //! For compatibility reasons with the case of not storing the face vars.
103 //! function to be called before assembling an element, preparing the vol vars within the stencil
104 template<class FVElementGeometry, class SolutionVector>
105 void bind_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
106 const FVElementGeometry& fvGeometry,
107 const SolutionVector& sol)
108 {}
109
110 //! Binding of an element, prepares only the face variables of the element
111 //! specialization for Staggered models
112 template<class FVElementGeometry, class SolutionVector>
113 void bindElement_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
114 const FVElementGeometry& fvGeometry,
115 const SolutionVector& sol)
116 {}
117
118 const GridFaceVariables* gridFaceVariablesPtr_;
119 };
120
121 /*!
122 * \ingroup StaggeredDiscretization
123 * \brief Class for the face variables vector. Specialization for the case of not storing the face variables globally.
124 */
125 template<class GFV>
126 class StaggeredElementFaceVariables<GFV, /*cachingEnabled*/false>
127 {
128 public:
129 //! export type of the grid volume variables
130 using GridFaceVariables = GFV;
131
132 //! export type of the volume variables
133 using FaceVariables = typename GridFaceVariables::FaceVariables;
134
135 StaggeredElementFaceVariables(const GridFaceVariables& globalFacesVars) : gridFaceVariablesPtr_(&globalFacesVars) {}
136
137 //! const operator for the access with an scvf
138 template<class SubControlVolumeFace, typename std::enable_if_t<!std::is_integral<SubControlVolumeFace>::value, int> = 0>
139 const FaceVariables& operator [](const SubControlVolumeFace& scvf) const
140 { return faceVariables_[scvf.localFaceIdx()]; }
141
142 //! const operator for the access with an index
143 const FaceVariables& operator [](const std::size_t scvfIdx) const
144 { return faceVariables_[getLocalIdx_(scvfIdx)]; }
145
146 //! operator for the access with an scvf
147 template<class SubControlVolumeFace, typename std::enable_if_t<!std::is_integral<SubControlVolumeFace>::value, int> = 0>
148 FaceVariables& operator [](const SubControlVolumeFace& scvf)
149 { return faceVariables_[scvf.localFaceIdx()]; }
150
151 // operator for the access with an index
152 FaceVariables& operator [](const std::size_t scvfIdx)
153 { return faceVariables_[getLocalIdx_(scvfIdx)]; }
154
155 /*!
156 * \brief bind the local view (r-value overload)
157 * This overload is called when an instance of this class is a temporary in the usage context
158 * This allows a usage like this: `const auto view = localView(...).bind(element);`
159 */
160 template<class FVElementGeometry, class SolutionVector>
161 StaggeredElementFaceVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
162 const FVElementGeometry& fvGeometry,
163 const SolutionVector& sol) &&
164 {
165 this->bind_(element, fvGeometry, sol);
166 return std::move(*this);
167 }
168
169 template<class FVElementGeometry, class SolutionVector>
170 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
171 const FVElementGeometry& fvGeometry,
172 const SolutionVector& sol) &
173 { this->bind_(element, fvGeometry, sol); }
174
175 /*!
176 * \brief bind the local view (r-value overload)
177 * This overload is called when an instance of this class is a temporary in the usage context
178 * This allows a usage like this: `const auto view = localView(...).bind(element);`
179 */
180 template<class FVElementGeometry, class SolutionVector>
181 StaggeredElementFaceVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
182 const FVElementGeometry& fvGeometry,
183 const SolutionVector& sol) &&
184 {
185 this->bindElement_(element, fvGeometry, sol);
186 return std::move(*this);
187 }
188
189 template<class FVElementGeometry, class SolutionVector>
190 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
191 const FVElementGeometry& fvGeometry,
192 const SolutionVector& sol) &
193 { this->bindElement_(element, fvGeometry, sol); }
194
195 //! The global volume variables object we are a restriction of
196 const GridFaceVariables& gridFaceVariables() const
197 { return *gridFaceVariablesPtr_; }
198
199 private:
200
201 //! For compatibility reasons with the case of not storing the vol vars.
202 //! function to be called before assembling an element, preparing the vol vars within the stencil
203 template<class FVElementGeometry, class SolutionVector>
204 void bind_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
205 const FVElementGeometry& fvGeometry,
206 const SolutionVector& sol)
207 {
208 faceVariables_.resize(fvGeometry.numScvf());
209 faceVarIndices_.resize(fvGeometry.numScvf());
210
211 constexpr auto faceIdx = FVElementGeometry::GridGeometry::faceIdx();
212
213 for(auto&& scvf : scvfs(fvGeometry))
214 {
215 faceVariables_[scvf.localFaceIdx()].update(sol[faceIdx], gridFaceVariables().problem(), element, fvGeometry, scvf);
216 faceVarIndices_[scvf.localFaceIdx()] = scvf.index();
217 }
218 }
219
220 //! Binding of an element, prepares only the face variables of the element
221 //! specialization for Staggered models
222 template<class FVElementGeometry, class SolutionVector>
223 void bindElement_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
224 const FVElementGeometry& fvGeometry,
225 const SolutionVector& sol)
226 {
227 faceVariables_.resize(fvGeometry.numScvf());
228 faceVarIndices_.resize(fvGeometry.numScvf());
229
230 constexpr auto faceIdx = FVElementGeometry::GridGeometry::faceIdx();
231
232 for(auto&& scvf : scvfs(fvGeometry))
233 {
234 faceVariables_[scvf.localFaceIdx()].updateOwnFaceOnly(sol[faceIdx][scvf.dofIndex()]);
235 faceVarIndices_[scvf.localFaceIdx()] = scvf.index();
236 }
237 }
238
239 int getLocalIdx_(const int scvfIdx) const
240 {
241 auto it = std::find(faceVarIndices_.begin(), faceVarIndices_.end(), scvfIdx);
242 assert(it != faceVarIndices_.end() && "Could not find the current face variables for scvfIdx!");
243 return std::distance(faceVarIndices_.begin(), it);
244 }
245
246 const GridFaceVariables* gridFaceVariablesPtr_;
247 std::vector<std::size_t> faceVarIndices_;
248 std::vector<FaceVariables> faceVariables_;
249 };
250
251 } // end namespace
252
253 #endif
254