3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
discretization/box/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_BOX_GRID_FLUXVARSCACHE_HH
25#define DUMUX_DISCRETIZATION_BOX_GRID_FLUXVARSCACHE_HH
26
27// make the local view function available whenever we use this class
30
31namespace Dumux {
32
37template<class P, class FVC>
39{
40 using Problem = P;
41 using FluxVariablesCache = FVC;
42
43 template<class GridFluxVariablesCache, bool cachingEnabled>
45};
46
52template<class Problem,
53 class FluxVariablesCache,
54 bool cachingEnabled = false,
57
63template<class P, class FVC, class Traits>
64class BoxGridFluxVariablesCache<P, FVC, true, Traits>
65{
66 using Problem = typename Traits::Problem;
68
69public:
71 using FluxVariablesCache = typename Traits::FluxVariablesCache;
72
74 static constexpr bool cachingEnabled = true;
75
77 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
78
79 BoxGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
80
81 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
82 void update(const GridGeometry& gridGeometry,
83 const GridVolumeVariables& gridVolVars,
84 const SolutionVector& sol,
85 bool forceUpdate = false)
86 {
87 // Here, we do not do anything unless it is a forced update
88 if (forceUpdate)
89 {
90 fluxVarsCache_.resize(gridGeometry.gridView().size(0));
91 auto fvGeometry = localView(gridGeometry);
92 auto elemVolVars = localView(gridVolVars);
93 for (const auto& element : elements(gridGeometry.gridView()))
94 {
95 auto eIdx = gridGeometry.elementMapper().index(element);
96
97 // bind the geometries and volume variables to the element (all the elements in stencil)
98 fvGeometry.bind(element);
99 elemVolVars.bind(element, fvGeometry, sol);
100
101 fluxVarsCache_[eIdx].resize(fvGeometry.numScvf());
102 for (auto&& scvf : scvfs(fvGeometry))
103 cache(eIdx, scvf.index()).update(problem(), element, fvGeometry, elemVolVars, scvf);
104 }
105 }
106 }
107
108 const Problem& problem() const
109 { return *problemPtr_; }
110
111 // access operator
112 const FluxVariablesCache& cache(std::size_t eIdx, std::size_t scvfIdx) const
113 { return fluxVarsCache_[eIdx][scvfIdx]; }
114
115 // access operator
116 FluxVariablesCache& cache(std::size_t eIdx, std::size_t scvfIdx)
117 { return fluxVarsCache_[eIdx][scvfIdx]; }
118
119private:
120 // currently bound element
121 const Problem* problemPtr_;
122 std::vector<std::vector<FluxVariablesCache>> fluxVarsCache_;
123};
124
129template<class P, class FVC, class Traits>
130class BoxGridFluxVariablesCache<P, FVC, false, Traits>
131{
132 using Problem = typename Traits::Problem;
134
135public:
137 using FluxVariablesCache = typename Traits::FluxVariablesCache;
138
140 static constexpr bool cachingEnabled = false;
141
143 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
144
145 BoxGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
146
147 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
148 void update(const GridGeometry& gridGeometry,
149 const GridVolumeVariables& gridVolVars,
150 const SolutionVector& sol,
151 bool forceUpdate = false) {}
152
153 const Problem& problem() const
154 { return *problemPtr_; }
155
156private:
157 const Problem* problemPtr_;
158};
159
160} // end namespace Dumux
161
162#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/box/elementfluxvariablescache.hh:43
Flux variable caches traits.
Definition: discretization/box/gridfluxvariablescache.hh:39
P Problem
Definition: discretization/box/gridfluxvariablescache.hh:40
FVC FluxVariablesCache
Definition: discretization/box/gridfluxvariablescache.hh:41
Flux variable caches on a gridview.
Definition: discretization/box/gridfluxvariablescache.hh:56
Flux variable caches on a gridview with grid caching enabled.
Definition: discretization/box/gridfluxvariablescache.hh:65
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition: discretization/box/gridfluxvariablescache.hh:82
const Problem & problem() const
Definition: discretization/box/gridfluxvariablescache.hh:108
const FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx) const
Definition: discretization/box/gridfluxvariablescache.hh:112
BoxGridFluxVariablesCache(const Problem &problem)
Definition: discretization/box/gridfluxvariablescache.hh:79
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/box/gridfluxvariablescache.hh:71
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/box/gridfluxvariablescache.hh:77
FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx)
Definition: discretization/box/gridfluxvariablescache.hh:116
Flux variable caches on a gridview with grid caching disabled.
Definition: discretization/box/gridfluxvariablescache.hh:131
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/box/gridfluxvariablescache.hh:137
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/box/gridfluxvariablescache.hh:143
const Problem & problem() const
Definition: discretization/box/gridfluxvariablescache.hh:153
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition: discretization/box/gridfluxvariablescache.hh:148
BoxGridFluxVariablesCache(const Problem &problem)
Definition: discretization/box/gridfluxvariablescache.hh:145
Global flux variable cache.