version 3.11-dev
Loading...
Searching...
No Matches
discretization/cvfe/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// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_CVFE_GRID_FLUXVARSCACHE_HH
13#define DUMUX_DISCRETIZATION_CVFE_GRID_FLUXVARSCACHE_HH
14
17
18// make the local view function available whenever we use this class
22
23namespace Dumux {
24
29template<class P, class FVC>
31{
32 using Problem = P;
33 using FluxVariablesCache = FVC;
34
35 template<class GridFluxVariablesCache, bool cachingEnabled>
37};
38
44template<class Problem,
45 class FluxVariablesCache,
46 bool cachingEnabled,
47 class Traits,
48 class ScvfQuadratureRule>
50
55template<class Problem,
56 class FluxVariablesCache,
57 bool cachingEnabled = false,
59using CVFEGridFluxVariablesCache = CVFEGridFluxVariablesCacheImpl<Problem, FluxVariablesCache, cachingEnabled,
61
68template<class P, class FVC, class Traits>
69class CVFEGridFluxVariablesCacheImpl<P, FVC, true, Traits, QuadratureRules::MidpointQuadrature>
70{
71 using Problem = typename Traits::Problem;
73
74public:
76 using FluxVariablesCache = typename Traits::FluxVariablesCache;
77
79 static constexpr bool cachingEnabled = true;
80
82 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
83
84 CVFEGridFluxVariablesCacheImpl(const Problem& problem) : problemPtr_(&problem) {}
85
86 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
87 void update(const GridGeometry& gridGeometry,
88 const GridVolumeVariables& gridVolVars,
89 const SolutionVector& sol,
90 bool forceUpdate = false)
91 {
92 // Here, we do not do anything unless it is a forced update
93 if (forceUpdate)
94 {
95 fluxVarsCache_.resize(gridGeometry.gridView().size(0));
96 Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem()](const std::size_t eIdx)
97 {
98 // Prepare the geometries within the elements of the stencil
99 const auto element = gridGeometry.element(eIdx);
100 const auto fvGeometry = localView(gridGeometry).bind(element);
101 const auto elemVolVars = localView(gridVolVars).bind(element, fvGeometry, sol);
102
103 // only update shape functions for fluxes if update is forced
104 fluxVarsCache_[eIdx].resize(fvGeometry.numScvf());
105 for (const auto& scvf : scvfs(fvGeometry))
106 cache(eIdx, scvf.index()).update(problem, element, fvGeometry, elemVolVars, scvf);
107 });
108 }
109 }
110
111 template<class FVElementGeometry, class ElementVolumeVariables>
112 void updateElement(const typename FVElementGeometry::Element& element,
113 const FVElementGeometry& fvGeometry,
114 const ElementVolumeVariables& elemVolVars)
115 {
116 if constexpr (FluxVariablesCache::isSolDependent)
117 {
118 const auto& gridDiscretization = Deprecated::gridGeometry(fvGeometry);
119 const auto eIdx = gridDiscretization.elementMapper().index(element);
120 fluxVarsCache_[eIdx].resize(fvGeometry.numScvf());
121 for (const auto& scvf : scvfs(fvGeometry))
122 cache(eIdx, scvf.index()).update(problem(), element, fvGeometry, elemVolVars, scvf);
123 }
124 }
125
126 const Problem& problem() const
127 { return *problemPtr_; }
128
129 // access operator
130 const FluxVariablesCache& cache(std::size_t eIdx, std::size_t scvfIdx) const
131 { return fluxVarsCache_[eIdx][scvfIdx]; }
132
133 // access operator
134 FluxVariablesCache& cache(std::size_t eIdx, std::size_t scvfIdx)
135 { return fluxVarsCache_[eIdx][scvfIdx]; }
136
137private:
138 // currently bound element
139 const Problem* problemPtr_;
140 std::vector<std::vector<FluxVariablesCache>> fluxVarsCache_;
141};
142
149template<class P, class FVC, class Traits, class ScvfQR>
150class CVFEGridFluxVariablesCacheImpl<P, FVC, true, Traits, ScvfQR>
151{
152 using Problem = typename Traits::Problem;
154
155public:
157 using FluxVariablesCache = typename Traits::FluxVariablesCache;
158
160 static constexpr bool cachingEnabled = true;
161
163 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
164
165 CVFEGridFluxVariablesCacheImpl(const Problem& problem) : problemPtr_(&problem) {}
166
167 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
168 void update(const GridGeometry& gridGeometry,
169 const GridVolumeVariables& gridVolVars,
170 const SolutionVector& sol,
171 bool forceUpdate = false)
172 {
173 // Here, we do not do anything unless it is a forced update
174 if (forceUpdate)
175 {
176 fluxVarsCache_.resize(gridGeometry.gridView().size(0));
177 qpsOffset_.resize(gridGeometry.gridView().size(0));
178 Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem()](const std::size_t eIdx)
179 {
180 // Prepare the geometries within the elements of the stencil
181 const auto element = gridGeometry.element(eIdx);
182 const auto fvGeometry = localView(gridGeometry).bind(element);
183 const auto elemVolVars = localView(gridVolVars).bind(element, fvGeometry, sol);
184
185 // Compute total number of cache entries and offsets for this element
186 qpsOffset_[eIdx].resize(fvGeometry.numScvf() + 1, 0);
187 for (const auto& scvf : scvfs(fvGeometry))
188 {
189 const auto numQps = std::ranges::size(CVFE::quadratureRule(fvGeometry, scvf));
190 qpsOffset_[eIdx][scvf.index() + 1] = numQps;
191 }
192 for (std::size_t i = 2; i < qpsOffset_[eIdx].size(); ++i)
193 qpsOffset_[eIdx][i] += qpsOffset_[eIdx][i-1];
194
195 // Resize flat cache and update entries
196 fluxVarsCache_[eIdx].resize(qpsOffset_[eIdx].back());
197 for (const auto& scvf : scvfs(fvGeometry))
198 {
199 for (const auto& qpData : CVFE::quadratureRule(fvGeometry, scvf))
200 cache(eIdx, qpData.ipData().scvfIndex(), qpData.ipData().qpIndex()).update(problem,
201 element,
202 fvGeometry,
203 elemVolVars,
204 qpData.ipData());
205 }
206 });
207 }
208 }
209
210 template<class FVElementGeometry, class ElementVolumeVariables>
211 void updateElement(const typename FVElementGeometry::Element& element,
212 const FVElementGeometry& fvGeometry,
213 const ElementVolumeVariables& elemVolVars)
214 {
215 if constexpr (FluxVariablesCache::isSolDependent)
216 {
217 const auto& gridDiscretization = Deprecated::gridGeometry(fvGeometry);
218 const auto eIdx = gridDiscretization.elementMapper().index(element);
219
220 // Compute offsets for this element
221 qpsOffset_[eIdx].resize(fvGeometry.numScvf() + 1, 0);
222 for (const auto& scvf : scvfs(fvGeometry))
223 {
224 const auto numQps = std::ranges::size(CVFE::quadratureRule(fvGeometry, scvf));
225 qpsOffset_[eIdx][scvf.index() + 1] = numQps;
226 }
227 for (std::size_t i = 2; i < qpsOffset_[eIdx].size(); ++i)
228 qpsOffset_[eIdx][i] += qpsOffset_[eIdx][i-1];
229
230 // Resize and update flat cache
231 fluxVarsCache_[eIdx].resize(qpsOffset_[eIdx].back());
232 for (const auto& scvf : scvfs(fvGeometry))
233 {
234 for (const auto& qpData : CVFE::quadratureRule(fvGeometry, scvf))
235 cache(eIdx, qpData.ipData().scvfIndex(), qpData.ipData().qpIndex()).update(problem(),
236 element,
237 fvGeometry,
238 elemVolVars,
239 qpData.ipData());
240 }
241 }
242 }
243
244 const Problem& problem() const
245 { return *problemPtr_; }
246
247 // access operator
248 const FluxVariablesCache& cache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx) const
249 { return fluxVarsCache_[eIdx][qpsOffset_[eIdx][scvfIdx] + qpIdx]; }
250
251 // access operator
252 FluxVariablesCache& cache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx)
253 { return fluxVarsCache_[eIdx][qpsOffset_[eIdx][scvfIdx] + qpIdx]; }
254
255private:
256 // currently bound element
257 const Problem* problemPtr_;
258 std::vector<std::vector<FluxVariablesCache>> fluxVarsCache_;
259 std::vector<std::vector<std::size_t>> qpsOffset_;
260};
261
266template<class P, class FVC, class Traits, class ScvfQR>
267class CVFEGridFluxVariablesCacheImpl<P, FVC, false, Traits, ScvfQR>
268{
269 using Problem = typename Traits::Problem;
271
272public:
274 using FluxVariablesCache = typename Traits::FluxVariablesCache;
275
277 static constexpr bool cachingEnabled = false;
278
280 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
281
282 CVFEGridFluxVariablesCacheImpl(const Problem& problem) : problemPtr_(&problem) {}
283
284 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
285 void update(const GridGeometry& gridGeometry,
286 const GridVolumeVariables& gridVolVars,
287 const SolutionVector& sol,
288 bool forceUpdate = false) {}
289
290 const Problem& problem() const
291 { return *problemPtr_; }
292
293private:
294 const Problem* problemPtr_;
295};
296
297} // end namespace Dumux
298
299#endif
CVFEGridFluxVariablesCacheImpl(const Problem &problem)
Definition discretization/cvfe/gridfluxvariablescache.hh:282
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition discretization/cvfe/gridfluxvariablescache.hh:274
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition discretization/cvfe/gridfluxvariablescache.hh:280
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition discretization/cvfe/gridfluxvariablescache.hh:285
const Problem & problem() const
Definition discretization/cvfe/gridfluxvariablescache.hh:290
static constexpr bool cachingEnabled
make it possible to query if caching is enabled
Definition discretization/cvfe/gridfluxvariablescache.hh:277
CVFEGridFluxVariablesCacheImpl(const Problem &problem)
Definition discretization/cvfe/gridfluxvariablescache.hh:165
static constexpr bool cachingEnabled
make it possible to query if caching is enabled
Definition discretization/cvfe/gridfluxvariablescache.hh:160
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition discretization/cvfe/gridfluxvariablescache.hh:157
FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx)
Definition discretization/cvfe/gridfluxvariablescache.hh:252
const Problem & problem() const
Definition discretization/cvfe/gridfluxvariablescache.hh:244
void updateElement(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Definition discretization/cvfe/gridfluxvariablescache.hh:211
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition discretization/cvfe/gridfluxvariablescache.hh:163
const FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx) const
Definition discretization/cvfe/gridfluxvariablescache.hh:248
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition discretization/cvfe/gridfluxvariablescache.hh:168
const Problem & problem() const
Definition discretization/cvfe/gridfluxvariablescache.hh:126
void updateElement(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Definition discretization/cvfe/gridfluxvariablescache.hh:112
static constexpr bool cachingEnabled
make it possible to query if caching is enabled
Definition discretization/cvfe/gridfluxvariablescache.hh:79
const FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx) const
Definition discretization/cvfe/gridfluxvariablescache.hh:130
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition discretization/cvfe/gridfluxvariablescache.hh:82
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition discretization/cvfe/gridfluxvariablescache.hh:87
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition discretization/cvfe/gridfluxvariablescache.hh:76
CVFEGridFluxVariablesCacheImpl(const Problem &problem)
Definition discretization/cvfe/gridfluxvariablescache.hh:84
FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx)
Definition discretization/cvfe/gridfluxvariablescache.hh:134
Flux variable caches implementation on a gridview.
Definition discretization/cvfe/gridfluxvariablescache.hh:49
Helpers for deprecation.
Global flux variable cache.
CVFEElementFluxVariablesCacheImpl< GFVC, cachingEnabled, Detail::ScvfQuadratureRuleOrDefault_t< typename GFVC::FluxVariablesCache > > CVFEElementFluxVariablesCache
The flux variables caches for an element.
Definition discretization/cvfe/elementfluxvariablescache.hh:56
CVFEGridFluxVariablesCacheImpl< Problem, FluxVariablesCache, cachingEnabled, Traits, Detail::ScvfQuadratureRuleOrDefault_t< typename Traits::FluxVariablesCache > > CVFEGridFluxVariablesCache
Flux variable caches on a gridview.
Definition discretization/cvfe/gridfluxvariablescache.hh:59
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition localview.hh:26
void parallelFor(const std::size_t count, const FunctorType &functor)
A parallel for loop (multithreading).
Definition parallel_for.hh:160
Free function to get the local view of a grid cache object.
auto quadratureRule(const FVElementGeometry &fvGeometry, const typename FVElementGeometry::SubControlVolume &scv, QuadratureRules::MidpointQuadrature)
Midpoint quadrature for scv.
Definition quadraturerules.hh:159
Dune::Std::detected_or_t< QuadratureRules::MidpointQuadrature, DefinesScvfQuadratureRule, FluxVariablesCache > ScvfQuadratureRuleOrDefault_t
Definition discretization/cvfe/elementfluxvariablescache.hh:33
Definition quadraturerules.hh:52
Definition adapt.hh:17
Parallel for loop (multithreading).
Quadrature rules over sub-control volumes and sub-control volume faces.
Flux variable caches traits.
Definition discretization/cvfe/gridfluxvariablescache.hh:31
P Problem
Definition discretization/cvfe/gridfluxvariablescache.hh:32
FVC FluxVariablesCache
Definition discretization/cvfe/gridfluxvariablescache.hh:33
CVFEElementFluxVariablesCache< GridFluxVariablesCache, cachingEnabled > LocalView
Definition discretization/cvfe/gridfluxvariablescache.hh:36