version 3.11-dev
Loading...
Searching...
No Matches
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>
22
23namespace Dumux {
24
32template<class GVV, bool cachingEnabled>
34
40template<class GVV>
41class CVFEElementVolumeVariables<GVV, /*cachingEnabled*/true>
42{
43 class MutableVariablesView
44 {
45 public:
46 MutableVariablesView(GVV& gridCache)
47 : gridCache_(gridCache) {}
48
49 using VolumeVariables = typename GVV::VolumeVariables;
50
51 template<class SubControlVolume>
52 VolumeVariables& operator [](const SubControlVolume& scv) const
53 { return gridCache_.volVars(scv.elementIndex(), scv.indexInElement()); }
54 private:
55 GVV& gridCache_;
56 };
57
58public:
61
63 using MutableView = MutableVariablesView;
64
66 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
67
71
72 const VolumeVariables& operator [](std::size_t scvIdx) const
73 { return gridVolVars().volVars(eIdx_, scvIdx); }
74
75 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
76 const VolumeVariables& operator [](const ScvOrLocalDof& scvOrLocalDof) const
77 {
78 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
79 return gridVolVars().volVars(eIdx_, scvOrLocalDof.index());
80 else
81 return gridVolVars().volVars(eIdx_, scvOrLocalDof.indexInElement());
82 }
83
89 template<class FVElementGeometry, class SolutionVector>
90 CVFEElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
91 const FVElementGeometry& fvGeometry,
92 const SolutionVector& sol) &&
93 {
94 this->bindElement(element, fvGeometry, sol);
95 return std::move(*this);
96 }
97
98 // For compatibility reasons with the case of not storing the vol vars.
99 // function to be called before assembling an element, preparing the vol vars within the stencil
100 template<class FVElementGeometry, class SolutionVector>
101 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
102 const FVElementGeometry& fvGeometry,
103 const SolutionVector& sol) &
104 {
105 bindElement(element, fvGeometry, sol);
106 }
107
113 template<class FVElementGeometry, class SolutionVector>
114 CVFEElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
115 const FVElementGeometry& fvGeometry,
116 const SolutionVector& sol) &&
117 {
118 this->bindElement(element, fvGeometry, sol);
119 return std::move(*this);
120 }
121
122 // function to prepare the vol vars within the element
123 template<class FVElementGeometry, class SolutionVector>
124 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
125 const FVElementGeometry& fvGeometry,
126 const SolutionVector& sol) &
127 {
128 const auto& gridDiscretization = Deprecated::gridGeometry(fvGeometry);
129 eIdx_ = gridDiscretization.elementMapper().index(element);
130 }
131
134 { return *gridVolVarsPtr_; }
135
142
143private:
144 const GridVolumeVariables* gridVolVarsPtr_;
145 std::size_t eIdx_;
146};
147
148
153template<class GVV>
154class CVFEElementVolumeVariables<GVV, /*cachingEnabled*/false>
155{
156 using ThisType = CVFEElementVolumeVariables<GVV, /*cachingEnabled*/false>;
157
158 class MutableVariablesView
159 {
160 public:
161 MutableVariablesView(ThisType& view)
162 : view_(view) {}
163
164 using VolumeVariables = typename GVV::VolumeVariables;
165
166 template<class SubControlVolume>
167 VolumeVariables& operator [](const SubControlVolume& scv) const
168 { return view_[scv]; }
169 private:
170 ThisType& view_;
171 };
172
173public:
176
178 using MutableView = MutableVariablesView;
179
181 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
182
186
192 template<class FVElementGeometry, class SolutionVector>
193 CVFEElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
194 const FVElementGeometry& fvGeometry,
195 const SolutionVector& sol) &&
196 {
197 this->bindElement(element, fvGeometry, sol);
198 return std::move(*this);
199 }
200
201 // specialization for control-volume finite element, simply forwards to the bindElement method
202 template<class FVElementGeometry, class SolutionVector>
203 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
204 const FVElementGeometry& fvGeometry,
205 const SolutionVector& sol) &
206 {
207 bindElement(element, fvGeometry, sol);
208 }
209
215 template<class FVElementGeometry, class SolutionVector>
216 CVFEElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
217 const FVElementGeometry& fvGeometry,
218 const SolutionVector& sol) &&
219 {
220 this->bindElement(element, fvGeometry, sol);
221 return std::move(*this);
222 }
223
224 // specialization for control-volume finite element
225 template<class FVElementGeometry, class SolutionVector>
226 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
227 const FVElementGeometry& fvGeometry,
228 const SolutionVector& sol) &
229 {
230 // get the solution at the dofs of the element
231 const auto& gridDiscretization = Deprecated::gridGeometry(fvGeometry);
232 auto elemSol = elementSolution(element, sol, gridDiscretization);
233
234 // resize volume variables to the required size
235 volumeVariables_.resize(fvGeometry.numScv());
236 for (auto&& scv : scvs(fvGeometry))
237 volumeVariables_[scv.indexInElement()].update(elemSol, gridVolVars().problem(), element, scv);
238 }
239
240 const VolumeVariables& operator [](std::size_t scvIdx) const
241 { return volumeVariables_[scvIdx]; }
242
243 VolumeVariables& operator [](std::size_t scvIdx)
244 { return volumeVariables_[scvIdx]; }
245
246 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
247 const VolumeVariables& operator [](const ScvOrLocalDof& scvOrLocalDof) const
248 {
249 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
250 return volumeVariables_[scvOrLocalDof.index()];
251 else
252 return volumeVariables_[scvOrLocalDof.indexInElement()];
253 }
254
255 template<class ScvOrLocalDof, typename std::enable_if_t<!std::is_integral<ScvOrLocalDof>::value, int> = 0>
256 VolumeVariables& operator [](const ScvOrLocalDof& scvOrLocalDof)
257 {
258 if constexpr (Concept::LocalDof<ScvOrLocalDof>)
259 return volumeVariables_[scvOrLocalDof.index()];
260 else
261 return volumeVariables_[scvOrLocalDof.indexInElement()];
262 }
263
266 { return *gridVolVarsPtr_; }
267
273 { return { *this }; }
274
275private:
276 const GridVolumeVariables* gridVolVarsPtr_;
277 std::vector<VolumeVariables> volumeVariables_;
278};
279
280} // end namespace Dumux
281
282#endif
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:193
MutableView asMutableView(GridVolumeVariables &)
return a local view on variables that is always mutable, regardless of the caching policy
Definition cvfe/elementvolumevariables.hh:272
GVV GridVolumeVariables
export type of the grid volume variables
Definition cvfe/elementvolumevariables.hh:175
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition cvfe/elementvolumevariables.hh:265
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition cvfe/elementvolumevariables.hh:203
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition cvfe/elementvolumevariables.hh:181
CVFEElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition cvfe/elementvolumevariables.hh:184
MutableVariablesView MutableView
export type of the mutable version of the view
Definition cvfe/elementvolumevariables.hh:178
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition cvfe/elementvolumevariables.hh:226
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:216
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition cvfe/elementvolumevariables.hh:101
MutableView asMutableView(GridVolumeVariables &gridVolVars)
return a local view on variables that is always mutable, regardless of the caching policy
Definition cvfe/elementvolumevariables.hh:140
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition cvfe/elementvolumevariables.hh:124
CVFEElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition cvfe/elementvolumevariables.hh:69
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition cvfe/elementvolumevariables.hh:133
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:90
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition cvfe/elementvolumevariables.hh:66
GVV GridVolumeVariables
export type of the grid volume variables
Definition cvfe/elementvolumevariables.hh:60
MutableVariablesView MutableView
export type of the mutable version of the view
Definition cvfe/elementvolumevariables.hh:63
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:114
The local (stencil) volume variables class for control-volume finite element.
Definition cvfe/elementvolumevariables.hh:33
Helpers for deprecation.
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:82