dune-grid  2.4
indexidset.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_GRID_COMMON_INDEXIDSET_HH
5 #define DUNE_GRID_COMMON_INDEXIDSET_HH
6 
7 #include <vector>
8 #include <dune/common/exceptions.hh>
10 
11 
17 namespace Dune
18 {
19 
20 #include <dune/common/bartonnackmanifcheck.hh>
21 
74  template< class GridImp, class IndexSetImp, class IndexTypeImp, class TypesImp >
75  class IndexSet
76  {
77  /* We use the remove_const to extract the Type from the mutable class,
78  because the const class is not instantiated yet. */
79  typedef typename remove_const< GridImp >::type::Traits Traits;
80 
81  public:
83  template <int cc>
84  struct Codim
85  {
86  typedef typename Traits :: template Codim<cc> :: Entity Entity;
87  };
88 
90  typedef IndexTypeImp IndexType;
91 
93  typedef TypesImp Types;
94 
96  static const int dimension = remove_const< GridImp >::type::dimension;
97 
98  //===========================================================
102  //===========================================================
103 
110  /*
111  We use the remove_const to extract the Type from the mutable class,
112  because the const class is not instantiated yet.
113  */
114  template<int cc>
115  IndexType index (const typename Traits::template Codim<cc>::Entity& e) const
116  {
117  CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
118  return asImp().template index<cc>(e);
119  }
120 
130  template<class Entity>
131  IndexType index (const Entity& e) const
132  {
133  enum { cc = Entity::codimension };
134  CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
135  return asImp().template index<cc>(e);
136  }
137 
152  template< int cc >
153  IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &e,
154  int i, unsigned int codim ) const
155  {
156  CHECK_INTERFACE_IMPLEMENTATION((asImp().template subIndex< cc >(e,i,codim)));
157  return asImp().template subIndex< cc >(e,i,codim);
158  }
159 
178  template< class Entity >
179  IndexType subIndex ( const Entity &e, int i, unsigned int codim ) const
180  {
181  static const int cc = Entity::codimension;
182  return asImp().template subIndex< cc >( e, i, codim );
183  }
185 
186 
187  //===========================================================
191  //===========================================================
192 
208  Types types ( int codim ) const
209  {
210  CHECK_INTERFACE_IMPLEMENTATION( (asImp().types( codim )) );
211  return asImp().types( codim );
212  }
213 
221  const std::vector<GeometryType>& geomTypes (int codim) const DUNE_DEPRECATED_MSG( "Use IndexSet::types instead." )
222  {
223  CHECK_INTERFACE_IMPLEMENTATION((asImp().geomTypes(codim)));
224  return asImp().geomTypes(codim);
225  }
226 
232  IndexType size (GeometryType type) const
233  {
234  CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
235  return asImp().size(type);
236  }
237 
244  IndexType size (int codim) const
245  {
246  CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
247  return asImp().size(codim);
248  }
249 
255  template<class Entity>
256  bool contains (const Entity& e) const
257  {
258  CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
259  return asImp().contains(e);
260  }
261 
262  // Must be explicitly defined although this class should get a default constructor.
263  IndexSet() {}
264 
265  private:
267  IndexSet(const IndexSet&);
269  IndexSet& operator=(const IndexSet&);
270 
272  IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
274  const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
275  };
276 
277 #undef CHECK_INTERFACE_IMPLEMENTATION
278 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
279 
280 
281 
285  template<class GridImp, class IndexSetImp>
287  : public IndexSet< GridImp, IndexSetImp >
288  {
290  typedef typename remove_const< GridImp >::type::Traits Traits;
291 
292  public:
294  typedef typename Base::IndexType IndexType;
295 
296  typedef typename Base::Types Types;
297 
299  static const int dimension = Base::dimension;
300 
301  using Base::index;
302  using Base::subIndex;
303 
304  //===========================================================
308  //===========================================================
309 
310  Types types ( int codim ) const { return asImp().geomTypes( codim ); }
311 
318  IndexType size ( const int codim ) const
319  {
320  IndexType s( 0 );
321  const std::vector< GeometryType > &geomTs = asImp().geomTypes( codim );
322  typedef typename std::vector< GeometryType >::const_iterator Iterator;
323  const Iterator end = geomTs.end();
324  for( Iterator it = geomTs.begin(); it != end; ++it )
325  s += Base::size( *it );
326  return s;
327  }
329 
330  private:
331  IndexSetImp &asImp () { return static_cast< IndexSetImp & >( *this );}
332  const IndexSetImp &asImp () const { return static_cast< const IndexSetImp & >( *this ); }
333  };
334 
335 
412  template<class GridImp, class IdSetImp, class IdTypeImp>
413  class IdSet
414  {
415  public:
417  typedef IdTypeImp IdType;
418 
420  template<class Entity>
421  IdType id (const Entity& e) const
422  {
423  enum { cc = Entity::codimension };
424  return asImp().template id<cc>(e);
425  }
426 
428  /*
429  We use the remove_const to extract the Type from the mutable class,
430  because the const class is not instantiated yet.
431  */
432  template<int cc>
433  IdType id (const typename remove_const<GridImp>::type::
434  Traits::template Codim<cc>::Entity& e) const
435  {
436  return asImp().template id<cc>(e);
437  }
438 
441  IdType subId (const typename remove_const<GridImp>::type::
442  Traits::template Codim<0>::Entity& e, int i, unsigned int codim) const
443  {
444  return asImp().subId(e,i,codim);
445  }
446 
447  // Default constructor (is not provided automatically because copy constructor is private)
448  IdSet() {}
449 
450  private:
452  IdSet(const IdSet&);
454  IdSet& operator=(const IdSet&);
455 
457  IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
459  const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
460  };
461 
462 }
463 
464 #endif // DUNE_GRID_COMMON_INDEXIDSET_HH
IndexType index(const typename Traits::template Codim< cc >::Entity &e) const
Map entity to index. The result of calling this method with an entity that is not in the index set is...
Definition: indexidset.hh:115
Know your own codimension.
Definition: common/entity.hh:104
IdType subId(const typename remove_const< GridImp >::type::Traits::template Codim< 0 >::Entity &e, int i, unsigned int codim) const
Get id of subentity i of co-dimension codim of a co-dimension 0 entity.
Definition: indexidset.hh:441
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
Include standard header files.
Definition: agrid.hh:59
IdSet()
Definition: indexidset.hh:448
Types types(int codim) const
Definition: indexidset.hh:310
IndexType size(const int codim) const
Return total number of entities of given codim in the entity set . This is simply a sum over all geom...
Definition: indexidset.hh:318
Base::IndexType IndexType
The type used for the indices.
Definition: indexidset.hh:294
Provide default implementation of method if IndexSet.
Definition: indexidset.hh:286
Different resources needed by all grid implementations.
IndexType subIndex(const Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:179
TypesImp Types
iterator range for geometry types in domain
Definition: indexidset.hh:93
bool contains(const Entity &e) const
Return true if the given entity is contained in .
Definition: indexidset.hh:256
IndexSet()
Definition: indexidset.hh:263
IndexType index(const Entity &e) const
Map entity to index. Easier to use than the above because codimension template parameter need not be ...
Definition: indexidset.hh:131
Id Set Interface.
Definition: common/grid.hh:362
IdType id(const Entity &e) const
Get id of an entity. This method is simpler to use than the one below.
Definition: indexidset.hh:421
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:96
Index Set Interface base class.
Definition: common/grid.hh:361
IndexType size(int codim) const
Return total number of entities of given codim in the entity set . This is simply a sum over all geom...
Definition: indexidset.hh:244
IdType id(const typename remove_const< GridImp >::type::Traits::template Codim< cc >::Entity &e) const
Get id of an entity of codim cc. Unhandy because template parameter must be supplied explicitely...
Definition: indexidset.hh:433
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:90
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:299
Base::Types Types
Definition: indexidset.hh:296
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:153
Types types(int codim) const
obtain all geometry types of entities in domain
Definition: indexidset.hh:208
Traits::template Codim< cc >::Entity Entity
Definition: indexidset.hh:86
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:417
const std::vector< GeometryType > & geomTypes(int codim) const
Return vector with all geometry types of entities in domain of index map. Return a vector with all ge...
Definition: indexidset.hh:221
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:232
Wrapper class for entities.
Definition: common/entity.hh:61
Export the type of the entity used as parameter in the index(...) method.
Definition: indexidset.hh:84