version 3.8
discretization/cellcentered/mpfa/gridfluxvariablescache.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_CCMPFA_GRID_FLUXVARSCACHE_HH
13#define DUMUX_DISCRETIZATION_CCMPFA_GRID_FLUXVARSCACHE_HH
14
15// make the local view function available whenever we use this class
18
19namespace Dumux {
20
25template<class ModelTraits>
27{
28 static constexpr bool enableAdvection = ModelTraits::enableAdvection();
29 static constexpr bool enableMolecularDiffusion = ModelTraits::enableMolecularDiffusion();
30 static constexpr bool enableHeatConduction = ModelTraits::enableEnergyBalance();
31
32 static constexpr int numPhases = ModelTraits::numFluidPhases();
33 static constexpr int numComponents = ModelTraits::numFluidComponents();
34};
35
40template<class P,
41 class FVC, class FVCF,
42 class PIV, class SIV,
43 class PDH, class SDH>
45{
46 using Problem = P;
47 using FluxVariablesCache = FVC;
49
54
55 template<class GridFluxVariablesCache, bool cachingEnabled>
57
58 // Reserve memory (over-) estimate for interaction volumes and corresponding data.
59 // The overestimate doesn't hurt as we are not in a memory-limited configuration.
60 // We need to avoid reallocation because in the caches we store pointers to the data handles.
61 // Default -> each facet has two neighbors (local adaption) and all scvfs belongs to different ivs.
62 // If you want to use higher local differences change the parameter below.
63 static constexpr std::size_t maxLocalElementLevelDifference()
64 { return 2; };
65};
66
72template<class Traits, bool cachingEnabled>
74
80template<class TheTraits>
81class CCMpfaGridFluxVariablesCache<TheTraits, true>
82{
83 using Problem = typename TheTraits::Problem;
85
87 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
88public:
90 using Traits = TheTraits;
91
93 using PrimaryInteractionVolume = typename Traits::PrimaryInteractionVolume;
94 using SecondaryInteractionVolume = typename Traits::SecondaryInteractionVolume;
95
97 using PrimaryIvDataHandle = typename Traits::PrimaryIvDataHandle;
98 using SecondaryIvDataHandle = typename Traits::SecondaryIvDataHandle;
99
101 using FluxVariablesCache = typename Traits::FluxVariablesCache;
102
104 static constexpr bool cachingEnabled = true;
105
107 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
108
110 CCMpfaGridFluxVariablesCache(const Problem& problem)
111 : problemPtr_(&problem)
112 {}
113
115 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
116 void update(const GridGeometry& gridGeometry,
117 const GridVolumeVariables& gridVolVars,
118 const SolutionVector& sol,
119 bool forceUpdate = false)
120 {
121 // Update only if the filler puts solution-dependent
122 // stuff into the caches or if update is enforced
123 if (FluxVariablesCacheFiller::isSolDependent || forceUpdate)
124 {
125 // clear previous data if forced update is desired
126 if (forceUpdate)
127 {
128 clear_();
129
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);
137
138 // reserve memory estimate for caches, interaction volumes and corresponding data
139 fluxVarsCache_.resize(gridGeometry.numScvf());
140 }
141
142 // instantiate helper class to fill the caches
143 FluxVariablesCacheFiller filler(problem());
144
145 // set all the caches to "outdated"
146 for (auto& cache : fluxVarsCache_)
147 cache.setUpdateStatus(false);
148
149 auto fvGeometry = localView(gridGeometry);
150 auto elemVolVars = localView(gridVolVars);
151 for (const auto& element : elements(gridGeometry.gridView()))
152 {
153 fvGeometry.bind(element);
154 elemVolVars.bind(element, fvGeometry, sol);
155
156 // Prepare all caches of the scvfs inside the corresponding interaction volume. Skip
157 // those ivs that are touching a boundary, we only store the data on interior ivs here.
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);
161 }
162 }
163 }
164
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)
169 {
170 // Update only if the filler puts
171 // solution-dependent stuff into the caches
172 if (FluxVariablesCacheFiller::isSolDependent)
173 {
174 const auto& gridGeometry = fvGeometry.gridGeometry();
175 const auto& assemblyMapI = gridGeometry.connectivityMap()[gridGeometry.elementMapper().index(element)];
176
177 // helper class to fill flux variables caches
178 FluxVariablesCacheFiller filler(problem());
179
180 // first, set all the caches to "outdated"
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);
186
187 // go through the caches maybe update them
188 for (const auto& scvf : scvfs(fvGeometry))
189 {
190 auto& scvfCache = fluxVarsCache_[scvf.index()];
191 if (!isEmbeddedInBoundaryIV_(scvf, gridGeometry) && !scvfCache.isUpdated())
192 filler.fill(*this, scvfCache, ivDataStorage_, fvGeometry, elemVolVars, scvf);
193 }
194
195 for (const auto& dataJ : assemblyMapI)
196 {
197 for (const auto scvfIdx : dataJ.scvfsJ)
198 {
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);
203 }
204 }
205 }
206 }
207
209 template<class SubControlVolumeFace>
210 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
211 { return fluxVarsCache_[scvf.index()]; }
212
214 template<class SubControlVolumeFace>
215 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
216 { return fluxVarsCache_[scvf.index()]; }
217
219 template<class SubControlVolumeFace>
220 const PrimaryInteractionVolume& primaryInteractionVolume(const SubControlVolumeFace& scvf) const
221 { return ivDataStorage_.primaryInteractionVolumes[ (*this)[scvf].ivIndexInContainer() ]; }
222
224 template<class SubControlVolumeFace>
225 const PrimaryIvDataHandle& primaryDataHandle(const SubControlVolumeFace& scvf) const
226 { return ivDataStorage_.primaryDataHandles[ (*this)[scvf].ivIndexInContainer() ]; }
227
229 template<class SubControlVolumeFace>
230 const SecondaryInteractionVolume& secondaryInteractionVolume(const SubControlVolumeFace& scvf) const
231 { return ivDataStorage_.secondaryInteractionVolumes[ (*this)[scvf].ivIndexInContainer() ]; }
232
234 template<class SubControlVolumeFace>
235 const SecondaryIvDataHandle& secondaryDataHandle(const SubControlVolumeFace& scvf) const
236 { return ivDataStorage_.secondaryDataHandles[ (*this)[scvf].ivIndexInContainer() ]; }
237
238 const Problem& problem() const
239 { return *problemPtr_; }
240
241private:
243 template<class SubControlVolumeFace, class GridGeometry>
244 bool isEmbeddedInBoundaryIV_(const SubControlVolumeFace& scvf, const GridGeometry& gridGeometry) const
245 {
246 const auto& gridIvIndexSets = gridGeometry.gridInteractionVolumeIndexSets();
247 if (gridGeometry.vertexUsesSecondaryInteractionVolume(scvf.vertexIndex()))
248 return gridIvIndexSets.secondaryIndexSet(scvf).nodalIndexSet().numBoundaryScvfs() > 0;
249 else
250 return gridIvIndexSets.primaryIndexSet(scvf).nodalIndexSet().numBoundaryScvfs() > 0;
251 }
252
254 void clear_()
255 {
256 fluxVarsCache_.clear();
257 ivDataStorage_.primaryInteractionVolumes.clear();
258 ivDataStorage_.secondaryInteractionVolumes.clear();
259 ivDataStorage_.primaryDataHandles.clear();
260 ivDataStorage_.secondaryDataHandles.clear();
261 }
262
263 const Problem* problemPtr_;
264 std::vector<FluxVariablesCache> fluxVarsCache_;
265
266 // stored interaction volumes and handles
267 using IVDataStorage = InteractionVolumeDataStorage<PrimaryInteractionVolume,
268 PrimaryIvDataHandle,
269 SecondaryInteractionVolume,
270 SecondaryIvDataHandle>;
271 IVDataStorage ivDataStorage_;
272};
273
278template<class TheTraits>
279class CCMpfaGridFluxVariablesCache<TheTraits, false>
280{
281 using Problem = typename TheTraits::Problem;
283
285 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
286public:
288 using Traits = TheTraits;
289
291 using PrimaryInteractionVolume = typename Traits::PrimaryInteractionVolume;
292 using SecondaryInteractionVolume = typename Traits::SecondaryInteractionVolume;
293
295 using PrimaryIvDataHandle = typename Traits::PrimaryIvDataHandle;
296 using SecondaryIvDataHandle = typename Traits::SecondaryIvDataHandle;
297
299 using FluxVariablesCache = typename Traits::FluxVariablesCache;
300
302 static constexpr bool cachingEnabled = false;
303
305 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
306
308 CCMpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
309
311 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
312 void update(const GridGeometry& gridGeometry,
313 const GridVolumeVariables& gridVolVars,
314 const SolutionVector& sol,
315 bool forceUpdate = false) {}
316
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) {}
322
323 const Problem& problem() const
324 { return *problemPtr_; }
325
326private:
327 const Problem* problemPtr_;
328};
329
330} // end namespace Dumux
331
332#endif
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.
Definition: adapt.hh:17
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