3.1-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;
70 using FVGridGeometry [[deprecated ("Use GridGeometry instead. Will be removed after 3.1!")]]= GridGeometry;
72 static constexpr std::size_t maxNumElementScvs = (1<<dim);
73
76 : gridGeometryPtr_(&gridGeometry) {}
77
79 const SubControlVolume& scv(LocalIndexType scvIdx) const
80 {
81 return gridGeometry().scvs(eIdx_)[scvIdx];
82 }
83
85 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
86 {
87 return gridGeometry().scvfs(eIdx_)[scvfIdx];
88 }
89
95 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
96 scvs(const BoxFVElementGeometry& fvGeometry)
97 {
98 const auto& g = fvGeometry.gridGeometry();
99 using Iter = typename std::vector<SubControlVolume>::const_iterator;
100 return Dune::IteratorRange<Iter>(g.scvs(fvGeometry.eIdx_).begin(), g.scvs(fvGeometry.eIdx_).end());
101 }
102
108 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
109 scvfs(const BoxFVElementGeometry& fvGeometry)
110 {
111 const auto& g = fvGeometry.gridGeometry();
112 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
113 return Dune::IteratorRange<Iter>(g.scvfs(fvGeometry.eIdx_).begin(), g.scvfs(fvGeometry.eIdx_).end());
114 }
115
117 const FeLocalBasis& feLocalBasis() const
118 {
119 return gridGeometry().feCache().get(elemGeometryType_).localBasis();
120 }
121
123 std::size_t numScv() const
124 {
125 return gridGeometry().scvs(eIdx_).size();
126 }
127
129 std::size_t numScvf() const
130 {
131 return gridGeometry().scvfs(eIdx_).size();
132 }
133
137 void bind(const Element& element)
138 {
139 this->bindElement(element);
140 }
141
145 void bindElement(const Element& element)
146 {
147 elemGeometryType_ = element.type();
148 eIdx_ = gridGeometry().elementMapper().index(element);
149 }
150
152 [[deprecated ("Use gridGeometry() instead. fvGridGeometry() will be removed after 3.1!")]]
154 { return gridGeometry(); }
156 { return *gridGeometryPtr_; }
157
159 bool hasBoundaryScvf() const
160 { return gridGeometry().hasBoundaryScvf(eIdx_); }
161
162private:
163 Dune::GeometryType elemGeometryType_;
164 const GridGeometry* gridGeometryPtr_;
165
166 GridIndexType eIdx_;
167};
168
170template<class GG>
171class BoxFVElementGeometry<GG, false>
172{
173 using GridView = typename GG::GridView;
174 static constexpr int dim = GridView::dimension;
175 static constexpr int dimWorld = GridView::dimensionworld;
176 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
177 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
178 using Element = typename GridView::template Codim<0>::Entity;
179 using CoordScalar = typename GridView::ctype;
180 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
181 using ReferenceElements = typename Dune::ReferenceElements<CoordScalar, dim>;
182
183 using GeometryHelper = BoxGeometryHelper<GridView, dim,
184 typename GG::SubControlVolume,
185 typename GG::SubControlVolumeFace>;
186public:
188 using SubControlVolume = typename GG::SubControlVolume;
190 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
192 using GridGeometry = GG;
193 using FVGridGeometry [[deprecated ("Use GridGeometry instead. Will be removed after 3.1!")]]= GridGeometry;
195 static constexpr std::size_t maxNumElementScvs = (1<<dim);
196
199 : gridGeometryPtr_(&gridGeometry) {}
200
202 const SubControlVolume& scv(LocalIndexType scvIdx) const
203 {
204 return scvs_[scvIdx];
205 }
206
208 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
209 {
210 return scvfs_[scvfIdx];
211 }
212
218 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
219 scvs(const BoxFVElementGeometry& fvGeometry)
220 {
221 using Iter = typename std::vector<SubControlVolume>::const_iterator;
222 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
223 }
224
230 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
231 scvfs(const BoxFVElementGeometry& fvGeometry)
232 {
233 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
234 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
235 }
236
238 const FeLocalBasis& feLocalBasis() const
239 {
240 return gridGeometry().feCache().get(elemGeometryType_).localBasis();
241 }
242
244 std::size_t numScv() const
245 {
246 return scvs_.size();
247 }
248
250 std::size_t numScvf() const
251 {
252 return scvfs_.size();
253 }
254
258 void bind(const Element& element)
259 {
260 this->bindElement(element);
261 }
262
266 void bindElement(const Element& element)
267 {
268 eIdx_ = gridGeometry().elementMapper().index(element);
269 makeElementGeometries(element);
270 }
271
273 [[deprecated ("Use gridGeometry() instead. fvGridGeometry() will be removed after 3.1!")]]
275 { return gridGeometry(); }
277 { return *gridGeometryPtr_; }
278
280 bool hasBoundaryScvf() const
281 { return hasBoundaryScvf_; }
282
283private:
284
285 void makeElementGeometries(const Element& element)
286 {
287 hasBoundaryScvf_ = false;
288
289 // get the element geometry
290 auto elementGeometry = element.geometry();
291 elemGeometryType_ = elementGeometry.type();
292 const auto referenceElement = ReferenceElements::general(elemGeometryType_);
293
294 // get the sub control volume geometries of this element
295 GeometryHelper geometryHelper(elementGeometry);
296
297 // construct the sub control volumes
298 scvs_.resize(elementGeometry.corners());
299 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
300 {
301 // get asssociated dof index
302 const auto dofIdxGlobal = gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim);
303
304 // add scv to the local container
305 scvs_[scvLocalIdx] = SubControlVolume(geometryHelper,
306 scvLocalIdx,
307 eIdx_,
308 dofIdxGlobal);
309 }
310
311 // construct the sub control volume faces
312 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
313 scvfs_.resize(numInnerScvf);
314
315 LocalIndexType scvfLocalIdx = 0;
316 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
317 {
318 // find the local scv indices this scvf is connected to
319 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(referenceElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
320 static_cast<LocalIndexType>(referenceElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
321
322 scvfs_[scvfLocalIdx] = SubControlVolumeFace(geometryHelper,
323 element,
324 elementGeometry,
325 scvfLocalIdx,
326 std::move(localScvIndices),
327 false);
328 }
329
330 // construct the sub control volume faces on the domain boundary
331 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
332 {
333 if (intersection.boundary() && !intersection.neighbor())
334 {
335 const auto isGeometry = intersection.geometry();
336 hasBoundaryScvf_ = true;
337
338 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
339 {
340 // find the scv this scvf is connected to
341 const LocalIndexType insideScvIdx = static_cast<LocalIndexType>(referenceElement.subEntity(intersection.indexInInside(), 1, isScvfLocalIdx, dim));
342 std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx};
343
344 scvfs_.emplace_back(geometryHelper,
345 intersection,
346 isGeometry,
347 isScvfLocalIdx,
348 scvfLocalIdx,
349 std::move(localScvIndices),
350 true);
351
352 // increment local counter
353 scvfLocalIdx++;
354 }
355 }
356 }
357 }
358
360 Dune::GeometryType elemGeometryType_;
361 GridIndexType eIdx_;
362
364 const GridGeometry* gridGeometryPtr_;
365
367 std::vector<SubControlVolume> scvs_;
368 std::vector<SubControlVolumeFace> scvfs_;
369
370 bool hasBoundaryScvf_ = false;
371};
372
373} // end namespace Dumux
374
375#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.
Dune::IteratorRange< typename MultiDomainGlue< DomainGridView, TargetGridView, DomainMapper, TargetMapper >::Intersections::const_iterator > intersections(const MultiDomainGlue< DomainGridView, TargetGridView, DomainMapper, TargetMapper > &glue)
Range generator to iterate with range-based for loops over all intersections as follows: for (const a...
Definition: glue.hh:62
make the local view function available whenever we use the grid geometry
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:117
void bindElement(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:145
BoxFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/box/fvelementgeometry.hh:75
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:96
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/box/fvelementgeometry.hh:123
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/box/fvelementgeometry.hh:79
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/box/fvelementgeometry.hh:129
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/box/fvelementgeometry.hh:65
const GridGeometry & gridGeometry() const
Definition: discretization/box/fvelementgeometry.hh:155
GridGeometry FVGridGeometry
Definition: discretization/box/fvelementgeometry.hh:70
const GridGeometry & fvGridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: discretization/box/fvelementgeometry.hh:153
void bind(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:137
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/box/fvelementgeometry.hh:159
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:109
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:85
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:250
BoxFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/box/fvelementgeometry.hh:198
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/box/fvelementgeometry.hh:192
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/box/fvelementgeometry.hh:280
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:219
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/box/fvelementgeometry.hh:244
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/box/fvelementgeometry.hh:208
const GridGeometry & gridGeometry() const
Definition: discretization/box/fvelementgeometry.hh:276
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:231
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/box/fvelementgeometry.hh:238
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/box/fvelementgeometry.hh:202
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/box/fvelementgeometry.hh:190
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/box/fvelementgeometry.hh:188
void bind(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:258
GridGeometry FVGridGeometry
Definition: discretization/box/fvelementgeometry.hh:193
const GridGeometry & fvGridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: discretization/box/fvelementgeometry.hh:274
void bindElement(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:266