00001 #ifndef DUNE_ALU3DGRIDITERATOR_HH
00002 #define DUNE_ALU3DGRIDITERATOR_HH
00003
00004
00005
00006
00007 #include <dune/grid/common/grid.hh>
00008 #include <dune/grid/common/intersectioniteratorwrapper.hh>
00009
00010
00011 #include "alu3dinclude.hh"
00012 #include "topology.hh"
00013 #include "faceutility.hh"
00014 #include "alu3diterators.hh"
00015 #include "memory.hh"
00016
00017 namespace Dune {
00018
00019 template<int cd, int dim, class GridImp>
00020 class ALU3dGridEntity;
00021 template<int cd, PartitionIteratorType pitype, class GridImp >
00022 class ALU3dGridLevelIterator;
00023 template<int cd, class GridImp >
00024 class ALU3dGridEntityPointer;
00025 template<int mydim, int coorddim, class GridImp>
00026 class ALU3dGridGeometry;
00027 template<class GridImp>
00028 class ALU3dGridHierarchicIterator;
00029 template<class GridImp>
00030 class ALU3dGridIntersectionIterator;
00031 template<int codim, PartitionIteratorType pitype, class GridImp>
00032 class ALU3dGridLeafIterator;
00033 template<int dim, int dimworld, ALU3dGridElementType elType>
00034 class ALU3dGrid;
00035 template <ALU3dGridElementType type>
00036 class ALU3dGridFaceInfo;
00037 template <ALU3dGridElementType elType>
00038 class ALU3dGridGeometricFaceInfo;
00039
00040
00041
00042
00043
00051 template<class GridImp>
00052 class ALU3dGridIntersectionIterator
00053 : public IntersectionIteratorDefaultImplementation <GridImp,ALU3dGridIntersectionIterator>
00054 {
00055 enum { dim = GridImp::dimension };
00056 enum { dimworld = GridImp::dimensionworld };
00057
00058 typedef ALU3dImplTraits<GridImp::elementType> ImplTraits;
00059 typedef typename ImplTraits::GEOElementType GEOElementType;
00060 typedef typename ImplTraits::IMPLElementType IMPLElementType;
00061 typedef typename ImplTraits::GEOFaceType GEOFaceType;
00062 typedef typename ImplTraits::NeighbourPairType NeighbourPairType;
00063 typedef typename ImplTraits::PLLBndFaceType PLLBndFaceType;
00064 typedef typename ImplTraits::BNDFaceType BNDFaceType;
00065
00066 typedef ALU3dGridFaceInfo<GridImp::elementType> FaceInfoType;
00067 typedef typename std::auto_ptr<FaceInfoType> FaceInfoPointer;
00068
00069 typedef typename SelectType<
00070 is_same<Int2Type<tetra>, Int2Type<GridImp::elementType> >::value,
00071 ALU3dGridGeometricFaceInfoTetra,
00072 ALU3dGridGeometricFaceInfoHexa
00073 >::Type GeometryInfoType;
00074
00075 typedef ElementTopologyMapping<GridImp::elementType> ElementTopo;
00076 typedef FaceTopologyMapping<GridImp::elementType> FaceTopo;
00077
00078 enum { numFaces = EntityCount<GridImp::elementType>::numFaces };
00079 enum { numVerticesPerFace =
00080 EntityCount<GridImp::elementType>::numVerticesPerFace };
00081 enum { numVertices = EntityCount<GridImp::elementType>::numVertices };
00082
00083 typedef ALU3dGridIntersectionIterator<GridImp> ThisType;
00084
00085 friend class ALU3dGridEntity<0,dim,GridImp>;
00086 friend class IntersectionIteratorWrapper<GridImp,ThisType>;
00087
00088 protected:
00089 enum IntersectionIteratorType { IntersectionLeaf , IntersectionLevel, IntersectionBoth };
00090
00091 public:
00092 typedef typename GridImp::template Codim<0>::Entity Entity;
00093 typedef typename GridImp::template Codim<1>::Geometry Geometry;
00094 typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry;
00095
00096 typedef ALU3dGridGeometry<dim-1,dimworld,GridImp> GeometryImp;
00097 typedef MakeableInterfaceObject<Geometry> GeometryObject;
00098
00099 typedef FieldVector<alu3d_ctype, dimworld> NormalType;
00100 typedef ALU3dGridEntityPointer<0,GridImp> EntityPointer;
00101
00102 typedef ALUMemoryProvider< ThisType > StorageType;
00103
00106 ALU3dGridIntersectionIterator(const GridImp & grid,
00107 ALU3DSPACE HElementType *el,
00108 int wLevel,bool end=false);
00109
00110 ALU3dGridIntersectionIterator(const GridImp & grid,int wLevel);
00111
00113 ALU3dGridIntersectionIterator(const ALU3dGridIntersectionIterator<GridImp> & org);
00114
00116 void assign(const ALU3dGridIntersectionIterator<GridImp> & org);
00117
00119 bool equals (const ALU3dGridIntersectionIterator<GridImp> & i) const;
00120
00122 void increment ();
00123
00125 EntityPointer outside() const;
00126
00128 EntityPointer inside() const;
00129
00131 bool boundary () const;
00132
00134 bool neighbor () const;
00135
00137 bool levelNeighbor () const;
00138
00140 bool leafNeighbor () const;
00141
00143 int boundaryId () const;
00144
00149 const LocalGeometry & intersectionSelfLocal () const;
00150
00155 const Geometry & intersectionGlobal () const;
00156
00159 int numberInSelf () const;
00160
00164 const LocalGeometry & intersectionNeighborLocal () const;
00165
00168 int numberInNeighbor () const;
00169
00171 int twistInSelf() const;
00172
00174 int twistInNeighbor() const;
00175
00178 NormalType & unitOuterNormal (const FieldVector<alu3d_ctype, dim-1>& local) const ;
00179
00182 NormalType & outerNormal (const FieldVector<alu3d_ctype, dim-1>& local) const;
00183
00186 NormalType & integrationOuterNormal (const FieldVector<alu3d_ctype, dim-1>& local) const;
00187
00189 int level () const;
00190
00192 bool conforming () const
00193 {
00194 return (connector_.conformanceState() == FaceInfoType::CONFORMING);
00195 }
00196
00197 protected:
00198
00199 void done () ;
00200
00201 void outputElementInfo() const;
00202
00203 void outputFaceInfo() const;
00204
00205 template <typename T>
00206 void printToScreen(int duneIdx, int aluIdx,
00207 const T& info) const;
00208
00209 void printToScreen(int duneIdx, int aluIdx) const;
00210
00211
00212 NormalType convert2FV(const alu3d_ctype (&p)[3]) const;
00213
00214
00215 void setFirstItem(const ALU3DSPACE HElementType & elem, int wLevel);
00216
00217
00218 template <class EntityType>
00219 void first(const EntityType & en, int wLevel);
00220
00221
00222 void setNewFace(const GEOFaceType& newFace);
00223
00224 void buildLocalGeometries() const;
00225
00226 void buildGlobalGeometry() const;
00227
00228
00229 const typename ALU3dImplTraits<tetra>::GEOFaceType*
00230 getFace(const ALU3DSPACE GEOTetraElementType& elem, int index) const;
00231
00232 const typename ALU3dImplTraits<hexa>::GEOFaceType*
00233 getFace(const ALU3DSPACE GEOHexaElementType& elem, int index) const;
00234
00237 mutable FaceInfoType connector_;
00238 mutable GeometryInfoType geoProvider_;
00239
00240
00241 const GridImp & grid_;
00242
00244 const IMPLElementType* item_;
00245
00246 mutable int innerLevel_;
00247 mutable int index_;
00248
00249 mutable bool generatedGlobalGeometry_;
00250 mutable bool generatedLocalGeometries_;
00251
00252 mutable GeometryObject intersectionGlobal_;
00253 mutable GeometryImp & intersectionGlobalImp_;
00254 mutable GeometryObject intersectionSelfLocal_;
00255 mutable GeometryImp & intersectionSelfLocalImp_;
00256 mutable GeometryObject intersectionNeighborLocal_;
00257 mutable GeometryImp & intersectionNeighborLocalImp_;
00258
00259
00260 mutable NormalType unitOuterNormal_;
00261
00262
00263 bool done_;
00264 };
00265
00266 template<class GridImp>
00267 class ALU3dGridLevelIntersectionIterator :
00268 public ALU3dGridIntersectionIterator<GridImp>
00269 {
00270 enum { dim = GridImp::dimension };
00271 enum { dimworld = GridImp::dimensionworld };
00272
00273 typedef ALU3dImplTraits<GridImp::elementType> ImplTraits;
00274 typedef typename ImplTraits::GEOElementType GEOElementType;
00275 typedef typename ImplTraits::IMPLElementType IMPLElementType;
00276 typedef typename ImplTraits::GEOFaceType GEOFaceType;
00277 typedef typename ImplTraits::NeighbourPairType NeighbourPairType;
00278 typedef typename ImplTraits::PLLBndFaceType PLLBndFaceType;
00279 typedef typename ImplTraits::BNDFaceType BNDFaceType;
00280
00281 typedef ALU3dGridFaceInfo<GridImp::elementType> FaceInfoType;
00282 typedef typename std::auto_ptr<FaceInfoType> FaceInfoPointer;
00283
00284 typedef typename SelectType<
00285 is_same<Int2Type<tetra>, Int2Type<GridImp::elementType> >::value,
00286 ALU3dGridGeometricFaceInfoTetra,
00287 ALU3dGridGeometricFaceInfoHexa
00288 >::Type GeometryInfoType;
00289
00290 typedef ElementTopologyMapping<GridImp::elementType> ElementTopo;
00291 typedef FaceTopologyMapping<GridImp::elementType> FaceTopo;
00292
00293 enum { numFaces = EntityCount<GridImp::elementType>::numFaces };
00294 enum { numVerticesPerFace =
00295 EntityCount<GridImp::elementType>::numVerticesPerFace };
00296 enum { numVertices = EntityCount<GridImp::elementType>::numVertices };
00297
00298 typedef ALU3dGridLevelIntersectionIterator<GridImp> ThisType;
00299
00300 friend class ALU3dGridEntity<0,dim,GridImp>;
00301 friend class IntersectionIteratorWrapper<GridImp,ThisType>;
00302
00303 public:
00304 typedef ALUMemoryProvider< ThisType > StorageType;
00305
00308 ALU3dGridLevelIntersectionIterator(const GridImp & grid,
00309 ALU3DSPACE HElementType *el,
00310 int wLevel,bool end=false);
00311
00312 ALU3dGridLevelIntersectionIterator(const GridImp & grid,int wLevel);
00313
00315 ALU3dGridLevelIntersectionIterator(const ThisType & org);
00316
00318 void assign(const ThisType & org);
00319
00321 void increment ();
00322
00323
00324 template <class EntityType>
00325 void first(const EntityType & en, int wLevel);
00326
00328 bool neighbor () const;
00329
00331 bool levelNeighbor () const;
00332
00334 bool leafNeighbor () const;
00335
00337 bool conforming () const
00338 {
00339 assert( this->connector_.conformanceState() == FaceInfoType::CONFORMING );
00340 return true;
00341 }
00342 private:
00343
00344 void setNewFace(const GEOFaceType& newFace);
00345
00346
00347 void setFirstItem(const ALU3DSPACE HElementType & elem, int wLevel);
00348
00349 bool levelNeighbor_;
00350 bool isLeafItem_;
00351 };
00352
00354
00355
00356
00358 template <class InternalIteratorType >
00359 struct ALU3dGridTreeIterator
00360 {
00361 typedef typename InternalIteratorType :: val_t val_t;
00362
00363
00364 template <class GridImp, int codim>
00365 struct GetLevel
00366 {
00367 template <class ItemType>
00368 static int getLevel(const GridImp & grid, const ItemType & item, int level )
00369 {
00370 assert( & item );
00371 return (level < 0) ? item.level() : level;
00372 }
00373 };
00374
00375
00376 template <class GridImp>
00377 struct GetLevel<GridImp,0>
00378 {
00379 template <class ItemType>
00380 static int getLevel(const GridImp & grid, const ItemType & item, int level )
00381 {
00382 return level;
00383 }
00384 };
00385
00386 template <class GridImp>
00387 struct GetLevel<GridImp,3>
00388 {
00389 template <class ItemType>
00390 static int getLevel(const GridImp & grid, const ItemType & item, int level)
00391 {
00392 return (level < 0) ? grid.getLevelOfLeafVertex(item) : level;
00393 }
00394 };
00395
00396 protected:
00397
00398 template <class GridImp, class IteratorImp>
00399 void firstItem(const GridImp & grid, IteratorImp & it, int level )
00400 {
00401 InternalIteratorType & iter = it.internalIterator();
00402 iter.first();
00403 if( ! iter.done() )
00404 {
00405 assert( iter.size() > 0 );
00406 setItem(grid,it,iter,level);
00407 }
00408 else
00409 {
00410 it.removeIter();
00411 }
00412 }
00413
00414
00415 template <class GridImp, class IteratorImp>
00416 void setItem (const GridImp & grid, IteratorImp & it, InternalIteratorType & iter, int level)
00417 {
00418 enum { codim = IteratorImp :: codimension };
00419 val_t & item = iter.item();
00420 assert( item.first || item.second );
00421 if( item.first )
00422 {
00423 it.updateEntityPointer( item.first ,
00424 GetLevel<GridImp,codim>::getLevel(grid, *(item.first) , level) );
00425 }
00426 else
00427 it.updateGhostPointer( *item.second );
00428 }
00429
00430
00431 template <class GridImp, class IteratorImp>
00432 void incrementIterator(const GridImp & grid, IteratorImp & it, int level)
00433 {
00434
00435 InternalIteratorType & iter = it.internalIterator();
00436
00437 iter.next();
00438
00439 if(iter.done())
00440 {
00441 it.removeIter();
00442 return ;
00443 }
00444
00445 setItem(grid,it,iter,level);
00446 return ;
00447 }
00448 };
00449
00450
00451
00452
00453
00457 template<int cd, PartitionIteratorType pitype, class GridImp>
00458 class ALU3dGridLevelIterator :
00459 public ALU3dGridEntityPointer <cd,GridImp> ,
00460 public LevelIteratorDefaultImplementation <cd,pitype,GridImp,ALU3dGridLevelIterator> ,
00461 public ALU3dGridTreeIterator< ALU3DSPACE ALU3dGridLevelIteratorWrapper<cd,pitype> >
00462 {
00463 enum { dim = GridImp::dimension };
00464 enum { dimworld = GridImp::dimensionworld };
00465
00466 friend class ALU3dGridEntity<3,dim,GridImp>;
00467 friend class ALU3dGridEntity<2,dim,GridImp>;
00468 friend class ALU3dGridEntity<1,dim,GridImp>;
00469 friend class ALU3dGridEntity<0,dim,GridImp>;
00470 friend class ALU3dGrid < dim , dimworld, GridImp::elementType >;
00471
00472 friend class ALU3dGridTreeIterator< ALU3DSPACE ALU3dGridLevelIteratorWrapper<cd,pitype> > ;
00473 public:
00474 typedef typename GridImp::template Codim<cd>::Entity Entity;
00475 typedef ALU3DSPACE VertexListType VertexListType;
00476
00478 typedef ALU3dGridLevelIterator<cd,pitype,GridImp> ThisType;
00479
00480 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper<cd,pitype> IteratorType;
00481 typedef IteratorType InternalIteratorType;
00482 typedef typename ALU3DSPACE IteratorElType<cd>::val_t val_t;
00483
00485 ALU3dGridLevelIterator(const GridImp & grid, int level, bool);
00486
00488 ALU3dGridLevelIterator(const GridImp & grid, int level);
00489
00491 ALU3dGridLevelIterator(const ThisType & org);
00492
00493
00494 ~ALU3dGridLevelIterator();
00495
00497 void increment ();
00498
00500 Entity & dereference () const;
00501
00503 ThisType & operator = (const ThisType & org);
00504 private:
00506 void assign (const ThisType & org);
00507
00508
00509 int level_;
00510
00511
00512 IteratorType * iter_ ;
00513
00514
00515 void removeIter ();
00516
00517 IteratorType & internalIterator ()
00518 {
00519 assert( iter_ );
00520 return *iter_;
00521 }
00522 };
00523
00524
00525
00526
00527
00528
00529
00531 template<int cdim, PartitionIteratorType pitype, class GridImp>
00532 class ALU3dGridLeafIterator :
00533 public LeafIteratorDefaultImplementation<cdim, pitype, GridImp, ALU3dGridLeafIterator>,
00534 public ALU3dGridEntityPointer<cdim,GridImp> ,
00535 public ALU3dGridTreeIterator< ALU3DSPACE ALU3dGridLeafIteratorWrapper<cdim, pitype> >
00536 {
00537 enum { dim = GridImp :: dimension };
00538
00539 friend class ALU3dGridEntity<cdim,dim,GridImp>;
00540 enum { codim = cdim };
00541
00542 friend class ALU3dGridTreeIterator< ALU3DSPACE ALU3dGridLeafIteratorWrapper<cdim, pitype> > ;
00543
00544 public:
00545 typedef typename GridImp::template Codim<cdim>::Entity Entity;
00546
00547
00548 typedef typename ALU3DSPACE ALU3dGridLeafIteratorWrapper<cdim, pitype> IteratorType;
00549 typedef IteratorType InternalIteratorType;
00550 typedef typename ALU3DSPACE IteratorElType<cdim>::val_t val_t;
00551
00552 typedef ALU3dGridLeafIterator<cdim, pitype, GridImp> ThisType;
00553
00555 ALU3dGridLeafIterator(const GridImp & grid, int level);
00556
00558 ALU3dGridLeafIterator(const GridImp & grid, int level , bool isBegin);
00559
00561 ALU3dGridLeafIterator(const ThisType & org);
00562
00564 ~ALU3dGridLeafIterator();
00565
00567 void increment ();
00568
00570 Entity & dereference () const;
00571
00573 ThisType & operator = (const ThisType & org);
00574
00575 private:
00576
00577 IteratorType * iter_;
00578
00580 void assign (const ThisType & org);
00581
00582
00583 void removeIter () ;
00584
00585
00586 InternalIteratorType & internalIterator ()
00587 {
00588 assert( iter_ );
00589 return *iter_;
00590 }
00591 };
00592
00593
00594
00595 template<class GridImp>
00596 class ALU3dGridHierarchicIterator :
00597 public ALU3dGridEntityPointer<0,GridImp> ,
00598 public HierarchicIteratorDefaultImplementation <GridImp,ALU3dGridHierarchicIterator>
00599 {
00600 enum { dim = GridImp::dimension };
00601 typedef ALU3dGridHierarchicIterator<GridImp> ThisType;
00602 public:
00603 typedef typename GridImp::template Codim<0>::Entity Entity;
00604 typedef typename GridImp::ctype ctype;
00605
00607 ALU3dGridHierarchicIterator(const GridImp &grid,
00608 const ALU3DSPACE HElementType & elem, int maxlevel, bool end );
00609
00611 ALU3dGridHierarchicIterator(const ALU3dGridHierarchicIterator<GridImp> &org);
00612
00614 void increment();
00615
00617 Entity & dereference () const;
00618
00620 ThisType & operator = (const ThisType & org);
00621
00622 private:
00623
00624 ALU3DSPACE HElementType * goNextElement (ALU3DSPACE HElementType * oldEl);
00625
00627 const ALU3DSPACE HElementType * elem_;
00628
00630 int maxlevel_;
00631 };
00632
00633
00634 }
00635
00636 #include "iterator_imp.cc"
00637
00638 #endif