dune-grid-dev-howto  2.1.1
identitygridentity.hh
Go to the documentation of this file.
00001 #ifndef DUNE_IDENTITYGRIDENTITY_HH
00002 #define DUNE_IDENTITYGRIDENTITY_HH
00003 
00009 namespace Dune {
00010 
00011 
00012 // Forward declarations
00013 
00014 template<int codim, int dim, class GridImp>
00015 class IdentityGridEntity;
00016 
00017 template<int codim, class GridImp>
00018 class IdentityGridEntityPointer;
00019 
00020 template<int codim, PartitionIteratorType pitype, class GridImp>
00021 class IdentityGridLevelIterator;
00022 
00023 template<class GridImp>
00024 class IdentityGridLevelIntersectionIterator;
00025 
00026 template<class GridImp>
00027 class IdentityGridLeafIntersectionIterator;
00028 
00029 template<class GridImp>
00030 class IdentityGridHierarchicIterator;
00031 
00032 
00033 // External forward declarations
00034 template< class Grid >
00035 class HostGridAccess;
00036 
00037 
00038 
00039 template<int codim, int dim, class GridImp>
00040 class IdentityGridMakeableEntity :
00041     public GridImp::template Codim<codim>::Entity
00042 {
00043     public:
00044     
00045         // The codimension of this entitypointer wrt the host grid
00046         enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension + codim};
00047     
00048         // EntityPointer to the equivalent entity in the host grid
00049         typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
00050         
00051         
00053         template< class HostGridEntityPointer >
00054         IdentityGridMakeableEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
00055             GridImp::template Codim<codim>::Entity (IdentityGridEntity<codim, dim, const GridImp>(identityGrid,hostEntity)),
00056             identityGrid_(identityGrid)
00057         {}
00058         
00059         
00061         template< class HostGridEntityPointer >
00062         void setToTarget(const HostGridEntityPointer& hostEntity) {
00063             this->realEntity.setToTarget(hostEntity);
00064         }
00065         
00066         
00068         const HostGridEntityPointer& getTarget() {
00069             return this->realEntity.hostEntity_;
00070         }
00071     
00072         
00073     private:
00074         
00075         const GridImp* identityGrid_;
00076 };
00077 
00078 
00079 //**********************************************************************
00080 //
00081 // --IdentityGridEntity
00082 // --Entity
00083 //
00091 template<int codim, int dim, class GridImp>
00092 class IdentityGridEntity :
00093     public EntityDefaultImplementation <codim,dim,GridImp,IdentityGridEntity>
00094 {
00095     friend class IdentityGridMakeableEntity<codim,dim,GridImp>;
00096 
00097     template <class GridImp_>
00098     friend class IdentityGridLevelIndexSet;
00099 
00100     template <class GridImp_>
00101     friend class IdentityGridLeafIndexSet;
00102 
00103     template <class GridImp_>
00104     friend class IdentityGridLocalIdSet;
00105 
00106     template <class GridImp_>
00107     friend class IdentityGridGlobalIdSet;
00108 
00109     friend class IdentityGridEntityPointer<codim,GridImp>;
00110 
00111     friend class HostGridAccess< typename remove_const< GridImp >::type >;
00112 
00113     
00114     private:
00115         
00116         typedef typename GridImp::ctype ctype;
00117         
00118         // The codimension of this entitypointer wrt the host grid
00119         enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension + codim};
00120 
00121         // EntityPointer to the equivalent entity in the host grid
00122         typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
00123         
00124 
00125     public:
00126     
00127         typedef typename GridImp::template Codim<codim>::Geometry Geometry;
00128     
00129         
00131         template< class HostGridEntityPointer >
00132         IdentityGridEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
00133             hostEntity_(hostEntity),
00134             identityGrid_(identityGrid),
00135             geo_(0),
00136             geoInFather_(0)
00137         {}
00138         
00139     
00141         IdentityGridEntity(const IdentityGridEntity& original) :
00142             hostEntity_(original.hostEntity_),
00143             identityGrid_(original.identityGrid_),
00144             geo_(0),
00145             geoInFather_(0)
00146         {}
00147     
00148         
00150         ~IdentityGridEntity()
00151         {
00152             if (geo_!=0)
00153             {
00154                 delete geo_;
00155                 geo_ = 0;
00156             }
00157             if (geoInFather_!=0)
00158             {
00159                 delete geoInFather_;
00160                 geoInFather_ = 0;
00161             }
00162         }
00163         
00164         
00166         IdentityGridEntity& operator=(const IdentityGridEntity& original)
00167         {
00168             if (this != &original)
00169             {
00170                 if (geo_!=0)
00171                 {
00172                     delete geo_;
00173                     geo_ = 0;
00174                 }
00175                 if (geoInFather_!=0)
00176                 {
00177                     delete geoInFather_;
00178                     geoInFather_ = 0;
00179                 }
00180                 identityGrid_ = original.identityGrid_;
00181                 hostEntity_ = original.hostEntity_;
00182             }
00183             return *this;
00184         }
00185 
00187         bool hasFather () const {
00188             return hostEntity_->hasFather();
00189         }
00190 
00192         int level () const {
00193             return hostEntity_->level();
00194         }
00195     
00196         
00199         PartitionType partitionType () const {
00200             return hostEntity_->partitionType();
00201         }
00202     
00203         
00207         template<int cc> int count () const{
00208             return hostEntity_->template count<cc>();
00209         }
00210         
00211         
00213         const Geometry& geometry () const
00214         {
00215             if (geo_==0)
00216                 geo_ = new MakeableInterfaceObject<Geometry>(hostEntity_->geometry());
00217             return *geo_;
00218         }
00219     
00220         
00221         HostGridEntityPointer hostEntity_;
00222     
00223         
00224     private:
00225     
00227         template< class HostGridEntityPointer >
00228         void setToTarget(const HostGridEntityPointer& target)
00229         {
00230             if(geo_!=0)
00231             {
00232                 delete geo_;
00233                 geo_ = 0;
00234             }
00235             if (geoInFather_!=0)
00236             {
00237                 delete geoInFather_;
00238                 geoInFather_ = 0;
00239             }
00240             hostEntity_ = target;
00241         }
00242     
00243         
00244         const GridImp* identityGrid_;
00245         
00247     mutable MakeableInterfaceObject<Geometry> *geo_;
00248     mutable MakeableInterfaceObject<Geometry> *geoInFather_;
00249 };
00250 
00251 
00252 
00253 
00254 //***********************
00255 //
00256 //  --IdentityGridEntity
00257 //
00258 //***********************
00266 template<int dim, class GridImp>
00267 class IdentityGridEntity<0,dim,GridImp> :
00268     public EntityDefaultImplementation<0,dim,GridImp, IdentityGridEntity>
00269 {
00270     friend class HostGridAccess< typename remove_const< GridImp >::type >;
00271 
00272     public:
00273     
00274         // The codimension of this entitypointer wrt the host grid
00275         enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension};
00276     
00277         // EntityPointer to the equivalent entity in the host grid
00278         typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
00279         
00280         typedef typename GridImp::template Codim<0>::Geometry Geometry;
00281     
00282         typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
00283     
00285         typedef IdentityGridLevelIntersectionIterator<GridImp> LevelIntersectionIterator;
00286     
00288         typedef IdentityGridLeafIntersectionIterator<GridImp> LeafIntersectionIterator;
00289     
00291         typedef IdentityGridHierarchicIterator<GridImp> HierarchicIterator;
00292         
00293         
00295         template< class HostGridEntityPointer >
00296         IdentityGridEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
00297             identityGrid_(identityGrid),
00298             geo_(0),
00299             geoInFather_(0),
00300             hostEntity_(hostEntity)
00301         {}
00302         
00303         
00305         IdentityGridEntity(const IdentityGridEntity& original) :
00306             identityGrid_(original.identityGrid_),
00307             geo_(0),
00308             geoInFather_(0),
00309             hostEntity_(original.hostEntity_)
00310         {}
00311     
00312         
00314         ~IdentityGridEntity()
00315         {
00316             if (geo_!=0)
00317             {
00318                 delete geo_;
00319                 geo_ = 0;
00320             }
00321             if (geoInFather_!=0)
00322             {
00323                 delete geoInFather_;
00324                 geoInFather_ = 0;
00325             }
00326         }
00327         
00328         
00330         IdentityGridEntity& operator=(const IdentityGridEntity& original)
00331         {
00332             if (this != &original)
00333             {
00334                 if (geo_!=0)
00335                 {
00336                     delete geo_;
00337                     geo_ = 0;
00338                 }
00339                 if (geoInFather_!=0)
00340                 {
00341                     delete geoInFather_;
00342                     geoInFather_ = 0;
00343                 }
00344                 identityGrid_ = original.identityGrid_;
00345                 hostEntity_ = original.hostEntity_;
00346             }
00347             return *this;
00348         }
00349 
00351         bool hasFather () const {
00352             return hostEntity_->hasFather();
00353         }
00354 
00356         int level () const
00357         {
00358             return hostEntity_->level();
00359         }
00360     
00361         
00363         PartitionType partitionType () const {
00364             return hostEntity_->partitionType();
00365         }
00366     
00367         
00369         const Geometry& geometry () const
00370         {
00371             if (geo_==0)
00372             {
00373                 geo_ = new MakeableInterfaceObject<Geometry>(hostEntity_->geometry());
00374             }
00375             return *geo_;
00376         }
00377     
00378         
00381         template<int cc>
00382         int count () const
00383         {
00384             return hostEntity_->template count<cc>();
00385         }
00386         
00387         
00391         template<int cc>
00392         typename GridImp::template Codim<cc>::EntityPointer subEntity (int i) const{
00393             return IdentityGridEntityPointer<cc,GridImp>(identityGrid_, hostEntity_->template subEntity<cc>(i));
00394         }
00395     
00396         
00398         IdentityGridLevelIntersectionIterator<GridImp> ilevelbegin () const{
00399             return IdentityGridLevelIntersectionIterator<GridImp>(identityGrid_,
00400                                                              hostEntity_->ilevelbegin());
00401         }
00402     
00403         
00405         IdentityGridLevelIntersectionIterator<GridImp> ilevelend () const{
00406             return IdentityGridLevelIntersectionIterator<GridImp>(identityGrid_,
00407                                                              hostEntity_->ilevelend());
00408         }
00409     
00410         
00412         IdentityGridLeafIntersectionIterator<GridImp> ileafbegin () const{
00413             return IdentityGridLeafIntersectionIterator<GridImp>(identityGrid_,
00414                                                                  hostEntity_->ileafbegin());
00415         }
00416     
00417         
00419         IdentityGridLeafIntersectionIterator<GridImp> ileafend () const{
00420             return IdentityGridLeafIntersectionIterator<GridImp>(identityGrid_,
00421                                                                  hostEntity_->ileafend());
00422         }
00423     
00424         
00426         bool isLeaf() const {
00427             return hostEntity_->isLeaf();
00428         }
00429     
00430         
00433         IdentityGridEntityPointer<0,GridImp> father () const {
00434             return IdentityGridEntityPointer<0,GridImp>(identityGrid_, hostEntity_->father());
00435         }
00436     
00437     
00447         const LocalGeometry& geometryInFather () const {
00448             if (geoInFather_==0)
00449                 geoInFather_ = new MakeableInterfaceObject<LocalGeometry>(hostEntity_->geometryInFather());
00450             return *geoInFather_;
00451         }
00452     
00453         
00458         IdentityGridHierarchicIterator<GridImp> hbegin (int maxLevel) const
00459         {
00460             return IdentityGridHierarchicIterator<const GridImp>(identityGrid_, *this, maxLevel);
00461         }
00462     
00463         
00465         IdentityGridHierarchicIterator<GridImp> hend (int maxLevel) const
00466         {
00467             return IdentityGridHierarchicIterator<const GridImp>(identityGrid_, *this, maxLevel, true);
00468         }
00469         
00470         
00472         bool wasRefined () const
00473         {
00474             if (identityGrid_->adaptationStep!=GridImp::adaptDone)
00475                 return false;
00476             
00477             int level = this->level();
00478             int index = identityGrid_->levelIndexSet(level).index(*this);
00479             return identityGrid_->refinementMark_[level][index];
00480         }
00481         
00482         
00484         bool mightBeCoarsened () const
00485         {
00486             return true;
00487         }
00488     
00489         
00490         // /////////////////////////////////////////
00491         //   Internal stuff
00492         // /////////////////////////////////////////
00493     
00494         
00496         template< class HostGridEntityPointer >
00497         void setToTarget(const HostGridEntityPointer& target)
00498         {
00499             if(geo_!=0)
00500             {
00501                 delete geo_;
00502                 geo_ = 0;
00503             }
00504             if (geoInFather_!=0)
00505             {
00506                 delete geoInFather_;
00507                 geoInFather_ = 0;
00508             }
00509             hostEntity_ = target;
00510         }
00511         
00512         
00513         const GridImp* identityGrid_;
00514         
00516         mutable MakeableInterfaceObject<Geometry> *geo_;
00517         
00519         mutable MakeableInterfaceObject<LocalGeometry> *geoInFather_;
00520 
00522         HostGridEntityPointer hostEntity_;
00523     
00524         
00525     private:
00526     
00527         typedef typename GridImp::ctype ctype;
00528 
00529 }; // end of IdentityGridEntity codim = 0
00530 
00531 
00532 } // namespace Dune
00533 
00534 
00535 #endif