dune-grid  2.2.0
alugrid/2d/indexsets.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALU2DGRIDINDEXSETS_HH
2 #define DUNE_ALU2DGRIDINDEXSETS_HH
3 
4 //- System includes
5 #include <vector>
6 
7 //- Dune includes
8 #include <dune/common/stdstreams.hh>
9 #include <dune/common/bigunsignedint.hh>
10 
11 #include <dune/grid/common/grid.hh>
13 
14 
15 //- Local includes
16 #include "alu2dinclude.hh"
17 
18 namespace Dune
19 {
20 
21  // External Forward Declarations
22  // -----------------------------
23 
24  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
25  class ALU2dGrid;
26 
27  template<int cd, int dim, class GridImp>
28  class ALU2dGridEntity;
29 
30 
31 
32  // ALU2dGridHierarchicIndexSet
33  // ---------------------------
34 
36  template <int dim, int dimworld, ALU2DSPACE ElementType eltype>
38  public IndexSet< ALU2dGrid< dim, dimworld, eltype >,
39  ALU2dGridHierarchicIndexSet< dim, dimworld, eltype >, int >
40  {
42 
44  enum { numCodim = dim+1 }; // i.e. 3
45 
46  friend class ALU2dGrid< dim, dimworld, eltype >;
47 
49  : grid_( grid )
50  {}
51 
52  public:
53  typedef typename GridType::Traits::template Codim<0>::Entity EntityCodim0Type;
54 
56  template< int codim >
57  int index ( const typename GridType::Traits::template Codim< codim >::Entity &entity ) const
58  {
59  return GridType::getRealImplementation( entity ).getIndex();
60  }
61 
63  template< class Entity >
64  int index ( const Entity &entity ) const
65  {
66  return GridType::getRealImplementation( entity ).getIndex();
67  }
68 
70  int subIndex ( const EntityCodim0Type &e, int i, unsigned int codim ) const
71  {
72  return grid_.getRealImplementation( e ).subIndex( i, codim);
73  }
74 
77  int size ( GeometryType type ) const
78  {
79  const int codim = dim-type.dim();
80  assert( grid_.geomTypes(codim).size() == 1 );
81  if( type != grid_.geomTypes(codim)[0] ) return 0;
82  // return size of hierarchic index set
83  return grid_.hierSetSize(codim);
84  }
85 
87  int size ( int codim ) const
88  {
89  // return size of hierarchic index set
90  return grid_.hierSetSize(codim);
91  }
92 
94  const std::vector<GeometryType>& geomTypes (int codim) const
95  {
96  return grid_.geomTypes(codim);
97  }
98 
100  template <class EntityType>
101  bool contains (const EntityType &) const { return true; }
102 
103  private:
104  // our Grid
105  const GridType & grid_;
106  };
107 
108  //***********************************************************
109  //
110  // --LocalIdSet
111  //
112  //***********************************************************
113 
115  template <int dim, int dimworld, ALU2DSPACE ElementType eltype>
117  public IdSet < ALU2dGrid< dim, dimworld, eltype >,
118  ALU2dGridLocalIdSet< dim, dimworld, eltype >, int >
119  {
122 
123  friend class ALU2dGrid< dim, dimworld, eltype >;
124 
125  // this means that only up to 300000000 entities are allowed
126  enum { codimMultiplier = 300000000 };
127  typedef typename GridType::Traits::template Codim<0>::Entity EntityCodim0Type;
128 
129  // create local id set , only for the grid allowed
130  ALU2dGridLocalIdSet(const GridType & grid) : hset_(grid.hierarchicIndexSet())
131  {
132  for(int i=0; i<dim+1; i++)
133  codimStart_[i] = i*codimMultiplier;
134  }
135 
136  // fake method to have the same method like GlobalIdSet
137  void updateIdSet() {}
138 
139  public:
141  typedef int IdType;
142 
146 
148  template <class EntityType>
149  int id (const EntityType & ep) const
150  {
151  enum { cd = EntityType :: codimension };
152  assert( hset_.size(cd) < codimMultiplier );
153  return codimStart_[cd] + hset_.index(ep);
154  }
155 
157  template <int codim>
158  int id (const typename GridType:: template Codim<codim> :: Entity & ep) const
159  {
160  //enum { cd = EntityType :: codimension };
161  assert( hset_.size(codim) < codimMultiplier );
162  return codimStart_[codim] + hset_.index(ep);
163  }
164 
166  int subId ( const EntityCodim0Type &e, int i, unsigned int codim ) const
167  {
168  assert( hset_.size( codim ) < codimMultiplier );
169  return codimStart_[ codim ] + hset_.subIndex( e, i, codim );
170  }
171 
172  private:
173  // our HierarchicIndexSet
174  const HierarchicIndexSetType & hset_;
175 
176  // store start of each codim numbers
177  int codimStart_[dim+1];
178  };
179 
180 } // end namespace Dune
181 
182 #endif