1#ifndef DUNE_ALU3DGRIDITERATOR_HH
2#define DUNE_ALU3DGRIDITERATOR_HH
10#include <dune/alugrid/common/memory.hh>
11#include <dune/alugrid/common/twists.hh>
14#include "alu3dinclude.hh"
16#include "faceutility.hh"
17#include "alu3diterators.hh"
21 template<
int cd,
int dim,
class Gr
idImp>
22 class ALU3dGridEntity;
23 template<
int cd, PartitionIteratorType pitype,
class Gr
idImp >
24 class ALU3dGridLevelIterator;
25 template<
int cd,
class Gr
idImp >
26 class ALU3dGridEntityPointer;
27 template<
int mydim,
int coorddim,
class Gr
idImp>
28 class ALU3dGridGeometry;
29 template<
class Gr
idImp>
30 class ALU3dGridHierarchicIterator;
31 template<
class Gr
idImp>
32 class ALU3dGridIntersectionIterator;
33 template<
int codim, PartitionIteratorType pitype,
class Gr
idImp>
34 class ALU3dGridLeafIterator;
35 template<
int,
int, ALU3dGr
idElementType,
class >
37 template<
int,
int, ALU3dGr
idElementType,
class >
38 class ALU3dGridFaceInfo;
39 template< ALU3dGr
idElementType,
class >
40 class ALU3dGridGeometricFaceInfo;
53template<
class Gr
idImp>
57 enum { dim = GridImp::dimension };
58 enum { dimworld = GridImp::dimensionworld };
60 typedef typename GridImp::MPICommunicatorType Comm;
62 typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits;
64 typedef typename ImplTraits::HElementType HElementType ;
65 typedef typename ImplTraits::HBndSegType HBndSegType;
66 typedef typename ImplTraits::GEOElementType GEOElementType;
67 typedef typename ImplTraits::IMPLElementType IMPLElementType;
68 typedef typename ImplTraits::GEOFaceType GEOFaceType;
69 typedef typename ImplTraits::NeighbourPairType NeighbourPairType;
70 typedef typename ImplTraits::BNDFaceType BNDFaceType;
72 typedef typename ALU3dImplTraits< tetra, Comm >::GEOElementType GEOTetraElementType;
73 typedef typename ALU3dImplTraits< tetra, Comm >::BNDFaceType GEOTriangleBndType;
74 typedef typename ALU3dImplTraits< hexa, Comm >::GEOElementType GEOHexaElementType;
75 typedef typename ALU3dImplTraits< hexa, Comm >::BNDFaceType GEOQuadBndType;
77 typedef ALU3dGridFaceInfo< dim, dimworld, GridImp::elementType, Comm > FaceInfoType;
79 typedef typename std::conditional<
80 tetra == GridImp::elementType,
87 enum { numFaces = (dim==3) ? EntityCount<GridImp::elementType>::numFaces : (GridImp::elementType==tetra ? 3 : 4) };
88 enum { numVerticesPerFace =
89 GeometryInfoType::numVerticesPerFace };
90 enum { numVertices = (dim==3) ? EntityCount<GridImp::elementType>::numVertices : (GridImp::elementType==tetra ? 3 : 4)};
98 enum IntersectionIteratorType { IntersectionLeaf , IntersectionLevel, IntersectionBoth };
104 typedef ALUTwists< (dim == 3 ) ? GridImp::elementType == tetra ? 3 : 4 : 2, dim-1 > Twists;
105 typedef typename Twists::Twist Twist;
204 int outsideLevel ()
const {
return connector_.outsideLevel(); }
209 return (
connector_.conformanceState() == FaceInfoType::CONFORMING);
218 return this->
getItem().weight();
224 template<
class EntityType >
void done (
const EntityType &en ) { done(); }
227 void setFirstItem(
const HElementType & elem,
int wLevel);
230 void setInteriorItem(
const HElementType & elem,
231 const BNDFaceType& bnd,
int wLevel);
234 void first(
const EntityImp& en,
int wLevel,
const GridImp& grid );
237 void setNewFace(
const GEOFaceType& newFace);
241 void setGhostFace(
const GEOFaceType& newFace);
245 void buildLocalGeometries()
const;
248 const typename ALU3dImplTraits< tetra, Comm >::GEOFaceType *
249 getFace (
const GEOTriangleBndType &bnd,
int index )
const;
252 const typename ALU3dImplTraits< hexa, Comm >::GEOFaceType *
253 getFace (
const GEOQuadBndType &bnd,
int index )
const;
256 const typename ALU3dImplTraits< tetra, Comm >::GEOFaceType *
257 getFace (
const GEOTetraElementType &elem,
int index )
const;
259 const typename ALU3dImplTraits< hexa, Comm >::GEOFaceType *
260 getFace (
const GEOHexaElementType &elem,
int index )
const;
265 mutable GeometryInfoType geoProvider_;
276 mutable int innerLevel_;
279 mutable GeometryImpl intersectionGlobal_;
280 mutable LocalGeometryImpl intersectionSelfLocal_;
281 mutable LocalGeometryImpl intersectionNeighborLocal_;
288 void invalidate() { done(); }
290 unsigned int refCount_;
293template<
class Gr
idImp>
294class ALU3dGridLevelIntersectionIterator :
295public ALU3dGridIntersectionIterator<GridImp>
297 enum { dim = GridImp::dimension };
298 enum { dimworld = GridImp::dimensionworld };
300 typedef typename GridImp::MPICommunicatorType Comm;
302 typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits;
304 typedef typename ImplTraits::HElementType HElementType ;
305 typedef typename ImplTraits::GEOElementType GEOElementType;
306 typedef typename ImplTraits::IMPLElementType IMPLElementType;
307 typedef typename ImplTraits::GEOFaceType GEOFaceType;
308 typedef typename ImplTraits::NeighbourPairType NeighbourPairType;
309 typedef typename ImplTraits::BNDFaceType BNDFaceType;
311 typedef ALU3dGridFaceInfo< dim, dimworld, GridImp::elementType, Comm > FaceInfoType;
313 typedef typename std::conditional<
314 tetra == GridImp::elementType,
315 ALU3dGridGeometricFaceInfoTetra< dim, dimworld, Comm >,
316 ALU3dGridGeometricFaceInfoHexa< dim, dimworld, Comm > >::type GeometryInfoType;
318 typedef ElementTopologyMapping<GridImp::elementType> ElementTopo;
319 typedef FaceTopologyMapping<GridImp::elementType> FaceTopo;
321 enum { numFaces = (dim==3) ? EntityCount<GridImp::elementType>::numFaces : (GridImp::elementType==tetra ? 3 : 4) };
322 enum { numVerticesPerFace =
323 GeometryInfoType::numVerticesPerFace };
324 enum { numVertices = (dim==3) ? EntityCount<GridImp::elementType>::numVertices : (GridImp::elementType==tetra ? 3 : 4)};
326 typedef ALU3dGridIntersectionIterator<GridImp> BaseType;
327 typedef ALU3dGridLevelIntersectionIterator<GridImp> ThisType;
329 typedef typename BaseType :: EntityImp EntityImp;
331 friend class ALU3dGridEntity<0,dim,GridImp>;
332 friend class IntersectionIteratorWrapper<GridImp,ThisType>;
334 using BaseType :: item_;
335 using BaseType :: ghost_;
336 using BaseType :: grid_;
337 using BaseType :: innerLevel_;
338 using BaseType :: index_;
339 using BaseType :: connector_;
340 using BaseType :: geoProvider_;
341 using BaseType :: boundary;
342 using BaseType :: done ;
343 using BaseType :: getFace;
344 using BaseType :: neighbor ;
348 ALU3dGridLevelIntersectionIterator();
351 ALU3dGridLevelIntersectionIterator(
const ThisType & org);
354 void assign(
const ThisType & org);
360 void first(
const EntityImp& en,
int wLevel,
const GridImp& grid );
363 bool neighbor ()
const;
368 alugrid_assert ( ( !
connector_.conformingRefinement() ) ?
369 ( !neighbor() || this->
connector_.conformanceState() == FaceInfoType::CONFORMING ) :
true );
378 void setNewFace(
const GEOFaceType& newFace);
381 void setFirstItem(
const HElementType & elem,
int wLevel);
384 void setInteriorItem(
const HElementType & elem,
385 const BNDFaceType& bnd,
int wLevel);
396template <
class InternalIteratorType >
397class ALU3dGridTreeIterator
400 typedef typename InternalIteratorType :: val_t val_t;
403 template <
class Gr
idImp,
int dim,
int codim>
407 template <
class ItemType>
408 static int getLevel(
const GridImp & grid,
const ItemType & item,
int level )
410 alugrid_assert ( & item );
411 return (level < 0) ? item.level() : level;
416 template <
class Gr
idImp,
int dim>
417 class GetLevel<GridImp,dim,0>
420 template <
class ItemType>
421 static int getLevel(
const GridImp & grid,
const ItemType & item,
int level )
427 template <
class Gr
idImp,
int dim>
428 class GetLevel<GridImp, dim, dim>
431 template <
class ItemType>
432 static int getLevel(
const GridImp & grid,
const ItemType & item,
int level)
434 return (level < 0) ? grid.getLevelOfLeafVertex(item) : level;
440 template <
class Gr
idImp,
class IteratorImp>
441 void firstItem(
const GridImp & grid, IteratorImp & it,
int level )
443 InternalIteratorType & iter = it.internalIterator();
445 ValidItem<IteratorImp::codimension, GridImp> validate;
446 while(!validate(grid,iter))
457 alugrid_assert ( iter.size() > 0 );
458 setItem(grid,it,iter,level);
467 template <
class Gr
idImp,
class IteratorImp>
468 void setItem (
const GridImp & grid, IteratorImp & it, InternalIteratorType & iter,
int level)
470 enum { codim = IteratorImp :: codimension };
471 val_t & item = iter.item();
472 alugrid_assert ( item.first || item.second );
475 it.updateEntityPointer( item.first ,
476 GetLevel<GridImp,GridImp::dimension,codim>::getLevel(grid, *(item.first) , level) );
479 it.updateGhostPointer( *item.second );
483 template <
class Gr
idImp,
class IteratorImp>
484 void incrementIterator(
const GridImp & grid, IteratorImp & it,
int level)
487 InternalIteratorType & iter = it.internalIterator();
488 ValidItem<IteratorImp::codimension, GridImp> validate;
498 }
while(!(validate(grid,iter) ) );
500 setItem(grid,it,iter,level);
506 template <
int codim,
class Gr
idImp>
509 bool operator()(
const GridImp & grid, InternalIteratorType & iter)
511 if(GridImp::dimension ==3 || iter.done())
return true;
512 else if (GridImp::dimension == 2)
514 typedef typename ALU3dImplTraits<GridImp::elementType, typename GridImp::MPICommunicatorType>::template Codim<GridImp::dimension, codim>::ImplementationType GEOElementType;
515 val_t & item = iter.item();
516 alugrid_assert ( item.first || item.second );
519 GEOElementType* elem =
static_cast<GEOElementType*
> (item.first);
525 else if( item.second )
532 template <
class Gr
idImp>
533 struct ValidItem<0, GridImp>
535 bool operator()(
const GridImp & grid, InternalIteratorType & iter)
550template<
int cd, PartitionIteratorType pitype,
class Gr
idImp>
552:
public ALU3dGridEntityPointer< cd, GridImp >,
553 public ALU3dGridTreeIterator<typename ALU3DSPACE IteratorSTI<
554 typename ALU3DSPACE IteratorElType< (GridImp::dimension == 2 && cd == 2) ? 3 : cd, typename GridImp::MPICommunicatorType >::val_t > >
557 enum { dim = GridImp::dimension };
558 enum { dimworld = GridImp::dimensionworld };
560 typedef typename GridImp::MPICommunicatorType Comm;
566 friend class ALU3dGrid< dim, dimworld, GridImp::elementType, Comm >;
568 friend class ALU3dGridTreeIterator<
569 typename ALU3DSPACE IteratorSTI<
570 typename ALU3DSPACE IteratorElType< (GridImp::dimension == 2 && cd == 2) ? 3 : cd, typename GridImp::MPICommunicatorType >::val_t >
573 typedef ALU3dGridEntityPointer< cd, GridImp >
BaseType;
576 typedef typename GridImp::template
Codim<cd>::Entity Entity;
584 typedef typename ALU3DSPACE IteratorElType< (GridImp::dimension == 2 && cd == 2) ? 3 : cd, Comm >::val_t val_t;
585 typedef typename ALU3DSPACE IteratorSTI< val_t > IteratorType ;
586 typedef IteratorType InternalIteratorType;
615 const GridImp &grid ()
const { alugrid_assert( grid_ );
return *grid_; }
618 const GridImp *grid_;
621 std::unique_ptr< IteratorType > iter_ ;
629 IteratorType & internalIterator ()
631 alugrid_assert ( iter_ );
643template<
int cdim, PartitionIteratorType pitype,
class Gr
idImp>
645:
public ALU3dGridEntityPointer< cdim, GridImp >,
646 public ALU3dGridTreeIterator<typename ALU3DSPACE IteratorSTI<
647 typename ALU3DSPACE IteratorElType< (GridImp::dimension == 2 && cdim == 2) ? 3 : cdim, typename GridImp::MPICommunicatorType >::val_t > >
649 enum { dim = GridImp :: dimension };
652 enum { codim = cdim };
654 typedef typename GridImp::MPICommunicatorType Comm;
656 typedef ALU3dGridEntityPointer< cdim, GridImp >
BaseType;
661 typedef typename ALU3DSPACE IteratorElType< (GridImp::dimension == 2 && cdim == 2) ? 3 : cdim, Comm >::val_t val_t;
662 typedef typename ALU3DSPACE IteratorSTI< val_t > IteratorType ;
663 friend class ALU3dGridTreeIterator< IteratorType > ;
665 typedef IteratorType InternalIteratorType;
694 const GridImp &grid ()
const { alugrid_assert( grid_ );
return *grid_; }
697 const GridImp *grid_;
700 std::unique_ptr< IteratorType > iter_;
703 void assign (
const ThisType & org);
709 InternalIteratorType & internalIterator ()
711 alugrid_assert ( iter_ );
718template<
class Gr
idImp>
719class ALU3dGridHierarchicIterator
720:
public ALU3dGridEntityPointer<0,GridImp>
723 typedef ALU3dGridHierarchicIterator<GridImp> ThisType;
724 enum { dim = GridImp::dimension };
726 typedef typename GridImp::MPICommunicatorType Comm;
728 typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits;
729 typedef typename ImplTraits::HElementType HElementType;
730 typedef typename ImplTraits::HBndSegType HBndSegType;
732 template <
class Po
interType,
class CommT >
733 class GhostElementStorage;
736 template <
class Po
interType >
737 class GhostElementStorage< PointerType, ALUGridNoComm >
740 GhostElementStorage() {}
741 explicit GhostElementStorage(
const PointerType& ) {}
742 PointerType& operator * () { PointerType* p = 0; alugrid_assert (
false ); abort();
return *p; }
743 const PointerType*
ghost ()
const {
return 0; }
744 PointerType* nextGhost ()
const {
return 0; }
745 PointerType* operator -> ()
const {
return 0; }
746 bool operator != (
const PointerType* )
const {
return false; }
747 bool operator ! ()
const {
return true ; }
748 GhostElementStorage& operator= (
const GhostElementStorage& ) {
return *
this; }
749 GhostElementStorage& operator= (
const PointerType* ) {
return *
this; }
750 bool valid ()
const {
return false; }
754 template <
class Po
interType >
755 class GhostElementStorage< PointerType, ALUGridMPIComm >
759 const HBndSegType * ghost_;
760 HBndSegType * nextGhost_;
762 GhostElementStorage() : ghost_( 0 ), nextGhost_( 0 ) {}
763 explicit GhostElementStorage(
const PointerType& gh ) : ghost_( &gh ), nextGhost_( 0 ) {}
764 GhostElementStorage(
const GhostElementStorage& org )
765 : ghost_( org.ghost_ ), nextGhost_( org.nextGhost_ ) {}
767 PointerType& operator * () { alugrid_assert ( nextGhost_ );
return *nextGhost_; }
768 const PointerType*
ghost ()
const {
return ghost_; }
769 PointerType* nextGhost ()
const {
return nextGhost_; }
770 PointerType* operator -> () {
return nextGhost_; }
771 bool operator != (
const PointerType* p )
const {
return (nextGhost_ != p); }
772 bool operator ! ()
const {
return nextGhost_ == 0; }
773 GhostElementStorage& operator= (
const GhostElementStorage& org)
776 nextGhost_ = org.nextGhost_;
779 GhostElementStorage& operator= (PointerType* p)
784 bool valid ()
const {
return (ghost_ != 0); }
788 typedef typename GridImp::template Codim<0>::Entity Entity;
789 typedef typename GridImp::ctype ctype;
792 ALU3dGridHierarchicIterator(
const HElementType & elem,
793 int maxlevel,
bool end );
796 ALU3dGridHierarchicIterator(
const HBndSegType& ghost,
801 ALU3dGridHierarchicIterator(
const ThisType &org);
804 ALU3dGridHierarchicIterator();
810 void releaseEntity () {}
813 ThisType & operator = (
const ThisType & org);
817 void assign(
const ThisType & org);
820 int getLevel(
const HElementType* item)
const;
823 int getLevel(
const HBndSegType* face)
const;
826 template <
class HItemType>
827 HItemType* goNextElement (
const HItemType* startElem, HItemType * oldEl);
830 const HElementType * elem_;
833 GhostElementStorage< HBndSegType, Comm > ghostElem_;
842#if COMPILE_ALUGRID_INLINE
843 #include "iterator.cc"
int level() const
ask for level of entities
Definition: entity.hh:510
Definition: faceutility.hh:367
Definition: faceutility.hh:323
Definition: iterator.hh:56
int indexInOutside() const
Definition: iterator_imp.cc:298
NormalType integrationOuterNormal(const FieldVector< alu3d_ctype, dim-1 > &local) const
Definition: iterator_imp.cc:348
NormalType unitOuterNormal(const FieldVector< alu3d_ctype, dim-1 > &local) const
Definition: iterator_imp.cc:385
size_t boundarySegmentIndex() const
return the boundary segment index
Definition: iterator_imp.cc:419
EntityImp outside() const
access neighbor
Definition: iterator_imp.cc:237
int boundaryId() const
return information about the Boundary
Definition: iterator_imp.cc:411
int level() const
return level of iterator (level of item)
Definition: iterator_imp.cc:502
Twist twistInInside() const
returns twist of face compared to inner element
Definition: iterator_imp.cc:305
int segmentId() const
return the segment id (non-consecutive)
Definition: iterator_imp.cc:429
const BNDFaceType * ghost_
current pointer to ghost face if iterator was started from ghost element
Definition: iterator.hh:271
const GEOFaceType & getItem() const
return current face
Definition: iterator.hh:213
NormalType outerNormal(const FieldVector< alu3d_ctype, dim-1 > &local) const
Definition: iterator_imp.cc:356
void increment()
increment iterator
Definition: iterator_imp.cc:181
LocalGeometry geometryInOutside() const
Definition: iterator_imp.cc:338
Geometry geometry() const
Definition: iterator_imp.cc:394
bool equals(const ALU3dGridIntersectionIterator< GridImp > &i) const
The copy constructor.
Definition: iterator_imp.cc:171
EntityImp inside() const
access entity where iteration started
Definition: iterator_imp.cc:254
const GridImp * grid_
pointer to grid implementation
Definition: iterator.hh:274
LocalGeometry geometryInInside() const
Definition: iterator_imp.cc:289
ALU3dGridIntersectionIterator(const bool levelIntersectionIterator=false)
The default Constructor.
Definition: iterator_imp.cc:26
FaceInfoType connector_
Definition: iterator.hh:264
Twist twistInOutside() const
returns twist of face compared to outer element
Definition: iterator_imp.cc:312
bool neighbor() const
return true if across the face an neighbor on leaf exists
Definition: iterator_imp.cc:274
GeometryType type() const
obtain the type of reference element for this intersection
Definition: iterator_imp.cc:403
void assign(const ALU3dGridIntersectionIterator< GridImp > &org)
assignment of iterators
Definition: iterator_imp.cc:145
const IMPLElementType * item_
current element from which we started the intersection iterator
Definition: iterator.hh:268
bool conforming() const
return true if intersection is conforming
Definition: iterator.hh:207
int weight() const
return communication weight
Definition: iterator.hh:216
Dune::Intersection< GridImp, Dune::ALU3dGridIntersectionIterator< GridImp > > Intersection
type of the intersection
Definition: iterator.hh:115
bool boundary() const
return true if intersection is with boundary.
Definition: iterator_imp.cc:268
int indexInInside() const
Definition: iterator_imp.cc:281
Leaf iterator.
Definition: iterator.hh:648
void increment()
prefix increment
Definition: iterator.cc:222
void releaseEntity()
release entity
Definition: iterator.hh:688
ThisType & operator=(const ThisType &org)
assignment of iterators
Definition: iterator.cc:185
ALU3dGridLeafIterator()
default constructor
Definition: iterator.hh:670
~ALU3dGridLeafIterator()
destructor deleting real iterator
Definition: iterator.cc:169
Definition: iterator.hh:556
void increment()
prefix increment
Definition: iterator.cc:117
void releaseEntity()
release entity
Definition: iterator.hh:607
ThisType & operator=(const ThisType &org)
assignment of iterators
Definition: iterator.cc:109
ALU3dGridLevelIterator< cd, pitype, GridImp > ThisType
typedef of my type
Definition: iterator.hh:580
ALU3dGridLevelIterator()
default constructor
Definition: iterator.hh:589
[ provides Dune::Grid ]
Definition: grid.hh:434
Definition: topology.hh:40
Definition: topology.hh:151
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:125
Class that wraps IntersectionIteratorImp of a grid and gets it's internal object from a object stack ...
Definition: intersectioniteratorwrapper.hh:23
Intersection of a mesh entity of codimension 0 ("element") with a "neighboring" element or with the d...
Definition: intersection.hh:164
Different resources needed by all grid implementations.
topology of a Cartesian grid
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:259
Provides proxy classes for IntersectionsIterators.
constexpr Ghost ghost
PartitionSet for the ghost partition.
Definition: partitionset.hh:284
Dune namespace.
Definition: alignedallocator.hh:13
void assign(T &dst, const T &src, bool mask)
masked Simd assignment (scalar version)
Definition: simd.hh:447
@ conforming
use only conforming bisection refinement
Definition: declaration.hh:25
Definition: alu3dinclude.hh:328
Static tag representing a codimension.
Definition: dimension.hh:24