24#ifndef DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH
25#define DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH
30#include <dune/common/exceptions.hh>
42template<
class GFVC,
bool cachingEnabled>
53 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) {}
91 template<
class SubControlVolumeFace>
93 {
return gridFluxVarsCache()[scvf]; }
97 {
return *gridFluxVarsCachePtr_; }
100 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
111 using FluxVariablesCacheFiller =
typename GFVC::Traits::FluxVariablesCacheFiller;
121 : gridFluxVarsCachePtr_(&global) {}
128 template<
class FVElementGeometry,
class ElementVolumeVariables>
129 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
130 const FVElementGeometry& fvGeometry,
131 const ElementVolumeVariables& elemVolVars)
134 const auto numScvf = fvGeometry.numScvf();
135 fluxVarsCache_.resize(numScvf);
136 globalScvfIndices_.resize(numScvf);
139 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
141 std::size_t localScvfIdx = 0;
143 for (
auto&& scvf : scvfs(fvGeometry))
145 filler.fill(*
this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf,
true);
146 globalScvfIndices_[localScvfIdx] = scvf.index();
156 template<
class FVElementGeometry,
class ElementVolumeVariables>
157 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
158 const FVElementGeometry& fvGeometry,
159 const ElementVolumeVariables& elemVolVars)
161 const auto& problem = gridFluxVarsCache().problem();
162 const auto& gridGeometry = fvGeometry.gridGeometry();
163 const auto globalI = gridGeometry.elementMapper().index(element);
164 const auto& connectivityMapI = gridGeometry.connectivityMap()[globalI];
165 const auto numNeighbors = connectivityMapI.size();
168 FluxVariablesCacheFiller filler(problem);
171 auto numScvf = fvGeometry.numScvf();
172 for (
unsigned int localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ)
173 numScvf += connectivityMapI[localIdxJ].scvfsJ.size();
176 fluxVarsCache_.resize(numScvf);
177 globalScvfIndices_.resize(numScvf);
178 unsigned int localScvfIdx = 0;
179 for (
auto&& scvf : scvfs(fvGeometry))
181 filler.fill(*
this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf,
true);
182 globalScvfIndices_[localScvfIdx] = scvf.index();
187 for (
unsigned int localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ)
189 const auto elementJ = gridGeometry.element(connectivityMapI[localIdxJ].globalJ);
190 for (
auto scvfIdx : connectivityMapI[localIdxJ].scvfsJ)
192 auto&& scvfJ = fvGeometry.scvf(scvfIdx);
193 filler.fill(*
this, fluxVarsCache_[localScvfIdx], elementJ, fvGeometry, elemVolVars, scvfJ,
true);
194 globalScvfIndices_[localScvfIdx] = scvfJ.index();
205 template<
class FVElementGeometry,
class ElementVolumeVariables>
206 void bindScvf(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
207 const FVElementGeometry& fvGeometry,
208 const ElementVolumeVariables& elemVolVars,
209 const typename FVElementGeometry::SubControlVolumeFace& scvf)
211 fluxVarsCache_.resize(1);
212 globalScvfIndices_.resize(1);
215 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
217 filler.fill(*
this, fluxVarsCache_[0], element, fvGeometry, elemVolVars, scvf,
true);
218 globalScvfIndices_[0] = scvf.index();
225 template<
class FVElementGeometry,
class ElementVolumeVariables>
226 void update(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
227 const FVElementGeometry& fvGeometry,
228 const ElementVolumeVariables& elemVolVars)
230 if (FluxVariablesCacheFiller::isSolDependent)
232 const auto& problem = gridFluxVarsCache().problem();
233 const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element);
236 FluxVariablesCacheFiller filler(problem);
239 for (
unsigned int localScvfIdx = 0; localScvfIdx < fluxVarsCache_.size(); ++localScvfIdx)
241 const auto& scvf = fvGeometry.scvf(globalScvfIndices_[localScvfIdx]);
243 const auto scvfInsideScvIdx = scvf.insideScvIdx();
244 const auto& insideElement = scvfInsideScvIdx == globalI ?
246 fvGeometry.gridGeometry().element(scvfInsideScvIdx);
248 filler.fill(*
this, fluxVarsCache_[localScvfIdx], insideElement, fvGeometry, elemVolVars, scvf);
254 template<
class SubControlVolumeFace>
256 {
return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
259 template<
class SubControlVolumeFace>
261 {
return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
265 {
return *gridFluxVarsCachePtr_; }
268 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
271 int getLocalScvfIdx_(
const int scvfIdx)
const
273 auto it = std::find(globalScvfIndices_.begin(), globalScvfIndices_.end(), scvfIdx);
274 assert(it != globalScvfIndices_.end() &&
"Could not find the flux vars cache for scvfIdx");
275 return std::distance(globalScvfIndices_.begin(), it);
278 std::vector<FluxVariablesCache> fluxVarsCache_;
279 std::vector<std::size_t> globalScvfIndices_;
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
The flux variables caches for an element.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:43
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: cellcentered/tpfa/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: cellcentered/tpfa/elementfluxvariablescache.hh:86
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:60
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: cellcentered/tpfa/elementfluxvariablescache.hh:73
CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:62
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:57
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: cellcentered/tpfa/elementfluxvariablescache.hh:79
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:96
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:115
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: cellcentered/tpfa/elementfluxvariablescache.hh:157
CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:120
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: cellcentered/tpfa/elementfluxvariablescache.hh:206
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: cellcentered/tpfa/elementfluxvariablescache.hh:129
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:264
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: cellcentered/tpfa/elementfluxvariablescache.hh:226
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:118