alugrid/3d/entity.hh

00001 #ifndef DUNE_ALU3DGRIDENTITY_HH
00002 #define DUNE_ALU3DGRIDENTITY_HH
00003 
00004 // System includes
00005 
00006 // Dune includes
00007 #include <dune/grid/common/entity.hh>
00008 #include <dune/grid/common/intersectioniteratorwrapper.hh>
00009 
00010 // Local includes
00011 #include "alu3dinclude.hh"
00012 #include "iterator.hh"
00013 
00014 namespace Dune {
00015   // Forward declarations
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   // default just returns level 
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   // for leaf vertices the level is somewhat difficult to obtain, because
00055   // this the maximum of levels of elements that have this vertex as sub
00056   // entity
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 
00103   GeometryType type () const;
00104 
00105   // set element as normal entity
00106   void setElement(const ElementType & item); 
00107   void setElement(const ElementType & item, const int level, int twist=0, int face = -1); 
00108 
00109   // not needed anymore 
00110   void setElement(const ALU3DSPACE HElementType & el, const ALU3DSPACE VertexType & vx);
00111   
00113   void setGhost(const ALU3DSPACE HBndSegType  &ghost);
00114 
00116   void removeElement (); 
00117   
00119   void reset ( int l ); 
00120   
00122   bool equals ( const ALU3dGridEntity<cd,dim,GridImp> & org ) const;
00123   
00125   void setEntity ( const ALU3dGridEntity<cd,dim,GridImp> & org );
00126   
00127   // return reference to internal item 
00128   const IMPLElementType & getItem () const { return *item_; }
00129 
00130 private: 
00132   int getIndex () const;
00133 
00135   PartitionType convertBndId(const ElementType & item) const
00136   {
00137     if(item.isGhost()) 
00138     {
00139       return GhostEntity;
00140     }
00141     else if(item.isBorder()) 
00142     {
00143       return BorderEntity;
00144     }
00145     else 
00146     {
00147       assert( item.isInterior() ); 
00148       return InteriorEntity;
00149     }
00150   }
00151 
00152   // the grid this entity belongs to
00153   const GridImp &grid_;
00154 
00155   int level_;  
00156   int gIndex_; 
00157   int twist_;  
00158   int face_;   
00159 
00160   // corresponding ALU3dGridElement
00161   const IMPLElementType * item_;
00162     
00164   mutable GeometryObject geo_;
00165   GeometryImp & geoImp_;
00166   
00167   mutable bool builtgeometry_;         
00168 
00169   mutable PartitionType partitionType_;
00170 };
00171 
00185 //***********************
00186 //  
00187 //  --ALU3dGridEntity
00188 //  --0Entity
00189 //
00190 //***********************
00191 template<int dim, class GridImp>
00192 class ALU3dGridEntity<0,dim,GridImp> 
00193 : public EntityDefaultImplementation<0,dim,GridImp,ALU3dGridEntity>
00194 {
00195   enum { dimworld = GridImp::dimensionworld };
00196   typedef typename ALU3dImplTraits<GridImp::elementType>::GEOElementType GEOElementType;
00197   typedef typename ALU3dImplTraits<GridImp::elementType>::PLLBndFaceType PLLBndFaceType;
00198   typedef typename ALU3dImplTraits<GridImp::elementType>::IMPLElementType IMPLElementType;
00199 
00200   enum { refine_element_t = 
00201          ALU3dImplTraits<GridImp::elementType>::refine_element_t };
00202   enum { coarse_element_t = 
00203          ALU3dImplTraits<GridImp::elementType>::coarse_element_t };
00204   enum { nosplit_element_t = ALU3dImplTraits<GridImp::elementType>::nosplit_element_t };
00205 
00206   typedef typename ALU3dImplTraits<GridImp::elementType>::MarkRuleType MarkRuleType;
00207 
00208   friend class ALU3dGrid < dim , dimworld, GridImp::elementType>;
00209   friend class ALU3dGridIntersectionIterator < GridImp >;
00210   friend class ALU3dGridIntersectionIterator < const GridImp >;
00211   friend class ALU3dGridHierarchicIterator   < const GridImp >;
00212   friend class ALU3dGridHierarchicIterator   < GridImp >;
00213   friend class ALU3dGridLevelIterator <0,All_Partition,GridImp>;
00214   friend class ALU3dGridLevelIterator <1,All_Partition,GridImp>;
00215   friend class ALU3dGridLevelIterator <2,All_Partition,GridImp>;
00216   friend class ALU3dGridLevelIterator <3,All_Partition,GridImp>;
00217   friend class ALU3dGridLeafIterator <0, All_Partition,GridImp>;
00218   friend class ALU3dGridLeafIterator <1, All_Partition,GridImp>;
00219   friend class ALU3dGridLeafIterator <2, All_Partition,GridImp>;
00220   friend class ALU3dGridLeafIterator <3, All_Partition,GridImp>;
00221 
00222   friend class ALU3dGridHierarchicIndexSet<dim,dimworld,GridImp::elementType>;
00223 
00224   typedef typename SelectType<
00225     is_same<GridImp,const ALU3dGrid<3, 3, tetra> >::value,
00226     ReferenceSimplex<alu3d_ctype, 3>,
00227     ReferenceCube<alu3d_ctype, 3>
00228   >::Type ReferenceElementType;
00229 
00230 public:
00231   typedef typename GridImp::template Codim<0>::Geometry   Geometry;
00232   typedef ALU3dGridGeometry<dim,dimworld,GridImp> GeometryImp;
00233   typedef MakeableInterfaceObject<Geometry> GeometryObject;
00234   typedef ALU3dGridIntersectionIterator<GridImp> IntersectionIteratorImp; 
00235 
00236   typedef LeafIntersectionIteratorWrapper <GridImp>  ALU3dGridIntersectionIteratorType; 
00237   typedef LeafIntersectionIteratorWrapper <GridImp>  ALU3dGridLeafIntersectionIteratorType; 
00238   typedef LevelIntersectionIteratorWrapper<GridImp>  ALU3dGridLevelIntersectionIteratorType; 
00239   
00240   typedef typename GridImp::template Codim<0>::Entity     Entity;
00241   typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00242 
00243   template <int cd>
00244   struct Codim
00245   {
00246     typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
00247   };
00248   
00250   ALU3dGridEntity(const GridImp &grid, int level);
00251   
00253   ALU3dGridEntity(const ALU3dGridEntity & org);
00254 
00256   int level () const ;
00257 
00259   const Geometry & geometry () const;
00260 
00262   GeometryType type () const;
00263 
00265   PartitionType partitionType() const;
00266   
00270   template<int cc> int count () const ; 
00271   
00274   template <int cc>
00275   typename Codim<cc>::EntityPointer entity (int i) const;
00276 
00282   ALU3dGridLeafIntersectionIteratorType ileafbegin () const;
00283 
00285   ALU3dGridLeafIntersectionIteratorType ileafend () const;
00286   
00292   ALU3dGridLevelIntersectionIteratorType ilevelbegin () const;
00293 
00295   ALU3dGridLevelIntersectionIteratorType ilevelend () const;
00296   
00298   bool isLeaf () const; 
00299 
00302   EntityPointer father () const;
00303 
00313   const Geometry & geometryInFather () const;
00314  
00319   ALU3dGridHierarchicIterator<GridImp> hbegin (int maxlevel) const;
00320   
00322   ALU3dGridHierarchicIterator<GridImp> hend (int maxlevel) const;
00323 
00324   //***************************************************************
00325   //  Interface for Adaptation
00326   //***************************************************************
00328   bool wasRefined () const; 
00329 
00331   bool mightBeCoarsened () const;
00332  
00334   bool hasBoundaryIntersections () const;
00335  
00336   // private method 
00340   bool mark( int refCount ) const;
00341 
00343   int getMark() const;
00344 
00348   void setElement(ALU3DSPACE HElementType &element);
00349   
00351   void setGhost(ALU3DSPACE HBndSegType & ghost);
00352 
00354   void reset ( int l );
00355 
00357   void removeElement();
00358 
00360   bool equals ( const ALU3dGridEntity<0,dim,GridImp> & org ) const;
00361   
00362   void setEntity ( const ALU3dGridEntity<0,dim,GridImp> & org );
00363 
00367   template<int cc> int getSubIndex (int i) const;
00368 
00369   // return reference to internal item 
00370   const IMPLElementType & getItem () const { return *item_; }
00371 
00372 private:
00374   int getIndex () const;
00375 
00376   // corresponding grid 
00377   const GridImp  & grid_;
00378 
00379   // the current element of grid 
00380   mutable IMPLElementType *item_;
00381   
00382   mutable bool isGhost_; 
00383 
00385   mutable GeometryObject geo_;
00386   GeometryImp & geoImp_;
00387   mutable bool builtgeometry_;  
00388 
00389   int walkLevel_; 
00390   
00391   int level_;    
00392 
00393   mutable GeometryObject geoInFather_;
00394   GeometryImp &  geoInFatherImp_;
00395 
00396   // is true if entity is leaf entity 
00397   bool isLeaf_;
00398 
00399   const ReferenceElementType & refElem_;
00400 }; // end of ALU3dGridEntity codim = 0
00401 
00402 //**********************************************************************
00403 //
00404 // --ALU3dGridEntityPointer
00405 // --EntityPointer
00406 // --EnPointer
00410 template<int cd, class GridImp>
00411 class ALU3dGridEntityPointerBase : 
00412 public EntityPointerDefaultImplementation <cd, GridImp, ALU3dGridEntityPointer<cd,GridImp> >
00413 {
00414   typedef ALU3dGridEntityPointerBase <cd,GridImp> ThisType;
00415   enum { dim       = GridImp::dimension };
00416   enum { dimworld  = GridImp::dimensionworld };
00417     
00418   friend class ALU3dGridEntity<cd,dim,GridImp>;
00419   friend class ALU3dGridEntity< 0,dim,GridImp>;
00420   friend class ALU3dGrid < dim , dimworld, GridImp::elementType >;
00421 
00422   typedef typename ALU3dImplTraits<GridImp::elementType>::template Codim<cd>::InterfaceType MyHElementType;
00423 
00424   typedef ALU3DSPACE HBndSegType HBndSegType;
00425   typedef typename ALU3dImplTraits<GridImp::elementType>::BNDFaceType BNDFaceType;
00426 public:
00428   typedef typename GridImp::template Codim<cd>::Entity Entity;
00430   typedef MakeableInterfaceObject<Entity> EntityObject;
00431   typedef typename EntityObject :: ImplementationType EntityImp;
00432   
00434   typedef ThisType ALU3dGridEntityPointerType;
00435 
00437   typedef ALU3dGridEntityPointerBase<cd,GridImp> Base;
00438   
00440   ALU3dGridEntityPointerBase(const GridImp & grid, 
00441                              const int level,
00442                              const MyHElementType & item);
00443 
00445   ALU3dGridEntityPointerBase(const GridImp & grid, 
00446                              const HBndSegType & ghostFace );  
00447 
00449   ALU3dGridEntityPointerBase(const ALU3dGridEntityPointerType & org);
00450   
00452   ~ALU3dGridEntityPointerBase();
00453 
00455   bool equals (const ALU3dGridEntityPointerType& i) const;
00456 
00458   ThisType & operator = (const ThisType & org);
00459 
00461   Entity & dereference () const ;
00462 
00464   int level () const ;
00465 
00466 protected:
00467   // clones object 
00468   void clone (const ALU3dGridEntityPointerType & org);
00469   
00470   // get entity and assign from org.entity  
00471   void getEntity (const ALU3dGridEntityPointerType & org);
00472   
00474   void done (); 
00475 
00478   ALU3dGridEntityPointerBase(const GridImp & grid, int level );
00479 
00480   // update underlying item pointer and set ghost entity
00481   void updateGhostPointer( HBndSegType & ghostFace );  
00482   // update underlying item pointer and set entity
00483   void updateEntityPointer( MyHElementType * item , int level = -1 );  
00484   
00485   // reference to grid 
00486   const GridImp & grid_;  
00487 
00488   // pointer to item 
00489   MyHElementType * item_;
00490 
00491   // entity that this EntityPointer points to 
00492   mutable EntityObject * entity_;
00493   // return reference to internal entity implementation 
00494   EntityImp & entityImp () const { 
00495     assert( entity_ );
00496     return grid_.getRealImplementation(*entity_); 
00497   }
00498 };
00499 
00503 template<class GridImp>
00504 class ALU3dGridEntityPointer<0,GridImp> : 
00505 public ALU3dGridEntityPointerBase<0,GridImp> 
00506 {
00507   enum { cd = 0 };
00508   typedef ALU3dGridEntityPointer <cd,GridImp> ThisType;
00509   enum { dim       = GridImp::dimension };
00510   enum { dimworld  = GridImp::dimensionworld };
00511     
00512   friend class ALU3dGridEntity<cd,dim,GridImp>;
00513   friend class ALU3dGridEntity< 0,dim,GridImp>;
00514   friend class ALU3dGrid < dim , dimworld, GridImp::elementType >;
00515 
00516   typedef typename ALU3dImplTraits<GridImp::elementType>::template Codim<cd>::InterfaceType MyHElementType;
00517 
00518   typedef ALU3DSPACE HBndSegType HBndSegType;
00519   typedef typename ALU3dImplTraits<GridImp::elementType>::BNDFaceType BNDFaceType;
00520 public:
00522   typedef typename GridImp::template Codim<cd>::Entity Entity;
00523   
00525   typedef ThisType ALU3dGridEntityPointerType;
00526   
00528   ALU3dGridEntityPointer(const GridImp & grid, 
00529                          const MyHElementType & item)
00530     : ALU3dGridEntityPointerBase<cd,GridImp> (grid,-1,item) {} // -1 is fake level here 
00531 
00533   ALU3dGridEntityPointer(const GridImp & grid, 
00534                          const HBndSegType & ghostFace )  
00535     : ALU3dGridEntityPointerBase<cd,GridImp> (grid,ghostFace) {}
00536 
00538   ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org)
00539     : ALU3dGridEntityPointerBase<cd,GridImp> (org) {}
00540 
00541 protected:
00544   ALU3dGridEntityPointer(const GridImp & grid, int level )
00545     : ALU3dGridEntityPointerBase<cd,GridImp> (grid,level) {}
00546 };
00547 
00548 
00549 template<int cd, class GridImp>
00550 class ALU3dGridEntityPointer : 
00551 public ALU3dGridEntityPointerBase<cd,GridImp>
00552 {
00553   typedef ALU3dGridEntityPointer <cd,GridImp> ThisType;
00554   enum { dim       = GridImp::dimension };
00555   enum { dimworld  = GridImp::dimensionworld };
00556     
00557   friend class ALU3dGridEntity<cd,dim,GridImp>;
00558   friend class ALU3dGridEntity< 0,dim,GridImp>;
00559   friend class ALU3dGrid < dim , dimworld, GridImp::elementType >;
00560 
00561   typedef typename ALU3dImplTraits<GridImp::elementType>::template Codim<cd>::InterfaceType MyHElementType;
00562 
00563   typedef ALU3DSPACE HBndSegType HBndSegType;
00564   typedef typename ALU3dImplTraits<GridImp::elementType>::BNDFaceType BNDFaceType;
00565 public:
00567   typedef typename GridImp::template Codim<cd>::Entity Entity;
00568   
00570   typedef ALU3dGridEntityPointer<cd,GridImp> ALU3dGridEntityPointerType;
00571   
00573   ALU3dGridEntityPointer(const GridImp & grid, 
00574                          const int level, 
00575                          const MyHElementType & item,
00576                          const int twist = 0,
00577                          const int duneFace = -1
00578                         );
00579 
00581   ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org);
00582   
00584   Entity & dereference () const ;
00585 
00587   ThisType & operator = (const ThisType & org);
00588 
00590   int level () const ;
00591 
00592 protected:
00593   // clones object 
00594   void clone (const ALU3dGridEntityPointerType & org);
00595   
00596   void updateEntityPointer( MyHElementType * item , int level );  
00597 
00600   ALU3dGridEntityPointer(const GridImp & grid, int level ) 
00601     : ALU3dGridEntityPointerBase<cd,GridImp> (grid,level)
00602     , level_(level)
00603     , twist_(0) , face_(-1) {}
00604 
00605   // level of entity 
00606   int level_; 
00607   // twist of face, for codim 1 only 
00608   int twist_;
00609   // face number, for codim 1 only 
00610   int face_;
00611 };
00612 
00613 } // end namespace Dune
00614 
00615 #include "entity_imp.cc"
00616 
00617 #endif

Generated on 6 Nov 2008 with Doxygen (ver 1.5.6) [logfile].