Dune Core Modules (2.4.1)

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