3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
discretization/box/fvelementgeometry.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 *****************************************************************************/
26#ifndef DUMUX_DISCRETIZATION_BOX_FV_ELEMENT_GEOMETRY_HH
27#define DUMUX_DISCRETIZATION_BOX_FV_ELEMENT_GEOMETRY_HH
28
29#include <dune/geometry/type.hh>
30#include <dune/localfunctions/lagrange/pqkfactory.hh>
31
35
36namespace Dumux {
37
46template<class GG, bool enableGridGeometryCache>
48
50template<class GG>
51class BoxFVElementGeometry<GG, true>
52{
53 using GridView = typename GG::GridView;
54 static constexpr int dim = GridView::dimension;
55 static constexpr int dimWorld = GridView::dimensionworld;
56 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
57 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
58 using CoordScalar = typename GridView::ctype;
59 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
60public:
62 using Element = typename GridView::template Codim<0>::Entity;
64 using SubControlVolume = typename GG::SubControlVolume;
66 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
68 using GridGeometry = GG;
70 static constexpr std::size_t maxNumElementScvs = (1<<dim);
71
74 : gridGeometryPtr_(&gridGeometry) {}
75
77 const SubControlVolume& scv(LocalIndexType scvIdx) const
78 {
79 return gridGeometry().scvs(eIdx_)[scvIdx];
80 }
81
83 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
84 {
85 return gridGeometry().scvfs(eIdx_)[scvfIdx];
86 }
87
93 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
94 scvs(const BoxFVElementGeometry& fvGeometry)
95 {
96 const auto& g = fvGeometry.gridGeometry();
97 using Iter = typename std::vector<SubControlVolume>::const_iterator;
98 return Dune::IteratorRange<Iter>(g.scvs(fvGeometry.eIdx_).begin(), g.scvs(fvGeometry.eIdx_).end());
99 }
100
106 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
107 scvfs(const BoxFVElementGeometry& fvGeometry)
108 {
109 const auto& g = fvGeometry.gridGeometry();
110 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
111 return Dune::IteratorRange<Iter>(g.scvfs(fvGeometry.eIdx_).begin(), g.scvfs(fvGeometry.eIdx_).end());
112 }
113
115 const FeLocalBasis& feLocalBasis() const
116 {
117 return gridGeometry().feCache().get(elemGeometryType_).localBasis();
118 }
119
121 std::size_t numScv() const
122 {
123 return gridGeometry().scvs(eIdx_).size();
124 }
125
127 std::size_t numScvf() const
128 {
129 return gridGeometry().scvfs(eIdx_).size();
130 }
131
135 void bind(const Element& element)
136 {
137 this->bindElement(element);
138 }
139
143 void bindElement(const Element& element)
144 {
145 elemGeometryType_ = element.type();
146 eIdx_ = gridGeometry().elementMapper().index(element);
147 }
148
151 { return *gridGeometryPtr_; }
152
154 bool hasBoundaryScvf() const
155 { return gridGeometry().hasBoundaryScvf(eIdx_); }
156
157private:
158 Dune::GeometryType elemGeometryType_;
159 const GridGeometry* gridGeometryPtr_;
160
161 GridIndexType eIdx_;
162};
163
165template<class GG>
166class BoxFVElementGeometry<GG, false>
167{
168 using GridView = typename GG::GridView;
169 static constexpr int dim = GridView::dimension;
170 static constexpr int dimWorld = GridView::dimensionworld;
171 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
172 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
173 using CoordScalar = typename GridView::ctype;
174 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
175
176 using GeometryHelper = BoxGeometryHelper<GridView, dim,
177 typename GG::SubControlVolume,
178 typename GG::SubControlVolumeFace>;
179public:
181 using Element = typename GridView::template Codim<0>::Entity;
183 using SubControlVolume = typename GG::SubControlVolume;
185 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
187 using GridGeometry = GG;
189 static constexpr std::size_t maxNumElementScvs = (1<<dim);
190
193 : gridGeometryPtr_(&gridGeometry) {}
194
196 const SubControlVolume& scv(LocalIndexType scvIdx) const
197 {
198 return scvs_[scvIdx];
199 }
200
202 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
203 {
204 return scvfs_[scvfIdx];
205 }
206
212 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
213 scvs(const BoxFVElementGeometry& fvGeometry)
214 {
215 using Iter = typename std::vector<SubControlVolume>::const_iterator;
216 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
217 }
218
224 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
225 scvfs(const BoxFVElementGeometry& fvGeometry)
226 {
227 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
228 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
229 }
230
232 const FeLocalBasis& feLocalBasis() const
233 {
234 return gridGeometry().feCache().get(elemGeometryType_).localBasis();
235 }
236
238 std::size_t numScv() const
239 {
240 return scvs_.size();
241 }
242
244 std::size_t numScvf() const
245 {
246 return scvfs_.size();
247 }
248
252 void bind(const Element& element)
253 {
254 this->bindElement(element);
255 }
256
260 void bindElement(const Element& element)
261 {
262 eIdx_ = gridGeometry().elementMapper().index(element);
263 makeElementGeometries(element);
264 }
265
268 { return *gridGeometryPtr_; }
269
271 bool hasBoundaryScvf() const
272 { return hasBoundaryScvf_; }
273
274private:
275
276 void makeElementGeometries(const Element& element)
277 {
278 hasBoundaryScvf_ = false;
279
280 // get the element geometry
281 auto elementGeometry = element.geometry();
282 elemGeometryType_ = elementGeometry.type();
283 const auto refElement = referenceElement(elementGeometry);
284
285 // get the sub control volume geometries of this element
286 GeometryHelper geometryHelper(elementGeometry);
287
288 // construct the sub control volumes
289 scvs_.resize(elementGeometry.corners());
290 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
291 {
292 // get asssociated dof index
293 const auto dofIdxGlobal = gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim);
294
295 // add scv to the local container
296 scvs_[scvLocalIdx] = SubControlVolume(geometryHelper,
297 scvLocalIdx,
298 eIdx_,
299 dofIdxGlobal);
300 }
301
302 // construct the sub control volume faces
303 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
304 scvfs_.resize(numInnerScvf);
305
306 LocalIndexType scvfLocalIdx = 0;
307 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
308 {
309 // find the local scv indices this scvf is connected to
310 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
311 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
312
313 scvfs_[scvfLocalIdx] = SubControlVolumeFace(geometryHelper,
314 element,
315 elementGeometry,
316 scvfLocalIdx,
317 std::move(localScvIndices),
318 false);
319 }
320
321 // construct the sub control volume faces on the domain boundary
322 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
323 {
324 if (intersection.boundary() && !intersection.neighbor())
325 {
326 const auto isGeometry = intersection.geometry();
327 hasBoundaryScvf_ = true;
328
329 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
330 {
331 // find the scv this scvf is connected to
332 const LocalIndexType insideScvIdx = static_cast<LocalIndexType>(refElement.subEntity(intersection.indexInInside(), 1, isScvfLocalIdx, dim));
333 std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx};
334
335 scvfs_.emplace_back(geometryHelper,
336 intersection,
337 isGeometry,
338 isScvfLocalIdx,
339 scvfLocalIdx,
340 std::move(localScvIndices),
341 true);
342
343 // increment local counter
344 scvfLocalIdx++;
345 }
346 }
347 }
348 }
349
351 Dune::GeometryType elemGeometryType_;
352 GridIndexType eIdx_;
353
355 const GridGeometry* gridGeometryPtr_;
356
358 std::vector<SubControlVolume> scvs_;
359 std::vector<SubControlVolumeFace> scvfs_;
360
361 bool hasBoundaryScvf_ = false;
362};
363
364} // end namespace Dumux
365
366#endif
Defines the index types used for grid and local indices.
Helper class constructing the dual grid finite volume geometries for the box discretizazion method.
Class providing iterators over sub control volumes and sub control volume faces of an element.
Definition: adapt.hh:29
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
unsigned int LocalIndex
Definition: indextraits.hh:40
Create sub control volumes and sub control volume face geometries.
Definition: boxgeometryhelper.hh:36
Base class for the finite volume geometry vector for box models This builds up the sub control volume...
Definition: discretization/box/fvelementgeometry.hh:47
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/box/fvelementgeometry.hh:115
void bindElement(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:143
BoxFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/box/fvelementgeometry.hh:73
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:94
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/box/fvelementgeometry.hh:121
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/box/fvelementgeometry.hh:77
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/box/fvelementgeometry.hh:127
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/box/fvelementgeometry.hh:64
const GridGeometry & gridGeometry() const
The grid geometry we are a restriction of.
Definition: discretization/box/fvelementgeometry.hh:150
void bind(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:135
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/box/fvelementgeometry.hh:154
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:107
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/box/fvelementgeometry.hh:66
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/box/fvelementgeometry.hh:83
typename GridView::template Codim< 0 >::Entity Element
export the element type
Definition: discretization/box/fvelementgeometry.hh:62
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/box/fvelementgeometry.hh:68
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/box/fvelementgeometry.hh:244
BoxFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/box/fvelementgeometry.hh:192
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/box/fvelementgeometry.hh:187
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/box/fvelementgeometry.hh:271
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:213
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/box/fvelementgeometry.hh:238
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/box/fvelementgeometry.hh:202
const GridGeometry & gridGeometry() const
The grid geometry we are a restriction of.
Definition: discretization/box/fvelementgeometry.hh:267
typename GridView::template Codim< 0 >::Entity Element
export the element type
Definition: discretization/box/fvelementgeometry.hh:181
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:225
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/box/fvelementgeometry.hh:232
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/box/fvelementgeometry.hh:196
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/box/fvelementgeometry.hh:185
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/box/fvelementgeometry.hh:183
void bind(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:252
void bindElement(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:260