4#ifndef DUNE_ALBERTA_TREEITERATOR_HH
5#define DUNE_ALBERTA_TREEITERATOR_HH
7#include <dune/common/hybridutilities.hh>
8#include <dune/common/std/utility.hh>
30 template<
int dim,
int dimworld >
39 static const int dimension = Grid::dimension;
41 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
42 typedef Alberta::ElementInfo< dimension > ElementInfo;
45 struct NoMarkSubEntities;
47 struct MarkSubEntities;
52 : dofNumbering_( dofNumbering )
54 for(
int codim = 0; codim <= dimension; ++codim )
59 : dofNumbering_( other.dofNumbering_ )
61 for(
int codim = 0; codim <= dimension; ++codim )
65 ~AlbertaMarkerVector ()
71 This &operator= (
const This & );
78 template<
int firstCodim,
class Iterator >
79 void markSubEntities (
const Iterator &begin,
const Iterator &end );
83 for(
int codim = 0; codim <= dimension; ++codim )
85 if( marker_[ codim ] != 0 )
86 delete[] marker_[ codim ];
94 return (marker_[ dimension ] != 0);
98 void print ( std::ostream &out = std::cout )
const;
101 const DofNumbering &dofNumbering_;
102 int *marker_[ dimension+1 ];
110 template<
int dim,
int dimworld >
114 template<
int firstCodim,
class Iterator >
115 static void mark (
const DofNumbering &dofNumbering,
int *(&marker)[ dimension + 1 ],
116 const Iterator &begin,
const Iterator &end )
125 template<
int dim,
int dimworld >
127 struct AlbertaMarkerVector< dim, dimworld >::MarkSubEntities
129 template<
int codim >
132 static const int numSubEntities = Alberta::NumSubEntities< dimension, codim >::value;
134 typedef Alberta::ElementInfo< dimension > ElementInfo;
136 static void apply (
const DofNumbering &dofNumbering,
137 int *(&marker)[ dimension + 1 ],
138 const ElementInfo &elementInfo )
140 int *array = marker[ codim ];
142 const int index = dofNumbering( elementInfo, 0, 0 );
143 for(
int i = 0; i < numSubEntities; ++i )
145 int &mark = array[ dofNumbering( elementInfo, codim, i ) ];
151 template<
int firstCodim,
class Iterator >
152 static void mark (
const DofNumbering &dofNumbering,
int *(&marker)[ dimension + 1 ],
153 const Iterator &begin,
const Iterator &end )
155 for(
int codim = firstCodim; codim <= dimension; ++codim )
157 const int size = dofNumbering.size( codim );
158 marker[ codim ] =
new int[ size ];
160 int *array = marker[ codim ];
161 for(
int i = 0; i < size; ++i )
165 for( Iterator it = begin; it != end; ++it )
167 const ElementInfo &elementInfo = it->impl().elementInfo();
182 template<
int codim,
class Gr
idImp,
bool leafIterator >
188 static const int dimension = GridImp::dimension;
189 static const int codimension = codim;
190 static const int dimensionworld = GridImp::dimensionworld;
193 friend class AlbertaGrid< dimension, dimensionworld >;
195 static const int numSubEntities
196 = Alberta::NumSubEntities< dimension, codimension >::value;
199 typedef Alberta::MeshPointer< dimension > MeshPointer;
200 typedef typename MeshPointer::MacroIterator MacroIterator;
204 typedef typename EntityObject::ImplementationType EntityImp;
205 typedef typename EntityImp::ElementInfo ElementInfo;
228 return entity_.impl().equals( other.entity_.impl() );
240 return entity_.impl().level();
250 return entity_.impl().grid();
254 void nextElement ( ElementInfo &elementInfo );
255 void nextElementStop (ElementInfo &elementInfo );
256 bool stopAtElement (
const ElementInfo &elementInfo )
const;
258 void goNext ( ElementInfo &elementInfo );
259 void goNext (
const std::integral_constant< int, 0 > cdVariable,
260 ElementInfo &elementInfo );
261 void goNext (
const std::integral_constant< int, 1 > cdVariable,
262 ElementInfo &elementInfo );
264 void goNext (
const std::integral_constant< int, cd > cdVariable,
265 ElementInfo &elementInfo );
275 MacroIterator macroIterator_;
278 const MarkerVector *marker_;
286 template<
int dim,
int dimworld >
287 template<
int codim >
291 assert( marker_[ codim ] != 0 );
293 const int subIndex = dofNumbering_( elementInfo, codim, subEntity );
294 const int markIndex = marker_[ codim ][ subIndex ];
295 assert( (markIndex >= 0) );
297 const int index = dofNumbering_( elementInfo, 0, 0 );
298 return (markIndex == index);
302 template<
int dim,
int dimworld >
303 template<
int firstCodim,
class Iterator >
308 std::conditional< (firstCodim <= dimension), MarkSubEntities<true>, NoMarkSubEntities<false> >::type
309 ::template mark< firstCodim, Iterator >( dofNumbering_, marker_, begin, end );
313 template<
int dim,
int dimworld >
316 for(
int codim = 1; codim <= dimension; ++codim )
318 int *marker = marker_[ codim ];
321 const int size = dofNumbering_.size( codim );
323 out <<
"Codimension " << codim <<
" (" << size <<
" entries)" << std::endl;
324 for(
int i = 0; i < size; ++i )
325 out <<
"subentity " << i <<
" visited on Element " << marker[ i ] << std::endl;
335 template<
int codim,
class Gr
idImp,
bool leafIterator >
345 template<
int codim,
class Gr
idImp,
bool leafIterator >
346 inline AlbertaGridTreeIterator< codim, GridImp, leafIterator >
347 ::AlbertaGridTreeIterator (
const GridImp &grid,
350 : entity_( EntityImp( grid ) ),
352 subEntity_( (codim == 0 ? 0 : -1) ),
353 macroIterator_( grid.meshPointer().begin() ),
356 ElementInfo elementInfo = *macroIterator_;
357 nextElementStop( elementInfo );
359 goNext( elementInfo );
361 entity_.impl().setElement( elementInfo, subEntity_ );
366 template<
int codim,
class Gr
idImp,
bool leafIterator >
370 : entity_( EntityImp( grid ) ),
373 macroIterator_( grid.meshPointer().end() ),
379 template<
int codim,
class Gr
idImp,
bool leafIterator >
382 : entity_( other.entity_ ),
383 level_( other.level_ ),
384 subEntity_( other.subEntity_ ),
385 macroIterator_( other.macroIterator_ ),
386 marker_( other.marker_ )
391 template<
int codim,
class Gr
idImp,
bool leafIterator >
395 entity_ = other.entity_;
396 level_ = other.level_;
397 subEntity_ = other.subEntity_;
398 macroIterator_ = other.macroIterator_;
399 marker_ = other.marker_;
405 template<
int codim,
class Gr
idImp,
bool leafIterator >
408 ElementInfo elementInfo = entity_.impl().elementInfo_;
409 goNext ( elementInfo );
411 entity_.impl().setElement( elementInfo, subEntity_ );
415 template<
int codim,
class Gr
idImp,
bool leafIterator >
419 if( elementInfo.isLeaf() || (elementInfo.level() >= level_) )
421 while( (elementInfo.level() > 0) && (elementInfo.indexInFather() == 1) )
422 elementInfo = elementInfo.father();
423 if( elementInfo.level() == 0 )
426 elementInfo = *macroIterator_;
429 elementInfo = elementInfo.father().child( 1 );
432 elementInfo = elementInfo.child( 0 );
436 template<
int codim,
class Gr
idImp,
bool leafIterator >
437 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
438 ::nextElementStop ( ElementInfo &elementInfo )
440 while( !(!elementInfo || stopAtElement( elementInfo )) )
441 nextElement( elementInfo );
445 template<
int codim,
class Gr
idImp,
bool leafIterator >
446 inline bool AlbertaGridTreeIterator< codim, GridImp, leafIterator >
447 ::stopAtElement (
const ElementInfo &elementInfo )
const
451 return (leafIterator ? elementInfo.isLeaf() : (level_ == elementInfo.level()));
455 template<
int codim,
class Gr
idImp,
bool leafIterator >
456 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
457 ::goNext ( ElementInfo &elementInfo )
459 std::integral_constant< int, codim > codimVariable;
460 goNext( codimVariable, elementInfo );
463 template<
int codim,
class Gr
idImp,
bool leafIterator >
464 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
465 ::goNext (
const std::integral_constant< int, 0 > cdVariable,
466 ElementInfo &elementInfo )
468 assert( stopAtElement( elementInfo ) );
470 nextElement( elementInfo );
471 nextElementStop( elementInfo );
474 template<
int codim,
class Gr
idImp,
bool leafIterator >
475 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
476 ::goNext (
const std::integral_constant< int, 1 > cdVariable,
477 ElementInfo &elementInfo )
479 assert( stopAtElement( elementInfo ) );
482 if( subEntity_ >= numSubEntities )
485 nextElement( elementInfo );
486 nextElementStop( elementInfo );
493 const int face = (dimension == 1 ? (numSubEntities-1)-subEntity_ : subEntity_);
495 const ALBERTA EL *neighbor = elementInfo.elInfo().neigh[ face ];
496 if( (neighbor != NULL) && !elementInfo.isBoundary( face ) )
499 const int elIndex = grid().dofNumbering() ( elementInfo, 0, 0 );
500 const int nbIndex = grid().dofNumbering() ( neighbor, 0, 0 );
501 if( elIndex < nbIndex )
502 goNext( cdVariable, elementInfo );
509 assert( marker_ != 0 );
510 if( !marker_->template subEntityOnElement< 1 >( elementInfo, subEntity_ ) )
511 goNext( cdVariable, elementInfo );
515 template<
int codim,
class Gr
idImp,
bool leafIterator >
517 inline void AlbertaGridTreeIterator< codim, GridImp, leafIterator >
518 ::goNext (
const std::integral_constant< int, cd > cdVariable,
519 ElementInfo &elementInfo )
521 assert( stopAtElement( elementInfo ) );
524 if( subEntity_ >= numSubEntities )
527 nextElement( elementInfo );
528 nextElementStop( elementInfo );
533 assert( marker_ != 0 );
534 if( !marker_->template subEntityOnElement< cd >( elementInfo, subEntity_ ) )
535 goNext( cdVariable, elementInfo );
Definition: treeiterator.hh:184
bool equals(const This &other) const
equality
Definition: treeiterator.hh:226
AlbertaGridTreeIterator(const GridImp &grid, const MarkerVector *marker, int travLevel)
Constructor making begin iterator.
Definition: treeiterator.hh:347
AlbertaGridTreeIterator(const GridImp &grid, int travLevel)
Constructor making end iterator.
Definition: treeiterator.hh:368
This & operator=(const This &other)
Constructor making end iterator.
Definition: treeiterator.hh:393
Entity & dereference() const
dereferencing
Definition: treeiterator.hh:232
int level() const
ask for level of entities
Definition: treeiterator.hh:238
void increment()
increment
Definition: treeiterator.hh:406
const GridImp & grid() const
obtain a reference to the grid
Definition: treeiterator.hh:248
AlbertaGridTreeIterator(const This &other)
Constructor making end iterator.
Definition: treeiterator.hh:381
marker assigning subentities to one element containing them
Definition: treeiterator.hh:32
AlbertaMarkerVector(const DofNumbering &dofNumbering)
create AlbertaMarkerVector with empty vectors
Definition: treeiterator.hh:51
bool up2Date() const
return true if marking is up to date
Definition: treeiterator.hh:92
bool subEntityOnElement(const ElementInfo &elementInfo, int subEntity) const
visit subentity on this element?
Definition: treeiterator.hh:289
void print(std::ostream &out=std::cout) const
print for debugin' only
Definition: treeiterator.hh:314
Wrapper class for entities.
Definition: entity.hh:64
provides a wrapper for ALBERTA's el_info structure
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:46
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:267
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:14
Static tag representing a codimension.
Definition: dimension.hh:22
Traits for type conversions and type information.