3.4
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#include <optional>
29
30#include <dune/geometry/type.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 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 {}
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(element_->type()).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 element_ = element;
138 eIdx_ = gridGeometry().elementMapper().index(element);
139 }
140
143 { return *gridGeometryPtr_; }
144
146 bool isBound() const
147 { return static_cast<bool>(element_); }
148
150 const Element& element() const
151 { return *element_; }
152
153private:
154 const GridGeometry* gridGeometryPtr_;
155
156 GridIndexType eIdx_;
157 std::optional<Element> element_;
158};
159
161template<class GG>
163{
164 using GridView = typename GG::GridView;
165 static constexpr int dim = GridView::dimension;
166 static constexpr int dimWorld = GridView::dimensionworld;
167
168 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
169 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
170
171 using CoordScalar = typename GridView::ctype;
172 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
173
174 using GeometryHelper = BoxGeometryHelper<GridView, dim,
175 typename GG::SubControlVolume,
176 typename GG::SubControlVolumeFace>;
177public:
179 using Element = typename GridView::template Codim<0>::Entity;
181 using SubControlVolume = typename GG::SubControlVolume;
183 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
185 using GridGeometry = GG;
187 static constexpr std::size_t maxNumElementScvs = (1<<dim);
188
191 : gridGeometryPtr_(&gridGeometry)
192 {}
193
195 const SubControlVolume& scv(LocalIndexType scvIdx) const
196 { return scvs_[scvIdx]; }
197
199 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
200 { return scvfs_[scvfIdx]; }
201
207 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
209 {
210 using Iter = typename std::vector<SubControlVolume>::const_iterator;
211 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
212 }
213
219 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
221 {
222 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
223 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
224 }
225
227 const FeLocalBasis& feLocalBasis() const
228 { return gridGeometry().feCache().get(element_->type()).localBasis(); }
229
231 std::size_t numScv() const
232 { return scvs_.size(); }
233
235 std::size_t numScvf() const
236 { return scvfs_.size(); }
237
241 void bind(const Element& element)
242 {
243 this->bindElement(element);
244 }
245
249 void bindElement(const Element& element)
250 {
251 element_ = element;
252 eIdx_ = gridGeometry().elementMapper().index(element);
253 makeElementGeometries_();
254 }
255
258 { return *gridGeometryPtr_; }
259
261 bool isBound() const
262 { return static_cast<bool>(element_); }
263
265 const Element& element() const
266 { return *element_; }
267
268private:
269
270 void makeElementGeometries_()
271 {
272 // get the element geometry
273 const auto& element = *element_;
274 const auto elementGeometry = element.geometry();
275 const auto refElement = referenceElement(elementGeometry);
276
277 // get the sub control volume geometries of this element
278 GeometryHelper geometryHelper(elementGeometry);
279
280 // construct the sub control volumes
281 scvs_.clear();
282 scvs_.reserve(elementGeometry.corners());
283 using LocalIndexType = typename SubControlVolumeFace::Traits::LocalIndexType;
284 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
285 scvs_.emplace_back(geometryHelper,
286 scvLocalIdx,
287 eIdx_,
288 gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim));
289
290 // construct the sub control volume faces
291 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
292 scvfs_.clear();
293 scvfs_.reserve(numInnerScvf);
294
295 unsigned int scvfLocalIdx = 0;
296 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
297 {
298 // find the local scv indices this scvf is connected to
299 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
300 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
301
302 // create the sub-control volume face
303 scvfs_.emplace_back(geometryHelper,
304 element,
305 elementGeometry,
306 scvfLocalIdx,
307 std::move(localScvIndices));
308 }
309
310 // construct the sub control volume faces on the domain/interior boundaries
311 // skip handled facets (necessary for e.g. Dune::FoamGrid)
312 std::vector<unsigned int> handledFacets;
313 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
314 {
315 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
316 continue;
317
318 handledFacets.push_back(intersection.indexInInside());
319
320 // determine if all corners live on the facet grid
321 const auto isGeometry = intersection.geometry();
322 const auto numFaceCorners = isGeometry.corners();
323 const auto idxInInside = intersection.indexInInside();
324 const auto boundary = intersection.boundary();
325
326 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
327 for (int i = 0; i < numFaceCorners; ++i)
328 vIndicesLocal[i] = static_cast<LocalIndexType>(refElement.subEntity(idxInInside, 1, i, dim));
329
330 // if all vertices are living on the facet grid, this is an interiour boundary
331 const bool isOnFacet = gridGeometry().isOnInteriorBoundary(element, intersection);
332
333 if (isOnFacet || boundary)
334 {
335 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
336 {
337 // find the inside scv this scvf is belonging to (localIdx = element local vertex index)
338 std::vector<LocalIndexType> localScvIndices = {vIndicesLocal[isScvfLocalIdx], vIndicesLocal[isScvfLocalIdx]};
339
340 // create the sub-control volume face
341 scvfs_.emplace_back(geometryHelper,
342 intersection,
343 isGeometry,
344 isScvfLocalIdx,
345 scvfLocalIdx,
346 std::move(localScvIndices),
347 boundary,
348 isOnFacet);
349
350 // increment local counter
351 scvfLocalIdx++;
352 }
353 }
354 }
355 }
356
358 const GridGeometry* gridGeometryPtr_;
359
361 GridIndexType eIdx_;
362 std::optional<Element> element_;
363
365 std::vector<SubControlVolume> scvs_;
366 std::vector<SubControlVolumeFace> scvfs_;
367};
368
369} // end namespace Dumux
370
371#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: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
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: multidomain/facet/box/fvelementgeometry.hh:146
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
const Element & element() const
The bound element.
Definition: multidomain/facet/box/fvelementgeometry.hh:150
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: multidomain/facet/box/fvelementgeometry.hh:63
BoxFacetCouplingFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:190
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: multidomain/facet/box/fvelementgeometry.hh:195
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: multidomain/facet/box/fvelementgeometry.hh:183
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: multidomain/facet/box/fvelementgeometry.hh:227
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:220
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvelementgeometry.hh:231
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: multidomain/facet/box/fvelementgeometry.hh:261
void bind(const Element &element)
Definition: multidomain/facet/box/fvelementgeometry.hh:241
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: multidomain/facet/box/fvelementgeometry.hh:235
void bindElement(const Element &element)
Definition: multidomain/facet/box/fvelementgeometry.hh:249
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:208
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: multidomain/facet/box/fvelementgeometry.hh:181
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: multidomain/facet/box/fvelementgeometry.hh:179
GG GridGeometry
export type of finite volume grid geometry
Definition: multidomain/facet/box/fvelementgeometry.hh:185
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: multidomain/facet/box/fvelementgeometry.hh:257
const Element & element() const
The bound element.
Definition: multidomain/facet/box/fvelementgeometry.hh:265
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: multidomain/facet/box/fvelementgeometry.hh:199