12#ifndef DUMUX_DISCRETIZATION_STAGGERED_ELEMENT_FLUXVARSCACHE_HH
13#define DUMUX_DISCRETIZATION_STAGGERED_ELEMENT_FLUXVARSCACHE_HH
21#include <dune/common/exceptions.hh>
29template<
class Gr
idFluxVariablesCache,
bool cachingEnabled>
41 using FluxVariablesCacheFiller =
typename GFVC::Traits::FluxVariablesCacheFiller;
52 : gridFluxVarsCachePtr_(&global) {}
59 template<
class FVElementGeometry,
class ElementVolumeVariables>
61 const FVElementGeometry& fvGeometry,
62 const ElementVolumeVariables& elemVolVars) &&
64 this->bindElement(element, fvGeometry, elemVolVars);
65 return std::move(*
this);
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) & {}
79 template<
class FVElementGeometry,
class ElementVolumeVariables>
81 const FVElementGeometry& fvGeometry,
82 const ElementVolumeVariables& elemVolVars) &&
84 this->bind(element, fvGeometry, elemVolVars);
85 return std::move(*
this);
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) & {}
99 template<
class FVElementGeometry,
class ElementVolumeVariables>
101 const FVElementGeometry& fvGeometry,
102 const ElementVolumeVariables& elemVolVars,
103 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
105 this->bindScvf(element, fvGeometry, elemVolVars, scvf);
106 return std::move(*
this);
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) & {}
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)
122 DUNE_THROW(Dune::InvalidStateException,
"In case of enabled caching, the grid flux variables cache must not to be updated");
126 template<
class SubControlVolumeFace>
128 {
return (*gridFluxVarsCachePtr_)[scvf.index()]; }
132 {
return *gridFluxVarsCachePtr_; }
135 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
147 using FluxVariablesCacheFiller =
typename GFVC::Traits::FluxVariablesCacheFiller;
157 : gridFluxVarsCachePtr_(&global) {}
164 template<
class FVElementGeometry,
class ElementVolumeVariables>
166 const FVElementGeometry& fvGeometry,
167 const ElementVolumeVariables& elemVolVars) &&
169 this->bindElement_(element, fvGeometry, elemVolVars);
170 return std::move(*
this);
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); }
185 template<
class FVElementGeometry,
class ElementVolumeVariables>
187 const FVElementGeometry& fvGeometry,
188 const ElementVolumeVariables& elemVolVars) &&
190 this->bind_(element, fvGeometry, elemVolVars);
191 return std::move(*
this);
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); }
206 template<
class FVElementGeometry,
class ElementVolumeVariables>
208 const FVElementGeometry& fvGeometry,
209 const ElementVolumeVariables& elemVolVars,
210 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
212 this->bindScvf_(element, fvGeometry, elemVolVars, scvf);
213 return std::move(*
this);
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); }
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)
257 template<
class SubControlVolumeFace>
259 {
return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
261 template<
class SubControlVolumeFace>
263 {
return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
267 {
return *gridFluxVarsCachePtr_; }
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)
282 const auto numScvf = fvGeometry.numScvf();
283 fluxVarsCache_.resize(numScvf);
284 globalScvfIndices_.resize(numScvf);
287 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
289 std::size_t localScvfIdx = 0;
291 for (
auto&& scvf : scvfs(fvGeometry))
293 filler.fill(*
this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf,
true);
294 globalScvfIndices_[localScvfIdx] = scvf.index();
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)
310 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
313 const auto numScvf = fvGeometry.numScvf();
316 fluxVarsCache_.resize(numScvf);
317 globalScvfIndices_.resize(numScvf);
318 unsigned int localScvfIdx = 0;
319 for (
auto&& scvf : scvfs(fvGeometry))
321 filler.fill(*
this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf,
true);
322 globalScvfIndices_[localScvfIdx] = scvf.index();
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)
338 fluxVarsCache_.resize(1);
339 globalScvfIndices_.resize(1);
343 FluxVariablesCacheFiller filler;
345 filler.fill(*
this, fluxVarsCache_[0], element, fvGeometry, elemVolVars, scvf,
true);
346 globalScvfIndices_[0] = scvf.index();
349 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
352 int getLocalScvfIdx_(
const int scvfIdx)
const
354 auto it = std::find(globalScvfIndices_.begin(), globalScvfIndices_.end(), scvfIdx);
355 assert(it != globalScvfIndices_.end() &&
"Could not find the flux vars cache for scvfIdx");
359 std::vector<FluxVariablesCache> fluxVarsCache_;
360 std::vector<std::size_t> globalScvfIndices_;
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