3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
cellcentered/tpfa/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_CCTPFA_GRID_FLUXVARSCACHE_HH
25#define DUMUX_DISCRETIZATION_CCTPFA_GRID_FLUXVARSCACHE_HH
26
30
31namespace Dumux {
32
37template<class P, class FVC, class FVCF>
39{
40 using Problem = P;
41 using FluxVariablesCache = FVC;
43
44 template<class GridFluxVariablesCache, bool cachingEnabled>
46};
47
53template<class Problem,
54 class FluxVariablesCache,
55 class FluxVariablesCacheFiller,
56 bool EnableGridFluxVariablesCache = false,
59
65template<class P, class FVC, class FVCF, class TheTraits>
66class CCTpfaGridFluxVariablesCache<P, FVC, FVCF, true, TheTraits>
67{
68 using Problem = typename TheTraits::Problem;
70
72 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
73public:
75 using Traits = TheTraits;
76
78 using FluxVariablesCache = typename Traits::FluxVariablesCache;
79
81 static constexpr bool cachingEnabled = true;
82
84 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
85
86 // The constructor
87 CCTpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
88
89 // When global caching is enabled, precompute transmissibilities and stencils for all the scv faces
90 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
91 void update(const GridGeometry& gridGeometry,
92 const GridVolumeVariables& gridVolVars,
93 const SolutionVector& sol,
94 bool forceUpdate = false)
95 {
96 // only do the update if fluxes are solution dependent or if update is forced
97 if (FluxVariablesCacheFiller::isSolDependent || forceUpdate)
98 {
99 // instantiate helper class to fill the caches
100 FluxVariablesCacheFiller filler(problem());
101
102 fluxVarsCache_.resize(gridGeometry.numScvf());
103 for (const auto& element : elements(gridGeometry.gridView()))
104 {
105 // Prepare the geometries within the elements of the stencil
106 auto fvGeometry = localView(gridGeometry);
107 fvGeometry.bind(element);
108
109 auto elemVolVars = localView(gridVolVars);
110 elemVolVars.bind(element, fvGeometry, sol);
111
112 for (auto&& scvf : scvfs(fvGeometry))
113 {
114 filler.fill(*this, fluxVarsCache_[scvf.index()], element, fvGeometry, elemVolVars, scvf, forceUpdate);
115 }
116 }
117 }
118 }
119
120 template<class FVElementGeometry, class ElementVolumeVariables>
121 void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
122 const FVElementGeometry& fvGeometry,
123 const ElementVolumeVariables& elemVolVars)
124 {
125 if (FluxVariablesCacheFiller::isSolDependent)
126 {
127 const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element);
128
129 // instantiate filler class
130 FluxVariablesCacheFiller filler(problem());
131
132 // update the caches inside this element
133 for (const auto& scvf : scvfs(fvGeometry))
134 filler.fill(*this, fluxVarsCache_[scvf.index()], element, fvGeometry, elemVolVars, scvf);
135
136 // update the caches in the neighbors
137 for (const auto& dataJ : fvGeometry.gridGeometry().connectivityMap()[globalI])
138 {
139 const auto elementJ = fvGeometry.gridGeometry().element(dataJ.globalJ);
140 for (const auto scvfIdxJ : dataJ.scvfsJ)
141 {
142 const auto& scvfJ = fvGeometry.scvf(scvfIdxJ);
143 filler.fill(*this, fluxVarsCache_[scvfJ.index()], elementJ, fvGeometry, elemVolVars, scvfJ);
144 }
145 }
146 }
147 }
148
149 // access operators in the case of caching
150 template<class SubControlVolumeFace>
151 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
152 { return fluxVarsCache_[scvf.index()]; }
153
154 template<class SubControlVolumeFace>
155 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
156 { return fluxVarsCache_[scvf.index()]; }
157
158 const Problem& problem() const
159 { return *problemPtr_; }
160
161private:
162 const Problem* problemPtr_;
163
164 std::vector<FluxVariablesCache> fluxVarsCache_;
165 std::vector<std::size_t> globalScvfIndices_;
166};
167
172template<class P, class FVC, class FVCF, class TheTraits>
173class CCTpfaGridFluxVariablesCache<P, FVC, FVCF, false, TheTraits>
174{
175 using Problem = typename TheTraits::Problem;
177
179 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
180public:
182 using Traits = TheTraits;
183
185 using FluxVariablesCache = typename Traits::FluxVariablesCache;
186
188 static constexpr bool cachingEnabled = false;
189
191 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
192
193 // The constructor
194 CCTpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
195
197 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
198 void update(const GridGeometry& gridGeometry,
199 const GridVolumeVariables& gridVolVars,
200 const SolutionVector& sol,
201 bool forceUpdate = false) {}
202
204 template<class FVElementGeometry, class ElementVolumeVariables>
205 void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
206 const FVElementGeometry& fvGeometry,
207 const ElementVolumeVariables& elemVolVars) {}
208
209 const Problem& problem() const
210 { return *problemPtr_; }
211
212private:
213 const Problem* problemPtr_;
214};
215
216} // end namespace Dumux
217
218#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
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
The flux variables caches for an element.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:43
Flux variable caches traits.
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:39
FVCF FluxVariablesCacheFiller
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:42
P Problem
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:40
FVC FluxVariablesCache
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:41
Flux variable caches on a gridview.
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:58
Flux variable caches on a gridview with grid caching enabled.
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:67
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:91
void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:121
CCTpfaGridFluxVariablesCache(const Problem &problem)
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:87
TheTraits Traits
the flux variables cache traits
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:75
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:84
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:78
const Problem & problem() const
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:158
Flux variable caches on a gridview with grid caching disabled.
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:174
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/tpfa/gridfluxvariablescache.hh:205
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/tpfa/gridfluxvariablescache.hh:198
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:185
CCTpfaGridFluxVariablesCache(const Problem &problem)
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:194
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:191
TheTraits Traits
the flux variables cache traits
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:182
const Problem & problem() const
Definition: cellcentered/tpfa/gridfluxvariablescache.hh:209
The flux variables caches for an element.