3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
cellcentered/tpfa/elementfluxvariablescache.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_ELEMENT_FLUXVARSCACHE_HH
25#define DUMUX_DISCRETIZATION_CCTPFA_ELEMENT_FLUXVARSCACHE_HH
26
27#include <algorithm>
28#include <cassert>
29#include <vector>
30#include <dune/common/exceptions.hh>
31
32namespace Dumux {
33
42template<class GFVC, bool cachingEnabled>
44
49template<class GFVC>
51{
53 using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller;
54
55public:
58
60 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
61
63 : gridFluxVarsCachePtr_(&global) {}
64
66 template<class FVElementGeometry, class ElementVolumeVariables>
67 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
68 const FVElementGeometry& fvGeometry,
69 const ElementVolumeVariables& elemVolVars) {}
70
72 template<class FVElementGeometry, class ElementVolumeVariables>
73 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
74 const FVElementGeometry& fvGeometry,
75 const ElementVolumeVariables& elemVolVars) {}
76
78 template<class FVElementGeometry, class ElementVolumeVariables>
79 void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
80 const FVElementGeometry& fvGeometry,
81 const ElementVolumeVariables& elemVolVars,
82 const typename FVElementGeometry::SubControlVolumeFace& scvf) {}
83
85 template<class FVElementGeometry, class ElementVolumeVariables>
86 void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
87 const FVElementGeometry& fvGeometry,
88 const ElementVolumeVariables& elemVolVars) {}
89
91 template<class SubControlVolumeFace>
92 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
93 { return gridFluxVarsCache()[scvf]; }
94
97 { return *gridFluxVarsCachePtr_; }
98
99private:
100 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
101};
102
107template<class GFVC>
109{
111 using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller;
112
113public:
116
118 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
119
121 : gridFluxVarsCachePtr_(&global) {}
122
128 template<class FVElementGeometry, class ElementVolumeVariables>
129 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
130 const FVElementGeometry& fvGeometry,
131 const ElementVolumeVariables& elemVolVars)
132 {
133 // resizing of the cache
134 const auto numScvf = fvGeometry.numScvf();
135 fluxVarsCache_.resize(numScvf);
136 globalScvfIndices_.resize(numScvf);
137
138 // instantiate helper class to fill the caches
139 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
140
141 std::size_t localScvfIdx = 0;
142 // fill the containers
143 for (auto&& scvf : scvfs(fvGeometry))
144 {
145 filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true);
146 globalScvfIndices_[localScvfIdx] = scvf.index();
147 localScvfIdx++;
148 }
149 }
150
156 template<class FVElementGeometry, class ElementVolumeVariables>
157 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
158 const FVElementGeometry& fvGeometry,
159 const ElementVolumeVariables& elemVolVars)
160 {
161 const auto& problem = gridFluxVarsCache().problem();
162 const auto& gridGeometry = fvGeometry.gridGeometry();
163 const auto globalI = gridGeometry.elementMapper().index(element);
164 const auto& connectivityMapI = gridGeometry.connectivityMap()[globalI];
165 const auto numNeighbors = connectivityMapI.size();
166
167 // instantiate helper class to fill the caches
168 FluxVariablesCacheFiller filler(problem);
169
170 // find the number of scv faces that need to be prepared
171 auto numScvf = fvGeometry.numScvf();
172 for (unsigned int localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ)
173 numScvf += connectivityMapI[localIdxJ].scvfsJ.size();
174
175 // fill the containers with the data on the scv faces inside the actual element
176 fluxVarsCache_.resize(numScvf);
177 globalScvfIndices_.resize(numScvf);
178 unsigned int localScvfIdx = 0;
179 for (auto&& scvf : scvfs(fvGeometry))
180 {
181 filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true);
182 globalScvfIndices_[localScvfIdx] = scvf.index();
183 localScvfIdx++;
184 }
185
186 // add required data on the scv faces in the neighboring elements
187 for (unsigned int localIdxJ = 0; localIdxJ < numNeighbors; ++localIdxJ)
188 {
189 const auto elementJ = gridGeometry.element(connectivityMapI[localIdxJ].globalJ);
190 for (auto scvfIdx : connectivityMapI[localIdxJ].scvfsJ)
191 {
192 auto&& scvfJ = fvGeometry.scvf(scvfIdx);
193 filler.fill(*this, fluxVarsCache_[localScvfIdx], elementJ, fvGeometry, elemVolVars, scvfJ, true);
194 globalScvfIndices_[localScvfIdx] = scvfJ.index();
195 localScvfIdx++;
196 }
197 }
198 }
199
205 template<class FVElementGeometry, class ElementVolumeVariables>
206 void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
207 const FVElementGeometry& fvGeometry,
208 const ElementVolumeVariables& elemVolVars,
209 const typename FVElementGeometry::SubControlVolumeFace& scvf)
210 {
211 fluxVarsCache_.resize(1);
212 globalScvfIndices_.resize(1);
213
214 // instantiate helper class to fill the caches
215 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
216
217 filler.fill(*this, fluxVarsCache_[0], element, fvGeometry, elemVolVars, scvf, true);
218 globalScvfIndices_[0] = scvf.index();
219 }
220
225 template<class FVElementGeometry, class ElementVolumeVariables>
226 void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
227 const FVElementGeometry& fvGeometry,
228 const ElementVolumeVariables& elemVolVars)
229 {
230 if (FluxVariablesCacheFiller::isSolDependent)
231 {
232 const auto& problem = gridFluxVarsCache().problem();
233 const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element);
234
235 // instantiate filler class
236 FluxVariablesCacheFiller filler(problem);
237
238 // let the filler class update the caches
239 for (unsigned int localScvfIdx = 0; localScvfIdx < fluxVarsCache_.size(); ++localScvfIdx)
240 {
241 const auto& scvf = fvGeometry.scvf(globalScvfIndices_[localScvfIdx]);
242
243 const auto scvfInsideScvIdx = scvf.insideScvIdx();
244 const auto& insideElement = scvfInsideScvIdx == globalI ?
245 element :
246 fvGeometry.gridGeometry().element(scvfInsideScvIdx);
247
248 filler.fill(*this, fluxVarsCache_[localScvfIdx], insideElement, fvGeometry, elemVolVars, scvf);
249 }
250 }
251 }
252
254 template<class SubControlVolumeFace>
255 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
256 { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
257
259 template<class SubControlVolumeFace>
260 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
261 { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
262
265 { return *gridFluxVarsCachePtr_; }
266
267private:
268 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
269
271 int getLocalScvfIdx_(const int scvfIdx) const
272 {
273 auto it = std::find(globalScvfIndices_.begin(), globalScvfIndices_.end(), scvfIdx);
274 assert(it != globalScvfIndices_.end() && "Could not find the flux vars cache for scvfIdx");
275 return std::distance(globalScvfIndices_.begin(), it);
276 }
277
278 std::vector<FluxVariablesCache> fluxVarsCache_;
279 std::vector<std::size_t> globalScvfIndices_;
280};
281
282} // end namespace Dumux
283
284#endif
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
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Specialization for the global caching being enabled - do nothing here.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:67
void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Specialization for the global caching being enabled - do nothing here.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:86
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:60
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Specialization for the global caching being enabled - do nothing here.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:73
CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:62
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:57
void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const typename FVElementGeometry::SubControlVolumeFace &scvf)
Specialization for the global caching being enabled - do nothing here.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:79
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:96
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:115
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Prepares the transmissibilities of the scv faces in the stencil of an element.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:157
CCTpfaElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:120
void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const typename FVElementGeometry::SubControlVolumeFace &scvf)
Prepares the transmissibilities of a single scv face.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:206
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Prepares the transmissibilities of the scv faces in an element.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:129
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:264
void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Update the transmissibilities if the volume variables have changed.
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:226
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: cellcentered/tpfa/elementfluxvariablescache.hh:118