version 3.11-dev
Loading...
Searching...
No Matches
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/common/reservedvector.hh>
22#include <dune/geometry/type.hh>
23#include <dune/localfunctions/lagrange/pqkfactory.hh>
24
30
32
33namespace Dumux {
34
43template<class GG, bool enableGridGeometryCache>
45
47template<class GG>
49{
50 using GridView = typename GG::GridView;
51 static constexpr int dim = GridView::dimension;
52 static constexpr int dimWorld = GridView::dimensionworld;
53 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
54 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
55 using CoordScalar = typename GridView::ctype;
56 using FiniteElement = typename GG::FeCache::FiniteElementType;
57 using FeLocalBasis = typename FiniteElement::Traits::LocalBasisType;
58 using GGCache = typename GG::Cache;
59 using GeometryHelper = typename GGCache::GeometryHelper;
60 using DofHelper = typename GGCache::DofHelper;
61
62 using BaseIpData = CVFE::InterpolationPointData<
63 typename GridView::template Codim<0>::Entity::Geometry::LocalCoordinate,
64 typename GridView::template Codim<0>::Entity::Geometry::GlobalCoordinate
65 >;
66
67public:
69 using Element = typename GridView::template Codim<0>::Entity;
71 using SubControlVolume = typename GG::SubControlVolume;
73 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
75 using GridGeometry = GG;
77 using BoundaryFace = typename GG::BoundaryFace;
79 using ScvQuadratureRule = typename GG::ScvQuadratureRule;
81 using ScvfQuadratureRule = typename GG::ScvfQuadratureRule;
83 using ElementQuadratureRule = typename GG::ElementQuadratureRule;
85 using IntersectionQuadratureRule = typename GG::IntersectionQuadratureRule;
87 using BoundaryFaceQuadratureRule = typename GG::BoundaryFaceQuadratureRule;
89 static constexpr std::size_t maxNumElementDofs = GridGeometry::maxNumElementDofs;
90
92 PQ1BubbleFVElementGeometry(const GGCache& ggCache)
93 : ggCache_(&ggCache)
94 {}
95
97 const SubControlVolume& scv(LocalIndexType scvIdx) const
98 {
99 return ggCache_->scvs(eIdx_)[scvIdx];
100 }
101
103 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
104 {
105 return ggCache_->scvfs(eIdx_)[scvfIdx];
106 }
107
113 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
115 {
116 using Iter = typename std::vector<SubControlVolume>::const_iterator;
117 const auto& s = fvGeometry.ggCache_->scvs(fvGeometry.eIdx_);
118 return Dune::IteratorRange<Iter>(s.begin(), s.end());
119 }
120
122 friend inline auto cvLocalDofs(const PQ1BubbleFVElementGeometry& fvGeometry)
123 {
124 return Dune::transformedRangeView(
125 Dune::range(fvGeometry.numLocalDofs()-GeometryHelper::numNonCVLocalDofs(fvGeometry.element().type())),
126 [&](const auto i) { return CVFE::LocalDof
127 {
128 static_cast<LocalIndexType>(i),
129 fvGeometry.dofIndices_[i],
130 static_cast<GridIndexType>(fvGeometry.elementIndex())
131 }; }
132 );
133 }
134
136 template<bool enable = GridGeometry::enableHybridCVFE, std::enable_if_t<enable, int> = 0>
137 friend inline auto nonCVLocalDofs(const PQ1BubbleFVElementGeometry& fvGeometry)
138 {
139 return Dune::transformedRangeView(
140 Dune::range(fvGeometry.numLocalDofs()-GeometryHelper::numNonCVLocalDofs(fvGeometry.element().type()), fvGeometry.numLocalDofs()),
141 [&](const auto i) { return CVFE::LocalDof
142 {
143 static_cast<LocalIndexType>(i),
144 fvGeometry.dofIndices_[i],
145 static_cast<GridIndexType>(fvGeometry.elementIndex())
146 }; }
147 );
148 }
149
151 friend inline auto localDofs(const PQ1BubbleFVElementGeometry& fvGeometry)
152 {
153 return Dune::transformedRangeView(
154 Dune::range(fvGeometry.numLocalDofs()),
155 [&](const auto i) { return CVFE::LocalDof
156 {
157 static_cast<LocalIndexType>(i),
158 fvGeometry.dofIndices_[i],
159 static_cast<GridIndexType>(fvGeometry.elementIndex())
160 }; }
161 );
162 }
163
165 friend inline auto localDofs(const PQ1BubbleFVElementGeometry& fvGeometry, const BoundaryFace& boundaryFace)
166 { return DofHelper::localDofsOnBoundaryFace(fvGeometry, boundaryFace); }
167
173 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
175 {
176 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
177 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
178 return Dune::IteratorRange<Iter>(s.begin(), s.end());
179 }
180
183 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
185 {
186 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
187 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
188 const auto& range = fvGeometry.ggCache_->boundaryFaceScvfRanges(fvGeometry.eIdx_)[boundaryFace.index()];
189 return Dune::IteratorRange<Iter>(s.begin() + range[0], s.begin() + range[0] + range[1]);
190 }
191
194 friend inline std::ranges::view auto
196 {
197 const auto& v = fvGeometry.ggCache_->boundaryFaces(fvGeometry.eIdx_);
198 return std::ranges::views::all(v);
199 }
200
202 const FeLocalBasis& feLocalBasis() const
203 {
204 return fe_->localBasis();
205 }
206
208 const auto& feLocalCoefficients() const
209 {
210 return fe_->localCoefficients();
211 }
212
214 std::size_t numLocalDofs() const
215 {
216 return dofIndices_.size();
217 }
218
220 std::size_t numScv() const
221 {
222 return ggCache_->scvs(eIdx_).size();
223 }
224
226 std::size_t numScvf() const
227 {
228 return ggCache_->scvfs(eIdx_).size();
229 }
230
237 {
238 this->bindElement(element);
239 return std::move(*this);
240 }
241
245 void bind(const Element& element) &
246 { this->bindElement(element); }
247
254 {
255 this->bindElement(element);
256 return std::move(*this);
257 }
258
263 {
264 element_ = element;
265 // cache element index
266 eIdx_ = gridDiscretization().elementMapper().index(element);
267 elementGeometry_.emplace(element.geometry());
268
269 // the local dofs are iterated many times per bind (every quadrature point of every face,
270 // every perturbation of a numerical derivative); look up the finite element and the dof
271 // indices once here instead of on every iteration
272 fe_ = &gridDiscretization().feCache().get(element.type());
273 const auto& localCoefficients = fe_->localCoefficients();
274 dofIndices_.clear();
275 for (std::size_t i = 0; i < DofHelper::numElementDofs(element.type()); ++i)
276 dofIndices_.push_back(static_cast<GridIndexType>(
277 DofHelper::dofIndex(gridDiscretization().dofMapper(), element, localCoefficients.localKey(i))
278 ));
279 }
280
282 bool isBound() const
283 { return static_cast<bool>(element_); }
284
286 const Element& element() const
287 { return *element_; }
288
290 const typename Element::Geometry& elementGeometry() const
291 { return *elementGeometry_; }
292
294 [[deprecated("Use gridDiscretization() instead")]]
296 { return ggCache_->gridGeometry(); }
297
300 { return ggCache_->gridGeometry(); }
301
303 bool hasBoundaryScvf() const
304 { return ggCache_->hasBoundaryScvf(eIdx_); }
305
307 bool hasBoundaryFaces() const
308 { return hasBoundaryScvf(); }
309
311 const BoundaryFace& boundaryFace(LocalIndexType bfIdx) const
312 { return ggCache_->boundaryFaces(eIdx_)[bfIdx]; }
313
315 std::size_t elementIndex() const
316 { return eIdx_; }
317
320 {
321 const auto localScvfIdx = scvf.index() - GeometryHelper::numInteriorScvf(element().type());
322 return ggCache_->scvfBoundaryGeometryKeys(eIdx_)[localScvfIdx][0];
323 }
324
326 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
327 {
328 if (scv.isOverlapping())
329 DUNE_THROW(Dune::NotImplemented, "Geometry of overlapping scv");
330
331 assert(isBound());
332 const GeometryHelper helper(*elementGeometry_);
333 return {
334 helper.getScvGeometryType(scv.indexInElement()),
335 helper.getScvCorners(scv.indexInElement())
336 };
337 }
338
340 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
341 {
342 assert(isBound());
343 if (scvf.boundary())
344 {
345 GeometryHelper helper(*elementGeometry_);
346 const auto localScvfIdx = scvf.index() - GeometryHelper::numInteriorScvf(element().type());
347 const auto [localFacetIndex, isScvfLocalIdx]
348 = ggCache_->scvfBoundaryGeometryKeys(eIdx_)[localScvfIdx];
349 return {
350 helper.getBoundaryScvfGeometryType(isScvfLocalIdx),
351 helper.getBoundaryScvfCorners(localFacetIndex, isScvfLocalIdx)
352 };
353 }
354 else
355 {
356 GeometryHelper helper(*elementGeometry_);
357 return {
358 helper.getInteriorScvfGeometryType(scvf.index()),
359 helper.getScvfCorners(scvf.index())
360 };
361 }
362 }
363
365 typename BoundaryFace::Traits::Geometry geometry(const BoundaryFace& boundaryFace) const
366 {
367 assert(isBound());
368 const auto& elemGeo = elementGeometry();
369 const auto faceGeoInRef = referenceElement(elemGeo).template geometry<1>(boundaryFace.intersectionIndex());
370 typename BoundaryFace::Traits::CornerStorage corners;
371 for (int i = 0; i < faceGeoInRef.corners(); ++i)
372 corners.push_back(elemGeo.global(faceGeoInRef.corner(i)));
373 return { faceGeoInRef.type(), corners };
374 }
375
377 friend inline auto ipData(const PQ1BubbleFVElementGeometry& fvGeometry, const SubControlVolume& scv)
378 {
379 const auto type = fvGeometry.element().type();
380 const auto& localKey = fvGeometry.feLocalCoefficients().localKey(scv.localDofIndex());
381
382 return CVFE::LocalDofInterpolationPointData{ DofHelper::localDofPosition(type, localKey), scv.dofPosition(), scv.localDofIndex() };
383 }
384
386 template<class LocalDof>
387 friend inline auto ipData(const PQ1BubbleFVElementGeometry& fvGeometry, const LocalDof& localDof)
388 {
389 const auto type = fvGeometry.element().type();
390 const auto& localKey = fvGeometry.feLocalCoefficients().localKey(localDof.index());
391 const auto& localPos = DofHelper::localDofPosition(type, localKey);
392
393 return CVFE::LocalDofInterpolationPointData{ localPos, fvGeometry.elementGeometry().global(localPos), localDof.index() };
394 }
395
397 friend inline auto ipData(const PQ1BubbleFVElementGeometry& fvGeometry, const typename Element::Geometry::GlobalCoordinate& globalPos)
398 {
399 // Create ipData that does not automatically calculate the local position but only if it is called
401 [&] (const typename Element::Geometry::GlobalCoordinate& pos) { return fvGeometry.elementGeometry().local(pos); },
402 globalPos
403 };
404 }
405
407 friend inline auto ipData(const PQ1BubbleFVElementGeometry& fvGeometry, const SubControlVolumeFace& scvf)
408 {
410 { scvf.unitOuterNormal(), scvf.index(), fvGeometry.elementGeometry().local(scvf.ipGlobal()), scvf.ipGlobal() };
411 }
412
413private:
414 const GGCache* ggCache_;
415 GridIndexType eIdx_;
416
417 std::optional<Element> element_;
418 std::optional<typename Element::Geometry> elementGeometry_;
419 const FiniteElement* fe_ = nullptr;
420 Dune::ReservedVector<GridIndexType, maxNumElementDofs> dofIndices_;
421};
422
423} // end namespace Dumux
424
425#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
An interpolation point related to a localDof of an element, giving its global and local positions.
Definition cvfe/interpolationpointdata.hh:60
friend Dune::IteratorRange< typename std::vector< SubControlVolume >::const_iterator > scvs(const PQ1BubbleFVElementGeometry &fvGeometry)
Definition discretization/pq1bubble/fvelementgeometry.hh:114
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const PQ1BubbleFVElementGeometry &fvGeometry)
Definition discretization/pq1bubble/fvelementgeometry.hh:174
typename GridView::template Codim< 0 >::Entity Element
export the element type
Definition discretization/pq1bubble/fvelementgeometry.hh:69
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition discretization/pq1bubble/fvelementgeometry.hh:303
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:137
typename GG::BoundaryFace BoundaryFace
export the boundary face type
Definition discretization/pq1bubble/fvelementgeometry.hh:77
friend std::ranges::view auto boundaryFaces(const PQ1BubbleFVElementGeometry &fvGeometry)
Definition discretization/pq1bubble/fvelementgeometry.hh:195
bool hasBoundaryFaces() const
Returns whether the element has boundary faces.
Definition discretization/pq1bubble/fvelementgeometry.hh:307
PQ1BubbleFVElementGeometry(const GGCache &ggCache)
Constructor.
Definition discretization/pq1bubble/fvelementgeometry.hh:92
typename GG::IntersectionQuadratureRule IntersectionQuadratureRule
the quadrature rule type for intersections
Definition discretization/pq1bubble/fvelementgeometry.hh:85
const GridGeometry & gridDiscretization() const
The grid discretization we are a restriction of.
Definition discretization/pq1bubble/fvelementgeometry.hh:299
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition discretization/pq1bubble/fvelementgeometry.hh:97
friend auto localDofs(const PQ1BubbleFVElementGeometry &fvGeometry)
an iterator over all local dofs
Definition discretization/pq1bubble/fvelementgeometry.hh:151
GG GridGeometry
export type of finite volume grid geometry
Definition discretization/pq1bubble/fvelementgeometry.hh:75
friend auto ipData(const PQ1BubbleFVElementGeometry &fvGeometry, const LocalDof &localDof)
Interpolation point data for a localDof.
Definition discretization/pq1bubble/fvelementgeometry.hh:387
const BoundaryFace & boundaryFace(LocalIndexType bfIdx) const
Get a boundary face with a local boundary face index.
Definition discretization/pq1bubble/fvelementgeometry.hh:311
std::size_t numLocalDofs() const
The total number of element-local dofs.
Definition discretization/pq1bubble/fvelementgeometry.hh:214
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition discretization/pq1bubble/fvelementgeometry.hh:202
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition discretization/pq1bubble/fvelementgeometry.hh:73
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition discretization/pq1bubble/fvelementgeometry.hh:71
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:253
const Element::Geometry & elementGeometry() const
The bound element geometry.
Definition discretization/pq1bubble/fvelementgeometry.hh:290
void bindElement(const Element &element) &
Definition discretization/pq1bubble/fvelementgeometry.hh:262
friend auto ipData(const PQ1BubbleFVElementGeometry &fvGeometry, const SubControlVolume &scv)
Interpolation point data for an scv.
Definition discretization/pq1bubble/fvelementgeometry.hh:377
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const PQ1BubbleFVElementGeometry &fvGeometry, const BoundaryFace &boundaryFace)
Definition discretization/pq1bubble/fvelementgeometry.hh:184
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:79
friend auto ipData(const PQ1BubbleFVElementGeometry &fvGeometry, const SubControlVolumeFace &scvf)
Interpolation point data for scvf.
Definition discretization/pq1bubble/fvelementgeometry.hh:407
void bind(const Element &element) &
Definition discretization/pq1bubble/fvelementgeometry.hh:245
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:236
typename GG::BoundaryFaceQuadratureRule BoundaryFaceQuadratureRule
the quadrature rule type for boundary faces
Definition discretization/pq1bubble/fvelementgeometry.hh:87
std::size_t intersectionIndex(const SubControlVolumeFace &scvf) const
The intersection index the scvf belongs to.
Definition discretization/pq1bubble/fvelementgeometry.hh:319
typename GG::ElementQuadratureRule ElementQuadratureRule
the quadrature rule type for elements
Definition discretization/pq1bubble/fvelementgeometry.hh:83
static constexpr std::size_t maxNumElementDofs
the maximum number of scvs per element (2^dim for cubes)
Definition discretization/pq1bubble/fvelementgeometry.hh:89
const auto & feLocalCoefficients() const
Get the local finite element coefficients.
Definition discretization/pq1bubble/fvelementgeometry.hh:208
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Geometry of a sub control volume face.
Definition discretization/pq1bubble/fvelementgeometry.hh:340
friend auto ipData(const PQ1BubbleFVElementGeometry &fvGeometry, const typename Element::Geometry::GlobalCoordinate &globalPos)
Interpolation point data for a global position.
Definition discretization/pq1bubble/fvelementgeometry.hh:397
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/pq1bubble/fvelementgeometry.hh:220
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Geometry of a sub control volume.
Definition discretization/pq1bubble/fvelementgeometry.hh:326
friend auto cvLocalDofs(const PQ1BubbleFVElementGeometry &fvGeometry)
iterate over dof indices that belong to dofs associated with control volumes
Definition discretization/pq1bubble/fvelementgeometry.hh:122
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition discretization/pq1bubble/fvelementgeometry.hh:103
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition discretization/pq1bubble/fvelementgeometry.hh:282
std::size_t elementIndex() const
The bound element index.
Definition discretization/pq1bubble/fvelementgeometry.hh:315
BoundaryFace::Traits::Geometry geometry(const BoundaryFace &boundaryFace) const
Geometry of a boundary face.
Definition discretization/pq1bubble/fvelementgeometry.hh:365
std::size_t numScvf() const
The total number of sub control volume faces.
Definition discretization/pq1bubble/fvelementgeometry.hh:226
const GridGeometry & gridGeometry() const
The grid geometry we are a restriction of.
Definition discretization/pq1bubble/fvelementgeometry.hh:295
typename GG::ScvfQuadratureRule ScvfQuadratureRule
the quadrature rule type for scvfs
Definition discretization/pq1bubble/fvelementgeometry.hh:81
const Element & element() const
The bound element.
Definition discretization/pq1bubble/fvelementgeometry.hh:286
Base class for the finite volume geometry vector for pq1bubble models This builds up the sub control ...
Definition discretization/pq1bubble/fvelementgeometry.hh:44
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