3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * 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 auto fvGeometry = localView(gridGeometry);
162 auto elemVolVars = localView(gridVolVars);
163 for (const auto& element : elements(gridGeometry.gridView()))
164 {
165 fvGeometry.bind(element);
166 elemVolVars.bind(element, fvGeometry, sol);
167
168 // Prepare all caches of the scvfs inside the corresponding interaction volume. Skip
169 // those ivs that are touching a boundary, we only store the data on interior ivs here.
170 for (const auto& scvf : scvfs(fvGeometry))
171 if (!isEmbeddedInBoundaryIV_(scvf, gridGeometry) && !fluxVarsCache_[scvf.index()].isUpdated())
172 filler.fill(*this, fluxVarsCache_[scvf.index()], ivDataStorage_, fvGeometry, elemVolVars, scvf, forceUpdate);
173 }
174 }
175 }
176
177 template<class FVElementGeometry, class ElementVolumeVariables>
178 void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
179 const FVElementGeometry& fvGeometry,
180 const ElementVolumeVariables& elemVolVars)
181 {
182 // Update only if the filler puts
183 // solution-dependent stuff into the caches
184 if (FluxVariablesCacheFiller::isSolDependent)
185 {
186 const auto& gridGeometry = fvGeometry.gridGeometry();
187 const auto& assemblyMapI = gridGeometry.connectivityMap()[gridGeometry.elementMapper().index(element)];
188
189 // helper class to fill flux variables caches
190 FluxVariablesCacheFiller filler(problem());
191
192 // first, set all the caches to "outdated"
193 for (const auto& scvf : scvfs(fvGeometry))
194 fluxVarsCache_[scvf.index()].setUpdateStatus(false);
195 for (const auto& dataJ : assemblyMapI)
196 for (const auto scvfIdx : dataJ.scvfsJ)
197 fluxVarsCache_[scvfIdx].setUpdateStatus(false);
198
199 // go through the caches maybe update them
200 for (const auto& scvf : scvfs(fvGeometry))
201 {
202 auto& scvfCache = fluxVarsCache_[scvf.index()];
203 if (!isEmbeddedInBoundaryIV_(scvf, gridGeometry) && !scvfCache.isUpdated())
204 filler.fill(*this, scvfCache, ivDataStorage_, fvGeometry, elemVolVars, scvf);
205 }
206
207 for (const auto& dataJ : assemblyMapI)
208 {
209 for (const auto scvfIdx : dataJ.scvfsJ)
210 {
211 auto& scvfCache = fluxVarsCache_[scvfIdx];
212 const auto& scvf = fvGeometry.scvf(scvfIdx);
213 if (!isEmbeddedInBoundaryIV_(scvf, gridGeometry) && !scvfCache.isUpdated())
214 filler.fill(*this, scvfCache, ivDataStorage_, fvGeometry, elemVolVars, scvf);
215 }
216 }
217 }
218 }
219
221 template<class SubControlVolumeFace>
222 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
223 { return fluxVarsCache_[scvf.index()]; }
224
226 template<class SubControlVolumeFace>
227 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
228 { return fluxVarsCache_[scvf.index()]; }
229
231 template<class SubControlVolumeFace>
232 const PrimaryInteractionVolume& primaryInteractionVolume(const SubControlVolumeFace& scvf) const
233 { return ivDataStorage_.primaryInteractionVolumes[ (*this)[scvf].ivIndexInContainer() ]; }
234
236 template<class SubControlVolumeFace>
237 const PrimaryIvDataHandle& primaryDataHandle(const SubControlVolumeFace& scvf) const
238 { return ivDataStorage_.primaryDataHandles[ (*this)[scvf].ivIndexInContainer() ]; }
239
241 template<class SubControlVolumeFace>
242 const SecondaryInteractionVolume& secondaryInteractionVolume(const SubControlVolumeFace& scvf) const
243 { return ivDataStorage_.secondaryInteractionVolumes[ (*this)[scvf].ivIndexInContainer() ]; }
244
246 template<class SubControlVolumeFace>
247 const SecondaryIvDataHandle& secondaryDataHandle(const SubControlVolumeFace& scvf) const
248 { return ivDataStorage_.secondaryDataHandles[ (*this)[scvf].ivIndexInContainer() ]; }
249
250 const Problem& problem() const
251 { return *problemPtr_; }
252
253private:
255 template<class SubControlVolumeFace, class GridGeometry>
256 bool isEmbeddedInBoundaryIV_(const SubControlVolumeFace& scvf, const GridGeometry& gridGeometry) const
257 {
258 const auto& gridIvIndexSets = gridGeometry.gridInteractionVolumeIndexSets();
259 if (gridGeometry.vertexUsesSecondaryInteractionVolume(scvf.vertexIndex()))
260 return gridIvIndexSets.secondaryIndexSet(scvf).nodalIndexSet().numBoundaryScvfs() > 0;
261 else
262 return gridIvIndexSets.primaryIndexSet(scvf).nodalIndexSet().numBoundaryScvfs() > 0;
263 }
264
266 void clear_()
267 {
268 fluxVarsCache_.clear();
269 ivDataStorage_.primaryInteractionVolumes.clear();
270 ivDataStorage_.secondaryInteractionVolumes.clear();
271 ivDataStorage_.primaryDataHandles.clear();
272 ivDataStorage_.secondaryDataHandles.clear();
273 }
274
275 const Problem* problemPtr_;
276 std::vector<FluxVariablesCache> fluxVarsCache_;
277
278 // stored interaction volumes and handles
279 using IVDataStorage = InteractionVolumeDataStorage<PrimaryInteractionVolume,
280 PrimaryIvDataHandle,
281 SecondaryInteractionVolume,
282 SecondaryIvDataHandle>;
283 IVDataStorage ivDataStorage_;
284};
285
290template<class TheTraits>
291class CCMpfaGridFluxVariablesCache<TheTraits, false>
292{
293 using Problem = typename TheTraits::Problem;
295
297 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
298public:
300 using Traits = TheTraits;
301
303 using PrimaryInteractionVolume = typename Traits::PrimaryInteractionVolume;
304 using SecondaryInteractionVolume = typename Traits::SecondaryInteractionVolume;
305
307 using PrimaryIvDataHandle = typename Traits::PrimaryIvDataHandle;
308 using SecondaryIvDataHandle = typename Traits::SecondaryIvDataHandle;
309
311 using FluxVariablesCache = typename Traits::FluxVariablesCache;
312
314 static constexpr bool cachingEnabled = false;
315
317 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
318
320 CCMpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
321
323 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
324 void update(const GridGeometry& gridGeometry,
325 const GridVolumeVariables& gridVolVars,
326 const SolutionVector& sol,
327 bool forceUpdate = false) {}
328
330 template<class FVElementGeometry, class ElementVolumeVariables>
331 void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
332 const FVElementGeometry& fvGeometry,
333 const ElementVolumeVariables& elemVolVars) {}
334
335 const Problem& problem() const
336 { return *problemPtr_; }
337
338private:
339 const Problem* problemPtr_;
340};
341
342} // end namespace Dumux
343
344#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: discretization/cellcentered/mpfa/elementfluxvariablescache.hh:62
Data handle physics traits.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:39
static constexpr bool enableHeatConduction
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:42
static constexpr bool enableMolecularDiffusion
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:41
static constexpr int numPhases
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:44
static constexpr bool enableAdvection
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:40
static constexpr int numComponents
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:45
Data handle physics traits.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:57
FVCF FluxVariablesCacheFiller
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:60
P Problem
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:58
FVC FluxVariablesCache
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:59
SDH SecondaryIvDataHandle
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:65
static constexpr std::size_t maxLocalElementLevelDifference()
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:75
PIV PrimaryInteractionVolume
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:62
PDH PrimaryIvDataHandle
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:64
SIV SecondaryInteractionVolume
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:63
Flux variable caches on a gridview.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:85
Flux variable caches on a gridview with grid caching enabled.
Definition: discretization/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: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:128
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:119
typename Traits::PrimaryInteractionVolume PrimaryInteractionVolume
export the interaction volume types
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:105
const Problem & problem() const
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:250
CCMpfaGridFluxVariablesCache(const Problem &problem)
The constructor.
Definition: discretization/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: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:247
TheTraits Traits
export the Traits
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:102
typename Traits::PrimaryIvDataHandle PrimaryIvDataHandle
export the data handle types used
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:109
const SecondaryInteractionVolume & secondaryInteractionVolume(const SubControlVolumeFace &scvf) const
access to the interaction volume an scvf is embedded in
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:242
typename Traits::SecondaryInteractionVolume SecondaryInteractionVolume
Definition: discretization/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: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:237
typename Traits::SecondaryIvDataHandle SecondaryIvDataHandle
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:110
const PrimaryInteractionVolume & primaryInteractionVolume(const SubControlVolumeFace &scvf) const
access to the interaction volume an scvf is embedded in
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:232
void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:178
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:113
Flux variable caches on a gridview with grid caching disabled.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:292
const Problem & problem() const
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:335
typename Traits::PrimaryInteractionVolume PrimaryInteractionVolume
export the interaction volume types
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:303
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:331
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:317
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:324
typename Traits::PrimaryIvDataHandle PrimaryIvDataHandle
export the data handle types used
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:307
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:311
typename Traits::SecondaryInteractionVolume SecondaryInteractionVolume
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:304
TheTraits Traits
export the Traits
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:300
CCMpfaGridFluxVariablesCache(const Problem &problem)
The constructor.
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:320
typename Traits::SecondaryIvDataHandle SecondaryIvDataHandle
Definition: discretization/cellcentered/mpfa/gridfluxvariablescache.hh:308
The element-local object of flux variables caches.