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::StaggeredElementFluxVariablesCache | ||
11 | */ | ||
12 | #ifndef DUMUX_DISCRETIZATION_STAGGERED_ELEMENT_FLUXVARSCACHE_HH | ||
13 | #define DUMUX_DISCRETIZATION_STAGGERED_ELEMENT_FLUXVARSCACHE_HH | ||
14 | |||
15 | #include <algorithm> | ||
16 | #include <cassert> | ||
17 | #include <iterator> | ||
18 | #include <vector> | ||
19 | #include <utility> | ||
20 | |||
21 | #include <dune/common/exceptions.hh> | ||
22 | |||
23 | namespace Dumux { | ||
24 | |||
25 | /*! | ||
26 | * \ingroup StaggeredDiscretization | ||
27 | * \brief Base class for the stencil local flux variables cache for the staggered model | ||
28 | */ | ||
29 | template<class GridFluxVariablesCache, bool cachingEnabled> | ||
30 | class StaggeredElementFluxVariablesCache; | ||
31 | |||
32 | /*! | ||
33 | * \ingroup StaggeredDiscretization | ||
34 | * \brief Class for the stencil local flux variables cache for the staggered model. | ||
35 | Specialization for the case of storing the fluxvars cache globally. | ||
36 | */ | ||
37 | template<class GFVC> | ||
38 | class StaggeredElementFluxVariablesCache<GFVC, true> | ||
39 | { | ||
40 | //! the type of the flux variables cache filler | ||
41 | using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller; | ||
42 | |||
43 | public: | ||
44 | //! export the type of the grid flux variables cache | ||
45 | using GridFluxVariablesCache = GFVC; | ||
46 | |||
47 | //! export the type of the flux variables cache | ||
48 | using FluxVariablesCache = typename GFVC::FluxVariablesCache; | ||
49 | |||
50 | |||
51 |
4/8✓ Branch 1 taken 1360572 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1360572 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 80 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 80 times.
✗ Branch 11 not taken.
|
3192240 | StaggeredElementFluxVariablesCache(const GridFluxVariablesCache& global) |
52 | : gridFluxVarsCachePtr_(&global) {} | ||
53 | |||
54 | /*! | ||
55 | * \brief bind the local view (r-value overload) | ||
56 | * This overload is called when an instance of this class is a temporary in the usage context | ||
57 | * This allows a usage like this: `const auto view = localView(...).bind(element);` | ||
58 | */ | ||
59 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
60 | StaggeredElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
61 | const FVElementGeometry& fvGeometry, | ||
62 | const ElementVolumeVariables& elemVolVars) && | ||
63 | { | ||
64 | this->bindElement(element, fvGeometry, elemVolVars); | ||
65 | return std::move(*this); | ||
66 | } | ||
67 | |||
68 | //! Specialization for the global caching being enabled - do nothing here | ||
69 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
70 | void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
71 | const FVElementGeometry& fvGeometry, | ||
72 | const ElementVolumeVariables& elemVolVars) & {} | ||
73 | |||
74 | /*! | ||
75 | * \brief bind the local view (r-value overload) | ||
76 | * This overload is called when an instance of this class is a temporary in the usage context | ||
77 | * This allows a usage like this: `const auto view = localView(...).bind(element);` | ||
78 | */ | ||
79 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
80 | StaggeredElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
81 | const FVElementGeometry& fvGeometry, | ||
82 | const ElementVolumeVariables& elemVolVars) && | ||
83 | { | ||
84 | this->bind(element, fvGeometry, elemVolVars); | ||
85 | return std::move(*this); | ||
86 | } | ||
87 | |||
88 | //! Specialization for the global caching being enabled - do nothing here | ||
89 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
90 | void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
91 | const FVElementGeometry& fvGeometry, | ||
92 | const ElementVolumeVariables& elemVolVars) & {} | ||
93 | |||
94 | /*! | ||
95 | * \brief bind the local view (r-value overload) | ||
96 | * This overload is called when an instance of this class is a temporary in the usage context | ||
97 | * This allows a usage like this: `const auto view = localView(...).bind(element);` | ||
98 | */ | ||
99 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
100 | StaggeredElementFluxVariablesCache bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
101 | const FVElementGeometry& fvGeometry, | ||
102 | const ElementVolumeVariables& elemVolVars, | ||
103 | const typename FVElementGeometry::SubControlVolumeFace& scvf) && | ||
104 | { | ||
105 | this->bindScvf(element, fvGeometry, elemVolVars, scvf); | ||
106 | return std::move(*this); | ||
107 | } | ||
108 | |||
109 | //! Specialization for the global caching being enabled - do nothing here | ||
110 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
111 | void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
112 | const FVElementGeometry& fvGeometry, | ||
113 | const ElementVolumeVariables& elemVolVars, | ||
114 | const typename FVElementGeometry::SubControlVolumeFace& scvf) & {} | ||
115 | |||
116 | //! Specialization for the global caching being enabled - do nothing here | ||
117 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
118 | void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
119 | const FVElementGeometry& fvGeometry, | ||
120 | const ElementVolumeVariables& elemVolVars) | ||
121 | { | ||
122 | DUNE_THROW(Dune::InvalidStateException, "In case of enabled caching, the grid flux variables cache must not to be updated"); | ||
123 | } | ||
124 | |||
125 | //! operators in the case of caching | ||
126 | template<class SubControlVolumeFace> | ||
127 | 148094344 | const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const | |
128 | 166059724 | { return (*gridFluxVarsCachePtr_)[scvf.index()]; } | |
129 | |||
130 | //! The global object we are a restriction of | ||
131 | 145578344 | const GridFluxVariablesCache& gridFluxVarsCache() const | |
132 | 145578344 | { return *gridFluxVarsCachePtr_; } | |
133 | |||
134 | private: | ||
135 | const GridFluxVariablesCache* gridFluxVarsCachePtr_; | ||
136 | }; | ||
137 | |||
138 | /*! | ||
139 | * \ingroup StaggeredDiscretization | ||
140 | * \brief Class for the stencil local flux variables cache for the staggered model. | ||
141 | Specialization for the case of not storing the fluxvars cache globally. | ||
142 | */ | ||
143 | template<class GFVC> | ||
144 | 600 | class StaggeredElementFluxVariablesCache<GFVC, false> | |
145 | { | ||
146 | //! the type of the flux variables cache filler | ||
147 | using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller; | ||
148 | |||
149 | public: | ||
150 | //! export the type of the grid flux variables cache | ||
151 | using GridFluxVariablesCache = GFVC; | ||
152 | |||
153 | //! export the type of the flux variables cache | ||
154 | using FluxVariablesCache = typename GFVC::FluxVariablesCache; | ||
155 | |||
156 | 600 | StaggeredElementFluxVariablesCache(const GridFluxVariablesCache& global) | |
157 |
24/48✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 25 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 25 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 25 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 25 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 25 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 25 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 25 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 25 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 25 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 25 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 25 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 25 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 25 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 25 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 25 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 25 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 25 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 25 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 25 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 25 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 25 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 25 times.
✗ Branch 71 not taken.
|
600 | : gridFluxVarsCachePtr_(&global) {} |
158 | |||
159 | /*! | ||
160 | * \brief bind the local view (r-value overload) | ||
161 | * This overload is called when an instance of this class is a temporary in the usage context | ||
162 | * This allows a usage like this: `const auto view = localView(...).bind(element);` | ||
163 | */ | ||
164 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
165 | StaggeredElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
166 | const FVElementGeometry& fvGeometry, | ||
167 | const ElementVolumeVariables& elemVolVars) && | ||
168 | { | ||
169 | this->bindElement_(element, fvGeometry, elemVolVars); | ||
170 | return std::move(*this); | ||
171 | } | ||
172 | |||
173 | //! Specialization for the global caching being enabled - do nothing here | ||
174 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
175 | void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
176 | const FVElementGeometry& fvGeometry, | ||
177 | const ElementVolumeVariables& elemVolVars) & | ||
178 | { this->bindElement_(element, fvGeometry, elemVolVars); } | ||
179 | |||
180 | /*! | ||
181 | * \brief bind the local view (r-value overload) | ||
182 | * This overload is called when an instance of this class is a temporary in the usage context | ||
183 | * This allows a usage like this: `const auto view = localView(...).bind(element);` | ||
184 | */ | ||
185 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
186 | 600 | StaggeredElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | |
187 | const FVElementGeometry& fvGeometry, | ||
188 | const ElementVolumeVariables& elemVolVars) && | ||
189 | { | ||
190 |
24/48✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 25 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 25 times.
✗ Branch 10 not taken.
✓ Branch 13 taken 25 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✓ Branch 21 taken 25 times.
✗ Branch 22 not taken.
✓ Branch 25 taken 25 times.
✗ Branch 26 not taken.
✓ Branch 29 taken 25 times.
✗ Branch 30 not taken.
✓ Branch 33 taken 25 times.
✗ Branch 34 not taken.
✓ Branch 37 taken 25 times.
✗ Branch 38 not taken.
✓ Branch 41 taken 25 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 25 times.
✗ Branch 46 not taken.
✓ Branch 49 taken 25 times.
✗ Branch 50 not taken.
✓ Branch 53 taken 25 times.
✗ Branch 54 not taken.
✓ Branch 57 taken 25 times.
✗ Branch 58 not taken.
✓ Branch 61 taken 25 times.
✗ Branch 62 not taken.
✓ Branch 65 taken 25 times.
✗ Branch 66 not taken.
✓ Branch 69 taken 25 times.
✗ Branch 70 not taken.
✓ Branch 73 taken 25 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 25 times.
✗ Branch 78 not taken.
✓ Branch 81 taken 25 times.
✗ Branch 82 not taken.
✓ Branch 85 taken 25 times.
✗ Branch 86 not taken.
✓ Branch 89 taken 25 times.
✗ Branch 90 not taken.
✓ Branch 93 taken 25 times.
✗ Branch 94 not taken.
|
600 | this->bind_(element, fvGeometry, elemVolVars); |
191 | 600 | return std::move(*this); | |
192 | } | ||
193 | |||
194 | //! Specialization for the global caching being enabled - do nothing here | ||
195 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
196 | void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
197 | const FVElementGeometry& fvGeometry, | ||
198 | const ElementVolumeVariables& elemVolVars) & | ||
199 | { this->bind_(element, fvGeometry, elemVolVars); } | ||
200 | |||
201 | /*! | ||
202 | * \brief bind the local view (r-value overload) | ||
203 | * This overload is called when an instance of this class is a temporary in the usage context | ||
204 | * This allows a usage like this: `const auto view = localView(...).bind(element);` | ||
205 | */ | ||
206 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
207 | StaggeredElementFluxVariablesCache bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
208 | const FVElementGeometry& fvGeometry, | ||
209 | const ElementVolumeVariables& elemVolVars, | ||
210 | const typename FVElementGeometry::SubControlVolumeFace& scvf) && | ||
211 | { | ||
212 | this->bindScvf_(element, fvGeometry, elemVolVars, scvf); | ||
213 | return std::move(*this); | ||
214 | } | ||
215 | |||
216 | //! Specialization for the global caching being enabled - do nothing here | ||
217 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
218 | void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
219 | const FVElementGeometry& fvGeometry, | ||
220 | const ElementVolumeVariables& elemVolVars, | ||
221 | const typename FVElementGeometry::SubControlVolumeFace& scvf) & | ||
222 | { this->bindScvf_(element, fvGeometry, elemVolVars, scvf); } | ||
223 | |||
224 | /*! | ||
225 | * \brief Update the transmissibilities if the volume variables have changed | ||
226 | * \note Results in undefined behaviour if called before bind() or with a different element | ||
227 | */ | ||
228 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
229 | void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
230 | const FVElementGeometry& fvGeometry, | ||
231 | const ElementVolumeVariables& elemVolVars) | ||
232 | { | ||
233 | // if (FluxVariablesCacheFiller::isSolDependent) TODO | ||
234 | // { | ||
235 | // const auto& problem = gridFluxVarsCache().problem(); | ||
236 | // const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element); | ||
237 | // | ||
238 | // // instantiate filler class | ||
239 | // FluxVariablesCacheFiller filler(problem); | ||
240 | // | ||
241 | // // let the filler class update the caches | ||
242 | // for (unsigned int localScvfIdx = 0; localScvfIdx < fluxVarsCache_.size(); ++localScvfIdx) | ||
243 | // { | ||
244 | // const auto& scvf = fvGeometry.scvf(globalScvfIndices_[localScvfIdx]); | ||
245 | // | ||
246 | // const auto scvfInsideScvIdx = scvf.insideScvIdx(); | ||
247 | // const auto& insideElement = scvfInsideScvIdx == globalI ? | ||
248 | // element : | ||
249 | // fvGeometry.gridGeometry().element(scvfInsideScvIdx); | ||
250 | // | ||
251 | // filler.fill(*this, fluxVarsCache_[localScvfIdx], insideElement, fvGeometry, elemVolVars, scvf); | ||
252 | // } | ||
253 | // } | ||
254 | } | ||
255 | |||
256 | //! access operators in the case of no caching | ||
257 | template<class SubControlVolumeFace> | ||
258 | const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const | ||
259 | { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; } | ||
260 | |||
261 | template<class SubControlVolumeFace> | ||
262 | FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) | ||
263 | { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; } | ||
264 | |||
265 | //! The global object we are a restriction of | ||
266 | const GridFluxVariablesCache& gridFluxVarsCache() const | ||
267 | 600 | { return *gridFluxVarsCachePtr_; } | |
268 | |||
269 | private: | ||
270 | |||
271 | /*! | ||
272 | * \brief Prepares the transmissibilities of the scv faces in an element | ||
273 | * \note the fvGeometry is assumed to be bound to the same element | ||
274 | * \note this function has to be called prior to flux calculations on the element. | ||
275 | */ | ||
276 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
277 | void bindElement_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
278 | const FVElementGeometry& fvGeometry, | ||
279 | const ElementVolumeVariables& elemVolVars) | ||
280 | { | ||
281 | // resizing of the cache | ||
282 | const auto numScvf = fvGeometry.numScvf(); | ||
283 | fluxVarsCache_.resize(numScvf); | ||
284 | globalScvfIndices_.resize(numScvf); | ||
285 | |||
286 | // instantiate helper class to fill the caches | ||
287 | FluxVariablesCacheFiller filler(gridFluxVarsCache().problem()); | ||
288 | |||
289 | std::size_t localScvfIdx = 0; | ||
290 | // fill the containers | ||
291 | for (auto&& scvf : scvfs(fvGeometry)) | ||
292 | { | ||
293 | filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true); | ||
294 | globalScvfIndices_[localScvfIdx] = scvf.index(); | ||
295 | localScvfIdx++; | ||
296 | } | ||
297 | } | ||
298 | |||
299 | /*! | ||
300 | * \brief Prepares the transmissibilities of the scv faces in the stencil of an element | ||
301 | * \note the fvGeometry is assumed to be bound to the same element | ||
302 | * \note this function has to be called prior to flux calculations on the element. | ||
303 | */ | ||
304 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
305 | 1200 | void bind_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | |
306 | const FVElementGeometry& fvGeometry, | ||
307 | const ElementVolumeVariables& elemVolVars) | ||
308 | { | ||
309 | // instantiate helper class to fill the caches | ||
310 | 1200 | FluxVariablesCacheFiller filler(gridFluxVarsCache().problem()); | |
311 | |||
312 | // find the number of scv faces that need to be prepared | ||
313 | 1200 | const auto numScvf = fvGeometry.numScvf(); | |
314 | |||
315 | // fill the containers with the data on the scv faces inside the actual element | ||
316 | 1200 | fluxVarsCache_.resize(numScvf); | |
317 | 1200 | globalScvfIndices_.resize(numScvf); | |
318 | 1200 | unsigned int localScvfIdx = 0; | |
319 |
2/2✓ Branch 0 taken 2400 times.
✓ Branch 1 taken 600 times.
|
6000 | for (auto&& scvf : scvfs(fvGeometry)) |
320 | { | ||
321 | 4800 | filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true); | |
322 | 4800 | globalScvfIndices_[localScvfIdx] = scvf.index(); | |
323 | 4800 | localScvfIdx++; | |
324 | } | ||
325 | 1200 | } | |
326 | |||
327 | /*! | ||
328 | * \brief Prepares the transmissibilities of a single scv face | ||
329 | * \note the fvGeometry is assumed to be bound to the same element | ||
330 | * \note this function has to be called prior to flux calculations on the element. | ||
331 | */ | ||
332 | template<class FVElementGeometry, class ElementVolumeVariables> | ||
333 | void bindScvf_ (const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element, | ||
334 | const FVElementGeometry& fvGeometry, | ||
335 | const ElementVolumeVariables& elemVolVars, | ||
336 | const typename FVElementGeometry::SubControlVolumeFace& scvf) | ||
337 | { | ||
338 | fluxVarsCache_.resize(1); | ||
339 | globalScvfIndices_.resize(1); | ||
340 | |||
341 | // instantiate helper class to fill the caches | ||
342 | // FluxVariablesCacheFiller filler(gridFluxVarsCache().problem()); | ||
343 | FluxVariablesCacheFiller filler; // TODO: use proper ctor | ||
344 | |||
345 | filler.fill(*this, fluxVarsCache_[0], element, fvGeometry, elemVolVars, scvf, true); | ||
346 | globalScvfIndices_[0] = scvf.index(); | ||
347 | } | ||
348 | |||
349 | const GridFluxVariablesCache* gridFluxVarsCachePtr_; | ||
350 | |||
351 | // get index of scvf in the local container | ||
352 | int getLocalScvfIdx_(const int scvfIdx) const | ||
353 | { | ||
354 | auto it = std::find(globalScvfIndices_.begin(), globalScvfIndices_.end(), scvfIdx); | ||
355 | assert(it != globalScvfIndices_.end() && "Could not find the flux vars cache for scvfIdx"); | ||
356 | return std::distance(globalScvfIndices_.begin(), it); | ||
357 | } | ||
358 | |||
359 | std::vector<FluxVariablesCache> fluxVarsCache_; | ||
360 | std::vector<std::size_t> globalScvfIndices_; | ||
361 | }; | ||
362 | |||
363 | } // end namespace Dumux | ||
364 | |||
365 | #endif | ||
366 |