3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH
25#define DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH
26
27#include <algorithm>
28#include <cassert>
29#include <vector>
30#include <utility>
31
32#include <dune/common/exceptions.hh>
33
34namespace Dumux {
35
44template<class GFVC, bool cachingEnabled>
46
51template<class GFVC>
53{
55 using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller;
56
57public:
60
62 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
63
65 : gridFluxVarsCachePtr_(&global) {}
66
72 template<class FVElementGeometry, class ElementVolumeVariables>
73 CCTpfaElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
74 const FVElementGeometry& fvGeometry,
75 const ElementVolumeVariables& elemVolVars) &&
76 {
77 this->bindElement(element, fvGeometry, elemVolVars);
78 return std::move(*this);
79 }
80
82 template<class FVElementGeometry, class ElementVolumeVariables>
83 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
84 const FVElementGeometry& fvGeometry,
85 const ElementVolumeVariables& elemVolVars) & {}
86
92 template<class FVElementGeometry, class ElementVolumeVariables>
93 CCTpfaElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
94 const FVElementGeometry& fvGeometry,
95 const ElementVolumeVariables& elemVolVars) &&
96 {
97 this->bind(element, fvGeometry, elemVolVars);
98 return std::move(*this);
99 }
100
102 template<class FVElementGeometry, class ElementVolumeVariables>
103 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
104 const FVElementGeometry& fvGeometry,
105 const ElementVolumeVariables& elemVolVars) & {}
106
112 template<class FVElementGeometry, class ElementVolumeVariables>
113 CCTpfaElementFluxVariablesCache bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
114 const FVElementGeometry& fvGeometry,
115 const ElementVolumeVariables& elemVolVars,
116 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
117 {
118 this->bindScvf(element, fvGeometry, elemVolVars, scvf);
119 return std::move(*this);
120 }
121
123 template<class FVElementGeometry, class ElementVolumeVariables>
124 void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
125 const FVElementGeometry& fvGeometry,
126 const ElementVolumeVariables& elemVolVars,
127 const typename FVElementGeometry::SubControlVolumeFace& scvf) & {}
128
130 template<class FVElementGeometry, class ElementVolumeVariables>
131 void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
132 const FVElementGeometry& fvGeometry,
133 const ElementVolumeVariables& elemVolVars) {}
134
136 template<class SubControlVolumeFace>
137 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
138 { return gridFluxVarsCache()[scvf]; }
139
142 { return *gridFluxVarsCachePtr_; }
143
144private:
145 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
146};
147
152template<class GFVC>
154{
156 using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller;
157
158public:
161
163 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
164
166 : gridFluxVarsCachePtr_(&global) {}
167
173 template<class FVElementGeometry, class ElementVolumeVariables>
174 CCTpfaElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
175 const FVElementGeometry& fvGeometry,
176 const ElementVolumeVariables& elemVolVars) &&
177 {
178 this->bindElement_(element, fvGeometry, elemVolVars);
179 return std::move(*this);
180 }
181
183 template<class FVElementGeometry, class ElementVolumeVariables>
184 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
185 const FVElementGeometry& fvGeometry,
186 const ElementVolumeVariables& elemVolVars) &
187 { this->bindElement_(element, fvGeometry, elemVolVars); }
188
194 template<class FVElementGeometry, class ElementVolumeVariables>
195 CCTpfaElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
196 const FVElementGeometry& fvGeometry,
197 const ElementVolumeVariables& elemVolVars) &&
198 {
199 this->bind_(element, fvGeometry, elemVolVars);
200 return std::move(*this);
201 }
202
204 template<class FVElementGeometry, class ElementVolumeVariables>
205 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
206 const FVElementGeometry& fvGeometry,
207 const ElementVolumeVariables& elemVolVars) &
208 { this->bind_(element, fvGeometry, elemVolVars); }
209
215 template<class FVElementGeometry, class ElementVolumeVariables>
216 CCTpfaElementFluxVariablesCache bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
217 const FVElementGeometry& fvGeometry,
218 const ElementVolumeVariables& elemVolVars,
219 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
220 {
221 this->bindScvf_(element, fvGeometry, elemVolVars, scvf);
222 return std::move(*this);
223 }
224
226 template<class FVElementGeometry, class ElementVolumeVariables>
227 void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
228 const FVElementGeometry& fvGeometry,
229 const ElementVolumeVariables& elemVolVars,
230 const typename FVElementGeometry::SubControlVolumeFace& scvf) &
231 { this->bindScvf_(element, fvGeometry, elemVolVars, scvf); }
232
237 template<class FVElementGeometry, class ElementVolumeVariables>
238 void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
239 const FVElementGeometry& fvGeometry,
240 const ElementVolumeVariables& elemVolVars)
241 {
242 if (FluxVariablesCacheFiller::isSolDependent)
243 {
244 const auto& problem = gridFluxVarsCache().problem();
245 const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element);
246
247 // instantiate filler class
248 FluxVariablesCacheFiller filler(problem);
249
250 // let the filler class update the caches
251 for (unsigned int localScvfIdx = 0; localScvfIdx < fluxVarsCache_.size(); ++localScvfIdx)
252 {
253 const auto& scvf = fvGeometry.scvf(globalScvfIndices_[localScvfIdx]);
254
255 const auto scvfInsideScvIdx = scvf.insideScvIdx();
256 const auto& insideElement = scvfInsideScvIdx == globalI ?
257 element :
258 fvGeometry.gridGeometry().element(scvfInsideScvIdx);
259
260 filler.fill(*this, fluxVarsCache_[localScvfIdx], insideElement, fvGeometry, elemVolVars, scvf);
261 }
262 }
263 }
264
266 template<class SubControlVolumeFace>
267 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
268 { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
269
271 template<class SubControlVolumeFace>
272 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
273 { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
274
277 { return *gridFluxVarsCachePtr_; }
278
279private:
280
286 template<class FVElementGeometry, class ElementVolumeVariables>
287 void bindElement_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
288 const FVElementGeometry& fvGeometry,
289 const ElementVolumeVariables& elemVolVars)
290 {
291 // resizing of the cache
292 const auto numScvf = fvGeometry.numScvf();
293 fluxVarsCache_.resize(numScvf);
294 globalScvfIndices_.resize(numScvf);
295
296 // instantiate helper class to fill the caches
297 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
298
299 std::size_t localScvfIdx = 0;
300 // fill the containers
301 for (auto&& scvf : scvfs(fvGeometry))
302 {
303 filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true);
304 globalScvfIndices_[localScvfIdx] = scvf.index();
305 localScvfIdx++;
306 }
307 }
308
314 template<class FVElementGeometry, class ElementVolumeVariables>
315 void bind_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
316 const FVElementGeometry& fvGeometry,
317 const ElementVolumeVariables& elemVolVars)
318 {
319 const auto& problem = gridFluxVarsCache().problem();
320 const auto& gridGeometry = fvGeometry.gridGeometry();
321 const auto globalI = gridGeometry.elementMapper().index(element);
322 const auto& connectivityMapI = gridGeometry.connectivityMap()[globalI];
323 const auto numNeighbors = connectivityMapI.size();
324
325 // instantiate helper class to fill the caches
326 FluxVariablesCacheFiller filler(problem);
327
328 // find the number of scv faces that need to be prepared
329 auto numScvf = fvGeometry.numScvf();
330 for (unsigned int localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ)
331 numScvf += connectivityMapI[localIdxJ].scvfsJ.size();
332
333 // fill the containers with the data on the scv faces inside the actual element
334 fluxVarsCache_.resize(numScvf);
335 globalScvfIndices_.resize(numScvf);
336 unsigned int localScvfIdx = 0;
337 for (auto&& scvf : scvfs(fvGeometry))
338 {
339 filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true);
340 globalScvfIndices_[localScvfIdx] = scvf.index();
341 localScvfIdx++;
342 }
343
344 // add required data on the scv faces in the neighboring elements
345 for (unsigned int localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ)
346 {
347 const auto elementJ = gridGeometry.element(connectivityMapI[localIdxJ].globalJ);
348 for (auto scvfIdx : connectivityMapI[localIdxJ].scvfsJ)
349 {
350 auto&& scvfJ = fvGeometry.scvf(scvfIdx);
351 filler.fill(*this, fluxVarsCache_[localScvfIdx], elementJ, fvGeometry, elemVolVars, scvfJ, true);
352 globalScvfIndices_[localScvfIdx] = scvfJ.index();
353 localScvfIdx++;
354 }
355 }
356 }
357
363 template<class FVElementGeometry, class ElementVolumeVariables>
364 void bindScvf_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
365 const FVElementGeometry& fvGeometry,
366 const ElementVolumeVariables& elemVolVars,
367 const typename FVElementGeometry::SubControlVolumeFace& scvf)
368 {
369 fluxVarsCache_.resize(1);
370 globalScvfIndices_.resize(1);
371
372 // instantiate helper class to fill the caches
373 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
374
375 filler.fill(*this, fluxVarsCache_[0], element, fvGeometry, elemVolVars, scvf, true);
376 globalScvfIndices_[0] = scvf.index();
377 }
378
379 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
380
382 int getLocalScvfIdx_(const int scvfIdx) const
383 {
384 auto it = std::find(globalScvfIndices_.begin(), globalScvfIndices_.end(), scvfIdx);
385 assert(it != globalScvfIndices_.end() && "Could not find the flux vars cache for scvfIdx");
386 return std::distance(globalScvfIndices_.begin(), it);
387 }
388
389 std::vector<FluxVariablesCache> fluxVarsCache_;
390 std::vector<std::size_t> globalScvfIndices_;
391};
392
393} // end namespace Dumux
394
395#endif
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:292
Definition: adapt.hh:29
The flux variables caches for an element.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:45
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:113
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:131
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:62
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:93
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:103
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:83
CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:64
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:59
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:141
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:124
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:73
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:205
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:160
CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:165
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:184
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:276
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:216
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:195
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:227
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:238
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:163
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:174