version 3.11-dev
discretization/pq1bubble/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-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
14#ifndef DUMUX_DISCRETIZATION_PQ1BUBBLE_FV_ELEMENT_GEOMETRY_HH
15#define DUMUX_DISCRETIZATION_PQ1BUBBLE_FV_ELEMENT_GEOMETRY_HH
16
17#include <optional>
18#include <span>
19#include <utility>
20#include <dune/common/exceptions.hh>
21#include <dune/geometry/type.hh>
22#include <dune/localfunctions/lagrange/pqkfactory.hh>
23
29
31
32namespace Dumux {
33
42template<class GG, bool enableGridGeometryCache>
44
46template<class GG>
48{
49 using GridView = typename GG::GridView;
50 static constexpr int dim = GridView::dimension;
51 static constexpr int dimWorld = GridView::dimensionworld;
52 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
53 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
54 using CoordScalar = typename GridView::ctype;
55 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
56 using GGCache = typename GG::Cache;
57 using GeometryHelper = typename GGCache::GeometryHelper;
58
60 typename GridView::template Codim<0>::Entity::Geometry::LocalCoordinate,
61 typename GridView::template Codim<0>::Entity::Geometry::GlobalCoordinate
62 >;
63
64public:
66 using Element = typename GridView::template Codim<0>::Entity;
68 using SubControlVolume = typename GG::SubControlVolume;
70 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
72 using GridGeometry = GG;
74 using BoundaryFace = typename GG::BoundaryFace;
76 using ScvQuadratureRule = typename GG::ScvQuadratureRule;
78 using ScvfQuadratureRule = typename GG::ScvfQuadratureRule;
80 using ElementQuadratureRule = typename GG::ElementQuadratureRule;
82 using IntersectionQuadratureRule = typename GG::IntersectionQuadratureRule;
84 using BoundaryFaceQuadratureRule = typename GG::BoundaryFaceQuadratureRule;
86 static constexpr std::size_t maxNumElementDofs = GridGeometry::maxNumElementDofs;
87
89 PQ1BubbleFVElementGeometry(const GGCache& ggCache)
90 : ggCache_(&ggCache)
91 {}
92
94 const SubControlVolume& scv(LocalIndexType scvIdx) const
95 {
96 return ggCache_->scvs(eIdx_)[scvIdx];
97 }
98
100 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
101 {
102 return ggCache_->scvfs(eIdx_)[scvfIdx];
103 }
104
110 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
112 {
113 using Iter = typename std::vector<SubControlVolume>::const_iterator;
114 const auto& s = fvGeometry.ggCache_->scvs(fvGeometry.eIdx_);
115 return Dune::IteratorRange<Iter>(s.begin(), s.end());
116 }
117
119 friend inline auto cvLocalDofs(const PQ1BubbleFVElementGeometry& fvGeometry)
120 {
121 return Dune::transformedRangeView(
122 Dune::range(fvGeometry.numLocalDofs()-GeometryHelper::numNonCVLocalDofs(fvGeometry.element().type())),
123 [&](const auto i) { return CVFE::LocalDof
124 {
125 static_cast<LocalIndexType>(i),
126 static_cast<GridIndexType>(GeometryHelper::dofIndex(fvGeometry.gridGeometry().dofMapper(), fvGeometry.element(),
127 fvGeometry.feLocalCoefficients().localKey(i))),
128 static_cast<GridIndexType>(fvGeometry.elementIndex())
129 }; }
130 );
131 }
132
134 template<bool enable = GridGeometry::enableHybridCVFE, std::enable_if_t<enable, int> = 0>
135 friend inline auto nonCVLocalDofs(const PQ1BubbleFVElementGeometry& fvGeometry)
136 {
137 return Dune::transformedRangeView(
138 Dune::range(fvGeometry.numLocalDofs()-GeometryHelper::numNonCVLocalDofs(fvGeometry.element().type()), fvGeometry.numLocalDofs()),
139 [&](const auto i) { return CVFE::LocalDof
140 {
141 static_cast<LocalIndexType>(i),
142 static_cast<GridIndexType>(GeometryHelper::dofIndex(fvGeometry.gridGeometry().dofMapper(), fvGeometry.element(),
143 fvGeometry.feLocalCoefficients().localKey(i))),
144 static_cast<GridIndexType>(fvGeometry.elementIndex())
145 }; }
146 );
147 }
148
150 friend inline auto localDofs(const PQ1BubbleFVElementGeometry& fvGeometry)
151 {
152 return Dune::transformedRangeView(
153 Dune::range(fvGeometry.numLocalDofs()),
154 [&](const auto i) { return CVFE::LocalDof
155 {
156 static_cast<LocalIndexType>(i),
157 static_cast<GridIndexType>(GeometryHelper::dofIndex(fvGeometry.gridGeometry().dofMapper(), fvGeometry.element(),
158 fvGeometry.feLocalCoefficients().localKey(i))),
159 static_cast<GridIndexType>(fvGeometry.elementIndex())
160 }; }
161 );
162 }
163
165 friend inline auto localDofs(const PQ1BubbleFVElementGeometry& fvGeometry, const BoundaryFace& boundaryFace)
166 {
167 return Dune::transformedRangeView(
168 Dune::range(GeometryHelper::numLocalDofsIntersection(fvGeometry.element().type(), boundaryFace.intersectionIndex())),
169 [&](const auto i)
170 {
171 auto localDofIdx = GeometryHelper::localDofIndexIntersection(fvGeometry.element().type(), boundaryFace.intersectionIndex(), i);
172 return CVFE::LocalDof
173 {
174 static_cast<LocalIndexType>(localDofIdx),
175 static_cast<GridIndexType>(GeometryHelper::dofIndex(fvGeometry.gridGeometry().dofMapper(), fvGeometry.element(),
176 fvGeometry.feLocalCoefficients().localKey(localDofIdx))),
177 static_cast<GridIndexType>(fvGeometry.elementIndex())
178 };
179 }
180 );
181 }
182
188 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
190 {
191 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
192 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
193 return Dune::IteratorRange<Iter>(s.begin(), s.end());
194 }
195
198 friend inline std::ranges::view auto
200 {
201 const auto& v = fvGeometry.ggCache_->boundaryFaces(fvGeometry.eIdx_);
202 return std::ranges::views::all(v);
203 }
204
206 const FeLocalBasis& feLocalBasis() const
207 {
208 return gridGeometry().feCache().get(element_->type()).localBasis();
209 }
210
212 const auto& feLocalCoefficients() const
213 {
214 return gridGeometry().feCache().get(element_->type()).localCoefficients();
215 }
216
218 std::size_t numLocalDofs() const
219 {
220 return GeometryHelper::numElementDofs(element().type());
221 }
222
224 std::size_t numScv() const
225 {
226 return ggCache_->scvs(eIdx_).size();
227 }
228
230 std::size_t numScvf() const
231 {
232 return ggCache_->scvfs(eIdx_).size();
233 }
234
241 {
242 this->bindElement(element);
243 return std::move(*this);
244 }
245
249 void bind(const Element& element) &
250 { this->bindElement(element); }
251
258 {
259 this->bindElement(element);
260 return std::move(*this);
261 }
262
266 void bindElement(const Element& element) &
267 {
268 element_ = element;
269 // cache element index
270 eIdx_ = gridGeometry().elementMapper().index(element);
271 elementGeometry_.emplace(element.geometry());
272 }
273
275 bool isBound() const
276 { return static_cast<bool>(element_); }
277
279 const Element& element() const
280 { return *element_; }
281
283 const typename Element::Geometry& elementGeometry() const
284 { return *elementGeometry_; }
285
288 { return ggCache_->gridGeometry(); }
289
291 bool hasBoundaryScvf() const
292 { return ggCache_->hasBoundaryScvf(eIdx_); }
293
295 bool hasBoundaryFaces() const
296 { return hasBoundaryScvf(); }
297
299 const BoundaryFace& boundaryFace(LocalIndexType bfIdx) const
300 { return ggCache_->boundaryFaces(eIdx_)[bfIdx]; }
301
303 std::size_t elementIndex() const
304 { return eIdx_; }
305
307 std::size_t intersectionIndex(const SubControlVolumeFace& scvf) const
308 {
309 const auto localScvfIdx = scvf.index() - GeometryHelper::numInteriorScvf(element().type());
310 return ggCache_->scvfBoundaryGeometryKeys(eIdx_)[localScvfIdx][0];
311 }
312
314 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
315 {
316 if (scv.isOverlapping())
317 DUNE_THROW(Dune::NotImplemented, "Geometry of overlapping scv");
318
319 assert(isBound());
320 const GeometryHelper helper(*elementGeometry_);
321 return {
322 helper.getScvGeometryType(scv.indexInElement()),
323 helper.getScvCorners(scv.indexInElement())
324 };
325 }
326
328 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
329 {
330 assert(isBound());
331 if (scvf.boundary())
332 {
333 GeometryHelper helper(*elementGeometry_);
334 const auto localScvfIdx = scvf.index() - GeometryHelper::numInteriorScvf(element().type());
335 const auto [localFacetIndex, isScvfLocalIdx]
336 = ggCache_->scvfBoundaryGeometryKeys(eIdx_)[localScvfIdx];
337 return {
338 helper.getBoundaryScvfGeometryType(isScvfLocalIdx),
339 helper.getBoundaryScvfCorners(localFacetIndex, isScvfLocalIdx)
340 };
341 }
342 else
343 {
344 GeometryHelper helper(*elementGeometry_);
345 return {
346 helper.getInteriorScvfGeometryType(scvf.index()),
347 helper.getScvfCorners(scvf.index())
348 };
349 }
350 }
351
353 typename BoundaryFace::Traits::Geometry geometry(const BoundaryFace& boundaryFace) const
354 {
355 assert(isBound());
356 const auto& elemGeo = elementGeometry();
357 const auto faceGeoInRef = referenceElement(elemGeo).template geometry<1>(boundaryFace.intersectionIndex());
358 typename BoundaryFace::Traits::CornerStorage corners;
359 for (int i = 0; i < faceGeoInRef.corners(); ++i)
360 corners.push_back(elemGeo.global(faceGeoInRef.corner(i)));
361 return { faceGeoInRef.type(), corners };
362 }
363
365 friend inline auto ipData(const PQ1BubbleFVElementGeometry& fvGeometry, const SubControlVolume& scv)
366 {
367 const auto type = fvGeometry.element().type();
368 const auto& localKey = fvGeometry.gridGeometry().feCache().get(type).localCoefficients().localKey(scv.localDofIndex());
369
370 return CVFE::LocalDofInterpolationPointData{ GeometryHelper::localDofPosition(type, localKey), scv.dofPosition(), scv.localDofIndex() };
371 }
372
374 template<class LocalDof>
375 friend inline auto ipData(const PQ1BubbleFVElementGeometry& fvGeometry, const LocalDof& localDof)
376 {
377 const auto type = fvGeometry.element().type();
378 const auto& localKey = fvGeometry.gridGeometry().feCache().get(type).localCoefficients().localKey(localDof.index());
379 const auto& localPos = GeometryHelper::localDofPosition(type, localKey);
380
381 return CVFE::LocalDofInterpolationPointData{ localPos, fvGeometry.elementGeometry().global(localPos), localDof.index() };
382 }
383
385 friend inline auto ipData(const PQ1BubbleFVElementGeometry& fvGeometry, const typename Element::Geometry::GlobalCoordinate& globalPos)
386 {
387 // Create ipData that does not automatically calculate the local position but only if it is called
389 [&] (const typename Element::Geometry::GlobalCoordinate& pos) { return fvGeometry.elementGeometry().local(pos); },
390 globalPos
391 };
392 }
393
395 friend inline auto ipData(const PQ1BubbleFVElementGeometry& fvGeometry, const SubControlVolumeFace& scvf)
396 {
398 { scvf.unitOuterNormal(), scvf.index(), fvGeometry.elementGeometry().local(scvf.ipGlobal()), scvf.ipGlobal() };
399 }
400
401private:
402 const GGCache* ggCache_;
403 GridIndexType eIdx_;
404
405 std::optional<Element> element_;
406 std::optional<typename Element::Geometry> elementGeometry_;
407};
408
409} // end namespace Dumux
410
411#endif
An interpolation point related to a face of an element.
Definition: cvfe/interpolationpointdata.hh:109
const GlobalPosition & unitOuterNormal() const
The unit outer normal vector at the quadrature point.
Definition: cvfe/interpolationpointdata.hh:123
An interpolation point related to an element that includes global and local positions.
Definition: cvfe/interpolationpointdata.hh:31
An interpolation point related to a global position of an element, giving its local positions by a ma...
Definition: cvfe/interpolationpointdata.hh:82
An interpolation point related to a localDof of an element, giving its global and local positions.
Definition: cvfe/interpolationpointdata.hh:60
LocalIndex localDofIndex() const
The local index of the corresponding dof.
Definition: cvfe/interpolationpointdata.hh:69
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const PQ1BubbleFVElementGeometry &fvGeometry)
Definition: discretization/pq1bubble/fvelementgeometry.hh:111
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const PQ1BubbleFVElementGeometry &fvGeometry)
Definition: discretization/pq1bubble/fvelementgeometry.hh:189
typename GridView::template Codim< 0 >::Entity Element
export the element type
Definition: discretization/pq1bubble/fvelementgeometry.hh:66
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition: discretization/pq1bubble/fvelementgeometry.hh:291
friend auto nonCVLocalDofs(const PQ1BubbleFVElementGeometry &fvGeometry)
iterate over dof indices that are treated as hybrid dofs using the finite element method
Definition: discretization/pq1bubble/fvelementgeometry.hh:135
typename GG::BoundaryFace BoundaryFace
export the boundary face type
Definition: discretization/pq1bubble/fvelementgeometry.hh:74
friend std::ranges::view auto boundaryFaces(const PQ1BubbleFVElementGeometry &fvGeometry)
Definition: discretization/pq1bubble/fvelementgeometry.hh:199
bool hasBoundaryFaces() const
Returns whether the element has boundary faces.
Definition: discretization/pq1bubble/fvelementgeometry.hh:295
PQ1BubbleFVElementGeometry(const GGCache &ggCache)
Constructor.
Definition: discretization/pq1bubble/fvelementgeometry.hh:89
typename GG::IntersectionQuadratureRule IntersectionQuadratureRule
the quadrature rule type for intersections
Definition: discretization/pq1bubble/fvelementgeometry.hh:82
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition: discretization/pq1bubble/fvelementgeometry.hh:94
friend auto localDofs(const PQ1BubbleFVElementGeometry &fvGeometry)
an iterator over all local dofs
Definition: discretization/pq1bubble/fvelementgeometry.hh:150
GG GridGeometry
export type of finite volume grid geometry
Definition: discretization/pq1bubble/fvelementgeometry.hh:72
friend auto ipData(const PQ1BubbleFVElementGeometry &fvGeometry, const LocalDof &localDof)
Interpolation point data for a localDof.
Definition: discretization/pq1bubble/fvelementgeometry.hh:375
const BoundaryFace & boundaryFace(LocalIndexType bfIdx) const
Get a boundary face with a local boundary face index.
Definition: discretization/pq1bubble/fvelementgeometry.hh:299
std::size_t numLocalDofs() const
The total number of element-local dofs.
Definition: discretization/pq1bubble/fvelementgeometry.hh:218
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition: discretization/pq1bubble/fvelementgeometry.hh:206
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition: discretization/pq1bubble/fvelementgeometry.hh:70
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition: discretization/pq1bubble/fvelementgeometry.hh:68
PQ1BubbleFVElementGeometry 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: discretization/pq1bubble/fvelementgeometry.hh:257
const Element::Geometry & elementGeometry() const
The bound element geometry.
Definition: discretization/pq1bubble/fvelementgeometry.hh:283
void bindElement(const Element &element) &
Definition: discretization/pq1bubble/fvelementgeometry.hh:266
friend auto ipData(const PQ1BubbleFVElementGeometry &fvGeometry, const SubControlVolume &scv)
Interpolation point data for an scv.
Definition: discretization/pq1bubble/fvelementgeometry.hh:365
friend auto localDofs(const PQ1BubbleFVElementGeometry &fvGeometry, const BoundaryFace &boundaryFace)
an iterator over all local dofs related to a boundary face
Definition: discretization/pq1bubble/fvelementgeometry.hh:165
typename GG::ScvQuadratureRule ScvQuadratureRule
the quadrature rule type for scvs
Definition: discretization/pq1bubble/fvelementgeometry.hh:76
friend auto ipData(const PQ1BubbleFVElementGeometry &fvGeometry, const SubControlVolumeFace &scvf)
Interpolation point data for scvf.
Definition: discretization/pq1bubble/fvelementgeometry.hh:395
void bind(const Element &element) &
Definition: discretization/pq1bubble/fvelementgeometry.hh:249
PQ1BubbleFVElementGeometry 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: discretization/pq1bubble/fvelementgeometry.hh:240
typename GG::BoundaryFaceQuadratureRule BoundaryFaceQuadratureRule
the quadrature rule type for boundary faces
Definition: discretization/pq1bubble/fvelementgeometry.hh:84
std::size_t intersectionIndex(const SubControlVolumeFace &scvf) const
The intersection index the scvf belongs to.
Definition: discretization/pq1bubble/fvelementgeometry.hh:307
typename GG::ElementQuadratureRule ElementQuadratureRule
the quadrature rule type for elements
Definition: discretization/pq1bubble/fvelementgeometry.hh:80
const auto & feLocalCoefficients() const
Get the local finite element coefficients.
Definition: discretization/pq1bubble/fvelementgeometry.hh:212
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Geometry of a sub control volume face.
Definition: discretization/pq1bubble/fvelementgeometry.hh:328
friend auto ipData(const PQ1BubbleFVElementGeometry &fvGeometry, const typename Element::Geometry::GlobalCoordinate &globalPos)
Interpolation point data for a global position.
Definition: discretization/pq1bubble/fvelementgeometry.hh:385
std::size_t numScv() const
The total number of sub control volumes.
Definition: discretization/pq1bubble/fvelementgeometry.hh:224
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Geometry of a sub control volume.
Definition: discretization/pq1bubble/fvelementgeometry.hh:314
friend auto cvLocalDofs(const PQ1BubbleFVElementGeometry &fvGeometry)
iterate over dof indices that belong to dofs associated with control volumes
Definition: discretization/pq1bubble/fvelementgeometry.hh:119
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition: discretization/pq1bubble/fvelementgeometry.hh:100
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition: discretization/pq1bubble/fvelementgeometry.hh:275
std::size_t elementIndex() const
The bound element index.
Definition: discretization/pq1bubble/fvelementgeometry.hh:303
BoundaryFace::Traits::Geometry geometry(const BoundaryFace &boundaryFace) const
Geometry of a boundary face.
Definition: discretization/pq1bubble/fvelementgeometry.hh:353
std::size_t numScvf() const
The total number of sub control volume faces.
Definition: discretization/pq1bubble/fvelementgeometry.hh:230
const GridGeometry & gridGeometry() const
The grid geometry we are a restriction of.
Definition: discretization/pq1bubble/fvelementgeometry.hh:287
typename GG::ScvfQuadratureRule ScvfQuadratureRule
the quadrature rule type for scvfs
Definition: discretization/pq1bubble/fvelementgeometry.hh:78
const Element & element() const
The bound element.
Definition: discretization/pq1bubble/fvelementgeometry.hh:279
Base class for the finite volume geometry vector for pq1bubble models This builds up the sub control ...
Definition: discretization/pq1bubble/fvelementgeometry.hh:43
Classes representing interpolation point data for control-volume finite element schemes.
Helper class constructing the dual grid finite volume geometries for the cvfe discretizazion method.
Defines the index types used for grid and local indices.
Class representing dofs on elements for control-volume finite element schemes.
Definition: adapt.hh:17
Quadrature rules over sub-control volumes and sub-control volume faces.
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