version 3.11-dev
Loading...
Searching...
No Matches
discretization/pq2/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_PQ2_FV_ELEMENT_GEOMETRY_HH
15#define DUMUX_DISCRETIZATION_PQ2_FV_ELEMENT_GEOMETRY_HH
16
17#include <cstddef>
18#include <cassert>
19#include <optional>
20#include <ranges>
21#include <span>
22#include <utility>
23#include <vector>
24
25#include <dune/common/rangeutilities.hh>
26#include <dune/geometry/type.hh>
27#include <dune/localfunctions/lagrange/pqkfactory.hh>
28
34
36
37namespace Dumux {
38
47template<class GG, bool enableGridGeometryCache>
49
51template<class GG>
52class PQ2FVElementGeometry<GG, true>
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;
61 using GGCache = typename GG::Cache;
62 using GeometryHelper = typename GGCache::GeometryHelper;
63 using DofHelper = typename GGCache::DofHelper;
64
65 using BaseIpData = CVFE::InterpolationPointData<
66 typename GridView::template Codim<0>::Entity::Geometry::LocalCoordinate,
67 typename GridView::template Codim<0>::Entity::Geometry::GlobalCoordinate
68 >;
69
70public:
72 using Element = typename GridView::template Codim<0>::Entity;
74 using SubControlVolume = typename GG::SubControlVolume;
76 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
78 using GridGeometry = GG;
80 using BoundaryFace = typename GG::BoundaryFace;
82 using ScvQuadratureRule = typename GG::ScvQuadratureRule;
84 using ScvfQuadratureRule = typename GG::ScvfQuadratureRule;
86 using ElementQuadratureRule = typename GG::ElementQuadratureRule;
88 using IntersectionQuadratureRule = typename GG::IntersectionQuadratureRule;
90 using BoundaryFaceQuadratureRule = typename GG::BoundaryFaceQuadratureRule;
92 static constexpr std::size_t maxNumElementDofs = GridGeometry::maxNumElementDofs;
93
95 PQ2FVElementGeometry(const GGCache& ggCache)
96 : ggCache_(&ggCache)
97 {}
98
100 const SubControlVolume& scv(LocalIndexType scvIdx) const
101 {
102 return ggCache_->scvs(eIdx_)[scvIdx];
103 }
104
106 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
107 {
108 return ggCache_->scvfs(eIdx_)[scvfIdx];
109 }
110
116 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
117 scvs(const PQ2FVElementGeometry& fvGeometry)
118 {
119 using Iter = typename std::vector<SubControlVolume>::const_iterator;
120 const auto& s = fvGeometry.ggCache_->scvs(fvGeometry.eIdx_);
121 return Dune::IteratorRange<Iter>(s.begin(), s.end());
122 }
123
124 friend inline auto cvLocalDofs(const PQ2FVElementGeometry& fvGeometry)
125 {
126 return std::views::iota(std::size_t(0), fvGeometry.numLocalDofs())
127 | std::views::filter([&](size_t i) { return fvGeometry.feLocalCoefficients().localKey(i).codim() == dim; })
128 | std::views::transform([&](size_t i) {
129 return CVFE::LocalDof{
130 static_cast<LocalIndexType>(i),
131 dofIndex_(fvGeometry, fvGeometry.feLocalCoefficients().localKey(i)),
132 static_cast<GridIndexType>(fvGeometry.elementIndex())
133 };
134 });
135 }
136
137 friend inline auto nonCVLocalDofs(const PQ2FVElementGeometry& fvGeometry)
138 {
139 return std::views::iota(std::size_t(0), fvGeometry.numLocalDofs())
140 | std::views::filter([&](size_t i) { return !(fvGeometry.feLocalCoefficients().localKey(i).codim() == dim); })
141 | std::views::transform([&](size_t i) {
142 return CVFE::LocalDof{
143 static_cast<LocalIndexType>(i),
144 dofIndex_(fvGeometry, fvGeometry.feLocalCoefficients().localKey(i)),
145 static_cast<GridIndexType>(fvGeometry.elementIndex())
146 };
147 });
148 }
149
150 friend inline auto localDofs(const PQ2FVElementGeometry& fvGeometry)
151 {
152 return Dune::transformedRangeView(
153 Dune::range(std::size_t(0), fvGeometry.numLocalDofs()), [&](const auto i) {
154 return CVFE::LocalDof{
155 static_cast<LocalIndexType>(i),
156 dofIndex_(fvGeometry, fvGeometry.feLocalCoefficients().localKey(i)),
157 static_cast<GridIndexType>(fvGeometry.elementIndex())
158 };
159 }
160 );
161 }
162
164 friend inline auto localDofs(const PQ2FVElementGeometry& fvGeometry, const BoundaryFace& boundaryFace)
165 { return DofHelper::localDofsOnBoundaryFace(fvGeometry, boundaryFace); }
166
172 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
173 scvfs(const PQ2FVElementGeometry& fvGeometry)
174 {
175 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
176 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
177 return Dune::IteratorRange<Iter>(s.begin(), s.end());
178 }
179
182 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
184 {
185 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
186 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
187 const auto& range = fvGeometry.ggCache_->boundaryFaceScvfRanges(fvGeometry.eIdx_)[boundaryFace.index()];
188 return Dune::IteratorRange<Iter>(s.begin() + range[0], s.begin() + range[0] + range[1]);
189 }
190
193 friend inline std::ranges::view auto
195 {
196 const auto& v = fvGeometry.ggCache_->boundaryFaces(fvGeometry.eIdx_);
197 return std::ranges::views::all(v);
198 }
199
201 const FeLocalBasis& feLocalBasis() const
202 {
203 return gridDiscretization().feCache().get(element_->type()).localBasis();
204 }
205
207 const auto& feLocalCoefficients() const
208 {
209 return gridDiscretization().feCache().get(element_->type()).localCoefficients();
210 }
211
213 std::size_t numLocalDofs() const
214 {
215 return feLocalCoefficients().size();
216 }
217
219 std::size_t numScv() const
220 {
221 return ggCache_->scvs(eIdx_).size();
222 }
223
225 std::size_t numScvf() const
226 {
227 return ggCache_->scvfs(eIdx_).size();
228 }
229
236 {
237 this->bindElement(element);
238 return std::move(*this);
239 }
240
244 void bind(const Element& element) &
245 { this->bindElement(element); }
246
253 {
254 this->bindElement(element);
255 return std::move(*this);
256 }
257
262 {
263 element_ = element;
264 // cache element index
265 eIdx_ = gridDiscretization().elementMapper().index(element);
266 elementGeometry_.emplace(element.geometry());
267 }
268
270 bool isBound() const
271 { return static_cast<bool>(element_); }
272
274 const Element& element() const
275 { return *element_; }
276
278 const typename Element::Geometry& elementGeometry() const
279 { return *elementGeometry_; }
280
283 { return ggCache_->gridGeometry(); }
284
286 bool hasBoundaryScvf() const
287 { return ggCache_->hasBoundaryScvf(eIdx_); }
288
290 bool hasBoundaryFaces() const
291 { return hasBoundaryScvf(); }
292
294 const BoundaryFace& boundaryFace(LocalIndexType bfIdx) const
295 { return ggCache_->boundaryFaces(eIdx_)[bfIdx]; }
296
298 std::size_t elementIndex() const
299 { return eIdx_; }
300
303 {
304 const auto localScvfIdx = scvf.index() - GeometryHelper::numInteriorScvf(element().type());
305 return ggCache_->scvfBoundaryGeometryKeys(eIdx_)[localScvfIdx][0];
306 }
307
309 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
310 {
311 assert(isBound());
312 const auto& geo = elementGeometry();
313 const GeometryHelper helper(geo);
314 const auto scvIdx = this->feLocalCoefficients().localKey(scv.localDofIndex()).subEntity();
315 return {
316 helper.getScvGeometryType(scvIdx),
317 helper.getScvCorners(scvIdx)
318 };
319 }
320
322 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
323 {
324 assert(isBound());
325 if (scvf.boundary())
326 {
327 GeometryHelper helper(*elementGeometry_);
328 const auto localScvfIdx = scvf.index() - GeometryHelper::numInteriorScvf(element().type());
329 const auto [localFacetIndex, isScvfLocalIdx]
330 = ggCache_->scvfBoundaryGeometryKeys(eIdx_)[localScvfIdx];
331 return {
332 helper.getBoundaryScvfGeometryType(isScvfLocalIdx),
333 helper.getBoundaryScvfCorners(localFacetIndex, isScvfLocalIdx)
334 };
335 }
336 else
337 {
338 GeometryHelper helper(*elementGeometry_);
339 return {
340 helper.getInteriorScvfGeometryType(scvf.index()),
341 helper.getScvfCorners(scvf.index())
342 };
343 }
344 }
345
347 typename BoundaryFace::Traits::Geometry geometry(const BoundaryFace& boundaryFace) const
348 {
349 assert(isBound());
350 const auto& elemGeo = elementGeometry();
351 const auto faceGeoInRef = referenceElement(elemGeo).template geometry<1>(boundaryFace.intersectionIndex());
352 typename BoundaryFace::Traits::CornerStorage corners;
353 for (int i = 0; i < faceGeoInRef.corners(); ++i)
354 corners.push_back(elemGeo.global(faceGeoInRef.corner(i)));
355 return { faceGeoInRef.type(), corners };
356 }
357
359 friend inline auto ipData(const PQ2FVElementGeometry& fvGeometry, const SubControlVolume& scv)
360 {
361 const auto type = fvGeometry.element().type();
362 const auto& localKey = fvGeometry.feLocalCoefficients().localKey(scv.localDofIndex());
363
364 return CVFE::LocalDofInterpolationPointData{ DofHelper::localDofPosition(type, localKey), scv.dofPosition(), scv.localDofIndex() };
365 }
366
368 template<class LocalDof>
369 friend inline auto ipData(const PQ2FVElementGeometry& fvGeometry, const LocalDof& localDof)
370 {
371 const auto type = fvGeometry.element().type();
372 const auto& localKey = fvGeometry.feLocalCoefficients().localKey(localDof.index());
373 const auto& localPos = DofHelper::localDofPosition(type, localKey);
374
375 return CVFE::LocalDofInterpolationPointData{ localPos, fvGeometry.elementGeometry().global(localPos), localDof.index() };
376 }
377
379 friend inline auto ipData(const PQ2FVElementGeometry& fvGeometry, const typename Element::Geometry::GlobalCoordinate& globalPos)
380 {
381 // Create ipData that does not automatically calculate the local position but only if it is called
383 [&] (const typename Element::Geometry::GlobalCoordinate& pos) { return fvGeometry.elementGeometry().local(pos); },
384 globalPos
385 };
386 }
387
389 friend inline auto ipData(const PQ2FVElementGeometry& fvGeometry, const SubControlVolumeFace& scvf)
390 {
392 { scvf.unitOuterNormal(), scvf.index(), fvGeometry.elementGeometry().local(scvf.ipGlobal()), scvf.ipGlobal() };
393 }
394
395private:
399 template<class LocalKey>
400 static GridIndexType dofIndex_(const PQ2FVElementGeometry& fvGeometry, const LocalKey& lk)
401 {
402 if constexpr (requires { fvGeometry.gridDiscretization().dofIndex(fvGeometry.element(), lk); })
403 return static_cast<GridIndexType>(fvGeometry.gridDiscretization().dofIndex(fvGeometry.element(), lk));
404 else
405 return static_cast<GridIndexType>(DofHelper::dofIndex(fvGeometry.gridDiscretization().dofMapper(), fvGeometry.element(), lk));
406 }
407
408 const GGCache* ggCache_;
409 GridIndexType eIdx_;
410
411 std::optional<Element> element_;
412 std::optional<typename Element::Geometry> elementGeometry_;
413};
414
415} // end namespace Dumux
416
417#endif
An interpolation point related to a face of an element.
Definition cvfe/interpolationpointdata.hh:109
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
A local degree of freedom from an element perspective.
Definition localdof.hh:27
An interpolation point related to a localDof of an element, giving its global and local positions.
Definition cvfe/interpolationpointdata.hh:60
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition discretization/pq2/fvelementgeometry.hh:270
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const PQ2FVElementGeometry &fvGeometry, const BoundaryFace &boundaryFace)
Definition discretization/pq2/fvelementgeometry.hh:183
std::size_t intersectionIndex(const SubControlVolumeFace &scvf) const
The intersection index the scvf belongs to.
Definition discretization/pq2/fvelementgeometry.hh:302
const Element::Geometry & elementGeometry() const
The bound element geometry.
Definition discretization/pq2/fvelementgeometry.hh:278
typename GG::ScvfQuadratureRule ScvfQuadratureRule
the quadrature rule type for scvfs
Definition discretization/pq2/fvelementgeometry.hh:84
friend auto ipData(const PQ2FVElementGeometry &fvGeometry, const SubControlVolume &scv)
Interpolation point data for an scv.
Definition discretization/pq2/fvelementgeometry.hh:359
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const PQ2FVElementGeometry &fvGeometry)
Definition discretization/pq2/fvelementgeometry.hh:173
friend auto ipData(const PQ2FVElementGeometry &fvGeometry, const LocalDof &localDof)
Interpolation point data for a localDof.
Definition discretization/pq2/fvelementgeometry.hh:369
void bind(const Element &element) &
Definition discretization/pq2/fvelementgeometry.hh:244
BoundaryFace::Traits::Geometry geometry(const BoundaryFace &boundaryFace) const
Geometry of a boundary face.
Definition discretization/pq2/fvelementgeometry.hh:347
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Geometry of a sub control volume face.
Definition discretization/pq2/fvelementgeometry.hh:322
PQ2FVElementGeometry(const GGCache &ggCache)
Constructor.
Definition discretization/pq2/fvelementgeometry.hh:95
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const PQ2FVElementGeometry &fvGeometry)
Definition discretization/pq2/fvelementgeometry.hh:117
friend auto ipData(const PQ2FVElementGeometry &fvGeometry, const SubControlVolumeFace &scvf)
Interpolation point data for scvf.
Definition discretization/pq2/fvelementgeometry.hh:389
const auto & feLocalCoefficients() const
Get a local finite element basis.
Definition discretization/pq2/fvelementgeometry.hh:207
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition discretization/pq2/fvelementgeometry.hh:76
friend auto nonCVLocalDofs(const PQ2FVElementGeometry &fvGeometry)
Definition discretization/pq2/fvelementgeometry.hh:137
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Geometry of a sub control volume.
Definition discretization/pq2/fvelementgeometry.hh:309
friend auto ipData(const PQ2FVElementGeometry &fvGeometry, const typename Element::Geometry::GlobalCoordinate &globalPos)
Interpolation point data for a global position.
Definition discretization/pq2/fvelementgeometry.hh:379
PQ2FVElementGeometry 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/pq2/fvelementgeometry.hh:235
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/pq2/fvelementgeometry.hh:219
std::size_t numScvf() const
The total number of sub control volume faces.
Definition discretization/pq2/fvelementgeometry.hh:225
void bindElement(const Element &element) &
Definition discretization/pq2/fvelementgeometry.hh:261
static constexpr std::size_t maxNumElementDofs
the maximum number of scvs per element for hypercubes
Definition discretization/pq2/fvelementgeometry.hh:92
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition discretization/pq2/fvelementgeometry.hh:286
typename GG::ScvQuadratureRule ScvQuadratureRule
the quadrature rule type for scvs
Definition discretization/pq2/fvelementgeometry.hh:82
bool hasBoundaryFaces() const
Returns whether the element has boundary faces.
Definition discretization/pq2/fvelementgeometry.hh:290
std::size_t elementIndex() const
The bound element index.
Definition discretization/pq2/fvelementgeometry.hh:298
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition discretization/pq2/fvelementgeometry.hh:106
friend auto localDofs(const PQ2FVElementGeometry &fvGeometry)
Definition discretization/pq2/fvelementgeometry.hh:150
const BoundaryFace & boundaryFace(LocalIndexType bfIdx) const
Get a boundary face with a local boundary face index.
Definition discretization/pq2/fvelementgeometry.hh:294
friend auto cvLocalDofs(const PQ2FVElementGeometry &fvGeometry)
Definition discretization/pq2/fvelementgeometry.hh:124
typename GG::ElementQuadratureRule ElementQuadratureRule
the quadrature rule type for elements
Definition discretization/pq2/fvelementgeometry.hh:86
typename GG::IntersectionQuadratureRule IntersectionQuadratureRule
the quadrature rule type for intersections
Definition discretization/pq2/fvelementgeometry.hh:88
friend std::ranges::view auto boundaryFaces(const PQ2FVElementGeometry &fvGeometry)
Definition discretization/pq2/fvelementgeometry.hh:194
typename GG::BoundaryFace BoundaryFace
export the boundary face type
Definition discretization/pq2/fvelementgeometry.hh:80
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition discretization/pq2/fvelementgeometry.hh:100
std::size_t numLocalDofs() const
The total number of element-local dofs.
Definition discretization/pq2/fvelementgeometry.hh:213
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition discretization/pq2/fvelementgeometry.hh:74
typename GG::BoundaryFaceQuadratureRule BoundaryFaceQuadratureRule
the quadrature rule type for boundary faces
Definition discretization/pq2/fvelementgeometry.hh:90
GG GridGeometry
export type of finite volume grid geometry
Definition discretization/pq2/fvelementgeometry.hh:78
typename GridView::template Codim< 0 >::Entity Element
export the element type
Definition discretization/pq2/fvelementgeometry.hh:72
const GridGeometry & gridDiscretization() const
The grid discretization we are a restriction of.
Definition discretization/pq2/fvelementgeometry.hh:282
const Element & element() const
The bound element.
Definition discretization/pq2/fvelementgeometry.hh:274
friend auto localDofs(const PQ2FVElementGeometry &fvGeometry, const BoundaryFace &boundaryFace)
an iterator over all local dofs related to a boundary face
Definition discretization/pq2/fvelementgeometry.hh:164
PQ2FVElementGeometry 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/pq2/fvelementgeometry.hh:252
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition discretization/pq2/fvelementgeometry.hh:201
Base class for the finite volume geometry vector for pq2 models This builds up the sub control volume...
Definition discretization/pq2/fvelementgeometry.hh:48
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