Dune Core Modules (2.6.0)

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 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 
150  template< int cc >
151  IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &e,
152  int i, unsigned int codim ) const
153  {
154  CHECK_INTERFACE_IMPLEMENTATION((asImp().template subIndex< cc >(e,i,codim)));
155  return asImp().template subIndex< cc >(e,i,codim);
156  }
157 
179  template< class Entity >
180  IndexType subIndex ( const Entity &e, int i, unsigned int codim ) const
181  {
182  static const int cc = Entity::codimension;
183  return asImp().template subIndex< cc >( e, i, codim );
184  }
186 
187 
188  //===========================================================
192  //===========================================================
193 
209  Types types ( int codim ) const
210  {
211  CHECK_INTERFACE_IMPLEMENTATION( (asImp().types( codim )) );
212  return asImp().types( codim );
213  }
214 
221  {
222  CHECK_INTERFACE_IMPLEMENTATION((asImp().size(type)));
223  return asImp().size(type);
224  }
225 
232  IndexType size (int codim) const
233  {
234  CHECK_INTERFACE_IMPLEMENTATION((asImp().size(codim)));
235  return asImp().size(codim);
236  }
237 
243  template<class Entity>
244  bool contains (const Entity& e) const
245  {
246  CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(e)));
247  return asImp().contains(e);
248  }
249 
250  protected:
251  // Must be explicitly defined although this class should get a default constructor.
252  IndexSet() = default;
253 
254  private:
256  IndexSet(const IndexSet&) = delete;
258  IndexSet& operator=(const IndexSet&) = delete;
259 
261  IndexSetImp& asImp () {return static_cast<IndexSetImp &> (*this);}
263  const IndexSetImp& asImp () const {return static_cast<const IndexSetImp &>(*this);}
264  };
265 
266 #undef CHECK_INTERFACE_IMPLEMENTATION
267 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
268 
269 
270 
274  template<class GridImp, class IndexSetImp>
276  : public IndexSet< GridImp, IndexSetImp >
277  {
279  typedef typename std::remove_const< GridImp >::type::Traits Traits;
280 
281  public:
283  typedef typename Base::IndexType IndexType;
284 
285  typedef typename Base::Types Types;
286 
288  static const int dimension = Base::dimension;
289 
290  using Base::index;
291  using Base::subIndex;
292 
293  //===========================================================
297  //===========================================================
298 
299  Types types ( int codim ) const { return asImp().geomTypes( codim ); }
300 
307  IndexType size ( const int codim ) const
308  {
309  IndexType s( 0 );
310  const std::vector< GeometryType > &geomTs = asImp().geomTypes( codim );
311  typedef typename std::vector< GeometryType >::const_iterator Iterator;
312  const Iterator end = geomTs.end();
313  for( Iterator it = geomTs.begin(); it != end; ++it )
314  s += Base::size( *it );
315  return s;
316  }
318 
319  private:
320  IndexSetImp &asImp () { return static_cast< IndexSetImp & >( *this );}
321  const IndexSetImp &asImp () const { return static_cast< const IndexSetImp & >( *this ); }
322  };
323 
324 
439  template<class GridImp, class IdSetImp, class IdTypeImp>
440  class IdSet
441  {
442  public:
444  typedef IdTypeImp IdType;
445 
447  template<class Entity>
448  IdType id (const Entity& e) const
449  {
450  enum { cc = Entity::codimension };
451  return asImp().template id<cc>(e);
452  }
453 
455  /*
456  We use the remove_const to extract the Type from the mutable class,
457  because the const class is not instantiated yet.
458  */
459  template<int cc>
460  IdType id (const typename std::remove_const<GridImp>::type::
461  Traits::template Codim<cc>::Entity& e) const
462  {
463  return asImp().template id<cc>(e);
464  }
465 
468  IdType subId (const typename std::remove_const<GridImp>::type::
469  Traits::template Codim<0>::Entity& e, int i, unsigned int codim) const
470  {
471  return asImp().subId(e,i,codim);
472  }
473 
474  protected:
475  // Default constructor (is not provided automatically because copy constructor is private)
476  IdSet() = default;
477 
478  private:
480  IdSet(const IdSet&) = delete;
482  IdSet& operator=(const IdSet&) = delete;
483 
485  IdSetImp& asImp () {return static_cast<IdSetImp &> (*this);}
487  const IdSetImp& asImp () const {return static_cast<const IdSetImp &>(*this);}
488  };
489 
490 }
491 
492 #endif // DUNE_GRID_COMMON_INDEXIDSET_HH
Provides check for implementation of interface methods when using static polymorphism,...
Wrapper class for entities.
Definition: entity.hh:64
@ codimension
Know your own codimension.
Definition: entity.hh:105
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:277
Id Set Interface.
Definition: indexidset.hh:441
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:444
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:468
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 explicitly.
Definition: indexidset.hh:460
IdType id(const Entity &e) const
Get id of an entity. This method is simpler to use than the one below.
Definition: indexidset.hh:448
Provide default implementation of method if IndexSet.
Definition: indexidset.hh:277
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:307
Base::IndexType IndexType
The type used for the indices.
Definition: indexidset.hh:283
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:288
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:180
static const int dimension
dimension of the grid (maximum allowed codimension)
Definition: indexidset.hh:96
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:232
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:151
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:209
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
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:90
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:220
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
bool contains(const Entity &e) const
Return true if the given entity is contained in .
Definition: indexidset.hh:244
Different resources needed by all grid implementations.
A few common exception classes.
Dune namespace.
Definition: alignedallocator.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 (Apr 26, 22:29, 2024)