3.2-git
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#include <dune/geometry/referenceelements.hh>
31
35
36namespace Dumux {
37
47template<class GG, bool enableGridGeometryCache>
49
51template<class GG>
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 {}
77
79 const SubControlVolume& scv(LocalIndexType scvIdx) const
80 { return gridGeometry().scvs(eIdx_)[scvIdx]; }
81
83 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
84 { return gridGeometry().scvfs(eIdx_)[scvfIdx]; }
85
91 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
93 {
94 const auto& g = fvGeometry.gridGeometry();
95 using Iter = typename std::vector<SubControlVolume>::const_iterator;
96 return Dune::IteratorRange<Iter>(g.scvs(fvGeometry.eIdx_).begin(), g.scvs(fvGeometry.eIdx_).end());
97 }
98
104 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
106 {
107 const auto& g = fvGeometry.gridGeometry();
108 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
109 return Dune::IteratorRange<Iter>(g.scvfs(fvGeometry.eIdx_).begin(), g.scvfs(fvGeometry.eIdx_).end());
110 }
111
113 const FeLocalBasis& feLocalBasis() const
114 { return gridGeometry().feCache().get(elemGeometryType_).localBasis(); }
115
117 std::size_t numScv() const
118 { return gridGeometry().scvs(eIdx_).size(); }
119
121 std::size_t numScvf() const
122 { return gridGeometry().scvfs(eIdx_).size(); }
123
127 void bind(const Element& element)
128 {
129 this->bindElement(element);
130 }
131
135 void bindElement(const Element& element)
136 {
137 elemGeometryType_ = element.type();
138 eIdx_ = gridGeometry().elementMapper().index(element);
139 }
140
143 { return *gridGeometryPtr_; }
144
145private:
146 Dune::GeometryType elemGeometryType_;
147 const GridGeometry* gridGeometryPtr_;
148
149 GridIndexType eIdx_;
150};
151
153template<class GG>
155{
156 using GridView = typename GG::GridView;
157 static constexpr int dim = GridView::dimension;
158 static constexpr int dimWorld = GridView::dimensionworld;
159
160 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
161 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
162 using Element = typename GridView::template Codim<0>::Entity;
163
164 using CoordScalar = typename GridView::ctype;
165 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
166 using ReferenceElements = typename Dune::ReferenceElements<CoordScalar, dim>;
167
168 using GeometryHelper = BoxGeometryHelper<GridView, dim,
169 typename GG::SubControlVolume,
170 typename GG::SubControlVolumeFace>;
171public:
173 using SubControlVolume = typename GG::SubControlVolume;
175 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
177 using GridGeometry = GG;
179 static constexpr std::size_t maxNumElementScvs = (1<<dim);
180
183 : gridGeometryPtr_(&gridGeometry)
184 {}
185
187 const SubControlVolume& scv(LocalIndexType scvIdx) const
188 { return scvs_[scvIdx]; }
189
191 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
192 { return scvfs_[scvfIdx]; }
193
199 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
201 {
202 using Iter = typename std::vector<SubControlVolume>::const_iterator;
203 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
204 }
205
211 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
213 {
214 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
215 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
216 }
217
219 const FeLocalBasis& feLocalBasis() const
220 { return gridGeometry().feCache().get(elemGeometryType_).localBasis(); }
221
223 std::size_t numScv() const
224 { return scvs_.size(); }
225
227 std::size_t numScvf() const
228 { return scvfs_.size(); }
229
233 void bind(const Element& element)
234 {
235 this->bindElement(element);
236 }
237
241 void bindElement(const Element& element)
242 {
243 eIdx_ = gridGeometry().elementMapper().index(element);
244 makeElementGeometries(element);
245 }
246
249 { return *gridGeometryPtr_; }
250
251private:
252
253 void makeElementGeometries(const Element& element)
254 {
255 auto eIdx = gridGeometry().elementMapper().index(element);
256
257 // get the element geometry
258 auto elementGeometry = element.geometry();
259 elemGeometryType_ = elementGeometry.type();
260 const auto referenceElement = ReferenceElements::general(elemGeometryType_);
261
262 // get the sub control volume geometries of this element
263 GeometryHelper geometryHelper(elementGeometry);
264
265 // construct the sub control volumes
266 scvs_.clear();
267 scvs_.reserve(elementGeometry.corners());
268 using LocalIndexType = typename SubControlVolumeFace::Traits::LocalIndexType;
269 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
270 scvs_.emplace_back(geometryHelper,
271 scvLocalIdx,
272 eIdx,
273 gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim));
274
275 // construct the sub control volume faces
276 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
277 scvfs_.clear();
278 scvfs_.reserve(numInnerScvf);
279
280 unsigned int scvfLocalIdx = 0;
281 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
282 {
283 // find the local scv indices this scvf is connected to
284 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(referenceElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
285 static_cast<LocalIndexType>(referenceElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
286
287 // create the sub-control volume face
288 scvfs_.emplace_back(geometryHelper,
289 element,
290 elementGeometry,
291 scvfLocalIdx,
292 std::move(localScvIndices));
293 }
294
295 // construct the sub control volume faces on the domain/interior boundaries
296 // skip handled facets (necessary for e.g. Dune::FoamGrid)
297 std::vector<unsigned int> handledFacets;
298 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
299 {
300 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
301 continue;
302
303 handledFacets.push_back(intersection.indexInInside());
304
305 // determine if all corners live on the facet grid
306 const auto isGeometry = intersection.geometry();
307 const auto numFaceCorners = isGeometry.corners();
308 const auto idxInInside = intersection.indexInInside();
309 const auto boundary = intersection.boundary();
310
311 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
312 for (int i = 0; i < numFaceCorners; ++i)
313 vIndicesLocal[i] = static_cast<LocalIndexType>(referenceElement.subEntity(idxInInside, 1, i, dim));
314
315 // if all vertices are living on the facet grid, this is an interiour boundary
316 const bool isOnFacet = gridGeometry().isOnInteriorBoundary(element, intersection);
317
318 if (isOnFacet || boundary)
319 {
320 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
321 {
322 // find the inside scv this scvf is belonging to (localIdx = element local vertex index)
323 std::vector<LocalIndexType> localScvIndices = {vIndicesLocal[isScvfLocalIdx], vIndicesLocal[isScvfLocalIdx]};
324
325 // create the sub-control volume face
326 scvfs_.emplace_back(geometryHelper,
327 intersection,
328 isGeometry,
329 isScvfLocalIdx,
330 scvfLocalIdx,
331 std::move(localScvIndices),
332 boundary,
333 isOnFacet);
334
335 // increment local counter
336 scvfLocalIdx++;
337 }
338 }
339 }
340 }
341
343 Dune::GeometryType elemGeometryType_;
344 GridIndexType eIdx_;
345
347 const GridGeometry* gridGeometryPtr_;
348
350 std::vector<SubControlVolume> scvs_;
351 std::vector<SubControlVolumeFace> scvfs_;
352};
353
354} // end namespace Dumux
355
356#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 element-local finite volume geometry for box models in the context of models consi...
Definition: multidomain/facet/box/fvelementgeometry.hh:48
GG GridGeometry
export type of finite volume grid geometry
Definition: multidomain/facet/box/fvelementgeometry.hh:69
void bind(const Element &element)
Definition: multidomain/facet/box/fvelementgeometry.hh:127
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvelementgeometry.hh:117
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: multidomain/facet/box/fvelementgeometry.hh:79
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:105
void bindElement(const Element &element)
Definition: multidomain/facet/box/fvelementgeometry.hh:135
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: multidomain/facet/box/fvelementgeometry.hh:83
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: multidomain/facet/box/fvelementgeometry.hh:65
BoxFacetCouplingFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:74
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: multidomain/facet/box/fvelementgeometry.hh:142
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:92
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: multidomain/facet/box/fvelementgeometry.hh:67
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: multidomain/facet/box/fvelementgeometry.hh:121
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: multidomain/facet/box/fvelementgeometry.hh:113
BoxFacetCouplingFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:182
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: multidomain/facet/box/fvelementgeometry.hh:187
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: multidomain/facet/box/fvelementgeometry.hh:175
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: multidomain/facet/box/fvelementgeometry.hh:219
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:212
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvelementgeometry.hh:223
void bind(const Element &element)
Definition: multidomain/facet/box/fvelementgeometry.hh:233
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: multidomain/facet/box/fvelementgeometry.hh:227
void bindElement(const Element &element)
Definition: multidomain/facet/box/fvelementgeometry.hh:241
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:200
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: multidomain/facet/box/fvelementgeometry.hh:173
GG GridGeometry
export type of finite volume grid geometry
Definition: multidomain/facet/box/fvelementgeometry.hh:177
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: multidomain/facet/box/fvelementgeometry.hh:248
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: multidomain/facet/box/fvelementgeometry.hh:191