12#ifndef DUMUX_DISCRETIZATION_HYBRID_CVFE_GRID_VARIABLES_CACHE_HH
13#define DUMUX_DISCRETIZATION_HYBRID_CVFE_GRID_VARIABLES_CACHE_HH
15#include <unordered_map>
23#include <dumux/common/concepts/localdofs_.hh>
33template<
class P,
class V,
class IPD>
40 template<
class Gr
idVariablesCache,
bool cachingEnabled>
48template<
class Traits,
bool enableCaching>
67 static constexpr bool cachingEnabled =
true;
77 template<
class Gr
idGeometry,
class SolutionVector>
78 void init(
const GridGeometry& gridGeometry,
const SolutionVector& sol)
80 variables_.resize(gridGeometry.gridView().size(0));
81 ipDataCache_ = std::make_shared<InterpolationPointDataCache>();
82 ipDataCache_->resize(gridGeometry.gridView().size(0));
84 Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem()](
const std::size_t eIdx)
86 const auto element = gridGeometry.element(eIdx);
87 const auto fvGeometry =
localView(gridGeometry).bindElement(element);
92 variables_[eIdx].resize(Dumux::Detail::LocalDofs::numLocalDofs(fvGeometry));
93 for (
const auto& localDof :
localDofs(fvGeometry))
94 variables_[eIdx][localDof.index()].update(elemSol, problem, fvGeometry, ipData(fvGeometry, localDof));
96 ipDataCache_->update(problem, element, fvGeometry, variables_[eIdx]);
100 template<
class Gr
idGeometry,
class SolutionVector>
101 void update(
const GridGeometry& gridGeometry,
const SolutionVector& sol)
103 if constexpr (InterpolationPointData::isSolDependent)
105 auto newIpDataCache = std::make_shared<InterpolationPointDataCache>();
106 newIpDataCache->resize(gridGeometry.gridView().size(0));
108 Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem(), newIpDataCache](
const std::size_t eIdx)
110 const auto element = gridGeometry.element(eIdx);
111 const auto fvGeometry =
localView(gridGeometry).bindElement(element);
116 for (
const auto& localDof :
localDofs(fvGeometry))
117 variables_[eIdx][localDof.index()].update(elemSol, problem, fvGeometry, ipData(fvGeometry, localDof));
119 newIpDataCache->update(problem, element, fvGeometry, variables_[eIdx]);
122 ipDataCache_ = std::move(newIpDataCache);
126 Dumux::parallelFor(gridGeometry.gridView().size(0), [&, &problem = problem()](
const std::size_t eIdx)
128 const auto element = gridGeometry.element(eIdx);
129 const auto fvGeometry =
localView(gridGeometry).bindElement(element);
134 for (
const auto& localDof :
localDofs(fvGeometry))
135 variables_[eIdx][localDof.index()].update(elemSol, problem, fvGeometry, ipData(fvGeometry, localDof));
140 template<
class ScvOrLocalDof>
143 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
144 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.index()];
146 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.localDofIndex()];
149 template<
class ScvOrLocalDof>
152 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
153 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.index()];
155 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.localDofIndex()];
159 {
return variables_[eIdx][localIdx]; }
162 {
return variables_[eIdx][localIdx]; }
165 {
return ipDataCache_->scvfCache(eIdx, scvfIdx, qpIdx); }
168 {
return ipDataCache_->scvfCache(eIdx, scvfIdx, qpIdx); }
171 {
return ipDataCache_->elementCache(eIdx, qpIdx); }
174 {
return ipDataCache_->elementCache(eIdx, qpIdx); }
177 {
return ipDataCache_->boundaryFaceCache(eIdx, bfIdx, qpIdx); }
180 {
return ipDataCache_->boundaryFaceCache(eIdx, bfIdx, qpIdx); }
183 {
return *problemPtr_; }
186 class InterpolationPointDataCache
190 std::vector<InterpolationPointData> scvfCache;
191 std::vector<std::size_t> qpsOffset;
192 std::vector<InterpolationPointData> elementCache;
193 std::unordered_map<int, std::vector<InterpolationPointData>> boundaryFaceCache;
195 template<
class Problem,
class FVElementGeometry,
class ElementVariables>
196 void update(
const Problem& problem,
197 const typename FVElementGeometry::Element& element,
198 const FVElementGeometry& fvGeometry,
199 const ElementVariables& elemVars)
201 qpsOffset.resize(fvGeometry.numScvf() + 1, 0);
202 for (
const auto& scvf : scvfs(fvGeometry))
205 qpsOffset[scvf.index() + 1] = numQps;
207 for (std::size_t i = 2; i < qpsOffset.size(); ++i)
208 qpsOffset[i] += qpsOffset[i-1];
210 scvfCache.resize(qpsOffset.back());
211 for (
const auto& scvf : scvfs(fvGeometry))
215 const auto scvfIdx = qpData.ipData().scvfIndex();
216 const auto qpIdx = qpData.ipData().qpIndex();
217 scvfCache[qpsOffset[scvfIdx] + qpIdx].update(problem,
226 elementCache.resize(std::ranges::size(elemQuadRule));
227 for (
const auto& qpData : elemQuadRule)
228 elementCache[qpData.ipData().qpIndex()].update(problem, element, fvGeometry, elemVars, qpData.ipData());
230 boundaryFaceCache.clear();
231 for (
const auto& boundaryFace : boundaryFaces(fvGeometry))
233 auto& bfCache = boundaryFaceCache[boundaryFace.index()];
235 bfCache.resize(std::ranges::size(quadRule));
236 for (
const auto& qpData : quadRule)
237 bfCache[qpData.ipData().qpIndex()].update(problem,
248 InterpolationPointDataCache()
251 void resize(
const std::size_t numElements)
253 elementCaches_.resize(numElements);
256 template<
class Problem,
class FVElementGeometry,
class ElementVariables>
257 void update(
const Problem& problem,
258 const typename FVElementGeometry::Element& element,
259 const FVElementGeometry& fvGeometry,
260 const ElementVariables& elemVars)
262 const auto eIdx = fvGeometry.gridGeometry().elementMapper().index(element);
263 elementCaches_[eIdx].update(problem, element, fvGeometry, elemVars);
267 const InterpolationPointData& scvfCache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx)
const
269 const auto& elementCache = elementCaches_[eIdx];
270 return elementCache.scvfCache[elementCache.qpsOffset[scvfIdx] + qpIdx];
274 InterpolationPointData& scvfCache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx)
276 auto& elementCache = elementCaches_[eIdx];
277 return elementCache.scvfCache[elementCache.qpsOffset[scvfIdx] + qpIdx];
281 const InterpolationPointData& elementCache(std::size_t eIdx, std::size_t qpIdx)
const
282 {
return elementCaches_[eIdx].elementCache[qpIdx]; }
285 InterpolationPointData& elementCache(std::size_t eIdx, std::size_t qpIdx)
286 {
return elementCaches_[eIdx].elementCache[qpIdx]; }
289 const InterpolationPointData& boundaryFaceCache(std::size_t eIdx,
int bfIdx, std::size_t qpIdx)
const
290 {
return elementCaches_[eIdx].boundaryFaceCache.at(bfIdx)[qpIdx]; }
293 InterpolationPointData& boundaryFaceCache(std::size_t eIdx,
int bfIdx, std::size_t qpIdx)
294 {
return elementCaches_[eIdx].boundaryFaceCache[bfIdx][qpIdx]; }
296 const ElementCache& cache(std::size_t eIdx)
const
297 {
return elementCaches_[eIdx]; }
299 ElementCache& cache(std::size_t eIdx)
300 {
return elementCaches_[eIdx]; }
303 std::vector<ElementCache> elementCaches_;
307 const auto&
cache(std::size_t eIdx)
const
308 {
return ipDataCache_->cache(eIdx); }
311 {
return ipDataCache_->cache(eIdx); }
314 const Problem* problemPtr_;
315 std::vector<std::vector<Variables>> variables_;
316 std::shared_ptr<InterpolationPointDataCache> ipDataCache_;
320template<
class Traits>
333 static constexpr bool cachingEnabled =
false;
346 template<
class Gr
idGeometry,
class SolutionVector>
347 void update(
const GridGeometry& gridGeometry,
const SolutionVector& sol) {}
350 {
return *problemPtr_;}
353 const Problem* problemPtr_;
The (stencil) element variables class for hybrid control-volume finite element.
Definition: hybrid/elementvariables.hh:40
Definition: hybrid/gridvariablescache.hh:322
typename Traits::InterpolationPointData InterpolationPointData
export interpolation point data type
Definition: hybrid/gridvariablescache.hh:342
HybridCVFEGridVariablesCache(const Problem &problem)
Definition: hybrid/gridvariablescache.hh:344
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: hybrid/gridvariablescache.hh:336
const Problem & problem() const
Definition: hybrid/gridvariablescache.hh:349
typename Traits::Problem Problem
export the problem type
Definition: hybrid/gridvariablescache.hh:327
typename Traits::Variables Variables
export the variables type
Definition: hybrid/gridvariablescache.hh:330
typename LocalView::MutableView MutableLocalView
export the type of the mutable local view
Definition: hybrid/gridvariablescache.hh:339
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: hybrid/gridvariablescache.hh:347
Definition: hybrid/gridvariablescache.hh:54
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: hybrid/gridvariablescache.hh:101
Variables & variables(const std::size_t eIdx, const std::size_t localIdx)
Definition: hybrid/gridvariablescache.hh:161
void init(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: hybrid/gridvariablescache.hh:78
Variables & variables(const ScvOrLocalDof &scvOrLocalDof)
Definition: hybrid/gridvariablescache.hh:150
auto & cache(std::size_t eIdx)
Definition: hybrid/gridvariablescache.hh:310
typename Traits::Variables Variables
export the variables type
Definition: hybrid/gridvariablescache.hh:61
const InterpolationPointData & boundaryFaceCache(std::size_t eIdx, int bfIdx, std::size_t qpIdx) const
Definition: hybrid/gridvariablescache.hh:176
InterpolationPointData & scvfCache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx)
Definition: hybrid/gridvariablescache.hh:167
typename LocalView::MutableView MutableLocalView
export the type of the mutable local view
Definition: hybrid/gridvariablescache.hh:73
const InterpolationPointData & scvfCache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx) const
Definition: hybrid/gridvariablescache.hh:164
HybridCVFEGridVariablesCache(const Problem &problem)
Definition: hybrid/gridvariablescache.hh:75
const auto & cache(std::size_t eIdx) const
Definition: hybrid/gridvariablescache.hh:307
typename Traits::InterpolationPointData InterpolationPointData
export interpolation point data type
Definition: hybrid/gridvariablescache.hh:64
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: hybrid/gridvariablescache.hh:70
const Problem & problem() const
Definition: hybrid/gridvariablescache.hh:182
typename Traits::Problem Problem
export the problem type
Definition: hybrid/gridvariablescache.hh:58
InterpolationPointData & boundaryFaceCache(std::size_t eIdx, int bfIdx, std::size_t qpIdx)
Definition: hybrid/gridvariablescache.hh:179
const Variables & variables(const ScvOrLocalDof &scvOrLocalDof) const
Definition: hybrid/gridvariablescache.hh:141
InterpolationPointData & elementCache(std::size_t eIdx, std::size_t qpIdx)
Definition: hybrid/gridvariablescache.hh:173
const Variables & variables(const std::size_t eIdx, const std::size_t localIdx) const
Definition: hybrid/gridvariablescache.hh:158
const InterpolationPointData & elementCache(std::size_t eIdx, std::size_t qpIdx) const
Definition: hybrid/gridvariablescache.hh:170
The grid variables cache class for hybrid control-volume finite element methods.
Definition: hybrid/gridvariablescache.hh:49
The local element solution class for control-volume finite element methods.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethods::cctpfa||GridGeometry::discMethod==DiscretizationMethods::ccmpfa, CCElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for cell-centered schemes.
Definition: cellcentered/elementsolution.hh:101
void parallelFor(const std::size_t count, const FunctorType &functor)
A parallel for loop (multithreading)
Definition: parallel_for.hh:160
The element variables class for hybrid control-volume finite element methods.
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
Definition: hybrid/elementvariables.hh:30
auto localDofs(const FVElementGeometry &fvGeometry)
range over local dofs
Definition: localdof.hh:50
Parallel for loop (multithreading)
Quadrature rules over sub-control volumes and sub-control volume faces.
Definition: hybrid/gridvariablescache.hh:35
IPD InterpolationPointData
Definition: hybrid/gridvariablescache.hh:38
P Problem
Definition: hybrid/gridvariablescache.hh:36
V Variables
Definition: hybrid/gridvariablescache.hh:37