12#ifndef DUMUX_DISCRETIZATION_CVFE_ELEMENT_VARIABLES_HH
13#define DUMUX_DISCRETIZATION_CVFE_ELEMENT_VARIABLES_HH
19#include <dumux/common/concepts/localdofs_.hh>
33template<
class GVC,
bool cachingEnabled>
44 class MutableVariablesView
47 MutableVariablesView(GVC& gridCache)
48 : gridCache_(gridCache) {}
50 using Variables =
typename GVC::VolumeVariables;
52 template<
class LocalDof>
53 Variables& operator [](
const LocalDof& localDof)
const
54 {
return gridCache_.volVars(localDof.elementIndex(), localDof.index()); }
70 using Variables =
typename GridVariablesCache::VolumeVariables;
76 template<
class FVElementGeometry>
81 : gridVariablesCachePtr_(&gridVariablesCache) {}
83 const Variables& operator [](std::size_t localDofIdx)
const
84 {
return gridVolVars().volVars(eIdx_, localDofIdx); }
86 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value,
int> = 0>
87 const Variables& operator [](
const ScvOrLocalDof& scvOrLocalDof)
const
89 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
90 return gridVolVars().volVars(eIdx_, scvOrLocalDof.index());
92 return gridVolVars().volVars(eIdx_, scvOrLocalDof.localDofIndex());
100 template<
class FVElementGeometry,
class SolutionVector>
102 const FVElementGeometry& fvGeometry,
103 const SolutionVector& sol) &&
105 this->bindElement(element, fvGeometry, sol);
106 return std::move(*
this);
111 template<
class FVElementGeometry,
class SolutionVector>
112 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
113 const FVElementGeometry& fvGeometry,
114 const SolutionVector& sol) &
116 bindElement(element, fvGeometry, sol);
124 template<
class FVElementGeometry,
class SolutionVector>
126 const FVElementGeometry& fvGeometry,
127 const SolutionVector& sol) &&
129 this->bindElement(element, fvGeometry, sol);
130 return std::move(*
this);
134 template<
class FVElementGeometry,
class SolutionVector>
135 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
136 const FVElementGeometry& fvGeometry,
137 const SolutionVector& sol) &
139 eIdx_ = fvGeometry.gridGeometry().elementMapper().index(element);
146 {
return *gridVariablesCachePtr_; }
153 {
return { gridVars }; }
156 const GridVariablesCache* gridVariablesCachePtr_;
169 class MutableVariablesView
172 MutableVariablesView(
ThisType& view)
175 using Variables =
typename GVC::VolumeVariables;
177 template<
class LocalDof>
178 Variables& operator [](
const LocalDof& localDof)
const
179 {
return view_[localDof]; }
195 using Variables =
typename GridVariablesCache::VolumeVariables;
201 template<
class FVElementGeometry>
206 : gridVariablesCachePtr_(&gridVarsCache) {}
213 template<
class FVElementGeometry,
class SolutionVector>
215 const FVElementGeometry& fvGeometry,
216 const SolutionVector& sol) &&
218 this->bindElement(element, fvGeometry, sol);
219 return std::move(*
this);
223 template<
class FVElementGeometry,
class SolutionVector>
224 void bind(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
225 const FVElementGeometry& fvGeometry,
226 const SolutionVector& sol) &
228 bindElement(element, fvGeometry, sol);
236 template<
class FVElementGeometry,
class SolutionVector>
238 const FVElementGeometry& fvGeometry,
239 const SolutionVector& sol) &&
241 this->bindElement(element, fvGeometry, sol);
242 return std::move(*
this);
246 template<
class FVElementGeometry,
class SolutionVector>
247 void bindElement(
const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
248 const FVElementGeometry& fvGeometry,
249 const SolutionVector& sol) &
252 auto elemSol =
elementSolution(element, sol, fvGeometry.gridGeometry());
255 variables_.resize(Dumux::Detail::LocalDofs::numLocalDofs(fvGeometry));
258 for (
const auto& localDof :
localDofs(fvGeometry))
259 variables_[localDof.index()].update(elemSol, gridVolVars().problem(), fvGeometry, ipData(fvGeometry, localDof));
262 const Variables& operator [](std::size_t localIdx)
const
263 {
return variables_[localIdx]; }
266 {
return variables_[localIdx]; }
268 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value,
int> = 0>
269 const Variables& operator [](
const ScvOrLocalDof& scvOrLocalDof)
const
271 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
272 return variables_[scvOrLocalDof.index()];
274 return variables_[scvOrLocalDof.localDofIndex()];
277 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value,
int> = 0>
278 Variables& operator [](
const ScvOrLocalDof& scvOrLocalDof)
280 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
281 return variables_[scvOrLocalDof.index()];
283 return variables_[scvOrLocalDof.localDofIndex()];
290 {
return *gridVariablesCachePtr_; }
297 {
return { *
this }; }
300 const GridVariablesCache* gridVariablesCachePtr_;
301 std::vector<Variables> variables_;
The local (stencil) element variables class for control-volume finite element without caching.
Definition: elementvariables.hh:166
CVFEElementVariables 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: elementvariables.hh:237
const GridVariablesCache & gridVolVars() const
Definition: elementvariables.hh:289
MutableView asMutableView(GridVariablesCache &)
return a local view on variables that is always mutable, regardless of the caching policy
Definition: elementvariables.hh:296
Variables VolumeVariables
Definition: elementvariables.hh:198
CVFEElementVariables 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: elementvariables.hh:214
GVC GridVariablesCache
export type of the grid variables
Definition: elementvariables.hh:186
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: elementvariables.hh:247
CVFEElementVariables(const GridVariablesCache &gridVarsCache)
Constructor.
Definition: elementvariables.hh:205
MutableVariablesView MutableView
export type of the mutable version of the view
Definition: elementvariables.hh:192
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: elementvariables.hh:224
typename GridVariablesCache::VolumeVariables Variables
export type of the variables
Definition: elementvariables.hh:195
GridVariablesCache GridVolumeVariables
Definition: elementvariables.hh:189
MutableView asMutableView(GridVariablesCache &gridVars)
return a local view on variables that is always mutable, regardless of the caching policy
Definition: elementvariables.hh:152
CVFEElementVariables(const GridVariablesCache &gridVariablesCache)
Constructor.
Definition: elementvariables.hh:80
GridVariablesCache GridVolumeVariables
Definition: elementvariables.hh:64
CVFEElementVariables 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: elementvariables.hh:101
Variables VolumeVariables
Definition: elementvariables.hh:73
typename GridVariablesCache::VolumeVariables Variables
export type of the variables
Definition: elementvariables.hh:70
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: elementvariables.hh:135
GVC GridVariablesCache
export type of the grid variables
Definition: elementvariables.hh:61
const GridVariablesCache & gridVolVars() const
Definition: elementvariables.hh:145
CVFEElementVariables 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: elementvariables.hh:125
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: elementvariables.hh:112
MutableVariablesView MutableView
export type of the mutable version of the view
Definition: elementvariables.hh:67
The (stencil) element variables class for control-volume finite element.
Definition: elementvariables.hh:34
Definition: variablesdeflectionpolicy.hh:25
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
Definition: elementvariables.hh:24
auto localDofs(const FVElementGeometry &fvGeometry)
range over local dofs
Definition: localdof.hh:50
Variables deflection policy.