version 3.11-dev
Loading...
Searching...
No Matches
discretization/facecentered/diamond/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//
12#ifndef DUMUX_DISCRETIZATION_FACECENTERED_DIAMOND_FV_ELEMENT_GEOMETRY_HH
13#define DUMUX_DISCRETIZATION_FACECENTERED_DIAMOND_FV_ELEMENT_GEOMETRY_HH
14
15#include <type_traits>
16#include <optional>
17#include <ranges>
18#include <span>
19
20#include <dune/common/reservedvector.hh>
21#include <dune/common/iteratorrange.hh>
22
28
29namespace Dumux {
30
37template<class GG, bool cachingEnabled>
39
44template<class GG>
45class FaceCenteredDiamondFVElementGeometry<GG, /*cachingEnabled*/true>
46{
47 using ThisType = FaceCenteredDiamondFVElementGeometry<GG, /*cachingEnabled*/true>;
48 using GridView = typename GG::GridView;
49 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
50 using LocalIndexType = typename IndexTraits<GridView>::SmallLocalIndex;
51 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
52 using GGCache = typename GG::Cache;
53 using GeometryHelper = typename GGCache::GeometryHelper;
54 using DofHelper = typename GGCache::DofHelper;
55
56 using BaseIpData = CVFE::InterpolationPointData<
57 typename GridView::template Codim<0>::Entity::Geometry::LocalCoordinate,
58 typename GridView::template Codim<0>::Entity::Geometry::GlobalCoordinate
59 >;
60
61public:
63 using SubControlVolume = typename GG::SubControlVolume;
64 using SubControlVolumeFace = typename GG::SubControlVolumeFace;
65 using BoundaryFace = typename GG::BoundaryFace;
66 using Element = typename GridView::template Codim<0>::Entity;
67 using GridGeometry = GG;
69 using ScvQuadratureRule = typename GG::ScvQuadratureRule;
71 using ScvfQuadratureRule = typename GG::ScvfQuadratureRule;
72
74 static constexpr std::size_t maxNumElementScvs = 2*GridView::dimension;
75
77 : ggCache_(&ggCache)
78 {}
79
81 const SubControlVolume& scv(LocalIndexType scvIdx) const
82 { return ggCache_->scvs(eIdx_)[scvIdx]; }
83
85 const SubControlVolumeFace& scvf(LocalIndexType scvfIdx) const
86 { return ggCache_->scvf(eIdx_)[scvfIdx]; }
87
93 friend inline auto
95 {
96 using Iter = typename std::vector<SubControlVolume>::const_iterator;
97 const auto& s = fvGeometry.ggCache_->scvs(fvGeometry.eIdx_);
98 return Dune::IteratorRange<Iter>(s.begin(), s.end());
99 }
100
106 friend inline auto
108 {
109 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
110 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
111 return Dune::IteratorRange<Iter>(s.begin(), s.end());
112 }
113
116 friend inline Dune::IteratorRange<typename std::vector<SubControlVolumeFace>::const_iterator>
118 {
119 using Iter = typename std::vector<SubControlVolumeFace>::const_iterator;
120 const auto& s = fvGeometry.ggCache_->scvfs(fvGeometry.eIdx_);
121 const auto& range = fvGeometry.ggCache_->boundaryFaceScvfRanges(fvGeometry.eIdx_)[boundaryFace.index()];
122 return Dune::IteratorRange<Iter>(s.begin() + range[0], s.begin() + range[0] + range[1]);
123 }
124
126 const FeLocalBasis& feLocalBasis() const
127 {
128 return gridGeometry().feCache().get(element().type()).localBasis();
129 }
130
132 const auto& feLocalCoefficients() const
133 {
134 return gridGeometry().feCache().get(element().type()).localCoefficients();
135 }
136
138 std::size_t numLocalDofs() const
139 {
140 return numScv();
141 }
142
144 std::size_t numScv() const
145 {
146 return ggCache_->scvs(eIdx_).size();
147 }
148
150 std::size_t numScvf() const
151 {
152 return ggCache_->scvfs(eIdx_).size();
153 }
154
156 bool hasBoundaryScvf() const
157 { return ggCache_->hasBoundaryScvf(eIdx_); }
158
160 bool hasBoundaryFaces() const
161 { return hasBoundaryScvf(); }
162
164 const BoundaryFace& boundaryFace(LocalIndexType bfIdx) const
165 { return ggCache_->boundaryFaces(eIdx_)[bfIdx]; }
166
168 friend inline std::ranges::view auto
170 {
171 const auto& v = fvGeometry.ggCache_->boundaryFaces(fvGeometry.eIdx_);
172 return std::ranges::views::all(v);
173 }
174
181 {
182 this->bindElement(element);
183 return std::move(*this);
184 }
185
186 void bind(const Element& element) &
187 {
188 this->bindElement(element);
189 }
190
197 {
198 this->bindElement(element);
199 return std::move(*this);
200 }
201
204 {
205 element_ = element;
206 elementGeometry_.emplace(element.geometry());
207 eIdx_ = gridGeometry().elementMapper().index(element);
208 }
209
211 bool isBound() const
212 { return static_cast<bool>(element_); }
213
215 const Element& element() const
216 { return *element_; }
217
219 const typename Element::Geometry& elementGeometry() const
220 { return *elementGeometry_; }
221
224 { return ggCache_->gridGeometry(); }
225
228 { return ggCache_->gridGeometry(); }
229
231 std::size_t elementIndex() const
232 { return eIdx_; }
233
236 {
237 // Since scvs are constructed around intersections, they have the same index
238 return scvf.insideScvIdx();
239 }
240
242 typename SubControlVolume::Traits::Geometry geometry(const SubControlVolume& scv) const
243 {
244 assert(isBound());
245 return {
246 SubControlVolume::Traits::geometryType((*elementGeometry_).type()),
247 GeometryHelper(*elementGeometry_).getScvCorners(scv.indexInElement())
248 };
249 }
250
252 typename SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace& scvf) const
253 {
254 assert(isBound());
255 if (scvf.boundary())
256 {
257 // use the information that each boundary scvf corresponds to one scv constructed around the same facet
258 const auto localFacetIndex = scvf.insideScvIdx();
259 return {
260 referenceElement(*elementGeometry_).type(localFacetIndex, 1),
261 GeometryHelper(*elementGeometry_).getBoundaryScvfCorners(localFacetIndex)
262 };
263 }
264 else
265 {
266 return {
267 SubControlVolumeFace::Traits::interiorGeometryType((*elementGeometry_).type()),
268 GeometryHelper(*elementGeometry_).getScvfCorners(scvf.index())
269 };
270 }
271 }
272
274 typename BoundaryFace::Traits::Geometry geometry(const BoundaryFace& boundaryFace) const
275 {
276 assert(isBound());
277 const auto& elemGeo = elementGeometry();
278 const auto faceGeoInRef = referenceElement(elemGeo).template geometry<1>(boundaryFace.intersectionIndex());
279 typename BoundaryFace::Traits::CornerStorage corners;
280 for (int i = 0; i < faceGeoInRef.corners(); ++i)
281 corners.push_back(elemGeo.global(faceGeoInRef.corner(i)));
282 return { faceGeoInRef.type(), corners };
283 }
284
286 friend inline auto localDofs(const FaceCenteredDiamondFVElementGeometry& fvGeometry,
288 { return DofHelper::localDofsOnBoundaryFace(fvGeometry, boundaryFace); }
289
291 friend inline auto ipData(const FaceCenteredDiamondFVElementGeometry& fvGeometry, const SubControlVolume& scv)
292 {
293 const auto type = fvGeometry.element().type();
294 const auto& localKey = fvGeometry.gridGeometry().feCache().get(type).localCoefficients().localKey(scv.localDofIndex());
295
296 return CVFE::LocalDofInterpolationPointData{ DofHelper::localDofPosition(type, localKey), scv.dofPosition(), scv.localDofIndex() };
297 }
298
300 template<class LocalDof>
301 friend inline auto ipData(const FaceCenteredDiamondFVElementGeometry& fvGeometry, const LocalDof& localDof)
302 {
303 const auto type = fvGeometry.element().type();
304 const auto& localKey = fvGeometry.gridGeometry().feCache().get(type).localCoefficients().localKey(localDof.index());
305 const auto& localPos = DofHelper::localDofPosition(type, localKey);
306
307 return CVFE::LocalDofInterpolationPointData{ localPos, fvGeometry.elementGeometry().global(localPos), localDof.index() };
308 }
309
311 friend inline auto ipData(const FaceCenteredDiamondFVElementGeometry& fvGeometry, const typename Element::Geometry::GlobalCoordinate& globalPos)
312 {
313 // Create ipData that does not automatically calculate the local position but only if it is called
315 [&] (const typename Element::Geometry::GlobalCoordinate& pos) { return fvGeometry.elementGeometry().local(pos); },
316 globalPos
317 };
318 }
319
321 friend inline auto ipData(const FaceCenteredDiamondFVElementGeometry& fvGeometry, const SubControlVolumeFace& scvf)
322 {
324 { scvf.unitOuterNormal(), scvf.index(), fvGeometry.elementGeometry().local(scvf.ipGlobal()), scvf.ipGlobal() };
325 }
326
327private:
328 std::optional<Element> element_;
329 std::optional<typename Element::Geometry> elementGeometry_;
330 GridIndexType eIdx_;
331 const GGCache* ggCache_;
332};
333
334} // end namespace Dumux
335
336#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 auto scvs(const FaceCenteredDiamondFVElementGeometry &fvGeometry)
Definition discretization/facecentered/diamond/fvelementgeometry.hh:94
void bindElement(const Element &element) &
Bind only element-local.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:203
const GridGeometry & gridGeometry() const
The grid geometry we are a restriction of.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:223
static constexpr std::size_t maxNumElementScvs
the maximum number of scvs per element
Definition discretization/facecentered/diamond/fvelementgeometry.hh:74
const Element & element() const
The bound element.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:215
typename GG::ScvQuadratureRule ScvQuadratureRule
the quadrature rule type for scvs
Definition discretization/facecentered/diamond/fvelementgeometry.hh:69
const auto & feLocalCoefficients() const
Get the local finite element coefficients.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:132
typename GG::SubControlVolume SubControlVolume
export type of subcontrol volume face
Definition discretization/facecentered/diamond/fvelementgeometry.hh:63
friend auto ipData(const FaceCenteredDiamondFVElementGeometry &fvGeometry, const LocalDof &localDof)
Interpolation point data for a localDof.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:301
std::size_t intersectionIndex(const SubControlVolumeFace &scvf) const
The intersection index the scvf belongs to.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:235
const Element::Geometry & elementGeometry() const
The bound element geometry.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:219
const GridGeometry & gridDiscretization() const
The grid discretization we are a restriction of.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:227
friend auto ipData(const FaceCenteredDiamondFVElementGeometry &fvGeometry, const SubControlVolumeFace &scvf)
Interpolation point data for scvf.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:321
bool hasBoundaryScvf() const
Returns whether one of the geometry's scvfs lies on a boundary.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:156
typename GG::SubControlVolumeFace SubControlVolumeFace
Definition discretization/facecentered/diamond/fvelementgeometry.hh:64
typename GG::ScvfQuadratureRule ScvfQuadratureRule
the quadrature rule type for scvfs
Definition discretization/facecentered/diamond/fvelementgeometry.hh:71
bool hasBoundaryFaces() const
Returns whether the element has boundary faces.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:160
friend auto ipData(const FaceCenteredDiamondFVElementGeometry &fvGeometry, const SubControlVolume &scv)
Interpolation point data for an scv.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:291
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:211
const BoundaryFace & boundaryFace(LocalIndexType bfIdx) const
Get a boundary face with a local boundary face index.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:164
std::size_t numScvf() const
number of sub control volumes in this fv element geometry
Definition discretization/facecentered/diamond/fvelementgeometry.hh:150
friend auto scvfs(const FaceCenteredDiamondFVElementGeometry &fvGeometry)
Definition discretization/facecentered/diamond/fvelementgeometry.hh:107
std::size_t elementIndex() const
The bound element index.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:231
GG GridGeometry
Definition discretization/facecentered/diamond/fvelementgeometry.hh:67
friend auto ipData(const FaceCenteredDiamondFVElementGeometry &fvGeometry, const typename Element::Geometry::GlobalCoordinate &globalPos)
Interpolation point data for a global position.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:311
friend Dune::IteratorRange< typename std::vector< SubControlVolumeFace >::const_iterator > scvfs(const FaceCenteredDiamondFVElementGeometry &fvGeometry, const BoundaryFace &boundaryFace)
Definition discretization/facecentered/diamond/fvelementgeometry.hh:117
const SubControlVolumeFace & scvf(LocalIndexType scvfIdx) const
Get a sub control volume face with a local scvf index.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:85
const SubControlVolume & scv(LocalIndexType scvIdx) const
Get a sub control volume with a local scv index.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:81
typename GridView::template Codim< 0 >::Entity Element
Definition discretization/facecentered/diamond/fvelementgeometry.hh:66
friend auto localDofs(const FaceCenteredDiamondFVElementGeometry &fvGeometry, const BoundaryFace &boundaryFace)
an iterator over all local dofs related to a boundary face
Definition discretization/facecentered/diamond/fvelementgeometry.hh:286
typename GG::BoundaryFace BoundaryFace
Definition discretization/facecentered/diamond/fvelementgeometry.hh:65
BoundaryFace::Traits::Geometry geometry(const BoundaryFace &boundaryFace) const
Geometry of a boundary face.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:274
FaceCenteredDiamondFVElementGeometry 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/facecentered/diamond/fvelementgeometry.hh:180
std::size_t numScv() const
number of sub control volumes in this fv element geometry
Definition discretization/facecentered/diamond/fvelementgeometry.hh:144
std::size_t numLocalDofs() const
The total number of element-local dofs.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:138
FaceCenteredDiamondFVElementGeometry(const GGCache &ggCache)
Definition discretization/facecentered/diamond/fvelementgeometry.hh:76
friend std::ranges::view auto boundaryFaces(const FaceCenteredDiamondFVElementGeometry &fvGeometry)
iterator range for boundary faces
Definition discretization/facecentered/diamond/fvelementgeometry.hh:169
void bind(const Element &element) &
Definition discretization/facecentered/diamond/fvelementgeometry.hh:186
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:126
SubControlVolumeFace::Traits::Geometry geometry(const SubControlVolumeFace &scvf) const
Geometry of a sub control volume face.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:252
SubControlVolume::Traits::Geometry geometry(const SubControlVolume &scv) const
Geometry of a sub control volume.
Definition discretization/facecentered/diamond/fvelementgeometry.hh:242
FaceCenteredDiamondFVElementGeometry 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/facecentered/diamond/fvelementgeometry.hh:196
Element-wise grid geometry (local view).
Definition discretization/facecentered/diamond/fvelementgeometry.hh:38
Classes representing interpolation point data for control-volume finite element schemes.
Helper class to construct SCVs and SCVFs for the diamond scheme.
Defines the index types used for grid and local indices.
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
std::uint_least8_t SmallLocalIndex
Definition indextraits.hh:29