24#ifndef DUMUX_DISCRETIZATION_STAGGERED_ELEMENT_FLUXVARSCACHE_HH
25#define DUMUX_DISCRETIZATION_STAGGERED_ELEMENT_FLUXVARSCACHE_HH
32#include <dune/common/exceptions.hh>
40template<
class Gr
idFluxVariablesCache,
bool cachingEnabled>
52 using FluxVariablesCacheFiller =
typename GFVC::Traits::FluxVariablesCacheFiller;
63 : gridFluxVarsCachePtr_(&global) {}
66 template<
class FVElementGeometry,
class ElementVolumeVariables>
67 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
68 const FVElementGeometry& fvGeometry,
69 const ElementVolumeVariables& elemVolVars) {}
72 template<
class FVElementGeometry,
class ElementVolumeVariables>
73 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
74 const FVElementGeometry& fvGeometry,
75 const ElementVolumeVariables& elemVolVars) {}
78 template<
class FVElementGeometry,
class ElementVolumeVariables>
79 void bindScvf(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
80 const FVElementGeometry& fvGeometry,
81 const ElementVolumeVariables& elemVolVars,
82 const typename FVElementGeometry::SubControlVolumeFace& scvf) {}
85 template<
class FVElementGeometry,
class ElementVolumeVariables>
86 void update(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
87 const FVElementGeometry& fvGeometry,
88 const ElementVolumeVariables& elemVolVars)
90 DUNE_THROW(Dune::InvalidStateException,
"In case of enabled caching, the grid flux variables cache must not to be updated");
94 template<
class SubControlVolumeFace>
96 {
return (*gridFluxVarsCachePtr_)[scvf.index()]; }
100 {
return *gridFluxVarsCachePtr_; }
103 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
115 using FluxVariablesCacheFiller =
typename GFVC::Traits::FluxVariablesCacheFiller;
125 : gridFluxVarsCachePtr_(&global) {}
132 template<
class FVElementGeometry,
class ElementVolumeVariables>
133 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
134 const FVElementGeometry& fvGeometry,
135 const ElementVolumeVariables& elemVolVars)
138 const auto numScvf = fvGeometry.numScvf();
139 fluxVarsCache_.resize(numScvf);
140 globalScvfIndices_.resize(numScvf);
143 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
145 std::size_t localScvfIdx = 0;
147 for (
auto&& scvf : scvfs(fvGeometry))
149 filler.fill(*
this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf,
true);
150 globalScvfIndices_[localScvfIdx] = scvf.index();
160 template<
class FVElementGeometry,
class ElementVolumeVariables>
161 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
162 const FVElementGeometry& fvGeometry,
163 const ElementVolumeVariables& elemVolVars)
166 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
169 const auto numScvf = fvGeometry.numScvf();
172 fluxVarsCache_.resize(numScvf);
173 globalScvfIndices_.resize(numScvf);
174 unsigned int localScvfIdx = 0;
175 for (
auto&& scvf : scvfs(fvGeometry))
177 filler.fill(*
this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf,
true);
178 globalScvfIndices_[localScvfIdx] = scvf.index();
188 template<
class FVElementGeometry,
class ElementVolumeVariables>
189 void bindScvf(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
190 const FVElementGeometry& fvGeometry,
191 const ElementVolumeVariables& elemVolVars,
192 const typename FVElementGeometry::SubControlVolumeFace& scvf)
194 fluxVarsCache_.resize(1);
195 globalScvfIndices_.resize(1);
199 FluxVariablesCacheFiller filler;
201 filler.fill(*
this, fluxVarsCache_[0], element, fvGeometry, elemVolVars, scvf,
true);
202 globalScvfIndices_[0] = scvf.index();
209 template<
class FVElementGeometry,
class ElementVolumeVariables>
210 void update(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
211 const FVElementGeometry& fvGeometry,
212 const ElementVolumeVariables& elemVolVars)
238 template<
class SubControlVolumeFace>
240 {
return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
242 template<
class SubControlVolumeFace>
244 {
return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
248 {
return *gridFluxVarsCachePtr_; }
251 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
254 int getLocalScvfIdx_(
const int scvfIdx)
const
256 auto it = std::find(globalScvfIndices_.begin(), globalScvfIndices_.end(), scvfIdx);
257 assert(it != globalScvfIndices_.end() &&
"Could not find the flux vars cache for scvfIdx");
261 std::vector<FluxVariablesCache> fluxVarsCache_;
262 std::vector<std::size_t> globalScvfIndices_;
ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: geometry/distance.hh:138
Base class for the stencil local flux variables cache for the staggered model.
Definition: staggered/elementfluxvariablescache.hh:41
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: staggered/elementfluxvariablescache.hh:59
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: staggered/elementfluxvariablescache.hh:73
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: staggered/elementfluxvariablescache.hh:99
StaggeredElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: staggered/elementfluxvariablescache.hh:62
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: staggered/elementfluxvariablescache.hh:67
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: staggered/elementfluxvariablescache.hh:86
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: staggered/elementfluxvariablescache.hh:56
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: staggered/elementfluxvariablescache.hh:79
StaggeredElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: staggered/elementfluxvariablescache.hh:124
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: staggered/elementfluxvariablescache.hh:247
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: staggered/elementfluxvariablescache.hh:210
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: staggered/elementfluxvariablescache.hh:119
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Prepares the transmissibilities of the scv faces in an element.
Definition: staggered/elementfluxvariablescache.hh:133
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: staggered/elementfluxvariablescache.hh:122
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Prepares the transmissibilities of the scv faces in the stencil of an element.
Definition: staggered/elementfluxvariablescache.hh:161
void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const typename FVElementGeometry::SubControlVolumeFace &scvf)
Prepares the transmissibilities of a single scv face.
Definition: staggered/elementfluxvariablescache.hh:189