version 3.8
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_FACETCOUPLING_BOX_FV_ELEMENT_GEOMETRY_HH
13#define DUMUX_FACETCOUPLING_BOX_FV_ELEMENT_GEOMETRY_HH
14
15#include <algorithm>
16#include <optional>
17
18#include <dune/geometry/type.hh>
19
23
24namespace Dumux {
25
35template<class GG, bool enableGridGeometryCache>
37
39template<class GG>
41{
42 using GridView = typename GG::GridView;
43 static constexpr int dim = GridView::dimension;
44 static constexpr int dimWorld = GridView::dimensionworld;
45 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
46 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
47 using CoordScalar = typename GridView::ctype;
48 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
49public:
51 using Element = typename GridView::template Codim<0>::Entity;
53 using SubControlVolume = typename GG::SubControlVolume;
55 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
57 using GridGeometry = GG;
59 static constexpr std::size_t maxNumElementScvs = (1<<dim);
60
63 : gridGeometryPtr_(&gridGeometry)
64 {}
65
67 const SubControlVolume& scv(LocalIndexType scvIdx) const
68 { return gridGeometry().scvs(eIdx_)[scvIdx]; }
69
71 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
72 { return gridGeometry().scvfs(eIdx_)[scvfIdx]; }
73
79 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
81 {
82 const auto& g = fvGeometry.gridGeometry();
83 using Iter = typename std::vector<SubControlVolume>::const_iterator;
84 return Dune::IteratorRange<Iter>(g.scvs(fvGeometry.eIdx_).begin(), g.scvs(fvGeometry.eIdx_).end());
85 }
86
92 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
94 {
95 const auto& g = fvGeometry.gridGeometry();
96 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
97 return Dune::IteratorRange<Iter>(g.scvfs(fvGeometry.eIdx_).begin(), g.scvfs(fvGeometry.eIdx_).end());
98 }
99
101 const FeLocalBasis& feLocalBasis() const
102 { return gridGeometry().feCache().get(element_->type()).localBasis(); }
103
105 std::size_t numScv() const
106 { return gridGeometry().scvs(eIdx_).size(); }
107
109 std::size_t numScvf() const
110 { return gridGeometry().scvfs(eIdx_).size(); }
111
118 {
119 this->bindElement(element);
120 return std::move(*this);
121 }
122
126 void bind(const Element& element) &
127 { this->bindElement(element); }
128
135 {
136 this->bindElement(element);
137 return std::move(*this);
138 }
139
143 void bindElement(const Element& element) &
144 {
145 element_ = element;
146 eIdx_ = gridGeometry().elementMapper().index(element);
147 }
148
151 { return *gridGeometryPtr_; }
152
154 bool isBound() const
155 { return static_cast<bool>(element_); }
156
158 const Element& element() const
159 { return *element_; }
160
161 // suppress warnings due to current implementation
162 // these interfaces should be used!
163 #pragma GCC diagnostic push
164 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
165
167 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
168 { return scv.geometry(); }
169
171 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
172 { return scvf.geometry(); }
173
174 #pragma GCC diagnostic pop
175
176private:
177 const GridGeometry* gridGeometryPtr_;
178
179 GridIndexType eIdx_;
180 std::optional<Element> element_;
181};
182
184template<class GG>
186{
187 using GridView = typename GG::GridView;
188 static constexpr int dim = GridView::dimension;
189 static constexpr int dimWorld = GridView::dimensionworld;
190
191 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
192 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
193
194 using CoordScalar = typename GridView::ctype;
195 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
196
197 using GeometryHelper = typename GG::GeometryHelper;
198public:
200 using Element = typename GridView::template Codim<0>::Entity;
202 using SubControlVolume = typename GG::SubControlVolume;
204 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
206 using GridGeometry = GG;
208 static constexpr std::size_t maxNumElementScvs = (1<<dim);
209
212 : gridGeometryPtr_(&gridGeometry)
213 {}
214
216 const SubControlVolume& scv(LocalIndexType scvIdx) const
217 { return scvs_[scvIdx]; }
218
220 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
221 { return scvfs_[scvfIdx]; }
222
228 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
230 {
231 using Iter = typename std::vector<SubControlVolume>::const_iterator;
232 return Dune::IteratorRange<Iter>(fvGeometry.scvs_.begin(), fvGeometry.scvs_.end());
233 }
234
240 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
242 {
243 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
244 return Dune::IteratorRange<Iter>(fvGeometry.scvfs_.begin(), fvGeometry.scvfs_.end());
245 }
246
248 const FeLocalBasis& feLocalBasis() const
249 { return gridGeometry().feCache().get(element_->type()).localBasis(); }
250
252 std::size_t numScv() const
253 { return scvs_.size(); }
254
256 std::size_t numScvf() const
257 { return scvfs_.size(); }
258
265 {
266 this->bindElement(element);
267 return std::move(*this);
268 }
269
273 void bind(const Element& element) &
274 { this->bindElement(element); }
275
282 {
283 this->bindElement(element);
284 return std::move(*this);
285 }
286
290 void bindElement(const Element& element) &
291 {
292 element_ = element;
293 eIdx_ = gridGeometry().elementMapper().index(element);
294 makeElementGeometries_();
295 }
296
299 { return *gridGeometryPtr_; }
300
302 bool isBound() const
303 { return static_cast<bool>(element_); }
304
306 const Element& element() const
307 { return *element_; }
308
309 // suppress warnings due to current implementation
310 // these interfaces should be used!
311 #pragma GCC diagnostic push
312 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
313
315 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
316 { return scv.geometry(); }
317
319 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
320 { return scvf.geometry(); }
321
322 #pragma GCC diagnostic pop
323
324private:
325
326 void makeElementGeometries_()
327 {
328 // get the element geometry
329 const auto& element = *element_;
330 const auto elementGeometry = element.geometry();
331 const auto refElement = referenceElement(elementGeometry);
332
333 // get the sub control volume geometries of this element
334 GeometryHelper geometryHelper(elementGeometry);
335
336 // construct the sub control volumes
337 scvs_.clear();
338 scvs_.reserve(elementGeometry.corners());
339 using LocalIndexType = typename SubControlVolumeFace::Traits::LocalIndexType;
340 for (LocalIndexType scvLocalIdx = 0; scvLocalIdx < elementGeometry.corners(); ++scvLocalIdx)
341 scvs_.emplace_back(geometryHelper.getScvCorners(scvLocalIdx),
342 scvLocalIdx,
343 eIdx_,
344 gridGeometry().vertexMapper().subIndex(element, scvLocalIdx, dim));
345
346 // construct the sub control volume faces
347 const auto numInnerScvf = (dim==1) ? 1 : element.subEntities(dim-1);
348 scvfs_.clear();
349 scvfs_.reserve(numInnerScvf);
350
351 unsigned int scvfLocalIdx = 0;
352 for (; scvfLocalIdx < numInnerScvf; ++scvfLocalIdx)
353 {
354 // find the local scv indices this scvf is connected to
355 std::vector<LocalIndexType> localScvIndices({static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 0, dim)),
356 static_cast<LocalIndexType>(refElement.subEntity(scvfLocalIdx, dim-1, 1, dim))});
357
358 // create the sub-control volume face
359 scvfs_.emplace_back(geometryHelper,
360 element,
361 elementGeometry,
362 scvfLocalIdx,
363 std::move(localScvIndices));
364 }
365
366 // construct the sub control volume faces on the domain/interior boundaries
367 // skip handled facets (necessary for e.g. Dune::FoamGrid)
368 std::vector<unsigned int> handledFacets;
369 for (const auto& intersection : intersections(gridGeometry().gridView(), element))
370 {
371 if (std::count(handledFacets.begin(), handledFacets.end(), intersection.indexInInside()))
372 continue;
373
374 handledFacets.push_back(intersection.indexInInside());
375
376 // determine if all corners live on the facet grid
377 const auto isGeometry = intersection.geometry();
378 const auto numFaceCorners = isGeometry.corners();
379 const auto idxInInside = intersection.indexInInside();
380 const auto boundary = intersection.boundary();
381
382 std::vector<LocalIndexType> vIndicesLocal(numFaceCorners);
383 for (int i = 0; i < numFaceCorners; ++i)
384 vIndicesLocal[i] = static_cast<LocalIndexType>(refElement.subEntity(idxInInside, 1, i, dim));
385
386 // if all vertices are living on the facet grid, this is an interiour boundary
387 const bool isOnFacet = gridGeometry().isOnInteriorBoundary(element, intersection);
388
389 if (isOnFacet || boundary)
390 {
391 for (unsigned int isScvfLocalIdx = 0; isScvfLocalIdx < isGeometry.corners(); ++isScvfLocalIdx)
392 {
393 // find the inside scv this scvf is belonging to (localIdx = element local vertex index)
394 std::vector<LocalIndexType> localScvIndices = {vIndicesLocal[isScvfLocalIdx], vIndicesLocal[isScvfLocalIdx]};
395
396 // create the sub-control volume face
397 scvfs_.emplace_back(geometryHelper,
398 intersection,
399 isGeometry,
400 isScvfLocalIdx,
401 scvfLocalIdx,
402 std::move(localScvIndices),
403 boundary,
404 isOnFacet);
405
406 // increment local counter
407 scvfLocalIdx++;
408 }
409 }
410 }
411 }
412
414 const GridGeometry* gridGeometryPtr_;
415
417 GridIndexType eIdx_;
418 std::optional<Element> element_;
419
421 std::vector<SubControlVolume> scvs_;
422 std::vector<SubControlVolumeFace> scvfs_;
423};
424
425} // end namespace Dumux
426
427#endif
Helper class constructing the dual grid finite volume geometries for the box discretizazion method.
void bindElement(const Element &element) &
Definition: multidomain/facet/box/fvelementgeometry.hh:290
BoxFacetCouplingFVElementGeometry 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: multidomain/facet/box/fvelementgeometry.hh:281
BoxFacetCouplingFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:211
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: multidomain/facet/box/fvelementgeometry.hh:216
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: multidomain/facet/box/fvelementgeometry.hh:204
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: multidomain/facet/box/fvelementgeometry.hh:248
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Create the geometry of a given sub control volume face.
Definition: multidomain/facet/box/fvelementgeometry.hh:319
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:241
void bind(const Element &element) &
Definition: multidomain/facet/box/fvelementgeometry.hh:273
std::size_t numScv() const
The total number of sub control volumes.
Definition: multidomain/facet/box/fvelementgeometry.hh:252
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: multidomain/facet/box/fvelementgeometry.hh:302
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: multidomain/facet/box/fvelementgeometry.hh:256
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:229
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: multidomain/facet/box/fvelementgeometry.hh:202
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: multidomain/facet/box/fvelementgeometry.hh:200
GG GridGeometry
export type of finite volume grid geometry
Definition: multidomain/facet/box/fvelementgeometry.hh:206
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: multidomain/facet/box/fvelementgeometry.hh:298
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Create the geometry of a given sub control volume.
Definition: multidomain/facet/box/fvelementgeometry.hh:315
const Element & element() const
The bound element.
Definition: multidomain/facet/box/fvelementgeometry.hh:306
BoxFacetCouplingFVElementGeometry 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: multidomain/facet/box/fvelementgeometry.hh:264
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: multidomain/facet/box/fvelementgeometry.hh:220
void bindElement(const Element &element) &
Definition: multidomain/facet/box/fvelementgeometry.hh:143
GG GridGeometry
export type of finite volume grid geometry
Definition: multidomain/facet/box/fvelementgeometry.hh:57
BoxFacetCouplingFVElementGeometry 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: multidomain/facet/box/fvelementgeometry.hh:117
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Create the geometry of a given sub control volume face.
Definition: multidomain/facet/box/fvelementgeometry.hh:171
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: multidomain/facet/box/fvelementgeometry.hh:154
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:105
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: multidomain/facet/box/fvelementgeometry.hh:67
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:93
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: multidomain/facet/box/fvelementgeometry.hh:71
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: multidomain/facet/box/fvelementgeometry.hh:53
BoxFacetCouplingFVElementGeometry(const GridGeometry &gridGeometry)
Constructor.
Definition: multidomain/facet/box/fvelementgeometry.hh:62
const GridGeometry & gridGeometry() const
The global finite volume geometry we are a restriction of.
Definition: multidomain/facet/box/fvelementgeometry.hh:150
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const BoxFacetCouplingFVElementGeometry &fvGeometry)
Definition: multidomain/facet/box/fvelementgeometry.hh:80
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: multidomain/facet/box/fvelementgeometry.hh:55
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Create the geometry of a given sub control volume.
Definition: multidomain/facet/box/fvelementgeometry.hh:167
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: multidomain/facet/box/fvelementgeometry.hh:109
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: multidomain/facet/box/fvelementgeometry.hh:101
const Element & element() const
The bound element.
Definition: multidomain/facet/box/fvelementgeometry.hh:158
typename GridView::template Codim< 0 >::Entity Element
export type of the element
Definition: multidomain/facet/box/fvelementgeometry.hh:51
BoxFacetCouplingFVElementGeometry 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: multidomain/facet/box/fvelementgeometry.hh:134
Base class for the element-local finite volume geometry for box models in the context of models consi...
Definition: multidomain/facet/box/fvelementgeometry.hh:36
Defines the index types used for grid and local indices.
Definition: adapt.hh:17
Class providing iterators over sub control volumes and sub control volume faces of an element.
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:27
unsigned int LocalIndex
Definition: indextraits.hh:28