dune-grid-dev-howto  2.2.0
identitygridindexsets.hh
Go to the documentation of this file.
1 #ifndef DUNE_IDENTITYGRID_INDEXSETS_HH
2 #define DUNE_IDENTITYGRID_INDEXSETS_HH
3 
8 #include <dune/grid/common/indexidset.hh>
9 
10 #include <vector>
11 
12 namespace Dune {
13 
15 template<class GridImp>
17  public IndexSet<GridImp,IdentityGridLevelIndexSet<GridImp> >
18 {
19  public:
20 
21  typedef typename remove_const<GridImp>::type::HostGridType HostGrid;
22 
23  enum {dim = GridImp::dimension};
24 
26  template<int codim>
27  int index (const typename GridImp::Traits::template Codim<codim>::Entity& e) const
28  {
29  return grid_->hostgrid_->levelIndexSet(level_).template index<codim>(*grid_->template getHostEntityPointer<codim>(e));
30  }
31 
32 
34  template<int cc>
35  int subIndex (const typename GridImp::Traits::template Codim<cc>::Entity& e, int i, int codim) const
36  {
37  return grid_->hostgrid_->levelIndexSet(level_).subIndex(*grid_->template getHostEntityPointer<cc>(e), i, codim);
38  }
39 
40 
42  int size (int codim) const {
43  return grid_->hostgrid_->levelIndexSet(level_).size(codim);
44  }
45 
46 
48  int size (GeometryType type) const
49  {
50  return grid_->hostgrid_->levelIndexSet(level_).size(type);
51  }
52 
53 
55  const std::vector<GeometryType>& geomTypes (int codim) const
56  {
57  return grid_->hostgrid_->levelIndexSet(level_).geomTypes(codim);
58  }
59 
61  template<class EntityType>
62  bool contains (const EntityType& e) const
63  {
64  return grid_->hostgrid_->levelIndexSet(level_).contains(*grid_->template getHostEntityPointer<EntityType::codimension>(e));
65  }
66 
68  void update(const GridImp& grid, int level)
69  {
70  grid_ = &grid;
71  level_ = level;
72  }
73 
74 
75  GridImp* grid_;
76 
77  int level_;
78 };
79 
80 
81 template<class GridImp>
83  public IndexSet<GridImp,IdentityGridLeafIndexSet<GridImp> >
84 {
85  typedef typename remove_const<GridImp>::type::HostGridType HostGrid;
86 
87 public:
88 
89 
90  /*
91  * We use the remove_const to extract the Type from the mutable class,
92  * because the const class is not instantiated yet.
93  */
94  enum {dim = remove_const<GridImp>::type::dimension};
95 
96 
98  IdentityGridLeafIndexSet (const GridImp& grid)
99  : grid_(&grid)
100  {}
101 
102 
104  /*
105  We use the RemoveConst to extract the Type from the mutable class,
106  because the const class is not instantiated yet.
107  */
108  template<int codim>
109  int index (const typename remove_const<GridImp>::type::template Codim<codim>::Entity& e) const
110  {
111  return grid_->hostgrid_->leafIndexSet().template index<codim>(*grid_->template getHostEntityPointer<codim>(e));
112  }
113 
114 
116  /*
117  We use the RemoveConst to extract the Type from the mutable class,
118  because the const class is not instantiated yet.
119  */
120  template<int cc>
121  int subIndex (const typename remove_const<GridImp>::type::Traits::template Codim<cc>::Entity& e, int i, int codim) const
122  {
123  return grid_->hostgrid_->leafIndexSet().subIndex(*grid_->template getHostEntityPointer<cc>(e),i, codim);
124  }
125 
126 
128  int size (GeometryType type) const
129  {
130  return grid_->hostgrid_->leafIndexSet().size(type);
131  }
132 
133 
135  int size (int codim) const
136  {
137  return grid_->hostgrid_->leafIndexSet().size(codim);
138  }
139 
140 
142  const std::vector<GeometryType>& geomTypes (int codim) const
143  {
144  return grid_->hostgrid_->leafIndexSet().geomTypes(codim);
145  }
146 
148  template<class EntityType>
149  bool contains (const EntityType& e) const
150  {
151  return grid_->hostgrid_->leafIndexSet().contains(*grid_->template getHostEntityPointer<EntityType::codimension>(e));
152  }
153 
154 
155 
157  void update(const GridImp& grid)
158  {
159  grid_ = &grid;
160  }
161 
162 
163  GridImp* grid_;
164 };
165 
166 
167 
168 
169 template <class GridImp>
171  public IdSet<GridImp,IdentityGridGlobalIdSet<GridImp>,
172  typename remove_const<GridImp>::type::HostGridType::Traits::GlobalIdSet::IdType>
173 {
174 
175  typedef typename remove_const<GridImp>::type::HostGridType HostGrid;
176 
177 
178  public:
180  IdentityGridGlobalIdSet (const GridImp& g) : grid_(&g) {}
181 
183  typedef typename HostGrid::Traits::GlobalIdSet::IdType IdType;
184 
185 
187  /*
188  We use the remove_const to extract the Type from the mutable class,
189  because the const class is not instantiated yet.
190  */
191  template<int cd>
192  IdType id (const typename remove_const<GridImp>::type::Traits::template Codim<cd>::Entity& e) const
193  {
194  // Return id of the host entity
195  return grid_->hostgrid_->globalIdSet().id(*grid_->getRealImplementation(e).hostEntity_);
196  }
197 
198 
200  /*
201  We use the remove_const to extract the Type from the mutable class,
202  because the const class is not instantiated yet.
203  */
204  IdType subId (const typename remove_const<GridImp>::type::Traits::template Codim<0>::Entity& e, int i, int codim) const
205  {
206  // Return sub id of the host entity
207  return grid_->hostgrid_->globalIdSet().subId(*grid_->getRealImplementation(e).hostEntity_,i, codim);
208  }
209 
210 
212  void update() {}
213 
214 
215  const GridImp* grid_;
216 };
217 
218 
219 
220 
221 template<class GridImp>
223  public IdSet<GridImp,IdentityGridLocalIdSet<GridImp>,
224  typename remove_const<GridImp>::type::HostGridType::Traits::LocalIdSet::IdType>
225 {
226  private:
227 
228  typedef typename remove_const<GridImp>::type::HostGridType HostGrid;
229 
230 
231  public:
233  typedef typename HostGrid::Traits::LocalIdSet::IdType IdType;
234 
235 
237  IdentityGridLocalIdSet (const GridImp& g) : grid_(&g) {}
238 
239 
241  /*
242  We use the remove_const to extract the Type from the mutable class,
243  because the const class is not instantiated yet.
244  */
245  template<int cd>
246  IdType id (const typename remove_const<GridImp>::type::Traits::template Codim<cd>::Entity& e) const
247  {
248  // Return id of the host entity
249  return grid_->hostgrid_->localIdSet().id(*grid_->getRealImplementation(e).hostEntity_);
250  }
251 
252 
254  /*
255  * We use the remove_const to extract the Type from the mutable class,
256  * because the const class is not instantiated yet.
257  */
258  IdType subId (const typename remove_const<GridImp>::type::template Codim<0>::Entity& e, int i, int codim) const
259  {
260  // Return sub id of the host entity
261  return grid_->hostgrid_->localIdSet().subId(*grid_->getRealImplementation(e).hostEntity_,i,codim);
262  }
263 
264 
266  void update() {}
267 
268 
269  const GridImp* grid_;
270 };
271 
272 
273 } // namespace Dune
274 
275 
276 #endif