24#ifndef DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH
25#define DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH
32#include <dune/common/exceptions.hh>
44template<
class GFVC,
bool cachingEnabled>
55 using FluxVariablesCacheFiller =
typename GFVC::Traits::FluxVariablesCacheFiller;
65 : gridFluxVarsCachePtr_(&global) {}
72 template<
class FVElementGeometry,
class ElementVolumeVariables>
74 const FVElementGeometry& fvGeometry,
75 const ElementVolumeVariables& elemVolVars) &&
77 this->bindElement(element, fvGeometry, elemVolVars);
78 return std::move(*
this);
82 template<
class FVElementGeometry,
class ElementVolumeVariables>
83 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
84 const FVElementGeometry& fvGeometry,
85 const ElementVolumeVariables& elemVolVars) & {}
92 template<
class FVElementGeometry,
class ElementVolumeVariables>
94 const FVElementGeometry& fvGeometry,
95 const ElementVolumeVariables& elemVolVars) &&
97 this->bind(element, fvGeometry, elemVolVars);
98 return std::move(*
this);
102 template<
class FVElementGeometry,
class ElementVolumeVariables>
103 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
104 const FVElementGeometry& fvGeometry,
105 const ElementVolumeVariables& elemVolVars) & {}
112 template<
class FVElementGeometry,
class ElementVolumeVariables>
114 const FVElementGeometry& fvGeometry,
115 const ElementVolumeVariables& elemVolVars,
116 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
118 this->bindScvf(element, fvGeometry, elemVolVars, scvf);
119 return std::move(*
this);
123 template<
class FVElementGeometry,
class ElementVolumeVariables>
124 void bindScvf(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
125 const FVElementGeometry& fvGeometry,
126 const ElementVolumeVariables& elemVolVars,
127 const typename FVElementGeometry::SubControlVolumeFace& scvf) & {}
130 template<
class FVElementGeometry,
class ElementVolumeVariables>
131 void update(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
132 const FVElementGeometry& fvGeometry,
133 const ElementVolumeVariables& elemVolVars) {}
136 template<
class SubControlVolumeFace>
138 {
return gridFluxVarsCache()[scvf]; }
142 {
return *gridFluxVarsCachePtr_; }
145 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
156 using FluxVariablesCacheFiller =
typename GFVC::Traits::FluxVariablesCacheFiller;
166 : gridFluxVarsCachePtr_(&global) {}
173 template<
class FVElementGeometry,
class ElementVolumeVariables>
175 const FVElementGeometry& fvGeometry,
176 const ElementVolumeVariables& elemVolVars) &&
178 this->bindElement_(element, fvGeometry, elemVolVars);
179 return std::move(*
this);
183 template<
class FVElementGeometry,
class ElementVolumeVariables>
184 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
185 const FVElementGeometry& fvGeometry,
186 const ElementVolumeVariables& elemVolVars) &
187 { this->bindElement_(element, fvGeometry, elemVolVars); }
194 template<
class FVElementGeometry,
class ElementVolumeVariables>
196 const FVElementGeometry& fvGeometry,
197 const ElementVolumeVariables& elemVolVars) &&
199 this->bind_(element, fvGeometry, elemVolVars);
200 return std::move(*
this);
204 template<
class FVElementGeometry,
class ElementVolumeVariables>
205 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
206 const FVElementGeometry& fvGeometry,
207 const ElementVolumeVariables& elemVolVars) &
208 { this->bind_(element, fvGeometry, elemVolVars); }
215 template<
class FVElementGeometry,
class ElementVolumeVariables>
217 const FVElementGeometry& fvGeometry,
218 const ElementVolumeVariables& elemVolVars,
219 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
221 this->bindScvf_(element, fvGeometry, elemVolVars, scvf);
222 return std::move(*
this);
226 template<
class FVElementGeometry,
class ElementVolumeVariables>
227 void bindScvf(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
228 const FVElementGeometry& fvGeometry,
229 const ElementVolumeVariables& elemVolVars,
230 const typename FVElementGeometry::SubControlVolumeFace& scvf) &
231 { this->bindScvf_(element, fvGeometry, elemVolVars, scvf); }
237 template<
class FVElementGeometry,
class ElementVolumeVariables>
238 void update(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
239 const FVElementGeometry& fvGeometry,
240 const ElementVolumeVariables& elemVolVars)
242 if (FluxVariablesCacheFiller::isSolDependent)
244 const auto& problem = gridFluxVarsCache().problem();
245 const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element);
248 FluxVariablesCacheFiller filler(problem);
251 for (
unsigned int localScvfIdx = 0; localScvfIdx < fluxVarsCache_.size(); ++localScvfIdx)
253 const auto& scvf = fvGeometry.scvf(globalScvfIndices_[localScvfIdx]);
255 const auto scvfInsideScvIdx = scvf.insideScvIdx();
256 const auto& insideElement = scvfInsideScvIdx == globalI ?
258 fvGeometry.gridGeometry().element(scvfInsideScvIdx);
260 filler.fill(*
this, fluxVarsCache_[localScvfIdx], insideElement, fvGeometry, elemVolVars, scvf);
266 template<
class SubControlVolumeFace>
268 {
return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
271 template<
class SubControlVolumeFace>
273 {
return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
277 {
return *gridFluxVarsCachePtr_; }
286 template<
class FVElementGeometry,
class ElementVolumeVariables>
287 void bindElement_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
288 const FVElementGeometry& fvGeometry,
289 const ElementVolumeVariables& elemVolVars)
292 const auto numScvf = fvGeometry.numScvf();
293 fluxVarsCache_.resize(numScvf);
294 globalScvfIndices_.resize(numScvf);
297 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
299 std::size_t localScvfIdx = 0;
301 for (
auto&& scvf : scvfs(fvGeometry))
303 filler.fill(*
this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf,
true);
304 globalScvfIndices_[localScvfIdx] = scvf.index();
314 template<
class FVElementGeometry,
class ElementVolumeVariables>
315 void bind_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
316 const FVElementGeometry& fvGeometry,
317 const ElementVolumeVariables& elemVolVars)
319 const auto& problem = gridFluxVarsCache().problem();
320 const auto& gridGeometry = fvGeometry.gridGeometry();
321 const auto globalI = gridGeometry.elementMapper().index(element);
322 const auto& connectivityMapI = gridGeometry.connectivityMap()[globalI];
323 const auto numNeighbors = connectivityMapI.size();
326 FluxVariablesCacheFiller filler(problem);
329 auto numScvf = fvGeometry.numScvf();
330 for (
unsigned int localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ)
331 numScvf += connectivityMapI[localIdxJ].scvfsJ.size();
334 fluxVarsCache_.resize(numScvf);
335 globalScvfIndices_.resize(numScvf);
336 unsigned int localScvfIdx = 0;
337 for (
auto&& scvf : scvfs(fvGeometry))
339 filler.fill(*
this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf,
true);
340 globalScvfIndices_[localScvfIdx] = scvf.index();
345 for (
unsigned int localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ)
347 const auto elementJ = gridGeometry.element(connectivityMapI[localIdxJ].globalJ);
348 for (
auto scvfIdx : connectivityMapI[localIdxJ].scvfsJ)
350 auto&& scvfJ = fvGeometry.scvf(scvfIdx);
351 filler.fill(*
this, fluxVarsCache_[localScvfIdx], elementJ, fvGeometry, elemVolVars, scvfJ,
true);
352 globalScvfIndices_[localScvfIdx] = scvfJ.index();
363 template<
class FVElementGeometry,
class ElementVolumeVariables>
364 void bindScvf_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
365 const FVElementGeometry& fvGeometry,
366 const ElementVolumeVariables& elemVolVars,
367 const typename FVElementGeometry::SubControlVolumeFace& scvf)
369 fluxVarsCache_.resize(1);
370 globalScvfIndices_.resize(1);
373 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
375 filler.fill(*
this, fluxVarsCache_[0], element, fvGeometry, elemVolVars, scvf,
true);
376 globalScvfIndices_[0] = scvf.index();
379 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
382 int getLocalScvfIdx_(
const int scvfIdx)
const
384 auto it = std::find(globalScvfIndices_.begin(), globalScvfIndices_.end(), scvfIdx);
385 assert(it != globalScvfIndices_.end() &&
"Could not find the flux vars cache for scvfIdx");
389 std::vector<FluxVariablesCache> fluxVarsCache_;
390 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
The flux variables caches for an element.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:45
CCTpfaElementFluxVariablesCache 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/cellcentered/tpfa/elementfluxvariablescache.hh:113
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/cellcentered/tpfa/elementfluxvariablescache.hh:131
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:62
CCTpfaElementFluxVariablesCache 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/cellcentered/tpfa/elementfluxvariablescache.hh:93
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/cellcentered/tpfa/elementfluxvariablescache.hh:103
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/cellcentered/tpfa/elementfluxvariablescache.hh:83
CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:64
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:59
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:141
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/cellcentered/tpfa/elementfluxvariablescache.hh:124
CCTpfaElementFluxVariablesCache 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/cellcentered/tpfa/elementfluxvariablescache.hh:73
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/cellcentered/tpfa/elementfluxvariablescache.hh:205
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:160
CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:165
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/cellcentered/tpfa/elementfluxvariablescache.hh:184
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:276
CCTpfaElementFluxVariablesCache 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/cellcentered/tpfa/elementfluxvariablescache.hh:216
CCTpfaElementFluxVariablesCache 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/cellcentered/tpfa/elementfluxvariablescache.hh:195
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/cellcentered/tpfa/elementfluxvariablescache.hh:227
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/cellcentered/tpfa/elementfluxvariablescache.hh:238
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:163
CCTpfaElementFluxVariablesCache 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/cellcentered/tpfa/elementfluxvariablescache.hh:174