3.5-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 <optional>
30#include <utility>
31#include <dune/geometry/type.hh>
32#include <dune/localfunctions/lagrange/pqkfactory.hh>
33
37
38namespace Dumux {
39
48template<class GG, bool enableGridGeometryCache>
50
52template<class GG>
53class BoxFVElementGeometry<GG, true>
54{
55 using GridView = typename GG::GridView;
56 static constexpr int dim = GridView::dimension;
57 static constexpr int dimWorld = GridView::dimensionworld;
58 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
59 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
60 using CoordScalar = typename GridView::ctype;
61 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
62public:
64 using Element = typename GridView::template Codim<0>::Entity;
66 using SubControlVolume = typename GG::SubControlVolume;
68 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
70 using GridGeometry = GG;
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(element_->type()).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
140 {
141 this->bindElement(element);
142 return std::move(*this);
143 }
144
148 void bind(const Element& element) &
149 { this->bindElement(element); }
150
157 {
158 this->bindElement(element);
159 return std::move(*this);
160 }
161
165 void bindElement(const Element& element) &
166 {
167 element_ = element;
168 // cache element index
169 eIdx_ = gridGeometry().elementMapper().index(element);
170 }
171
173 bool isBound() const
174 { return static_cast<bool>(element_); }
175
177 const Element& element() const
178 { return *element_; }
179
182 { return *gridGeometryPtr_; }
183
185 bool hasBoundaryScvf() const
186 { return gridGeometry().hasBoundaryScvf(eIdx_); }
187
188private:
189 const GridGeometry* gridGeometryPtr_;
190 GridIndexType eIdx_;
191
192 std::optional<Element> element_;
193};
194
196template<class GG>
197class BoxFVElementGeometry<GG, false>
198{
199 using GridView = typename GG::GridView;
200 static constexpr int dim = GridView::dimension;
201 static constexpr int dimWorld = GridView::dimensionworld;
202 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
203 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
204 using CoordScalar = typename GridView::ctype;
205 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
206
207 using GeometryHelper = BoxGeometryHelper<GridView, dim,
208 typename GG::SubControlVolume,
209 typename GG::SubControlVolumeFace>;
210public:
212 using Element = typename GridView::template Codim<0>::Entity;
214 using SubControlVolume = typename GG::SubControlVolume;
216 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
218 using GridGeometry = GG;
220 static constexpr std::size_t maxNumElementScvs = (1<<dim);
221
224 : gridGeometryPtr_(&gridGeometry) {}
225
227 const SubControlVolume& scv(LocalIndexType scvIdx) const
228 {
229 return scvs_[scvIdx];
230 }
231
233 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
234 {
235 return scvfs_[scvfIdx];
236 }
237
243 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
244 scvs(const BoxFVElementGeometry& fvGeometry)
245 {
246 using Iter = typename std::vector<SubControlVolume>::const_iterator;
247 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
248 }
249
255 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
256 scvfs(const BoxFVElementGeometry& fvGeometry)
257 {
258 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
259 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
260 }
261
263 const FeLocalBasis& feLocalBasis() const
264 {
265 return gridGeometry().feCache().get(element_->type()).localBasis();
266 }
267
269 std::size_t numScv() const
270 {
271 return scvs_.size();
272 }
273
275 std::size_t numScvf() const
276 {
277 return scvfs_.size();
278 }
279
286 {
287 this->bindElement(element);
288 return std::move(*this);
289 }
290
294 void bind(const Element& element) &
295 { this->bindElement(element); }
296
303 {
304 this->bindElement(element);
305 return std::move(*this);
306 }
307
311 void bindElement(const Element& element) &
312 {
313 element_ = element;
314 eIdx_ = gridGeometry().elementMapper().index(element);
315 makeElementGeometries_();
316 }
317
319 bool isBound() const
320 { return static_cast<bool>(element_); }
321
323 const Element& element() const
324 { return *element_; }
325
328 { return *gridGeometryPtr_; }
329
331 bool hasBoundaryScvf() const
332 { return hasBoundaryScvf_; }
333
334private:
335
336 void makeElementGeometries_()
337 {
338 hasBoundaryScvf_ = false;
339
340 // get the element geometry
341 const auto& element = *element_;
342 const auto elementGeometry = element.geometry();
343 const auto refElement = referenceElement(elementGeometry);
344
345 // get the sub control volume geometries of this element
346 GeometryHelper geometryHelper(elementGeometry);
347
348 // construct the sub control volumes
349 scvs_.resize(elementGeometry.corners());
350 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
351 {
352 // get asssociated dof index
353 const auto dofIdxGlobal = gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim);
354
355 // add scv to the local container
356 scvs_[scvLocalIdx] = SubControlVolume(geometryHelper,
357 scvLocalIdx,
358 eIdx_,
359 dofIdxGlobal);
360 }
361
362 // construct the sub control volume faces
363 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
364 scvfs_.resize(numInnerScvf);
365
366 LocalIndexType scvfLocalIdx = 0;
367 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
368 {
369 // find the local scv indices this scvf is connected to
370 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
371 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
372
373 scvfs_[scvfLocalIdx] = SubControlVolumeFace(geometryHelper,
374 element,
375 elementGeometry,
376 scvfLocalIdx,
377 std::move(localScvIndices),
378 false);
379 }
380
381 // construct the sub control volume faces on the domain boundary
382 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
383 {
384 if (intersection.boundary() && !intersection.neighbor())
385 {
386 const auto isGeometry = intersection.geometry();
387 hasBoundaryScvf_ = true;
388
389 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
390 {
391 // find the scv this scvf is connected to
392 const LocalIndexType insideScvIdx = static_cast<LocalIndexType>(refElement.subEntity(intersection.indexInInside(), 1, isScvfLocalIdx, dim));
393 std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx};
394
395 scvfs_.emplace_back(geometryHelper,
396 intersection,
397 isGeometry,
398 isScvfLocalIdx,
399 scvfLocalIdx,
400 std::move(localScvIndices),
401 true);
402
403 // increment local counter
404 scvfLocalIdx++;
405 }
406 }
407 }
408 }
409
411 GridIndexType eIdx_;
412 std::optional<Element> element_;
413
415 const GridGeometry* gridGeometryPtr_;
416
418 std::vector<SubControlVolume> scvs_;
419 std::vector<SubControlVolumeFace> scvfs_;
420
421 bool hasBoundaryScvf_ = false;
422};
423
424} // end namespace Dumux
425
426#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:49
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/box/fvelementgeometry.hh:173
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/box/fvelementgeometry.hh:117
BoxFVElementGeometry bindElement(const Element &element) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/box/fvelementgeometry.hh:156
const Element & element() const
The bound element.
Definition: discretization/box/fvelementgeometry.hh:177
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:66
const GridGeometry & gridGeometry() const
The grid geometry we are a restriction of.
Definition: discretization/box/fvelementgeometry.hh:181
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/box/fvelementgeometry.hh:185
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:109
void bind(const Element &element) &
Definition: discretization/box/fvelementgeometry.hh:148
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/box/fvelementgeometry.hh:68
void bindElement(const Element &element) &
Definition: discretization/box/fvelementgeometry.hh:165
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/box/fvelementgeometry.hh:85
BoxFVElementGeometry bind(const Element &element) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/box/fvelementgeometry.hh:139
typename GridView::template Codim< 0 >::Entity Element
export the element type
Definition: discretization/box/fvelementgeometry.hh:64
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/box/fvelementgeometry.hh:70
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/box/fvelementgeometry.hh:319
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/box/fvelementgeometry.hh:275
BoxFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/box/fvelementgeometry.hh:223
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/box/fvelementgeometry.hh:218
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/box/fvelementgeometry.hh:331
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:244
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/box/fvelementgeometry.hh:269
void bindElement(const Element &element) &
Definition: discretization/box/fvelementgeometry.hh:311
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/box/fvelementgeometry.hh:233
const GridGeometry & gridGeometry() const
The grid geometry we are a restriction of.
Definition: discretization/box/fvelementgeometry.hh:327
typename GridView::template Codim< 0 >::Entity Element
export the element type
Definition: discretization/box/fvelementgeometry.hh:212
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:256
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/box/fvelementgeometry.hh:263
const Element & element() const
The bound element.
Definition: discretization/box/fvelementgeometry.hh:323
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/box/fvelementgeometry.hh:227
BoxFVElementGeometry bind(const Element &element) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/box/fvelementgeometry.hh:285
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/box/fvelementgeometry.hh:216
BoxFVElementGeometry bindElement(const Element &element) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: discretization/box/fvelementgeometry.hh:302
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/box/fvelementgeometry.hh:214
void bind(const Element &element) &
Definition: discretization/box/fvelementgeometry.hh:294