4 #ifndef DUNE_ALBERTA_TREEITERATOR_HH
5 #define DUNE_ALBERTA_TREEITERATOR_HH
7 #include <dune/common/typetraits.hh>
28 template<
int dim,
int dimworld >
43 struct NoMarkSubEntities;
45 struct MarkSubEntities;
50 : dofNumbering_( dofNumbering )
52 for(
int codim = 0; codim <= dimension; ++codim )
57 : dofNumbering_( other.dofNumbering_ )
59 for(
int codim = 0; codim <= dimension; ++codim )
69 This &operator= (
const This & );
76 template<
int firstCodim,
class Iterator >
81 for(
int codim = 0; codim <= dimension; ++codim )
83 if( marker_[ codim ] != 0 )
84 delete[] marker_[ codim ];
92 return (marker_[ dimension ] != 0);
96 void print ( std::ostream &out = std::cout )
const;
99 const DofNumbering &dofNumbering_;
100 int *marker_[ dimension+1 ];
108 template<
int dim,
int dimworld >
110 struct AlbertaMarkerVector< dim, dimworld >::NoMarkSubEntities
112 template<
int firstCodim,
class Iterator >
113 static void mark (
const DofNumbering &dofNumbering,
int *(&marker)[ dimension + 1 ],
114 const Iterator &begin,
const Iterator &end )
123 template<
int dim,
int dimworld >
125 struct AlbertaMarkerVector< dim, dimworld >::MarkSubEntities
127 template<
int codim >
135 int *(&marker)[ dimension + 1 ],
138 int *array = marker[ codim ];
140 const int index = dofNumbering( elementInfo, 0, 0 );
141 for(
int i = 0; i < numSubEntities; ++i )
143 int &mark = array[ dofNumbering( elementInfo, codim, i ) ];
149 template<
int firstCodim,
class Iterator >
150 static void mark (
const DofNumbering &dofNumbering,
int *(&marker)[ dimension + 1 ],
151 const Iterator &begin,
const Iterator &end )
153 for(
int codim = firstCodim; codim <= dimension; ++codim )
155 const int size = dofNumbering.
size( codim );
156 marker[ codim ] =
new int[ size ];
158 int *array = marker[ codim ];
159 for(
int i = 0; i < size; ++i )
163 for( Iterator it = begin; it != end; ++it )
166 ForLoop< Codim, firstCodim, dimension >::apply( dofNumbering, marker, elementInfo );
179 template<
int codim,
class Gr
idImp,
bool leafIterator >
180 class AlbertaGridTreeIterator
181 :
public AlbertaGridEntityPointer< codim, GridImp >
183 typedef AlbertaGridTreeIterator< codim, GridImp, leafIterator > This;
184 typedef AlbertaGridEntityPointer< codim, GridImp > Base;
194 static const int numSubEntities
202 typedef typename GridImp::template Codim< codim >::Entity
Entity;
234 bool stopAtElement (
const ElementInfo &elementInfo )
const;
237 void goNext (
const std::integral_constant< int, 0 > cdVariable,
239 void goNext (
const std::integral_constant< int, 1 > cdVariable,
242 void goNext (
const std::integral_constant< int, cd > cdVariable,
262 template<
int dim,
int dimworld >
263 template<
int codim >
267 assert( marker_[ codim ] != 0 );
269 const int subIndex = dofNumbering_( elementInfo, codim, subEntity );
270 const int markIndex = marker_[ codim ][ subIndex ];
271 assert( (markIndex >= 0) );
273 const int index = dofNumbering_( elementInfo, 0, 0 );
274 return (markIndex == index);
278 template<
int dim,
int dimworld >
279 template<
int firstCodim,
class Iterator >
284 std::conditional< (firstCodim <= dimension), MarkSubEntities<true>, NoMarkSubEntities<false> >::type
285 ::template mark< firstCodim, Iterator >( dofNumbering_, marker_, begin, end );
289 template<
int dim,
int dimworld >
292 for(
int codim = 1; codim <= dimension; ++codim )
294 int *marker = marker_[ codim ];
297 const int size = dofNumbering_.size( codim );
299 out <<
"Codimension " << codim <<
" (" << size <<
" entries)" << std::endl;
300 for(
int i = 0; i < size; ++i )
301 out <<
"subentity " << i <<
" visited on Element " << marker[ i ] << std::endl;
311 template<
int codim,
class Gr
idImp,
bool leafIterator >
321 template<
int codim,
class Gr
idImp,
bool leafIterator >
328 subEntity_( (codim == 0 ? 0 : -1) ),
329 macroIterator_( grid.meshPointer().begin() ),
333 nextElementStop( elementInfo );
335 goNext( elementInfo );
337 entityImp().setElement( elementInfo, subEntity_ );
342 template<
int codim,
class Gr
idImp,
bool leafIterator >
349 macroIterator_( grid.meshPointer().end() ),
355 template<
int codim,
class Gr
idImp,
bool leafIterator >
359 level_( other.level_ ),
360 subEntity_( other.subEntity_ ),
361 macroIterator_( other.macroIterator_ ),
362 marker_( other.marker_ )
367 template<
int codim,
class Gr
idImp,
bool leafIterator >
371 Base::operator=( other );
373 level_ = other.level_;
374 subEntity_ = other.subEntity_;
375 macroIterator_ = other.macroIterator_;
376 marker_ = other.marker_;
382 template<
int codim,
class Gr
idImp,
bool leafIterator >
385 ElementInfo elementInfo = entityImp().elementInfo_;
386 goNext ( elementInfo );
388 entityImp().setElement( elementInfo, subEntity_ );
392 template<
int codim,
class Gr
idImp,
bool leafIterator >
396 if( elementInfo.isLeaf() || (elementInfo.level() >= level_) )
398 while( (elementInfo.level() > 0) && (elementInfo.indexInFather() == 1) )
399 elementInfo = elementInfo.father();
400 if( elementInfo.level() == 0 )
403 elementInfo = *macroIterator_;
406 elementInfo = elementInfo.father().child( 1 );
409 elementInfo = elementInfo.child( 0 );
413 template<
int codim,
class Gr
idImp,
bool leafIterator >
414 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
415 ::nextElementStop ( ElementInfo &elementInfo )
417 while( !(!elementInfo || stopAtElement( elementInfo )) )
418 nextElement( elementInfo );
422 template<
int codim,
class Gr
idImp,
bool leafIterator >
423 inline bool AlbertaGridTreeIterator< codim, GridImp, leafIterator >
424 ::stopAtElement (
const ElementInfo &elementInfo )
const
428 return (leafIterator ? elementInfo.isLeaf() : (level_ == elementInfo.level()));
432 template<
int codim,
class Gr
idImp,
bool leafIterator >
433 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
434 ::goNext ( ElementInfo &elementInfo )
436 std::integral_constant< int, codim > codimVariable;
437 goNext( codimVariable, elementInfo );
440 template<
int codim,
class Gr
idImp,
bool leafIterator >
441 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
442 ::goNext (
const std::integral_constant< int, 0 > cdVariable,
443 ElementInfo &elementInfo )
445 assert( stopAtElement( elementInfo ) );
447 nextElement( elementInfo );
448 nextElementStop( elementInfo );
451 template<
int codim,
class Gr
idImp,
bool leafIterator >
452 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
453 ::goNext (
const std::integral_constant< int, 1 > cdVariable,
454 ElementInfo &elementInfo )
456 assert( stopAtElement( elementInfo ) );
459 if( subEntity_ >= numSubEntities )
462 nextElement( elementInfo );
463 nextElementStop( elementInfo );
470 const int face = (dimension == 1 ? (numSubEntities-1)-subEntity_ : subEntity_);
472 const ALBERTA EL *neighbor = elementInfo.elInfo().neigh[ face ];
473 if( (neighbor != NULL) && !elementInfo.isBoundary( face ) )
476 const int elIndex = grid().dofNumbering() ( elementInfo, 0, 0 );
477 const int nbIndex = grid().dofNumbering() ( neighbor, 0, 0 );
478 if( elIndex < nbIndex )
479 goNext( cdVariable, elementInfo );
486 assert( marker_ != 0 );
487 if( !marker_->template subEntityOnElement< 1 >( elementInfo, subEntity_ ) )
488 goNext( cdVariable, elementInfo );
492 template<
int codim,
class Gr
idImp,
bool leafIterator >
494 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
495 ::goNext (
const std::integral_constant< int, cd > cdVariable,
496 ElementInfo &elementInfo )
498 assert( stopAtElement( elementInfo ) );
501 if( subEntity_ >= numSubEntities )
504 nextElement( elementInfo );
505 nextElementStop( elementInfo );
510 assert( marker_ != 0 );
511 if( !marker_->template subEntityOnElement< cd >( elementInfo, subEntity_ ) )
512 goNext( cdVariable, elementInfo );
517 #endif // #if HAVE_ALBERTA
519 #endif // #ifndef DUNE_ALBERTA_TREEITERATOR_HH