common/entity.hh

00001 #ifndef DUNE_GRID_ENTITY_HH
00002 #define DUNE_GRID_ENTITY_HH
00003 
00004 #include <dune/common/typetraits.hh>
00005 #include "grid.hh"
00006 #include "entitypointer.hh"
00007 
00008 namespace Dune
00009 {
00010 
00080 template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp>
00081 class Entity {
00082   enum { dimworld = GridImp::dimensionworld };
00083   typedef typename GridImp::ctype ct;
00084 protected:
00085   EntityImp<cd,dim,GridImp> realEntity;
00086 public:
00087 
00088   //===========================================================
00092   //===========================================================
00093 protected:
00094   // The type of the wrapped implementation, for internal use only
00095   typedef EntityImp<cd,dim,GridImp> ImplementationType; 
00096 
00097 public:
00099   typedef typename GridImp::template Codim<cd>::Geometry Geometry;
00100 
00101   enum {
00103     codimension=cd
00104   };
00105   enum {
00107     dimension=dim
00108   };
00109   enum {
00111     mydimension=dim-cd
00112   };
00113   enum {
00115     dimensionworld=dimworld
00116   };
00117 
00119   typedef ct ctype;
00121 
00122 
00123 
00124   //===========================================================
00128   //===========================================================
00129 
00131   int level () const { return realEntity.level(); }
00132 
00134   PartitionType partitionType () const { return realEntity.partitionType(); }
00135 
00145   const Geometry& geometry () const { return realEntity.geometry(); }
00147 
00151     GeometryType type () const { return realEntity.type(); };
00152 
00153   //===========================================================
00157   //===========================================================
00158 
00160   explicit Entity(const EntityImp<cd,dim,GridImp> & e) : realEntity(e) {};  
00161 
00162   /* not part of the interface but maybe in later versions
00163      \brief Id of the boundary which is associated with the entity, 
00164    returns 0 for inner entities, arbitrary int otherwise 
00165   */
00166   //int boundaryId () const { return realEntity.boundaryId(); }
00167 
00169 
00170 protected:
00171   typedef typename remove_const<GridImp>::type mutableGridImp;
00172   
00173   //===========================================================
00177   //===========================================================
00178 
00179   // give the GridDefaultImplementation class access to the realImp 
00180   friend class GridDefaultImplementation<
00181             GridImp::dimension, GridImp::dimensionworld,
00182             typename GridImp::ctype,
00183             typename GridImp::GridFamily> ;
00184 
00185   /* make entity pointer friend */
00186   friend class Dune::EntityPointer<GridImp,
00187                                    typename GridImp::GridFamily::Traits::template Codim<cd>::EntityPointerImpl>;
00188 
00190   EntityImp<cd,dim,GridImp> & getRealImp() { return realEntity; }
00192   const EntityImp<cd,dim,GridImp> & getRealImp() const { return realEntity; }
00193 
00194 protected:  
00196   Entity(const Entity& rhs) : realEntity(rhs.realEntity) {};
00198   Entity & operator = (const Entity& rhs) { 
00199       realEntity = rhs.realEntity; 
00200       return *this;
00201   }
00203 };
00204 
00213 template<int dim, class GridImp, template<int,int,class> class EntityImp>
00214 class Entity <0,dim,GridImp,EntityImp> 
00215 {
00216   enum { dimworld = GridImp::dimensionworld };
00217   typedef typename GridImp::ctype ct;
00218 
00219 protected:
00220   typedef typename remove_const<GridImp>::type mutableGridImp;
00221 
00222   EntityImp<0,dim,GridImp> realEntity;
00223 
00224   // The type of the wrapped implementation, for internal use only
00225   typedef EntityImp<0,dim,GridImp> ImplementationType; 
00226 public:
00227 
00228   //===========================================================
00232   //===========================================================
00233 
00235   typedef typename GridImp::template Codim<0>::Geometry Geometry;
00236 
00240   typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
00241 
00243   template <int cd>
00244   struct Codim
00245   {
00246     typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
00247   };
00248 
00250   typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00251 
00253   typedef typename GridImp::template Codim<0>::LeafIntersectionIterator LeafIntersectionIterator;
00254 
00256   typedef typename GridImp::template Codim<0>::LevelIntersectionIterator LevelIntersectionIterator;
00257 
00259   typedef typename GridImp::template Codim<0>::HierarchicIterator HierarchicIterator;
00260   
00261   enum { 
00263   codimension=0 
00264   };
00265   enum { 
00267   dimension=dim 
00268   };
00269   enum { 
00271   mydimension=dim 
00272   };
00273   enum { 
00275   dimensionworld=dimworld 
00276   };
00278   typedef ct ctype;
00280 
00281 
00282   //===========================================================
00286   //===========================================================
00287 
00289   int level () const { return realEntity.level(); }
00290 
00292   PartitionType partitionType () const { return realEntity.partitionType(); }
00293 
00295   const Geometry& geometry () const { return realEntity.geometry(); }
00297 
00301     GeometryType type () const { return realEntity.type(); };
00302 
00303   //===========================================================
00307   //===========================================================
00308 
00314   template<int cc> int count () const { return realEntity.count<cc>(); }
00315 
00318   template<int cc> typename Codim<cc>::EntityPointer entity (int i) const
00319     {
00320       return realEntity.entity<cc>(i);
00321     }
00322  
00329   LeafIntersectionIterator ileafbegin () const
00330     {
00331       return realEntity.ileafbegin();
00332     }
00333   
00336   LeafIntersectionIterator ileafend () const
00337     {
00338       return realEntity.ileafend();
00339     }
00340 
00347   LevelIntersectionIterator ilevelbegin () const
00348     {
00349       return realEntity.ilevelbegin();
00350     }
00351   
00354   LevelIntersectionIterator ilevelend () const
00355     {
00356       return realEntity.ilevelend();
00357     }
00358 
00363   EntityPointer father () const
00364     {
00365       return realEntity.father();
00366     }
00367 
00369   bool isLeaf () const
00370     {
00371       return realEntity.isLeaf();
00372     }
00373 
00377   bool isRegular() const { return realEntity.isRegular(); }
00378 
00392   const LocalGeometry& geometryInFather () const
00393     {
00394       return realEntity.geometryInFather();
00395     }
00396 
00403   HierarchicIterator hbegin (int maxlevel) const
00404     {
00405       return realEntity.hbegin(maxlevel);
00406     }
00407 
00410   HierarchicIterator hend (int maxlevel) const
00411     {
00412       return realEntity.hend(maxlevel);
00413     }
00414 
00417   bool wasRefined () const DUNE_DEPRECATED { return realEntity.wasRefined(); }
00418   
00421   bool mightBeCoarsened () const DUNE_DEPRECATED { return realEntity.mightBeCoarsened (); }
00422 
00425   bool isNew () const { return realEntity.isNew(); }
00426   
00429   bool mightVanish () const { return realEntity.mightVanish(); }
00430 
00431   //===========================================================
00435   //===========================================================
00439   bool hasBoundaryIntersections () const { return realEntity.hasBoundaryIntersections(); }    
00440 
00442   explicit Entity(const EntityImp<0,dim,GridImp> & e) : realEntity(e) {};  
00443 
00444   // @copydoc Dune::Entity::boundaryId()
00445   // maybe available in later versions 
00446   //int boundaryId () const { return realEntity.boundaryId(); }
00447 
00448   /* not part of the interface, mybe in later versions 
00449      \brief The boundaryId of the i-th subentity of codimension <tt>cc</tt>
00450      
00451      This does the same as <code>entity<cc>(i).boundaryId()</code>, but it is
00452      usually a lot faster.
00453    */
00454   /*
00455   template <int cc> int subBoundaryId  ( int i ) const
00456     {
00457       return realEntity.subBoundaryId<cc>(i);
00458     }
00459   */
00460 
00462 
00463 
00464 protected:
00465   //===========================================================
00469   //===========================================================
00470 
00471   // give the GridDefaultImplementation class access to the realImp 
00472   friend class GridDefaultImplementation<
00473             GridImp::dimension, GridImp::dimensionworld,
00474             typename GridImp::ctype,
00475             typename GridImp::GridFamily> ;
00476 
00477   /* make entity pointer friend */
00478   friend class Dune::EntityPointer<GridImp,
00479                                    typename GridImp::GridFamily::Traits::template Codim<0>::EntityPointerImpl>;
00480 
00482   EntityImp<0,dim,GridImp> & getRealImp() { return realEntity; }
00484   const EntityImp<0,dim,GridImp> & getRealImp() const { return realEntity; }
00485 
00486 protected:
00488   Entity(const Entity& rhs) : realEntity(rhs.realEntity) {};
00490   Entity & operator = (const Entity& rhs) {
00491     realEntity = rhs.realEntity;
00492     return *this;
00493   };
00495 };
00496 
00497 
00498 //********************************************************************
00509 template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp>
00510 class EntityDefaultImplementation 
00511 {
00512   enum { dimworld = GridImp::dimensionworld };
00513   typedef typename GridImp::ctype ct;
00514 public:
00516   enum { codimension=cd };
00517 
00519   enum { dimension=dim };
00520 
00522   enum { mydimension=dim-cd };
00523 
00525   enum { dimensionworld=dimworld };
00526 
00528   typedef ct ctype;
00529 
00533     GeometryType type () const { return asImp().geometry().type(); };
00534 
00535 private:
00537   EntityImp<cd,dim,GridImp>& asImp () 
00538   { 
00539   return static_cast<EntityImp<cd,dim,GridImp>&>(*this); 
00540   }
00541   const EntityImp<cd,dim,GridImp>& asImp () const 
00542   { 
00543   return static_cast<const EntityImp<cd,dim,GridImp>&>(*this); 
00544   }
00545 }; // end EntityDefaultImplementation
00546 
00547 //********************************************************************
00559 template<int dim, class GridImp, template<int,int,class> class EntityImp>
00560 class EntityDefaultImplementation <0,dim,GridImp,EntityImp> 
00561 {
00562   enum { dimworld = GridImp::dimensionworld };
00563   typedef typename GridImp::ctype ct;
00564 
00565 public:
00567   enum { codimension=0 };
00568 
00570   enum { dimension=dim };
00571 
00573   enum { mydimension=dim };
00574 
00576   enum { dimensionworld=dimworld };
00577 
00579   typedef ct ctype;
00580 
00584   bool isRegular() const { return true; }
00585 
00589     GeometryType type () const { return asImp().geometry().type(); };
00590 
00591   /* maybe in later versions 
00592    * \brief Default implementation for access to boundaryId of sub entities 
00593    *
00594    * Default implementation for access to boundaryId via interface method
00595    * entity<codim>.boundaryId(), default is very slow, but works, can be
00596    * overloaded be the actual grid implementation.
00597    */
00598   /*
00599   template <int cc> int subBoundaryId  ( int i ) const
00600     {
00601       return (asImp().template entity<cc>(i))->boundaryId();
00602     }
00603   */
00604 
00607   bool wasRefined () const DUNE_DEPRECATED { return false; }
00608 
00611   bool mightBeCoarsened () const DUNE_DEPRECATED { return false; }
00612 
00615   bool isNew () const { return false; }
00616   
00619   bool mightVanish () const { return false; }
00620 
00625   bool hasBoundaryIntersections () const 
00626   {
00627     {
00628       typedef typename GridImp :: template Codim<0> :: LevelIntersectionIterator
00629         IntersectionIterator; 
00630       IntersectionIterator end = asImp().ilevelend();
00631       for(IntersectionIterator it = asImp().ilevelbegin(); it != end; ++it)
00632       {
00633         if( it->boundary() ) return true;
00634       }
00635     }
00636     
00637     {
00638       typedef typename GridImp :: template Codim<0> :: LeafIntersectionIterator
00639         IntersectionIterator; 
00640       IntersectionIterator end = asImp().ileafend();
00641       for(IntersectionIterator it = asImp().ileafbegin(); it != end; ++it)
00642       {
00643         if( it->boundary() ) return true;
00644       }
00645     }
00646     
00647     return false;
00648   }
00649 
00650 private:
00651   //  Barton-Nackman trick 
00652   EntityImp<0,dim,GridImp>& asImp () { return static_cast<EntityImp<0,dim,GridImp>&>(*this); }
00653   const EntityImp<0,dim,GridImp>& asImp () const { return static_cast<const EntityImp<0,dim,GridImp>&>(*this); }
00654 };
00655 
00656 }
00657 
00658 #endif // DUNE_GRID_ENTITY_HH

Generated on Sun Nov 15 22:28:40 2009 for dune-grid by  doxygen 1.5.6