identitygridentity.hh

Go to the documentation of this file.
00001 #ifndef DUNE_IDENTITYGRIDENTITY_HH
00002 #define DUNE_IDENTITYGRIDENTITY_HH
00003 
00008 #include <dune/grid/common/referenceelements.hh>
00009 
00010 
00011 namespace Dune {
00012 
00013 
00014 // Forward declarations
00015 
00016 template<int codim, int dim, class GridImp>
00017 class IdentityGridEntity;
00018 
00019 template<int codim, class GridImp>
00020 class IdentityGridEntityPointer;
00021 
00022 template<int codim, PartitionIteratorType pitype, class GridImp>
00023 class IdentityGridLevelIterator;
00024 
00025 template<class GridImp>
00026 class IdentityGridLevelIntersectionIterator;
00027 
00028 template<class GridImp>
00029 class IdentityGridLeafIntersectionIterator;
00030 
00031 template<class GridImp>
00032 class IdentityGridHierarchicIterator;
00033 
00034 
00035 
00036 
00037 template<int codim, int dim, class GridImp>
00038 class IdentityGridMakeableEntity :
00039     public GridImp::template Codim<codim>::Entity
00040 {
00041     public:
00042     
00043         // The codimension of this entitypointer wrt the host grid
00044         enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension + codim};
00045     
00046         // EntityPointer to the equivalent entity in the host grid
00047         typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
00048         
00049         
00051         IdentityGridMakeableEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
00052             GridImp::template Codim<codim>::Entity (IdentityGridEntity<codim, dim, const GridImp>(identityGrid,hostEntity)),
00053             identityGrid_(identityGrid)
00054         {}
00055         
00056         
00058         void setToTarget(const HostGridEntityPointer& hostEntity) {
00059             this->realEntity.setToTarget(hostEntity);
00060         }
00061         
00062         
00064         const HostGridEntityPointer& getTarget() {
00065             return this->realEntity.hostEntity_;
00066         }
00067     
00068         
00069     private:
00070         
00071         const GridImp* identityGrid_;
00072 };
00073 
00074 
00075 //**********************************************************************
00076 //
00077 // --IdentityGridEntity
00078 // --Entity
00079 //
00087 template<int codim, int dim, class GridImp>
00088 class IdentityGridEntity :
00089     public EntityDefaultImplementation <codim,dim,GridImp,IdentityGridEntity>
00090 {
00091     friend class IdentityGridMakeableEntity<codim,dim,GridImp>;
00092 
00093     template <class GridImp_>
00094     friend class IdentityGridLevelIndexSet;
00095 
00096     template <class GridImp_>
00097     friend class IdentityGridLeafIndexSet;
00098 
00099     template <class GridImp_>
00100     friend class IdentityGridLocalIdSet;
00101 
00102     template <class GridImp_>
00103     friend class IdentityGridGlobalIdSet;
00104 
00105     friend class IdentityGridEntityPointer<codim,GridImp>;
00106 
00107     
00108     private:
00109         
00110         typedef typename GridImp::ctype ctype;
00111         
00112         // The codimension of this entitypointer wrt the host grid
00113         enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension + codim};
00114 
00115         // EntityPointer to the equivalent entity in the host grid
00116         typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
00117         
00118 
00119     public:
00120     
00121         typedef typename GridImp::template Codim<codim>::Geometry Geometry;
00122     
00123         
00125         IdentityGridEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
00126             hostEntity_(hostEntity),
00127             identityGrid_(identityGrid),
00128             geo_(0),
00129             geoInFather_(0)
00130         {}
00131         
00132     
00134         IdentityGridEntity(const IdentityGridEntity& original) :
00135             hostEntity_(original.hostEntity_),
00136             identityGrid_(original.identityGrid_),
00137             geo_(0),
00138             geoInFather_(0)
00139         {}
00140     
00141         
00143         ~IdentityGridEntity()
00144         {
00145             if (geo_!=0)
00146             {
00147                 delete geo_;
00148                 geo_ = 0;
00149             }
00150             if (geoInFather_!=0)
00151             {
00152                 delete geoInFather_;
00153                 geoInFather_ = 0;
00154             }
00155         }
00156         
00157         
00159         IdentityGridEntity& operator=(const IdentityGridEntity& original)
00160         {
00161             if (this != &original)
00162             {
00163                 if (geo_!=0)
00164                 {
00165                     delete geo_;
00166                     geo_ = 0;
00167                 }
00168                 if (geoInFather_!=0)
00169                 {
00170                     delete geoInFather_;
00171                     geoInFather_ = 0;
00172                 }
00173                 identityGrid_ = original.identityGrid_;
00174                 hostEntity_ = original.hostEntity_;
00175             }
00176             return *this;
00177         }
00178 
00180         bool hasFather () const {
00181             return hostEntity_->hasFather();
00182         }
00183 
00185         int level () const {
00186             return hostEntity_->level();
00187         }
00188     
00189         
00192         PartitionType partitionType () const {
00193             return hostEntity_->partitionType();
00194         }
00195     
00196         
00200         template<int cc> int count () const{
00201             return hostEntity_->template count<cc>();
00202         }
00203         
00204         
00206         const Geometry& geometry () const
00207         {
00208             if (geo_==0)
00209                 geo_ = new MakeableInterfaceObject<Geometry>(hostEntity_->geometry());
00210             return *geo_;
00211         }
00212     
00213         
00214         HostGridEntityPointer hostEntity_;
00215     
00216         
00217     private:
00218     
00220         void setToTarget(const HostGridEntityPointer& target)
00221         {
00222             if(geo_!=0)
00223             {
00224                 delete geo_;
00225                 geo_ = 0;
00226             }
00227             if (geoInFather_!=0)
00228             {
00229                 delete geoInFather_;
00230                 geoInFather_ = 0;
00231             }
00232             hostEntity_ = target;
00233         }
00234     
00235         
00236         const GridImp* identityGrid_;
00237         
00239     mutable MakeableInterfaceObject<Geometry> *geo_;
00240     mutable MakeableInterfaceObject<Geometry> *geoInFather_;
00241 };
00242 
00243 
00244 
00245 
00246 //***********************
00247 //
00248 //  --IdentityGridEntity
00249 //
00250 //***********************
00258 template<int dim, class GridImp>
00259 class IdentityGridEntity<0,dim,GridImp> :
00260     public EntityDefaultImplementation<0,dim,GridImp, IdentityGridEntity>
00261 {
00262     public:
00263     
00264         // The codimension of this entitypointer wrt the host grid
00265         enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension};
00266     
00267         // EntityPointer to the equivalent entity in the host grid
00268         typedef typename GridImp::HostGridType::Traits::template Codim<CodimInHostGrid>::EntityPointer HostGridEntityPointer;
00269         
00270         typedef typename GridImp::template Codim<0>::Geometry Geometry;
00271     
00272         typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
00273     
00275         typedef IdentityGridLevelIntersectionIterator<GridImp> LevelIntersectionIterator;
00276     
00278         typedef IdentityGridLeafIntersectionIterator<GridImp> LeafIntersectionIterator;
00279     
00281         typedef IdentityGridHierarchicIterator<GridImp> HierarchicIterator;
00282         
00283         
00285         IdentityGridEntity(const GridImp* identityGrid, const HostGridEntityPointer& hostEntity) :
00286             identityGrid_(identityGrid),
00287             geo_(0),
00288             geoInFather_(0),
00289             hostEntity_(hostEntity)
00290         {}
00291         
00292         
00294         IdentityGridEntity(const IdentityGridEntity& original) :
00295             identityGrid_(original.identityGrid_),
00296             geo_(0),
00297             geoInFather_(0),
00298             hostEntity_(original.hostEntity_)
00299         {}
00300     
00301         
00303         ~IdentityGridEntity()
00304         {
00305             if (geo_!=0)
00306             {
00307                 delete geo_;
00308                 geo_ = 0;
00309             }
00310             if (geoInFather_!=0)
00311             {
00312                 delete geoInFather_;
00313                 geoInFather_ = 0;
00314             }
00315         }
00316         
00317         
00319         IdentityGridEntity& operator=(const IdentityGridEntity& original)
00320         {
00321             if (this != &original)
00322             {
00323                 if (geo_!=0)
00324                 {
00325                     delete geo_;
00326                     geo_ = 0;
00327                 }
00328                 if (geoInFather_!=0)
00329                 {
00330                     delete geoInFather_;
00331                     geoInFather_ = 0;
00332                 }
00333                 identityGrid_ = original.identityGrid_;
00334                 hostEntity_ = original.hostEntity_;
00335             }
00336             return *this;
00337         }
00338 
00340         bool hasFather () const {
00341             return hostEntity_->hasFather();
00342         }
00343 
00345         int level () const
00346         {
00347             return hostEntity_->level();
00348         }
00349     
00350         
00352         PartitionType partitionType () const {
00353             return hostEntity_->partitionType();
00354         }
00355     
00356         
00358         const Geometry& geometry () const
00359         {
00360             if (geo_==0)
00361             {
00362                 geo_ = new MakeableInterfaceObject<Geometry>(hostEntity_->geometry());
00363             }
00364             return *geo_;
00365         }
00366     
00367         
00370         template<int cc>
00371         int count () const
00372         {
00373             return hostEntity_->template count<cc>();
00374         }
00375         
00376         
00380         template<int cc>
00381         typename GridImp::template Codim<cc>::EntityPointer subEntity (int i) const{
00382             return IdentityGridEntityPointer<cc,GridImp>(identityGrid_, hostEntity_->template subEntity<cc>(i));
00383         }
00384     
00385         
00387         IdentityGridLevelIntersectionIterator<GridImp> ilevelbegin () const{
00388             return IdentityGridLevelIntersectionIterator<GridImp>(identityGrid_,
00389                                                              hostEntity_->ilevelbegin());
00390         }
00391     
00392         
00394         IdentityGridLevelIntersectionIterator<GridImp> ilevelend () const{
00395             return IdentityGridLevelIntersectionIterator<GridImp>(identityGrid_,
00396                                                              hostEntity_->ilevelend());
00397         }
00398     
00399         
00401         IdentityGridLeafIntersectionIterator<GridImp> ileafbegin () const{
00402             return IdentityGridLeafIntersectionIterator<GridImp>(identityGrid_,
00403                                                                  hostEntity_->ileafbegin());
00404         }
00405     
00406         
00408         IdentityGridLeafIntersectionIterator<GridImp> ileafend () const{
00409             return IdentityGridLeafIntersectionIterator<GridImp>(identityGrid_,
00410                                                                  hostEntity_->ileafend());
00411         }
00412     
00413         
00415         bool isLeaf() const {
00416             return hostEntity_->isLeaf();
00417         }
00418     
00419         
00422         IdentityGridEntityPointer<0,GridImp> father () const {
00423             return IdentityGridEntityPointer<0,GridImp>(identityGrid_, hostEntity_->father());
00424         }
00425     
00426     
00436         const LocalGeometry& geometryInFather () const {
00437             if (geoInFather_==0)
00438                 geoInFather_ = new MakeableInterfaceObject<LocalGeometry>(hostEntity_->geometryInFather());
00439             return *geoInFather_;
00440         }
00441     
00442         
00447         IdentityGridHierarchicIterator<GridImp> hbegin (int maxLevel) const
00448         {
00449             return IdentityGridHierarchicIterator<const GridImp>(identityGrid_, *this, maxLevel);
00450         }
00451     
00452         
00454         IdentityGridHierarchicIterator<GridImp> hend (int maxLevel) const
00455         {
00456             return IdentityGridHierarchicIterator<const GridImp>(identityGrid_, *this, maxLevel, true);
00457         }
00458         
00459         
00461         bool wasRefined () const
00462         {
00463             if (identityGrid_->adaptationStep!=GridImp::adaptDone)
00464                 return false;
00465             
00466             int level = this->level();
00467             int index = identityGrid_->levelIndexSet(level).index(*this);
00468             return identityGrid_->refinementMark_[level][index];
00469         }
00470         
00471         
00473         bool mightBeCoarsened () const
00474         {
00475             return true;
00476         }
00477     
00478         
00479         // /////////////////////////////////////////
00480         //   Internal stuff
00481         // /////////////////////////////////////////
00482     
00483         
00485         void setToTarget(const HostGridEntityPointer& target)
00486         {
00487             if(geo_!=0)
00488             {
00489                 delete geo_;
00490                 geo_ = 0;
00491             }
00492             if (geoInFather_!=0)
00493             {
00494                 delete geoInFather_;
00495                 geoInFather_ = 0;
00496             }
00497             hostEntity_ = target;
00498         }
00499         
00500         
00501         const GridImp* identityGrid_;
00502         
00504         mutable MakeableInterfaceObject<Geometry> *geo_;
00505         
00507         mutable MakeableInterfaceObject<LocalGeometry> *geoInFather_;
00508 
00510         HostGridEntityPointer hostEntity_;
00511     
00512         
00513     private:
00514     
00515         typedef typename GridImp::ctype ctype;
00516 
00517 }; // end of IdentityGridEntity codim = 0
00518 
00519 
00520 } // namespace Dune
00521 
00522 
00523 #endif
Generated on Sat Apr 24 11:13:38 2010 for dune-grid-dev-howto by  doxygen 1.6.3