dune-grid  2.3.1
alugrid/2d/iterator.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_ALU2DGRID_ITERATOR_HH
4 #define DUNE_ALU2DGRID_ITERATOR_HH
5 
6 // System includes
7 #include <stack>
8 #include <utility>
9 
10 // Dune includes
11 #include <dune/grid/common/grid.hh>
13 
14 // Local includes
15 #include "entity.hh"
16 
17 namespace Dune {
18  // Forward declarations
19  template<int cd, int dim, class GridImp>
20  class ALU2dGridEntity;
21  template<int cd, PartitionIteratorType pitype, class GridImp >
22  class ALU2dGridLevelIterator;
23  template<int cd, class GridImp >
24  class ALU2dGridEntityPointer;
25  template<int mydim, int coorddim, class GridImp>
26  class ALU2dGridGeometry;
27  template<class GridImp>
28  class ALU2dGridHierarchicIterator;
29  template<class GridImp>
30  class ALU2dGridIntersectionBase;
31  template<class GridImp>
32  class ALU2dGridLeafIntersectionIterator;
33  template<class GridImp>
34  class ALU2dGridLevelIntersectionIterator;
35  template<int codim, PartitionIteratorType pitype, class GridImp>
36  class ALU2dGridLeafIterator;
37  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
38  class ALU2dGrid;
39 
40 
41  //********************************************************************
42  // --ALU2dGridLeafIterator
43  // --LeafIterator
44  // --for codim = 0,2
45  //
46  //********************************************************************
47 
48  template<int cdim, PartitionIteratorType pitype, class GridImp>
49  class ALU2dGridLeafIterator
50  : public ALU2dGridEntityPointer<cdim,GridImp>
51  // public LeafIteratorDefaultImplementation<cdim, pitype, GridImp, ALU2dGridLeafIterator>
52  {
53  static const int dim = GridImp::dimension;
54  static const int dimworld = GridImp::dimensionworld;
55  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
56  static const int codim = cdim;
57 
58  friend class ALU2dGridEntity<0,dimworld,GridImp>;
59  friend class ALU2dGridEntity<1,dimworld,GridImp>;
60  friend class ALU2dGridEntity<dim,dimworld,GridImp>;
61  friend class ALU2dGrid< dim, dimworld, eltype >;
62 
65 
67 
68  typedef typename GridImp :: ALU2dGridLeafMarkerVectorType LeafMarkerVectorType;
69 
70  // default impl for elements
71  template <class ElementImp, class MarkerVectorImp, int codim>
72  struct GetLevel
73  {
74  // return level of element
75  static int level(const ElementImp & elem, const MarkerVectorImp& marker)
76  {
77  return elem.level();
78  }
79  };
80 
81  // specialization for vertices
82  template <class ElementImp, class MarkerVectorImp>
83  struct GetLevel<ElementImp,MarkerVectorImp,2>
84  {
85  // return level of leaf vertex
86  static int level(const ElementImp & elem, const MarkerVectorImp& marker)
87  {
88  return marker.levelOfVertex(elem.getIndex());
89  }
90  };
91 
92  public:
93  typedef typename GridImp :: GridObjectFactoryType FactoryType;
94 
96  typedef typename GridImp::template Codim<cdim>::Entity Entity;
98 
100  ALU2dGridLeafIterator(const FactoryType& factory, bool end);
101 
103  ALU2dGridLeafIterator(const ThisType & org);
104 
106  void increment ();
107 
109  ThisType & operator = (const ThisType & org);
110 
111  private:
113  bool endIter_;
115  int level_;
116  ElementType * elem_;
117  typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
118  // Listwalkptr, behaves like a proxy for Leafwalk and Levelwalk Ptrs
119  IteratorType iter_;
120 
121  // for the codim 2 case
122  LeafMarkerVectorType & marker_;
123  }; // end ALU2dGridLeafIterator
124 
125 
126  //********************************************************************
127  // --ALU2dGridLeafIterator
128  // --LeafIterator
129  // --specialized for codim = 1
130  //
131  //********************************************************************
132 
133  template<PartitionIteratorType pitype, class GridImp>
134  class ALU2dGridLeafIterator<1,pitype,GridImp>
135  : public ALU2dGridEntityPointer<1,GridImp>
136  // public LeafIteratorDefaultImplementation<1, pitype, GridImp, ALU2dGridLeafIterator>
137  {
138  static const int dim = GridImp::dimension;
139  static const int dimworld = GridImp::dimensionworld;
140  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
141  static const int codim = 1;
142 
143  friend class ALU2dGridEntity<0,dimworld,GridImp>;
144  friend class ALU2dGridEntity<1,dimworld,GridImp>;
145  friend class ALU2dGridEntity<dim,dimworld,GridImp>;
146  friend class ALU2dGrid< dim, dimworld, eltype >;
147 
150 
152 
153  typedef typename GridImp :: ALU2dGridLeafMarkerVectorType LeafMarkerVectorType;
154 
155  public:
156  typedef typename GridImp :: GridObjectFactoryType FactoryType;
157 
159  typedef typename GridImp::template Codim<1>::Entity Entity;
161 
163  ALU2dGridLeafIterator(const FactoryType& factory, bool end);
164 
166  ALU2dGridLeafIterator(const ThisType & org);
167 
169  void increment ();
170 
172  ThisType & operator = (const ThisType & org);
173 
174  private:
175  int goNextElement();
176 
178  bool endIter_;
180  int level_;
182  int face_;
183 
185  ElementType * elem_;
186 
187  typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
188 
189  // Listwalkptr, behaves like a proxy for Leafwalk and Levelwalk Ptrs
190  IteratorType iter_;
191 
192  // for the codim 1 case
193  LeafMarkerVectorType & marker_;
194 
195  }; // end ALU2dGridLeafIterator
196 
197  //**********************************************************************
198  //
199  // --ALU2dGridLevelIterator
200  // --LevelIterator, specialized for cd=0
201  //**********************************************************************
202 
203  template<PartitionIteratorType pitype, class GridImp>
204  class ALU2dGridLevelIterator<0, pitype, GridImp>
205  : public ALU2dGridEntityPointer<0,GridImp>
206  // public LevelIteratorDefaultImplementation <0, pitype, GridImp, ALU2dGridLevelIterator>
207  {
208  static const int dim = GridImp::dimension;
209  static const int dimworld = GridImp::dimensionworld;
210  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
211  static const int codim = 0;
212 
213  friend class ALU2dGridEntity<dim,dimworld,GridImp>;
214  friend class ALU2dGridEntity<1,dimworld,GridImp>;
215  friend class ALU2dGridEntity<0,dimworld,GridImp>;
216  friend class ALU2dGrid< dim, dimworld, eltype >;
217 
220 
221  typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType;
223 
224  public:
225  typedef typename GridImp :: GridObjectFactoryType FactoryType;
226 
227  typedef typename GridImp::template Codim<codim>::Entity Entity;
228 
230  ALU2dGridLevelIterator(const FactoryType& factory, int level, bool end);
231 
233  ALU2dGridLevelIterator(const ThisType & org);
234 
236  void increment ();
237 
239  ThisType & operator = (const ThisType & org);
240 
241  private:
243  bool endIter_;
245  int level_;
246 
248  HElementType * item_;
249 
252  typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
253  IteratorType iter_;
254 
255  };
256 
257  //**********************************************************************
258  //
259  // --ALU2dGridLevelIterator
260  // --LevelIterator, specialized for cd=1
261  //**********************************************************************
262 
263  template<PartitionIteratorType pitype, class GridImp>
264  class ALU2dGridLevelIterator<1, pitype, GridImp>
265  : public ALU2dGridEntityPointer<1,GridImp>
266  // public LevelIteratorDefaultImplementation <1, pitype, GridImp, ALU2dGridLevelIterator>
267  {
268  static const int dim = GridImp::dimension;
269  static const int dimworld = GridImp::dimensionworld;
270  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
271  static const int codim = 1;
272 
273  friend class ALU2dGridEntity<dim,dimworld,GridImp>;
274  friend class ALU2dGridEntity<1,dimworld,GridImp>;
275  friend class ALU2dGridEntity<0,dimworld,GridImp>;
276  friend class ALU2dGrid< dim, dimworld, eltype >;
277 
280 
281  typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType;
282 
284  public:
285  typedef typename GridImp :: GridObjectFactoryType FactoryType;
286 
287  typedef typename GridImp::template Codim<codim>::Entity Entity;
288 
290  ALU2dGridLevelIterator(const FactoryType& factroy, int level, bool end);
291 
293  ALU2dGridLevelIterator(const ThisType & org);
294 
296 
298  void increment ();
299 
301  ThisType & operator = (const ThisType & org);
302 
303  private:
305  bool endIter_;
307  int level_;
309  int myFace_;
310 
311  // current item
312  HElementType * item_;
315  ElementType * elem_;
316  // Listwalkptr is a proxy for iterator pointers
317  typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
318 
319  IteratorType iter_;
320 
321  ALU2dGridMarkerVector * marker_;
322 
323  ALU2dGridMarkerVector & marker()
324  {
325  assert( marker_ );
326  return *marker_;
327  }
328  };
329 
330  //**********************************************************************
331  //
332  // --ALU2dGridLevelIterator
333  // --LevelIterator, specialized for cd=2
334  //**********************************************************************
335 
336  template<PartitionIteratorType pitype, class GridImp>
337  class ALU2dGridLevelIterator<2, pitype, GridImp>
338  : public ALU2dGridEntityPointer<2,GridImp>
339  // public LevelIteratorDefaultImplementation <2, pitype, GridImp, ALU2dGridLevelIterator>
340  {
341  static const int dim = GridImp::dimension;
342  static const int dimworld = GridImp::dimensionworld;
343  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
344  static const int codim = 2;
345 
346  friend class ALU2dGridEntity<dim,dimworld,GridImp>;
347  friend class ALU2dGridEntity<1,dimworld,GridImp>;
348  friend class ALU2dGridEntity<0,dimworld,GridImp>;
349  friend class ALU2dGrid< dim, dimworld, eltype >;
350 
353 
354  typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType ;
356 
357  public:
358  typedef typename GridImp :: GridObjectFactoryType FactoryType;
359 
360  typedef typename GridImp::template Codim<codim>::Entity Entity;
361 
363  ALU2dGridLevelIterator(const FactoryType& factory, int level, bool end);
364 
366  ALU2dGridLevelIterator(const ThisType & org);
367 
369 
371  void increment ();
372 
374  ThisType & operator = (const ThisType & org);
375 
376  private:
378  bool endIter_;
380  int level_;
382  int myFace_;
384 
388 
389  HElementType * item_;
390  VertexType * vertex_;
391 
392 
393  typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
394  IteratorType iter_;
395 
396  // marker vector to tell on which element vertex is visited
397  ALU2dGridMarkerVector * marker_;
398  ALU2dGridMarkerVector & marker()
399  {
400  assert( marker_ );
401  return *marker_;
402  }
403  };
404 
405  //***************************************************************
406  //
407  // - HierarchicIteraror
408  // --HierarchicIterator
409  //***************************************************************
410 
412  template<class GridImp>
413  class ALU2dGridHierarchicIterator
414  : public ALU2dGridEntityPointer<0,GridImp>
415  // public HierarchicIteratorDefaultImplementation <GridImp,ALU2dGridHierarchicIterator>
416  {
417  typedef ALU2dGridHierarchicIterator<GridImp> ThisType;
418 
419  static const int dim = GridImp::dimension;
420  static const int dimworld = GridImp::dimensionworld;
421  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
422  static const int codim = 2;
423 
424  typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType ;
425 
426  public:
427  typedef typename GridImp :: GridObjectFactoryType FactoryType;
428 
430  typedef typename GridImp::template Codim<0>::Entity Entity;
432  typedef typename GridImp::ctype ctype;
435 
438  const HElementType & elem, int maxlevel, bool end=false);
439 
442 
444  void increment();
445 
448  {
450  elem_ = org.elem_;
451  maxlevel_= org.maxlevel_;
452  endIter_ = org.endIter_;
453  return *this;
454  }
455 
456  private:
457 
459  HElementType * goNextElement (HElementType * oldEl);
460 
462  const HElementType * elem_;
463 
465  int maxlevel_;
467  bool endIter_;
468  }; // end ALU2dHierarchicIterator
469 
470 } // end namespace Dune
471 
472 #include "iterator_imp.cc"
473 
474 #endif // #ifndef DUNE_ALU2DGRID_ITERATOR_HH
GridImp::GridObjectFactoryType FactoryType
Definition: alugrid/2d/iterator.hh:225
Definition: alugrid/2d/entity.hh:22
GridImp::template Codim< cdim >::Entity Entity
type of entity we iterate (interface)
Definition: alugrid/2d/iterator.hh:96
ThisType & operator=(const ThisType &org)
assigment operator
ElementType
Definition: alu2dinclude.hh:55
#define ALU2DSPACE
Definition: alu2dinclude.hh:34
ALU2dGridLeafIterator(const FactoryType &factory, bool end)
Constructor called by LeafIterator.
ALU2dGridEntity< 0, dim, GridImp > EntityImp
tpye of entity implementation
Definition: alugrid/2d/iterator.hh:434
Definition: alugrid/2d/entity.hh:36
HmeshType::helement_t HElementType
Definition: alu2dinclude.hh:108
Definition: alugrid/2d/entity.hh:20
ThisType & operator=(const ALU2dGridHierarchicIterator< GridImp > &org)
the assignment operator
Definition: alugrid/2d/iterator.hh:447
GridImp::GridObjectFactoryType FactoryType
Definition: alugrid/2d/iterator.hh:358
GridImp::template Codim< codim >::Entity Entity
Definition: alugrid/2d/iterator.hh:287
Definition: alugrid/2d/iterator.hh:264
GridImp::ctype ctype
type of coordinates, i.e. double
Definition: alugrid/2d/iterator.hh:432
Dune::ALU2dImplTraits< dimworld, eltype >::template Codim< cdim >::InterfaceType ElementType
Definition: alugrid/2d/iterator.hh:97
Definition: alu2dinclude.hh:118
GridImp::template Codim< codim >::Entity Entity
Definition: alugrid/2d/iterator.hh:227
GridImp::template Codim< codim >::Entity Entity
Definition: alugrid/2d/iterator.hh:360
Dune::ALU2dImplTraits< dimworld, eltype >::template Codim< 1 >::InterfaceType ElementType
Definition: alugrid/2d/iterator.hh:160
GridImp::template Codim< 0 >::Entity Entity
type of entities we iterate
Definition: alugrid/2d/iterator.hh:430
ALU2dGridHierarchicIterator(const FactoryType &factory, const HElementType &elem, int maxlevel, bool end=false)
the normal Constructor
GridImp::GridObjectFactoryType FactoryType
Definition: alugrid/2d/iterator.hh:156
Provides proxy classes for IntersectionsIterators.
void increment()
prefix increment
GridImp::GridObjectFactoryType FactoryType
Definition: alugrid/2d/iterator.hh:93
Definition: alugrid/2d/iterator.hh:204
Different resources needed by all grid implementations.
void increment()
increment, go to next entity
Hierarchic Iterator of ALU2dGrid.
Definition: alugrid/2d/entity.hh:28
Definition: alu2dinclude.hh:97
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:80
Definition: alugrid/2d/iterator.hh:134
Definition: alugrid/2d/entity.hh:210
GridImp::template Codim< 1 >::Entity Entity
type of entity we iterate (interface)
Definition: alugrid/2d/iterator.hh:159
ThisType & operator=(const ThisType &org)
assigment of iterator
GridImp::GridObjectFactoryType FactoryType
Definition: alugrid/2d/iterator.hh:427
GridImp::GridObjectFactoryType FactoryType
Definition: alugrid/2d/iterator.hh:285
[ provides Dune::Grid ]
Definition: alugrid/2d/entity.hh:38
int level() const
ask for level of entities
Definition: alugrid/2d/iterator.hh:337