version 3.8
discretization/cellcentered/tpfa/elementfluxvariablescache.hh
Go to the documentation of this file.
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//
12#ifndef DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH
13#define DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH
14
15#include <algorithm>
16#include <cassert>
17#include <vector>
18#include <utility>
19
20#include <dune/common/exceptions.hh>
21
22namespace Dumux {
23
32template<class GFVC, bool cachingEnabled>
34
39template<class GFVC>
41{
43 using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller;
44
45public:
48
50 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
51
53 : gridFluxVarsCachePtr_(&global) {}
54
60 template<class FVElementGeometry, class ElementVolumeVariables>
61 CCTpfaElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
62 const FVElementGeometry& fvGeometry,
63 const ElementVolumeVariables& elemVolVars) &&
64 {
65 this->bindElement(element, fvGeometry, elemVolVars);
66 return std::move(*this);
67 }
68
70 template<class FVElementGeometry, class ElementVolumeVariables>
71 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
72 const FVElementGeometry& fvGeometry,
73 const ElementVolumeVariables& elemVolVars) & {}
74
80 template<class FVElementGeometry, class ElementVolumeVariables>
81 CCTpfaElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
82 const FVElementGeometry& fvGeometry,
83 const ElementVolumeVariables& elemVolVars) &&
84 {
85 this->bind(element, fvGeometry, elemVolVars);
86 return std::move(*this);
87 }
88
90 template<class FVElementGeometry, class ElementVolumeVariables>
91 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
92 const FVElementGeometry& fvGeometry,
93 const ElementVolumeVariables& elemVolVars) & {}
94
100 template<class FVElementGeometry, class ElementVolumeVariables>
101 CCTpfaElementFluxVariablesCache bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
102 const FVElementGeometry& fvGeometry,
103 const ElementVolumeVariables& elemVolVars,
104 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
105 {
106 this->bindScvf(element, fvGeometry, elemVolVars, scvf);
107 return std::move(*this);
108 }
109
111 template<class FVElementGeometry, class ElementVolumeVariables>
112 void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
113 const FVElementGeometry& fvGeometry,
114 const ElementVolumeVariables& elemVolVars,
115 const typename FVElementGeometry::SubControlVolumeFace& scvf) & {}
116
118 template<class FVElementGeometry, class ElementVolumeVariables>
119 void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
120 const FVElementGeometry& fvGeometry,
121 const ElementVolumeVariables& elemVolVars) {}
122
124 template<class SubControlVolumeFace>
125 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
126 { return gridFluxVarsCache()[scvf]; }
127
130 { return *gridFluxVarsCachePtr_; }
131
132private:
133 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
134};
135
140template<class GFVC>
142{
144 using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller;
145
146public:
149
151 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
152
154 : gridFluxVarsCachePtr_(&global) {}
155
161 template<class FVElementGeometry, class ElementVolumeVariables>
162 CCTpfaElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
163 const FVElementGeometry& fvGeometry,
164 const ElementVolumeVariables& elemVolVars) &&
165 {
166 this->bindElement_(element, fvGeometry, elemVolVars);
167 return std::move(*this);
168 }
169
171 template<class FVElementGeometry, class ElementVolumeVariables>
172 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
173 const FVElementGeometry& fvGeometry,
174 const ElementVolumeVariables& elemVolVars) &
175 { this->bindElement_(element, fvGeometry, elemVolVars); }
176
182 template<class FVElementGeometry, class ElementVolumeVariables>
183 CCTpfaElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
184 const FVElementGeometry& fvGeometry,
185 const ElementVolumeVariables& elemVolVars) &&
186 {
187 this->bind_(element, fvGeometry, elemVolVars);
188 return std::move(*this);
189 }
190
192 template<class FVElementGeometry, class ElementVolumeVariables>
193 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
194 const FVElementGeometry& fvGeometry,
195 const ElementVolumeVariables& elemVolVars) &
196 { this->bind_(element, fvGeometry, elemVolVars); }
197
203 template<class FVElementGeometry, class ElementVolumeVariables>
204 CCTpfaElementFluxVariablesCache bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
205 const FVElementGeometry& fvGeometry,
206 const ElementVolumeVariables& elemVolVars,
207 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
208 {
209 this->bindScvf_(element, fvGeometry, elemVolVars, scvf);
210 return std::move(*this);
211 }
212
214 template<class FVElementGeometry, class ElementVolumeVariables>
215 void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
216 const FVElementGeometry& fvGeometry,
217 const ElementVolumeVariables& elemVolVars,
218 const typename FVElementGeometry::SubControlVolumeFace& scvf) &
219 { this->bindScvf_(element, fvGeometry, elemVolVars, scvf); }
220
225 template<class FVElementGeometry, class ElementVolumeVariables>
226 void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
227 const FVElementGeometry& fvGeometry,
228 const ElementVolumeVariables& elemVolVars)
229 {
230 if (FluxVariablesCacheFiller::isSolDependent)
231 {
232 const auto& problem = gridFluxVarsCache().problem();
233 const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element);
234
235 // instantiate filler class
236 FluxVariablesCacheFiller filler(problem);
237
238 // let the filler class update the caches
239 for (unsigned int localScvfIdx = 0; localScvfIdx < fluxVarsCache_.size(); ++localScvfIdx)
240 {
241 const auto& scvf = fvGeometry.scvf(globalScvfIndices_[localScvfIdx]);
242
243 const auto scvfInsideScvIdx = scvf.insideScvIdx();
244 const auto& insideElement = scvfInsideScvIdx == globalI ?
245 element :
246 fvGeometry.gridGeometry().element(scvfInsideScvIdx);
247
248 filler.fill(*this, fluxVarsCache_[localScvfIdx], insideElement, fvGeometry, elemVolVars, scvf);
249 }
250 }
251 }
252
254 template<class SubControlVolumeFace>
255 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
256 { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
257
259 template<class SubControlVolumeFace>
260 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
261 { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
262
265 { return *gridFluxVarsCachePtr_; }
266
267private:
268
274 template<class FVElementGeometry, class ElementVolumeVariables>
275 void bindElement_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
276 const FVElementGeometry& fvGeometry,
277 const ElementVolumeVariables& elemVolVars)
278 {
279 // resizing of the cache
280 const auto numScvf = fvGeometry.numScvf();
281 fluxVarsCache_.resize(numScvf);
282 globalScvfIndices_.resize(numScvf);
283
284 // instantiate helper class to fill the caches
285 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
286
287 std::size_t localScvfIdx = 0;
288 // fill the containers
289 for (auto&& scvf : scvfs(fvGeometry))
290 {
291 filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true);
292 globalScvfIndices_[localScvfIdx] = scvf.index();
293 localScvfIdx++;
294 }
295 }
296
302 template<class FVElementGeometry, class ElementVolumeVariables>
303 void bind_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
304 const FVElementGeometry& fvGeometry,
305 const ElementVolumeVariables& elemVolVars)
306 {
307 const auto& problem = gridFluxVarsCache().problem();
308 const auto& gridGeometry = fvGeometry.gridGeometry();
309 const auto globalI = gridGeometry.elementMapper().index(element);
310 const auto& connectivityMapI = gridGeometry.connectivityMap()[globalI];
311 const auto numNeighbors = connectivityMapI.size();
312
313 // instantiate helper class to fill the caches
314 FluxVariablesCacheFiller filler(problem);
315
316 // find the number of scv faces that need to be prepared
317 auto numScvf = fvGeometry.numScvf();
318 for (unsigned int localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ)
319 numScvf += connectivityMapI[localIdxJ].scvfsJ.size();
320
321 // fill the containers with the data on the scv faces inside the actual element
322 fluxVarsCache_.resize(numScvf);
323 globalScvfIndices_.resize(numScvf);
324 unsigned int localScvfIdx = 0;
325 for (auto&& scvf : scvfs(fvGeometry))
326 {
327 filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true);
328 globalScvfIndices_[localScvfIdx] = scvf.index();
329 localScvfIdx++;
330 }
331
332 // add required data on the scv faces in the neighboring elements
333 for (unsigned int localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ)
334 {
335 const auto elementJ = gridGeometry.element(connectivityMapI[localIdxJ].globalJ);
336 for (auto scvfIdx : connectivityMapI[localIdxJ].scvfsJ)
337 {
338 auto&& scvfJ = fvGeometry.scvf(scvfIdx);
339 filler.fill(*this, fluxVarsCache_[localScvfIdx], elementJ, fvGeometry, elemVolVars, scvfJ, true);
340 globalScvfIndices_[localScvfIdx] = scvfJ.index();
341 localScvfIdx++;
342 }
343 }
344 }
345
351 template<class FVElementGeometry, class ElementVolumeVariables>
352 void bindScvf_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
353 const FVElementGeometry& fvGeometry,
354 const ElementVolumeVariables& elemVolVars,
355 const typename FVElementGeometry::SubControlVolumeFace& scvf)
356 {
357 fluxVarsCache_.resize(1);
358 globalScvfIndices_.resize(1);
359
360 // instantiate helper class to fill the caches
361 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
362
363 filler.fill(*this, fluxVarsCache_[0], element, fvGeometry, elemVolVars, scvf, true);
364 globalScvfIndices_[0] = scvf.index();
365 }
366
367 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
368
370 int getLocalScvfIdx_(const int scvfIdx) const
371 {
372 auto it = std::find(globalScvfIndices_.begin(), globalScvfIndices_.end(), scvfIdx);
373 assert(it != globalScvfIndices_.end() && "Could not find the flux vars cache for scvfIdx");
374 return std::distance(globalScvfIndices_.begin(), it);
375 }
376
377 std::vector<FluxVariablesCache> fluxVarsCache_;
378 std::vector<std::size_t> globalScvfIndices_;
379};
380
381} // end namespace Dumux
382
383#endif
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars) &
Specialization for the global caching being enabled - do nothing here.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:193
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:148
CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:153
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars) &
Specialization for the global caching being enabled - do nothing here.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:172
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:264
CCTpfaElementFluxVariablesCache bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const typename FVElementGeometry::SubControlVolumeFace &scvf) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:204
CCTpfaElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:183
void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const typename FVElementGeometry::SubControlVolumeFace &scvf) &
Specialization for the global caching being enabled - do nothing here.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:215
void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Update the transmissibilities if the volume variables have changed.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:226
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:151
CCTpfaElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:162
CCTpfaElementFluxVariablesCache bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const typename FVElementGeometry::SubControlVolumeFace &scvf) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:101
void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Specialization for the global caching being enabled - do nothing here.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:119
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:50
CCTpfaElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:81
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars) &
Specialization for the global caching being enabled - do nothing here.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:91
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars) &
Specialization for the global caching being enabled - do nothing here.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:71
CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:52
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:47
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:129
void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const typename FVElementGeometry::SubControlVolumeFace &scvf) &
Specialization for the global caching being enabled - do nothing here.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:112
CCTpfaElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:61
The flux variables caches for an element.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:33
static ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:282
Definition: adapt.hh:17