dune-grid-dev-howto  2.3beta2
identitygridindexsets.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_IDENTITYGRID_INDEXSETS_HH
4 #define DUNE_IDENTITYGRID_INDEXSETS_HH
5 
10 #include <dune/grid/common/indexidset.hh>
11 
12 #include <vector>
13 
14 namespace Dune {
15 
17  template<class GridImp>
19  public IndexSet<GridImp,IdentityGridLevelIndexSet<GridImp> >
20  {
21  public:
22 
23  typedef typename remove_const<GridImp>::type::HostGridType HostGrid;
24 
25  enum {dim = GridImp::dimension};
26 
28  template<int codim>
29  int index (const typename GridImp::Traits::template Codim<codim>::Entity& e) const
30  {
31  return grid_->hostgrid_->levelIndexSet(level_).template index<codim>(*grid_->template getHostEntityPointer<codim>(e));
32  }
33 
34 
36  template<int cc>
37  int subIndex (const typename GridImp::Traits::template Codim<cc>::Entity& e, int i, int codim) const
38  {
39  return grid_->hostgrid_->levelIndexSet(level_).subIndex(*grid_->template getHostEntityPointer<cc>(e), i, codim);
40  }
41 
42 
44  int size (int codim) const {
45  return grid_->hostgrid_->levelIndexSet(level_).size(codim);
46  }
47 
48 
50  int size (GeometryType type) const
51  {
52  return grid_->hostgrid_->levelIndexSet(level_).size(type);
53  }
54 
55 
57  const std::vector<GeometryType>& geomTypes (int codim) const
58  {
59  return grid_->hostgrid_->levelIndexSet(level_).geomTypes(codim);
60  }
61 
63  template<class EntityType>
64  bool contains (const EntityType& e) const
65  {
66  return grid_->hostgrid_->levelIndexSet(level_).contains(*grid_->template getHostEntityPointer<EntityType::codimension>(e));
67  }
68 
70  void update(const GridImp& grid, int level)
71  {
72  grid_ = &grid;
73  level_ = level;
74  }
75 
76 
77  GridImp* grid_;
78 
79  int level_;
80  };
81 
82 
83  template<class GridImp>
85  public IndexSet<GridImp,IdentityGridLeafIndexSet<GridImp> >
86  {
87  typedef typename remove_const<GridImp>::type::HostGridType HostGrid;
88 
89  public:
90 
91 
92  /*
93  * We use the remove_const to extract the Type from the mutable class,
94  * because the const class is not instantiated yet.
95  */
96  enum {dim = remove_const<GridImp>::type::dimension};
97 
98 
100  IdentityGridLeafIndexSet (const GridImp& grid)
101  : grid_(&grid)
102  {}
103 
104 
106  /*
107  We use the RemoveConst to extract the Type from the mutable class,
108  because the const class is not instantiated yet.
109  */
110  template<int codim>
111  int index (const typename remove_const<GridImp>::type::template Codim<codim>::Entity& e) const
112  {
113  return grid_->hostgrid_->leafIndexSet().template index<codim>(*grid_->template getHostEntityPointer<codim>(e));
114  }
115 
116 
118  /*
119  We use the RemoveConst to extract the Type from the mutable class,
120  because the const class is not instantiated yet.
121  */
122  template<int cc>
123  int subIndex (const typename remove_const<GridImp>::type::Traits::template Codim<cc>::Entity& e, int i, int codim) const
124  {
125  return grid_->hostgrid_->leafIndexSet().subIndex(*grid_->template getHostEntityPointer<cc>(e),i, codim);
126  }
127 
128 
130  int size (GeometryType type) const
131  {
132  return grid_->hostgrid_->leafIndexSet().size(type);
133  }
134 
135 
137  int size (int codim) const
138  {
139  return grid_->hostgrid_->leafIndexSet().size(codim);
140  }
141 
142 
144  const std::vector<GeometryType>& geomTypes (int codim) const
145  {
146  return grid_->hostgrid_->leafIndexSet().geomTypes(codim);
147  }
148 
150  template<class EntityType>
151  bool contains (const EntityType& e) const
152  {
153  return grid_->hostgrid_->leafIndexSet().contains(*grid_->template getHostEntityPointer<EntityType::codimension>(e));
154  }
155 
156 
157 
159  void update(const GridImp& grid)
160  {
161  grid_ = &grid;
162  }
163 
164 
165  GridImp* grid_;
166  };
167 
168 
169 
170 
171  template <class GridImp>
173  public IdSet<GridImp,IdentityGridGlobalIdSet<GridImp>,
174  typename remove_const<GridImp>::type::HostGridType::Traits::GlobalIdSet::IdType>
175  {
176 
177  typedef typename remove_const<GridImp>::type::HostGridType HostGrid;
178 
179 
180  public:
182  IdentityGridGlobalIdSet (const GridImp& g) : grid_(&g) {}
183 
185  typedef typename HostGrid::Traits::GlobalIdSet::IdType IdType;
186 
187 
189  /*
190  We use the remove_const to extract the Type from the mutable class,
191  because the const class is not instantiated yet.
192  */
193  template<int cd>
194  IdType id (const typename remove_const<GridImp>::type::Traits::template Codim<cd>::Entity& e) const
195  {
196  // Return id of the host entity
197  return grid_->hostgrid_->globalIdSet().id(*grid_->getRealImplementation(e).hostEntity_);
198  }
199 
200 
202  /*
203  We use the remove_const to extract the Type from the mutable class,
204  because the const class is not instantiated yet.
205  */
206  IdType subId (const typename remove_const<GridImp>::type::Traits::template Codim<0>::Entity& e, int i, int codim) const
207  {
208  // Return sub id of the host entity
209  return grid_->hostgrid_->globalIdSet().subId(*grid_->getRealImplementation(e).hostEntity_,i, codim);
210  }
211 
212 
214  void update() {}
215 
216 
217  const GridImp* grid_;
218  };
219 
220 
221 
222 
223  template<class GridImp>
225  public IdSet<GridImp,IdentityGridLocalIdSet<GridImp>,
226  typename remove_const<GridImp>::type::HostGridType::Traits::LocalIdSet::IdType>
227  {
228  private:
229 
230  typedef typename remove_const<GridImp>::type::HostGridType HostGrid;
231 
232 
233  public:
235  typedef typename HostGrid::Traits::LocalIdSet::IdType IdType;
236 
237 
239  IdentityGridLocalIdSet (const GridImp& g) : grid_(&g) {}
240 
241 
243  /*
244  We use the remove_const to extract the Type from the mutable class,
245  because the const class is not instantiated yet.
246  */
247  template<int cd>
248  IdType id (const typename remove_const<GridImp>::type::Traits::template Codim<cd>::Entity& e) const
249  {
250  // Return id of the host entity
251  return grid_->hostgrid_->localIdSet().id(*grid_->getRealImplementation(e).hostEntity_);
252  }
253 
254 
256  /*
257  * We use the remove_const to extract the Type from the mutable class,
258  * because the const class is not instantiated yet.
259  */
260  IdType subId (const typename remove_const<GridImp>::type::template Codim<0>::Entity& e, int i, int codim) const
261  {
262  // Return sub id of the host entity
263  return grid_->hostgrid_->localIdSet().subId(*grid_->getRealImplementation(e).hostEntity_,i,codim);
264  }
265 
266 
268  void update() {}
269 
270 
271  const GridImp* grid_;
272  };
273 
274 
275 } // namespace Dune
276 
277 
278 #endif