dune-fem  2.4.1-rc
idgridpart/indexset.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_GRIDPART_IDGRIDPART_INDEXSET_HH
2 #define DUNE_FEM_GRIDPART_IDGRIDPART_INDEXSET_HH
3 
4 #include <type_traits>
5 #include <vector>
6 
7 #include <dune/geometry/type.hh>
8 
11 
13 
14 namespace Dune
15 {
16 
17  namespace Fem
18  {
19 
20  // Internal forward declaration
21  // ----------------------------
22 
23  template< class GridFamily >
24  class IdIndexSet;
25 
26 
27 
28  namespace __IdIndexSet
29  {
30 
31  // IndexSet
32  // --------
33 
34  template< class GridFamily >
35  class IndexSet
36  {
37  protected:
38  typedef typename std::remove_const< GridFamily >::type::Traits Traits;
39 
40  public:
41  typedef typename Traits::HostGridPartType::IndexSetType HostIndexSetType;
42 
43  static const int dimension = HostIndexSetType::dimension;
44 
45  template< int codim >
46  struct Codim
47  {
48  typedef typename Traits::template Codim< codim >::Entity Entity;
49  };
50 
51  typedef typename HostIndexSetType::IndexType IndexType;
52 
53  typedef typename HostIndexSetType::Types Types;
54 
55  explicit IndexSet ( const HostIndexSetType &hostIndexSet )
56  : hostIndexSet_( hostIndexSet )
57  {}
58 
59  Types types ( int codim ) const
60  {
61  return hostIndexSet().types( codim );
62  }
63 
64  const std::vector< GeometryType > &geomTypes ( int codim ) const
65  {
66  return hostIndexSet().geomTypes( codim );
67  }
68 
69  template< class Entity >
70  bool contains ( const Entity &entity ) const
71  {
72  return hostIndexSet().contains( entity.impl().hostEntity() );
73  }
74 
75  IndexType size ( GeometryType type ) const
76  {
77  return hostIndexSet().size( type );
78  }
79 
80  IndexType size ( int codim ) const
81  {
82  return hostIndexSet().size( codim );
83  }
84 
85  template< class Entity >
86  IndexType index ( const Entity &entity ) const
87  {
88  return index< Entity::codimension >( entity );
89  }
90 
91  template< int codim >
92  IndexType index ( const typename Codim< codim >::Entity &entity ) const
93  {
94  return hostIndexSet().template index< codim >( entity.impl().hostEntity() );
95  }
96 
97  template< class Entity >
98  IndexType subIndex ( const Entity &entity, int i, unsigned int cd ) const
99  {
100  return subIndex< Entity::codimension >( entity, i, cd );
101  }
102 
103  template< int codim >
104  IndexType subIndex ( const typename Codim< codim >::Entity &entity, int i, unsigned int cd ) const
105  {
106  return hostIndexSet().template subIndex< codim >( entity.impl().hostEntity(), i, cd );
107  }
108 
109  const HostIndexSetType &hostIndexSet () const
110  {
111  return hostIndexSet_;
112  }
113 
114  private:
115  const HostIndexSetType &hostIndexSet_;
116  };
117 
118 
119 
120  // ConsecutiveIndexSet
121  // -------------------
122 
123  template< class GridFamily >
125  : public IndexSet< GridFamily >
126  {
128 
129  public:
131 
132  using BaseType::hostIndexSet;
133 
134  explicit ConsecutiveIndexSet ( const HostIndexSetType &hostIndexSet )
135  : BaseType ( hostIndexSet )
136  {}
137 
138  bool consecutive () const { return hostIndexSet().consecutive(); }
139 
140  void resize () { hostIndexSet().resize(); }
141 
142  bool compress () { return hostIndexSet().compress(); }
143 
144  void insertEntity ( const typename BaseType::template Codim< 0 >::Entity &entity )
145  {
146  hostIndexSet().insertEntity( entity.impl().hostEntity() );
147  }
148 
149  void removeEntity ( const typename BaseType::template Codim< 0 >::Entity &entity )
150  {
151  hostIndexSet().removeEntity( entity.impl().hostEntity() );
152  }
153 
154  void backup () const { hostIndexSet().backup(); }
155 
156  void restore () { hostIndexSet().restore(); }
157 
158  template< class T >
160  {
161  hostIndexSet().write( stream );
162  }
163 
164  template< class T >
165  void read ( InStreamInterface< T > &stream )
166  {
167  hostIndexSet().read( stream );
168  }
169 
170  protected:
171  HostIndexSetType &hostIndexSet ()
172  {
173  return const_cast< HostIndexSetType & >( BaseType::hostIndexSet() );
174  }
175  };
176 
177 
178 
179  // AdaptiveIndexSet
180  // ----------------
181 
182  template< class GridFamily >
184  : public ConsecutiveIndexSet< GridFamily >
185  {
187 
188  public:
190  : BaseType ( hostIndexSet )
191  {}
192 
193  int numberOfHoles ( GeometryType type ) const
194  {
195  return this->hostIndexSet().numberOfHoles( type );
196  }
197 
198  int numberOfHoles ( int codim ) const
199  {
200  return this->hostIndexSet().numberOfHoles( codim );
201  }
202 
203  int oldIndex ( int hole, GeometryType type ) const
204  {
205  return this->hostIndexSet().oldIndex( hole, type );
206  }
207 
208  int oldIndex ( int hole, int codim ) const
209  {
210  return this->hostIndexSet().oldIndex( hole, codim );
211  }
212 
213  int newIndex ( int hole, GeometryType type ) const
214  {
215  return this->hostIndexSet().newIndex( hole, type );
216  }
217 
218  int newIndex ( int hole, int codim ) const
219  {
220  return this->hostIndexSet().newIndex( hole, codim );
221  }
222  };
223 
224 
225 
226  // Implementation
227  // --------------
228 
229  template< class GridFamily,
230  class HostIndexSet = typename std::remove_const< GridFamily >::type::Traits::HostGridPartType::IndexSetType,
234  {
235  typedef typename std::conditional< adaptive,
237  typename std::conditional< consecutive,
240  >::type
241  >::type Type;
242  };
243 
244  } // namespace __IdIndexSet
245 
246 
247 
248  // IdIndexSet
249  // ----------
250 
251  template< class GridFamily >
252  class IdIndexSet
253  : public __IdIndexSet::Implementation< GridFamily >::Type
254  {
255  typedef typename __IdIndexSet::Implementation< GridFamily >::Type BaseType;
256 
257  friend class Capabilities::isPersistentIndexSet< IdIndexSet< GridFamily > >;
258 
259  public:
260  explicit IdIndexSet ( const typename BaseType::HostIndexSetType &hostIndexSet )
261  : BaseType ( hostIndexSet )
262  {}
263  };
264 
265 
266 
267  namespace Capabilities
268  {
269 
270  template< class GridFamily >
271  struct isConsecutiveIndexSet< IdIndexSet< GridFamily > >
272  : public isConsecutiveIndexSet< typename IdIndexSet< GridFamily >::HostIndexSetType >
273  {};
274 
275  template< class GridFamily >
276  struct isAdaptiveIndexSet< IdIndexSet< GridFamily > >
277  : public isAdaptiveIndexSet< typename IdIndexSet< GridFamily >::HostIndexSetType >
278  {};
279 
280  template< class GridFamily >
281  struct isPersistentIndexSet< IdIndexSet< GridFamily > >
282  {
283  private:
285  typedef typename IndexSetType::HostIndexSetType HostIndexSetType;
286 
287  public:
289 
290  static constexpr PersistentIndexSetInterface *map ( IndexSetType &indexSet ) noexcept
291  {
292  return isPersistentIndexSet< HostIndexSetType >::map( indexSet.hostIndexSet() );
293  }
294  };
295 
296  } // namespace Capabilities
297 
298  } // namespace Fem
299 
300 } // namespace Dune
301 
302 #endif // #ifndef DUNE_FEM_GRIDPART_IDGRIDPART_INDEXSET_HH
IndexType subIndex(const typename Codim< codim >::Entity &entity, int i, unsigned int cd) const
Definition: idgridpart/indexset.hh:104
std::remove_const< GridFamily >::type::Traits Traits
Definition: idgridpart/indexset.hh:38
IndexType subIndex(const Entity &entity, int i, unsigned int cd) const
Definition: idgridpart/indexset.hh:98
Traits::template Codim< codim >::Entity Entity
Definition: idgridpart/indexset.hh:48
static constexpr PersistentIndexSetInterface * map(IndexSetType &indexSet) noexcept
Definition: idgridpart/indexset.hh:290
void restore()
Definition: idgridpart/indexset.hh:156
bool consecutive() const
Definition: idgridpart/indexset.hh:138
IndexType index(const typename Codim< codim >::Entity &entity) const
Definition: idgridpart/indexset.hh:92
const HostIndexSetType & hostIndexSet() const
Definition: idgridpart/indexset.hh:109
IndexSet(const HostIndexSetType &hostIndexSet)
Definition: idgridpart/indexset.hh:55
Traits::HostGridPartType::IndexSetType HostIndexSetType
Definition: idgridpart/indexset.hh:41
IndexType index(const Entity &entity) const
Definition: idgridpart/indexset.hh:86
Definition: idgridpart/indexset.hh:233
int numberOfHoles(int codim) const
Definition: idgridpart/indexset.hh:198
AdaptiveIndexSet(const typename BaseType::HostIndexSetType &hostIndexSet)
Definition: idgridpart/indexset.hh:189
specialize with true if index set implements the interface for consecutive index sets ...
Definition: common/indexset.hh:46
void read(InStreamInterface< T > &stream)
Definition: idgridpart/indexset.hh:165
int oldIndex(int hole, GeometryType type) const
Definition: idgridpart/indexset.hh:203
IdIndexSet(const typename BaseType::HostIndexSetType &hostIndexSet)
Definition: idgridpart/indexset.hh:260
int numberOfHoles(GeometryType type) const
Definition: idgridpart/indexset.hh:193
Definition: idgridpart/indexset.hh:24
void insertEntity(const typename BaseType::template Codim< 0 >::Entity &entity)
Definition: idgridpart/indexset.hh:144
int newIndex(int hole, GeometryType type) const
Definition: idgridpart/indexset.hh:213
void backup() const
Definition: idgridpart/indexset.hh:154
HostIndexSetType::Types Types
Definition: idgridpart/indexset.hh:53
void write(OutStreamInterface< T > &stream)
Definition: idgridpart/indexset.hh:159
static const int dimension
Definition: idgridpart/indexset.hh:43
Definition: coordinate.hh:4
std::conditional< adaptive, AdaptiveIndexSet< GridFamily >, typename std::conditional< consecutive, ConsecutiveIndexSet< GridFamily >, IndexSet< GridFamily > >::type >::type Type
Definition: idgridpart/indexset.hh:241
specialize with true if index set implements the interface for adaptive index sets ...
Definition: common/indexset.hh:69
abstract interface for an input stream
Definition: streams.hh:177
ConsecutiveIndexSet(const HostIndexSetType &hostIndexSet)
Definition: idgridpart/indexset.hh:134
int oldIndex(int hole, int codim) const
Definition: idgridpart/indexset.hh:208
IndexType size(GeometryType type) const
Definition: idgridpart/indexset.hh:75
Definition: idgridpart/indexset.hh:35
Definition: idgridpart/indexset.hh:124
IndexType size(int codim) const
Definition: idgridpart/indexset.hh:80
HostIndexSetType & hostIndexSet()
Definition: idgridpart/indexset.hh:171
Types types(int codim) const
Definition: idgridpart/indexset.hh:59
void resize()
Definition: idgridpart/indexset.hh:140
capability for persistent index sets
Definition: persistentindexset.hh:90
Definition: idgridpart/indexset.hh:46
bool contains(const Entity &entity) const
Definition: idgridpart/indexset.hh:70
bool compress()
Definition: idgridpart/indexset.hh:142
HostIndexSetType::IndexType IndexType
Definition: idgridpart/indexset.hh:51
int newIndex(int hole, int codim) const
Definition: idgridpart/indexset.hh:218
Definition: idgridpart/indexset.hh:183
BaseType::HostIndexSetType HostIndexSetType
Definition: idgridpart/indexset.hh:130
virtual base class for persistent index sets
Definition: persistentindexset.hh:34
void removeEntity(const typename BaseType::template Codim< 0 >::Entity &entity)
Definition: idgridpart/indexset.hh:149
abstract interface for an output stream
Definition: streams.hh:44
const std::vector< GeometryType > & geomTypes(int codim) const
Definition: idgridpart/indexset.hh:64