12#ifndef DUMUX_DISCRETIZATION_HYBRID_CVFE_ELEMENT_VARIABLES_HH
13#define DUMUX_DISCRETIZATION_HYBRID_CVFE_ELEMENT_VARIABLES_HH
23#include <dumux/common/concepts/ipdata_.hh>
24#include <dumux/common/concepts/localdofs_.hh>
41template<
class GVC,
bool cachingEnabled>
52 class MutableVariablesView
55 MutableVariablesView(GVC& gridCache)
56 : gridCache_(gridCache) {}
58 using Variables =
typename GVC::Variables;
60 template<Dumux::Concept::LocalDof LocalDof>
61 Variables& operator [](
const LocalDof& localDof)
const
62 {
return gridCache_.variables(localDof); }
67 class MutableVariablesViewWithIpCacheAccess
70 MutableVariablesViewWithIpCacheAccess(GVC& gridCache)
71 : gridCache_(gridCache)
74 using Variables =
typename GVC::Variables;
76 template<Dumux::Concept::LocalDof LocalDof>
77 Variables& operator [](
const LocalDof& localDof)
const
78 {
return gridCache_.variables(localDof); }
80 auto&
cache(std::size_t eIdx)
const
81 {
return gridCache_.cache(eIdx); }
96 InterpolationPointData::isSolDependent,
97 MutableVariablesViewWithIpCacheAccess,
102 using Variables =
typename GridVariablesCache::Variables;
105 template<
class FVElementGeometry>
107 InterpolationPointData::isSolDependent,
116 const Variables& operator [](std::size_t localDofIdx)
const
119 template<Dumux::Concept::LocalDof LocalDof>
120 const Variables& operator [](
const LocalDof& localDof)
const
123 template<
class IpData>
124 requires requires (
const IpData& ipData) { ipData.localDofIndex(); }
125 const Variables& operator [](
const IpData& ipData)
const
128 template<Concept::ScvfQpIpData IpData>
130 const IpData& ipData)
131 {
return elemVars.gridVariablesCache().scvfCache(elemVars.eIdx_, ipData.scvfIndex(), ipData.qpIndex()); }
133 template<Concept::BoundaryFaceQpIpData IpData>
135 const IpData& ipData)
136 {
return elemVars.gridVariablesCache().boundaryFaceCache(elemVars.eIdx_, ipData.boundaryFaceIndex(), ipData.qpIndex()); }
138 template<Concept::QIpData IpData>
140 const IpData& ipData)
141 {
return elemVars.gridVariablesCache().elementCache(elemVars.eIdx_, ipData.qpIndex()); }
148 template<
class FVElementGeometry,
class SolutionVector>
150 const FVElementGeometry& fvGeometry,
151 const SolutionVector& sol) &&
154 return std::move(*
this);
159 template<
class FVElementGeometry,
class SolutionVector>
160 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
161 const FVElementGeometry& fvGeometry,
162 const SolutionVector& sol) &
172 template<
class FVElementGeometry,
class SolutionVector>
174 const FVElementGeometry& fvGeometry,
175 const SolutionVector& sol) &&
178 return std::move(*
this);
182 template<
class FVElementGeometry,
class SolutionVector>
183 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
184 const FVElementGeometry& fvGeometry,
185 const SolutionVector& sol) &
187 const auto& gridDiscretization = Deprecated::gridGeometry(fvGeometry);
188 eIdx_ = gridDiscretization.elementMapper().index(element);
193 {
return *gridVariablesCachePtr_; }
200 {
return { gridVars }; }
203 const GridVariablesCache* gridVariablesCachePtr_;
215 using Problem = std::decay_t<decltype(std::declval<GVC>().problem())>;
217 using GridView =
typename GridGeometry::GridView;
220 static constexpr std::size_t maxNumBoundaryFaces = GridView::dimension << 1;
222 class MutableVariablesView
225 MutableVariablesView(ThisType& view)
228 using Variables =
typename GVC::Variables;
230 template<Dumux::Concept::LocalDof LocalDof>
231 Variables& operator [](
const LocalDof& localDof)
const
232 {
return view_[localDof]; }
237 class MutableVariablesViewWithIpCacheAccess
240 MutableVariablesViewWithIpCacheAccess(ThisType& view)
244 using Variables =
typename GVC::Variables;
246 template<Dumux::Concept::LocalDof LocalDof>
247 Variables& operator [](
const LocalDof& localDof)
const
248 {
return view_[localDof]; }
250 auto&
cache(std::size_t)
const
251 {
return *view_.ipDataCache_; }
266 InterpolationPointData::isSolDependent,
267 MutableVariablesViewWithIpCacheAccess,
272 using Variables =
typename GridVariablesCache::Variables;
275 template<
class FVElementGeometry>
277 InterpolationPointData::isSolDependent,
284 : gridVariablesCachePtr_(&gridVarsCache)
285 , ipDataCache_(std::make_shared<InterpolationPointDataCache>())
293 template<
class FVElementGeometry,
class SolutionVector>
295 const FVElementGeometry& fvGeometry,
296 const SolutionVector& sol) &&
299 return std::move(*
this);
303 template<
class FVElementGeometry,
class SolutionVector>
304 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
305 const FVElementGeometry& fvGeometry,
306 const SolutionVector& sol) &
316 template<
class FVElementGeometry,
class SolutionVector>
318 const FVElementGeometry& fvGeometry,
319 const SolutionVector& sol) &&
322 return std::move(*
this);
326 template<
class FVElementGeometry,
class SolutionVector>
327 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
328 const FVElementGeometry& fvGeometry,
329 const SolutionVector& sol) &
332 const auto& gridDiscretization = Deprecated::gridGeometry(fvGeometry);
336 variables_.resize(Dumux::Detail::LocalDofs::numLocalDofs(fvGeometry));
339 for (
const auto& localDof :
localDofs(fvGeometry))
340 variables_[localDof.index()].update(elemSol,
gridVariablesCache().problem(), fvGeometry, ipData(fvGeometry, localDof));
342 if constexpr (InterpolationPointData::isSolDependent)
344 auto newIpDataCache = std::make_shared<InterpolationPointDataCache>(*ipDataCache_);
345 newIpDataCache->update(
gridVariablesCache().problem(), element, fvGeometry, variables_);
346 ipDataCache_ = std::move(newIpDataCache);
349 ipDataCache_->update(
gridVariablesCache().problem(), element, fvGeometry, variables_);
352 const Variables& operator [](std::size_t localIdx)
const
353 {
return variables_[localIdx]; }
356 {
return variables_[localIdx]; }
358 template<Dumux::Concept::LocalDof LocalDof>
359 const Variables& operator [](
const LocalDof& localDof)
const
360 {
return variables_[localDof.index()]; }
362 template<Dumux::Concept::LocalDof LocalDof>
364 {
return variables_[localDof.index()]; }
366 template<
class IpData>
367 requires requires (
const IpData& ipData) { ipData.localDofIndex(); }
368 const Variables& operator [](
const IpData& ipData)
const
369 {
return variables_[ipData.localDofIndex()]; }
371 template<
class IpData>
372 requires requires (
const IpData& ipData) { ipData.localDofIndex(); }
374 {
return variables_[ipData.localDofIndex()]; }
376 template<Concept::ScvfQpIpData IpData>
378 const IpData& ipData)
379 {
return elemVars.ipDataCache_->scvfCache(ipData.scvfIndex(), ipData.qpIndex()); }
381 template<Concept::BoundaryFaceQpIpData IpData>
383 const IpData& ipData)
384 {
return elemVars.ipDataCache_->boundaryFaceCache(ipData.boundaryFaceIndex(), ipData.qpIndex()); }
386 template<Concept::QIpData IpData>
388 const IpData& ipData)
389 {
return elemVars.ipDataCache_->elementCache(ipData.qpIndex()); }
393 {
return *gridVariablesCachePtr_; }
400 {
return { *
this }; }
403 class InterpolationPointDataCache
406 InterpolationPointDataCache()
409 template<
class Problem,
class FVElementGeometry,
class ElementVariables>
410 void update(
const Problem& problem,
411 const typename FVElementGeometry::Element& element,
412 const FVElementGeometry& fvGeometry,
413 const ElementVariables& elemVars)
415 updateElementCache_(problem, element, fvGeometry, elemVars);
419 const InterpolationPointData& scvfCache(std::size_t scvfIdx, std::size_t qpIdx)
const
420 {
return scvfCache_[scvfIdx][qpIdx]; }
423 InterpolationPointData& scvfCache(std::size_t scvfIdx, std::size_t qpIdx)
424 {
return scvfCache_[scvfIdx][qpIdx]; }
427 const InterpolationPointData& elementCache(std::size_t qpIdx)
const
428 {
return elementCache_[qpIdx]; }
431 InterpolationPointData& elementCache(std::size_t qpIdx)
432 {
return elementCache_[qpIdx]; }
435 const InterpolationPointData& boundaryFaceCache(std::size_t bfIdx, std::size_t qpIdx)
const
436 {
return boundaryFaceCache_[bfIdx][qpIdx]; }
439 InterpolationPointData& boundaryFaceCache(std::size_t bfIdx, std::size_t qpIdx)
440 {
return boundaryFaceCache_[bfIdx][qpIdx]; }
443 template<
class Problem,
class FVElementGeometry,
class ElementVariables>
444 void updateElementCache_(
const Problem& problem,
445 const typename FVElementGeometry::Element& element,
446 const FVElementGeometry& fvGeometry,
447 const ElementVariables& elemVars)
449 scvfCache_.resize(fvGeometry.numScvf());
450 for (
const auto& scvf : scvfs(fvGeometry))
453 scvfCache_[scvf.index()].resize(std::ranges::size(quadRule));
454 for (
const auto& qpData : quadRule)
455 scvfCache_[scvf.index()][qpData.ipData().qpIndex()].update(
456 problem, element, fvGeometry, elemVars, qpData.ipData()
461 elementCache_.resize(std::ranges::size(elemQuadRule));
462 for (
const auto& qpData : elemQuadRule)
463 elementCache_[qpData.ipData().qpIndex()].update(problem, element, fvGeometry, elemVars, qpData.ipData());
465 for (
const auto& boundaryFace : boundaryFaces(fvGeometry))
467 auto& bfCache = boundaryFaceCache_[boundaryFace.index()];
469 bfCache.resize(std::ranges::size(quadRule));
470 for (
const auto& qpData : quadRule)
471 bfCache[qpData.ipData().qpIndex()].update(problem,
479 std::vector<std::vector<InterpolationPointData>> scvfCache_;
480 std::vector<InterpolationPointData> elementCache_;
481 std::array<std::vector<InterpolationPointData>, maxNumBoundaryFaces> boundaryFaceCache_;
484 const GridVariablesCache* gridVariablesCachePtr_;
485 std::vector<Variables> variables_;
486 std::shared_ptr<InterpolationPointDataCache> ipDataCache_;
Definition variablesdeflectionpolicy.hh:29
Definition variablesdeflectionpolicy.hh:95
std::conditional_t< InterpolationPointData::isSolDependent, MutableVariablesViewWithIpCacheAccess, MutableVariablesView > MutableView
export type of the mutable version of the view
Definition cvfe/hybrid/elementvariables.hh:265
MutableView asMutableView(GridVariablesCache &)
return a local view on variables that is always mutable, regardless of the caching policy
Definition cvfe/hybrid/elementvariables.hh:399
HybridCVFEElementVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition cvfe/hybrid/elementvariables.hh:294
HybridCVFEElementVariables(const GridVariablesCache &gridVarsCache)
Constructor.
Definition cvfe/hybrid/elementvariables.hh:283
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition cvfe/hybrid/elementvariables.hh:304
friend const InterpolationPointData & cache(const HybridCVFEElementVariables &elemVars, const IpData &ipData)
Definition cvfe/hybrid/elementvariables.hh:377
GVC GridVariablesCache
export type of the grid variables cache
Definition cvfe/hybrid/elementvariables.hh:259
typename GridVariablesCache::InterpolationPointData InterpolationPointData
export interpolation point data
Definition cvfe/hybrid/elementvariables.hh:262
const GridVariablesCache & gridVariablesCache() const
The grid variables cache object we are a restriction of.
Definition cvfe/hybrid/elementvariables.hh:392
std::conditional_t< InterpolationPointData::isSolDependent, Dumux::Detail::CVFE::VariablesDeflectionPolicyWithIpCacheUpdate< MutableView, FVElementGeometry >, Dumux::Detail::CVFE::VariablesDeflectionPolicy< MutableView, FVElementGeometry > > DeflectionPolicy
export type of deflection policy
Definition cvfe/hybrid/elementvariables.hh:276
HybridCVFEElementVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition cvfe/hybrid/elementvariables.hh:317
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition cvfe/hybrid/elementvariables.hh:327
typename GridVariablesCache::Variables Variables
export type of the variables
Definition cvfe/hybrid/elementvariables.hh:272
const GridVariablesCache & gridVariablesCache() const
The grid variables cache object we are a restriction of.
Definition cvfe/hybrid/elementvariables.hh:192
MutableView asMutableView(GridVariablesCache &gridVars)
return a local view on variables that is always mutable, regardless of the caching policy
Definition cvfe/hybrid/elementvariables.hh:199
GVC GridVariablesCache
export type of the grid variables cache
Definition cvfe/hybrid/elementvariables.hh:89
std::conditional_t< InterpolationPointData::isSolDependent, MutableVariablesViewWithIpCacheAccess, MutableVariablesView > MutableView
export type of the mutable version of the view
Definition cvfe/hybrid/elementvariables.hh:95
typename GridVariablesCache::InterpolationPointData InterpolationPointData
export interpolation point data
Definition cvfe/hybrid/elementvariables.hh:92
friend const InterpolationPointData & cache(const HybridCVFEElementVariables &elemVars, const IpData &ipData)
Definition cvfe/hybrid/elementvariables.hh:129
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition cvfe/hybrid/elementvariables.hh:183
HybridCVFEElementVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition cvfe/hybrid/elementvariables.hh:149
HybridCVFEElementVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition cvfe/hybrid/elementvariables.hh:173
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition cvfe/hybrid/elementvariables.hh:160
typename GridVariablesCache::Variables Variables
export type of the variables
Definition cvfe/hybrid/elementvariables.hh:102
std::conditional_t< InterpolationPointData::isSolDependent, Dumux::Detail::CVFE::VariablesDeflectionPolicyWithIpCacheUpdate< MutableView, FVElementGeometry >, Dumux::Detail::CVFE::VariablesDeflectionPolicy< MutableView, FVElementGeometry > > DeflectionPolicy
export type of deflection policy
Definition cvfe/hybrid/elementvariables.hh:106
HybridCVFEElementVariables(const GridVariablesCache &gridVariablesCache)
Constructor.
Definition cvfe/hybrid/elementvariables.hh:113
The (stencil) element variables class for hybrid control-volume finite element.
Definition cvfe/hybrid/elementvariables.hh:42
Base class for all standard finite volume or finite element problems.
Definition common/problem.hh:39
Type traits for problem classes.
Element solution classes and factory functions.
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
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
Quadrature rules over sub-control volumes and sub-control volume faces.
Detail::ProblemGridGeometry< Problem > GridGeometry
Definition common/typetraits/problem.hh:50
Variables deflection policy.