00001 #ifndef DUNE_ALU3DGRIDENTITY_HH
00002 #define DUNE_ALU3DGRIDENTITY_HH
00003
00004
00005
00006
00007 #include <dune/grid/common/entity.hh>
00008 #include <dune/grid/common/intersectioniteratorwrapper.hh>
00009
00010
00011 #include "alu3dinclude.hh"
00012 #include "iterator.hh"
00013
00014 namespace Dune {
00015
00016 template<int cd, int dim, class GridImp>
00017 class ALU3dGridEntity;
00018 template<int cd, PartitionIteratorType pitype, class GridImp >
00019 class ALU3dGridLevelIterator;
00020 template<int cd, class GridImp >
00021 class ALU3dGridEntityPointer;
00022 template<int mydim, int coorddim, class GridImp>
00023 class ALU3dGridGeometry;
00024 template<class GridImp>
00025 class ALU3dGridHierarchicIterator;
00026 template<class GridImp>
00027 class ALU3dGridIntersectionIterator;
00028 template<int codim, PartitionIteratorType, class GridImp>
00029 class ALU3dGridLeafIterator;
00030 template<int dim, int dimworld, ALU3dGridElementType elType>
00031 class ALU3dGrid;
00032
00039 template<int cd, int dim, class GridImp>
00040 class ALU3dGridEntity :
00041 public EntityDefaultImplementation <cd,dim,GridImp,ALU3dGridEntity>
00042 {
00043
00044 template <class GridType, int cdim>
00045 struct GetLevel
00046 {
00047 template <class ItemType>
00048 static int getLevel(const GridType & grid, const ItemType & item )
00049 {
00050 return item.level();
00051 }
00052 };
00053
00054
00055
00056
00057 template <class GridType>
00058 struct GetLevel<GridType,3>
00059 {
00060 template <class ItemType>
00061 static int getLevel(const GridType & grid, const ItemType & item)
00062 {
00063 return (item.isLeafEntity()) ? grid.getLevelOfLeafVertex(item) : item.level();
00064 }
00065 };
00066
00067 enum { dimworld = GridImp::dimensionworld };
00068
00069 friend class ALU3dGrid < dim , dimworld, GridImp::elementType >;
00070 friend class ALU3dGridEntity < 0, dim, GridImp >;
00071 friend class ALU3dGridLevelIterator < cd, All_Partition, GridImp >;
00072
00073 friend class ALU3dGridHierarchicIndexSet<dim,dimworld,GridImp::elementType>;
00074
00075 public:
00076 typedef typename ALU3dImplTraits<GridImp::elementType>::template Codim<cd>::InterfaceType ElementType;
00077 typedef typename ALU3dImplTraits<GridImp::elementType>::template Codim<cd>::ImplementationType IMPLElementType;
00078
00079 typedef typename GridImp::template Codim<cd>::Entity Entity;
00080 typedef typename GridImp::template Codim<cd>::Geometry Geometry;
00081
00082 typedef ALU3dGridGeometry<dim-cd,GridImp::dimensionworld,GridImp> GeometryImp;
00083 typedef MakeableInterfaceObject<Geometry> GeometryObject;
00084
00085 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00086
00088 int level () const;
00089
00091 PartitionType partitionType() const;
00092
00094 ALU3dGridEntity(const GridImp &grid, int level);
00095
00097 ALU3dGridEntity(const ALU3dGridEntity & org);
00098
00100 const Geometry & geometry () const;
00101
00102
00103 void setElement(const ElementType & item);
00104 void setElement(const ElementType & item, const int level, int twist=0, int face = -1);
00105
00106
00107 void setElement(const ALU3DSPACE HElementType & el, const ALU3DSPACE VertexType & vx);
00108
00110 void setGhost(const ALU3DSPACE HBndSegType &ghost);
00111
00113 void removeElement ();
00114
00116 void reset ( int l );
00117
00119 bool equals ( const ALU3dGridEntity<cd,dim,GridImp> & org ) const;
00120
00122 void setEntity ( const ALU3dGridEntity<cd,dim,GridImp> & org );
00123
00124
00125 const IMPLElementType & getItem () const { return *item_; }
00126
00127 private:
00129 int getIndex () const;
00130
00132 PartitionType convertBndId(const ElementType & item) const
00133 {
00134 if(item.isGhost()) return GhostEntity;
00135 if(item.isBorder()) return BorderEntity;
00136 if(item.isInterior()) return InteriorEntity;
00137 return InteriorEntity;
00138 }
00139
00140
00141 const GridImp &grid_;
00142
00143 int level_;
00144 int gIndex_;
00145 int twist_;
00146 int face_;
00147
00148
00149 const IMPLElementType * item_;
00150
00152 mutable GeometryObject geo_;
00153 mutable GeometryImp & geoImp_;
00154
00155 mutable bool builtgeometry_;
00156
00157 mutable PartitionType partitionType_;
00158 };
00159
00173
00174
00175
00176
00177
00178
00179 template<int dim, class GridImp>
00180 class ALU3dGridEntity<0,dim,GridImp>
00181 : public EntityDefaultImplementation<0,dim,GridImp,ALU3dGridEntity>
00182 {
00183 enum { dimworld = GridImp::dimensionworld };
00184 typedef typename ALU3dImplTraits<GridImp::elementType>::GEOElementType GEOElementType;
00185 typedef typename ALU3dImplTraits<GridImp::elementType>::PLLBndFaceType PLLBndFaceType;
00186 typedef typename ALU3dImplTraits<GridImp::elementType>::IMPLElementType IMPLElementType;
00187
00188 enum { refine_element_t =
00189 ALU3dImplTraits<GridImp::elementType>::refine_element_t };
00190 enum { coarse_element_t =
00191 ALU3dImplTraits<GridImp::elementType>::coarse_element_t };
00192 enum { nosplit_element_t = ALU3dImplTraits<GridImp::elementType>::nosplit_element_t };
00193
00194 typedef typename ALU3dImplTraits<GridImp::elementType>::MarkRuleType MarkRuleType;
00195
00196 friend class ALU3dGrid < dim , dimworld, GridImp::elementType>;
00197 friend class ALU3dGridIntersectionIterator < GridImp >;
00198 friend class ALU3dGridIntersectionIterator < const GridImp >;
00199 friend class ALU3dGridHierarchicIterator < const GridImp >;
00200 friend class ALU3dGridHierarchicIterator < GridImp >;
00201 friend class ALU3dGridLevelIterator <0,All_Partition,GridImp>;
00202 friend class ALU3dGridLevelIterator <1,All_Partition,GridImp>;
00203 friend class ALU3dGridLevelIterator <2,All_Partition,GridImp>;
00204 friend class ALU3dGridLevelIterator <3,All_Partition,GridImp>;
00205 friend class ALU3dGridLeafIterator <0, All_Partition,GridImp>;
00206 friend class ALU3dGridLeafIterator <1, All_Partition,GridImp>;
00207 friend class ALU3dGridLeafIterator <2, All_Partition,GridImp>;
00208 friend class ALU3dGridLeafIterator <3, All_Partition,GridImp>;
00209
00210 friend class ALU3dGridHierarchicIndexSet<dim,dimworld,GridImp::elementType>;
00211
00212 typedef typename SelectType<
00213 SameType<GridImp,const ALU3dGrid<3, 3, tetra> >::value,
00214 ReferenceSimplex<alu3d_ctype, 3>,
00215 ReferenceCube<alu3d_ctype, 3>
00216 >::Type ReferenceElementType;
00217
00218 public:
00219 typedef typename GridImp::template Codim<0>::Geometry Geometry;
00220 typedef ALU3dGridGeometry<dim,dimworld,GridImp> GeometryImp;
00221 typedef MakeableInterfaceObject<Geometry> GeometryObject;
00222 typedef ALU3dGridIntersectionIterator<GridImp> IntersectionIteratorImp;
00223
00224 typedef LeafIntersectionIteratorWrapper <GridImp> ALU3dGridIntersectionIteratorType;
00225 typedef LeafIntersectionIteratorWrapper <GridImp> ALU3dGridLeafIntersectionIteratorType;
00226 typedef LevelIntersectionIteratorWrapper<GridImp> ALU3dGridLevelIntersectionIteratorType;
00227
00228 typedef typename GridImp::template Codim<0>::Entity Entity;
00229 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00230
00231 template <int cd>
00232 struct Codim
00233 {
00234 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
00235 };
00236
00238 ALU3dGridEntity(const GridImp &grid, int level);
00239
00241 ALU3dGridEntity(const ALU3dGridEntity & org);
00242
00244 int level () const ;
00245
00247 const Geometry & geometry () const;
00248
00250 PartitionType partitionType() const;
00251
00255 template<int cc> int count () const ;
00256
00259 template <int cc>
00260 typename Codim<cc>::EntityPointer entity (int i) const;
00261
00267 ALU3dGridLeafIntersectionIteratorType ileafbegin () const;
00268
00270 ALU3dGridLeafIntersectionIteratorType ileafend () const;
00271
00277 ALU3dGridLevelIntersectionIteratorType ilevelbegin () const;
00278
00280 ALU3dGridLevelIntersectionIteratorType ilevelend () const;
00281
00283 bool isLeaf () const;
00284
00287 EntityPointer father () const;
00288
00298 const Geometry & geometryInFather () const;
00299
00304 ALU3dGridHierarchicIterator<GridImp> hbegin (int maxlevel) const;
00305
00307 ALU3dGridHierarchicIterator<GridImp> hend (int maxlevel) const;
00308
00309
00310
00311
00313 bool wasRefined () const;
00314
00316 bool mightBeCoarsened () const;
00317
00319 bool hasBoundaryIntersections () const;
00320
00321
00325 bool mark( int refCount ) const;
00326
00328 int getMark() const;
00329
00333 void setElement(ALU3DSPACE HElementType &element);
00334
00336 void setGhost(ALU3DSPACE HBndSegType & ghost);
00337
00339 void reset ( int l );
00340
00342 void removeElement();
00343
00345 bool equals ( const ALU3dGridEntity<0,dim,GridImp> & org ) const;
00346
00347 void setEntity ( const ALU3dGridEntity<0,dim,GridImp> & org );
00348
00352 template<int cc> int getSubIndex (int i) const;
00353
00354
00355 const IMPLElementType & getItem () const { return *item_; }
00356
00357 private:
00359 int getIndex () const;
00360
00361
00362 const GridImp & grid_;
00363
00364
00365 mutable IMPLElementType *item_;
00366
00367 mutable bool isGhost_;
00368
00370 mutable GeometryObject geo_;
00371 mutable GeometryImp & geoImp_;
00372 mutable bool builtgeometry_;
00373
00374 int walkLevel_;
00375
00376 int level_;
00377
00378 mutable GeometryObject geoInFather_;
00379 mutable GeometryImp & geoInFatherImp_;
00380
00381
00382 bool isLeaf_;
00383
00384 const ReferenceElementType & refElem_;
00385 };
00386
00387
00388
00389
00390
00391
00395 template<int cd, class GridImp>
00396 class ALU3dGridEntityPointerBase :
00397 public EntityPointerDefaultImplementation <cd, GridImp, ALU3dGridEntityPointer<cd,GridImp> >
00398 {
00399 typedef ALU3dGridEntityPointerBase <cd,GridImp> ThisType;
00400 enum { dim = GridImp::dimension };
00401 enum { dimworld = GridImp::dimensionworld };
00402
00403 friend class ALU3dGridEntity<cd,dim,GridImp>;
00404 friend class ALU3dGridEntity< 0,dim,GridImp>;
00405 friend class ALU3dGrid < dim , dimworld, GridImp::elementType >;
00406
00407 typedef typename ALU3dImplTraits<GridImp::elementType>::template Codim<cd>::InterfaceType MyHElementType;
00408
00409 typedef ALU3DSPACE HBndSegType HBndSegType;
00410 typedef typename ALU3dImplTraits<GridImp::elementType>::BNDFaceType BNDFaceType;
00411 public:
00413 typedef typename GridImp::template Codim<cd>::Entity Entity;
00415 typedef MakeableInterfaceObject<Entity> EntityObject;
00416 typedef typename EntityObject :: ImplementationType EntityImp;
00417
00419 typedef ThisType ALU3dGridEntityPointerType;
00420
00422 typedef ALU3dGridEntityPointerBase<cd,GridImp> Base;
00423
00425 ALU3dGridEntityPointerBase(const GridImp & grid,
00426 const int level,
00427 const MyHElementType & item);
00428
00430 ALU3dGridEntityPointerBase(const GridImp & grid,
00431 const HBndSegType & ghostFace );
00432
00434 ALU3dGridEntityPointerBase(const ALU3dGridEntityPointerType & org);
00435
00437 ~ALU3dGridEntityPointerBase();
00438
00440 bool equals (const ALU3dGridEntityPointerType& i) const;
00441
00443 ThisType & operator = (const ThisType & org);
00444
00446 Entity & dereference () const ;
00447
00449 int level () const ;
00450
00451 protected:
00452
00453 void clone (const ALU3dGridEntityPointerType & org);
00454
00455
00456 void getEntity (const ALU3dGridEntityPointerType & org);
00457
00459 void done ();
00460
00463 ALU3dGridEntityPointerBase(const GridImp & grid, int level );
00464
00465
00466 void updateGhostPointer( HBndSegType & ghostFace );
00467
00468 void updateEntityPointer( MyHElementType * item , int level = -1 );
00469
00470
00471 const GridImp & grid_;
00472
00473
00474 MyHElementType * item_;
00475
00476
00477 mutable EntityObject * entity_;
00478
00479 EntityImp & entityImp () const {
00480 assert( entity_ );
00481 return grid_.getRealImplementation(*entity_);
00482 }
00483 };
00484
00488 template<class GridImp>
00489 class ALU3dGridEntityPointer<0,GridImp> :
00490 public ALU3dGridEntityPointerBase<0,GridImp>
00491 {
00492 enum { cd = 0 };
00493 typedef ALU3dGridEntityPointer <cd,GridImp> ThisType;
00494 enum { dim = GridImp::dimension };
00495 enum { dimworld = GridImp::dimensionworld };
00496
00497 friend class ALU3dGridEntity<cd,dim,GridImp>;
00498 friend class ALU3dGridEntity< 0,dim,GridImp>;
00499 friend class ALU3dGrid < dim , dimworld, GridImp::elementType >;
00500
00501 typedef typename ALU3dImplTraits<GridImp::elementType>::template Codim<cd>::InterfaceType MyHElementType;
00502
00503 typedef ALU3DSPACE HBndSegType HBndSegType;
00504 typedef typename ALU3dImplTraits<GridImp::elementType>::BNDFaceType BNDFaceType;
00505 public:
00507 typedef typename GridImp::template Codim<cd>::Entity Entity;
00508
00510 typedef ThisType ALU3dGridEntityPointerType;
00511
00513 ALU3dGridEntityPointer(const GridImp & grid,
00514 const MyHElementType & item)
00515 : ALU3dGridEntityPointerBase<cd,GridImp> (grid,-1,item) {}
00516
00518 ALU3dGridEntityPointer(const GridImp & grid,
00519 const HBndSegType & ghostFace )
00520 : ALU3dGridEntityPointerBase<cd,GridImp> (grid,ghostFace) {}
00521
00523 ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org)
00524 : ALU3dGridEntityPointerBase<cd,GridImp> (org) {}
00525
00526 protected:
00529 ALU3dGridEntityPointer(const GridImp & grid, int level )
00530 : ALU3dGridEntityPointerBase<cd,GridImp> (grid,level) {}
00531 };
00532
00533
00534 template<int cd, class GridImp>
00535 class ALU3dGridEntityPointer :
00536 public ALU3dGridEntityPointerBase<cd,GridImp>
00537 {
00538 typedef ALU3dGridEntityPointer <cd,GridImp> ThisType;
00539 enum { dim = GridImp::dimension };
00540 enum { dimworld = GridImp::dimensionworld };
00541
00542 friend class ALU3dGridEntity<cd,dim,GridImp>;
00543 friend class ALU3dGridEntity< 0,dim,GridImp>;
00544 friend class ALU3dGrid < dim , dimworld, GridImp::elementType >;
00545
00546 typedef typename ALU3dImplTraits<GridImp::elementType>::template Codim<cd>::InterfaceType MyHElementType;
00547
00548 typedef ALU3DSPACE HBndSegType HBndSegType;
00549 typedef typename ALU3dImplTraits<GridImp::elementType>::BNDFaceType BNDFaceType;
00550 public:
00552 typedef typename GridImp::template Codim<cd>::Entity Entity;
00553
00555 typedef ALU3dGridEntityPointer<cd,GridImp> ALU3dGridEntityPointerType;
00556
00558 ALU3dGridEntityPointer(const GridImp & grid,
00559 const int level,
00560 const MyHElementType & item,
00561 const int twist = 0,
00562 const int duneFace = -1
00563 );
00564
00566 ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org);
00567
00569 Entity & dereference () const ;
00570
00572 ThisType & operator = (const ThisType & org);
00573
00575 int level () const ;
00576
00577 protected:
00578
00579 void clone (const ALU3dGridEntityPointerType & org);
00580
00581 void updateEntityPointer( MyHElementType * item , int level );
00582
00585 ALU3dGridEntityPointer(const GridImp & grid, int level )
00586 : ALU3dGridEntityPointerBase<cd,GridImp> (grid,level)
00587 , level_(level)
00588 , twist_(0) , face_(-1) {}
00589
00590
00591 int level_;
00592
00593 int twist_;
00594
00595 int face_;
00596 };
00597
00598 }
00599
00600 #include "entity_imp.cc"
00601
00602 #endif