24#ifndef DUMUX_DISCRETIZATION_CCMPFA_GRID_FLUXVARSCACHE_HH
25#define DUMUX_DISCRETIZATION_CCMPFA_GRID_FLUXVARSCACHE_HH
37template<
class ModelTraits>
44 static constexpr int numPhases = ModelTraits::numFluidPhases();
53 class FVC,
class FVCF,
67 template<
class Gr
idFluxVariablesCache,
bool cachingEnabled>
84template<
class Traits,
bool cachingEnabled>
92template<
class TheTraits>
95 using Problem =
typename TheTraits::Problem;
99 using FluxVariablesCacheFiller =
typename TheTraits::FluxVariablesCacheFiller;
116 static constexpr bool cachingEnabled =
true;
123 : problemPtr_(&problem)
127 template<
class Gr
idGeometry,
class Gr
idVolumeVariables,
class SolutionVector>
128 void update(
const GridGeometry& gridGeometry,
129 const GridVolumeVariables& gridVolVars,
130 const SolutionVector& sol,
131 bool forceUpdate =
false)
135 if (FluxVariablesCacheFiller::isSolDependent || forceUpdate)
142 const auto& gridIvIndexSets = gridGeometry.gridInteractionVolumeIndexSets();
143 const auto numPrimaryIvs = gridIvIndexSets.numPrimaryInteractionVolumes();
144 const auto numSecondaryIVs = gridIvIndexSets.numSecondaryInteractionVolumes();
145 ivDataStorage_.primaryInteractionVolumes.reserve(numPrimaryIvs);
146 ivDataStorage_.secondaryInteractionVolumes.reserve(numSecondaryIVs);
147 ivDataStorage_.primaryDataHandles.reserve(numPrimaryIvs);
148 ivDataStorage_.secondaryDataHandles.reserve(numSecondaryIVs);
151 fluxVarsCache_.resize(gridGeometry.numScvf());
155 FluxVariablesCacheFiller filler(problem());
158 for (
auto& cache : fluxVarsCache_)
159 cache.setUpdateStatus(
false);
161 for (
const auto& element : elements(gridGeometry.gridView()))
163 auto fvGeometry =
localView(gridGeometry);
164 fvGeometry.bind(element);
166 auto elemVolVars =
localView(gridVolVars);
167 elemVolVars.bind(element, fvGeometry, sol);
171 for (
const auto& scvf : scvfs(fvGeometry))
172 if (!isEmbeddedInBoundaryIV_(scvf, gridGeometry) && !fluxVarsCache_[scvf.index()].isUpdated())
173 filler.fill(*
this, fluxVarsCache_[scvf.index()], ivDataStorage_, element, fvGeometry, elemVolVars, scvf, forceUpdate);
178 template<
class FVElementGeometry,
class ElementVolumeVariables>
179 void updateElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
180 const FVElementGeometry& fvGeometry,
181 const ElementVolumeVariables& elemVolVars)
185 if (FluxVariablesCacheFiller::isSolDependent)
187 const auto& gridGeometry = fvGeometry.gridGeometry();
188 const auto& assemblyMapI = gridGeometry.connectivityMap()[gridGeometry.elementMapper().index(element)];
191 FluxVariablesCacheFiller filler(problem());
194 for (
const auto& scvf : scvfs(fvGeometry))
195 fluxVarsCache_[scvf.index()].setUpdateStatus(
false);
196 for (
const auto& dataJ : assemblyMapI)
197 for (
const auto scvfIdx : dataJ.scvfsJ)
198 fluxVarsCache_[scvfIdx].setUpdateStatus(
false);
201 for (
const auto& scvf : scvfs(fvGeometry))
203 auto& scvfCache = fluxVarsCache_[scvf.index()];
204 if (!isEmbeddedInBoundaryIV_(scvf, gridGeometry) && !scvfCache.isUpdated())
205 filler.fill(*
this, scvfCache, ivDataStorage_, element, fvGeometry, elemVolVars, scvf);
208 for (
const auto& dataJ : assemblyMapI)
210 const auto elementJ = gridGeometry.element(dataJ.globalJ);
211 for (
const auto scvfIdx : dataJ.scvfsJ)
213 auto& scvfCache = fluxVarsCache_[scvfIdx];
214 const auto& scvf = fvGeometry.scvf(scvfIdx);
215 if (!isEmbeddedInBoundaryIV_(scvf, gridGeometry) && !scvfCache.isUpdated())
216 filler.fill(*
this, scvfCache, ivDataStorage_, elementJ, fvGeometry, elemVolVars, scvf);
223 template<
class SubControlVolumeFace>
225 {
return fluxVarsCache_[scvf.index()]; }
228 template<
class SubControlVolumeFace>
230 {
return fluxVarsCache_[scvf.index()]; }
233 template<
class SubControlVolumeFace>
235 {
return ivDataStorage_.primaryInteractionVolumes[ (*this)[scvf].ivIndexInContainer() ]; }
238 template<
class SubControlVolumeFace>
240 {
return ivDataStorage_.primaryDataHandles[ (*this)[scvf].ivIndexInContainer() ]; }
243 template<
class SubControlVolumeFace>
245 {
return ivDataStorage_.secondaryInteractionVolumes[ (*this)[scvf].ivIndexInContainer() ]; }
248 template<
class SubControlVolumeFace>
250 {
return ivDataStorage_.secondaryDataHandles[ (*this)[scvf].ivIndexInContainer() ]; }
253 {
return *problemPtr_; }
257 template<
class SubControlVolumeFace,
class Gr
idGeometry>
258 bool isEmbeddedInBoundaryIV_(
const SubControlVolumeFace& scvf,
const GridGeometry& gridGeometry)
const
260 const auto& gridIvIndexSets = gridGeometry.gridInteractionVolumeIndexSets();
261 if (gridGeometry.vertexUsesSecondaryInteractionVolume(scvf.vertexIndex()))
262 return gridIvIndexSets.secondaryIndexSet(scvf).nodalIndexSet().numBoundaryScvfs() > 0;
264 return gridIvIndexSets.primaryIndexSet(scvf).nodalIndexSet().numBoundaryScvfs() > 0;
270 fluxVarsCache_.clear();
271 ivDataStorage_.primaryInteractionVolumes.clear();
272 ivDataStorage_.secondaryInteractionVolumes.clear();
273 ivDataStorage_.primaryDataHandles.clear();
274 ivDataStorage_.secondaryDataHandles.clear();
277 const Problem* problemPtr_;
278 std::vector<FluxVariablesCache> fluxVarsCache_;
281 using IVDataStorage = InteractionVolumeDataStorage<PrimaryInteractionVolume,
283 SecondaryInteractionVolume,
284 SecondaryIvDataHandle>;
285 IVDataStorage ivDataStorage_;
292template<
class TheTraits>
295 using Problem =
typename TheTraits::Problem;
299 using FluxVariablesCacheFiller =
typename TheTraits::FluxVariablesCacheFiller;
316 static constexpr bool cachingEnabled =
false;
325 template<
class Gr
idGeometry,
class Gr
idVolumeVariables,
class SolutionVector>
326 void update(
const GridGeometry& gridGeometry,
327 const GridVolumeVariables& gridVolVars,
328 const SolutionVector& sol,
329 bool forceUpdate =
false) {}
332 template<
class FVElementGeometry,
class ElementVolumeVariables>
333 void updateElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
334 const FVElementGeometry& fvGeometry,
335 const ElementVolumeVariables& elemVolVars) {}
338 {
return *problemPtr_; }
341 const Problem* problemPtr_;
Free function to get the local view of a grid cache object.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
The flux variables caches for an element.
Definition: cellcentered/mpfa/elementfluxvariablescache.hh:61
Data handle physics traits.
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:39
static constexpr bool enableHeatConduction
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:42
static constexpr bool enableMolecularDiffusion
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:41
static constexpr int numPhases
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:44
static constexpr bool enableAdvection
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:40
static constexpr int numComponents
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:45
Data handle physics traits.
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:57
FVCF FluxVariablesCacheFiller
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:60
P Problem
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:58
FVC FluxVariablesCache
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:59
SDH SecondaryIvDataHandle
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:65
static constexpr std::size_t maxLocalElementLevelDifference()
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:75
PIV PrimaryInteractionVolume
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:62
PDH PrimaryIvDataHandle
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:64
SIV SecondaryInteractionVolume
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:63
Flux variable caches on a gridview.
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:85
Flux variable caches on a gridview with grid caching enabled.
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:94
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: cellcentered/mpfa/gridfluxvariablescache.hh:128
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:119
typename Traits::PrimaryInteractionVolume PrimaryInteractionVolume
export the interaction volume types
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:105
const Problem & problem() const
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:252
CCMpfaGridFluxVariablesCache(const Problem &problem)
The constructor.
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:122
const SecondaryIvDataHandle & secondaryDataHandle(const SubControlVolumeFace &scvf) const
access to the data handle of an interaction volume an scvf is embedded in
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:249
TheTraits Traits
export the Traits
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:102
typename Traits::PrimaryIvDataHandle PrimaryIvDataHandle
export the data handle types used
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:109
const SecondaryInteractionVolume & secondaryInteractionVolume(const SubControlVolumeFace &scvf) const
access to the interaction volume an scvf is embedded in
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:244
typename Traits::SecondaryInteractionVolume SecondaryInteractionVolume
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:106
const PrimaryIvDataHandle & primaryDataHandle(const SubControlVolumeFace &scvf) const
access to the data handle of an interaction volume an scvf is embedded in
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:239
typename Traits::SecondaryIvDataHandle SecondaryIvDataHandle
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:110
const PrimaryInteractionVolume & primaryInteractionVolume(const SubControlVolumeFace &scvf) const
access to the interaction volume an scvf is embedded in
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:234
void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:179
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:113
Flux variable caches on a gridview with grid caching disabled.
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:294
const Problem & problem() const
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:337
typename Traits::PrimaryInteractionVolume PrimaryInteractionVolume
export the interaction volume types
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:305
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: cellcentered/mpfa/gridfluxvariablescache.hh:333
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:319
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: cellcentered/mpfa/gridfluxvariablescache.hh:326
typename Traits::PrimaryIvDataHandle PrimaryIvDataHandle
export the data handle types used
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:309
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:313
typename Traits::SecondaryInteractionVolume SecondaryInteractionVolume
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:306
TheTraits Traits
export the Traits
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:302
CCMpfaGridFluxVariablesCache(const Problem &problem)
The constructor.
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:322
typename Traits::SecondaryIvDataHandle SecondaryIvDataHandle
Definition: cellcentered/mpfa/gridfluxvariablescache.hh:310
The element-local object of flux variables caches.