3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
discretization/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
28
29// make the local view function available whenever we use this class
32
33namespace Dumux {
34
39template<class P, class FVC, class FVCF>
41{
42 using Problem = P;
43 using FluxVariablesCache = FVC;
45
46 template<class GridFluxVariablesCache, bool cachingEnabled>
48};
49
55template<class Problem,
56 class FluxVariablesCache,
57 class FluxVariablesCacheFiller,
58 bool EnableGridFluxVariablesCache = false,
61
67template<class P, class FVC, class FVCF, class TheTraits>
68class CCTpfaGridFluxVariablesCache<P, FVC, FVCF, true, TheTraits>
69{
70 using Problem = typename TheTraits::Problem;
72
74 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
75public:
77 using Traits = TheTraits;
78
80 using FluxVariablesCache = typename Traits::FluxVariablesCache;
81
83 static constexpr bool cachingEnabled = true;
84
86 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
87
88 // The constructor
89 CCTpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
90
91 // When global caching is enabled, precompute transmissibilities and stencils for all the scv faces
92 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
93 void update(const GridGeometry& gridGeometry,
94 const GridVolumeVariables& gridVolVars,
95 const SolutionVector& sol,
96 bool forceUpdate = false)
97 {
98 // only do the update if fluxes are solution dependent or if update is forced
99 if (FluxVariablesCacheFiller::isSolDependent || forceUpdate)
100 {
101 // instantiate helper class to fill the caches
102 FluxVariablesCacheFiller filler(problem());
103
104 fluxVarsCache_.resize(gridGeometry.numScvf());
105
106 Dumux::parallelFor(gridGeometry.gridView().size(0), [&](const std::size_t eIdx)
107 {
108 // Prepare the geometries within the elements of the stencil
109 const auto element = gridGeometry.element(eIdx);
110 const auto fvGeometry = localView(gridGeometry).bind(element);
111 const auto elemVolVars = localView(gridVolVars).bind(element, fvGeometry, sol);
112
113 for (auto&& scvf : scvfs(fvGeometry))
114 {
115 filler.fill(*this, fluxVarsCache_[scvf.index()], element, fvGeometry, elemVolVars, scvf, forceUpdate);
116 }
117 });
118 }
119 }
120
121 template<class FVElementGeometry, class ElementVolumeVariables>
122 void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
123 const FVElementGeometry& fvGeometry,
124 const ElementVolumeVariables& elemVolVars)
125 {
126 if (FluxVariablesCacheFiller::isSolDependent)
127 {
128 const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element);
129
130 // instantiate filler class
131 FluxVariablesCacheFiller filler(problem());
132
133 // update the caches inside this element
134 for (const auto& scvf : scvfs(fvGeometry))
135 filler.fill(*this, fluxVarsCache_[scvf.index()], element, fvGeometry, elemVolVars, scvf);
136
137 // update the caches in the neighbors
138 for (const auto& dataJ : fvGeometry.gridGeometry().connectivityMap()[globalI])
139 {
140 const auto elementJ = fvGeometry.gridGeometry().element(dataJ.globalJ);
141 for (const auto scvfIdxJ : dataJ.scvfsJ)
142 {
143 const auto& scvfJ = fvGeometry.scvf(scvfIdxJ);
144 filler.fill(*this, fluxVarsCache_[scvfJ.index()], elementJ, fvGeometry, elemVolVars, scvfJ);
145 }
146 }
147 }
148 }
149
150 // access operators in the case of caching
151 template<class SubControlVolumeFace>
152 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
153 { return fluxVarsCache_[scvf.index()]; }
154
155 template<class SubControlVolumeFace>
156 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
157 { return fluxVarsCache_[scvf.index()]; }
158
159 const Problem& problem() const
160 { return *problemPtr_; }
161
162private:
163 const Problem* problemPtr_;
164
165 std::vector<FluxVariablesCache> fluxVarsCache_;
166 std::vector<std::size_t> globalScvfIndices_;
167};
168
173template<class P, class FVC, class FVCF, class TheTraits>
174class CCTpfaGridFluxVariablesCache<P, FVC, FVCF, false, TheTraits>
175{
176 using Problem = typename TheTraits::Problem;
178
180 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
181public:
183 using Traits = TheTraits;
184
186 using FluxVariablesCache = typename Traits::FluxVariablesCache;
187
189 static constexpr bool cachingEnabled = false;
190
192 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
193
194 // The constructor
195 CCTpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
196
198 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
199 void update(const GridGeometry& gridGeometry,
200 const GridVolumeVariables& gridVolVars,
201 const SolutionVector& sol,
202 bool forceUpdate = false) {}
203
205 template<class FVElementGeometry, class ElementVolumeVariables>
206 void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
207 const FVElementGeometry& fvGeometry,
208 const ElementVolumeVariables& elemVolVars) {}
209
210 const Problem& problem() const
211 { return *problemPtr_; }
212
213private:
214 const Problem* problemPtr_;
215};
216
217} // end namespace Dumux
218
219#endif
Parallel for loop (multithreading)
Free function to get the local view of a grid cache object.
void parallelFor(const std::size_t count, const FunctorType &functor)
A parallel for loop (multithreading)
Definition: parallel_for.hh:172
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
The flux variables caches for an element.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:45
Flux variable caches traits.
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:41
FVCF FluxVariablesCacheFiller
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:44
P Problem
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:42
FVC FluxVariablesCache
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:43
Flux variable caches on a gridview.
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:60
Flux variable caches on a gridview with grid caching enabled.
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:69
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:93
void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:122
CCTpfaGridFluxVariablesCache(const Problem &problem)
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:89
TheTraits Traits
the flux variables cache traits
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:77
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:86
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:80
const Problem & problem() const
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:159
Flux variable caches on a gridview with grid caching disabled.
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:175
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/tpfa/gridfluxvariablescache.hh:206
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/tpfa/gridfluxvariablescache.hh:199
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:186
CCTpfaGridFluxVariablesCache(const Problem &problem)
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:195
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:192
TheTraits Traits
the flux variables cache traits
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:183
const Problem & problem() const
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:210
The flux variables caches for an element.