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