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