3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
multidomain/facet/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 *****************************************************************************/
24#ifndef DUMUX_FACETCOUPLING_BOX_FV_ELEMENT_GEOMETRY_HH
25#define DUMUX_FACETCOUPLING_BOX_FV_ELEMENT_GEOMETRY_HH
26
27#include <algorithm>
28
29#include <dune/geometry/type.hh>
30
34
35namespace Dumux {
36
46template<class GG, bool enableGridGeometryCache>
48
50template<class GG>
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 {}
76
78 const SubControlVolume& scv(LocalIndexType scvIdx) const
79 { return gridGeometry().scvs(eIdx_)[scvIdx]; }
80
82 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
83 { return gridGeometry().scvfs(eIdx_)[scvfIdx]; }
84
90 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
92 {
93 const auto& g = fvGeometry.gridGeometry();
94 using Iter = typename std::vector<SubControlVolume>::const_iterator;
95 return Dune::IteratorRange<Iter>(g.scvs(fvGeometry.eIdx_).begin(), g.scvs(fvGeometry.eIdx_).end());
96 }
97
103 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
105 {
106 const auto& g = fvGeometry.gridGeometry();
107 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
108 return Dune::IteratorRange<Iter>(g.scvfs(fvGeometry.eIdx_).begin(), g.scvfs(fvGeometry.eIdx_).end());
109 }
110
112 const FeLocalBasis& feLocalBasis() const
113 { return gridGeometry().feCache().get(elemGeometryType_).localBasis(); }
114
116 std::size_t numScv() const
117 { return gridGeometry().scvs(eIdx_).size(); }
118
120 std::size_t numScvf() const
121 { return gridGeometry().scvfs(eIdx_).size(); }
122
126 void bind(const Element& element)
127 {
128 this->bindElement(element);
129 }
130
134 void bindElement(const Element& element)
135 {
136 elemGeometryType_ = element.type();
137 eIdx_ = gridGeometry().elementMapper().index(element);
138 }
139
142 { return *gridGeometryPtr_; }
143
144private:
145 Dune::GeometryType elemGeometryType_;
146 const GridGeometry* gridGeometryPtr_;
147
148 GridIndexType eIdx_;
149};
150
152template<class GG>
154{
155 using GridView = typename GG::GridView;
156 static constexpr int dim = GridView::dimension;
157 static constexpr int dimWorld = GridView::dimensionworld;
158
159 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
160 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
161
162 using CoordScalar = typename GridView::ctype;
163 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
164
165 using GeometryHelper = BoxGeometryHelper<GridView, dim,
166 typename GG::SubControlVolume,
167 typename GG::SubControlVolumeFace>;
168public:
170 using Element = typename GridView::template Codim<0>::Entity;
172 using SubControlVolume = typename GG::SubControlVolume;
174 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
176 using GridGeometry = GG;
178 static constexpr std::size_t maxNumElementScvs = (1<<dim);
179
182 : gridGeometryPtr_(&gridGeometry)
183 {}
184
186 const SubControlVolume& scv(LocalIndexType scvIdx) const
187 { return scvs_[scvIdx]; }
188
190 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
191 { return scvfs_[scvfIdx]; }
192
198 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
200 {
201 using Iter = typename std::vector<SubControlVolume>::const_iterator;
202 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
203 }
204
210 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
212 {
213 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
214 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
215 }
216
218 const FeLocalBasis& feLocalBasis() const
219 { return gridGeometry().feCache().get(elemGeometryType_).localBasis(); }
220
222 std::size_t numScv() const
223 { return scvs_.size(); }
224
226 std::size_t numScvf() const
227 { return scvfs_.size(); }
228
232 void bind(const Element& element)
233 {
234 this->bindElement(element);
235 }
236
240 void bindElement(const Element& element)
241 {
242 eIdx_ = gridGeometry().elementMapper().index(element);
243 makeElementGeometries(element);
244 }
245
248 { return *gridGeometryPtr_; }
249
250private:
251
252 void makeElementGeometries(const Element& element)
253 {
254 auto eIdx = gridGeometry().elementMapper().index(element);
255
256 // get the element geometry
257 auto elementGeometry = element.geometry();
258 elemGeometryType_ = elementGeometry.type();
259 const auto refElement = referenceElement(elementGeometry);
260
261 // get the sub control volume geometries of this element
262 GeometryHelper geometryHelper(elementGeometry);
263
264 // construct the sub control volumes
265 scvs_.clear();
266 scvs_.reserve(elementGeometry.corners());
267 using LocalIndexType = typename SubControlVolumeFace::Traits::LocalIndexType;
268 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
269 scvs_.emplace_back(geometryHelper,
270 scvLocalIdx,
271 eIdx,
272 gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim));
273
274 // construct the sub control volume faces
275 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
276 scvfs_.clear();
277 scvfs_.reserve(numInnerScvf);
278
279 unsigned int scvfLocalIdx = 0;
280 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
281 {
282 // find the local scv indices this scvf is connected to
283 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
284 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
285
286 // create the sub-control volume face
287 scvfs_.emplace_back(geometryHelper,
288 element,
289 elementGeometry,
290 scvfLocalIdx,
291 std::move(localScvIndices));
292 }
293
294 // construct the sub control volume faces on the domain/interior boundaries
295 // skip handled facets (necessary for e.g. Dune::FoamGrid)
296 std::vector<unsigned int> handledFacets;
297 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
298 {
299 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
300 continue;
301
302 handledFacets.push_back(intersection.indexInInside());
303
304 // determine if all corners live on the facet grid
305 const auto isGeometry = intersection.geometry();
306 const auto numFaceCorners = isGeometry.corners();
307 const auto idxInInside = intersection.indexInInside();
308 const auto boundary = intersection.boundary();
309
310 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
311 for (int i = 0; i < numFaceCorners; ++i)
312 vIndicesLocal[i] = static_cast<LocalIndexType>(refElement.subEntity(idxInInside, 1, i, dim));
313
314 // if all vertices are living on the facet grid, this is an interiour boundary
315 const bool isOnFacet = gridGeometry().isOnInteriorBoundary(element, intersection);
316
317 if (isOnFacet || boundary)
318 {
319 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
320 {
321 // find the inside scv this scvf is belonging to (localIdx = element local vertex index)
322 std::vector<LocalIndexType> localScvIndices = {vIndicesLocal[isScvfLocalIdx], vIndicesLocal[isScvfLocalIdx]};
323
324 // create the sub-control volume face
325 scvfs_.emplace_back(geometryHelper,
326 intersection,
327 isGeometry,
328 isScvfLocalIdx,
329 scvfLocalIdx,
330 std::move(localScvIndices),
331 boundary,
332 isOnFacet);
333
334 // increment local counter
335 scvfLocalIdx++;
336 }
337 }
338 }
339 }
340
342 Dune::GeometryType elemGeometryType_;
343 GridIndexType eIdx_;
344
346 const GridGeometry* gridGeometryPtr_;
347
349 std::vector<SubControlVolume> scvs_;
350 std::vector<SubControlVolumeFace> scvfs_;
351};
352
353} // end namespace Dumux
354
355#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 element-local finite volume geometry for box models in the context of models consi...
Definition: multidomain/facet/box/fvelementgeometry.hh:47
GG GridGeometry
export type of finite volume grid geometry
Definition: multidomain/facet/box/fvelementgeometry.hh:68
void bind(const Element &element)
Definition: multidomain/facet/box/fvelementgeometry.hh:126
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvelementgeometry.hh:116
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: multidomain/facet/box/fvelementgeometry.hh:78
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:104
void bindElement(const Element &element)
Definition: multidomain/facet/box/fvelementgeometry.hh:134
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: multidomain/facet/box/fvelementgeometry.hh:82
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: multidomain/facet/box/fvelementgeometry.hh:64
BoxFacetCouplingFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:73
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: multidomain/facet/box/fvelementgeometry.hh:141
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:91
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: multidomain/facet/box/fvelementgeometry.hh:66
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: multidomain/facet/box/fvelementgeometry.hh:120
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: multidomain/facet/box/fvelementgeometry.hh:112
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: multidomain/facet/box/fvelementgeometry.hh:62
BoxFacetCouplingFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:181
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: multidomain/facet/box/fvelementgeometry.hh:186
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: multidomain/facet/box/fvelementgeometry.hh:174
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: multidomain/facet/box/fvelementgeometry.hh:218
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:211
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvelementgeometry.hh:222
void bind(const Element &element)
Definition: multidomain/facet/box/fvelementgeometry.hh:232
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: multidomain/facet/box/fvelementgeometry.hh:226
void bindElement(const Element &element)
Definition: multidomain/facet/box/fvelementgeometry.hh:240
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:199
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: multidomain/facet/box/fvelementgeometry.hh:172
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: multidomain/facet/box/fvelementgeometry.hh:170
GG GridGeometry
export type of finite volume grid geometry
Definition: multidomain/facet/box/fvelementgeometry.hh:176
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: multidomain/facet/box/fvelementgeometry.hh:247
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: multidomain/facet/box/fvelementgeometry.hh:190