4#ifndef DUNE_ALBERTA_TREEITERATOR_HH
5#define DUNE_ALBERTA_TREEITERATOR_HH
10#include <dune/grid/albertagrid/entitypointer.hh>
28 template<
int dim,
int dimworld >
37 static const int dimension = Grid::dimension;
39 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
40 typedef Alberta::ElementInfo< dimension > ElementInfo;
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 )
63 ~AlbertaMarkerVector ()
69 This &operator= (
const This & );
76 template<
int firstCodim,
class Iterator >
77 void markSubEntities (
const Iterator &begin,
const Iterator &end );
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 >
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 >
130 static const int numSubEntities = Alberta::NumSubEntities< dimension, codim >::value;
132 typedef Alberta::ElementInfo< dimension > ElementInfo;
134 static void apply (
const DofNumbering &dofNumbering,
135 int *(&marker)[ dimension + 1 ],
136 const ElementInfo &elementInfo )
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 ) ];
144 mark = std::max( index, mark );
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 >
187 static const int dimension = GridImp::dimension;
188 static const int codimension = codim;
189 static const int dimensionworld = GridImp::dimensionworld;
192 friend class AlbertaGrid< dimension, dimensionworld >;
194 static const int numSubEntities
195 = Alberta::NumSubEntities< dimension, codimension >::value;
198 typedef typename Base::ElementInfo ElementInfo;
199 typedef Alberta::MeshPointer< dimension > MeshPointer;
200 typedef typename MeshPointer::MacroIterator MacroIterator;
202 typedef typename GridImp::template Codim< codim >::Entity Entity;
204 typedef typename EntityObject::ImplementationType EntityImp;
230 void nextElement ( ElementInfo &elementInfo );
231 void nextElementStop (ElementInfo &elementInfo );
232 bool stopAtElement (
const ElementInfo &elementInfo )
const;
234 void goNext ( ElementInfo &elementInfo );
236 ElementInfo &elementInfo );
238 ElementInfo &elementInfo );
241 ElementInfo &elementInfo );
249 MacroIterator macroIterator_;
260 template<
int dim,
int dimworld >
261 template<
int codim >
265 assert( marker_[ codim ] != 0 );
267 const int subIndex = dofNumbering_( elementInfo, codim, subEntity );
268 const int markIndex = marker_[ codim ][ subIndex ];
269 assert( (markIndex >= 0) );
271 const int index = dofNumbering_( elementInfo, 0, 0 );
272 return (markIndex == index);
276 template<
int dim,
int dimworld >
277 template<
int firstCodim,
class Iterator >
282 conditional< (firstCodim <= dimension), MarkSubEntities<true>, NoMarkSubEntities<false> >::type
283 ::template mark< firstCodim, Iterator >( dofNumbering_, marker_, begin, end );
287 template<
int dim,
int dimworld >
290 for(
int codim = 1; codim <= dimension; ++codim )
292 int *marker = marker_[ codim ];
295 const int size = dofNumbering_.size( codim );
297 out <<
"Codimension " << codim <<
" (" << size <<
" entries)" << std::endl;
298 for(
int i = 0; i < size; ++i )
299 out <<
"subentity " << i <<
" visited on Element " << marker[ i ] << std::endl;
309 template<
int codim,
class Gr
idImp,
bool leafIterator >
316 subEntity_( (codim == 0 ? 0 : -1) ),
317 macroIterator_( grid.meshPointer().begin() ),
320 ElementInfo elementInfo = *macroIterator_;
321 nextElementStop( elementInfo );
323 goNext( elementInfo );
325 entityImp().setElement( elementInfo, subEntity_ );
330 template<
int codim,
class Gr
idImp,
bool leafIterator >
337 macroIterator_( grid.meshPointer().end() ),
343 template<
int codim,
class Gr
idImp,
bool leafIterator >
347 level_( other.level_ ),
348 subEntity_( other.subEntity_ ),
349 macroIterator_( other.macroIterator_ ),
350 marker_( other.marker_ )
355 template<
int codim,
class Gr
idImp,
bool leafIterator >
359 Base::operator=( other );
361 level_ = other.level_;
362 subEntity_ = other.subEntity_;
363 macroIterator_ = other.macroIterator_;
364 marker_ = other.marker_;
370 template<
int codim,
class Gr
idImp,
bool leafIterator >
373 ElementInfo elementInfo = entityImp().elementInfo_;
374 goNext ( elementInfo );
376 entityImp().setElement( elementInfo, subEntity_ );
380 template<
int codim,
class Gr
idImp,
bool leafIterator >
384 if( elementInfo.isLeaf() || (elementInfo.level() >= level_) )
386 while( (elementInfo.level() > 0) && (elementInfo.indexInFather() == 1) )
387 elementInfo = elementInfo.father();
388 if( elementInfo.level() == 0 )
391 elementInfo = *macroIterator_;
394 elementInfo = elementInfo.father().child( 1 );
397 elementInfo = elementInfo.child( 0 );
401 template<
int codim,
class Gr
idImp,
bool leafIterator >
402 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
403 ::nextElementStop ( ElementInfo &elementInfo )
405 while( !(!elementInfo || stopAtElement( elementInfo )) )
406 nextElement( elementInfo );
410 template<
int codim,
class Gr
idImp,
bool leafIterator >
411 inline bool AlbertaGridTreeIterator< codim, GridImp, leafIterator >
412 ::stopAtElement (
const ElementInfo &elementInfo )
const
416 return (leafIterator ? elementInfo.isLeaf() : (level_ == elementInfo.level()));
420 template<
int codim,
class Gr
idImp,
bool leafIterator >
421 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
422 ::goNext ( ElementInfo &elementInfo )
424 integral_constant< int, codim > codimVariable;
425 goNext( codimVariable, elementInfo );
428 template<
int codim,
class Gr
idImp,
bool leafIterator >
429 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
430 ::goNext (
const integral_constant< int, 0 > cdVariable,
431 ElementInfo &elementInfo )
433 assert( stopAtElement( elementInfo ) );
435 nextElement( elementInfo );
436 nextElementStop( elementInfo );
439 template<
int codim,
class Gr
idImp,
bool leafIterator >
440 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
441 ::goNext (
const integral_constant< int, 1 > cdVariable,
442 ElementInfo &elementInfo )
444 assert( stopAtElement( elementInfo ) );
447 if( subEntity_ >= numSubEntities )
450 nextElement( elementInfo );
451 nextElementStop( elementInfo );
458 const int face = (dimension == 1 ? (numSubEntities-1)-subEntity_ : subEntity_);
460 const ALBERTA EL *neighbor = elementInfo.elInfo().neigh[ face ];
461 if( (neighbor != NULL) && !elementInfo.isBoundary( face ) )
464 const int elIndex = grid().dofNumbering() ( elementInfo, 0, 0 );
465 const int nbIndex = grid().dofNumbering() ( neighbor, 0, 0 );
466 if( elIndex < nbIndex )
467 goNext( cdVariable, elementInfo );
474 assert( marker_ != 0 );
475 if( !marker_->template subEntityOnElement< 1 >( elementInfo, subEntity_ ) )
476 goNext( cdVariable, elementInfo );
480 template<
int codim,
class Gr
idImp,
bool leafIterator >
482 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
483 ::goNext (
const integral_constant< int, cd > cdVariable,
484 ElementInfo &elementInfo )
486 assert( stopAtElement( elementInfo ) );
489 if( subEntity_ >= numSubEntities )
492 nextElement( elementInfo );
493 nextElementStop( elementInfo );
498 assert( marker_ != 0 );
499 if( !marker_->template subEntityOnElement< cd >( elementInfo, subEntity_ ) )
500 goNext( cdVariable, elementInfo );
EntityPointer implementation for AlbertaGrid.
Definition: entitypointer.hh:29
const GridImp & grid() const
obtain a reference to the grid
Definition: entitypointer.hh:192
EntityImp & entityImp()
obtain reference to internal entity implementation
Definition: entitypointer.hh:177
Definition: treeiterator.hh:182
AlbertaGridTreeIterator(const GridImp &grid, const MarkerVector *marker, int travLevel)
Constructor making begin iterator.
Definition: treeiterator.hh:311
AlbertaGridTreeIterator(const GridImp &grid, int travLevel)
Constructor making end iterator.
Definition: treeiterator.hh:332
This & operator=(const This &other)
Constructor making end iterator.
Definition: treeiterator.hh:357
const GridImp & grid() const
obtain a reference to the grid
Definition: entitypointer.hh:192
EntityImp & entityImp()
obtain reference to internal entity implementation
Definition: entitypointer.hh:177
void increment()
increment
Definition: treeiterator.hh:371
AlbertaGridTreeIterator(const This &other)
Constructor making end iterator.
Definition: treeiterator.hh:345
marker assigning subentities to one element containing them
Definition: treeiterator.hh:30
AlbertaMarkerVector(const DofNumbering &dofNumbering)
create AlbertaMarkerVector with empty vectors
Definition: treeiterator.hh:49
bool up2Date() const
return true if marking is up to date
Definition: treeiterator.hh:90
bool subEntityOnElement(const ElementInfo &elementInfo, int subEntity) const
visit subentity on this element?
Definition: treeiterator.hh:263
void print(std::ostream &out=std::cout) const
print for debugin' only
Definition: treeiterator.hh:288
static ReturnImplementationType< InterfaceType >::ImplementationType & getRealImplementation(InterfaceType &i)
return real implementation of interface class
Definition: grid.hh:1223
provides a wrapper for ALBERTA's mesh structure
Dune namespace.
Definition: alignment.hh:14
Select a type based on a condition.
Definition: typetraits.hh:419
Generate a type for a given integral constant.
Definition: typetraits.hh:457
Traits for type conversions and type information.