dune-grid  2.2.0
albertagrid/entity.hh
Go to the documentation of this file.
00001 #ifndef DUNE_ALBERTA_ENTITY_HH
00002 #define DUNE_ALBERTA_ENTITY_HH
00003 
00004 #include <dune/grid/common/entity.hh>
00005 
00006 #include <dune/grid/albertagrid/elementinfo.hh>
00007 #include <dune/grid/albertagrid/entityseed.hh>
00008 #include <dune/grid/albertagrid/geometry.hh>
00009 
00010 #if HAVE_ALBERTA
00011 
00012 namespace Dune
00013 {
00014 
00015   // Forward Declarations
00016   // --------------------
00017 
00018   template< int codim, class GridImp >
00019   class AlbertaGridEntityPointer;
00020 
00021   template< int codim, class GridImp, bool leafIterator >
00022   class AlbertaGridTreeIterator;
00023 
00024   template< class GridImp >
00025   class AlbertaGridHierarchicIterator;
00026 
00027   template< class GridImp >
00028   class AlbertaGridLeafIntersection;
00029 
00030   template< class GridImp >
00031   class AlbertaGridLeafIntersectionIterator;
00032 
00033 
00034 
00035   // AlbertaGridEntity
00036   // -----------------
00037 
00044   template< int codim, int dim, class GridImp >
00045   class AlbertaGridEntity
00046   : public EntityDefaultImplementation< codim, dim, GridImp, AlbertaGridEntity >
00047   {
00048     typedef AlbertaGridEntity< codim, dim, GridImp > This;
00049 
00050     enum { dimworld = GridImp::dimensionworld };
00051     friend class AlbertaGrid< dim , dimworld >;
00052     friend class AlbertaGridEntity< 0, dim, GridImp>;
00053 
00054     template< int, class, bool > friend class AlbertaGridTreeIterator;
00055     friend class AlbertaGridEntityPointer< codim, GridImp >;
00056 
00057   public:
00058     static const int dimension = dim;
00059     static const int codimension = codim;
00060     static const int mydimension = dimension - codimension;
00061 
00062     template< int cd >
00063     struct Codim
00064     {
00065       typedef typename GridImp::template Codim< cd >::EntityPointer EntityPointer;
00066     };
00067 
00068     typedef typename GridImp::template Codim< codim >::Entity Entity;
00069     typedef typename GridImp::template Codim< codim >::EntitySeed EntitySeed;
00070     typedef typename GridImp::template Codim< codim >::Geometry Geometry;
00071     typedef typename GridImp::template Codim< codim >::LevelIterator LevelIterator;
00072 
00073     typedef Alberta::ElementInfo< dimension > ElementInfo;
00074 
00075   private:
00076     //typedef MakeableInterfaceObject< Geometry > GeometryObject;
00077     //typedef typename GeometryObject::ImplementationType GeometryImp;
00078     typedef typename GridImp::Traits::template Codim< codim >::GeometryImpl GeometryImpl;
00079 
00080   public:
00082     explicit AlbertaGridEntity ( const GridImp &grid );
00083 
00085     AlbertaGridEntity ( const GridImp &grid, const ElementInfo &elementInfo, int subEntity );
00086 
00088     int level () const;
00089 
00091     PartitionType partitionType() const; 
00092 
00094     Geometry geometry () const;
00095 
00097     GeometryType type () const;
00098 
00100     EntitySeed seed () const { return EntitySeed( elementInfo(), subEntity() ); }
00101 
00102     //***********************************************
00103     // end of interface methods 
00104     //***********************************************
00105 
00107     ALBERTA EL_INFO *getElInfo () const;
00108 
00109     const ElementInfo &elementInfo () const { return elementInfo_; }
00110 
00112     bool equals ( const This &other ) const;
00113     
00114     void clearElement ();
00115     void setElement ( const ElementInfo &elementInfo, int subEntity );
00116 
00117     // same as setElInfo just with a entity given 
00118     void setEntity ( const This &other );
00119 
00121     const GridImp &grid () const
00122     {
00123       return *grid_;
00124     }
00125 
00127     int subEntity () const
00128     {
00129       return subEntity_;
00130     }
00131 
00133     int twist () const
00134     {
00135       return elementInfo().template twist< codimension >( subEntity() );
00136     }
00137 
00138   private: 
00139     // grid this entity belong to 
00140     const GridImp *grid_;
00141 
00142     // ALBERTA element info
00143     ElementInfo elementInfo_;
00144 
00145     // number of the subentity within the element (in ALBERTA numbering)
00146     int subEntity_;
00147   };
00148 
00149 
00150 
00151   // AlbertaGridEntity for codimension 0
00152   // -----------------------------------
00153 
00167   template< int dim, class GridImp >
00168   class AlbertaGridEntity< 0, dim, GridImp >
00169   : public EntityDefaultImplementation< 0, dim, GridImp, AlbertaGridEntity >
00170   {
00171     typedef AlbertaGridEntity< 0, dim, GridImp > This;
00172 
00173     static const int dimworld = GridImp::dimensionworld;
00174 
00175     friend class AlbertaGrid< dim, dimworld >;
00176     friend class AlbertaGridLeafIntersection< GridImp >;
00177     friend class AlbertaGridHierarchicIterator< GridImp >;
00178     template< int, class, bool > friend class AlbertaGridTreeIterator;
00179     friend class AlbertaGridEntityPointer<0,GridImp>;
00180 
00181   public:
00182     static const int dimension = dim;
00183     static const int codimension = 0;
00184     static const int mydimension = dimension - codimension;
00185 
00186     template< int codim >
00187     struct Codim
00188     {
00189       typedef typename GridImp::template Codim< codim >::EntityPointer
00190         EntityPointer;
00191     };
00192 
00193     typedef typename GridImp::template Codim< 0 >::Entity Entity;
00194     typedef typename GridImp::template Codim< 0 >::EntitySeed EntitySeed;
00195     typedef typename GridImp::template Codim< 0 >::Geometry Geometry;
00196     typedef typename GridImp::template Codim< 0 >::LocalGeometry LocalGeometry;
00197     typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl GeometryImpl;
00198 
00199     typedef typename GridImp::template Codim<0>::LevelIterator LevelIterator;
00200     typedef typename GridImp::HierarchicIterator HierarchicIterator;
00201     typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
00202 
00203     typedef Dune::AlbertaGridLeafIntersectionIterator< GridImp > AlbertaGridLeafIntersectionIterator;
00204     typedef AlbertaGridLeafIntersectionIterator AlbertaGridLevelIntersectionIterator;
00205 
00206     typedef Alberta::ElementInfo< dimension > ElementInfo;
00207 
00209     explicit AlbertaGridEntity ( const GridImp &grid );
00210 
00212     AlbertaGridEntity ( const GridImp &grid, const ElementInfo &elementInfo, int subEntity );
00213 
00215     int level () const;
00216 
00218     int boundaryId () const;
00219 
00221     Geometry geometry () const;
00222 
00224     GeometryType type () const;
00225 
00227     EntitySeed seed () const { return EntitySeed( elementInfo() ); }
00228 
00235     template< int codim >
00236     int count () const
00237     {
00238       return Alberta::NumSubEntities< dimension, codim >::value;
00239     }
00240  
00251     template< int codim >
00252     typename Codim< codim >::EntityPointer subEntity ( int i ) const;
00253 
00259     AlbertaGridLeafIntersectionIterator ileafbegin () const;
00260 
00262     AlbertaGridLeafIntersectionIterator ileafend () const;
00263 
00264     AlbertaGridLevelIntersectionIterator ilevelbegin () const
00265     {
00266       if( grid().maxLevel() == 0 ) 
00267         return ileafbegin();
00268       else 
00269       {
00270         DUNE_THROW( NotImplemented, "method ilevelbegin not implemented for AlbertaGrid." );
00271         return ileafend();
00272       }
00273     }
00274 
00275     AlbertaGridLevelIntersectionIterator ilevelend () const
00276     {
00277       return ileafend();
00278     }
00279 
00281     bool isLeaf () const; 
00282 
00285     EntityPointer father () const;
00287     bool hasFather () const
00288     {
00289       return (this->level()>0);
00290     }
00291 
00300     LocalGeometry geometryInFather () const;
00301   
00306     HierarchicIterator hbegin (int maxlevel) const;
00307   
00309     HierarchicIterator hend (int maxlevel) const;
00310 
00312     bool isNew () const;
00313 
00315     bool mightVanish () const;
00316 
00319     bool hasBoundaryIntersections () const ;
00320     
00322     PartitionType partitionType() const; 
00323 
00325     bool equals ( const AlbertaGridEntity<0,dim,GridImp> & i) const;
00326 
00327     // needed for LevelIterator to compare 
00328     ALBERTA EL_INFO *getElInfo () const;
00329 
00330     const ElementInfo &elementInfo () const
00331     {
00332       return elementInfo_;
00333     }
00334 
00335     void clearElement ();
00336     void setElement ( const ElementInfo &elementInfo, int subEntity );
00337 
00338     // same as setElInfo just with a entity given 
00339     void setEntity ( const This &other );
00340 
00342     const GridImp &grid () const
00343     {
00344       return *grid_;
00345     }
00346 
00348     int subEntity () const
00349     {
00350       return 0;
00351     }
00352 
00354     int twist () const
00355     {
00356       return elementInfo().template twist< codimension >( subEntity() );
00357     }
00358 
00360     template< int codim >
00361     int twist ( int i ) const
00362     {
00363       return elementInfo().template twist< codim >( grid().generic2alberta( codim, i ) );
00364     }
00365 
00366   private: 
00368     int nChild () const;
00369 
00371     const GridImp *grid_;
00372 
00373     // Alberta element info
00374     ElementInfo elementInfo_;
00375 
00376     // local coordinates within father 
00377     typedef MakeableInterfaceObject< Geometry > GeometryObject;
00378   };
00379 
00380 } // namespace Dune
00381 
00382 #endif // #if HAVE_ALBERTA
00383 
00384 #endif // #ifndef DUNE_ALBERTA_ENTITY_HH