version 3.11-dev
elementvariables.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_CVFE_ELEMENT_VARIABLES_HH
13#define DUMUX_DISCRETIZATION_CVFE_ELEMENT_VARIABLES_HH
14
15#include <type_traits>
16#include <utility>
17#include <vector>
18
19#include <dumux/common/concepts/localdofs_.hh>
21
23
25
33template<class GVC, bool cachingEnabled>
35
41template<class GVC>
42class CVFEElementVariables<GVC, /*cachingEnabled*/true>
43{
44 class MutableVariablesView
45 {
46 public:
47 MutableVariablesView(GVC& gridCache)
48 : gridCache_(gridCache) {}
49
50 using Variables = typename GVC::VolumeVariables;
51
52 template<class LocalDof>
53 Variables& operator [](const LocalDof& localDof) const
54 { return gridCache_.volVars(localDof.elementIndex(), localDof.index()); }
55 private:
56 GVC& gridCache_;
57 };
58
59public:
61 using GridVariablesCache = GVC;
65
67 using MutableView = MutableVariablesView;
68
70 using Variables = typename GridVariablesCache::VolumeVariables;
74
76 template<class FVElementGeometry>
78
80 CVFEElementVariables(const GridVariablesCache& gridVariablesCache)
81 : gridVariablesCachePtr_(&gridVariablesCache) {}
82
83 const Variables& operator [](std::size_t localDofIdx) const
84 { return gridVolVars().volVars(eIdx_, localDofIdx); }
85
86 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
87 const Variables& operator [](const ScvOrLocalDof& scvOrLocalDof) const
88 {
89 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
90 return gridVolVars().volVars(eIdx_, scvOrLocalDof.index());
91 else
92 return gridVolVars().volVars(eIdx_, scvOrLocalDof.localDofIndex());
93 }
94
100 template<class FVElementGeometry, class SolutionVector>
101 CVFEElementVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
102 const FVElementGeometry& fvGeometry,
103 const SolutionVector& sol) &&
104 {
105 this->bindElement(element, fvGeometry, sol);
106 return std::move(*this);
107 }
108
109 // For compatibility reasons with the case of not storing the variables.
110 // function to be called before assembling an element, preparing the variables within the stencil
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) &
115 {
116 bindElement(element, fvGeometry, sol);
117 }
118
124 template<class FVElementGeometry, class SolutionVector>
125 CVFEElementVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
126 const FVElementGeometry& fvGeometry,
127 const SolutionVector& sol) &&
128 {
129 this->bindElement(element, fvGeometry, sol);
130 return std::move(*this);
131 }
132
133 // function to prepare the variables within the element
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) &
138 {
139 eIdx_ = fvGeometry.gridGeometry().elementMapper().index(element);
140 }
141
146 { return *gridVariablesCachePtr_; }
147
153 { return { gridVars }; }
154
155private:
156 const GridVariablesCache* gridVariablesCachePtr_;
157 std::size_t eIdx_;
158};
159
164template<class GVC>
165class CVFEElementVariables<GVC, /*cachingEnabled*/false>
166{
167 using ThisType = CVFEElementVariables<GVC, /*cachingEnabled*/false>;
168
169 class MutableVariablesView
170 {
171 public:
172 MutableVariablesView(ThisType& view)
173 : view_(view) {}
174
175 using Variables = typename GVC::VolumeVariables;
176
177 template<class LocalDof>
178 Variables& operator [](const LocalDof& localDof) const
179 { return view_[localDof]; }
180 private:
181 ThisType& view_;
182 };
183
184public:
190
192 using MutableView = MutableVariablesView;
193
195 using Variables = typename GridVariablesCache::VolumeVariables;
199
201 template<class FVElementGeometry>
203
206 : gridVariablesCachePtr_(&gridVarsCache) {}
207
213 template<class FVElementGeometry, class SolutionVector>
214 CVFEElementVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
215 const FVElementGeometry& fvGeometry,
216 const SolutionVector& sol) &&
217 {
218 this->bindElement(element, fvGeometry, sol);
219 return std::move(*this);
220 }
221
222 // specialization for control-volume finite element, simply forwards to the bindElement method
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) &
227 {
228 bindElement(element, fvGeometry, sol);
229 }
230
236 template<class FVElementGeometry, class SolutionVector>
237 CVFEElementVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
238 const FVElementGeometry& fvGeometry,
239 const SolutionVector& sol) &&
240 {
241 this->bindElement(element, fvGeometry, sol);
242 return std::move(*this);
243 }
244
245 // specialization for control-volume finite element
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) &
250 {
251 // get the solution at the dofs of the element
252 auto elemSol = elementSolution(element, sol, fvGeometry.gridGeometry());
253
254 // resize variables to the required size
255 variables_.resize(Dumux::Detail::LocalDofs::numLocalDofs(fvGeometry));
256
257 // update variables related to localDofs
258 for (const auto& localDof : localDofs(fvGeometry))
259 variables_[localDof.index()].update(elemSol, gridVolVars().problem(), fvGeometry, ipData(fvGeometry, localDof));
260 }
261
262 const Variables& operator [](std::size_t localIdx) const
263 { return variables_[localIdx]; }
264
265 Variables& operator [](std::size_t localIdx)
266 { return variables_[localIdx]; }
267
268 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
269 const Variables& operator [](const ScvOrLocalDof& scvOrLocalDof) const
270 {
271 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
272 return variables_[scvOrLocalDof.index()];
273 else
274 return variables_[scvOrLocalDof.localDofIndex()];
275 }
276
277 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
278 Variables& operator [](const ScvOrLocalDof& scvOrLocalDof)
279 {
280 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
281 return variables_[scvOrLocalDof.index()];
282 else
283 return variables_[scvOrLocalDof.localDofIndex()];
284 }
285
290 { return *gridVariablesCachePtr_; }
291
297 { return { *this }; }
298
299private:
300 const GridVariablesCache* gridVariablesCachePtr_;
301 std::vector<Variables> variables_;
302};
303
304} // end namespace Dumux
305
306#endif
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.