3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
elementfacevariables.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_DISCRETIZATION_STAGGERED_ELEMENTFACEVARIABLES_HH
25#define DUMUX_DISCRETIZATION_STAGGERED_ELEMENTFACEVARIABLES_HH
26
27#include <algorithm>
28#include <cassert>
29#include <vector>
30#include <utility>
31
32namespace Dumux {
33
38template<class GridFaceVariables, bool cachingEnabled>
40{};
41
46template<class GFV>
47class StaggeredElementFaceVariables<GFV, /*cachingEnabled*/true>
48{
49public:
51 using GridFaceVariables = GFV;
52
54 using FaceVariables = typename GridFaceVariables::FaceVariables;
55
56 StaggeredElementFaceVariables(const GridFaceVariables& gridFaceVariables) : gridFaceVariablesPtr_(&gridFaceVariables) {}
57
59 template<class SubControlVolumeFace, typename std::enable_if_t<!std::is_integral<SubControlVolumeFace>::value, int> = 0>
60 const FaceVariables& operator [](const SubControlVolumeFace& scvf) const
61 { return gridFaceVariables().faceVars(scvf.index()); }
62
65 const FaceVariables& operator [](const std::size_t scvfIdx) const
66 { return gridFaceVariables().faceVars(scvfIdx); }
67
73 template<class FVElementGeometry, class SolutionVector>
74 StaggeredElementFaceVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
75 const FVElementGeometry& fvGeometry,
76 const SolutionVector& sol) &&
77 {
78 this->bind_(element, fvGeometry, sol);
79 return std::move(*this);
80 }
81
82 template<class FVElementGeometry, class SolutionVector>
83 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
84 const FVElementGeometry& fvGeometry,
85 const SolutionVector& sol) &
86 { this->bind_(element, fvGeometry, sol); }
87
93 template<class FVElementGeometry, class SolutionVector>
94 StaggeredElementFaceVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
95 const FVElementGeometry& fvGeometry,
96 const SolutionVector& sol) &&
97 {
98 this->bindElement_(element, fvGeometry, sol);
99 return std::move(*this);
100 }
101
102 template<class FVElementGeometry, class SolutionVector>
103 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
104 const FVElementGeometry& fvGeometry,
105 const SolutionVector& sol) &
106 { this->bindElement_(element, fvGeometry, sol); }
107
110 { return *gridFaceVariablesPtr_; }
111
112private:
113
116 template<class FVElementGeometry, class SolutionVector>
117 void bind_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
118 const FVElementGeometry& fvGeometry,
119 const SolutionVector& sol)
120 {}
121
124 template<class FVElementGeometry, class SolutionVector>
125 void bindElement_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
126 const FVElementGeometry& fvGeometry,
127 const SolutionVector& sol)
128 {}
129
130 const GridFaceVariables* gridFaceVariablesPtr_;
131};
132
137template<class GFV>
138class StaggeredElementFaceVariables<GFV, /*cachingEnabled*/false>
139{
140public:
142 using GridFaceVariables = GFV;
143
145 using FaceVariables = typename GridFaceVariables::FaceVariables;
146
147 StaggeredElementFaceVariables(const GridFaceVariables& globalFacesVars) : gridFaceVariablesPtr_(&globalFacesVars) {}
148
150 template<class SubControlVolumeFace, typename std::enable_if_t<!std::is_integral<SubControlVolumeFace>::value, int> = 0>
151 const FaceVariables& operator [](const SubControlVolumeFace& scvf) const
152 { return faceVariables_[scvf.localFaceIdx()]; }
153
155 const FaceVariables& operator [](const std::size_t scvfIdx) const
156 { return faceVariables_[getLocalIdx_(scvfIdx)]; }
157
159 template<class SubControlVolumeFace, typename std::enable_if_t<!std::is_integral<SubControlVolumeFace>::value, int> = 0>
160 FaceVariables& operator [](const SubControlVolumeFace& scvf)
161 { return faceVariables_[scvf.localFaceIdx()]; }
162
163 // operator for the access with an index
164 FaceVariables& operator [](const std::size_t scvfIdx)
165 { return faceVariables_[getLocalIdx_(scvfIdx)]; }
166
172 template<class FVElementGeometry, class SolutionVector>
173 StaggeredElementFaceVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
174 const FVElementGeometry& fvGeometry,
175 const SolutionVector& sol) &&
176 {
177 this->bind_(element, fvGeometry, sol);
178 return std::move(*this);
179 }
180
181 template<class FVElementGeometry, class SolutionVector>
182 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
183 const FVElementGeometry& fvGeometry,
184 const SolutionVector& sol) &
185 { this->bind_(element, fvGeometry, sol); }
186
192 template<class FVElementGeometry, class SolutionVector>
193 StaggeredElementFaceVariables bindElement(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 template<class FVElementGeometry, class SolutionVector>
202 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
203 const FVElementGeometry& fvGeometry,
204 const SolutionVector& sol) &
205 { this->bindElement_(element, fvGeometry, sol); }
206
209 { return *gridFaceVariablesPtr_; }
210
211private:
212
215 template<class FVElementGeometry, class SolutionVector>
216 void bind_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
217 const FVElementGeometry& fvGeometry,
218 const SolutionVector& sol)
219 {
220 faceVariables_.resize(fvGeometry.numScvf());
221 faceVarIndices_.resize(fvGeometry.numScvf());
222
223 constexpr auto faceIdx = FVElementGeometry::GridGeometry::faceIdx();
224
225 for(auto&& scvf : scvfs(fvGeometry))
226 {
227 faceVariables_[scvf.localFaceIdx()].update(sol[faceIdx], gridFaceVariables().problem(), element, fvGeometry, scvf);
228 faceVarIndices_[scvf.localFaceIdx()] = scvf.index();
229 }
230 }
231
234 template<class FVElementGeometry, class SolutionVector>
235 void bindElement_(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
236 const FVElementGeometry& fvGeometry,
237 const SolutionVector& sol)
238 {
239 faceVariables_.resize(fvGeometry.numScvf());
240 faceVarIndices_.resize(fvGeometry.numScvf());
241
242 constexpr auto faceIdx = FVElementGeometry::GridGeometry::faceIdx();
243
244 for(auto&& scvf : scvfs(fvGeometry))
245 {
246 faceVariables_[scvf.localFaceIdx()].updateOwnFaceOnly(sol[faceIdx][scvf.dofIndex()]);
247 faceVarIndices_[scvf.localFaceIdx()] = scvf.index();
248 }
249 }
250
251 int getLocalIdx_(const int scvfIdx) const
252 {
253 auto it = std::find(faceVarIndices_.begin(), faceVarIndices_.end(), scvfIdx);
254 assert(it != faceVarIndices_.end() && "Could not find the current face variables for scvfIdx!");
255 return std::distance(faceVarIndices_.begin(), it);
256 }
257
258 const GridFaceVariables* gridFaceVariablesPtr_;
259 std::vector<std::size_t> faceVarIndices_;
260 std::vector<FaceVariables> faceVariables_;
261};
262
263} // end namespace
264
265#endif
static ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:294
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
Base class for the face variables vector.
Definition: elementfacevariables.hh:40
StaggeredElementFaceVariables 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: elementfacevariables.hh:74
typename GridFaceVariables::FaceVariables FaceVariables
export type of the volume variables
Definition: elementfacevariables.hh:54
StaggeredElementFaceVariables(const GridFaceVariables &gridFaceVariables)
Definition: elementfacevariables.hh:56
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: elementfacevariables.hh:103
StaggeredElementFaceVariables 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: elementfacevariables.hh:94
const GridFaceVariables & gridFaceVariables() const
The global volume variables object we are a restriction of.
Definition: elementfacevariables.hh:109
GFV GridFaceVariables
export type of the grid volume variables
Definition: elementfacevariables.hh:51
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: elementfacevariables.hh:83
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: elementfacevariables.hh:202
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: elementfacevariables.hh:182
StaggeredElementFaceVariables(const GridFaceVariables &globalFacesVars)
Definition: elementfacevariables.hh:147
typename GridFaceVariables::FaceVariables FaceVariables
export type of the volume variables
Definition: elementfacevariables.hh:145
StaggeredElementFaceVariables 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: elementfacevariables.hh:193
const GridFaceVariables & gridFaceVariables() const
The global volume variables object we are a restriction of.
Definition: elementfacevariables.hh:208
GFV GridFaceVariables
export type of the grid volume variables
Definition: elementfacevariables.hh:142
StaggeredElementFaceVariables 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: elementfacevariables.hh:173