3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
discretization/staggered/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_STAGGERED_ELEMENT_FLUXVARSCACHE_HH
25#define DUMUX_DISCRETIZATION_STAGGERED_ELEMENT_FLUXVARSCACHE_HH
26
27#include <algorithm>
28#include <cassert>
29#include <iterator>
30#include <vector>
31#include <utility>
32
33#include <dune/common/exceptions.hh>
34
35namespace Dumux {
36
41template<class GridFluxVariablesCache, bool cachingEnabled>
43
49template<class GFVC>
51{
53 using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller;
54
55public:
58
60 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
61
62
64 : gridFluxVarsCachePtr_(&global) {}
65
71 template<class FVElementGeometry, class ElementVolumeVariables>
72 StaggeredElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
73 const FVElementGeometry& fvGeometry,
74 const ElementVolumeVariables& elemVolVars) &&
75 {
76 this->bindElement(element, fvGeometry, elemVolVars);
77 return std::move(*this);
78 }
79
81 template<class FVElementGeometry, class ElementVolumeVariables>
82 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
83 const FVElementGeometry& fvGeometry,
84 const ElementVolumeVariables& elemVolVars) & {}
85
91 template<class FVElementGeometry, class ElementVolumeVariables>
92 StaggeredElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
93 const FVElementGeometry& fvGeometry,
94 const ElementVolumeVariables& elemVolVars) &&
95 {
96 this->bind(element, fvGeometry, elemVolVars);
97 return std::move(*this);
98 }
99
101 template<class FVElementGeometry, class ElementVolumeVariables>
102 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
103 const FVElementGeometry& fvGeometry,
104 const ElementVolumeVariables& elemVolVars) & {}
105
111 template<class FVElementGeometry, class ElementVolumeVariables>
112 StaggeredElementFluxVariablesCache 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 {
117 this->bindScvf(element, fvGeometry, elemVolVars, scvf);
118 return std::move(*this);
119 }
120
122 template<class FVElementGeometry, class ElementVolumeVariables>
123 void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
124 const FVElementGeometry& fvGeometry,
125 const ElementVolumeVariables& elemVolVars,
126 const typename FVElementGeometry::SubControlVolumeFace& scvf) & {}
127
129 template<class FVElementGeometry, class ElementVolumeVariables>
130 void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
131 const FVElementGeometry& fvGeometry,
132 const ElementVolumeVariables& elemVolVars)
133 {
134 DUNE_THROW(Dune::InvalidStateException, "In case of enabled caching, the grid flux variables cache must not to be updated");
135 }
136
138 template<class SubControlVolumeFace>
139 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
140 { return (*gridFluxVarsCachePtr_)[scvf.index()]; }
141
144 { return *gridFluxVarsCachePtr_; }
145
146private:
147 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
148};
149
155template<class GFVC>
157{
159 using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller;
160
161public:
164
166 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
167
169 : gridFluxVarsCachePtr_(&global) {}
170
176 template<class FVElementGeometry, class ElementVolumeVariables>
177 StaggeredElementFluxVariablesCache bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
178 const FVElementGeometry& fvGeometry,
179 const ElementVolumeVariables& elemVolVars) &&
180 {
181 this->bindElement_(element, fvGeometry, elemVolVars);
182 return std::move(*this);
183 }
184
186 template<class FVElementGeometry, class ElementVolumeVariables>
187 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
188 const FVElementGeometry& fvGeometry,
189 const ElementVolumeVariables& elemVolVars) &
190 { this->bindElement_(element, fvGeometry, elemVolVars); }
191
197 template<class FVElementGeometry, class ElementVolumeVariables>
198 StaggeredElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
199 const FVElementGeometry& fvGeometry,
200 const ElementVolumeVariables& elemVolVars) &&
201 {
202 this->bind_(element, fvGeometry, elemVolVars);
203 return std::move(*this);
204 }
205
207 template<class FVElementGeometry, class ElementVolumeVariables>
208 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
209 const FVElementGeometry& fvGeometry,
210 const ElementVolumeVariables& elemVolVars) &
211 { this->bind_(element, fvGeometry, elemVolVars); }
212
218 template<class FVElementGeometry, class ElementVolumeVariables>
219 StaggeredElementFluxVariablesCache bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
220 const FVElementGeometry& fvGeometry,
221 const ElementVolumeVariables& elemVolVars,
222 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
223 {
224 this->bindScvf_(element, fvGeometry, elemVolVars, scvf);
225 return std::move(*this);
226 }
227
229 template<class FVElementGeometry, class ElementVolumeVariables>
230 void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
231 const FVElementGeometry& fvGeometry,
232 const ElementVolumeVariables& elemVolVars,
233 const typename FVElementGeometry::SubControlVolumeFace& scvf) &
234 { this->bindScvf_(element, fvGeometry, elemVolVars, scvf); }
235
240 template<class FVElementGeometry, class ElementVolumeVariables>
241 void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
242 const FVElementGeometry& fvGeometry,
243 const ElementVolumeVariables& elemVolVars)
244 {
245 // if (FluxVariablesCacheFiller::isSolDependent) TODO
246 // {
247 // const auto& problem = gridFluxVarsCache().problem();
248 // const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element);
249 //
250 // // instantiate filler class
251 // FluxVariablesCacheFiller filler(problem);
252 //
253 // // let the filler class update the caches
254 // for (unsigned int localScvfIdx = 0; localScvfIdx < fluxVarsCache_.size(); ++localScvfIdx)
255 // {
256 // const auto& scvf = fvGeometry.scvf(globalScvfIndices_[localScvfIdx]);
257 //
258 // const auto scvfInsideScvIdx = scvf.insideScvIdx();
259 // const auto& insideElement = scvfInsideScvIdx == globalI ?
260 // element :
261 // fvGeometry.gridGeometry().element(scvfInsideScvIdx);
262 //
263 // filler.fill(*this, fluxVarsCache_[localScvfIdx], insideElement, fvGeometry, elemVolVars, scvf);
264 // }
265 // }
266 }
267
269 template<class SubControlVolumeFace>
270 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
271 { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
272
273 template<class SubControlVolumeFace>
274 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
275 { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
276
279 { return *gridFluxVarsCachePtr_; }
280
281private:
282
288 template<class FVElementGeometry, class ElementVolumeVariables>
289 void bindElement_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
290 const FVElementGeometry& fvGeometry,
291 const ElementVolumeVariables& elemVolVars)
292 {
293 // resizing of the cache
294 const auto numScvf = fvGeometry.numScvf();
295 fluxVarsCache_.resize(numScvf);
296 globalScvfIndices_.resize(numScvf);
297
298 // instantiate helper class to fill the caches
299 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
300
301 std::size_t localScvfIdx = 0;
302 // fill the containers
303 for (auto&& scvf : scvfs(fvGeometry))
304 {
305 filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true);
306 globalScvfIndices_[localScvfIdx] = scvf.index();
307 localScvfIdx++;
308 }
309 }
310
316 template<class FVElementGeometry, class ElementVolumeVariables>
317 void bind_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
318 const FVElementGeometry& fvGeometry,
319 const ElementVolumeVariables& elemVolVars)
320 {
321 // instantiate helper class to fill the caches
322 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
323
324 // find the number of scv faces that need to be prepared
325 const auto numScvf = fvGeometry.numScvf();
326
327 // fill the containers with the data on the scv faces inside the actual element
328 fluxVarsCache_.resize(numScvf);
329 globalScvfIndices_.resize(numScvf);
330 unsigned int localScvfIdx = 0;
331 for (auto&& scvf : scvfs(fvGeometry))
332 {
333 filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true);
334 globalScvfIndices_[localScvfIdx] = scvf.index();
335 localScvfIdx++;
336 }
337 }
338
344 template<class FVElementGeometry, class ElementVolumeVariables>
345 void bindScvf_ (const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
346 const FVElementGeometry& fvGeometry,
347 const ElementVolumeVariables& elemVolVars,
348 const typename FVElementGeometry::SubControlVolumeFace& scvf)
349 {
350 fluxVarsCache_.resize(1);
351 globalScvfIndices_.resize(1);
352
353 // instantiate helper class to fill the caches
354 // FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
355 FluxVariablesCacheFiller filler; // TODO: use proper ctor
356
357 filler.fill(*this, fluxVarsCache_[0], element, fvGeometry, elemVolVars, scvf, true);
358 globalScvfIndices_[0] = scvf.index();
359 }
360
361 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
362
363 // get index of scvf in the local container
364 int getLocalScvfIdx_(const int scvfIdx) const
365 {
366 auto it = std::find(globalScvfIndices_.begin(), globalScvfIndices_.end(), scvfIdx);
367 assert(it != globalScvfIndices_.end() && "Could not find the flux vars cache for scvfIdx");
368 return std::distance(globalScvfIndices_.begin(), it);
369 }
370
371 std::vector<FluxVariablesCache> fluxVarsCache_;
372 std::vector<std::size_t> globalScvfIndices_;
373};
374
375} // end namespace Dumux
376
377#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
Base class for the stencil local flux variables cache for the staggered model.
Definition: discretization/staggered/elementfluxvariablescache.hh:42
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: discretization/staggered/elementfluxvariablescache.hh:60
StaggeredElementFluxVariablesCache 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/staggered/elementfluxvariablescache.hh:72
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: discretization/staggered/elementfluxvariablescache.hh:143
StaggeredElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: discretization/staggered/elementfluxvariablescache.hh:63
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/staggered/elementfluxvariablescache.hh:82
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/staggered/elementfluxvariablescache.hh:123
StaggeredElementFluxVariablesCache 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/staggered/elementfluxvariablescache.hh:92
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/staggered/elementfluxvariablescache.hh:130
StaggeredElementFluxVariablesCache 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/staggered/elementfluxvariablescache.hh:112
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/staggered/elementfluxvariablescache.hh:102
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: discretization/staggered/elementfluxvariablescache.hh:57
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/staggered/elementfluxvariablescache.hh:208
StaggeredElementFluxVariablesCache 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/staggered/elementfluxvariablescache.hh:198
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/staggered/elementfluxvariablescache.hh:187
StaggeredElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: discretization/staggered/elementfluxvariablescache.hh:168
StaggeredElementFluxVariablesCache 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/staggered/elementfluxvariablescache.hh:177
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: discretization/staggered/elementfluxvariablescache.hh:278
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/staggered/elementfluxvariablescache.hh:241
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: discretization/staggered/elementfluxvariablescache.hh:163
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/staggered/elementfluxvariablescache.hh:230
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: discretization/staggered/elementfluxvariablescache.hh:166
StaggeredElementFluxVariablesCache 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/staggered/elementfluxvariablescache.hh:219