24#ifndef DUMUX_DISCRETIZATION_STAGGERED_ELEMENT_FLUXVARSCACHE_HH
25#define DUMUX_DISCRETIZATION_STAGGERED_ELEMENT_FLUXVARSCACHE_HH
33#include <dune/common/exceptions.hh>
41template<
class Gr
idFluxVariablesCache,
bool cachingEnabled>
53 using FluxVariablesCacheFiller =
typename GFVC::Traits::FluxVariablesCacheFiller;
64 : gridFluxVarsCachePtr_(&global) {}
71 template<
class FVElementGeometry,
class ElementVolumeVariables>
73 const FVElementGeometry& fvGeometry,
74 const ElementVolumeVariables& elemVolVars) &&
76 this->bindElement(element, fvGeometry, elemVolVars);
77 return std::move(*
this);
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) & {}
91 template<
class FVElementGeometry,
class ElementVolumeVariables>
93 const FVElementGeometry& fvGeometry,
94 const ElementVolumeVariables& elemVolVars) &&
96 this->bind(element, fvGeometry, elemVolVars);
97 return std::move(*
this);
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) & {}
111 template<
class FVElementGeometry,
class ElementVolumeVariables>
113 const FVElementGeometry& fvGeometry,
114 const ElementVolumeVariables& elemVolVars,
115 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
117 this->bindScvf(element, fvGeometry, elemVolVars, scvf);
118 return std::move(*
this);
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) & {}
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)
134 DUNE_THROW(Dune::InvalidStateException,
"In case of enabled caching, the grid flux variables cache must not to be updated");
138 template<
class SubControlVolumeFace>
140 {
return (*gridFluxVarsCachePtr_)[scvf.index()]; }
144 {
return *gridFluxVarsCachePtr_; }
147 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
159 using FluxVariablesCacheFiller =
typename GFVC::Traits::FluxVariablesCacheFiller;
169 : gridFluxVarsCachePtr_(&global) {}
176 template<
class FVElementGeometry,
class ElementVolumeVariables>
178 const FVElementGeometry& fvGeometry,
179 const ElementVolumeVariables& elemVolVars) &&
181 this->bindElement_(element, fvGeometry, elemVolVars);
182 return std::move(*
this);
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); }
197 template<
class FVElementGeometry,
class ElementVolumeVariables>
199 const FVElementGeometry& fvGeometry,
200 const ElementVolumeVariables& elemVolVars) &&
202 this->bind_(element, fvGeometry, elemVolVars);
203 return std::move(*
this);
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); }
218 template<
class FVElementGeometry,
class ElementVolumeVariables>
220 const FVElementGeometry& fvGeometry,
221 const ElementVolumeVariables& elemVolVars,
222 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
224 this->bindScvf_(element, fvGeometry, elemVolVars, scvf);
225 return std::move(*
this);
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); }
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)
269 template<
class SubControlVolumeFace>
271 {
return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
273 template<
class SubControlVolumeFace>
275 {
return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
279 {
return *gridFluxVarsCachePtr_; }
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)
294 const auto numScvf = fvGeometry.numScvf();
295 fluxVarsCache_.resize(numScvf);
296 globalScvfIndices_.resize(numScvf);
299 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
301 std::size_t localScvfIdx = 0;
303 for (
auto&& scvf : scvfs(fvGeometry))
305 filler.fill(*
this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf,
true);
306 globalScvfIndices_[localScvfIdx] = scvf.index();
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)
322 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
325 const auto numScvf = fvGeometry.numScvf();
328 fluxVarsCache_.resize(numScvf);
329 globalScvfIndices_.resize(numScvf);
330 unsigned int localScvfIdx = 0;
331 for (
auto&& scvf : scvfs(fvGeometry))
333 filler.fill(*
this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf,
true);
334 globalScvfIndices_[localScvfIdx] = scvf.index();
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)
350 fluxVarsCache_.resize(1);
351 globalScvfIndices_.resize(1);
355 FluxVariablesCacheFiller filler;
357 filler.fill(*
this, fluxVarsCache_[0], element, fvGeometry, elemVolVars, scvf,
true);
358 globalScvfIndices_[0] = scvf.index();
361 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
364 int getLocalScvfIdx_(
const int scvfIdx)
const
366 auto it = std::find(globalScvfIndices_.begin(), globalScvfIndices_.end(), scvfIdx);
367 assert(it != globalScvfIndices_.end() &&
"Could not find the flux vars cache for scvfIdx");
371 std::vector<FluxVariablesCache> fluxVarsCache_;
372 std::vector<std::size_t> globalScvfIndices_;
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
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