Dune Core Modules (2.4.2)

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>
10 
11 
17 namespace Dune
18 {
19 
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
Provides check for implementation of interface methods when using static polymorphism,...
Wrapper class for entities.
Definition: entity.hh:62
@ codimension
Know your own codimension.
Definition: entity.hh:104
Id Set Interface.
Definition: indexidset.hh:414
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
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:417
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
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
Provide default implementation of method if IndexSet.
Definition: indexidset.hh:288
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
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:299
Index Set Interface base class.
Definition: indexidset.hh:76
IndexType subIndex(const Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:179
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:96
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
TypesImp Types
iterator range for geometry types in domain
Definition: indexidset.hh:93
Types types(int codim) const
obtain all geometry types of entities in domain
Definition: indexidset.hh:208
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
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:90
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
Different resources needed by all grid implementations.
A few common exception classes.
#define DUNE_DEPRECATED_MSG(text)
Mark some entity as deprecated.
Definition: deprecated.hh:169
Dune namespace.
Definition: alignment.hh:10
Static tag representing a codimension.
Definition: dimension.hh:22
Export the type of the entity used as parameter in the index(...) method.
Definition: indexidset.hh:85
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)