12#ifndef DUMUX_DISCRETIZATION_HYBRID_CVFE_GRID_FLUXVARSCACHE_HH
13#define DUMUX_DISCRETIZATION_HYBRID_CVFE_GRID_FLUXVARSCACHE_HH
17#include <unordered_map>
32template<
class P,
class FVC>
38 template<
class Gr
idFluxVariablesCache,
bool cachingEnabled>
47template<
class Problem,
48 class FluxVariablesCache,
49 bool cachingEnabled =
false,
59template<
class P,
class FVC,
class Traits>
62 using Problem =
typename Traits::Problem;
70 static constexpr bool cachingEnabled =
true;
77 template<
class Gr
idGeometry,
class Gr
idVolumeVariables,
class SolutionVector>
78 void update(
const GridGeometry& gridGeometry,
79 const GridVolumeVariables& gridVolVars,
80 const SolutionVector& sol,
81 bool forceUpdate =
false)
86 fluxVarsCache_.resize(gridGeometry.gridView().size(0));
87 scvfOffset_.resize(gridGeometry.gridView().size(0));
88 elementCache_.resize(gridGeometry.gridView().size(0));
89 boundaryIntersectionCache_.resize(gridGeometry.gridView().size(0));
90 Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem()](
const std::size_t eIdx)
93 const auto element = gridGeometry.element(eIdx);
94 const auto fvGeometry =
localView(gridGeometry).bind(element);
95 const auto elemVolVars =
localView(gridVolVars).bind(element, fvGeometry, sol);
98 scvfOffset_[eIdx].resize(fvGeometry.numScvf() + 1, 0);
99 for (
const auto& scvf : scvfs(fvGeometry))
102 scvfOffset_[eIdx][scvf.index() + 1] = numQps;
104 for (std::size_t i = 2; i < scvfOffset_[eIdx].size(); ++i)
105 scvfOffset_[eIdx][i] += scvfOffset_[eIdx][i-1];
107 fluxVarsCache_[eIdx].resize(scvfOffset_[eIdx].back());
108 for (
const auto& scvf : scvfs(fvGeometry))
111 cache(eIdx, qpData.ipData().scvfIndex(), qpData.ipData().qpIndex()).update(problem,
120 elementCache_[eIdx].resize(std::ranges::size(elemQuadRule));
121 for (
const auto& qpData : elemQuadRule)
122 elementCache_[eIdx][qpData.ipData().qpIndex()].update(problem, element, fvGeometry, elemVolVars, qpData.ipData());
125 if (!boundaryIntersectionCache_[eIdx])
126 boundaryIntersectionCache_[eIdx] = std::make_unique<std::unordered_map<int, std::vector<FluxVariablesCache>>>();
128 boundaryIntersectionCache_[eIdx]->clear();
130 for (
const auto& intersection : intersections(gridGeometry.gridView(), element))
132 if (intersection.boundary())
135 const auto iIdx = intersection.indexInInside();
136 (*boundaryIntersectionCache_[eIdx])[iIdx].resize(std::ranges::size(quadRule));
138 for (
const auto& qpData : quadRule)
139 (*boundaryIntersectionCache_[eIdx])[iIdx][qpData.ipData().qpIndex()].update(problem,
150 template<
class FVElementGeometry,
class ElementVolumeVariables>
152 const FVElementGeometry& fvGeometry,
153 const ElementVolumeVariables& elemVolVars)
155 if constexpr (FluxVariablesCache::isSolDependent)
157 const auto eIdx = fvGeometry.gridGeometry().elementMapper().index(element);
160 scvfOffset_[eIdx].resize(fvGeometry.numScvf() + 1, 0);
161 for (
const auto& scvf : scvfs(fvGeometry))
164 scvfOffset_[eIdx][scvf.index() + 1] = numQps;
166 for (std::size_t i = 2; i < scvfOffset_[eIdx].size(); ++i)
167 scvfOffset_[eIdx][i] += scvfOffset_[eIdx][i-1];
169 fluxVarsCache_[eIdx].resize(scvfOffset_[eIdx].back());
170 for (
const auto& scvf : scvfs(fvGeometry))
173 cache(eIdx, qpData.ipData().scvfIndex(), qpData.ipData().qpIndex()).update(problem(),
182 elementCache_[eIdx].resize(std::ranges::size(elemQuadRule));
183 for (
const auto& qpData : elemQuadRule)
184 elementCache_[eIdx][qpData.ipData().qpIndex()].update(problem(), element, fvGeometry, elemVolVars, qpData.ipData());
187 if (!boundaryIntersectionCache_[eIdx])
188 boundaryIntersectionCache_[eIdx] = std::make_unique<std::unordered_map<int, std::vector<FluxVariablesCache>>>();
190 boundaryIntersectionCache_[eIdx]->clear();
192 for (
const auto& intersection : intersections(fvGeometry.gridGeometry().gridView(), element))
194 if (intersection.boundary())
197 const auto iIdx = intersection.indexInInside();
198 (*boundaryIntersectionCache_[eIdx])[iIdx].resize(std::ranges::size(quadRule));
200 for (
const auto& qpData : quadRule)
201 (*boundaryIntersectionCache_[eIdx])[iIdx][qpData.ipData().qpIndex()].update(problem(),
212 {
return *problemPtr_; }
216 {
return fluxVarsCache_[eIdx][scvfOffset_[eIdx][scvfIdx] + qpIdx]; }
220 {
return fluxVarsCache_[eIdx][scvfOffset_[eIdx][scvfIdx] + qpIdx]; }
232 const Problem* problemPtr_;
233 std::vector<std::vector<FluxVariablesCache>> fluxVarsCache_;
234 std::vector<std::vector<std::size_t>> scvfOffset_;
235 std::vector<std::vector<FluxVariablesCache>> elementCache_;
236 std::vector<std::unique_ptr<std::unordered_map<int, std::vector<FluxVariablesCache>>>> boundaryIntersectionCache_;
243template<
class P,
class FVC,
class Traits>
246 using Problem =
typename Traits::Problem;
254 static constexpr bool cachingEnabled =
false;
261 template<
class Gr
idGeometry,
class Gr
idVolumeVariables,
class SolutionVector>
262 void update(
const GridGeometry& gridGeometry,
263 const GridVolumeVariables& gridVolVars,
264 const SolutionVector& sol,
265 bool forceUpdate =
false) {}
268 {
return *problemPtr_; }
271 const Problem* problemPtr_;
The flux variables caches for an element when using hybrid CVFE discretizations.
Definition: discretization/cvfe/hybrid/elementfluxvariablescache.hh:38
Flux variable caches on a gridview with grid caching disabled.
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:245
const Problem & problem() const
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:267
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:262
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:251
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:257
HybridCVFEGridFluxVariablesCache(const Problem &problem)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:259
Flux variable caches on a gridview with grid caching enabled (general quadrature specialization)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:61
const FluxVariablesCache & elementCache(std::size_t eIdx, std::size_t qpIdx) const
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:223
const Problem & problem() const
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:211
FluxVariablesCache & elementCache(std::size_t eIdx, std::size_t qpIdx)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:224
HybridCVFEGridFluxVariablesCache(const Problem &problem)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:75
FluxVariablesCache & boundaryIntersectionCache(std::size_t eIdx, int iIdx, std::size_t qpIdx)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:227
const FluxVariablesCache & boundaryIntersectionCache(std::size_t eIdx, int iIdx, std::size_t qpIdx) const
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:228
FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:219
const FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx) const
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:215
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:73
void updateElement(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:151
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:67
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:78
Flux variable caches implementation on a gridview.
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:51
Global flux variable cache.
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:148
Parallel for loop (multithreading)
Quadrature rules over sub-control volumes and sub-control volume faces.
Flux variable caches traits.
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:34
FVC FluxVariablesCache
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:36
P Problem
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:35