12#ifndef DUMUX_DISCRETIZATION_CCMPFA_GRID_FLUXVARSCACHE_HH
13#define DUMUX_DISCRETIZATION_CCMPFA_GRID_FLUXVARSCACHE_HH
25template<
class ModelTraits>
32 static constexpr int numPhases = ModelTraits::numFluidPhases();
41 class FVC,
class FVCF,
55 template<
class Gr
idFluxVariablesCache,
bool cachingEnabled>
72template<
class Traits,
bool cachingEnabled>
80template<
class TheTraits>
83 using Problem =
typename TheTraits::Problem;
87 using FluxVariablesCacheFiller =
typename TheTraits::FluxVariablesCacheFiller;
104 static constexpr bool cachingEnabled =
true;
111 : problemPtr_(&problem)
115 template<
class Gr
idGeometry,
class Gr
idVolumeVariables,
class SolutionVector>
116 void update(
const GridGeometry& gridGeometry,
117 const GridVolumeVariables& gridVolVars,
118 const SolutionVector& sol,
119 bool forceUpdate =
false)
123 if (FluxVariablesCacheFiller::isSolDependent || forceUpdate)
130 const auto& gridIvIndexSets = gridGeometry.gridInteractionVolumeIndexSets();
131 const auto numPrimaryIvs = gridIvIndexSets.numPrimaryInteractionVolumes();
132 const auto numSecondaryIVs = gridIvIndexSets.numSecondaryInteractionVolumes();
133 ivDataStorage_.primaryInteractionVolumes.reserve(numPrimaryIvs);
134 ivDataStorage_.secondaryInteractionVolumes.reserve(numSecondaryIVs);
135 ivDataStorage_.primaryDataHandles.reserve(numPrimaryIvs);
136 ivDataStorage_.secondaryDataHandles.reserve(numSecondaryIVs);
139 fluxVarsCache_.resize(gridGeometry.numScvf());
143 FluxVariablesCacheFiller filler(problem());
146 for (
auto& cache : fluxVarsCache_)
147 cache.setUpdateStatus(
false);
149 auto fvGeometry =
localView(gridGeometry);
150 auto elemVolVars =
localView(gridVolVars);
151 for (
const auto& element : elements(gridGeometry.gridView()))
153 fvGeometry.bind(element);
154 elemVolVars.bind(element, fvGeometry, sol);
158 for (
const auto& scvf : scvfs(fvGeometry))
159 if (!isEmbeddedInBoundaryIV_(scvf, gridGeometry) && !fluxVarsCache_[scvf.index()].isUpdated())
160 filler.fill(*
this, fluxVarsCache_[scvf.index()], ivDataStorage_, fvGeometry, elemVolVars, scvf, forceUpdate);
165 template<
class FVElementGeometry,
class ElementVolumeVariables>
166 void updateElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
167 const FVElementGeometry& fvGeometry,
168 const ElementVolumeVariables& elemVolVars)
172 if (FluxVariablesCacheFiller::isSolDependent)
174 const auto& gridGeometry = fvGeometry.gridGeometry();
175 const auto& assemblyMapI = gridGeometry.connectivityMap()[gridGeometry.elementMapper().index(element)];
178 FluxVariablesCacheFiller filler(problem());
181 for (
const auto& scvf : scvfs(fvGeometry))
182 fluxVarsCache_[scvf.index()].setUpdateStatus(
false);
183 for (
const auto& dataJ : assemblyMapI)
184 for (
const auto scvfIdx : dataJ.scvfsJ)
185 fluxVarsCache_[scvfIdx].setUpdateStatus(
false);
188 for (
const auto& scvf : scvfs(fvGeometry))
190 auto& scvfCache = fluxVarsCache_[scvf.index()];
191 if (!isEmbeddedInBoundaryIV_(scvf, gridGeometry) && !scvfCache.isUpdated())
192 filler.fill(*
this, scvfCache, ivDataStorage_, fvGeometry, elemVolVars, scvf);
195 for (
const auto& dataJ : assemblyMapI)
197 for (
const auto scvfIdx : dataJ.scvfsJ)
199 auto& scvfCache = fluxVarsCache_[scvfIdx];
200 const auto& scvf = fvGeometry.scvf(scvfIdx);
201 if (!isEmbeddedInBoundaryIV_(scvf, gridGeometry) && !scvfCache.isUpdated())
202 filler.fill(*
this, scvfCache, ivDataStorage_, fvGeometry, elemVolVars, scvf);
209 template<
class SubControlVolumeFace>
211 {
return fluxVarsCache_[scvf.index()]; }
214 template<
class SubControlVolumeFace>
216 {
return fluxVarsCache_[scvf.index()]; }
219 template<
class SubControlVolumeFace>
221 {
return ivDataStorage_.primaryInteractionVolumes[ (*this)[scvf].ivIndexInContainer() ]; }
224 template<
class SubControlVolumeFace>
226 {
return ivDataStorage_.primaryDataHandles[ (*this)[scvf].ivIndexInContainer() ]; }
229 template<
class SubControlVolumeFace>
231 {
return ivDataStorage_.secondaryInteractionVolumes[ (*this)[scvf].ivIndexInContainer() ]; }
234 template<
class SubControlVolumeFace>
236 {
return ivDataStorage_.secondaryDataHandles[ (*this)[scvf].ivIndexInContainer() ]; }
239 {
return *problemPtr_; }
243 template<
class SubControlVolumeFace,
class Gr
idGeometry>
244 bool isEmbeddedInBoundaryIV_(
const SubControlVolumeFace& scvf,
const GridGeometry& gridGeometry)
const
246 const auto& gridIvIndexSets = gridGeometry.gridInteractionVolumeIndexSets();
247 if (gridGeometry.vertexUsesSecondaryInteractionVolume(scvf.vertexIndex()))
248 return gridIvIndexSets.secondaryIndexSet(scvf).nodalIndexSet().numBoundaryScvfs() > 0;
250 return gridIvIndexSets.primaryIndexSet(scvf).nodalIndexSet().numBoundaryScvfs() > 0;
256 fluxVarsCache_.clear();
257 ivDataStorage_.primaryInteractionVolumes.clear();
258 ivDataStorage_.secondaryInteractionVolumes.clear();
259 ivDataStorage_.primaryDataHandles.clear();
260 ivDataStorage_.secondaryDataHandles.clear();
263 const Problem* problemPtr_;
264 std::vector<FluxVariablesCache> fluxVarsCache_;
267 using IVDataStorage = InteractionVolumeDataStorage<PrimaryInteractionVolume,
269 SecondaryInteractionVolume,
270 SecondaryIvDataHandle>;
271 IVDataStorage ivDataStorage_;
278template<
class TheTraits>
281 using Problem =
typename TheTraits::Problem;
285 using FluxVariablesCacheFiller =
typename TheTraits::FluxVariablesCacheFiller;
302 static constexpr bool cachingEnabled =
false;
311 template<
class Gr
idGeometry,
class Gr
idVolumeVariables,
class SolutionVector>
312 void update(
const GridGeometry& gridGeometry,
313 const GridVolumeVariables& gridVolVars,
314 const SolutionVector& sol,
315 bool forceUpdate =
false) {}
318 template<
class FVElementGeometry,
class ElementVolumeVariables>
319 void updateElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
320 const FVElementGeometry& fvGeometry,
321 const ElementVolumeVariables& elemVolVars) {}
324 {
return *problemPtr_; }
327 const Problem* problemPtr_;
The flux variables caches for an element.
Definition: discretization/cellcentered/mpfa/elementfluxvariablescache.hh:50
Flux variable caches on a gridview with grid caching disabled.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:280
const Problem & problem() const
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:323
typename Traits::PrimaryInteractionVolume PrimaryInteractionVolume
export the interaction volume types
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:291
void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
When global flux variables caching is disabled, we don't need to update the cache.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:319
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:305
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
When global flux variables caching is disabled, we don't need to update the cache.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:312
typename Traits::PrimaryIvDataHandle PrimaryIvDataHandle
export the data handle types used
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:295
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:299
typename Traits::SecondaryInteractionVolume SecondaryInteractionVolume
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:292
TheTraits Traits
export the Traits
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:288
CCMpfaGridFluxVariablesCache(const Problem &problem)
The constructor.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:308
typename Traits::SecondaryIvDataHandle SecondaryIvDataHandle
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:296
Flux variable caches on a gridview with grid caching enabled.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:82
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
When global caching is enabled, precompute transmissibilities for all scv faces.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:116
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:107
typename Traits::PrimaryInteractionVolume PrimaryInteractionVolume
export the interaction volume types
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:93
const Problem & problem() const
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:238
CCMpfaGridFluxVariablesCache(const Problem &problem)
The constructor.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:110
const SecondaryIvDataHandle & secondaryDataHandle(const SubControlVolumeFace &scvf) const
access to the data handle of an interaction volume an scvf is embedded in
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:235
TheTraits Traits
export the Traits
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:90
typename Traits::PrimaryIvDataHandle PrimaryIvDataHandle
export the data handle types used
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:97
const SecondaryInteractionVolume & secondaryInteractionVolume(const SubControlVolumeFace &scvf) const
access to the interaction volume an scvf is embedded in
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:230
typename Traits::SecondaryInteractionVolume SecondaryInteractionVolume
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:94
const PrimaryIvDataHandle & primaryDataHandle(const SubControlVolumeFace &scvf) const
access to the data handle of an interaction volume an scvf is embedded in
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:225
typename Traits::SecondaryIvDataHandle SecondaryIvDataHandle
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:98
const PrimaryInteractionVolume & primaryInteractionVolume(const SubControlVolumeFace &scvf) const
access to the interaction volume an scvf is embedded in
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:220
void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:166
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:101
Flux variable caches on a gridview.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:73
The element-local object of flux variables caches.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
Free function to get the local view of a grid cache object.
Data handle physics traits.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:45
FVCF FluxVariablesCacheFiller
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:48
P Problem
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:46
FVC FluxVariablesCache
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:47
SDH SecondaryIvDataHandle
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:53
static constexpr std::size_t maxLocalElementLevelDifference()
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:63
PIV PrimaryInteractionVolume
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:50
PDH PrimaryIvDataHandle
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:52
SIV SecondaryInteractionVolume
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:51
Data handle physics traits.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:27
static constexpr bool enableHeatConduction
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:30
static constexpr bool enableMolecularDiffusion
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:29
static constexpr int numPhases
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:32
static constexpr bool enableAdvection
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:28
static constexpr int numComponents
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:33