12#ifndef DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH
13#define DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH
20#include <dune/common/exceptions.hh>
32template<
class GFVC,
bool cachingEnabled>
43 using FluxVariablesCacheFiller =
typename GFVC::Traits::FluxVariablesCacheFiller;
53 : gridFluxVarsCachePtr_(&global) {}
60 template<
class FVElementGeometry,
class ElementVolumeVariables>
62 const FVElementGeometry& fvGeometry,
63 const ElementVolumeVariables& elemVolVars) &&
65 this->bindElement(element, fvGeometry, elemVolVars);
66 return std::move(*
this);
70 template<
class FVElementGeometry,
class ElementVolumeVariables>
71 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
72 const FVElementGeometry& fvGeometry,
73 const ElementVolumeVariables& elemVolVars) & {}
80 template<
class FVElementGeometry,
class ElementVolumeVariables>
82 const FVElementGeometry& fvGeometry,
83 const ElementVolumeVariables& elemVolVars) &&
85 this->bind(element, fvGeometry, elemVolVars);
86 return std::move(*
this);
90 template<
class FVElementGeometry,
class ElementVolumeVariables>
91 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
92 const FVElementGeometry& fvGeometry,
93 const ElementVolumeVariables& elemVolVars) & {}
100 template<
class FVElementGeometry,
class ElementVolumeVariables>
102 const FVElementGeometry& fvGeometry,
103 const ElementVolumeVariables& elemVolVars,
104 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
106 this->bindScvf(element, fvGeometry, elemVolVars, scvf);
107 return std::move(*
this);
111 template<
class FVElementGeometry,
class ElementVolumeVariables>
112 void bindScvf(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
113 const FVElementGeometry& fvGeometry,
114 const ElementVolumeVariables& elemVolVars,
115 const typename FVElementGeometry::SubControlVolumeFace& scvf) & {}
118 template<
class FVElementGeometry,
class ElementVolumeVariables>
119 void update(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
120 const FVElementGeometry& fvGeometry,
121 const ElementVolumeVariables& elemVolVars) {}
124 template<
class SubControlVolumeFace>
126 {
return gridFluxVarsCache()[scvf]; }
130 {
return *gridFluxVarsCachePtr_; }
133 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
144 using FluxVariablesCacheFiller =
typename GFVC::Traits::FluxVariablesCacheFiller;
154 : gridFluxVarsCachePtr_(&global) {}
161 template<
class FVElementGeometry,
class ElementVolumeVariables>
163 const FVElementGeometry& fvGeometry,
164 const ElementVolumeVariables& elemVolVars) &&
166 this->bindElement_(element, fvGeometry, elemVolVars);
167 return std::move(*
this);
171 template<
class FVElementGeometry,
class ElementVolumeVariables>
172 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
173 const FVElementGeometry& fvGeometry,
174 const ElementVolumeVariables& elemVolVars) &
175 { this->bindElement_(element, fvGeometry, elemVolVars); }
182 template<
class FVElementGeometry,
class ElementVolumeVariables>
184 const FVElementGeometry& fvGeometry,
185 const ElementVolumeVariables& elemVolVars) &&
187 this->bind_(element, fvGeometry, elemVolVars);
188 return std::move(*
this);
192 template<
class FVElementGeometry,
class ElementVolumeVariables>
193 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
194 const FVElementGeometry& fvGeometry,
195 const ElementVolumeVariables& elemVolVars) &
196 { this->bind_(element, fvGeometry, elemVolVars); }
203 template<
class FVElementGeometry,
class ElementVolumeVariables>
205 const FVElementGeometry& fvGeometry,
206 const ElementVolumeVariables& elemVolVars,
207 const typename FVElementGeometry::SubControlVolumeFace& scvf) &&
209 this->bindScvf_(element, fvGeometry, elemVolVars, scvf);
210 return std::move(*
this);
214 template<
class FVElementGeometry,
class ElementVolumeVariables>
215 void bindScvf(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
216 const FVElementGeometry& fvGeometry,
217 const ElementVolumeVariables& elemVolVars,
218 const typename FVElementGeometry::SubControlVolumeFace& scvf) &
219 { this->bindScvf_(element, fvGeometry, elemVolVars, scvf); }
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_; }
274 template<
class FVElementGeometry,
class ElementVolumeVariables>
275 void bindElement_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
276 const FVElementGeometry& fvGeometry,
277 const ElementVolumeVariables& elemVolVars)
280 const auto numScvf = fvGeometry.numScvf();
281 fluxVarsCache_.resize(numScvf);
282 globalScvfIndices_.resize(numScvf);
285 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
287 std::size_t localScvfIdx = 0;
289 for (
auto&& scvf : scvfs(fvGeometry))
291 filler.fill(*
this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf,
true);
292 globalScvfIndices_[localScvfIdx] = scvf.index();
302 template<
class FVElementGeometry,
class ElementVolumeVariables>
303 void bind_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
304 const FVElementGeometry& fvGeometry,
305 const ElementVolumeVariables& elemVolVars)
307 const auto& problem = gridFluxVarsCache().problem();
308 const auto& gridGeometry = fvGeometry.gridGeometry();
309 const auto globalI = gridGeometry.elementMapper().index(element);
310 const auto& connectivityMapI = gridGeometry.connectivityMap()[globalI];
311 const auto numNeighbors = connectivityMapI.size();
314 FluxVariablesCacheFiller filler(problem);
317 auto numScvf = fvGeometry.numScvf();
318 for (
unsigned int localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ)
319 numScvf += connectivityMapI[localIdxJ].scvfsJ.size();
322 fluxVarsCache_.resize(numScvf);
323 globalScvfIndices_.resize(numScvf);
324 unsigned int localScvfIdx = 0;
325 for (
auto&& scvf : scvfs(fvGeometry))
327 filler.fill(*
this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf,
true);
328 globalScvfIndices_[localScvfIdx] = scvf.index();
333 for (
unsigned int localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ)
335 const auto elementJ = gridGeometry.element(connectivityMapI[localIdxJ].globalJ);
336 for (
auto scvfIdx : connectivityMapI[localIdxJ].scvfsJ)
338 auto&& scvfJ = fvGeometry.scvf(scvfIdx);
339 filler.fill(*
this, fluxVarsCache_[localScvfIdx], elementJ, fvGeometry, elemVolVars, scvfJ,
true);
340 globalScvfIndices_[localScvfIdx] = scvfJ.index();
351 template<
class FVElementGeometry,
class ElementVolumeVariables>
352 void bindScvf_(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
353 const FVElementGeometry& fvGeometry,
354 const ElementVolumeVariables& elemVolVars,
355 const typename FVElementGeometry::SubControlVolumeFace& scvf)
357 fluxVarsCache_.resize(1);
358 globalScvfIndices_.resize(1);
361 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
363 filler.fill(*
this, fluxVarsCache_[0], element, fvGeometry, elemVolVars, scvf,
true);
364 globalScvfIndices_[0] = scvf.index();
367 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
370 int getLocalScvfIdx_(
const int scvfIdx)
const
372 auto it = std::find(globalScvfIndices_.begin(), globalScvfIndices_.end(), scvfIdx);
373 assert(it != globalScvfIndices_.end() &&
"Could not find the flux vars cache for scvfIdx");
377 std::vector<FluxVariablesCache> fluxVarsCache_;
378 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/cellcentered/tpfa/elementfluxvariablescache.hh:193
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:148
CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:153
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:172
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:264
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:204
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:183
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:215
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:226
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:151
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:162
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:101
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:119
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:50
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:81
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:91
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:71
CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:52
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:47
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:129
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:112
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:61
The flux variables caches for an element.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:33
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