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 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 |
24/48✓ Branch 1 taken 144 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 81 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 1 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 1 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
|
3192927 | 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 | 1794387351 | const FaceVariables& operator [](const SubControlVolumeFace& scvf) const | |
49 | 137662059 | { 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 | { 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 | { this->bindElement_(element, fvGeometry, sol); } | ||
95 | |||
96 | //! The global volume variables object we are a restriction of | ||
97 | 1656725292 | const GridFaceVariables& gridFaceVariables() const | |
98 |
15/16✓ Branch 1 taken 126520681 times.
✓ Branch 2 taken 76172172 times.
✓ Branch 3 taken 161011852 times.
✓ Branch 4 taken 88929596 times.
✓ Branch 5 taken 54363236 times.
✓ Branch 6 taken 94956384 times.
✓ Branch 10 taken 80921755 times.
✓ Branch 11 taken 81896844 times.
✓ Branch 12 taken 55444079 times.
✓ Branch 13 taken 37698856 times.
✓ Branch 7 taken 47750810 times.
✓ Branch 8 taken 114613624 times.
✓ Branch 9 taken 69501085 times.
✓ Branch 0 taken 19 times.
✓ Branch 14 taken 13805983 times.
✗ Branch 15 not taken.
|
1520010916 | { 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 |