4#ifndef DUNE_ALBERTA_TREEITERATOR_HH
5#define DUNE_ALBERTA_TREEITERATOR_HH
9#include <dune/common/hybridutilities.hh>
31 template<
int dim,
int dimworld >
40 static const int dimension = Grid::dimension;
42 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
43 typedef Alberta::ElementInfo< dimension > ElementInfo;
46 struct NoMarkSubEntities;
48 struct MarkSubEntities;
53 : dofNumbering_( dofNumbering )
55 for(
int codim = 0; codim <= dimension; ++codim )
60 : dofNumbering_( other.dofNumbering_ )
62 for(
int codim = 0; codim <= dimension; ++codim )
66 ~AlbertaMarkerVector ()
72 This &operator= (
const This & );
79 template<
int firstCodim,
class Iterator >
80 void markSubEntities (
const Iterator &begin,
const Iterator &end );
84 for(
int codim = 0; codim <= dimension; ++codim )
86 if( marker_[ codim ] != 0 )
87 delete[] marker_[ codim ];
95 return (marker_[ dimension ] != 0);
99 void print ( std::ostream &out = std::cout )
const;
102 const DofNumbering &dofNumbering_;
103 int *marker_[ dimension+1 ];
111 template<
int dim,
int dimworld >
115 template<
int firstCodim,
class Iterator >
116 static void mark ( [[maybe_unused]]
const DofNumbering & dofNumbering,
117 [[maybe_unused]]
int *(&marker)[ dimension + 1 ],
118 [[maybe_unused]]
const Iterator &begin,
119 [[maybe_unused]]
const Iterator &end )
128 template<
int dim,
int dimworld >
130 struct AlbertaMarkerVector< dim, dimworld >::MarkSubEntities
132 template<
int codim >
135 static const int numSubEntities = Alberta::NumSubEntities< dimension, codim >::value;
137 typedef Alberta::ElementInfo< dimension > ElementInfo;
139 static void apply (
const DofNumbering &dofNumbering,
140 int *(&marker)[ dimension + 1 ],
141 const ElementInfo &elementInfo )
143 int *array = marker[ codim ];
145 const int index = dofNumbering( elementInfo, 0, 0 );
146 for(
int i = 0; i < numSubEntities; ++i )
148 int &mark = array[ dofNumbering( elementInfo, codim, i ) ];
154 template<
int firstCodim,
class Iterator >
155 static void mark (
const DofNumbering &dofNumbering,
int *(&marker)[ dimension + 1 ],
156 const Iterator &begin,
const Iterator &end )
158 for(
int codim = firstCodim; codim <= dimension; ++codim )
160 const int size = dofNumbering.size( codim );
161 marker[ codim ] =
new int[ size ];
163 int *array = marker[ codim ];
164 for(
int i = 0; i < size; ++i )
168 for( Iterator it = begin; it != end; ++it )
170 const ElementInfo &elementInfo = it->impl().elementInfo();
172 [ & ](
auto i ){ Codim< i+firstCodim >::apply( dofNumbering, marker, elementInfo ); } );
185 template<
int codim,
class Gr
idImp,
bool leafIterator >
191 static const int dimension = GridImp::dimension;
192 static const int codimension = codim;
193 static const int dimensionworld = GridImp::dimensionworld;
196 friend class AlbertaGrid< dimension, dimensionworld >;
198 static const int numSubEntities
199 = Alberta::NumSubEntities< dimension, codimension >::value;
202 typedef Alberta::MeshPointer< dimension > MeshPointer;
203 typedef typename MeshPointer::MacroIterator MacroIterator;
207 typedef typename EntityObject::ImplementationType EntityImp;
208 typedef typename EntityImp::ElementInfo ElementInfo;
231 return entity_.impl().equals( other.entity_.impl() );
243 return entity_.impl().level();
253 return entity_.impl().grid();
257 void nextElement ( ElementInfo &elementInfo );
258 void nextElementStop (ElementInfo &elementInfo );
259 bool stopAtElement (
const ElementInfo &elementInfo )
const;
261 void goNext ( ElementInfo &elementInfo );
262 void goNext (
const std::integral_constant< int, 0 > cdVariable,
263 ElementInfo &elementInfo );
264 void goNext (
const std::integral_constant< int, 1 > cdVariable,
265 ElementInfo &elementInfo );
267 void goNext (
const std::integral_constant< int, cd > cdVariable,
268 ElementInfo &elementInfo );
278 MacroIterator macroIterator_;
281 const MarkerVector *marker_;
289 template<
int dim,
int dimworld >
290 template<
int codim >
294 assert( marker_[ codim ] != 0 );
296 const int subIndex = dofNumbering_( elementInfo, codim, subEntity );
297 const int markIndex = marker_[ codim ][ subIndex ];
298 assert( (markIndex >= 0) );
300 const int index = dofNumbering_( elementInfo, 0, 0 );
301 return (markIndex == index);
305 template<
int dim,
int dimworld >
306 template<
int firstCodim,
class Iterator >
311 std::conditional< (firstCodim <= dimension), MarkSubEntities<true>, NoMarkSubEntities<false> >::type
312 ::template mark< firstCodim, Iterator >( dofNumbering_, marker_, begin, end );
316 template<
int dim,
int dimworld >
319 for(
int codim = 1; codim <= dimension; ++codim )
321 int *marker = marker_[ codim ];
324 const int size = dofNumbering_.size( codim );
326 out <<
"Codimension " << codim <<
" (" << size <<
" entries)" << std::endl;
327 for(
int i = 0; i < size; ++i )
328 out <<
"subentity " << i <<
" visited on Element " << marker[ i ] << std::endl;
338 template<
int codim,
class Gr
idImp,
bool leafIterator >
348 template<
int codim,
class Gr
idImp,
bool leafIterator >
349 inline AlbertaGridTreeIterator< codim, GridImp, leafIterator >
350 ::AlbertaGridTreeIterator (
const GridImp &grid,
353 : entity_( EntityImp( grid ) ),
355 subEntity_( (codim == 0 ? 0 : -1) ),
356 macroIterator_( grid.meshPointer().begin() ),
359 ElementInfo elementInfo = *macroIterator_;
360 nextElementStop( elementInfo );
362 goNext( elementInfo );
364 entity_.impl().setElement( elementInfo, subEntity_ );
369 template<
int codim,
class Gr
idImp,
bool leafIterator >
373 : entity_( EntityImp( grid ) ),
376 macroIterator_( grid.meshPointer().end() ),
382 template<
int codim,
class Gr
idImp,
bool leafIterator >
385 : entity_( other.entity_ ),
386 level_( other.level_ ),
387 subEntity_( other.subEntity_ ),
388 macroIterator_( other.macroIterator_ ),
389 marker_( other.marker_ )
394 template<
int codim,
class Gr
idImp,
bool leafIterator >
398 entity_ = other.entity_;
399 level_ = other.level_;
400 subEntity_ = other.subEntity_;
401 macroIterator_ = other.macroIterator_;
402 marker_ = other.marker_;
408 template<
int codim,
class Gr
idImp,
bool leafIterator >
411 ElementInfo elementInfo = entity_.impl().elementInfo_;
412 goNext ( elementInfo );
414 entity_.impl().setElement( elementInfo, subEntity_ );
418 template<
int codim,
class Gr
idImp,
bool leafIterator >
422 if( elementInfo.isLeaf() || (elementInfo.level() >= level_) )
424 while( (elementInfo.level() > 0) && (elementInfo.indexInFather() == 1) )
425 elementInfo = elementInfo.father();
426 if( elementInfo.level() == 0 )
429 elementInfo = *macroIterator_;
432 elementInfo = elementInfo.father().child( 1 );
435 elementInfo = elementInfo.child( 0 );
439 template<
int codim,
class Gr
idImp,
bool leafIterator >
440 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
441 ::nextElementStop ( ElementInfo &elementInfo )
443 while( !(!elementInfo || stopAtElement( elementInfo )) )
444 nextElement( elementInfo );
448 template<
int codim,
class Gr
idImp,
bool leafIterator >
449 inline bool AlbertaGridTreeIterator< codim, GridImp, leafIterator >
450 ::stopAtElement (
const ElementInfo &elementInfo )
const
454 return (leafIterator ? elementInfo.isLeaf() : (level_ == elementInfo.level()));
458 template<
int codim,
class Gr
idImp,
bool leafIterator >
459 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
460 ::goNext ( ElementInfo &elementInfo )
462 std::integral_constant< int, codim > codimVariable;
463 goNext( codimVariable, elementInfo );
466 template<
int codim,
class Gr
idImp,
bool leafIterator >
467 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
468 ::goNext (
const std::integral_constant< int, 0 > ,
469 ElementInfo &elementInfo )
471 assert( stopAtElement( elementInfo ) );
473 nextElement( elementInfo );
474 nextElementStop( elementInfo );
477 template<
int codim,
class Gr
idImp,
bool leafIterator >
478 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
479 ::goNext (
const std::integral_constant< int, 1 > cdVariable,
480 ElementInfo &elementInfo )
482 assert( stopAtElement( elementInfo ) );
485 if( subEntity_ >= numSubEntities )
488 nextElement( elementInfo );
489 nextElementStop( elementInfo );
496 const int face = (dimension == 1 ? (numSubEntities-1)-subEntity_ : subEntity_);
498 const ALBERTA EL *neighbor = elementInfo.elInfo().neigh[ face ];
499 if( (neighbor != NULL) && !elementInfo.isBoundary( face ) )
502 const int elIndex = grid().dofNumbering() ( elementInfo, 0, 0 );
503 const int nbIndex = grid().dofNumbering() ( neighbor, 0, 0 );
504 if( elIndex < nbIndex )
505 goNext( cdVariable, elementInfo );
512 assert( marker_ != 0 );
513 if( !marker_->template subEntityOnElement< 1 >( elementInfo, subEntity_ ) )
514 goNext( cdVariable, elementInfo );
518 template<
int codim,
class Gr
idImp,
bool leafIterator >
520 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
521 ::goNext (
const std::integral_constant< int, cd > cdVariable,
522 ElementInfo &elementInfo )
524 assert( stopAtElement( elementInfo ) );
527 if( subEntity_ >= numSubEntities )
530 nextElement( elementInfo );
531 nextElementStop( elementInfo );
536 assert( marker_ != 0 );
537 if( !marker_->template subEntityOnElement< cd >( elementInfo, subEntity_ ) )
538 goNext( cdVariable, elementInfo );
Definition: treeiterator.hh:187
bool equals(const This &other) const
equality
Definition: treeiterator.hh:229
AlbertaGridTreeIterator(const GridImp &grid, const MarkerVector *marker, int travLevel)
Constructor making begin iterator.
Definition: treeiterator.hh:350
AlbertaGridTreeIterator(const GridImp &grid, int travLevel)
Constructor making end iterator.
Definition: treeiterator.hh:371
This & operator=(const This &other)
Constructor making end iterator.
Definition: treeiterator.hh:396
Entity & dereference() const
dereferencing
Definition: treeiterator.hh:235
int level() const
ask for level of entities
Definition: treeiterator.hh:241
void increment()
increment
Definition: treeiterator.hh:409
const GridImp & grid() const
obtain a reference to the grid
Definition: treeiterator.hh:251
AlbertaGridTreeIterator(const This &other)
Constructor making end iterator.
Definition: treeiterator.hh:384
marker assigning subentities to one element containing them
Definition: treeiterator.hh:33
AlbertaMarkerVector(const DofNumbering &dofNumbering)
create AlbertaMarkerVector with empty vectors
Definition: treeiterator.hh:52
bool up2Date() const
return true if marking is up to date
Definition: treeiterator.hh:93
bool subEntityOnElement(const ElementInfo &elementInfo, int subEntity) const
visit subentity on this element?
Definition: treeiterator.hh:292
void print(std::ostream &out=std::cout) const
print for debugin' only
Definition: treeiterator.hh:317
Wrapper class for entities.
Definition: entity.hh:64
Traits for type conversions and type information.
provides a wrapper for ALBERTA's el_info structure
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:266
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
provides a wrapper for ALBERTA's mesh structure
Dune namespace.
Definition: alignedallocator.hh:11
Static tag representing a codimension.
Definition: dimension.hh:22