version 3.10-dev
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// 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_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
23namespace Dumux {
24
29template<class GridFluxVariablesCache, bool cachingEnabled>
31
37template<class GFVC>
39{
41 using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller;
42
43public:
46
48 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
49
50
52 : gridFluxVarsCachePtr_(&global) {}
53
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
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
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
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
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
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
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
126 template<class SubControlVolumeFace>
127 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
128 { return (*gridFluxVarsCachePtr_)[scvf.index()]; }
129
132 { return *gridFluxVarsCachePtr_; }
133
134private:
135 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
136};
137
143template<class GFVC>
145{
147 using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller;
148
149public:
152
154 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
155
157 : gridFluxVarsCachePtr_(&global) {}
158
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
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
185 template<class FVElementGeometry, class ElementVolumeVariables>
186 StaggeredElementFluxVariablesCache bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
187 const FVElementGeometry& fvGeometry,
188 const ElementVolumeVariables& elemVolVars) &&
189 {
190 this->bind_(element, fvGeometry, elemVolVars);
191 return std::move(*this);
192 }
193
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
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
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
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
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
267 { return *gridFluxVarsCachePtr_; }
268
269private:
270
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
304 template<class FVElementGeometry, class ElementVolumeVariables>
305 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 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
311
312 // find the number of scv faces that need to be prepared
313 const auto numScvf = fvGeometry.numScvf();
314
315 // fill the containers with the data on the scv faces inside the actual element
316 fluxVarsCache_.resize(numScvf);
317 globalScvfIndices_.resize(numScvf);
318 unsigned int localScvfIdx = 0;
319 for (auto&& scvf : scvfs(fvGeometry))
320 {
321 filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true);
322 globalScvfIndices_[localScvfIdx] = scvf.index();
323 localScvfIdx++;
324 }
325 }
326
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
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:196
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:186
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:175
StaggeredElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: discretization/staggered/elementfluxvariablescache.hh:156
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:165
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: discretization/staggered/elementfluxvariablescache.hh:266
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:229
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: discretization/staggered/elementfluxvariablescache.hh:151
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:218
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: discretization/staggered/elementfluxvariablescache.hh:154
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:207
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: discretization/staggered/elementfluxvariablescache.hh:48
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:60
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: discretization/staggered/elementfluxvariablescache.hh:131
StaggeredElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: discretization/staggered/elementfluxvariablescache.hh:51
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:70
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:111
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:80
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:118
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:100
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:90
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: discretization/staggered/elementfluxvariablescache.hh:45
Base class for the stencil local flux variables cache for the staggered model.
Definition: discretization/staggered/elementfluxvariablescache.hh:30
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