version 3.9
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_CCTPFA_GRID_FLUXVARSCACHE_HH
13#define DUMUX_DISCRETIZATION_CCTPFA_GRID_FLUXVARSCACHE_HH
14
16
17// make the local view function available whenever we use this class
20
21namespace Dumux {
22
27template<class P, class FVC, class FVCF>
29{
30 using Problem = P;
31 using FluxVariablesCache = FVC;
33
34 template<class GridFluxVariablesCache, bool cachingEnabled>
36};
37
43template<class Problem,
44 class FluxVariablesCache,
45 class FluxVariablesCacheFiller,
46 bool EnableGridFluxVariablesCache = false,
49
55template<class P, class FVC, class FVCF, class TheTraits>
56class CCTpfaGridFluxVariablesCache<P, FVC, FVCF, true, TheTraits>
57{
58 using Problem = typename TheTraits::Problem;
60
62 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
63public:
65 using Traits = TheTraits;
66
68 using FluxVariablesCache = typename Traits::FluxVariablesCache;
69
71 static constexpr bool cachingEnabled = true;
72
74 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
75
76 // The constructor
77 CCTpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
78
79 // When global caching is enabled, precompute transmissibilities and stencils for all the scv faces
80 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
81 void update(const GridGeometry& gridGeometry,
82 const GridVolumeVariables& gridVolVars,
83 const SolutionVector& sol,
84 bool forceUpdate = false)
85 {
86 // only do the update if fluxes are solution dependent or if update is forced
87 if (FluxVariablesCacheFiller::isSolDependent || forceUpdate)
88 {
89 // instantiate helper class to fill the caches
90 FluxVariablesCacheFiller filler(problem());
91
92 fluxVarsCache_.resize(gridGeometry.numScvf());
93
94 Dumux::parallelFor(gridGeometry.gridView().size(0), [&](const std::size_t eIdx)
95 {
96 // Prepare the geometries within the elements of the stencil
97 const auto element = gridGeometry.element(eIdx);
98 const auto fvGeometry = localView(gridGeometry).bind(element);
99 const auto elemVolVars = localView(gridVolVars).bind(element, fvGeometry, sol);
100
101 for (auto&& scvf : scvfs(fvGeometry))
102 {
103 filler.fill(*this, fluxVarsCache_[scvf.index()], element, fvGeometry, elemVolVars, scvf, forceUpdate);
104 }
105 });
106 }
107 }
108
109 template<class FVElementGeometry, class ElementVolumeVariables>
110 void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
111 const FVElementGeometry& fvGeometry,
112 const ElementVolumeVariables& elemVolVars)
113 {
114 if (FluxVariablesCacheFiller::isSolDependent)
115 {
116 const auto globalI = fvGeometry.gridGeometry().elementMapper().index(element);
117
118 // instantiate filler class
119 FluxVariablesCacheFiller filler(problem());
120
121 // update the caches inside this element
122 for (const auto& scvf : scvfs(fvGeometry))
123 filler.fill(*this, fluxVarsCache_[scvf.index()], element, fvGeometry, elemVolVars, scvf);
124
125 // update the caches in the neighbors
126 for (const auto& dataJ : fvGeometry.gridGeometry().connectivityMap()[globalI])
127 {
128 const auto elementJ = fvGeometry.gridGeometry().element(dataJ.globalJ);
129 for (const auto scvfIdxJ : dataJ.scvfsJ)
130 {
131 const auto& scvfJ = fvGeometry.scvf(scvfIdxJ);
132 filler.fill(*this, fluxVarsCache_[scvfJ.index()], elementJ, fvGeometry, elemVolVars, scvfJ);
133 }
134 }
135 }
136 }
137
138 // access operators in the case of caching
139 template<class SubControlVolumeFace>
140 const FluxVariablesCache& operator [](const SubControlVolumeFace& scvf) const
141 { return fluxVarsCache_[scvf.index()]; }
142
143 template<class SubControlVolumeFace>
144 FluxVariablesCache& operator [](const SubControlVolumeFace& scvf)
145 { return fluxVarsCache_[scvf.index()]; }
146
147 const Problem& problem() const
148 { return *problemPtr_; }
149
150private:
151 const Problem* problemPtr_;
152
153 std::vector<FluxVariablesCache> fluxVarsCache_;
154 std::vector<std::size_t> globalScvfIndices_;
155};
156
161template<class P, class FVC, class FVCF, class TheTraits>
162class CCTpfaGridFluxVariablesCache<P, FVC, FVCF, false, TheTraits>
163{
164 using Problem = typename TheTraits::Problem;
166
168 using FluxVariablesCacheFiller = typename TheTraits::FluxVariablesCacheFiller;
169public:
171 using Traits = TheTraits;
172
174 using FluxVariablesCache = typename Traits::FluxVariablesCache;
175
177 static constexpr bool cachingEnabled = false;
178
180 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
181
182 // The constructor
183 CCTpfaGridFluxVariablesCache(const Problem& problem) : problemPtr_(&problem) {}
184
186 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
187 void update(const GridGeometry& gridGeometry,
188 const GridVolumeVariables& gridVolVars,
189 const SolutionVector& sol,
190 bool forceUpdate = false) {}
191
193 template<class FVElementGeometry, class ElementVolumeVariables>
194 void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
195 const FVElementGeometry& fvGeometry,
196 const ElementVolumeVariables& elemVolVars) {}
197
198 const Problem& problem() const
199 { return *problemPtr_; }
200
201private:
202 const Problem* problemPtr_;
203};
204
205} // end namespace Dumux
206
207#endif
The flux variables caches for an element.
Definition: discretization/cellcentered/tpfa/elementfluxvariablescache.hh:33
Flux variable caches on a gridview with grid caching disabled.
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:163
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:194
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:187
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:174
CCTpfaGridFluxVariablesCache(const Problem &problem)
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:183
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:180
TheTraits Traits
the flux variables cache traits
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:171
const Problem & problem() const
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:198
Flux variable caches on a gridview with grid caching enabled.
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:57
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:81
void updateElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:110
CCTpfaGridFluxVariablesCache(const Problem &problem)
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:77
TheTraits Traits
the flux variables cache traits
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:65
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:74
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:68
const Problem & problem() const
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:147
Flux variable caches on a gridview.
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:48
The flux variables caches for an element.
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.
Definition: adapt.hh:17
Parallel for loop (multithreading)
Flux variable caches traits.
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:29
FVCF FluxVariablesCacheFiller
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:32
P Problem
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:30
FVC FluxVariablesCache
Definition: discretization/cellcentered/tpfa/gridfluxvariablescache.hh:31