3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
staggered/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_STAGGERED_ELEMENT_FLUXVARSCACHE_HH
25#define DUMUX_DISCRETIZATION_STAGGERED_ELEMENT_FLUXVARSCACHE_HH
26
27#include <algorithm>
28#include <cassert>
29#include <iterator>
30#include <vector>
31
32#include <dune/common/exceptions.hh>
33
34namespace Dumux {
35
40template<class GridFluxVariablesCache, bool cachingEnabled>
42
48template<class GFVC>
50{
52 using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller;
53
54public:
57
59 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
60
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 {
90 DUNE_THROW(Dune::InvalidStateException, "In case of enabled caching, the grid flux variables cache must not to be updated");
91 }
92
94 template<class SubControlVolumeFace>
95 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
96 { return (*gridFluxVarsCachePtr_)[scvf.index()]; }
97
100 { return *gridFluxVarsCachePtr_; }
101
102private:
103 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
104};
105
111template<class GFVC>
113{
115 using FluxVariablesCacheFiller = typename GFVC::Traits::FluxVariablesCacheFiller;
116
117public:
120
122 using FluxVariablesCache = typename GFVC::FluxVariablesCache;
123
125 : gridFluxVarsCachePtr_(&global) {}
126
132 template<class FVElementGeometry, class ElementVolumeVariables>
133 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
134 const FVElementGeometry& fvGeometry,
135 const ElementVolumeVariables& elemVolVars)
136 {
137 // resizing of the cache
138 const auto numScvf = fvGeometry.numScvf();
139 fluxVarsCache_.resize(numScvf);
140 globalScvfIndices_.resize(numScvf);
141
142 // instantiate helper class to fill the caches
143 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
144
145 std::size_t localScvfIdx = 0;
146 // fill the containers
147 for (auto&& scvf : scvfs(fvGeometry))
148 {
149 filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true);
150 globalScvfIndices_[localScvfIdx] = scvf.index();
151 localScvfIdx++;
152 }
153 }
154
160 template<class FVElementGeometry, class ElementVolumeVariables>
161 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
162 const FVElementGeometry& fvGeometry,
163 const ElementVolumeVariables& elemVolVars)
164 {
165 // instantiate helper class to fill the caches
166 FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
167
168 // find the number of scv faces that need to be prepared
169 const auto numScvf = fvGeometry.numScvf();
170
171 // fill the containers with the data on the scv faces inside the actual element
172 fluxVarsCache_.resize(numScvf);
173 globalScvfIndices_.resize(numScvf);
174 unsigned int localScvfIdx = 0;
175 for (auto&& scvf : scvfs(fvGeometry))
176 {
177 filler.fill(*this, fluxVarsCache_[localScvfIdx], element, fvGeometry, elemVolVars, scvf, true);
178 globalScvfIndices_[localScvfIdx] = scvf.index();
179 localScvfIdx++;
180 }
181 }
182
188 template<class FVElementGeometry, class ElementVolumeVariables>
189 void bindScvf(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
190 const FVElementGeometry& fvGeometry,
191 const ElementVolumeVariables& elemVolVars,
192 const typename FVElementGeometry::SubControlVolumeFace& scvf)
193 {
194 fluxVarsCache_.resize(1);
195 globalScvfIndices_.resize(1);
196
197 // instantiate helper class to fill the caches
198 // FluxVariablesCacheFiller filler(gridFluxVarsCache().problem());
199 FluxVariablesCacheFiller filler; // TODO: use proper ctor
200
201 filler.fill(*this, fluxVarsCache_[0], element, fvGeometry, elemVolVars, scvf, true);
202 globalScvfIndices_[0] = scvf.index();
203 }
204
209 template<class FVElementGeometry, class ElementVolumeVariables>
210 void update(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
211 const FVElementGeometry& fvGeometry,
212 const ElementVolumeVariables& elemVolVars)
213 {
214 // if (FluxVariablesCacheFiller::isSolDependent) TODO
215 // {
216 // const auto& problem = gridFluxVarsCache().problem();
217 // const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element);
218 //
219 // // instantiate filler class
220 // FluxVariablesCacheFiller filler(problem);
221 //
222 // // let the filler class update the caches
223 // for (unsigned int localScvfIdx = 0; localScvfIdx < fluxVarsCache_.size(); ++localScvfIdx)
224 // {
225 // const auto& scvf = fvGeometry.scvf(globalScvfIndices_[localScvfIdx]);
226 //
227 // const auto scvfInsideScvIdx = scvf.insideScvIdx();
228 // const auto& insideElement = scvfInsideScvIdx == globalI ?
229 // element :
230 // fvGeometry.gridGeometry().element(scvfInsideScvIdx);
231 //
232 // filler.fill(*this, fluxVarsCache_[localScvfIdx], insideElement, fvGeometry, elemVolVars, scvf);
233 // }
234 // }
235 }
236
238 template<class SubControlVolumeFace>
239 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
240 { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
241
242 template<class SubControlVolumeFace>
243 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
244 { return fluxVarsCache_[getLocalScvfIdx_(scvf.index())]; }
245
248 { return *gridFluxVarsCachePtr_; }
249
250private:
251 const GridFluxVariablesCache* gridFluxVarsCachePtr_;
252
253 // get index of scvf in the local container
254 int getLocalScvfIdx_(const int scvfIdx) const
255 {
256 auto it = std::find(globalScvfIndices_.begin(), globalScvfIndices_.end(), scvfIdx);
257 assert(it != globalScvfIndices_.end() && "Could not find the flux vars cache for scvfIdx");
258 return std::distance(globalScvfIndices_.begin(), it);
259 }
260
261 std::vector<FluxVariablesCache> fluxVarsCache_;
262 std::vector<std::size_t> globalScvfIndices_;
263};
264
265} // end namespace Dumux
266
267#endif
Definition: adapt.hh:29
Base class for the stencil local flux variables cache for the staggered model.
Definition: staggered/elementfluxvariablescache.hh:41
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: staggered/elementfluxvariablescache.hh:59
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: staggered/elementfluxvariablescache.hh:73
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: staggered/elementfluxvariablescache.hh:99
StaggeredElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: staggered/elementfluxvariablescache.hh:62
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: staggered/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: staggered/elementfluxvariablescache.hh:86
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: staggered/elementfluxvariablescache.hh:56
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: staggered/elementfluxvariablescache.hh:79
StaggeredElementFluxVariablesCache(const GridFluxVariablesCache &global)
Definition: staggered/elementfluxvariablescache.hh:124
const GridFluxVariablesCache & gridFluxVarsCache() const
The global object we are a restriction of.
Definition: staggered/elementfluxvariablescache.hh:247
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: staggered/elementfluxvariablescache.hh:210
GFVC GridFluxVariablesCache
export the type of the grid flux variables cache
Definition: staggered/elementfluxvariablescache.hh:119
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: staggered/elementfluxvariablescache.hh:133
typename GFVC::FluxVariablesCache FluxVariablesCache
export the type of the flux variables cache
Definition: staggered/elementfluxvariablescache.hh:122
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: staggered/elementfluxvariablescache.hh:161
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: staggered/elementfluxvariablescache.hh:189