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>
34template<
class P,
class V,
class IPD>
41 template<
class Gr
idVariablesCache,
bool cachingEnabled>
49template<
class Traits,
bool enableCaching>
78 template<
class Gr
idGeometry,
class SolutionVector>
79 void init(
const GridGeometry& gridGeometry,
const SolutionVector& sol)
81 variables_.resize(gridGeometry.gridView().size(0));
82 ipDataCache_ = std::make_shared<InterpolationPointDataCache>();
83 ipDataCache_->resize(gridGeometry.gridView().size(0));
87 const auto element = gridGeometry.element(eIdx);
88 const auto fvGeometry =
localView(gridGeometry).bindElement(element);
93 variables_[eIdx].resize(Dumux::Detail::LocalDofs::numLocalDofs(fvGeometry));
94 for (
const auto& localDof :
localDofs(fvGeometry))
95 variables_[eIdx][localDof.index()].update(elemSol,
problem, fvGeometry, ipData(fvGeometry, localDof));
97 ipDataCache_->update(
problem, element, fvGeometry, variables_[eIdx]);
101 template<
class Gr
idGeometry,
class SolutionVector>
102 void update(
const GridGeometry& gridGeometry,
const SolutionVector& sol)
104 if constexpr (InterpolationPointData::isSolDependent)
106 auto newIpDataCache = std::make_shared<InterpolationPointDataCache>();
107 newIpDataCache->resize(gridGeometry.gridView().size(0));
111 const auto element = gridGeometry.element(eIdx);
112 const auto fvGeometry =
localView(gridGeometry).bindElement(element);
117 for (
const auto& localDof :
localDofs(fvGeometry))
118 variables_[eIdx][localDof.index()].update(elemSol,
problem, fvGeometry, ipData(fvGeometry, localDof));
120 newIpDataCache->update(
problem, element, fvGeometry, variables_[eIdx]);
123 ipDataCache_ = std::move(newIpDataCache);
129 const auto element = gridGeometry.element(eIdx);
130 const auto fvGeometry =
localView(gridGeometry).bindElement(element);
135 for (
const auto& localDof :
localDofs(fvGeometry))
136 variables_[eIdx][localDof.index()].update(elemSol,
problem, fvGeometry, ipData(fvGeometry, localDof));
141 template<
class ScvOrLocalDof>
144 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
145 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.index()];
147 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.localDofIndex()];
150 template<
class ScvOrLocalDof>
153 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
154 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.index()];
156 return variables_[scvOrLocalDof.elementIndex()][scvOrLocalDof.localDofIndex()];
160 {
return variables_[eIdx][localIdx]; }
163 {
return variables_[eIdx][localIdx]; }
166 {
return ipDataCache_->scvfCache(eIdx, scvfIdx, qpIdx); }
169 {
return ipDataCache_->scvfCache(eIdx, scvfIdx, qpIdx); }
172 {
return ipDataCache_->elementCache(eIdx, qpIdx); }
175 {
return ipDataCache_->elementCache(eIdx, qpIdx); }
178 {
return ipDataCache_->boundaryFaceCache(eIdx, bfIdx, qpIdx); }
181 {
return ipDataCache_->boundaryFaceCache(eIdx, bfIdx, qpIdx); }
184 {
return *problemPtr_; }
187 class InterpolationPointDataCache
191 std::vector<InterpolationPointData> scvfCache;
192 std::vector<std::size_t> qpsOffset;
193 std::vector<InterpolationPointData> elementCache;
194 std::unordered_map<int, std::vector<InterpolationPointData>> boundaryFaceCache;
196 template<
class Problem,
class FVElementGeometry,
class ElementVariables>
197 void update(
const Problem& problem,
198 const typename FVElementGeometry::Element& element,
199 const FVElementGeometry& fvGeometry,
200 const ElementVariables& elemVars)
202 qpsOffset.resize(fvGeometry.numScvf() + 1, 0);
203 for (
const auto& scvf : scvfs(fvGeometry))
206 qpsOffset[scvf.index() + 1] = numQps;
208 for (std::size_t i = 2; i < qpsOffset.size(); ++i)
209 qpsOffset[i] += qpsOffset[i-1];
211 scvfCache.resize(qpsOffset.back());
212 for (
const auto& scvf : scvfs(fvGeometry))
216 const auto scvfIdx = qpData.ipData().scvfIndex();
217 const auto qpIdx = qpData.ipData().qpIndex();
218 scvfCache[qpsOffset[scvfIdx] + qpIdx].update(problem,
227 elementCache.resize(std::ranges::size(elemQuadRule));
228 for (
const auto& qpData : elemQuadRule)
229 elementCache[qpData.ipData().qpIndex()].update(problem, element, fvGeometry, elemVars, qpData.ipData());
231 boundaryFaceCache.clear();
232 for (
const auto& boundaryFace : boundaryFaces(fvGeometry))
234 auto& bfCache = boundaryFaceCache[boundaryFace.index()];
236 bfCache.resize(std::ranges::size(quadRule));
237 for (
const auto& qpData : quadRule)
238 bfCache[qpData.ipData().qpIndex()].update(problem,
249 InterpolationPointDataCache()
252 void resize(
const std::size_t numElements)
254 elementCaches_.resize(numElements);
257 template<
class Problem,
class FVElementGeometry,
class ElementVariables>
258 void update(
const Problem& problem,
259 const typename FVElementGeometry::Element& element,
260 const FVElementGeometry& fvGeometry,
261 const ElementVariables& elemVars)
263 const auto& gridDiscretization = Deprecated::gridGeometry(fvGeometry);
264 const auto eIdx = gridDiscretization.elementMapper().index(element);
265 elementCaches_[eIdx].update(problem, element, fvGeometry, elemVars);
269 const InterpolationPointData& scvfCache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx)
const
271 const auto& elementCache = elementCaches_[eIdx];
272 return elementCache.scvfCache[elementCache.qpsOffset[scvfIdx] + qpIdx];
276 InterpolationPointData& scvfCache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx)
278 auto& elementCache = elementCaches_[eIdx];
279 return elementCache.scvfCache[elementCache.qpsOffset[scvfIdx] + qpIdx];
283 const InterpolationPointData& elementCache(std::size_t eIdx, std::size_t qpIdx)
const
284 {
return elementCaches_[eIdx].elementCache[qpIdx]; }
287 InterpolationPointData& elementCache(std::size_t eIdx, std::size_t qpIdx)
288 {
return elementCaches_[eIdx].elementCache[qpIdx]; }
291 const InterpolationPointData& boundaryFaceCache(std::size_t eIdx,
int bfIdx, std::size_t qpIdx)
const
292 {
return elementCaches_[eIdx].boundaryFaceCache.at(bfIdx)[qpIdx]; }
295 InterpolationPointData& boundaryFaceCache(std::size_t eIdx,
int bfIdx, std::size_t qpIdx)
296 {
return elementCaches_[eIdx].boundaryFaceCache[bfIdx][qpIdx]; }
298 const ElementCache& cache(std::size_t eIdx)
const
299 {
return elementCaches_[eIdx]; }
301 ElementCache& cache(std::size_t eIdx)
302 {
return elementCaches_[eIdx]; }
305 std::vector<ElementCache> elementCaches_;
309 const auto&
cache(std::size_t eIdx)
const
310 {
return ipDataCache_->cache(eIdx); }
313 {
return ipDataCache_->cache(eIdx); }
317 std::vector<std::vector<Variables>> variables_;
318 std::shared_ptr<InterpolationPointDataCache> ipDataCache_;
322template<
class Traits>
348 template<
class Gr
idGeometry,
class SolutionVector>
349 void update(
const GridGeometry& gridGeometry,
const SolutionVector& sol) {}
352 {
return *problemPtr_;}
The (stencil) element variables class for hybrid control-volume finite element.
Definition cvfe/hybrid/elementvariables.hh:42
typename Traits::InterpolationPointData InterpolationPointData
export interpolation point data type
Definition cvfe/hybrid/gridvariablescache.hh:344
HybridCVFEGridVariablesCache(const Problem &problem)
Definition cvfe/hybrid/gridvariablescache.hh:346
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition cvfe/hybrid/gridvariablescache.hh:338
static constexpr bool cachingEnabled
make it possible to query if caching is enabled
Definition cvfe/hybrid/gridvariablescache.hh:335
const Problem & problem() const
Definition cvfe/hybrid/gridvariablescache.hh:351
typename Traits::Problem Problem
export the problem type
Definition cvfe/hybrid/gridvariablescache.hh:329
typename Traits::Variables Variables
export the variables type
Definition cvfe/hybrid/gridvariablescache.hh:332
typename LocalView::MutableView MutableLocalView
export the type of the mutable local view
Definition cvfe/hybrid/gridvariablescache.hh:341
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition cvfe/hybrid/gridvariablescache.hh:349
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition cvfe/hybrid/gridvariablescache.hh:102
Variables & variables(const std::size_t eIdx, const std::size_t localIdx)
Definition cvfe/hybrid/gridvariablescache.hh:162
void init(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition cvfe/hybrid/gridvariablescache.hh:79
Variables & variables(const ScvOrLocalDof &scvOrLocalDof)
Definition cvfe/hybrid/gridvariablescache.hh:151
auto & cache(std::size_t eIdx)
Definition cvfe/hybrid/gridvariablescache.hh:312
static constexpr bool cachingEnabled
make it possible to query if caching is enabled
Definition cvfe/hybrid/gridvariablescache.hh:68
typename Traits::Variables Variables
export the variables type
Definition cvfe/hybrid/gridvariablescache.hh:62
const InterpolationPointData & boundaryFaceCache(std::size_t eIdx, int bfIdx, std::size_t qpIdx) const
Definition cvfe/hybrid/gridvariablescache.hh:177
InterpolationPointData & scvfCache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx)
Definition cvfe/hybrid/gridvariablescache.hh:168
typename LocalView::MutableView MutableLocalView
export the type of the mutable local view
Definition cvfe/hybrid/gridvariablescache.hh:74
const InterpolationPointData & scvfCache(std::size_t eIdx, std::size_t scvfIdx, std::size_t qpIdx) const
Definition cvfe/hybrid/gridvariablescache.hh:165
HybridCVFEGridVariablesCache(const Problem &problem)
Definition cvfe/hybrid/gridvariablescache.hh:76
const auto & cache(std::size_t eIdx) const
Definition cvfe/hybrid/gridvariablescache.hh:309
typename Traits::InterpolationPointData InterpolationPointData
export interpolation point data type
Definition cvfe/hybrid/gridvariablescache.hh:65
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition cvfe/hybrid/gridvariablescache.hh:71
const Problem & problem() const
Definition cvfe/hybrid/gridvariablescache.hh:183
typename Traits::Problem Problem
export the problem type
Definition cvfe/hybrid/gridvariablescache.hh:59
InterpolationPointData & boundaryFaceCache(std::size_t eIdx, int bfIdx, std::size_t qpIdx)
Definition cvfe/hybrid/gridvariablescache.hh:180
const Variables & variables(const ScvOrLocalDof &scvOrLocalDof) const
Definition cvfe/hybrid/gridvariablescache.hh:142
InterpolationPointData & elementCache(std::size_t eIdx, std::size_t qpIdx)
Definition cvfe/hybrid/gridvariablescache.hh:174
const Variables & variables(const std::size_t eIdx, const std::size_t localIdx) const
Definition cvfe/hybrid/gridvariablescache.hh:159
const InterpolationPointData & elementCache(std::size_t eIdx, std::size_t qpIdx) const
Definition cvfe/hybrid/gridvariablescache.hh:171
The grid variables cache class for hybrid control-volume finite element methods.
Definition cvfe/hybrid/gridvariablescache.hh:50
Base class for all standard finite volume or finite element problems.
Definition common/problem.hh:39
The local element solution class for control-volume finite element methods.
The element variables class for hybrid 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
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 cvfe/hybrid/elementvariables.hh:32
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 cvfe/hybrid/gridvariablescache.hh:36
IPD InterpolationPointData
Definition cvfe/hybrid/gridvariablescache.hh:39
P Problem
Definition cvfe/hybrid/gridvariablescache.hh:37
V Variables
Definition cvfe/hybrid/gridvariablescache.hh:38
HybridCVFEElementVariables< GridVariablesCache, cachingEnabled > LocalView
Definition cvfe/hybrid/gridvariablescache.hh:42