dune-grid  3.0-git
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 std::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 = std::remove_const< GridImp >::type::dimension;
97 
98  //===========================================================
102  //===========================================================
103 
110  template<int cc>
111  IndexType index (const typename Traits::template Codim<cc>::Entity& e) const
112  {
113  CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
114  return asImp().template index<cc>(e);
115  }
116 
126  template<class Entity>
127  IndexType index (const Entity& e) const
128  {
129  enum { cc = Entity::codimension };
130  CHECK_INTERFACE_IMPLEMENTATION((asImp().template index<cc>(e)));
131  return asImp().template index<cc>(e);
132  }
133 
148  template< int cc >
149  IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &e,
150  int i, unsigned int codim ) const
151  {
152  CHECK_INTERFACE_IMPLEMENTATION((asImp().template subIndex< cc >(e,i,codim)));
153  return asImp().template subIndex< cc >(e,i,codim);
154  }
155 
174  template< class Entity >
175  IndexType subIndex ( const Entity &e, int i, unsigned int codim ) const
176  {
177  static const int cc = Entity::codimension;
178  return asImp().template subIndex< cc >( e, i, codim );
179  }
181 
182 
183  //===========================================================
187  //===========================================================
188 
204  Types types ( int codim ) const
205  {
206  CHECK_INTERFACE_IMPLEMENTATION( (asImp().types( codim )) );
207  return asImp().types( codim );
208  }
209 
216  {
217  CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
218  return asImp().size(type);
219  }
220 
227  IndexType size (int codim) const
228  {
229  CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
230  return asImp().size(codim);
231  }
232 
238  template<class Entity>
239  bool contains (const Entity& e) const
240  {
241  CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
242  return asImp().contains(e);
243  }
244 
245  // Must be explicitly defined although this class should get a default constructor.
246  IndexSet() {}
247 
248  private:
250  IndexSet(const IndexSet&);
252  IndexSet& operator=(const IndexSet&);
253 
255  IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
257  const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
258  };
259 
260 #undef CHECK_INTERFACE_IMPLEMENTATION
261 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
262 
263 
264 
268  template<class GridImp, class IndexSetImp>
270  : public IndexSet< GridImp, IndexSetImp >
271  {
273  typedef typename std::remove_const< GridImp >::type::Traits Traits;
274 
275  public:
277  typedef typename Base::IndexType IndexType;
278 
279  typedef typename Base::Types Types;
280 
282  static const int dimension = Base::dimension;
283 
284  using Base::index;
285  using Base::subIndex;
286 
287  //===========================================================
291  //===========================================================
292 
293  Types types ( int codim ) const { return asImp().geomTypes( codim ); }
294 
301  IndexType size ( const int codim ) const
302  {
303  IndexType s( 0 );
304  const std::vector< GeometryType > &geomTs = asImp().geomTypes( codim );
305  typedef typename std::vector< GeometryType >::const_iterator Iterator;
306  const Iterator end = geomTs.end();
307  for( Iterator it = geomTs.begin(); it != end; ++it )
308  s += Base::size( *it );
309  return s;
310  }
312 
313  private:
314  IndexSetImp &asImp () { return static_cast< IndexSetImp & >( *this );}
315  const IndexSetImp &asImp () const { return static_cast< const IndexSetImp & >( *this ); }
316  };
317 
318 
395  template<class GridImp, class IdSetImp, class IdTypeImp>
396  class IdSet
397  {
398  public:
400  typedef IdTypeImp IdType;
401 
403  template<class Entity>
404  IdType id (const Entity& e) const
405  {
406  enum { cc = Entity::codimension };
407  return asImp().template id<cc>(e);
408  }
409 
411  /*
412  We use the remove_const to extract the Type from the mutable class,
413  because the const class is not instantiated yet.
414  */
415  template<int cc>
416  IdType id (const typename std::remove_const<GridImp>::type::
417  Traits::template Codim<cc>::Entity& e) const
418  {
419  return asImp().template id<cc>(e);
420  }
421 
424  IdType subId (const typename std::remove_const<GridImp>::type::
425  Traits::template Codim<0>::Entity& e, int i, unsigned int codim) const
426  {
427  return asImp().subId(e,i,codim);
428  }
429 
430  // Default constructor (is not provided automatically because copy constructor is private)
431  IdSet() {}
432 
433  private:
435  IdSet(const IdSet&);
437  IdSet& operator=(const IdSet&);
438 
440  IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
442  const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
443  };
444 
445 }
446 
447 #endif // DUNE_GRID_COMMON_INDEXIDSET_HH
grid.hh
Different resources needed by all grid implementations.
Dune::IndexSetDefaultImplementation::IndexType
Base::IndexType IndexType
The type used for the indices.
Definition: indexidset.hh:277
Dune::IdSet::id
IdType id(const typename std::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:416
Dune
Include standard header files.
Definition: agrid.hh:59
Dune::IndexSet::Codim::Entity
Traits ::template Codim< cc >::Entity Entity
Definition: indexidset.hh:86
Dune::Entity::codimension
Know your own codimension.
Definition: common/entity.hh:104
Dune::VTK::GeometryType
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
Dune::IndexSet::subIndex
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:149
Dune::Entity
Wrapper class for entities.
Definition: common/entity.hh:61
Dune::IdSet::IdType
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:400
Dune::IndexSetDefaultImplementation::Types
Base::Types Types
Definition: indexidset.hh:279
Dune::IdSet
Id Set Interface.
Definition: common/grid.hh:347
Dune::IdSet::subId
IdType subId(const typename std::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:424
Dune::IndexSet::size
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:215
Dune::IdSet::IdSet
IdSet()
Definition: indexidset.hh:431
Dune::IndexSet::Codim
Export the type of the entity used as parameter in the index(...) method.
Definition: indexidset.hh:84
Dune::IndexSet
Index Set Interface base class.
Definition: common/grid.hh:346
Dune::IndexSet::index
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:111
Dune::IndexSet::Types
TypesImp Types
iterator range for geometry types in domain
Definition: indexidset.hh:93
Dune::IndexSet::dimension
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:96
Dune::IdSet::id
IdType id(const Entity &e) const
Get id of an entity. This method is simpler to use than the one below.
Definition: indexidset.hh:404
Dune::IndexSet::index
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:127
Dune::IndexSetDefaultImplementation::size
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:301
Dune::IndexSet::contains
bool contains(const Entity &e) const
Return true if the given entity is contained in .
Definition: indexidset.hh:239
Dune::IndexSet::types
Types types(int codim) const
obtain all geometry types of entities in domain
Definition: indexidset.hh:204
Dune::IndexSetDefaultImplementation::types
Types types(int codim) const
Definition: indexidset.hh:293
Dune::IndexSetDefaultImplementation::dimension
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:282
Dune::IndexSet::IndexSet
IndexSet()
Definition: indexidset.hh:246
Dune::IndexSet::size
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:227
Dune::IndexSetDefaultImplementation
Provide default implementation of method if IndexSet.
Definition: indexidset.hh:269
Dune::IndexSet::IndexType
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:90