dune-grid  2.2.0
alugrid/2d/iterator.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALU2DGRID_ITERATOR_HH
2 #define DUNE_ALU2DGRID_ITERATOR_HH
3 
4 // System includes
5 #include <stack>
6 #include <utility>
7 
8 // Dune includes
11 
12 // Local includes
13 #include "entity.hh"
14 
15 namespace Dune {
16  // Forward declarations
17  template<int cd, int dim, class GridImp>
18  class ALU2dGridEntity;
19  template<int cd, PartitionIteratorType pitype, class GridImp >
20  class ALU2dGridLevelIterator;
21  template<int cd, class GridImp >
22  class ALU2dGridEntityPointer;
23  template<int mydim, int coorddim, class GridImp>
24  class ALU2dGridGeometry;
25  template<class GridImp>
26  class ALU2dGridHierarchicIterator;
27  template<class GridImp>
28  class ALU2dGridIntersectionBase;
29  template<class GridImp>
30  class ALU2dGridLeafIntersectionIterator;
31  template<class GridImp>
32  class ALU2dGridLevelIntersectionIterator;
33  template<int codim, PartitionIteratorType pitype, class GridImp>
34  class ALU2dGridLeafIterator;
35  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
36  class ALU2dGrid;
37 
38 
39 //********************************************************************
40 // --ALU2dGridLeafIterator
41 // --LeafIterator
42 // --for codim = 0,2
43 //
44 //********************************************************************
45 
46 template<int cdim, PartitionIteratorType pitype, class GridImp>
48 : public ALU2dGridEntityPointer<cdim,GridImp>
49  // public LeafIteratorDefaultImplementation<cdim, pitype, GridImp, ALU2dGridLeafIterator>
50 {
51  static const int dim = GridImp::dimension;
52  static const int dimworld = GridImp::dimensionworld;
53  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
54  static const int codim = cdim;
55 
56  friend class ALU2dGridEntity<0,dimworld,GridImp>;
57  friend class ALU2dGridEntity<1,dimworld,GridImp>;
58  friend class ALU2dGridEntity<dim,dimworld,GridImp>;
59  friend class ALU2dGrid< dim, dimworld, eltype >;
60 
63 
65 
66  typedef typename GridImp :: ALU2dGridLeafMarkerVectorType LeafMarkerVectorType;
67 
68  // default impl for elements
69  template <class ElementImp, class MarkerVectorImp, int codim>
70  struct GetLevel
71  {
72  // return level of element
73  static int level(const ElementImp & elem, const MarkerVectorImp& marker)
74  {
75  return elem.level();
76  }
77  };
78 
79  // specialization for vertices
80  template <class ElementImp, class MarkerVectorImp>
81  struct GetLevel<ElementImp,MarkerVectorImp,2>
82  {
83  // return level of leaf vertex
84  static int level(const ElementImp & elem, const MarkerVectorImp& marker)
85  {
86  return marker.levelOfVertex(elem.getIndex());
87  }
88  };
89 
90  public:
91  typedef typename GridImp :: GridObjectFactoryType FactoryType;
92 
94  typedef typename GridImp::template Codim<cdim>::Entity Entity;
96 
98  ALU2dGridLeafIterator(const FactoryType& factory, bool end);
99 
101  ALU2dGridLeafIterator(const ThisType & org);
102 
104  void increment ();
105 
107  ThisType & operator = (const ThisType & org);
108 
109 private:
111  bool endIter_;
113  int level_;
114  ElementType * elem_;
115  typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
116  // Listwalkptr, behaves like a proxy for Leafwalk and Levelwalk Ptrs
117  IteratorType iter_;
118 
119  // for the codim 2 case
120  LeafMarkerVectorType & marker_;
121 }; // end ALU2dGridLeafIterator
122 
123 
124 //********************************************************************
125 // --ALU2dGridLeafIterator
126 // --LeafIterator
127 // --specialized for codim = 1
128 //
129 //********************************************************************
130 
131 template<PartitionIteratorType pitype, class GridImp>
132 class ALU2dGridLeafIterator<1,pitype,GridImp>
133 : public ALU2dGridEntityPointer<1,GridImp>
134  // public LeafIteratorDefaultImplementation<1, pitype, GridImp, ALU2dGridLeafIterator>
135 {
136  static const int dim = GridImp::dimension;
137  static const int dimworld = GridImp::dimensionworld;
138  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
139  static const int codim = 1;
140 
141  friend class ALU2dGridEntity<0,dimworld,GridImp>;
142  friend class ALU2dGridEntity<1,dimworld,GridImp>;
143  friend class ALU2dGridEntity<dim,dimworld,GridImp>;
144  friend class ALU2dGrid< dim, dimworld, eltype >;
145 
148 
150 
151  typedef typename GridImp :: ALU2dGridLeafMarkerVectorType LeafMarkerVectorType;
152 
153  public:
154  typedef typename GridImp :: GridObjectFactoryType FactoryType;
155 
157  typedef typename GridImp::template Codim<1>::Entity Entity;
159 
161  ALU2dGridLeafIterator(const FactoryType& factory, bool end);
162 
164  ALU2dGridLeafIterator(const ThisType & org);
165 
167  void increment ();
168 
170  ThisType & operator = (const ThisType & org);
171 
172 private:
173  int goNextElement();
174 
176  bool endIter_;
178  int level_;
180  int face_;
181 
183  ElementType * elem_;
184 
185  typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
186 
187  // Listwalkptr, behaves like a proxy for Leafwalk and Levelwalk Ptrs
188  IteratorType iter_;
189 
190  // for the codim 1 case
191  LeafMarkerVectorType & marker_;
192 
193 }; // end ALU2dGridLeafIterator
194 
195 //**********************************************************************
196 //
197 // --ALU2dGridLevelIterator
198 // --LevelIterator, specialized for cd=0
199 //**********************************************************************
200 
201 template<PartitionIteratorType pitype, class GridImp>
202 class ALU2dGridLevelIterator<0, pitype, GridImp>
203 : public ALU2dGridEntityPointer<0,GridImp>
204  // public LevelIteratorDefaultImplementation <0, pitype, GridImp, ALU2dGridLevelIterator>
205 {
206  static const int dim = GridImp::dimension;
207  static const int dimworld = GridImp::dimensionworld;
208  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
209  static const int codim = 0;
210 
211  friend class ALU2dGridEntity<dim,dimworld,GridImp>;
212  friend class ALU2dGridEntity<1,dimworld,GridImp>;
213  friend class ALU2dGridEntity<0,dimworld,GridImp>;
214  friend class ALU2dGrid< dim, dimworld, eltype >;
215 
218 
219  typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType;
221 
222 public:
223  typedef typename GridImp :: GridObjectFactoryType FactoryType;
224 
225  typedef typename GridImp::template Codim<codim>::Entity Entity;
226 
228  ALU2dGridLevelIterator(const FactoryType& factory, int level, bool end);
229 
231  ALU2dGridLevelIterator(const ThisType & org);
232 
234  void increment ();
235 
237  ThisType & operator = (const ThisType & org);
238 
239 private:
241  bool endIter_;
243  int level_;
244 
246  HElementType * item_;
247 
250  typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
251  IteratorType iter_;
252 
253 };
254 
255 //**********************************************************************
256 //
257 // --ALU2dGridLevelIterator
258 // --LevelIterator, specialized for cd=1
259 //**********************************************************************
260 
261 template<PartitionIteratorType pitype, class GridImp>
262 class ALU2dGridLevelIterator<1, pitype, GridImp>
263 : public ALU2dGridEntityPointer<1,GridImp>
264  // public LevelIteratorDefaultImplementation <1, pitype, GridImp, ALU2dGridLevelIterator>
265 {
266  static const int dim = GridImp::dimension;
267  static const int dimworld = GridImp::dimensionworld;
268  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
269  static const int codim = 1;
270 
271  friend class ALU2dGridEntity<dim,dimworld,GridImp>;
272  friend class ALU2dGridEntity<1,dimworld,GridImp>;
273  friend class ALU2dGridEntity<0,dimworld,GridImp>;
274  friend class ALU2dGrid< dim, dimworld, eltype >;
275 
278 
279  typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType;
280 
282 public:
283  typedef typename GridImp :: GridObjectFactoryType FactoryType;
284 
285  typedef typename GridImp::template Codim<codim>::Entity Entity;
286 
288  ALU2dGridLevelIterator(const FactoryType& factroy, int level, bool end);
289 
291  ALU2dGridLevelIterator(const ThisType & org);
292 
293  ~ALU2dGridLevelIterator();
294 
296  void increment ();
297 
299  ThisType & operator = (const ThisType & org);
300 
301 private:
303  bool endIter_;
305  int level_;
307  int myFace_;
308 
309  // current item
310  HElementType * item_;
313  ElementType * elem_;
314  // Listwalkptr is a proxy for iterator pointers
315  typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
316 
317  IteratorType iter_;
318 
319  ALU2dGridMarkerVector * marker_;
320 
321  ALU2dGridMarkerVector & marker()
322  {
323  assert( marker_ );
324  return *marker_;
325  }
326 };
327 
328 //**********************************************************************
329 //
330 // --ALU2dGridLevelIterator
331 // --LevelIterator, specialized for cd=2
332 //**********************************************************************
333 
334 template<PartitionIteratorType pitype, class GridImp>
335 class ALU2dGridLevelIterator<2, pitype, GridImp>
336 : public ALU2dGridEntityPointer<2,GridImp>
337  // public LevelIteratorDefaultImplementation <2, pitype, GridImp, ALU2dGridLevelIterator>
338 {
339  static const int dim = GridImp::dimension;
340  static const int dimworld = GridImp::dimensionworld;
341  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
342  static const int codim = 2;
343 
344  friend class ALU2dGridEntity<dim,dimworld,GridImp>;
345  friend class ALU2dGridEntity<1,dimworld,GridImp>;
346  friend class ALU2dGridEntity<0,dimworld,GridImp>;
347  friend class ALU2dGrid< dim, dimworld, eltype >;
348 
351 
352  typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType ;
354 
355 public:
356  typedef typename GridImp :: GridObjectFactoryType FactoryType;
357 
358  typedef typename GridImp::template Codim<codim>::Entity Entity;
359 
361  ALU2dGridLevelIterator(const FactoryType& factory, int level, bool end);
362 
364  ALU2dGridLevelIterator(const ThisType & org);
365 
366  ~ALU2dGridLevelIterator();
367 
369  void increment ();
370 
372  ThisType & operator = (const ThisType & org);
373 
374 private:
376  bool endIter_;
378  int level_;
380  int myFace_;
382 
386 
387  HElementType * item_;
388  VertexType * vertex_;
389 
390 
391  typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
392  IteratorType iter_;
393 
394  // marker vector to tell on which element vertex is visited
395  ALU2dGridMarkerVector * marker_;
396  ALU2dGridMarkerVector & marker()
397  {
398  assert( marker_ );
399  return *marker_;
400  }
401 };
402 
403 //***************************************************************
404 //
405 // - HierarchicIteraror
406 // --HierarchicIterator
407 //***************************************************************
408 
410 template<class GridImp>
412 : public ALU2dGridEntityPointer<0,GridImp>
413  // public HierarchicIteratorDefaultImplementation <GridImp,ALU2dGridHierarchicIterator>
414 {
416 
417  static const int dim = GridImp::dimension;
418  static const int dimworld = GridImp::dimensionworld;
419  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
420  static const int codim = 2;
421 
422  typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType ;
423 
424 public:
425  typedef typename GridImp :: GridObjectFactoryType FactoryType;
426 
428  typedef typename GridImp::template Codim<0>::Entity Entity;
430  typedef typename GridImp::ctype ctype;
433 
436  const HElementType & elem, int maxlevel, bool end=false);
437 
440 
442  void increment();
443 
446  {
448  elem_ = org.elem_;
449  maxlevel_= org.maxlevel_;
450  endIter_ = org.endIter_;
451  return *this;
452  };
453 
454 private:
455 
457  HElementType * goNextElement (HElementType * oldEl);
458 
460  const HElementType * elem_;
461 
463  int maxlevel_;
465  bool endIter_;
466 }; // end ALU2dHierarchicIterator
467 
468 } // end namespace Dune
469 
470 #include "iterator_imp.cc"
471 
472 #endif // #ifndef DUNE_ALU2DGRID_ITERATOR_HH