dune-grid  2.2.1
alu3diterators.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALU3DITERATORS_HH
2 #define DUNE_ALU3DITERATORS_HH
3 
4 // System includes
5 
6 // Dune includes
8 
9 // Local includes
10 #include "alu3dinclude.hh"
11 #include "topology.hh"
12 
13 namespace ALUGridSpace
14 {
15 
16  //*************************************************************
17  // definition of original LeafIterators of ALUGrid
18  //
19  // default is element (codim = 0)
20  template< int codim, class Comm >
22  {
23  typedef typename Dune::ALU3dBasicImplTraits< Comm >::HElementType HElementType;
24  typedef typename AccessIterator< HElementType >::Handle IteratorType;
25  };
26 
27  //******************************************************************
28  // LevelIterators
29  //******************************************************************
30  template< int codim, class Comm >
31  struct ALUHElementType;
32 
33  template< class Comm >
34  struct ALUHElementType< 0, Comm >
35  {
36  typedef typename Dune::ALU3dBasicImplTraits< Comm >::HElementType ElementType;
37  };
38 
39  template< class Comm >
40  struct ALUHElementType< 1, Comm >
41  {
42  typedef typename Dune::ALU3dBasicImplTraits< Comm >::HFaceType ElementType;
43  };
44 
45  template< class Comm >
46  struct ALUHElementType< 2, Comm >
47  {
48  typedef typename Dune::ALU3dBasicImplTraits< Comm >::HEdgeType ElementType;
49  };
50 
51  template< class Comm >
52  struct ALUHElementType< 3, Comm >
53  {
54  typedef typename Dune::ALU3dBasicImplTraits< Comm >::VertexType ElementType;
55  };
56 
57 
58  //*********************************************************
59  // LevelIterator Wrapper
60  //*********************************************************
61  template< class val_t >
63  : public IteratorSTI< val_t >
64  {
65  public:
67 
68  virtual int size () = 0;
69  virtual void next () = 0;
70  virtual void first() = 0;
71  virtual int done () const = 0;
72  virtual val_t & item () const = 0;
73  virtual IteratorSTI< val_t > * clone () const { assert(false); abort(); return 0; }
74  };
75 
77 
78  // defines the pair of element and boundary
79  template< int codim, class Comm >
81  {
83  typedef typename Dune::ALU3dBasicImplTraits< Comm >::HBndSegType HBndSegType;
84  typedef pair< ElType *, HBndSegType * > val_t;
85  };
86 
87  template< int codim, PartitionIteratorType pitype, class Comm >
88  class ALU3dGridLevelIteratorWrapper;
89 
90  // the element level iterator
91  template< PartitionIteratorType pitype, class Comm >
92  class ALU3dGridLevelIteratorWrapper< 0, pitype, Comm >
93  : public IteratorWrapperInterface< typename IteratorElType< 0, Comm >::val_t >
94  {
95  typedef typename IteratorElType< 0, Comm >::ElType ElType;
96  typedef typename IteratorElType< 0, Comm >::HBndSegType HBndSegType;
97  typedef ALU3DSPACE LevelIterator< ElType > IteratorType;
98 
99  // the iterator
100  IteratorType it_;
101 
102  public:
104  mutable val_t elem_;
105 
106  // constructor creating iterator
107  template< class GridImp >
108  ALU3dGridLevelIteratorWrapper ( const GridImp &grid, int level, const int nlinks )
109  : it_( grid.myGrid(), level ),
110  elem_( (ElType *)0, (HBndSegType *)0 )
111  {}
112 
113  // copy constructor
114  ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org )
115  : it_( org.it_ ), elem_(org.elem_)
116  {
117  }
118 
119  int size () { return it_->size(); }
120  void next () { it_->next(); }
121  void first() { it_->first(); }
122  int done () const { return it_->done(); }
123  val_t & item () const
124  {
125  assert( ! done () );
126  elem_.first = & it_->item();
127  return elem_;
128  }
129  };
130 
131  // the face level iterator
132  template< PartitionIteratorType pitype, class Comm >
133  class ALU3dGridLevelIteratorWrapper< 1, pitype, Comm >
134  : public IteratorWrapperInterface< typename IteratorElType< 1, Comm >::val_t >
135  {
136  typedef typename IteratorElType< 1, Comm >::ElType ElType;
137  typedef typename IteratorElType< 1, Comm >::HBndSegType HBndSegType;
138 #ifdef ALUGRID_PERIODIC_BOUNDARY
139  typedef ALU3DSPACE any_has_level_periodic< ElType > StopRule_t;
140  typedef GridIterator< ElType, StopRule_t > IteratorType;
141 #else
142  typedef ALU3DSPACE LevelIterator< ElType > IteratorType;
143 #endif
144 
145  // the iterator
146  IteratorType it_;
147 
148  public:
150  mutable val_t elem_;
151 
152  // constructor creating iterator
153  template< class GridImp >
154  ALU3dGridLevelIteratorWrapper ( const GridImp &grid, int level, const int nlinks )
155 #ifdef ALUGRID_PERIODIC_BOUNDARY
156  : it_( grid.myGrid(), StopRule_t(level) ),
157 #else
158  : it_( grid.myGrid(), level ),
159 #endif
160  elem_( (ElType *)0, (HBndSegType*)0 )
161  {}
162 
163  // copy constructor
164  ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org )
165  : it_( org.it_ ), elem_(org.elem_)
166  {}
167 
168  int size () { return it_->size(); }
169  void next () { it_->next(); }
170  void first() { it_->first(); }
171  int done () const { return it_->done(); }
172  val_t & item () const
173  {
174  assert( ! done () );
175  elem_.first = & it_->item();
176  return elem_;
177  }
178  };
179 
180  // the vertex level iterator, little bit different to the others
181  // this implementation uses the vertex leaf iterator and runs over all
182  // vertices with level <= the given iteration level
183  template< PartitionIteratorType pitype, class Comm >
184  class ALU3dGridLevelIteratorWrapper< 3, pitype, Comm >
185  : public IteratorWrapperInterface< typename IteratorElType< 3, Comm >::val_t >
186  {
187  typedef typename IteratorElType< 3, Comm >::ElType ElType;
188  typedef typename IteratorElType< 3, Comm >::HBndSegType HBndSegType;
190  typedef typename VertexListType::IteratorType IteratorType;
191 
192  VertexListType & vxList_;
193 
194  mutable int count_;
195  const int size_;
196 
197  public:
199  mutable val_t elem_;
200 
201  // constructor creating iterator
202  template< class GridImp >
203  ALU3dGridLevelIteratorWrapper ( const GridImp &grid, int level, const int nlinks )
204  : vxList_ ( grid.getVertexList( level ) ),
205  count_( 0 ),
206  size_( vxList_.size() ),
207  elem_( (ElType *)0, (HBndSegType *)0 )
208  {
209  assert( vxList_.up2Date() );
210  }
211 
212  // copy constructor
213  ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org )
214  : vxList_(org.vxList_) , count_(org.count_) , size_(org.size_)
215  , elem_(org.elem_)
216  {
217  }
218 
219  // returns size of leaf iterator, wrong here, return leaf size
220  int size () { return size_; }
221 
223  void next ()
224  {
225  if( done () ) return ;
226  ++count_;
227  return ;
228  }
229 
230  void first() { count_ = 0; }
231  int done () const { return (count_ >= size_) ? 1 : 0; }
232  val_t & item () const
233  {
234  assert( ! done () );
235  elem_.first = vxList_.getItemList()[count_];
236  assert( elem_.first );
237  return elem_;
238  }
239  };
240 
241  template< int codim, PartitionIteratorType pitype, class Comm >
242  class ALU3dGridLeafIteratorWrapper;
243 
244  //typedef pair< ALUHElementType<0>::ElementType * , HBndSegType * > LeafValType;
245  //typedef IteratorWrapperInterface<LeafValType> IteratorWrapperInterfaceType;
246 
247  //**********************************************************
248  // LeafIterator Wrapper
249  //**********************************************************
250  template< PartitionIteratorType pitype, class Comm >
251  class ALU3dGridLeafIteratorWrapper< 0, pitype, Comm >
252  : public IteratorWrapperInterface< typename IteratorElType< 0, Comm >::val_t >
253  {
254  typedef typename IteratorElType< 0, Comm >::ElType ElType;
255  typedef typename IteratorElType< 0, Comm >::HBndSegType HBndSegType;
256  typedef LeafIterator< ElType > IteratorType;
257 
258  // the ALU3dGrid Iterator
259  IteratorType it_;
260 
261  public:
263 
264  private:
265  mutable val_t elem_;
266 
267  public:
268  // constructor creating Iterator
269  template< class GridImp >
270  ALU3dGridLeafIteratorWrapper ( const GridImp &grid, int level, const int links )
271  : it_( grid.myGrid() ),
272  elem_( (ElType *)0, (HBndSegType *)0 )
273  {}
274 
275  // constructor copying iterator
276  ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org )
277  : it_( org.it_ ), elem_(org.elem_)
278  {}
279 
280  int size () { return it_->size(); }
281  void next () { it_->next(); }
282  void first() { it_->first(); }
283  int done () const { return it_->done(); }
284  val_t & item () const
285  {
286  assert( ! done () );
287  elem_.first = & it_->item();
288  return elem_;
289  }
290  };
291 
292  template< class ElType, PartitionIteratorType pitype, class Comm >
294  {
295  typedef is_leaf_entity< ElType > StopRule_t;
296  };
297 
298  // only in parallel we need only the interior items, in serial all items
299  // are interior, to make the check fasterm this is only in parallel
300  // implemented
301 #if ALU3DGRID_PARALLEL
302  template< class ElType >
303  struct LeafStopRule< ElType, Dune::Interior_Partition, MPI_Comm >
304  {
305  typedef is_interior_leaf_entity< ElType > StopRule_t;
306  };
307 #endif // #if ALU3DGRID_PARALLEL
308 
309 
310  template< PartitionIteratorType pitype, class Comm >
311  class ALU3dGridLeafIteratorWrapper< 1, pitype, Comm >
312  : public IteratorWrapperInterface< typename IteratorElType< 1, Comm >::val_t >
313  {
314  typedef typename IteratorElType< 1, Comm >::ElType ElType;
315  typedef typename IteratorElType< 1, Comm >::HBndSegType HBndSegType;
316  typedef typename LeafStopRule< ElType, pitype, Comm >::StopRule_t StopRule_t;
317  typedef GridIterator< ElType, StopRule_t > IteratorType;
318 
319  // the face iterator
320  IteratorType it_;
321 
322  public:
324  private:
325  mutable val_t elem_;
326  public:
327  // constructor creating Iterator
328  template< class GridImp >
329  ALU3dGridLeafIteratorWrapper ( const GridImp &grid, int level, const int links )
330  : it_( grid.myGrid(), StopRule_t() ),
331  elem_( (ElType *)0, (HBndSegType *)0 )
332  {}
333 
334  // constructor copying iterator
335  ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org )
336  : it_( org.it_ ), elem_(org.elem_) {}
337 
338  ~ALU3dGridLeafIteratorWrapper ()
339  {
340  }
341 
342  int size () { return it_->size(); }
343  void next () { it_->next(); }
344  void first() { it_->first(); }
345  int done () const { return it_->done(); }
346  val_t & item () const
347  {
348  assert( ! done () );
349  elem_.first = & it_->item();
350  return elem_;
351  }
352  };
353 
354  template< PartitionIteratorType pitype, class Comm >
355  class ALU3dGridLeafIteratorWrapper< 2, pitype, Comm >
356  : public IteratorWrapperInterface< typename IteratorElType< 2, Comm >::val_t >
357  {
358  typedef typename IteratorElType< 2, Comm >::ElType ElType;
359  typedef typename IteratorElType< 2, Comm >::HBndSegType HBndSegType;
360  typedef typename LeafStopRule< ElType, pitype, Comm >::StopRule_t StopRule_t;
361  typedef GridIterator< ElType, StopRule_t > IteratorType;
362 
363  public:
365 
366  private:
367  // the edge iterator
368  IteratorType it_;
369 
370  mutable val_t elem_;
371 
372  public:
373  // constructor creating Iterator
374  template< class GridImp >
375  ALU3dGridLeafIteratorWrapper ( const GridImp &grid, int level, const int links )
376  : it_( grid.myGrid(), StopRule_t() ),
377  elem_( (ElType *)0, (HBndSegType *)0 )
378  {}
379 
380  // constructor copying iterator
381  ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org )
382  : it_( org.it_ ), elem_(org.elem_) {}
383 
384  int size () { return it_->size(); }
385  void next () { it_->next(); }
386  void first() { it_->first(); }
387  int done () const { return it_->done(); }
388  val_t & item () const
389  {
390  assert( ! done () );
391  elem_.first = & it_->item();
392  return elem_;
393  }
394  };
395 
396 
397  // the vertex leaf iterator, little bit different to the others
398  template< PartitionIteratorType pitype, class Comm >
399  class ALU3dGridLeafIteratorWrapper< 3, pitype, Comm >
400  : public IteratorWrapperInterface< typename IteratorElType< 3, Comm >::val_t >
401  {
402  typedef typename IteratorElType< 3, Comm >::ElType ElType;
403  typedef typename IteratorElType< 3, Comm >::HBndSegType HBndSegType;
405  typedef typename LeafVertexListType::IteratorType IteratorType;
406  typedef typename LeafVertexListType::ItemType VxItemType;
407  typedef typename LeafStopRule< ElType, pitype, Comm >::StopRule_t StopRule_t;
408 
409  LeafVertexListType & vxList_;
410  typedef typename LeafVertexListType :: IteratorType ListIteratorType;
411 
412  mutable int count_;
413  const int size_;
414 
415  public:
417  mutable val_t elem_;
418  const StopRule_t rule_;
419 
420  // constructor creating iterator
421  template< class GridImp >
422  ALU3dGridLeafIteratorWrapper ( const GridImp &grid, int level, const int nlinks )
423  : vxList_( grid.getLeafVertexList() ),
424  count_( 0 ),
425  size_( vxList_.size() ),
426  elem_( (ElType *)0, (HBndSegType *)0 ),
427  rule_()
428  {
429  assert( vxList_.up2Date() );
430  }
431 
432  // copy constructor
433  ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org )
434  : vxList_(org.vxList_)
435  , count_(org.count_) , size_(org.size_)
436  , elem_(org.elem_)
437  , rule_()
438  {
439  }
440 
441  // returns size of leaf iterator, wrong here, return leaf size
442  int size () { return size_; }
443 
445  void next ()
446  {
447  ++count_;
448  goNextValid();
449  return ;
450  }
451 
452  void first()
453  {
454  count_ = 0;
455  goNextValid();
456  }
457  int done () const { return (count_ >= size_) ? 1 : 0; }
458  val_t & item () const
459  {
460  assert( ! done () );
461  assert( elem_.first );
462  return elem_;
463  }
464  private:
465  val_t & getItem () const
466  {
467  //elem_.first = vxList_.getItemList()[count_].first;
468  assert( ! done () );
469  elem_.first = vxList_.getItemList()[count_].first;
470  return elem_;
471  }
472  void goNextValid()
473  {
474  if( done() ) return ;
475  if( getItem().first == 0)
476  {
477  ++count_;
478  goNextValid();
479  }
480  else
481  {
482  assert( elem_.first );
483  if(! rule_( elem_.first ) )
484  {
485  ++count_;
486  goNextValid();
487  }
488  }
489  }
490  };
491 
492  /*
493  template <PartitionIteratorType pitype>
494  class ALU3dGridLeafIteratorWrapper<3,pitype>
495  : public IteratorWrapperInterface < typename IteratorElType<3>::val_t >
496  {
497  typedef IteratorElType<3>::ElType ElType;
498  typedef typename LeafStopRule< ElType, pitype > :: StopRule_t StopRule_t;
499  // ElType is vertex_STI
500  typedef LeafIterator < ElType > IteratorType;
501 
502  // the vertex iterator
503  IteratorType it_;
504 
505  public:
506  typedef IteratorElType<3>::val_t val_t;
507  private:
508  mutable val_t elem_;
509  const StopRule_t rule_;
510  public:
511  // constructor creating Iterator
512  template <class GridImp>
513  ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level, const int links )
514  : it_(grid.myGrid()), elem_(0,0) , rule_ () {}
515 
516  // constructor copying iterator
517  ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org )
518  : it_( org.it_ ), elem_(org.elem_) , rule_() {}
519 
520  int size () { return it_->size(); }
521 
522  void next ()
523  {
524  it_->next();
525  if (!it_->done())
526  {
527  // take standard walk rule to cehck vertices again, see walk.h
528  if(! rule_(it_->item()) ) next();
529  }
530  }
531 
532  void first() { it_->first(); }
533  int done () const{ return it_->done(); }
534  val_t & item () const
535  {
536  assert( ! done () );
537  elem_.first = & it_->item();
538  return elem_;
539  }
540  };
541  */
542 
543 #if ALU3DGRID_PARALLEL
544  template< int codim >
545  class LeafLevelIteratorTTProxy
546  {
547  // type is hface_STI or hedge_STI
548  typedef typename ALUHElementType< codim, MPI_Comm >::ElementType ElType;
549 
550  typedef typename Dune::ALU3dBasicImplTraits< MPI_Comm >::GitterImplType GitterImplType;
551 
552  typedef IteratorSTI< ElType > IteratorType;
553  IteratorType * inner_;
554  IteratorType * outer_;
555 
556  public:
557  // constructor creating leafBorderIteratorTT
558  LeafLevelIteratorTTProxy( GitterImplType & gitter , int link )
559  {
560  pair < IteratorSTI< ElType > * , IteratorSTI< ElType > * >
561  p = gitter.leafBorderIteratorTT( (ElType *) 0 , link );
562 
563  inner_ = p.first;
564  outer_ = p.second;
565  }
566 
567  // constructor creating levelBorderIteratorTT
568  LeafLevelIteratorTTProxy( GitterImplType & gitter , int link , int level )
569  {
570  pair < IteratorSTI< ElType > * , IteratorSTI< ElType > * >
571  p = gitter.levelBorderIteratorTT( (ElType *) 0 , link , level );
572 
573  inner_ = p.first;
574  outer_ = p.second;
575  }
576 
577  LeafLevelIteratorTTProxy( const LeafLevelIteratorTTProxy & org )
578  : inner_(org.inner_->clone())
579  , outer_(org.outer_->clone())
580  {}
581 
582  ~LeafLevelIteratorTTProxy()
583  {
584  delete inner_;
585  delete outer_;
586  }
587 
588  IteratorType & inner () { assert(inner_); return *inner_; }
589  IteratorType & outer () { assert(outer_); return *outer_; }
590  };
591 
592 
593 
594  typedef pair< ALUHElementType< 0, MPI_Comm >::ElementType *, Dune::ALU3dBasicImplTraits< MPI_Comm >::HBndSegType * > LeafValType;
595 
596  //****************************
597  //
598  // --GhostIterator
599  //
600  //****************************
601  class ALU3dGridGhostIterator
602  : public IteratorWrapperInterface< LeafValType >
603  {
604  public:
605  typedef Dune::ALU3dBasicImplTraits< MPI_Comm >::GitterImplType GitterImplType;
606 
607  typedef Dune::ALU3dBasicImplTraits< MPI_Comm >::HElementType HElementType;
608  typedef Dune::ALU3dBasicImplTraits< MPI_Comm >::HBndSegType HBndSegType;
609 
610  protected:
611  GitterImplType & gitter_;
612 
613  // this tpye is hface_STI
615 
616  typedef LeafLevelIteratorTTProxy< 1 > IteratorType;
617 
618  IteratorType * iterTT_;
619 
620  typedef IteratorSTI < ElType > InnerIteratorType;
621  InnerIteratorType * it_;
622 
623  // number of links
624  const int nl_;
625 
626  // current link
627  int link_;
628 
629  bool usingInner_;
630  public:
631  typedef LeafValType val_t;
632  private:
633  // the pair of elementand boundary face
634  mutable val_t elem_;
635  public:
636  typedef ElementPllXIF_t ItemType;
637 
638  template< class GridImp >
639  ALU3dGridGhostIterator ( const GridImp &grid, int level, const int nlinks )
640  : gitter_( grid.myGrid() ),
641  iterTT_( 0 ),
642  it_( 0 ),
643  nl_( nlinks ),
644  link_( nlinks ), // makes default status == done
645  elem_( (HElementType *)0, (HBndSegType *)0 )
646  {}
647 
648  ALU3dGridGhostIterator (const ALU3dGridGhostIterator & org)
649  : gitter_(org.gitter_)
650  , iterTT_(0) , it_(0)
651  , nl_(org.nl_)
652  , link_(org.link_)
653  , usingInner_(false)
654  , elem_(org.elem_)
655  {
656  if( org.iterTT_ )
657  {
658  iterTT_ = new IteratorType ( *org.iterTT_ );
659  usingInner_ = org.usingInner_;
660  if( org.it_ )
661  {
662  assert( ! org.it_->done() );
663  it_ = (usingInner_) ? &( iterTT_->inner() ) : &( iterTT_->outer() );
664  }
665  }
666  }
667 
668  ~ALU3dGridGhostIterator ()
669  {
670  removeIterators();
671  }
672 
673  protected:
674  virtual IteratorType * newIterator()
675  {
676  return new IteratorType ( gitter_, link_ );
677  }
678 
679  void removeIterators()
680  {
681  if(iterTT_) delete iterTT_;
682  iterTT_ = 0;
683  it_ = 0;
684  usingInner_ = false;
685  }
686 
687  void createIterator()
688  {
689  if (usingInner_) checkInnerOuter();
690 
691  if (!usingInner_)
692  {
693  ++link_;
694 
695  removeIterators();
696  if(link_ < nl_)
697  {
698  iterTT_ = newIterator();
699  assert(iterTT_);
700  checkInnerOuter();
701  if (!it_) createIterator();
702  }
703  }
704  }
705 
706  void checkInnerOuter()
707  {
708  it_ = 0;
709  if (!usingInner_)
710  {
711  assert(iterTT_);
712  it_ = &( iterTT_->inner() );
713  InnerIteratorType & it = iterTT_->inner();
714  it.first();
715  if(!it.done())
716  {
717  usingInner_ = true;
718  pair < ElementPllXIF_t *, int > p = it.item ().accessPllX ().accessOuterPllX () ;
719  pair< HElementType *, HBndSegType * > elems( (HElementType *)0, (HBndSegType *)0 );
720  p.first->getAttachedElement(elems);
721 
722  assert( elems.first || elems.second );
723 
724  if(elems.second)
725  {
726  return;
727  }
728  }
729  }
730 
731  usingInner_ = false;
732  InnerIteratorType & out = iterTT_->outer();
733  out.first();
734  if(!out.done())
735  {
736  pair < ElementPllXIF_t *, int > p = out.item ().accessPllX ().accessOuterPllX () ;
737  pair< HElementType *, HBndSegType * > elems( (HElementType *)0, (HBndSegType *)0 );
738  p.first->getAttachedElement(elems);
739 
740  assert( elems.second );
741  it_ = &out;
742  return ;
743  }
744 
745  it_ = 0;
746  }
747 
748  virtual void checkLeafEntity ()
749  {
750  if(it_)
751  {
752  if(!it_->done())
753  {
754  val_t & el = item();
755  HBndSegType * pll = el.second;
756  assert( pll );
757 
758  // this occurs if internal element is leaf but the corresponding
759  // ghost is not leaf, we have to go next
760  if ( ! pll->isLeafEntity() ) next();
761  }
762  }
763  }
764 
765  public:
766  int size () // ???? gives size only of small part of ghost cells ????
767  {
768  // if no iterator then size is zero
769  // which can happen in the case of parallel grid with 1 processor
770  if(!it_)
771  {
772  return 0;
773  }
774  return it_->size();
775  }
776 
777  // go next ghost
778  void next ()
779  {
780  if(it_)
781  {
782  // if not done increment
783  if( !it_->done() ) it_->next();
784 
785  // if now done, create new iterator
786  if( it_->done() ) createIterator();
787 
788  checkLeafEntity();
789  }
790  }
791 
792  void first()
793  {
794  link_ = -1;
795  usingInner_ = false;
796  // create iterator calls also first of iterators
797  createIterator();
798  checkLeafEntity();
799  if( it_ ) assert( !it_->done());
800  }
801 
802  int done () const
803  {
804  assert( (link_ >= nl_) ? (it_ == 0) : 1 );
805  return ((link_ >= nl_ || !it_ ) ? 1 : 0);
806  }
807 
808  val_t & item () const
809  {
810  assert(it_);
811  pair < ElementPllXIF_t *, int > p = it_->item ().accessPllX ().accessOuterPllX () ;
812  pair < HElementType * , HBndSegType * > p2;
813  p.first->getAttachedElement(p2);
814  assert(p2.second);
815  elem_.second = p2.second;
816  return elem_;
817  }
818 
819  }; // end ALU3dGridGhostIterator
820 
821 
822  // the leaf ghost partition iterator
823  template<>
824  class ALU3dGridLeafIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm >
825  : public ALU3dGridGhostIterator
826  {
827  protected:
828  typedef LeafLevelIteratorTTProxy<1> IteratorType;
829  IteratorType * newIterator()
830  {
831  return new IteratorType ( this->gitter_, this->link_ );
832  }
833 
834  void checkLeafEntity ()
835  {
836  if(this->it_)
837  {
838  if(! this->it_->done())
839  {
840  val_t & el = this->item();
841  HBndSegType * pll = el.second;
842  assert( pll );
843 
844  // this occurs if internal element is leaf but the corresponding
845  // ghost is not leaf, we have to go next
846  if ( ! pll->isLeafEntity() ) this->next();
847  }
848  }
849  }
850 
851  public:
852  template <class GridImp>
853  ALU3dGridLeafIteratorWrapper(const GridImp & grid, int level , const int nlinks )
854  : ALU3dGridGhostIterator(grid,level,nlinks) {}
855 
856  ALU3dGridLeafIteratorWrapper(const ALU3dGridLeafIteratorWrapper & org)
857  : ALU3dGridGhostIterator(org) {}
858  };
859 
860  // the level ghost partition iterator
861  template<>
862  class ALU3dGridLevelIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm >
863  : public ALU3dGridGhostIterator
864  {
865  const int level_;
866  const int mxl_;
867  protected:
868  typedef LeafLevelIteratorTTProxy<1> IteratorType;
869  IteratorType * newIterator()
870  {
871  // create new level Iterator Proxy
872  return new IteratorType ( this->gitter_, this->link_ , level_ );
873  }
874 
875  // for level iterators don't check leaf entity
876  void checkLeafEntity ()
877  {
878  if(this->it_)
879  {
880  if(! this->it_->done())
881  {
882  val_t & el = this->item();
883 
884  assert( el.second );
885  HBndSegType & pll = *(el.second);
886 
887  // this occurs if internal element is leaf but the corresponding
888  // ghost is not leaf, we have to go next if level of ghost is not
889  // our level
890  if ( ! pll.down() )
891  {
892  if( pll.ghostLevel() != level_ ) this->next();
893  }
894  }
895  }
896  }
897 
898  public:
899  template <class GridImp>
900  ALU3dGridLevelIteratorWrapper(const GridImp & grid,int level , const int nlinks )
901  : ALU3dGridGhostIterator(grid,level,nlinks)
902  , level_(level) , mxl_(grid.maxLevel()){}
903 
904  ALU3dGridLevelIteratorWrapper(const ALU3dGridLevelIteratorWrapper & org)
905  : ALU3dGridGhostIterator(org) , level_(org.level_) , mxl_(org.mxl_){}
906  };
907 
909  //
910  // Helper class to get item from Helement
911  //
913  template< class GridImp, int cd >
914  struct GetItem;
915 
916  template< class GridImp >
917  struct GetItem< GridImp, 1 >
918  {
919  enum { cd = 1 };
920  enum { elType = GridImp::elementType };
921 
922  typedef typename GridImp::MPICommunicatorType Comm;
923 
924  typedef typename Dune::ALU3dBasicImplTraits< Comm >::HElementType HElementType;
925  typedef typename Dune::ALU3dImplTraits< GridImp::elementType, Comm >::GEOElementType GEOElementType;
926  typedef typename IteratorElType< 1, Comm >::ElType ItemType;
927 
928  static ItemType *getItemFromEl ( typename Dune::ALU3dImplTraits< Dune::tetra, Comm >::GEOElementType &el, int i )
929  {
930  return el.myhface3( i );
931  }
932 
933  static ItemType *getItemFromEl ( typename Dune::ALU3dImplTraits< Dune::hexa, Comm >::GEOElementType &el, int i )
934  {
935  return el.myhface4( i );
936  }
937 
938  static ItemType *getItem ( HElementType &el, int i )
939  {
940  return getItemFromEl( static_cast< GEOElementType & >( el ), i );
941  }
942 
943  static int numItems ()
944  {
946  }
947  };
948 
949  template< class GridImp >
950  struct GetItem< GridImp, 2 >
951  {
952  enum { cd = 2 };
953  enum { elType = GridImp::elementType };
954 
955  typedef typename GridImp::MPICommunicatorType Comm;
956 
957  typedef typename Dune::ALU3dBasicImplTraits< Comm >::HElementType HElementType;
958  typedef typename Dune::ALU3dImplTraits< GridImp::elementType, Comm >::GEOElementType GEOElementType;
959  typedef typename IteratorElType< 2, Comm >::ElType ItemType;
960 
961  static ItemType *getItem ( HElementType &el, int i )
962  {
963  return static_cast< GEOElementType & >( el ).myhedge1( i );
964  }
965 
966  static int numItems ()
967  {
969  }
970  };
971 
972  template< class GridImp >
973  struct GetItem< GridImp, 3 >
974  {
975  enum { cd = 3 };
976  enum { elType = GridImp::elementType };
977 
978  typedef typename GridImp::MPICommunicatorType Comm;
979 
980  typedef typename Dune::ALU3dBasicImplTraits< Comm >::HElementType HElementType;
981  typedef typename Dune::ALU3dImplTraits< GridImp::elementType, Comm >::GEOElementType GEOElementType;
982  typedef typename IteratorElType< 3, Comm >::ElType ItemType;
983 
984  static ItemType *getItem ( HElementType &el, int i )
985  {
986  return static_cast< GEOElementType & >( el ).myvertex( i );
987  }
988 
989  static int numItems ()
990  {
992  }
993  };
994 
995 
997  template< int codim >
998  class ALU3dGridGhostIteratorHigherCodim
999  : public IteratorWrapperInterface< typename IteratorElType< codim, MPI_Comm >::val_t >
1000  {
1001  public:
1002  typedef typename Dune::ALU3dBasicImplTraits< MPI_Comm >::HElementType HElementType;
1003  typedef typename Dune::ALU3dBasicImplTraits< MPI_Comm >::HBndSegType HBndSegType;
1004  typedef typename Dune::ALU3dBasicImplTraits< MPI_Comm >::GhostPairType GhostPairType;
1005  typedef typename IteratorElType< codim, MPI_Comm >::ElType ElType;
1006  typedef typename IteratorElType< codim, MPI_Comm >::val_t val_t;
1007 
1008  private:
1009  template< Dune::ALU3dGridElementType elType, int cd >
1010  struct SelectVector;
1011 
1012  template< Dune::ALU3dGridElementType elType >
1013  struct SelectVector< elType, 1 >
1014  {
1015  typedef typename Dune::ALU3dImplTraits< elType, MPI_Comm >::GEOElementType GEOElementType;
1016 
1017  static const vector< int > &getNotOnItemVector ( int face )
1018  {
1019  return GEOElementType::facesNotOnFace( face );
1020  }
1021  };
1022 
1023  template< Dune::ALU3dGridElementType elType >
1024  struct SelectVector< elType, 2 >
1025  {
1026  typedef typename Dune::ALU3dImplTraits< elType, MPI_Comm >::GEOElementType GEOElementType;
1027  static const vector< int > &getNotOnItemVector( int face )
1028  {
1029  return GEOElementType::edgesNotOnFace( face );
1030  }
1031  };
1032 
1033  template< Dune::ALU3dGridElementType elType >
1034  struct SelectVector< elType, 3 >
1035  {
1036  typedef typename Dune::ALU3dImplTraits< elType, MPI_Comm >::GEOElementType GEOElementType;
1037  static const vector< int > &getNotOnItemVector ( int face )
1038  {
1039  return GEOElementType::verticesNotOnFace( face );
1040  }
1041  };
1042 
1043  typedef ElType *getItemFunc_t ( HElementType &el, int i );
1044 
1045  private:
1046  typedef Dune :: ALU3dGridItemListType GhostItemListType;
1047  GhostItemListType &ghList_;
1048  typedef typename GhostItemListType :: IteratorType IteratorType;
1049  IteratorType curr_;
1050  IteratorType end_;
1051  mutable val_t elem_;
1052  mutable int count_;
1053 
1054  public:
1055  template< class GhostElementIteratorImp, class GridImp >
1056  ALU3dGridGhostIteratorHigherCodim ( GhostElementIteratorImp *, const GridImp &grid,
1057  int level, const int nlinks, GhostItemListType &ghList )
1058  : ghList_( ghList ),
1059  elem_( (ElType *)0, (HBndSegType *)0 ),
1060  count_( 0 )
1061  {
1062  if( ! ghList_.up2Date() )
1063  {
1064  GhostElementIteratorImp ghostIter(grid,level,nlinks);
1065  updateGhostList(grid,ghostIter,ghList_);
1066  }
1067  }
1068 
1069  ALU3dGridGhostIteratorHigherCodim(const ALU3dGridGhostIteratorHigherCodim & org)
1070  : ghList_( org.ghList_ )
1071  , elem_(org.elem_)
1072  , count_(org.count_)
1073  {}
1074 
1075  int size () { return ghList_.getItemList().size(); }
1076  void first() { count_ = 0; }
1077  void next () { ++count_; }
1078  int done () const { return (count_ >= (int) ghList_.getItemList().size() ? 1 : 0); }
1079  val_t & item () const
1080  {
1081  assert( ! done() );
1082  void * item = ghList_.getItemList()[count_];
1083  elem_.first = ((ElType * ) item);
1084  assert( elem_.first );
1085  return elem_;
1086  }
1087 
1088  protected:
1089  template <class GridImp, class GhostElementIteratorImp>
1090  void updateGhostList(const GridImp & grid, GhostElementIteratorImp & ghostIter, GhostItemListType & ghList)
1091  {
1092  int count = 0;
1093  for( ghostIter.first(); !ghostIter.done(); ghostIter.next() )
1094  {
1095  ++count;
1096  }
1097 
1098  const int numItems = SelectVector<GridImp::elementType,codim>::getNotOnItemVector(0).size();
1099  const int maxSize = numItems * count;
1100 
1101  ghList.getItemList().reserve(maxSize);
1102  ghList.getItemList().resize(0);
1103  map< int , int > visited;
1104 
1105  for( ghostIter.first(); !ghostIter.done(); ghostIter.next() )
1106  {
1107  GhostPairType ghPair = ghostIter.item().second->getGhost();
1108  const vector<int> & notOnFace = SelectVector<GridImp::elementType,codim>::
1109  getNotOnItemVector(ghPair.second);
1110  for(int i=0; i<numItems; ++i)
1111  {
1112  ElType * item = GetItem<GridImp,codim>::getItem( *(ghPair.first) , notOnFace[i] );
1113  int idx = item->getIndex();
1114  if( visited.find(idx) == visited.end() )
1115  {
1116  ghList.getItemList().push_back( (void *) item );
1117  visited[idx] = 1;
1118  }
1119  }
1120  }
1121  ghList.markAsUp2Date();
1122  }
1123  };
1124 
1125  // the leaf ghost partition iterator
1126  template<>
1127  class ALU3dGridLeafIteratorWrapper< 1, Dune::Ghost_Partition, MPI_Comm >
1128  : public ALU3dGridGhostIteratorHigherCodim< 1 >
1129  {
1130  enum { codim = 1 };
1131  typedef ALU3dGridLeafIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostElementIteratorType;
1132 
1133  public:
1134  template <class GridImp>
1135  ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1136  : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLeafList(codim)) {}
1137 
1138  ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org )
1139  : ALU3dGridGhostIteratorHigherCodim<codim>(org) {}
1140  };
1141 
1142  // the leaf ghost partition iterator
1143  template<>
1144  class ALU3dGridLeafIteratorWrapper< 2, Dune::Ghost_Partition, MPI_Comm >
1145  : public ALU3dGridGhostIteratorHigherCodim< 2 >
1146  {
1147  enum { codim = 2 };
1148  typedef ALU3dGridLeafIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostElementIteratorType;
1149 
1150  public:
1151  template <class GridImp>
1152  ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1153  : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLeafList(codim)) {}
1154 
1155  ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org )
1156  : ALU3dGridGhostIteratorHigherCodim<codim>(org) {}
1157  };
1158 
1159  // the leaf ghost partition iterator
1160  template<>
1161  class ALU3dGridLeafIteratorWrapper< 3, Dune::Ghost_Partition, MPI_Comm >
1162  : public ALU3dGridGhostIteratorHigherCodim< 3 >
1163  {
1164  enum { codim = 3 };
1165  typedef ALU3dGridLeafIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostElementIteratorType;
1166 
1167  public:
1168  template <class GridImp>
1169  ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1170  : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLeafList(codim)) {}
1171 
1172  ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org )
1173  : ALU3dGridGhostIteratorHigherCodim<codim>(org) {}
1174  };
1175 
1176  // the level ghost partition iterator
1177  template<>
1178  class ALU3dGridLevelIteratorWrapper< 1, Dune::Ghost_Partition, MPI_Comm >
1179  : public ALU3dGridGhostIteratorHigherCodim< 1 >
1180  {
1181  enum { codim = 1 };
1182  typedef ALU3dGridLevelIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostElementIteratorType;
1183 
1184  public:
1185  template <class GridImp>
1186  ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1187  : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLevelList(codim,level)) {}
1188 
1189  ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org )
1190  : ALU3dGridGhostIteratorHigherCodim<codim>(org) {}
1191  };
1192 
1193  // the level ghost partition iterator
1194  template<>
1195  class ALU3dGridLevelIteratorWrapper< 2, Dune::Ghost_Partition, MPI_Comm >
1196  : public ALU3dGridGhostIteratorHigherCodim< 2 >
1197  {
1198  enum { codim = 2 };
1199  typedef ALU3dGridLevelIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostElementIteratorType;
1200 
1201  public:
1202  template <class GridImp>
1203  ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1204  : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLevelList(codim,level)) {}
1205 
1206  ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org )
1207  : ALU3dGridGhostIteratorHigherCodim<codim>(org) {}
1208  };
1209 
1210  // the level ghost partition iterator
1211  template<>
1212  class ALU3dGridLevelIteratorWrapper< 3, Dune::Ghost_Partition, MPI_Comm >
1213  : public ALU3dGridGhostIteratorHigherCodim< 3 >
1214  {
1215  enum { codim = 3 };
1216  typedef ALU3dGridLevelIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostElementIteratorType;
1217 
1218  public:
1219  template <class GridImp>
1220  ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1221  : ALU3dGridGhostIteratorHigherCodim<codim>((GhostElementIteratorType *)0,grid,level,nlinks,grid.getGhostLevelList(codim,level)) {}
1222 
1223  ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org )
1224  : ALU3dGridGhostIteratorHigherCodim<codim>(org) {}
1225  };
1226 
1227  // the all partition iterator
1228  template<>
1229  class ALU3dGridLeafIteratorWrapper< 0, Dune::All_Partition, MPI_Comm >
1230  : public IteratorWrapperInterface< IteratorElType< 0, MPI_Comm >::val_t >
1231  {
1232  enum { codim = 0 };
1233  typedef ALU3dGridLeafIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType;
1234  typedef ALU3dGridLeafIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType;
1235 
1236  public:
1237  typedef IteratorElType< codim, MPI_Comm >::val_t val_t;
1238  // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
1239  typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType;
1240  private:
1241  IteratorType iter_;
1242  public:
1243 
1244  template <class GridImp>
1245  ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1246  : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
1247  GhostIteratorType ( grid, level, nlinks ) )
1248  {
1249  }
1250 
1251  ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org )
1252  : iter_ (org.iter_) {}
1253 
1254  int size () { return iter_.size(); }
1255  void next () { iter_.next(); }
1256  void first() { iter_.first(); }
1257  int done () const {return iter_.done(); }
1258  val_t & item () const { assert( ! done() ); return iter_.item(); }
1259  };
1260 
1261  // the all partition iterator
1262  template<>
1263  class ALU3dGridLeafIteratorWrapper< 1, Dune::All_Partition, MPI_Comm >
1264  : public IteratorWrapperInterface< IteratorElType< 1, MPI_Comm >::val_t >
1265  {
1266  enum { codim = 1 };
1267  typedef ALU3dGridLeafIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType;
1268  typedef ALU3dGridLeafIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType;
1269 
1270  public:
1271  typedef IteratorElType< codim, MPI_Comm >::val_t val_t;
1272  // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
1273  typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType;
1274  private:
1275  IteratorType iter_;
1276  public:
1277 
1278  template <class GridImp>
1279  ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1280  : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
1281  GhostIteratorType ( grid, level, nlinks ) )
1282  {
1283  }
1284 
1285  ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org )
1286  : iter_ (org.iter_) {}
1287 
1288  int size () { return iter_.size(); }
1289  void next () { iter_.next(); }
1290  void first() { iter_.first(); }
1291  int done () const {return iter_.done(); }
1292  val_t & item () const { assert( ! done() ); return iter_.item(); }
1293  };
1294 
1295  // the all partition iterator
1296  template<>
1297  class ALU3dGridLeafIteratorWrapper< 2, Dune::All_Partition, MPI_Comm >
1298  : public IteratorWrapperInterface< IteratorElType< 2, MPI_Comm >::val_t >
1299  {
1300  enum { codim = 2 };
1301  typedef ALU3dGridLeafIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType;
1302  typedef ALU3dGridLeafIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType;
1303 
1304  public:
1305  typedef IteratorElType< codim, MPI_Comm >::val_t val_t;
1306  // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
1307  typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType;
1308  private:
1309  IteratorType iter_;
1310  public:
1311 
1312  template <class GridImp>
1313  ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1314  : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
1315  GhostIteratorType ( grid, level, nlinks ) )
1316  {
1317  }
1318 
1319  ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org )
1320  : iter_ (org.iter_) {}
1321 
1322  int size () { return iter_.size(); }
1323  void next () { iter_.next(); }
1324  void first() { iter_.first(); }
1325  int done () const {return iter_.done(); }
1326  val_t & item () const { assert( ! done() ); return iter_.item(); }
1327  };
1328 
1329  // the all partition iterator
1330  template<>
1331  class ALU3dGridLeafIteratorWrapper< 3, Dune::All_Partition, MPI_Comm >
1332  : public IteratorWrapperInterface< IteratorElType< 3, MPI_Comm >::val_t >
1333  {
1334  enum { codim = 3 };
1335  typedef ALU3dGridLeafIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType;
1336  typedef ALU3dGridLeafIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType;
1337 
1338  public:
1339  typedef IteratorElType< codim, MPI_Comm >::val_t val_t;
1340  // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
1341  typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType;
1342  private:
1343  IteratorType iter_;
1344  public:
1345 
1346  template <class GridImp>
1347  ALU3dGridLeafIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1348  : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
1349  GhostIteratorType ( grid, level, nlinks ) )
1350  {
1351  }
1352 
1353  ALU3dGridLeafIteratorWrapper (const ALU3dGridLeafIteratorWrapper & org )
1354  : iter_ (org.iter_) {}
1355 
1356  int size () { return iter_.size(); }
1357  void next () { iter_.next(); }
1358  void first() { iter_.first(); }
1359  int done () const {return iter_.done(); }
1360  val_t & item () const { assert( ! done() ); return iter_.item(); }
1361  };
1362 
1363  // the all partition iterator
1364  template<>
1365  class ALU3dGridLevelIteratorWrapper< 0, Dune::All_Partition, MPI_Comm >
1366  : public IteratorWrapperInterface< LeafValType >
1367  {
1368  typedef ALU3dGridLevelIteratorWrapper< 0, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType;
1369  typedef ALU3dGridLevelIteratorWrapper< 0, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType;
1370 
1371  public:
1372  typedef LeafValType val_t;
1373  // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
1374  typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType;
1375  private:
1376  IteratorType iter_;
1377  public:
1378 
1379  template <class GridImp>
1380  ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1381  : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
1382  GhostIteratorType ( grid, level, nlinks ) )
1383  {
1384  }
1385 
1386  ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org)
1387  : iter_(org.iter_) {}
1388 
1389  int size () { return iter_.size(); }
1390  void next () { iter_.next(); }
1391  void first() { iter_.first(); }
1392  int done () const {return iter_.done(); }
1393  val_t & item () const { assert( ! done() ); return iter_.item(); }
1394  };
1395 #endif // #if ALU3DGRID_PARALLEL
1396 
1397  // placed here because we need ALU3dGridLevelIteratorWrapper<0,Dune::All_Partition> here
1398  // the edge level iterator
1399  template< PartitionIteratorType pitype, class Comm >
1400  class ALU3dGridLevelIteratorWrapper< 2, pitype, Comm >
1401  : public IteratorWrapperInterface< typename IteratorElType< 2, Comm >::val_t >
1402  {
1403  public:
1405  typedef typename Dune::ALU3dBasicImplTraits< Comm >::HBndSegType HBndSegType;
1406  typedef typename Dune::ALU3dBasicImplTraits< Comm >::GEOEdgeType GEOEdgeType;
1407 
1409 
1410  private:
1411  mutable val_t elem_;
1412  const int level_;
1413 
1415  ItemListType & edgeList_;
1416 
1417  size_t count_ ;
1418  bool maxLevel_;
1419 
1420  public:
1421  // constructor creating iterator
1422  template< class GridImp >
1423  ALU3dGridLevelIteratorWrapper ( const GridImp &grid, int level, const int nlinks )
1424  : elem_( (ElType *)0, (HBndSegType *)0 ),
1425  level_( level ),
1426  edgeList_( grid.getEdgeList( level ) ),
1427  count_( 0 )
1428  {
1429  if( ! edgeList_.up2Date() )
1430  updateEdgeList(grid,level,nlinks);
1431  }
1432 
1433  // copy constructor
1434  ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org )
1435  : elem_(org.elem_)
1436  , level_(org.level_)
1437  , edgeList_( org.edgeList_ )
1438  , count_(org.count_)
1439  {
1440  }
1441 
1442  int size () { return edgeList_.getItemList().size(); }
1443  void next ()
1444  {
1445  ++count_;
1446  }
1447 
1448  void first()
1449  {
1450  count_ = 0;
1451  }
1452 
1453  int done () const { return ((count_ >= edgeList_.size()) ? 1: 0); }
1454 
1455  val_t & item () const
1456  {
1457  assert( ! done () );
1458  elem_.first = ( (ElType *) edgeList_.getItemList()[count_]);
1459 
1460  assert( elem_.first );
1461  return elem_;
1462  }
1463 
1464  private:
1465  template <class GridImp>
1466  void updateEdgeList(const GridImp & grid, int level, int nlinks)
1467  {
1468  typedef ALU3dGridLevelIteratorWrapper< 0, Dune::All_Partition, Comm > ElementLevelIterator;
1469  typedef typename ElementLevelIterator :: val_t el_val_t;
1470  ElementLevelIterator iter(grid,level,nlinks);
1471 
1472  edgeList_.getItemList().resize(0);
1473  map < int , int > visited;
1474 
1475  for( iter.first(); ! iter.done(); iter.next() )
1476  {
1477  typedef typename Dune::ALU3dImplTraits< GridImp::elementType, Comm >::GEOElementType GEOElementType;
1479 
1480  GEOElementType *elem = 0;
1481  el_val_t & item = iter.item();
1482 
1483  if( item.first )
1484  elem = static_cast< GEOElementType * > (item.first);
1485  else if( item.second )
1486  elem = static_cast< GEOElementType * > (item.second->getGhost().first);
1487 
1488  assert( elem );
1489  for(int e=0; e<numEdges; ++e)
1490  {
1491  ElType * edge = elem->myhedge1(e);
1492  if( edge->isGhost() ) continue;
1493 
1494  int idx = edge->getIndex();
1495  if( visited.find(idx) == visited.end() )
1496  {
1497  edgeList_.getItemList().push_back( (void *) edge );
1498  visited[idx] = 1;
1499  }
1500  }
1501  }
1502  edgeList_.markAsUp2Date();
1503  }
1504  };
1505 
1506 #if ALU3DGRID_PARALLEL
1507  // the all partition iterator
1508  template<>
1509  class ALU3dGridLevelIteratorWrapper< 1, Dune::All_Partition, MPI_Comm >
1510  : public IteratorWrapperInterface< IteratorElType< 1, MPI_Comm >::val_t >
1511  {
1512  enum { codim = 1 };
1513  typedef ALU3dGridLevelIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType;
1514  typedef ALU3dGridLevelIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType;
1515 
1516  public:
1517  typedef IteratorElType< codim, MPI_Comm >::val_t val_t;
1518  // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
1519  typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType;
1520  private:
1521  IteratorType iter_;
1522  public:
1523 
1524  template <class GridImp>
1525  ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1526  : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
1527  GhostIteratorType ( grid, level, nlinks ) )
1528  {
1529  }
1530 
1531  ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org )
1532  : iter_ (org.iter_) {}
1533 
1534  int size () { return iter_.size(); }
1535  void next () { iter_.next(); }
1536  void first() { iter_.first(); }
1537  int done () const {return iter_.done(); }
1538  val_t & item () const { assert( ! done() ); return iter_.item(); }
1539  };
1540 
1541  // the all partition iterator
1542  template<>
1543  class ALU3dGridLevelIteratorWrapper< 2, Dune::All_Partition, MPI_Comm >
1544  : public IteratorWrapperInterface< IteratorElType< 2, MPI_Comm >::val_t >
1545  {
1546  enum { codim = 2 };
1547  typedef ALU3dGridLevelIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType;
1548  typedef ALU3dGridLevelIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType;
1549 
1550  public:
1551  typedef IteratorElType< codim, MPI_Comm >::val_t val_t;
1552  // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
1553  typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType;
1554  private:
1555  IteratorType iter_;
1556  public:
1557 
1558  template <class GridImp>
1559  ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1560  : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
1561  GhostIteratorType ( grid, level, nlinks ) )
1562  {
1563  }
1564 
1565  ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org )
1566  : iter_ (org.iter_) {}
1567 
1568  int size () { return iter_.size(); }
1569  void next () { iter_.next(); }
1570  void first() { iter_.first(); }
1571  int done () const {return iter_.done(); }
1572  val_t & item () const { assert( ! done() ); return iter_.item(); }
1573  };
1574 
1575  // the all partition iterator
1576  template<>
1577  class ALU3dGridLevelIteratorWrapper< 3, Dune::All_Partition, MPI_Comm >
1578  : public IteratorWrapperInterface < IteratorElType< 3, MPI_Comm >::val_t >
1579  {
1580  enum { codim = 3 };
1581  typedef ALU3dGridLevelIteratorWrapper< codim, Dune::InteriorBorder_Partition, MPI_Comm > InteriorIteratorType;
1582  typedef ALU3dGridLevelIteratorWrapper< codim, Dune::Ghost_Partition, MPI_Comm > GhostIteratorType;
1583 
1584  public:
1585  typedef IteratorElType< codim, MPI_Comm >::val_t val_t;
1586  // use ALUGrids AlignIterator to combine Interior and Ghost Iterator
1587  typedef AlignIterator< InteriorIteratorType, GhostIteratorType, val_t > IteratorType;
1588  private:
1589  IteratorType iter_;
1590  public:
1591 
1592  template <class GridImp>
1593  ALU3dGridLevelIteratorWrapper (const GridImp & grid, int level , const int nlinks )
1594  : iter_ ( InteriorIteratorType ( grid, level, nlinks ) ,
1595  GhostIteratorType ( grid, level, nlinks ) )
1596  {
1597  }
1598 
1599  ALU3dGridLevelIteratorWrapper (const ALU3dGridLevelIteratorWrapper & org )
1600  : iter_ (org.iter_) {}
1601 
1602  int size () { return iter_.size(); }
1603  void next () { iter_.next(); }
1604  void first() { iter_.first(); }
1605  int done () const {return iter_.done(); }
1606  val_t & item () const { assert( ! done() ); return iter_.item(); }
1607  };
1608 #endif // #if ALU3DGRID_PARALLEL
1609 
1610 } // end namespace ALUGridSpace
1611 
1612 #endif // #ifndef DUNE_ALU3DITERATORS_HH