version 3.11-dev
Loading...
Searching...
No Matches
feelementdiscretization.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_FE_ELEMENT_DISCRETIZATION_HH
15#define DUMUX_DISCRETIZATION_FE_ELEMENT_DISCRETIZATION_HH
16
17#include <optional>
18#include <ranges>
19#include <utility>
20
21#include <dune/common/rangeutilities.hh>
22#include <dune/geometry/type.hh>
23
28
29namespace Dumux::Experimental {
30
39template<class GG, bool enableGridDiscretizationCache>
41{
42 using GridView = typename GG::GridView;
43 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
44 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
45 using FeLocalBasis = typename GG::FeCache::FiniteElementType::Traits::LocalBasisType;
46 using GGCache = typename GG::Cache;
47 using DofHelper = typename GGCache::DofHelper;
48
49public:
51 using Element = typename GridView::template Codim<0>::Entity;
54 using GridGeometry [[deprecated("Use GridDiscretization instead")]] = GG;
56 using ElementQuadratureRule = typename GG::ElementQuadratureRule;
58 using IntersectionQuadratureRule = typename GG::IntersectionQuadratureRule;
60 using BoundaryFaceQuadratureRule = typename GG::BoundaryFaceQuadratureRule;
62 using BoundaryFace = typename GG::BoundaryFace;
64 static constexpr std::size_t maxNumElementDofs = GridDiscretization::maxNumElementDofs;
65
67 FEElementDiscretization(const GGCache& ggCache)
68 : ggCache_(&ggCache)
69 {}
70
72 friend inline auto localDofs(const FEElementDiscretization& elemDisc)
73 { return DofHelper::localDofs(elemDisc); }
74
76 friend inline auto nonCVLocalDofs(const FEElementDiscretization& elemDisc)
77 { return localDofs(elemDisc); }
78
81 friend inline auto localDofs(const FEElementDiscretization& elemDisc, const BoundaryFace& boundaryFace)
82 { return DofHelper::localDofsOnBoundaryFace(elemDisc, boundaryFace); }
83
86 friend inline std::ranges::view auto
88 {
89 const auto& v = elemDisc.ggCache_->boundaryFaces(elemDisc.eIdx_);
90 return std::ranges::views::all(v);
91 }
92
94 const FeLocalBasis& feLocalBasis() const
95 { return gridDiscretization().feCache().get(element_->type()).localBasis(); }
96
98 const auto& feLocalCoefficients() const
99 { return gridDiscretization().feCache().get(element_->type()).localCoefficients(); }
100
102 std::size_t numLocalDofs() const
103 { return feLocalCoefficients().size(); }
104
111 {
112 this->bindElement(element);
113 return std::move(*this);
114 }
115
118 void bind(const Element& element) &
119 { this->bindElement(element); }
120
127 {
128 this->bindElement(element);
129 return std::move(*this);
130 }
131
134 {
135 element_ = element;
136 eIdx_ = gridDiscretization().elementMapper().index(element);
137 elementGeometry_.emplace(element.geometry());
138 }
139
141 bool isBound() const
142 { return static_cast<bool>(element_); }
143
145 const Element& element() const
146 { return *element_; }
147
149 const typename Element::Geometry& elementGeometry() const
150 { return *elementGeometry_; }
151
153 [[deprecated("Use gridDiscretization() instead")]]
155 { return ggCache_->gridDiscretization(); }
156
159 { return ggCache_->gridDiscretization(); }
160
162 bool hasBoundaryFaces() const
163 { return !ggCache_->boundaryFaces(eIdx_).empty(); }
164
166 const BoundaryFace& boundaryFace(LocalIndexType bfIdx) const
167 { return ggCache_->boundaryFaces(eIdx_)[bfIdx]; }
168
170 std::size_t elementIndex() const
171 { return eIdx_; }
172
174 typename BoundaryFace::Traits::Geometry geometry(const BoundaryFace& boundaryFace) const
175 {
176 assert(isBound());
177 const auto& elemGeo = elementGeometry();
178 const auto faceGeoInRef = referenceElement(elemGeo).template geometry<1>(boundaryFace.intersectionIndex());
179 typename BoundaryFace::Traits::CornerStorage corners;
180 for (int i = 0; i < faceGeoInRef.corners(); ++i)
181 corners.push_back(elemGeo.global(faceGeoInRef.corner(i)));
182 return { faceGeoInRef.type(), corners };
183 }
184
186 template<class LocalDof>
187 friend inline auto ipData(const FEElementDiscretization& elemDisc, const LocalDof& localDof)
188 {
189 const auto type = elemDisc.element().type();
190 const auto& localKey = elemDisc.feLocalCoefficients().localKey(localDof.index());
191 const auto& localPos = DofHelper::localDofPosition(type, localKey);
193 localPos,
194 elemDisc.elementGeometry().global(localPos),
195 localDof.index()
196 };
197 }
198
200 friend inline auto ipData(const FEElementDiscretization& elemDisc,
201 const typename Element::Geometry::GlobalCoordinate& globalPos)
202 {
204 [&] (const typename Element::Geometry::GlobalCoordinate& pos) {
205 return elemDisc.elementGeometry().local(pos); },
206 globalPos
207 };
208 }
209
210private:
211 const GGCache* ggCache_;
212 GridIndexType eIdx_;
213
214 std::optional<Element> element_;
215 std::optional<typename Element::Geometry> elementGeometry_;
216};
217
218} // end namespace Dumux::Experimental
219
220#endif
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
const auto & feLocalCoefficients() const
Get the local finite element coefficients.
Definition feelementdiscretization.hh:98
typename GG::BoundaryFaceQuadratureRule BoundaryFaceQuadratureRule
the quadrature rule type for boundary faces
Definition feelementdiscretization.hh:60
friend auto ipData(const FEElementDiscretization &elemDisc, const LocalDof &localDof)
Interpolation point data for a localDof.
Definition feelementdiscretization.hh:187
std::size_t numLocalDofs() const
The total number of element-local dofs.
Definition feelementdiscretization.hh:102
static constexpr std::size_t maxNumElementDofs
Definition feelementdiscretization.hh:64
const GridDiscretization & gridGeometry() const
The grid geometry we are a restriction of (deprecated).
Definition feelementdiscretization.hh:154
friend auto localDofs(const FEElementDiscretization &elemDisc)
iterate over all local dofs
Definition feelementdiscretization.hh:72
FEElementDiscretization(const GGCache &ggCache)
Constructor.
Definition feelementdiscretization.hh:67
typename GG::BoundaryFace BoundaryFace
export the boundary face type
Definition feelementdiscretization.hh:62
const Element & element() const
Definition feelementdiscretization.hh:145
FEElementDiscretization 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 feelementdiscretization.hh:126
friend auto ipData(const FEElementDiscretization &elemDisc, const typename Element::Geometry::GlobalCoordinate &globalPos)
Interpolation point data for a global position.
Definition feelementdiscretization.hh:200
typename GG::ElementQuadratureRule ElementQuadratureRule
the quadrature rule type for elements
Definition feelementdiscretization.hh:56
const Element::Geometry & elementGeometry() const
The bound element geometry.
Definition feelementdiscretization.hh:149
FEElementDiscretization 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 feelementdiscretization.hh:110
bool isBound() const
Returns true if bind/bindElement has already been called.
Definition feelementdiscretization.hh:141
void bind(const Element &element) &
Definition feelementdiscretization.hh:118
GG GridDiscretization
export type of finite element grid discretization
Definition feelementdiscretization.hh:53
friend auto localDofs(const FEElementDiscretization &elemDisc, const BoundaryFace &boundaryFace)
Definition feelementdiscretization.hh:81
friend std::ranges::view auto boundaryFaces(const FEElementDiscretization &elemDisc)
Definition feelementdiscretization.hh:87
const BoundaryFace & boundaryFace(LocalIndexType bfIdx) const
Definition feelementdiscretization.hh:166
const FeLocalBasis & feLocalBasis() const
Get a local finite element basis.
Definition feelementdiscretization.hh:94
std::size_t elementIndex() const
The bound element index.
Definition feelementdiscretization.hh:170
friend auto nonCVLocalDofs(const FEElementDiscretization &elemDisc)
iterate over non-CV local dofs (for pure FE methods all dofs are non-CV)
Definition feelementdiscretization.hh:76
typename GridView::template Codim< 0 >::Entity Element
export the element type
Definition feelementdiscretization.hh:51
typename GG::IntersectionQuadratureRule IntersectionQuadratureRule
the quadrature rule type for intersections
Definition feelementdiscretization.hh:58
bool hasBoundaryFaces() const
Returns whether the element has boundary faces.
Definition feelementdiscretization.hh:162
BoundaryFace::Traits::Geometry geometry(const BoundaryFace &boundaryFace) const
Geometry of a boundary face.
Definition feelementdiscretization.hh:174
const GridDiscretization & gridDiscretization() const
The grid discretization we are a restriction of.
Definition feelementdiscretization.hh:158
void bindElement(const Element &element) &
Binding of an element, has to be called before using the fe geometries.
Definition feelementdiscretization.hh:133
Classes representing interpolation point data for control-volume finite element schemes.
Defines the index types used for grid and local indices.
Class representing dofs on elements for control-volume finite element schemes.
Definition assembly/assembler.hh:44
Quadrature rules over sub-control volumes and sub-control volume faces.
typename GridView::IndexSet::IndexType GridIndex
Definition indextraits.hh:27
unsigned int LocalIndex
Definition indextraits.hh:28