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 boundaryFaceCache_.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 (!boundaryFaceCache_[eIdx])
126 boundaryFaceCache_[eIdx] = std::make_unique<std::unordered_map<int, std::vector<FluxVariablesCache>>>();
128 boundaryFaceCache_[eIdx]->clear();
130 for (
const auto& boundaryFace : boundaryFaces(fvGeometry))
133 const auto bfIdx = boundaryFace.index();
134 (*boundaryFaceCache_[eIdx])[bfIdx].resize(std::ranges::size(quadRule));
136 for (
const auto& qpData : quadRule)
137 (*boundaryFaceCache_[eIdx])[bfIdx][qpData.ipData().qpIndex()].update(problem,
147 template<
class FVElementGeometry,
class ElementVolumeVariables>
149 const FVElementGeometry& fvGeometry,
150 const ElementVolumeVariables& elemVolVars)
152 if constexpr (FluxVariablesCache::isSolDependent)
154 const auto eIdx = fvGeometry.gridGeometry().elementMapper().index(element);
157 scvfOffset_[eIdx].resize(fvGeometry.numScvf() + 1, 0);
158 for (
const auto& scvf : scvfs(fvGeometry))
161 scvfOffset_[eIdx][scvf.index() + 1] = numQps;
163 for (std::size_t i = 2; i < scvfOffset_[eIdx].size(); ++i)
164 scvfOffset_[eIdx][i] += scvfOffset_[eIdx][i-1];
166 fluxVarsCache_[eIdx].resize(scvfOffset_[eIdx].back());
167 for (
const auto& scvf : scvfs(fvGeometry))
170 cache(eIdx, qpData.ipData().scvfIndex(), qpData.ipData().qpIndex()).update(problem(),
179 elementCache_[eIdx].resize(std::ranges::size(elemQuadRule));
180 for (
const auto& qpData : elemQuadRule)
181 elementCache_[eIdx][qpData.ipData().qpIndex()].update(problem(), element, fvGeometry, elemVolVars, qpData.ipData());
184 if (!boundaryFaceCache_[eIdx])
185 boundaryFaceCache_[eIdx] = std::make_unique<std::unordered_map<int, std::vector<FluxVariablesCache>>>();
187 boundaryFaceCache_[eIdx]->clear();
189 for (
const auto& boundaryFace : boundaryFaces(fvGeometry))
192 const auto bfIdx = boundaryFace.index();
193 (*boundaryFaceCache_[eIdx])[bfIdx].resize(std::ranges::size(quadRule));
195 for (
const auto& qpData : quadRule)
196 (*boundaryFaceCache_[eIdx])[bfIdx][qpData.ipData().qpIndex()].update(problem(),
206 {
return *problemPtr_; }
210 {
return fluxVarsCache_[eIdx][scvfOffset_[eIdx][scvfIdx] + qpIdx]; }
214 {
return fluxVarsCache_[eIdx][scvfOffset_[eIdx][scvfIdx] + qpIdx]; }
226 const Problem* problemPtr_;
227 std::vector<std::vector<FluxVariablesCache>> fluxVarsCache_;
228 std::vector<std::vector<std::size_t>> scvfOffset_;
229 std::vector<std::vector<FluxVariablesCache>> elementCache_;
230 std::vector<std::unique_ptr<std::unordered_map<int, std::vector<FluxVariablesCache>>>> boundaryFaceCache_;
237template<
class P,
class FVC,
class Traits>
240 using Problem =
typename Traits::Problem;
248 static constexpr bool cachingEnabled =
false;
255 template<
class Gr
idGeometry,
class Gr
idVolumeVariables,
class SolutionVector>
256 void update(
const GridGeometry& gridGeometry,
257 const GridVolumeVariables& gridVolVars,
258 const SolutionVector& sol,
259 bool forceUpdate =
false) {}
262 {
return *problemPtr_; }
265 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:239
const Problem & problem() const
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:261
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=false)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:256
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:245
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:251
HybridCVFEGridFluxVariablesCache(const Problem &problem)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:253
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:217
const Problem & problem() const
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:205
FluxVariablesCache & elementCache(std::size_t eIdx, std::size_t qpIdx)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:218
HybridCVFEGridFluxVariablesCache(const Problem &problem)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:75
FluxVariablesCache & boundaryFaceCache(std::size_t eIdx, int bfIdx, std::size_t qpIdx)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:221
FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx)
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:213
const FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx) const
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:209
const FluxVariablesCache & boundaryFaceCache(std::size_t eIdx, int bfIdx, std::size_t qpIdx) const
Definition: discretization/cvfe/hybrid/gridfluxvariablescache.hh:222
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:148
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:159
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