dune-fem  2.8-git
typeindexset.hh
Go to the documentation of this file.
1 #ifndef DUNE_GEOMETRY_TYPEINDEXSET_HH
2 #define DUNE_GEOMETRY_TYPEINDEXSET_HH
3 
4 #include <cstddef>
5 
6 #include <dune/geometry/type.hh>
7 
8 namespace Dune
9 {
10 
11  namespace Fem
12  {
13  namespace hpDG {
14  // LocalGeometryTypeIndexSet
15  // -------------------------
16 
24  template< int dim, bool regular = false >
26 
27  template< int dim >
28  class LocalGeometryTypeIndexSet< dim, true >
29  {
31 
32  public:
33  inline static constexpr std::size_t size () noexcept
34  {
35  return (1 << dim) - ((1 << dim) >> 1);
36  }
37 
38  inline static constexpr std::size_t index ( const GeometryType &type ) noexcept
39  {
40  return (type.id() >> 1);
41  }
42 
43  inline static constexpr bool contains ( const GeometryType &type ) noexcept
44  {
45  return ((type.dim() == dim) && !type.isNone());
46  }
47 
48  inline static GeometryType type ( std::size_t index ) noexcept
49  {
50  return GeometryType( static_cast< unsigned int >( index ) << 1, dim );
51  }
52  };
53 
54  template< int dim >
55  class LocalGeometryTypeIndexSet< dim, false >
56  {
59 
60  public:
61  inline static constexpr std::size_t size () noexcept
62  {
63  return (RegularTypeIndexSet::size() + 1);
64  }
65 
66  inline static constexpr std::size_t index ( const GeometryType &type ) noexcept
67  {
68  return (type.isNone() ? RegularTypeIndexSet::size() : type.id() >> 1);
69  }
70 
71  inline static constexpr bool contains ( const GeometryType &type ) noexcept
72  {
73  return (type.dim() == dim);
74  }
75 
76  inline static GeometryType type ( std::size_t index ) noexcept
77  {
78  return (index < RegularTypeIndexSet::size() ? RegularTypeIndexSet::type( index ) : GeometryType( 0, dim, true ));
79  }
80  };
81 
82 
83 
84  // GlobalGeometryTypeIndexSet
85  // --------------------------
86 
94  template< int maxdim, bool regular = false >
96 
97  template< int maxdim >
98  class GlobalGeometryTypeIndexSet< maxdim, true >
99  {
101 
102  public:
103  inline static constexpr std::size_t size () noexcept
104  {
105  return (1 << maxdim);
106  }
107 
108  inline static constexpr std::size_t index ( const GeometryType &type ) noexcept
109  {
110  return ((1 << type.dim()) + type.id()) >> 1;
111  }
112 
113  inline static constexpr bool contains ( const GeometryType &type ) noexcept
114  {
115  return ((type.dim() <= maxdim) && !type.isNone());
116  }
117 
118  inline static GeometryType type ( std::size_t index ) noexcept
119  {
120  return GeometryType( (index << 1) & ~(1 << dim( index )), dim( index ) );
121  }
122 
123  private:
124  inline static constexpr int dim ( std::size_t index, int d = maxdim )
125  {
126  return ((d <= 0) || ((index & (1 << (d-1))) != 0) ? d : dim( index, d-1 ));
127  }
128  };
129 
130  template< int maxdim >
131  class GlobalGeometryTypeIndexSet< maxdim, false >
132  {
135 
136  public:
137  inline static constexpr std::size_t size () noexcept
138  {
139  return RegularTypeIndexSet::size() + (maxdim + 1);
140  }
141 
142  inline static constexpr std::size_t index ( const GeometryType &type ) noexcept
143  {
144  return (type.isNone() ? RegularTypeIndexSet::size() + type.dim() : RegularTypeIndexSet::index( type ));
145  }
146 
147  inline static constexpr bool contains ( const GeometryType &type ) noexcept
148  {
149  return (type.dim() <= maxdim);
150  }
151 
152  inline static GeometryType type ( std::size_t index ) noexcept
153  {
154  return (index < RegularTypeIndexSet::size() ? RegularTypeIndexSet::type( index ) : GeometryType( 0, static_cast< int >( index - RegularTypeIndexSet::size() ), true ));
155  }
156  };
157 
158 
159 
160  // SingleGeometryTypeIndexSet
161  // --------------------------
162 
170  template< unsigned int topologyId, int dim >
172  {
174 
175  public:
176  inline static constexpr std::size_t size () noexcept
177  {
178  return 1;
179  }
180 
181  inline static constexpr std::size_t index ( const GeometryType &type ) noexcept
182  {
183  return 0;
184  }
185 
186  inline static constexpr bool contains ( const GeometryType &type ) noexcept
187  {
188  return (type == GeometryType( topologyId, dim ));
189  }
190 
191  inline static GeometryType type ( std::size_t index ) noexcept
192  {
193  return GeometryType( topologyId, dim );
194  }
195  };
196 
197 
198 
199  // GeometryTypes
200  // -------------
201 
202  template< class TypeIndexSet >
204  {
205  struct Iterator
206  {
207  bool operator== ( const Iterator &other ) const { return (index == other.index); }
208  bool operator!= ( const Iterator &other ) const { return (index != other.index); }
209 
210  GeometryType operator* () const { return TypeIndexSet::type( index ); }
211 
212  Iterator &operator++ () { ++index; return *this; }
213 
214  std::size_t index;
215  };
216 
217  Iterator begin () const { return Iterator{ 0 }; }
218  Iterator end () const { return Iterator{ TypeIndexSet::size() }; }
219  };
220 
221 } // namespace hpDG
222 } // namespace Fem
223 } // namespace Dune
224 
225 #endif // #ifndef DUNE_GEOMETRY_TYPEINDEXSET_HH
Definition: bindguard.hh:11
Please doc me.
Definition: typeindexset.hh:25
static constexpr std::size_t index(const GeometryType &type) noexcept
Definition: typeindexset.hh:38
static GeometryType type(std::size_t index) noexcept
Definition: typeindexset.hh:48
static constexpr std::size_t size() noexcept
Definition: typeindexset.hh:33
static constexpr bool contains(const GeometryType &type) noexcept
Definition: typeindexset.hh:43
static GeometryType type(std::size_t index) noexcept
Definition: typeindexset.hh:76
static constexpr bool contains(const GeometryType &type) noexcept
Definition: typeindexset.hh:71
static constexpr std::size_t index(const GeometryType &type) noexcept
Definition: typeindexset.hh:66
static constexpr std::size_t size() noexcept
Definition: typeindexset.hh:61
Please doc me.
Definition: typeindexset.hh:95
static constexpr bool contains(const GeometryType &type) noexcept
Definition: typeindexset.hh:113
static GeometryType type(std::size_t index) noexcept
Definition: typeindexset.hh:118
static constexpr std::size_t index(const GeometryType &type) noexcept
Definition: typeindexset.hh:108
static constexpr std::size_t size() noexcept
Definition: typeindexset.hh:103
static GeometryType type(std::size_t index) noexcept
Definition: typeindexset.hh:152
static constexpr std::size_t size() noexcept
Definition: typeindexset.hh:137
static constexpr std::size_t index(const GeometryType &type) noexcept
Definition: typeindexset.hh:142
static constexpr bool contains(const GeometryType &type) noexcept
Definition: typeindexset.hh:147
Please doc me.
Definition: typeindexset.hh:172
static constexpr std::size_t index(const GeometryType &type) noexcept
Definition: typeindexset.hh:181
static GeometryType type(std::size_t index) noexcept
Definition: typeindexset.hh:191
static constexpr std::size_t size() noexcept
Definition: typeindexset.hh:176
static constexpr bool contains(const GeometryType &type) noexcept
Definition: typeindexset.hh:186
Definition: typeindexset.hh:204
Iterator end() const
Definition: typeindexset.hh:218
Iterator begin() const
Definition: typeindexset.hh:217
Definition: typeindexset.hh:206
bool operator!=(const Iterator &other) const
Definition: typeindexset.hh:208
bool operator==(const Iterator &other) const
Definition: typeindexset.hh:207
Iterator & operator++()
Definition: typeindexset.hh:212
GeometryType operator*() const
Definition: typeindexset.hh:210
std::size_t index
Definition: typeindexset.hh:214