DUNE PDELab (2.7)

elementmapper.hh
1#ifndef DUNE_PDELAB_COMMON_ELEMENTMAPPER_HH
2#define DUNE_PDELAB_COMMON_ELEMENTMAPPER_HH
3
4#include <vector>
5#include <algorithm>
6#include <numeric>
7
11
12namespace Dune {
13
14 namespace PDELab {
15
16#ifndef DOXYGEN
17
18 // implementation for mixed grids
19 template<typename GV, bool has_single_cell_type>
20 class ElementMapperBase
21 {
22
23 protected:
24
25 typedef typename GV::template Codim<0>::Entity Element;
26 typedef std::size_t size_type;
27
28 private:
29
30 static const size_type dim = GV::dimension;
31 typedef typename GV::IndexSet IndexSet;
32
33 protected:
34
35 void update()
36 {
37 // clear old values
38 std::fill(_gt_offsets.begin(),_gt_offsets.end(),0);
39
40 // extract per-GeometryType sizes in codim 0
41 for (auto gt : _index_set.types(0))
42 {
43 _gt_offsets[LocalGeometryTypeIndex::index(gt) + 1] = _index_set.size(gt);
44 }
45
46 // convert to offsets
47 std::partial_sum(_gt_offsets.begin(),_gt_offsets.end(),_gt_offsets.begin());
48 }
49
50 size_type map(const Element& e) const
51 {
52 return _gt_offsets[LocalGeometryTypeIndex::index(e.type())] + _index_set.index(e);
53 }
54
55 ElementMapperBase(const GV& gv)
56 : _gt_offsets(LocalGeometryTypeIndex::size(dim) + 1)
57 , _index_set(gv.indexSet())
58 {
59 update();
60 }
61
62 private:
63
64 std::vector<size_type> _gt_offsets;
65 const IndexSet& _index_set;
66
67 };
68
69 // implementation for grids with a single codim 0 geometry type
70 template<typename GV>
71 class ElementMapperBase<GV,true>
72 {
73
74 protected:
75
76 typedef typename GV::template Codim<0>::Entity Element;
77 typedef typename GV::IndexSet IndexSet;
78 typedef std::size_t size_type;
79
80 void update()
81 {}
82
83 size_type map(const Element& e) const
84 {
85 return _index_set.index(e);
86 }
87
88 ElementMapperBase(const GV& gv)
89 : _index_set(gv.indexSet())
90 {}
91
92 private:
93
94 const IndexSet& _index_set;
95
96 };
97
98#endif // DOXYGEN
99
100
102
112 template<typename GV>
114 : public ElementMapperBase<GV,
115 Dune::Capabilities::hasSingleGeometryType<
116 typename GV::Grid
117 >::v
118 >
119 {
120
121 typedef ElementMapperBase<
122 GV,
124 typename GV::Grid
125 >::v
126 > BaseT;
127
128 public:
129
131 typedef typename BaseT::size_type size_type;
132
134 typedef typename BaseT::Element Element;
135
137
140 ElementMapper(const GV& gv)
141 : BaseT(gv)
142 {}
143
145
153 size_type map(const Element& e) const
154 {
155 return BaseT::map(e);
156 }
157
158 };
159
160 } // namespace PDELab
161
162} // namespace Dune
163
164#endif // DUNE_PDELAB_COMMON_ELEMENTMAPPER_HH
static constexpr std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type within its dimension.
Definition: typeindex.hh:68
Class providing a consecutive index for codim 0 entities of a GridView.
Definition: elementmapper.hh:119
BaseT::size_type size_type
The type of the returned index.
Definition: elementmapper.hh:131
ElementMapper(const GV &gv)
Construct a CellIndexProvider for the given GridView.
Definition: elementmapper.hh:140
BaseT::Element Element
The type of the codim 0 entities of the GridView.
Definition: elementmapper.hh:134
size_type map(const Element &e) const
Return the index of the given element.
Definition: elementmapper.hh:153
A set of traits classes to store static information about grid implementation.
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:156
Dune namespace.
Definition: alignedallocator.hh:14
Specialize with 'true' for if the codimension 0 entity of the grid has only one possible geometry typ...
Definition: capabilities.hh:25
A unique label for each type of element that can occur in a grid.
Helper classes to provide indices for geometrytypes for use in a vector.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)