alugrid/2d/entity.hh

00001 #ifndef DUNE_ALU2DGRIDENTITY_HH
00002 #define DUNE_ALU2DGRIDENTITY_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 "iterator.hh"
00012 
00013 namespace Dune {
00014   // Forward declarations
00015   template<int cd, int dim, class GridImp> 
00016   class ALU2dGridEntity;
00017   template<int cd, PartitionIteratorType pitype, class GridImp >
00018   class ALU2dGridLevelIterator;
00019   template<int cd, class GridImp > 
00020   class ALU2dGridEntityPointer;
00021   template<int mydim, int coorddim, class GridImp>
00022   class ALU2dGridGeometry;
00023   template<class GridImp> 
00024   class ALU2dGridHierarchicIterator;  
00025   template<class GridImp>
00026   class ALU2dGridLevelIntersectionIterator;
00027   template<class GridImp>
00028   class ALU2dGridLeafIntersectionIterator;
00029   template<class GridImp>
00030   class ALU2dGridIntersectionIterator;
00031   template<int codim, PartitionIteratorType, class GridImp>
00032   class ALU2dGridLeafIterator;
00033   template<int dim, int dimworld> 
00034   class ALU2dGrid;
00035 
00036 //**********************************************************************
00037 //
00038 // --ALU2dGridEntity
00039 // --Entity
00040 //
00041 //**********************************************************************
00048 template<int cd, int dim, class GridImp>
00049 class ALU2dGridEntity : 
00050 public EntityDefaultImplementation <cd,dim,GridImp,ALU2dGridEntity> 
00051 {
00052   enum { dimworld = GridImp::dimensionworld };
00053   
00054   friend class ALU2dGrid < dim , dimworld>;  
00055   friend class ALU2dGridIntersectionIterator < GridImp >;
00056   friend class ALU2dGridIntersectionIterator < const GridImp >;
00057   friend class ALU2dGridLevelIntersectionIterator < GridImp >;
00058   friend class ALU2dGridLevelIntersectionIterator < const GridImp >;
00059   friend class ALU2dGridLeafIntersectionIterator < GridImp >;
00060   friend class ALU2dGridLeafIntersectionIterator < const GridImp >;  
00061   friend class ALU2dGridHierarchicIterator   < const GridImp >;
00062   friend class ALU2dGridHierarchicIterator   < GridImp >;
00063   friend class ALU2dGridLevelIterator <0,All_Partition,GridImp>;
00064   friend class ALU2dGridLevelIterator <1,All_Partition,GridImp>;
00065   friend class ALU2dGridLevelIterator <2,All_Partition,GridImp>;  
00066   friend class ALU2dGridLeafIterator <0, All_Partition,GridImp>;
00067   friend class ALU2dGridLeafIterator <1, All_Partition,GridImp>;
00068   friend class ALU2dGridLeafIterator <2, All_Partition,GridImp>;  
00069   friend class ALU2dGridMakeableEntity<0,dim,GridImp>;
00070 
00071   friend class ALU2dGridHierarchicIndexSet<dim,dimworld>;
00072   
00073   typedef typename ALU2DSPACE Hmesh_basic::helement_t HElementType ;
00074   
00075 public:
00076   typedef typename Dune::ALU2dImplTraits::template Codim<cd>::InterfaceType ElementType;
00077 
00079   typedef typename GridImp::template Codim<cd>::Entity Entity;  
00081   typedef typename GridImp::template Codim<cd>::Geometry Geometry;
00083   typedef MakeableInterfaceObject<Geometry> GeometryObj;
00084   typedef ALU2dGridGeometry<dim-cd,dimworld,GridImp> GeometryImp;
00085  
00087   typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00088   
00090   int level () const;
00091       
00093   ALU2dGridEntity(const GridImp &grid, int level);
00094 
00096   ALU2dGridEntity(const ALU2dGridEntity & org);
00097   
00099   const Geometry & geometry () const;
00100   
00102   void removeElement();
00103 
00107 
00108   void setElement(const ElementType &element, int face=-1, int level = -1) const;  
00109   void setElement(const HElementType & el, const ALU2DSPACE Vertex & vx);
00110   void setElement(const ALU2dGridEntity & org) const {
00111     setElement(*(org.item_), org.face_);
00112   }  
00113    
00115   bool equals ( const ALU2dGridEntity<cd,dim,GridImp> & org ) const;
00116 
00119   PartitionType partitionType() const{ return InteriorEntity; }
00120   
00125   int boundaryId () const; 
00126     
00131   EntityPointer ownersFather () const;
00132  
00134   FieldVector<alu2d_ctype, dim>& positionInOwnersFather () const;
00135 
00136     
00137 private: 
00139   int getIndex () const; 
00140     
00142   const GridImp &grid_;
00143         
00145   mutable ElementType * item_;     
00147   
00148   mutable GeometryObj geoObj_;
00149   mutable GeometryImp & geoImp_;
00150   mutable bool builtgeometry_;         // true if geometry has been constructed 
00151   
00152   mutable int level_;  
00153   mutable int face_;  
00154 };
00155 
00169 //***********************
00170 //  
00171 //  --ALU2dGridEntity
00172 //  --0Entity
00173 //
00174 //***********************
00175 template<int dim, class GridImp>
00176 class ALU2dGridEntity<0,dim,GridImp> 
00177 : public EntityDefaultImplementation<0,dim,GridImp,ALU2dGridEntity>
00178 {
00179   enum { dimworld = GridImp::dimensionworld };
00180   
00181   friend class ALU2dGrid < dim , dimworld>;
00182   friend class ALU2dGridIntersectionIterator < GridImp >;
00183   friend class ALU2dGridIntersectionIterator < const GridImp >;
00184   friend class ALU2dGridLevelIntersectionIterator < GridImp >;
00185   friend class ALU2dGridLevelIntersectionIterator < const GridImp >;
00186   friend class ALU2dGridLeafIntersectionIterator < GridImp >;
00187   friend class ALU2dGridLeafIntersectionIterator < const GridImp >;
00188   friend class ALU2dGridHierarchicIterator   < const GridImp >;
00189   friend class ALU2dGridHierarchicIterator   < GridImp >;
00190   friend class ALU2dGridLevelIterator <0,All_Partition,GridImp>;
00191   friend class ALU2dGridLevelIterator <1,All_Partition,GridImp>;
00192   friend class ALU2dGridLevelIterator <2,All_Partition,GridImp>;  
00193   friend class ALU2dGridLeafIterator <0, All_Partition,GridImp>;
00194   friend class ALU2dGridLeafIterator <1, All_Partition,GridImp>;
00195   friend class ALU2dGridLeafIterator <2, All_Partition,GridImp>;  
00196   friend class ALU2dGridMakeableEntity<0,dim,GridImp>;
00197 
00198   friend class ALU2dGridHierarchicIndexSet<dim,dimworld>;
00199   
00200   typedef typename ALU2DSPACE Hmesh_basic::helement_t HElementType ;
00201   
00202 public:
00204   typedef typename GridImp::template Codim<0>::Geometry Geometry;
00206   typedef MakeableInterfaceObject<Geometry> GeometryObj;
00207   typedef ALU2dGridGeometry<dim,dimworld,GridImp> GeometryImp;
00208 
00210   typedef LeafIntersectionIteratorWrapper< GridImp > ALU2dGridLeafIntersectionIteratorType;
00211   typedef LevelIntersectionIteratorWrapper< GridImp > ALU2dGridLevelIntersectionIteratorType;
00212   typedef ALU2dGridLeafIntersectionIteratorType ALU2dGridIntersectionIteratorType; 
00213  
00215   typedef typename GridImp::template Codim<0>::Entity  Entity;
00217   //typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00218   typedef ALU2dGridEntityPointer<0,GridImp> EntityPointer;
00219 
00220   template <int cd>
00221   struct Codim
00222   {
00223     typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
00224   };
00225     
00227   ALU2dGridEntity(const GridImp &grid, int level);
00228     
00230   ALU2dGridEntity(const ALU2dGridEntity & org);
00231  
00233   int level () const ;
00234 
00236   const Geometry & geometry () const; 
00237   
00241   template<int cc> 
00242   int count () const {
00243     enum {c = (cc==0)?1 : dim+1};
00244     return c;
00245   }
00246   
00251   int boundaryId () const {
00252     // elements are always inside of our Domain
00253     return 0;
00254   }
00255   
00262   // As ibegin() and iend() are deprecated these methods will deliver a LeafIntersectionIterator
00263   ALU2dGridIntersectionIteratorType ibegin () const
00264   {
00265     return ileafbegin();
00266   }
00268   ALU2dGridIntersectionIteratorType iend () const
00269   {
00270     return ileafend();
00271   }
00272 
00273   ALU2dGridLevelIntersectionIteratorType ilevelbegin () const
00274   {
00275     return ALU2dGridLevelIntersectionIteratorType(grid_, *this, this->level(),false); 
00276   }
00277   ALU2dGridLevelIntersectionIteratorType ilevelend () const
00278   {
00279     return ALU2dGridLevelIntersectionIteratorType(grid_, *this, this->level(),true); 
00280   }
00281   ALU2dGridLeafIntersectionIteratorType ileafbegin () const
00282   {
00283     return ALU2dGridLeafIntersectionIteratorType(grid_, *this, this->level(), false); 
00284   }
00285   ALU2dGridLeafIntersectionIteratorType ileafend () const
00286   {
00287     return ALU2dGridLeafIntersectionIteratorType(grid_, *this, this->level(),true); 
00288   }
00289     
00291   bool isLeaf () const; 
00292 
00295   EntityPointer father () const;  
00296  
00301   ALU2dGridHierarchicIterator<GridImp> hbegin (int maxLevel) const
00302   {
00303     return ALU2dGridHierarchicIterator<GridImp> (grid_,*item_,maxLevel,false); 
00304   }
00305   
00307   ALU2dGridHierarchicIterator<GridImp> hend (int maxLevel) const
00308   {
00309     return ALU2dGridHierarchicIterator<GridImp> (grid_,*item_,maxLevel,true); 
00310   }
00311 
00314   template <int cc>
00315   typename Codim<cc>::EntityPointer entity (int i) const;
00316   
00318   PartitionType partitionType() const{ return InteriorEntity; }
00319    
00326   template <int cc> 
00327   int subBoundaryId  ( int i ) const;
00328   
00329    
00340   const Geometry & geometryInFather () const;  
00341   
00343   bool mightBeCoarsened () const{
00344     return ((item_->is(ALU2DSPACE Refco::crs))==1);  
00345   }
00346   bool wasRefined () const {
00347     return ((item_->wasRefined())==1);
00348   }
00349 
00350   //***************************************************************
00351   //  Interface for Adaptation
00352   //***************************************************************
00353  
00354  public:
00358   bool mark(int refCount) const;
00359 
00361   int getMark() const;
00362 
00366   void setElement(const HElementType &element, int face=-1, int level = -1) const;
00367   
00368   void setElement(const ALU2dGridEntity & org) const {
00369     setElement(*(org.item_));
00370   }
00371 
00373   void reset ( int l );
00374 
00376   void removeElement();
00377 
00379   bool equals ( const ALU2dGridEntity<0,dim,GridImp> & org ) const;
00380 
00381   // return reference to HElement (needed by IntersectionIterator)
00382   HElementType & getItem() const 
00383   { 
00384     assert( item_ );
00385     return *item_; 
00386   }
00387   
00388 private:
00390   int nChild () const;
00391 
00393   int getIndex () const;
00394 
00398   template<int cc> int getSubIndex (int i) const;   
00399   
00401   const GridImp  & grid_;
00402   
00404   mutable HElementType *item_;   
00405   
00407   mutable GeometryObj geoObj_;
00408   mutable GeometryImp & geoImp_;
00409   mutable bool builtgeometry_;  
00410   
00411   //mutable GeometryImp geoInFather_;
00412   //int index_; //! level index of entity
00413   
00414   mutable int walkLevel_; 
00415 
00416   mutable bool isLeaf_;
00417     
00418 }; // end of ALU2dGridEntity codim = 0
00419 
00420 
00421 //**********************************************************************
00422 //
00423 // --ALU2dGridEntityPointer
00424 // --EntityPointer
00425 // --EnPointer
00426 //**********************************************************************
00430 template<int cd, class GridImp>
00431 class ALU2dGridEntityPointer : 
00432 public EntityPointerDefaultImplementation <cd, GridImp, ALU2dGridEntityPointer<cd,GridImp> >
00433 {
00434   // type of this class 
00435   typedef ALU2dGridEntityPointer <cd,GridImp> ThisType;
00436   enum { dim       = GridImp::dimension };
00437   enum { dimworld  = GridImp::dimensionworld };
00438   typedef typename Dune::ALU2dImplTraits::template Codim<cd>::InterfaceType ElementType;
00439   
00440 public:
00442   typedef typename GridImp::template Codim<cd>::Entity Entity;
00444   typedef ALU2dGridEntity<cd,dim,GridImp> EntityImp;
00445   typedef MakeableInterfaceObject<Entity> EntityObj;
00446 
00447   typedef ALU2dGridEntityPointer<cd,GridImp> Base;
00448      
00450   ALU2dGridEntityPointer(const GridImp & grid, 
00451        const ElementType & item,
00452                          int face,
00453        int level
00454                          );
00455  
00457   ALU2dGridEntityPointer(const GridImp & grid) ;
00458 
00460   ALU2dGridEntityPointer(const ThisType & org) ;
00461 
00463   ~ALU2dGridEntityPointer();
00464  
00466   // this may have to be changed!
00467   bool equals (const ThisType & i) const; 
00468  
00470   Entity & dereference() const ;
00471  
00473   int level () const;
00474  
00475   ThisType & operator = (const ThisType & org);
00476 
00477 protected:
00478   EntityImp & entityImp();
00479 
00480   const EntityImp & entityImp() const;
00481  
00483   void done ();
00484  
00486   void updateEntityPointer( ElementType * item, int face=-1, int level=-1 );    
00487     
00489   const GridImp & grid_;  
00490 
00492   mutable ElementType * item_;
00493   mutable int level_;
00494   int face_;
00496   mutable EntityObj * entity_;
00497 };
00498 
00499 } // end namespace Dune
00500 
00501 #include "entity_imp.cc"
00502 #endif

Generated on 12 Dec 2007 with Doxygen (ver 1.5.1)