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/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 using DofHelper = typename GGCache::DofHelper;
59
60 using BaseIpData = CVFE::InterpolationPointData<
61 typename GridView::template Codim<0>::Entity::Geometry::LocalCoordinate,
62 typename GridView::template Codim<0>::Entity::Geometry::GlobalCoordinate
63 >;
64
65public:
67 using Element = typename GridView::template Codim<0>::Entity;
69 using SubControlVolume = typename GG::SubControlVolume;
71 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
73 using GridGeometry = GG;
75 using BoundaryFace = typename GG::BoundaryFace;
77 using ScvQuadratureRule = typename GG::ScvQuadratureRule;
79 using ScvfQuadratureRule = typename GG::ScvfQuadratureRule;
81 using ElementQuadratureRule = typename GG::ElementQuadratureRule;
83 using IntersectionQuadratureRule = typename GG::IntersectionQuadratureRule;
85 using BoundaryFaceQuadratureRule = typename GG::BoundaryFaceQuadratureRule;
87 static constexpr std::size_t maxNumElementDofs = GridGeometry::maxNumElementDofs;
88
90 PQ1BubbleFVElementGeometry(const GGCache& ggCache)
91 : ggCache_(&ggCache)
92 {}
93
95 const SubControlVolume& scv(LocalIndexType scvIdx) const
96 {
97 return ggCache_->scvs(eIdx_)[scvIdx];
98 }
99
101 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
102 {
103 return ggCache_->scvfs(eIdx_)[scvfIdx];
104 }
105
111 friend inline Dune::IteratorRange<typename std::vector<SubControlVolume>::const_iterator>
113 {
114 using Iter = typename std::vector<SubControlVolume>::const_iterator;
115 const auto& s = fvGeometry.ggCache_->scvs(fvGeometry.eIdx_);
116 return Dune::IteratorRange<Iter>(s.begin(), s.end());
117 }
118
120 friend inline auto cvLocalDofs(const PQ1BubbleFVElementGeometry& fvGeometry)
121 {
122 return Dune::transformedRangeView(
123 Dune::range(fvGeometry.numLocalDofs()-GeometryHelper::numNonCVLocalDofs(fvGeometry.element().type())),
124 [&](const auto i) { return CVFE::LocalDof
125 {
126 static_cast<LocalIndexType>(i),
127 static_cast<GridIndexType>(DofHelper::dofIndex(fvGeometry.gridDiscretization().dofMapper(), fvGeometry.element(),
128 fvGeometry.feLocalCoefficients().localKey(i))),
129 static_cast<GridIndexType>(fvGeometry.elementIndex())
130 }; }
131 );
132 }
133
135 template<bool enable = GridGeometry::enableHybridCVFE, std::enable_if_t<enable, int> = 0>
136 friend inline auto nonCVLocalDofs(const PQ1BubbleFVElementGeometry& fvGeometry)
137 {
138 return Dune::transformedRangeView(
139 Dune::range(fvGeometry.numLocalDofs()-GeometryHelper::numNonCVLocalDofs(fvGeometry.element().type()), fvGeometry.numLocalDofs()),
140 [&](const auto i) { return CVFE::LocalDof
141 {
142 static_cast<LocalIndexType>(i),
143 static_cast<GridIndexType>(DofHelper::dofIndex(fvGeometry.gridDiscretization().dofMapper(), fvGeometry.element(),
144 fvGeometry.feLocalCoefficients().localKey(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 static_cast<GridIndexType>(DofHelper::dofIndex(fvGeometry.gridDiscretization().dofMapper(), fvGeometry.element(),
159 fvGeometry.feLocalCoefficients().localKey(i))),
160 static_cast<GridIndexType>(fvGeometry.elementIndex())
161 }; }
162 );
163 }
164
166 friend inline auto localDofs(const PQ1BubbleFVElementGeometry& fvGeometry, const BoundaryFace& boundaryFace)
167 { return DofHelper::localDofsOnBoundaryFace(fvGeometry, boundaryFace); }
168
174 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
176 {
177 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
178 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
179 return Dune::IteratorRange<Iter>(s.begin(), s.end());
180 }
181
184 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
186 {
187 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
188 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
189 const auto& range = fvGeometry.ggCache_->boundaryFaceScvfRanges(fvGeometry.eIdx_)[boundaryFace.index()];
190 return Dune::IteratorRange<Iter>(s.begin() + range[0], s.begin() + range[0] + range[1]);
191 }
192
195 friend inline std::ranges::view auto
197 {
198 const auto& v = fvGeometry.ggCache_->boundaryFaces(fvGeometry.eIdx_);
199 return std::ranges::views::all(v);
200 }
201
203 const FeLocalBasis& feLocalBasis() const
204 {
205 return gridDiscretization().feCache().get(element_->type()).localBasis();
206 }
207
209 const auto& feLocalCoefficients() const
210 {
211 return gridDiscretization().feCache().get(element_->type()).localCoefficients();
212 }
213
215 std::size_t numLocalDofs() const
216 {
217 return DofHelper::numElementDofs(element().type());
218 }
219
221 std::size_t numScv() const
222 {
223 return ggCache_->scvs(eIdx_).size();
224 }
225
227 std::size_t numScvf() const
228 {
229 return ggCache_->scvfs(eIdx_).size();
230 }
231
238 {
239 this->bindElement(element);
240 return std::move(*this);
241 }
242
246 void bind(const Element& element) &
247 { this->bindElement(element); }
248
255 {
256 this->bindElement(element);
257 return std::move(*this);
258 }
259
264 {
265 element_ = element;
266 // cache element index
267 eIdx_ = gridDiscretization().elementMapper().index(element);
268 elementGeometry_.emplace(element.geometry());
269 }
270
272 bool isBound() const
273 { return static_cast<bool>(element_); }
274
276 const Element& element() const
277 { return *element_; }
278
280 const typename Element::Geometry& elementGeometry() const
281 { return *elementGeometry_; }
282
284 [[deprecated("Use gridDiscretization() instead")]]
286 { return ggCache_->gridGeometry(); }
287
290 { return ggCache_->gridGeometry(); }
291
293 bool hasBoundaryScvf() const
294 { return ggCache_->hasBoundaryScvf(eIdx_); }
295
297 bool hasBoundaryFaces() const
298 { return hasBoundaryScvf(); }
299
301 const BoundaryFace& boundaryFace(LocalIndexType bfIdx) const
302 { return ggCache_->boundaryFaces(eIdx_)[bfIdx]; }
303
305 std::size_t elementIndex() const
306 { return eIdx_; }
307
310 {
311 const auto localScvfIdx = scvf.index() - GeometryHelper::numInteriorScvf(element().type());
312 return ggCache_->scvfBoundaryGeometryKeys(eIdx_)[localScvfIdx][0];
313 }
314
316 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
317 {
318 if (scv.isOverlapping())
319 DUNE_THROW(Dune::NotImplemented, "Geometry of overlapping scv");
320
321 assert(isBound());
322 const GeometryHelper helper(*elementGeometry_);
323 return {
324 helper.getScvGeometryType(scv.indexInElement()),
325 helper.getScvCorners(scv.indexInElement())
326 };
327 }
328
330 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
331 {
332 assert(isBound());
333 if (scvf.boundary())
334 {
335 GeometryHelper helper(*elementGeometry_);
336 const auto localScvfIdx = scvf.index() - GeometryHelper::numInteriorScvf(element().type());
337 const auto [localFacetIndex, isScvfLocalIdx]
338 = ggCache_->scvfBoundaryGeometryKeys(eIdx_)[localScvfIdx];
339 return {
340 helper.getBoundaryScvfGeometryType(isScvfLocalIdx),
341 helper.getBoundaryScvfCorners(localFacetIndex, isScvfLocalIdx)
342 };
343 }
344 else
345 {
346 GeometryHelper helper(*elementGeometry_);
347 return {
348 helper.getInteriorScvfGeometryType(scvf.index()),
349 helper.getScvfCorners(scvf.index())
350 };
351 }
352 }
353
355 typename BoundaryFace::Traits::Geometry geometry(const BoundaryFace& boundaryFace) const
356 {
357 assert(isBound());
358 const auto& elemGeo = elementGeometry();
359 const auto faceGeoInRef = referenceElement(elemGeo).template geometry<1>(boundaryFace.intersectionIndex());
360 typename BoundaryFace::Traits::CornerStorage corners;
361 for (int i = 0; i < faceGeoInRef.corners(); ++i)
362 corners.push_back(elemGeo.global(faceGeoInRef.corner(i)));
363 return { faceGeoInRef.type(), corners };
364 }
365
367 friend inline auto ipData(const PQ1BubbleFVElementGeometry& fvGeometry, const SubControlVolume& scv)
368 {
369 const auto type = fvGeometry.element().type();
370 const auto& localKey = fvGeometry.gridDiscretization().feCache().get(type).localCoefficients().localKey(scv.localDofIndex());
371
372 return CVFE::LocalDofInterpolationPointData{ DofHelper::localDofPosition(type, localKey), scv.dofPosition(), scv.localDofIndex() };
373 }
374
376 template<class LocalDof>
377 friend inline auto ipData(const PQ1BubbleFVElementGeometry& fvGeometry, const LocalDof& localDof)
378 {
379 const auto type = fvGeometry.element().type();
380 const auto& localKey = fvGeometry.gridDiscretization().feCache().get(type).localCoefficients().localKey(localDof.index());
381 const auto& localPos = DofHelper::localDofPosition(type, localKey);
382
383 return CVFE::LocalDofInterpolationPointData{ localPos, fvGeometry.elementGeometry().global(localPos), localDof.index() };
384 }
385
387 friend inline auto ipData(const PQ1BubbleFVElementGeometry& fvGeometry, const typename Element::Geometry::GlobalCoordinate& globalPos)
388 {
389 // Create ipData that does not automatically calculate the local position but only if it is called
391 [&] (const typename Element::Geometry::GlobalCoordinate& pos) { return fvGeometry.elementGeometry().local(pos); },
392 globalPos
393 };
394 }
395
397 friend inline auto ipData(const PQ1BubbleFVElementGeometry& fvGeometry, const SubControlVolumeFace& scvf)
398 {
400 { scvf.unitOuterNormal(), scvf.index(), fvGeometry.elementGeometry().local(scvf.ipGlobal()), scvf.ipGlobal() };
401 }
402
403private:
404 const GGCache* ggCache_;
405 GridIndexType eIdx_;
406
407 std::optional<Element> element_;
408 std::optional<typename Element::Geometry> elementGeometry_;
409};
410
411} // end namespace Dumux
412
413#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:112
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const PQ1BubbleFVElementGeometry &fvGeometry)
Definition discretization/pq1bubble/fvelementgeometry.hh:175
typename GridView::template Codim< 0 >::Entity Element
export the element type
Definition discretization/pq1bubble/fvelementgeometry.hh:67
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition discretization/pq1bubble/fvelementgeometry.hh:293
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:136
typename GG::BoundaryFace BoundaryFace
export the boundary face type
Definition discretization/pq1bubble/fvelementgeometry.hh:75
friend std::ranges::view auto boundaryFaces(const PQ1BubbleFVElementGeometry &fvGeometry)
Definition discretization/pq1bubble/fvelementgeometry.hh:196
bool hasBoundaryFaces() const
Returns whether the element has boundary faces.
Definition discretization/pq1bubble/fvelementgeometry.hh:297
PQ1BubbleFVElementGeometry(const GGCache &ggCache)
Constructor.
Definition discretization/pq1bubble/fvelementgeometry.hh:90
typename GG::IntersectionQuadratureRule IntersectionQuadratureRule
the quadrature rule type for intersections
Definition discretization/pq1bubble/fvelementgeometry.hh:83
const GridGeometry & gridDiscretization() const
The grid discretization we are a restriction of.
Definition discretization/pq1bubble/fvelementgeometry.hh:289
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition discretization/pq1bubble/fvelementgeometry.hh:95
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:73
friend auto ipData(const PQ1BubbleFVElementGeometry &fvGeometry, const LocalDof &localDof)
Interpolation point data for a localDof.
Definition discretization/pq1bubble/fvelementgeometry.hh:377
const BoundaryFace & boundaryFace(LocalIndexType bfIdx) const
Get a boundary face with a local boundary face index.
Definition discretization/pq1bubble/fvelementgeometry.hh:301
std::size_t numLocalDofs() const
The total number of element-local dofs.
Definition discretization/pq1bubble/fvelementgeometry.hh:215
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition discretization/pq1bubble/fvelementgeometry.hh:203
typename GG::SubControlVolumeFace SubControlVolumeFace
export type of subcontrol volume face
Definition discretization/pq1bubble/fvelementgeometry.hh:71
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume
Definition discretization/pq1bubble/fvelementgeometry.hh:69
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:254
const Element::Geometry & elementGeometry() const
The bound element geometry.
Definition discretization/pq1bubble/fvelementgeometry.hh:280
void bindElement(const Element &element) &
Definition discretization/pq1bubble/fvelementgeometry.hh:263
friend auto ipData(const PQ1BubbleFVElementGeometry &fvGeometry, const SubControlVolume &scv)
Interpolation point data for an scv.
Definition discretization/pq1bubble/fvelementgeometry.hh:367
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const PQ1BubbleFVElementGeometry &fvGeometry, const BoundaryFace &boundaryFace)
Definition discretization/pq1bubble/fvelementgeometry.hh:185
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:166
typename GG::ScvQuadratureRule ScvQuadratureRule
the quadrature rule type for scvs
Definition discretization/pq1bubble/fvelementgeometry.hh:77
friend auto ipData(const PQ1BubbleFVElementGeometry &fvGeometry, const SubControlVolumeFace &scvf)
Interpolation point data for scvf.
Definition discretization/pq1bubble/fvelementgeometry.hh:397
void bind(const Element &element) &
Definition discretization/pq1bubble/fvelementgeometry.hh:246
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:237
typename GG::BoundaryFaceQuadratureRule BoundaryFaceQuadratureRule
the quadrature rule type for boundary faces
Definition discretization/pq1bubble/fvelementgeometry.hh:85
std::size_t intersectionIndex(const SubControlVolumeFace &scvf) const
The intersection index the scvf belongs to.
Definition discretization/pq1bubble/fvelementgeometry.hh:309
typename GG::ElementQuadratureRule ElementQuadratureRule
the quadrature rule type for elements
Definition discretization/pq1bubble/fvelementgeometry.hh:81
static constexpr std::size_t maxNumElementDofs
the maximum number of scvs per element (2^dim for cubes)
Definition discretization/pq1bubble/fvelementgeometry.hh:87
const auto & feLocalCoefficients() const
Get the local finite element coefficients.
Definition discretization/pq1bubble/fvelementgeometry.hh:209
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Geometry of a sub control volume face.
Definition discretization/pq1bubble/fvelementgeometry.hh:330
friend auto ipData(const PQ1BubbleFVElementGeometry &fvGeometry, const typename Element::Geometry::GlobalCoordinate &globalPos)
Interpolation point data for a global position.
Definition discretization/pq1bubble/fvelementgeometry.hh:387
std::size_t numScv() const
The total number of sub control volumes.
Definition discretization/pq1bubble/fvelementgeometry.hh:221
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Geometry of a sub control volume.
Definition discretization/pq1bubble/fvelementgeometry.hh:316
friend auto cvLocalDofs(const PQ1BubbleFVElementGeometry &fvGeometry)
iterate over dof indices that belong to dofs associated with control volumes
Definition discretization/pq1bubble/fvelementgeometry.hh:120
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition discretization/pq1bubble/fvelementgeometry.hh:101
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition discretization/pq1bubble/fvelementgeometry.hh:272
std::size_t elementIndex() const
The bound element index.
Definition discretization/pq1bubble/fvelementgeometry.hh:305
BoundaryFace::Traits::Geometry geometry(const BoundaryFace &boundaryFace) const
Geometry of a boundary face.
Definition discretization/pq1bubble/fvelementgeometry.hh:355
std::size_t numScvf() const
The total number of sub control volume faces.
Definition discretization/pq1bubble/fvelementgeometry.hh:227
const GridGeometry & gridGeometry() const
The grid geometry we are a restriction of.
Definition discretization/pq1bubble/fvelementgeometry.hh:285
typename GG::ScvfQuadratureRule ScvfQuadratureRule
the quadrature rule type for scvfs
Definition discretization/pq1bubble/fvelementgeometry.hh:79
const Element & element() const
The bound element.
Definition discretization/pq1bubble/fvelementgeometry.hh:276
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