3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_DISCRETIZATION_CCMPFA_GRID_FLUXVARSCACHE_HH
25#define DUMUX_DISCRETIZATION_CCMPFA_GRID_FLUXVARSCACHE_HH
26
27// make the local view function available whenever we use this class
30
31namespace Dumux {
32
37template<class ModelTraits>
39{
40 static constexpr bool enableAdvection = ModelTraits::enableAdvection();
41 static constexpr bool enableMolecularDiffusion = ModelTraits::enableMolecularDiffusion();
42 static constexpr bool enableHeatConduction = ModelTraits::enableEnergyBalance();
43
44 static constexpr int numPhases = ModelTraits::numFluidPhases();
45 static constexpr int numComponents = ModelTraits::numFluidComponents();
46};
47
52template<class P,
53 class FVC, class FVCF,
54 class PIV, class SIV,
55 class PDH, class SDH>
57{
58 using Problem = P;
59 using FluxVariablesCache = FVC;
61
66
67 template<class GridFluxVariablesCache, bool cachingEnabled>
69
70 // Reserve memory (over-) estimate for interaction volumes and corresponding data.
71 // The overestimate doesn't hurt as we are not in a memory-limited configuration.
72 // We need to avoid reallocation because in the caches we store pointers to the data handles.
73 // Default -> each facet has two neighbors (local adaption) and all scvfs belongs to different ivs.
74 // If you want to use higher local differences change the parameter below.
75 static constexpr std::size_t maxLocalElementLevelDifference()
76 { return 2; };
77};
78
84template<class Traits, bool cachingEnabled>
86
92template<class TheTraits>
93class CCMpfaGridFluxVariablesCache<TheTraits, true>
94{
95 using Problem = typename TheTraits::Problem;
97
99 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
100public:
102 using Traits = TheTraits;
103
105 using PrimaryInteractionVolume = typename Traits::PrimaryInteractionVolume;
106 using SecondaryInteractionVolume = typename Traits::SecondaryInteractionVolume;
107
109 using PrimaryIvDataHandle = typename Traits::PrimaryIvDataHandle;
110 using SecondaryIvDataHandle = typename Traits::SecondaryIvDataHandle;
111
113 using FluxVariablesCache = typename Traits::FluxVariablesCache;
114
116 static constexpr bool cachingEnabled = true;
117
119 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
120
122 CCMpfaGridFluxVariablesCache(const Problem& problem)
123 : problemPtr_(&problem)
124 {}
125
127 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
128 void update(const GridGeometry& gridGeometry,
129 const GridVolumeVariables& gridVolVars,
130 const SolutionVector& sol,
131 bool forceUpdate = false)
132 {
133 // Update only if the filler puts solution-dependent
134 // stuff into the caches or if update is enforced
135 if (FluxVariablesCacheFiller::isSolDependent || forceUpdate)
136 {
137 // clear previous data if forced update is desired
138 if (forceUpdate)
139 {
140 clear_();
141
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);
149
150 // reserve memory estimate for caches, interaction volumes and corresponding data
151 fluxVarsCache_.resize(gridGeometry.numScvf());
152 }
153
154 // instantiate helper class to fill the caches
155 FluxVariablesCacheFiller filler(problem());
156
157 // set all the caches to "outdated"
158 for (auto& cache : fluxVarsCache_)
159 cache.setUpdateStatus(false);
160
161 for (const auto& element : elements(gridGeometry.gridView()))
162 {
163 auto fvGeometry = localView(gridGeometry);
164 fvGeometry.bind(element);
165
166 auto elemVolVars = localView(gridVolVars);
167 elemVolVars.bind(element, fvGeometry, sol);
168
169 // Prepare all caches of the scvfs inside the corresponding interaction volume. Skip
170 // those ivs that are touching a boundary, we only store the data on interior ivs here.
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);
174 }
175 }
176 }
177
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)
182 {
183 // Update only if the filler puts
184 // solution-dependent stuff into the caches
185 if (FluxVariablesCacheFiller::isSolDependent)
186 {
187 const auto& gridGeometry = fvGeometry.gridGeometry();
188 const auto& assemblyMapI = gridGeometry.connectivityMap()[gridGeometry.elementMapper().index(element)];
189
190 // helper class to fill flux variables caches
191 FluxVariablesCacheFiller filler(problem());
192
193 // first, set all the caches to "outdated"
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);
199
200 // go through the caches maybe update them
201 for (const auto& scvf : scvfs(fvGeometry))
202 {
203 auto& scvfCache = fluxVarsCache_[scvf.index()];
204 if (!isEmbeddedInBoundaryIV_(scvf, gridGeometry) && !scvfCache.isUpdated())
205 filler.fill(*this, scvfCache, ivDataStorage_, element, fvGeometry, elemVolVars, scvf);
206 }
207
208 for (const auto& dataJ : assemblyMapI)
209 {
210 const auto elementJ = gridGeometry.element(dataJ.globalJ);
211 for (const auto scvfIdx : dataJ.scvfsJ)
212 {
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);
217 }
218 }
219 }
220 }
221
223 template<class SubControlVolumeFace>
224 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
225 { return fluxVarsCache_[scvf.index()]; }
226
228 template<class SubControlVolumeFace>
229 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
230 { return fluxVarsCache_[scvf.index()]; }
231
233 template<class SubControlVolumeFace>
234 const PrimaryInteractionVolume& primaryInteractionVolume(const SubControlVolumeFace& scvf) const
235 { return ivDataStorage_.primaryInteractionVolumes[ (*this)[scvf].ivIndexInContainer() ]; }
236
238 template<class SubControlVolumeFace>
239 const PrimaryIvDataHandle& primaryDataHandle(const SubControlVolumeFace& scvf) const
240 { return ivDataStorage_.primaryDataHandles[ (*this)[scvf].ivIndexInContainer() ]; }
241
243 template<class SubControlVolumeFace>
244 const SecondaryInteractionVolume& secondaryInteractionVolume(const SubControlVolumeFace& scvf) const
245 { return ivDataStorage_.secondaryInteractionVolumes[ (*this)[scvf].ivIndexInContainer() ]; }
246
248 template<class SubControlVolumeFace>
249 const SecondaryIvDataHandle& secondaryDataHandle(const SubControlVolumeFace& scvf) const
250 { return ivDataStorage_.secondaryDataHandles[ (*this)[scvf].ivIndexInContainer() ]; }
251
252 const Problem& problem() const
253 { return *problemPtr_; }
254
255private:
257 template<class SubControlVolumeFace, class GridGeometry>
258 bool isEmbeddedInBoundaryIV_(const SubControlVolumeFace& scvf, const GridGeometry& gridGeometry) const
259 {
260 const auto& gridIvIndexSets = gridGeometry.gridInteractionVolumeIndexSets();
261 if (gridGeometry.vertexUsesSecondaryInteractionVolume(scvf.vertexIndex()))
262 return gridIvIndexSets.secondaryIndexSet(scvf).nodalIndexSet().numBoundaryScvfs() > 0;
263 else
264 return gridIvIndexSets.primaryIndexSet(scvf).nodalIndexSet().numBoundaryScvfs() > 0;
265 }
266
268 void clear_()
269 {
270 fluxVarsCache_.clear();
271 ivDataStorage_.primaryInteractionVolumes.clear();
272 ivDataStorage_.secondaryInteractionVolumes.clear();
273 ivDataStorage_.primaryDataHandles.clear();
274 ivDataStorage_.secondaryDataHandles.clear();
275 }
276
277 const Problem* problemPtr_;
278 std::vector<FluxVariablesCache> fluxVarsCache_;
279
280 // stored interaction volumes and handles
281 using IVDataStorage = InteractionVolumeDataStorage<PrimaryInteractionVolume,
282 PrimaryIvDataHandle,
283 SecondaryInteractionVolume,
284 SecondaryIvDataHandle>;
285 IVDataStorage ivDataStorage_;
286};
287
292template<class TheTraits>
293class CCMpfaGridFluxVariablesCache<TheTraits, false>
294{
295 using Problem = typename TheTraits::Problem;
297
299 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
300public:
302 using Traits = TheTraits;
303
305 using PrimaryInteractionVolume = typename Traits::PrimaryInteractionVolume;
306 using SecondaryInteractionVolume = typename Traits::SecondaryInteractionVolume;
307
309 using PrimaryIvDataHandle = typename Traits::PrimaryIvDataHandle;
310 using SecondaryIvDataHandle = typename Traits::SecondaryIvDataHandle;
311
313 using FluxVariablesCache = typename Traits::FluxVariablesCache;
314
316 static constexpr bool cachingEnabled = false;
317
319 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
320
322 CCMpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
323
325 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
326 void update(const GridGeometry& gridGeometry,
327 const GridVolumeVariables& gridVolVars,
328 const SolutionVector& sol,
329 bool forceUpdate = false) {}
330
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) {}
336
337 const Problem& problem() const
338 { return *problemPtr_; }
339
340private:
341 const Problem* problemPtr_;
342};
343
344} // end namespace Dumux
345
346#endif
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
Definition: adapt.hh:29
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.