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;
194 static const int numSubEntities
202 typedef typename GridImp::template Codim< codim >::Entity
Entity;
232 bool stopAtElement (
const ElementInfo &elementInfo )
const;
235 void goNext (
const integral_constant< int, 0 > cdVariable,
237 void goNext (
const integral_constant< int, 1 > cdVariable,
240 void goNext (
const integral_constant< int, cd > cdVariable,
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() ),
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 );
505 #endif // #if HAVE_ALBERTA
507 #endif // #ifndef DUNE_ALBERTA_TREEITERATOR_HH
bool up2Date() const
return true if marking is up to date
Definition: treeiterator.hh:90
Definition: albertagrid/entity.hh:24
int size(int codim) const
Definition: dofadmin.hh:157
static ReturnImplementationType< InterfaceType >::ImplementationType & getRealImplementation(InterfaceType &i)
return real implementation of interface class
Definition: common/grid.hh:1223
int max(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:341
provides a wrapper for ALBERTA's mesh structure
AlbertaMarkerVector(const This &other)
Definition: treeiterator.hh:56
MakeableInterfaceObject< Entity > EntityObject
Definition: treeiterator.hh:203
Alberta::MeshPointer< dimension > MeshPointer
Definition: treeiterator.hh:199
Definition: treeiterator.hh:128
Base::ElementInfo ElementInfo
Definition: treeiterator.hh:198
static void apply(const DofNumbering &dofNumbering, int *(&marker)[dimension+1], const ElementInfo &elementInfo)
Definition: treeiterator.hh:134
Alberta::ElementInfo< dimension > ElementInfo
Definition: treeiterator.hh:132
bool subEntityOnElement(const ElementInfo &elementInfo, int subEntity) const
visit subentity on this element?
Definition: treeiterator.hh:263
MeshPointer::MacroIterator MacroIterator
Definition: treeiterator.hh:200
void markSubEntities(const Iterator &begin, const Iterator &end)
Definition: treeiterator.hh:279
[ provides Dune::Grid ]
Definition: agrid.hh:137
This & operator=(const This &other)
Constructor making end iterator.
Definition: treeiterator.hh:357
AlbertaMarkerVector(const DofNumbering &dofNumbering)
create AlbertaMarkerVector with empty vectors
Definition: treeiterator.hh:49
const GridImp & grid() const
obtain a reference to the grid
void increment()
increment
Definition: treeiterator.hh:371
void print(std::ostream &out=std::cout) const
print for debugin' only
Definition: treeiterator.hh:288
~AlbertaMarkerVector()
Definition: treeiterator.hh:63
static const int dimension
Definition: treeiterator.hh:187
AlbertaMarkerVector< dimension, dimensionworld > MarkerVector
Definition: treeiterator.hh:206
Entity::Implementation ImplementationType
Definition: common/grid.hh:1377
static const int codimension
Definition: treeiterator.hh:188
GridImp::template Codim< codim >::Entity Entity
Definition: treeiterator.hh:202
static const int dimension
Definition: agrid.hh:177
#define ALBERTA
Definition: albertaheader.hh:27
EntityImp::ElementInfo ElementInfo
Definition: albertagrid/entitypointer.hh:49
EntityObject::ImplementationType EntityImp
Definition: treeiterator.hh:204
marker assigning subentities to one element containing them
Definition: treeiterator.hh:29
void clear()
Definition: treeiterator.hh:79
EntityImp & entityImp()
obtain reference to internal entity implementation
AlbertaGridTreeIterator(const This &other)
Constructor making end iterator.
Definition: treeiterator.hh:345
static const int dimensionworld
Definition: treeiterator.hh:189