3.4
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 <dune/geometry/type.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 CoordScalar = typename GridView::ctype;
60 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
61public:
63 using Element = typename GridView::template Codim<0>::Entity;
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(element_->type()).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 element_ = element;
147 // cache element index
148 eIdx_ = gridGeometry().elementMapper().index(element);
149 }
150
152 bool isBound() const
153 { return static_cast<bool>(element_); }
154
156 const Element& element() const
157 { return *element_; }
158
161 { return *gridGeometryPtr_; }
162
164 bool hasBoundaryScvf() const
165 { return gridGeometry().hasBoundaryScvf(eIdx_); }
166
167private:
168 const GridGeometry* gridGeometryPtr_;
169 GridIndexType eIdx_;
170
171 std::optional<Element> element_;
172};
173
175template<class GG>
176class BoxFVElementGeometry<GG, false>
177{
178 using GridView = typename GG::GridView;
179 static constexpr int dim = GridView::dimension;
180 static constexpr int dimWorld = GridView::dimensionworld;
181 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
182 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
183 using CoordScalar = typename GridView::ctype;
184 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
185
186 using GeometryHelper = BoxGeometryHelper<GridView, dim,
187 typename GG::SubControlVolume,
188 typename GG::SubControlVolumeFace>;
189public:
191 using Element = typename GridView::template Codim<0>::Entity;
193 using SubControlVolume = typename GG::SubControlVolume;
195 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
197 using GridGeometry = GG;
199 static constexpr std::size_t maxNumElementScvs = (1<<dim);
200
203 : gridGeometryPtr_(&gridGeometry) {}
204
206 const SubControlVolume& scv(LocalIndexType scvIdx) const
207 {
208 return scvs_[scvIdx];
209 }
210
212 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
213 {
214 return scvfs_[scvfIdx];
215 }
216
222 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
223 scvs(const BoxFVElementGeometry& fvGeometry)
224 {
225 using Iter = typename std::vector<SubControlVolume>::const_iterator;
226 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
227 }
228
234 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
235 scvfs(const BoxFVElementGeometry& fvGeometry)
236 {
237 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
238 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
239 }
240
242 const FeLocalBasis& feLocalBasis() const
243 {
244 return gridGeometry().feCache().get(element_->type()).localBasis();
245 }
246
248 std::size_t numScv() const
249 {
250 return scvs_.size();
251 }
252
254 std::size_t numScvf() const
255 {
256 return scvfs_.size();
257 }
258
262 void bind(const Element& element)
263 {
264 this->bindElement(element);
265 }
266
270 void bindElement(const Element& element)
271 {
272 element_ = element;
273 eIdx_ = gridGeometry().elementMapper().index(element);
274 makeElementGeometries_();
275 }
276
278 bool isBound() const
279 { return static_cast<bool>(element_); }
280
282 const Element& element() const
283 { return *element_; }
284
287 { return *gridGeometryPtr_; }
288
290 bool hasBoundaryScvf() const
291 { return hasBoundaryScvf_; }
292
293private:
294
295 void makeElementGeometries_()
296 {
297 hasBoundaryScvf_ = false;
298
299 // get the element geometry
300 const auto& element = *element_;
301 const auto elementGeometry = element.geometry();
302 const auto refElement = referenceElement(elementGeometry);
303
304 // get the sub control volume geometries of this element
305 GeometryHelper geometryHelper(elementGeometry);
306
307 // construct the sub control volumes
308 scvs_.resize(elementGeometry.corners());
309 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
310 {
311 // get asssociated dof index
312 const auto dofIdxGlobal = gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim);
313
314 // add scv to the local container
315 scvs_[scvLocalIdx] = SubControlVolume(geometryHelper,
316 scvLocalIdx,
317 eIdx_,
318 dofIdxGlobal);
319 }
320
321 // construct the sub control volume faces
322 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
323 scvfs_.resize(numInnerScvf);
324
325 LocalIndexType scvfLocalIdx = 0;
326 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
327 {
328 // find the local scv indices this scvf is connected to
329 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
330 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
331
332 scvfs_[scvfLocalIdx] = SubControlVolumeFace(geometryHelper,
333 element,
334 elementGeometry,
335 scvfLocalIdx,
336 std::move(localScvIndices),
337 false);
338 }
339
340 // construct the sub control volume faces on the domain boundary
341 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
342 {
343 if (intersection.boundary() && !intersection.neighbor())
344 {
345 const auto isGeometry = intersection.geometry();
346 hasBoundaryScvf_ = true;
347
348 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
349 {
350 // find the scv this scvf is connected to
351 const LocalIndexType insideScvIdx = static_cast<LocalIndexType>(refElement.subEntity(intersection.indexInInside(), 1, isScvfLocalIdx, dim));
352 std::vector<LocalIndexType> localScvIndices = {insideScvIdx, insideScvIdx};
353
354 scvfs_.emplace_back(geometryHelper,
355 intersection,
356 isGeometry,
357 isScvfLocalIdx,
358 scvfLocalIdx,
359 std::move(localScvIndices),
360 true);
361
362 // increment local counter
363 scvfLocalIdx++;
364 }
365 }
366 }
367 }
368
370 GridIndexType eIdx_;
371 std::optional<Element> element_;
372
374 const GridGeometry* gridGeometryPtr_;
375
377 std::vector<SubControlVolume> scvs_;
378 std::vector<SubControlVolumeFace> scvfs_;
379
380 bool hasBoundaryScvf_ = false;
381};
382
383} // end namespace Dumux
384
385#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:48
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/box/fvelementgeometry.hh:152
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
const Element & element() const
The bound element.
Definition: discretization/box/fvelementgeometry.hh:156
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:160
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:164
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
typename GridView::template Codim< 0 >::Entity Element
export the element type
Definition: discretization/box/fvelementgeometry.hh:63
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/box/fvelementgeometry.hh:69
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/box/fvelementgeometry.hh:278
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/box/fvelementgeometry.hh:254
BoxFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: discretization/box/fvelementgeometry.hh:202
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/box/fvelementgeometry.hh:197
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/box/fvelementgeometry.hh:290
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:223
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/box/fvelementgeometry.hh:248
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/box/fvelementgeometry.hh:212
const GridGeometry & gridGeometry() const
The grid geometry we are a restriction of.
Definition: discretization/box/fvelementgeometry.hh:286
typename GridView::template Codim< 0 >::Entity Element
export the element type
Definition: discretization/box/fvelementgeometry.hh:191
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFVElementGeometry &fvGeometry)
Definition: discretization/box/fvelementgeometry.hh:235
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/box/fvelementgeometry.hh:242
const Element & element() const
The bound element.
Definition: discretization/box/fvelementgeometry.hh:282
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/box/fvelementgeometry.hh:206
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/box/fvelementgeometry.hh:195
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/box/fvelementgeometry.hh:193
void bind(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:262
void bindElement(const Element &element)
Definition: discretization/box/fvelementgeometry.hh:270