version 3.11-dev
cvfe/elementvolumevariables.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_VOLUMEVARIABLES_HH
13#define DUMUX_DISCRETIZATION_CVFE_ELEMENT_VOLUMEVARIABLES_HH
14
15#include <type_traits>
16#include <utility>
17#include <vector>
18
19#include <dumux/common/concepts/localdofs_.hh>
21
22namespace Dumux {
23
31template<class GVV, bool cachingEnabled>
33
39template<class GVV>
40class CVFEElementVolumeVariables<GVV, /*cachingEnabled*/true>
41{
42 class MutableVariablesView
43 {
44 public:
45 MutableVariablesView(GVV& gridCache)
46 : gridCache_(gridCache) {}
47
48 using VolumeVariables = typename GVV::VolumeVariables;
49
50 template<class SubControlVolume>
51 VolumeVariables& operator [](const SubControlVolume& scv) const
52 { return gridCache_.volVars(scv.elementIndex(), scv.indexInElement()); }
53 private:
54 GVV& gridCache_;
55 };
56
57public:
60
62 using MutableView = MutableVariablesView;
63
65 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
66
69 : gridVolVarsPtr_(&gridVolVars) {}
70
71 const VolumeVariables& operator [](std::size_t scvIdx) const
72 { return gridVolVars().volVars(eIdx_, scvIdx); }
73
74 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
75 const VolumeVariables& operator [](const ScvOrLocalDof& scvOrLocalDof) const
76 {
77 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
78 return gridVolVars().volVars(eIdx_, scvOrLocalDof.index());
79 else
80 return gridVolVars().volVars(eIdx_, scvOrLocalDof.indexInElement());
81 }
82
88 template<class FVElementGeometry, class SolutionVector>
89 CVFEElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
90 const FVElementGeometry& fvGeometry,
91 const SolutionVector& sol) &&
92 {
93 this->bindElement(element, fvGeometry, sol);
94 return std::move(*this);
95 }
96
97 // For compatibility reasons with the case of not storing the vol vars.
98 // function to be called before assembling an element, preparing the vol vars within the stencil
99 template<class FVElementGeometry, class SolutionVector>
100 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
101 const FVElementGeometry& fvGeometry,
102 const SolutionVector& sol) &
103 {
104 bindElement(element, fvGeometry, sol);
105 }
106
112 template<class FVElementGeometry, class SolutionVector>
113 CVFEElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
114 const FVElementGeometry& fvGeometry,
115 const SolutionVector& sol) &&
116 {
117 this->bindElement(element, fvGeometry, sol);
118 return std::move(*this);
119 }
120
121 // function to prepare the vol vars within the element
122 template<class FVElementGeometry, class SolutionVector>
123 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
124 const FVElementGeometry& fvGeometry,
125 const SolutionVector& sol) &
126 {
127 eIdx_ = fvGeometry.gridGeometry().elementMapper().index(element);
128 }
129
132 { return *gridVolVarsPtr_; }
133
139 { return { gridVolVars }; }
140
141private:
142 const GridVolumeVariables* gridVolVarsPtr_;
143 std::size_t eIdx_;
144};
145
146
151template<class GVV>
152class CVFEElementVolumeVariables<GVV, /*cachingEnabled*/false>
153{
154 using ThisType = CVFEElementVolumeVariables<GVV, /*cachingEnabled*/false>;
155
156 class MutableVariablesView
157 {
158 public:
159 MutableVariablesView(ThisType& view)
160 : view_(view) {}
161
162 using VolumeVariables = typename GVV::VolumeVariables;
163
164 template<class SubControlVolume>
165 VolumeVariables& operator [](const SubControlVolume& scv) const
166 { return view_[scv]; }
167 private:
168 ThisType& view_;
169 };
170
171public:
174
176 using MutableView = MutableVariablesView;
177
179 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
180
183 : gridVolVarsPtr_(&gridVolVars) {}
184
190 template<class FVElementGeometry, class SolutionVector>
191 CVFEElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
192 const FVElementGeometry& fvGeometry,
193 const SolutionVector& sol) &&
194 {
195 this->bindElement(element, fvGeometry, sol);
196 return std::move(*this);
197 }
198
199 // specialization for control-volume finite element, simply forwards to the bindElement method
200 template<class FVElementGeometry, class SolutionVector>
201 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
202 const FVElementGeometry& fvGeometry,
203 const SolutionVector& sol) &
204 {
205 bindElement(element, fvGeometry, sol);
206 }
207
213 template<class FVElementGeometry, class SolutionVector>
214 CVFEElementVolumeVariables bindElement(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
223 template<class FVElementGeometry, class SolutionVector>
224 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
225 const FVElementGeometry& fvGeometry,
226 const SolutionVector& sol) &
227 {
228 // get the solution at the dofs of the element
229 auto elemSol = elementSolution(element, sol, fvGeometry.gridGeometry());
230
231 // resize volume variables to the required size
232 volumeVariables_.resize(fvGeometry.numScv());
233 for (auto&& scv : scvs(fvGeometry))
234 volumeVariables_[scv.indexInElement()].update(elemSol, gridVolVars().problem(), element, scv);
235 }
236
237 const VolumeVariables& operator [](std::size_t scvIdx) const
238 { return volumeVariables_[scvIdx]; }
239
240 VolumeVariables& operator [](std::size_t scvIdx)
241 { return volumeVariables_[scvIdx]; }
242
243 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
244 const VolumeVariables& operator [](const ScvOrLocalDof& scvOrLocalDof) const
245 {
246 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
247 return volumeVariables_[scvOrLocalDof.index()];
248 else
249 return volumeVariables_[scvOrLocalDof.indexInElement()];
250 }
251
252 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
253 VolumeVariables& operator [](const ScvOrLocalDof& scvOrLocalDof)
254 {
255 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
256 return volumeVariables_[scvOrLocalDof.index()];
257 else
258 return volumeVariables_[scvOrLocalDof.indexInElement()];
259 }
260
263 { return *gridVolVarsPtr_; }
264
270 { return { *this }; }
271
272private:
273 const GridVolumeVariables* gridVolVarsPtr_;
274 std::vector<VolumeVariables> volumeVariables_;
275};
276
277} // end namespace Dumux
278
279#endif
The local (stencil) volume variables class for control-volume finite element without caching.
Definition: cvfe/elementvolumevariables.hh:153
CVFEElementVolumeVariables 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/elementvolumevariables.hh:191
MutableView asMutableView(GridVolumeVariables &)
return a local view on variables that is always mutable, regardless of the caching policy
Definition: cvfe/elementvolumevariables.hh:269
GVV GridVolumeVariables
export type of the grid volume variables
Definition: cvfe/elementvolumevariables.hh:173
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition: cvfe/elementvolumevariables.hh:262
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: cvfe/elementvolumevariables.hh:201
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: cvfe/elementvolumevariables.hh:179
CVFEElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition: cvfe/elementvolumevariables.hh:182
MutableVariablesView MutableView
export type of the mutable version of the view
Definition: cvfe/elementvolumevariables.hh:176
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: cvfe/elementvolumevariables.hh:224
CVFEElementVolumeVariables 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/elementvolumevariables.hh:214
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: cvfe/elementvolumevariables.hh:100
MutableView asMutableView(GridVolumeVariables &gridVolVars)
return a local view on variables that is always mutable, regardless of the caching policy
Definition: cvfe/elementvolumevariables.hh:138
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: cvfe/elementvolumevariables.hh:123
CVFEElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition: cvfe/elementvolumevariables.hh:68
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition: cvfe/elementvolumevariables.hh:131
CVFEElementVolumeVariables 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/elementvolumevariables.hh:89
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: cvfe/elementvolumevariables.hh:65
GVV GridVolumeVariables
export type of the grid volume variables
Definition: cvfe/elementvolumevariables.hh:59
MutableVariablesView MutableView
export type of the mutable version of the view
Definition: cvfe/elementvolumevariables.hh:62
CVFEElementVolumeVariables 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/elementvolumevariables.hh:113
The local (stencil) volume variables class for control-volume finite element.
Definition: cvfe/elementvolumevariables.hh:32
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: adapt.hh:17
std::ranges::range auto scvs(const FVElementGeometry &fvGeometry, const LocalDof &localDof)
Definition: localdof.hh:79