3.2-git
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/geometry/referenceelements.hh>
31#include <dune/localfunctions/lagrange/pqkfactory.hh>
32
36
37namespace Dumux {
38
47template<class GG, bool enableGridGeometryCache>
49
51template<class GG>
52class BoxFVElementGeometry<GG, true>
53{
54 using GridView = typename GG::GridView;
55 static constexpr int dim = GridView::dimension;
56 static constexpr int dimWorld = GridView::dimensionworld;
57 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
58 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
59 using Element = typename GridView::template Codim<0>::Entity;
60 using CoordScalar = typename GridView::ctype;
61 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
62 using ReferenceElements = typename Dune::ReferenceElements<CoordScalar, dim>;
63public:
65 using SubControlVolume = typename GG::SubControlVolume;
67 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
69 using GridGeometry = GG;
71 static constexpr std::size_t maxNumElementScvs = (1<<dim);
72
75 : gridGeometryPtr_(&gridGeometry) {}
76
78 const SubControlVolume& scv(LocalIndexType scvIdx) const
79 {
80 return gridGeometry().scvs(eIdx_)[scvIdx];
81 }
82
84 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
85 {
86 return gridGeometry().scvfs(eIdx_)[scvfIdx];
87 }
88
94 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
95 scvs(const BoxFVElementGeometry& fvGeometry)
96 {
97 const auto& g = fvGeometry.gridGeometry();
98 using Iter = typename std::vector<SubControlVolume>::const_iterator;
99 return Dune::IteratorRange<Iter>(g.scvs(fvGeometry.eIdx_).begin(), g.scvs(fvGeometry.eIdx_).end());
100 }
101
107 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
108 scvfs(const BoxFVElementGeometry& fvGeometry)
109 {
110 const auto& g = fvGeometry.gridGeometry();
111 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
112 return Dune::IteratorRange<Iter>(g.scvfs(fvGeometry.eIdx_).begin(), g.scvfs(fvGeometry.eIdx_).end());
113 }
114
116 const FeLocalBasis& feLocalBasis() const
117 {
118 return gridGeometry().feCache().get(elemGeometryType_).localBasis();
119 }
120
122 std::size_t numScv() const
123 {
124 return gridGeometry().scvs(eIdx_).size();
125 }
126
128 std::size_t numScvf() const
129 {
130 return gridGeometry().scvfs(eIdx_).size();
131 }
132
136 void bind(const Element& element)
137 {
138 this->bindElement(element);
139 }
140
144 void bindElement(const Element& element)
145 {
146 elemGeometryType_ = element.type();
147 eIdx_ = gridGeometry().elementMapper().index(element);
148 }
149
152 { return *gridGeometryPtr_; }
153
155 bool hasBoundaryScvf() const
156 { return gridGeometry().hasBoundaryScvf(eIdx_); }
157
158private:
159 Dune::GeometryType elemGeometryType_;
160 const GridGeometry* gridGeometryPtr_;
161
162 GridIndexType eIdx_;
163};
164
166template<class GG>
167class BoxFVElementGeometry<GG, false>
168{
169 using GridView = typename GG::GridView;
170 static constexpr int dim = GridView::dimension;
171 static constexpr int dimWorld = GridView::dimensionworld;
172 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
173 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
174 using Element = typename GridView::template Codim<0>::Entity;
175 using CoordScalar = typename GridView::ctype;
176 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
177 using ReferenceElements = typename Dune::ReferenceElements<CoordScalar, dim>;
178
179 using GeometryHelper = BoxGeometryHelper<GridView, dim,
180 typename GG::SubControlVolume,
181 typename GG::SubControlVolumeFace>;
182public:
184 using SubControlVolume = typename GG::SubControlVolume;
186 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
188 using GridGeometry = GG;
190 static constexpr std::size_t maxNumElementScvs = (1<<dim);
191
194 : gridGeometryPtr_(&gridGeometry) {}
195
197 const SubControlVolume& scv(LocalIndexType scvIdx) const
198 {
199 return scvs_[scvIdx];
200 }
201
203 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
204 {
205 return scvfs_[scvfIdx];
206 }
207
213 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
214 scvs(const BoxFVElementGeometry& fvGeometry)
215 {
216 using Iter = typename std::vector<SubControlVolume>::const_iterator;
217 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
218 }
219
225 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
226 scvfs(const BoxFVElementGeometry& fvGeometry)
227 {
228 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
229 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
230 }
231
233 const FeLocalBasis& feLocalBasis() const
234 {
235 return gridGeometry().feCache().get(elemGeometryType_).localBasis();
236 }
237
239 std::size_t numScv() const
240 {
241 return scvs_.size();
242 }
243
245 std::size_t numScvf() const
246 {
247 return scvfs_.size();
248 }
249
253 void bind(const Element& element)
254 {
255 this->bindElement(element);
256 }
257
261 void bindElement(const Element& element)
262 {
263 eIdx_ = gridGeometry().elementMapper().index(element);
264 makeElementGeometries(element);
265 }
266
269 { return *gridGeometryPtr_; }
270
272 bool hasBoundaryScvf() const
273 { return hasBoundaryScvf_; }
274
275private:
276
277 void makeElementGeometries(const Element& element)
278 {
279 hasBoundaryScvf_ = false;
280
281 // get the element geometry
282 auto elementGeometry = element.geometry();
283 elemGeometryType_ = elementGeometry.type();
284 const auto referenceElement = ReferenceElements::general(elemGeometryType_);
285
286 // get the sub control volume geometries of this element
287 GeometryHelper geometryHelper(elementGeometry);
288
289 // construct the sub control volumes
290 scvs_.resize(elementGeometry.corners());
291 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
292 {
293 // get asssociated dof index
294 const auto dofIdxGlobal = gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim);
295
296 // add scv to the local container
297 scvs_[scvLocalIdx] = SubControlVolume(geometryHelper,
298 scvLocalIdx,
299 eIdx_,
300 dofIdxGlobal);
301 }
302
303 // construct the sub control volume faces
304 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
305 scvfs_.resize(numInnerScvf);
306
307 LocalIndexType scvfLocalIdx = 0;
308 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
309 {
310 // find the local scv indices this scvf is connected to
311 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(referenceElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
312 static_cast<LocalIndexType>(referenceElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
313
314 scvfs_[scvfLocalIdx] = SubControlVolumeFace(geometryHelper,
315 element,
316 elementGeometry,
317 scvfLocalIdx,
318 std::move(localScvIndices),
319 false);
320 }
321
322 // construct the sub control volume faces on the domain boundary
323 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
324 {
325 if (intersection.boundary() && !intersection.neighbor())
326 {
327 const auto isGeometry = intersection.geometry();
328 hasBoundaryScvf_ = true;
329
330 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
331 {
332 // find the scv this scvf is connected to
333 const LocalIndexType insideScvIdx = static_cast<LocalIndexType>(referenceElement.subEntity(intersection.indexInInside(), 1, isScvfLocalIdx, dim));
334 std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx};
335
336 scvfs_.emplace_back(geometryHelper,
337 intersection,
338 isGeometry,
339 isScvfLocalIdx,
340 scvfLocalIdx,
341 std::move(localScvIndices),
342 true);
343
344 // increment local counter
345 scvfLocalIdx++;
346 }
347 }
348 }
349 }
350
352 Dune::GeometryType elemGeometryType_;
353 GridIndexType eIdx_;
354
356 const GridGeometry* gridGeometryPtr_;
357
359 std::vector<SubControlVolume> scvs_;
360 std::vector<SubControlVolumeFace> scvfs_;
361
362 bool hasBoundaryScvf_ = false;
363};
364
365} // end namespace Dumux
366
367#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:37
Base class for the finite volume geometry vector for box models This builds up the sub control volume...
Definition: discretization/box/fvelementgeometry.hh:48
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/box/fvelementgeometry.hh:116
void bindElement(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:144
BoxFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/box/fvelementgeometry.hh:74
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:95
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/box/fvelementgeometry.hh:122
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/box/fvelementgeometry.hh:78
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/box/fvelementgeometry.hh:128
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/box/fvelementgeometry.hh:65
const GridGeometry & gridGeometry() const
The grid geometry we are a restriction of.
Definition: discretization/box/fvelementgeometry.hh:151
void bind(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:136
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/box/fvelementgeometry.hh:155
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:108
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/box/fvelementgeometry.hh:67
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/box/fvelementgeometry.hh:84
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/box/fvelementgeometry.hh:69
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/box/fvelementgeometry.hh:245
BoxFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/box/fvelementgeometry.hh:193
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/box/fvelementgeometry.hh:188
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/box/fvelementgeometry.hh:272
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:214
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/box/fvelementgeometry.hh:239
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/box/fvelementgeometry.hh:203
const GridGeometry & gridGeometry() const
The grid geometry we are a restriction of.
Definition: discretization/box/fvelementgeometry.hh:268
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:226
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/box/fvelementgeometry.hh:233
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/box/fvelementgeometry.hh:197
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/box/fvelementgeometry.hh:186
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/box/fvelementgeometry.hh:184
void bind(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:253
void bindElement(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:261