6#ifndef DUNE_ALBERTA_TREEITERATOR_HH
7#define DUNE_ALBERTA_TREEITERATOR_HH
11#include <dune/common/hybridutilities.hh>
33 template<
int dim,
int dimworld >
42 static const int dimension = Grid::dimension;
44 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
45 typedef Alberta::ElementInfo< dimension > ElementInfo;
48 struct NoMarkSubEntities;
50 struct MarkSubEntities;
55 : dofNumbering_( dofNumbering )
57 for(
int codim = 0; codim <= dimension; ++codim )
62 : dofNumbering_( other.dofNumbering_ )
64 for(
int codim = 0; codim <= dimension; ++codim )
68 ~AlbertaMarkerVector ()
74 This &operator= (
const This & );
81 template<
int firstCodim,
class Iterator >
82 void markSubEntities (
const Iterator &begin,
const Iterator &end );
86 for(
int codim = 0; codim <= dimension; ++codim )
88 if( marker_[ codim ] != 0 )
89 delete[] marker_[ codim ];
97 return (marker_[ dimension ] != 0);
101 void print ( std::ostream &out = std::cout )
const;
104 const DofNumbering &dofNumbering_;
105 int *marker_[ dimension+1 ];
113 template<
int dim,
int dimworld >
117 template<
int firstCodim,
class Iterator >
118 static void mark ( [[maybe_unused]]
const DofNumbering & dofNumbering,
119 [[maybe_unused]]
int *(&marker)[ dimension + 1 ],
120 [[maybe_unused]]
const Iterator &begin,
121 [[maybe_unused]]
const Iterator &end )
130 template<
int dim,
int dimworld >
132 struct AlbertaMarkerVector< dim, dimworld >::MarkSubEntities
134 template<
int codim >
137 static const int numSubEntities = Alberta::NumSubEntities< dimension, codim >::value;
139 typedef Alberta::ElementInfo< dimension > ElementInfo;
141 static void apply (
const DofNumbering &dofNumbering,
142 int *(&marker)[ dimension + 1 ],
143 const ElementInfo &elementInfo )
145 int *array = marker[ codim ];
147 const int index = dofNumbering( elementInfo, 0, 0 );
148 for(
int i = 0; i < numSubEntities; ++i )
150 int &mark = array[ dofNumbering( elementInfo, codim, i ) ];
156 template<
int firstCodim,
class Iterator >
157 static void mark (
const DofNumbering &dofNumbering,
int *(&marker)[ dimension + 1 ],
158 const Iterator &begin,
const Iterator &end )
160 for(
int codim = firstCodim; codim <= dimension; ++codim )
162 const int size = dofNumbering.size( codim );
163 marker[ codim ] =
new int[
size ];
165 int *array = marker[ codim ];
166 for(
int i = 0; i <
size; ++i )
170 for( Iterator it = begin; it != end; ++it )
172 const ElementInfo &elementInfo = it->impl().elementInfo();
174 [ & ](
auto i ){ Codim< i+firstCodim >::apply( dofNumbering, marker, elementInfo ); } );
187 template<
int codim,
class Gr
idImp,
bool leafIterator >
193 static const int dimension = GridImp::dimension;
194 static const int codimension = codim;
195 static const int dimensionworld = GridImp::dimensionworld;
198 friend class AlbertaGrid< dimension, dimensionworld >;
200 static const int numSubEntities
201 = Alberta::NumSubEntities< dimension, codimension >::value;
204 typedef Alberta::MeshPointer< dimension > MeshPointer;
205 typedef typename MeshPointer::MacroIterator MacroIterator;
209 typedef typename EntityObject::ImplementationType EntityImp;
210 typedef typename EntityImp::ElementInfo ElementInfo;
233 return entity_.impl().equals( other.entity_.impl() );
245 return entity_.impl().level();
255 return entity_.impl().grid();
259 void nextElement ( ElementInfo &elementInfo );
260 void nextElementStop (ElementInfo &elementInfo );
261 bool stopAtElement (
const ElementInfo &elementInfo )
const;
263 void goNext ( ElementInfo &elementInfo );
264 void goNext (
const std::integral_constant< int, 0 > cdVariable,
265 ElementInfo &elementInfo );
266 void goNext (
const std::integral_constant< int, 1 > cdVariable,
267 ElementInfo &elementInfo );
269 void goNext (
const std::integral_constant< int, cd > cdVariable,
270 ElementInfo &elementInfo );
280 MacroIterator macroIterator_;
283 const MarkerVector *marker_;
291 template<
int dim,
int dimworld >
292 template<
int codim >
296 assert( marker_[ codim ] != 0 );
298 const int subIndex = dofNumbering_( elementInfo, codim, subEntity );
299 const int markIndex = marker_[ codim ][ subIndex ];
300 assert( (markIndex >= 0) );
302 const int index = dofNumbering_( elementInfo, 0, 0 );
303 return (markIndex == index);
307 template<
int dim,
int dimworld >
308 template<
int firstCodim,
class Iterator >
313 std::conditional< (firstCodim <= dimension), MarkSubEntities<true>, NoMarkSubEntities<false> >::type
314 ::template mark< firstCodim, Iterator >( dofNumbering_, marker_, begin, end );
318 template<
int dim,
int dimworld >
321 for(
int codim = 1; codim <= dimension; ++codim )
323 int *marker = marker_[ codim ];
326 const int size = dofNumbering_.size( codim );
328 out <<
"Codimension " << codim <<
" (" <<
size <<
" entries)" << std::endl;
329 for(
int i = 0; i <
size; ++i )
330 out <<
"subentity " << i <<
" visited on Element " << marker[ i ] << std::endl;
340 template<
int codim,
class Gr
idImp,
bool leafIterator >
350 template<
int codim,
class Gr
idImp,
bool leafIterator >
351 inline AlbertaGridTreeIterator< codim, GridImp, leafIterator >
352 ::AlbertaGridTreeIterator (
const GridImp &grid,
355 : entity_( EntityImp( grid ) ),
357 subEntity_( (codim == 0 ? 0 : -1) ),
358 macroIterator_( grid.meshPointer().begin() ),
361 ElementInfo elementInfo = *macroIterator_;
362 nextElementStop( elementInfo );
364 goNext( elementInfo );
366 entity_.impl().setElement( elementInfo, subEntity_ );
371 template<
int codim,
class Gr
idImp,
bool leafIterator >
375 : entity_( EntityImp( grid ) ),
378 macroIterator_( grid.meshPointer().end() ),
384 template<
int codim,
class Gr
idImp,
bool leafIterator >
387 : entity_( other.entity_ ),
388 level_( other.level_ ),
389 subEntity_( other.subEntity_ ),
390 macroIterator_( other.macroIterator_ ),
391 marker_( other.marker_ )
396 template<
int codim,
class Gr
idImp,
bool leafIterator >
400 entity_ = other.entity_;
401 level_ = other.level_;
402 subEntity_ = other.subEntity_;
403 macroIterator_ = other.macroIterator_;
404 marker_ = other.marker_;
410 template<
int codim,
class Gr
idImp,
bool leafIterator >
413 ElementInfo elementInfo = entity_.impl().elementInfo_;
414 goNext ( elementInfo );
416 entity_.impl().setElement( elementInfo, subEntity_ );
420 template<
int codim,
class Gr
idImp,
bool leafIterator >
424 if( elementInfo.isLeaf() || (elementInfo.level() >= level_) )
426 while( (elementInfo.level() > 0) && (elementInfo.indexInFather() == 1) )
427 elementInfo = elementInfo.father();
428 if( elementInfo.level() == 0 )
431 elementInfo = *macroIterator_;
434 elementInfo = elementInfo.father().child( 1 );
437 elementInfo = elementInfo.child( 0 );
441 template<
int codim,
class Gr
idImp,
bool leafIterator >
442 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
443 ::nextElementStop ( ElementInfo &elementInfo )
445 while( !(!elementInfo || stopAtElement( elementInfo )) )
446 nextElement( elementInfo );
450 template<
int codim,
class Gr
idImp,
bool leafIterator >
451 inline bool AlbertaGridTreeIterator< codim, GridImp, leafIterator >
452 ::stopAtElement (
const ElementInfo &elementInfo )
const
456 return (leafIterator ? elementInfo.isLeaf() : (level_ == elementInfo.level()));
460 template<
int codim,
class Gr
idImp,
bool leafIterator >
461 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
462 ::goNext ( ElementInfo &elementInfo )
464 std::integral_constant< int, codim > codimVariable;
465 goNext( codimVariable, elementInfo );
468 template<
int codim,
class Gr
idImp,
bool leafIterator >
469 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
470 ::goNext (
const std::integral_constant< int, 0 > ,
471 ElementInfo &elementInfo )
473 assert( stopAtElement( elementInfo ) );
475 nextElement( elementInfo );
476 nextElementStop( elementInfo );
479 template<
int codim,
class Gr
idImp,
bool leafIterator >
480 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
481 ::goNext (
const std::integral_constant< int, 1 > cdVariable,
482 ElementInfo &elementInfo )
484 assert( stopAtElement( elementInfo ) );
487 if( subEntity_ >= numSubEntities )
490 nextElement( elementInfo );
491 nextElementStop( elementInfo );
498 const int face = (dimension == 1 ? (numSubEntities-1)-subEntity_ : subEntity_);
500 const ALBERTA EL *neighbor = elementInfo.elInfo().neigh[ face ];
501 if( (neighbor != NULL) && !elementInfo.isBoundary( face ) )
504 const int elIndex = grid().dofNumbering() ( elementInfo, 0, 0 );
505 const int nbIndex = grid().dofNumbering() ( neighbor, 0, 0 );
506 if( elIndex < nbIndex )
507 goNext( cdVariable, elementInfo );
514 assert( marker_ != 0 );
515 if( !marker_->template subEntityOnElement< 1 >( elementInfo, subEntity_ ) )
516 goNext( cdVariable, elementInfo );
520 template<
int codim,
class Gr
idImp,
bool leafIterator >
522 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
523 ::goNext (
const std::integral_constant< int, cd > cdVariable,
524 ElementInfo &elementInfo )
526 assert( stopAtElement( elementInfo ) );
529 if( subEntity_ >= numSubEntities )
532 nextElement( elementInfo );
533 nextElementStop( elementInfo );
538 assert( marker_ != 0 );
539 if( !marker_->template subEntityOnElement< cd >( elementInfo, subEntity_ ) )
540 goNext( cdVariable, elementInfo );
Definition: treeiterator.hh:189
bool equals(const This &other) const
equality
Definition: treeiterator.hh:231
AlbertaGridTreeIterator(const GridImp &grid, const MarkerVector *marker, int travLevel)
Constructor making begin iterator.
Definition: treeiterator.hh:352
AlbertaGridTreeIterator(const GridImp &grid, int travLevel)
Constructor making end iterator.
Definition: treeiterator.hh:373
This & operator=(const This &other)
Constructor making end iterator.
Definition: treeiterator.hh:398
Entity & dereference() const
dereferencing
Definition: treeiterator.hh:237
int level() const
ask for level of entities
Definition: treeiterator.hh:243
void increment()
increment
Definition: treeiterator.hh:411
const GridImp & grid() const
obtain a reference to the grid
Definition: treeiterator.hh:253
AlbertaGridTreeIterator(const This &other)
Constructor making end iterator.
Definition: treeiterator.hh:386
marker assigning subentities to one element containing them
Definition: treeiterator.hh:35
AlbertaMarkerVector(const DofNumbering &dofNumbering)
create AlbertaMarkerVector with empty vectors
Definition: treeiterator.hh:54
bool up2Date() const
return true if marking is up to date
Definition: treeiterator.hh:95
bool subEntityOnElement(const ElementInfo &elementInfo, int subEntity) const
visit subentity on this element?
Definition: treeiterator.hh:294
void print(std::ostream &out=std::cout) const
print for debugin' only
Definition: treeiterator.hh:319
Wrapper class for entities.
Definition: entity.hh:66
provides a wrapper for ALBERTA's el_info structure
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
provides a wrapper for ALBERTA's mesh structure
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Static tag representing a codimension.
Definition: dimension.hh:24
Traits for type conversions and type information.