dune-fem  2.4.1-rc
common/indexset.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_GRIDPART_COMMON_INDEXSET_HH
2 #define DUNE_FEM_GRIDPART_COMMON_INDEXSET_HH
3 
4 #include <type_traits>
5 #include <utility>
6 #include <vector>
7 
8 #include <dune/common/deprecated.hh>
9 
10 #include <dune/geometry/type.hh>
11 
13 
14 namespace Dune
15 {
16 
17  namespace Fem
18  {
19 
20  // Internal forward declaration
21  // ----------------------------
22 
23 
24  template< class Traits >
25  class IndexSet;
26  template< class Traits >
28  template< class Traits >
30 
31 
32 
33  namespace Capabilities
34  {
35 
36  // isConsecutiveIndexSet
37  // ---------------------
38 
45  template< class IndexSet >
47  {
48  template< class Traits >
49  static std::true_type __isConsecutive ( const ConsecutiveIndexSet< Traits > & );
50 
51  static std::false_type __isConsecutive ( ... );
52 
53  public:
54  static const bool v = decltype( __isConsecutive( std::declval< IndexSet >() ) )::value;
55  };
56 
57 
58 
59  // isAdaptiveIndexSet
60  // ------------------
61 
68  template< class IndexSet >
70  {
71  template< class Traits >
72  static std::true_type __isAdaptive ( const AdaptiveIndexSet< Traits > & );
73 
74  static std::false_type __isAdaptive ( ... );
75 
76  public:
77  static const bool v = decltype( __isAdaptive( std::declval< IndexSet >() ) )::value;
78  };
79 
80 
81 
82 #ifndef DOXYGEN
83 
84  template< class IndexSet >
85  struct isConsecutiveIndexSet< const IndexSet >
86  : public isConsecutiveIndexSet< IndexSet >
87  {};
88 
89  template< class IndexSet >
90  struct isAdaptiveIndexSet< const IndexSet >
91  : public isAdaptiveIndexSet< IndexSet >
92  {};
93 
94 #endif // #ifndef DOXYGEN
95 
96  } // namespace Capabilites
97 
98 
99 
100  // IndexSet
101  // --------
102 
108  template< class Traits >
109  class IndexSet
110  {
111  public:
113  static const int dimension = Traits::dimension;
114 
115  template< int codim >
116  struct Codim
117  {
119  typedef typename Traits::template Codim< codim >::Entity Entity;
120  };
121 
123  typedef typename Traits::IndexType IndexType;
124 
126  typedef typename Traits::Types Types;
127 
128  protected:
129  IndexSet () = default;
130 
131  public:
133  Types types ( int codim ) const
134  {
135  return impl().types( codim );
136  }
137 
139  const std::vector< GeometryType > &geomTypes ( int codim ) const
140  DUNE_DEPRECATED_MSG("IndexSet::geomTypes(codim) is deprecated, use IndexSet::types(codim) instead")
141  {
142  return impl().geomTypes( codim );
143  }
144 
146  template< class Entity >
147  bool contains ( const Entity &entity ) const
148  {
149  return impl().contains( entity );
150  }
151 
153  IndexType size ( GeometryType type ) const
154  {
155  return impl().size( type );
156  }
157 
159  IndexType size ( int codim ) const
160  {
161  return impl().size( codim );
162  }
163 
165  template< class Entity >
166  IndexType index ( const Entity &entity ) const
167  {
168  return index< Entity::codimension >( entity );
169  }
170 
172  template< int codim >
173  IndexType index ( const typename Codim< codim >::Entity &entity ) const
174  {
175  return impl().template index< codim >( entity );
176  }
177 
179  template< class Entity >
180  IndexType subIndex ( const Entity &entity, int i, unsigned int cd ) const
181  {
182  return subIndex< Entity::codimension >( entity, i, cd );
183  }
184 
186  template< int codim >
187  IndexType subIndex ( const typename Codim< codim >::Entity &entity, int i, unsigned int cd ) const
188  {
189  return impl().template subIndex< codim >( entity, i, cd );
190  }
191 
192  protected:
193  const typename Traits::IndexSetType &impl () const
194  {
195  return static_cast< const typename Traits::IndexSetType & >( *this );
196  }
197  };
198 
199 
200 
201  // ConsecutiveIndexSet
202  // -------------------
203 
209  template< class Traits >
210  class ConsecutiveIndexSet
211  : public IndexSet< Traits >
212  {
213  typedef IndexSet< Traits > BaseType;
214 
215  protected:
216  using BaseType::impl;
217 
218  ConsecutiveIndexSet () = default;
219 
220  public:
226  static constexpr bool consecutive () noexcept
227  // DUNE_DEPRECATED_MSG("IndexSet::consecutive() is deprecated, use Capabilities::isConsecutiveIndexSet<IndexSet>::v instead")
228  {
229  return true;
230  }
231 
233  void resize () { impl().resize(); }
234 
236  bool compress () { return impl().compress(); }
237 
239  void insertEntity ( const typename BaseType::template Codim< 0 >::Entity &entity )
240  {
241  impl().insertEntity( entity );
242  }
243 
245  void removeEntity ( const typename BaseType::template Codim< 0 >::Entity &entity )
246  {
247  impl().removeEntity( entity );
248  }
249 
251  void backup () const { impl().backup(); }
252 
254  void restore () { impl().restore(); }
255 
257  template< class T >
258  void write ( OutStreamInterface< T > &stream ) const
259  {
260  impl().write( stream );
261  }
262 
264  template< class T >
265  void read ( InStreamInterface< T > &stream )
266  {
267  impl().read( stream );
268  }
269 
272  protected:
273  typename Traits::IndexSetType &impl ()
274  {
275  const typename Traits::IndexSetType &impl = BaseType::impl();
276  return const_cast< typename Traits::IndexSetType & >( impl );
277  }
278  };
279 
280 
281 
282  // AdaptiveIndexSet
283  // ----------------
284 
290  template< class Traits >
291  class AdaptiveIndexSet
292  : public ConsecutiveIndexSet< Traits >
293  {
295 
296  protected:
297  using BaseType::impl;
298 
299  AdaptiveIndexSet () = default;
300 
301  public:
307  int numberOfHoles ( GeometryType type ) const
308  {
309  return impl().numberOfHoles( type );
310  }
311 
313  int oldIndex ( int hole, GeometryType type ) const
314  {
315  return impl().oldIndex( hole, type );
316  }
317 
319  int newIndex ( int hole, GeometryType type ) const
320  {
321  return impl().newIndex( hole, type );
322  }
323 
326 #ifndef DOXYGEN
327 
328  int numberOfHoles ( int codim ) const
329  DUNE_DEPRECATED_MSG("AdaptiveIndexSet::numberOfHoles(int) is deprecated, use AdaptiveIndexSet::numberOfHoles(type) instead")
330  {
331  return impl().numberOfHoles( codim );
332  }
333 
334  int oldIndex ( int hole, int codim ) const
335  DUNE_DEPRECATED_MSG("AdaptiveIndexSet::oldIndex(int, int) is deprecated, use AdaptiveIndexSet::oldIndex(int, type) instead")
336  {
337  return impl().oldIndex( hole, codim );
338  }
339 
340  int newIndex ( int hole, int codim ) const
341  DUNE_DEPRECATED_MSG("AdaptiveIndexSet::newIndex(int) is deprecated, use AdaptiveIndexSet::newIndex(int, type) instead")
342  {
343  return impl().numberOfHoles( hole, codim );
344  }
345 
346 #endif // #ifndef DOXYGEN
347  };
348 
349  } // namespace Fem
350 
351 } // namespace Dune
352 
353 #endif // #ifndef DUNE_FEM_GRIDPART_COMMON_INDEXSET_HH
Definition: common/indexset.hh:116
interface documentation for (grid part) index sets
Definition: common/indexset.hh:25
Traits::IndexSetType & impl()
Definition: common/indexset.hh:273
bool contains(const Entity &entity) const
return true if entity has index
Definition: common/indexset.hh:147
int numberOfHoles(GeometryType type) const
return number of holes for given type
Definition: common/indexset.hh:307
IndexType index(const Entity &entity) const
return index for given entity
Definition: common/indexset.hh:166
int newIndex(int hole, GeometryType type) const
return new index for given hole and type
Definition: common/indexset.hh:319
Types types(int codim) const
return range of geometry types
Definition: common/indexset.hh:133
void removeEntity(const typename BaseType::template Codim< 0 >::Entity &entity)
please doc me
Definition: common/indexset.hh:245
IndexType index(const typename Codim< codim >::Entity &entity) const
return index for given entity
Definition: common/indexset.hh:173
specialize with true if index set implements the interface for consecutive index sets ...
Definition: common/indexset.hh:46
static std::true_type __isConsecutive(const ConsecutiveIndexSet< Traits > &)
IndexType subIndex(const Entity &entity, int i, unsigned int cd) const
return index for given subentity
Definition: common/indexset.hh:180
void insertEntity(const typename BaseType::template Codim< 0 >::Entity &entity)
please doc me
Definition: common/indexset.hh:239
extended interface for adaptive, consecutive index sets
Definition: common/indexset.hh:29
void backup() const
please doc me
Definition: common/indexset.hh:251
void read(InStreamInterface< T > &stream)
please doc me
Definition: common/indexset.hh:265
void write(OutStreamInterface< T > &stream) const
please doc me
Definition: common/indexset.hh:258
Definition: coordinate.hh:4
int oldIndex(int hole, GeometryType type) const
return old index for given hole and type
Definition: common/indexset.hh:313
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
IndexType size(int codim) const
return number of entities of given codimension
Definition: common/indexset.hh:159
void resize()
please doc me
Definition: common/indexset.hh:233
IndexType size(GeometryType type) const
return number of entities of given type
Definition: common/indexset.hh:153
Traits::template Codim< codim >::Entity Entity
entity type
Definition: common/indexset.hh:119
IndexType subIndex(const typename Codim< codim >::Entity &entity, int i, unsigned int cd) const
return index for given subentity
Definition: common/indexset.hh:187
bool compress()
please doc me
Definition: common/indexset.hh:236
static constexpr bool consecutive() noexcept
please doc me
Definition: common/indexset.hh:226
const Traits::IndexSetType & impl() const
Definition: common/indexset.hh:193
Traits::IndexType IndexType
index type
Definition: common/indexset.hh:123
void restore()
please doc me
Definition: common/indexset.hh:254
Traits::Types Types
geometry type range type
Definition: common/indexset.hh:126
static const bool v
Definition: common/indexset.hh:54
const std::vector< GeometryType > & geomTypes(int codim) const
return vector of geometry types used of given codimension
Definition: common/indexset.hh:139
abstract interface for an output stream
Definition: streams.hh:44
extended interface for consecutive index sets
Definition: common/indexset.hh:27