gridpart.hh

Go to the documentation of this file.
00001 #ifndef DUNE_GRIDPART_HH
00002 #define DUNE_GRIDPART_HH
00003 
00004 //- System includes
00005 
00006 //- Dune includes
00007 #include <dune/grid/common/grid.hh>
00008 #include <dune/grid/common/defaultindexsets.hh>
00009 #include <dune/grid/common/datahandleif.hh>
00010 
00011 #include <dune/common/bartonnackmanifcheck.hh>
00012 #include <dune/common/deprecated.hh>
00013 
00057 namespace Dune {
00064   // Forward declarations
00065   template <class GridImp, PartitionIteratorType pitype>
00066   class LevelGridPartTraits;
00067   template <class GridImp, PartitionIteratorType pitype>
00068   class LeafGridPartTraits;
00069   template <class GridImp, PartitionIteratorType pitype>
00070   class HierarchicGridPartTraits;
00071 
00079   template <class GridPartTraits>
00080   class GridPartInterface {
00081   public:
00083     typedef GridPartTraits Traits;
00084 
00086     typedef typename GridPartTraits::GridPartType GridPartType;
00087 
00088    
00090     typedef typename GridPartTraits::GridType GridType;
00091     
00093     typedef typename GridPartTraits::IndexSetType IndexSetType;
00094 
00096     typedef typename GridPartTraits::IntersectionIteratorType IntersectionIteratorType; 
00097 
00099     typedef IntersectionIteratorType IntersectionType; 
00100 
00102     typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
00103     
00105     enum { conforming = GridPartTraits :: conforming };
00106   public:
00108     const GridType & grid () const 
00109     { 
00110       CHECK_INTERFACE_IMPLEMENTATION((asImp().grid()));
00111       return asImp().grid(); 
00112     }
00114     GridType & grid () 
00115     { 
00116       CHECK_INTERFACE_IMPLEMENTATION((asImp().grid()));
00117       return asImp().grid(); 
00118     }
00119     
00121     const IndexSetType& indexSet() const 
00122     { 
00123       CHECK_INTERFACE_IMPLEMENTATION((asImp().indexSet()));
00124       return asImp().indexSet(); 
00125     }
00126 
00130     template <int cd>
00131     typename GridPartTraits::template Codim<cd>::IteratorType
00132     begin() const 
00133     { 
00134       CHECK_INTERFACE_IMPLEMENTATION((asImp().template begin<cd>()));
00135       return asImp().template begin<cd>(); 
00136     }
00137 
00141     template <int cd>
00142     typename GridPartTraits::template Codim<cd>::IteratorType
00143     end() const 
00144     { 
00145       CHECK_INTERFACE_IMPLEMENTATION((asImp().template end<cd>()));
00146       return asImp().template end<cd>(); 
00147     }
00148 
00150     int level() const 
00151     { 
00152       CHECK_INTERFACE_IMPLEMENTATION((asImp().level()));
00153       return asImp().level(); 
00154     }
00155 
00157     IntersectionIteratorType ibegin(const EntityCodim0Type & en) const 
00158     {
00159       CHECK_INTERFACE_IMPLEMENTATION((asImp().ibegin(en)));
00160       return asImp().ibegin(en); 
00161     }
00162     
00164     IntersectionIteratorType iend(const EntityCodim0Type & en) const 
00165     {
00166       CHECK_INTERFACE_IMPLEMENTATION((asImp().iend(en)));
00167       return asImp().iend(en); 
00168     }
00169 
00171     template <class DataHandleImp,class DataType>
00172     void communicate(CommDataHandleIF<DataHandleImp,DataType> & data, 
00173                      InterfaceType iftype, CommunicationDirection dir) const 
00174     {
00175       CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().communicate(data,iftype,dir)));
00176     }
00177 
00178   protected: 
00180     GridPartInterface () {}  
00181 
00182   private:
00183     // Barton-Nackman 
00184     GridPartType& asImp() { 
00185       return static_cast<GridPartType&>(*this); 
00186     }
00187     
00188     // const Barton-Nackman 
00189     const GridPartType& asImp() const { 
00190       return static_cast<const GridPartType&>(*this);
00191     }
00192   };
00193 
00195   template <class GridPartTraits>
00196   class GridPartDefault : 
00197     public GridPartInterface<GridPartTraits> {
00198   public:
00200     typedef typename GridPartTraits::GridType GridType;
00202     typedef typename GridPartTraits::IndexSetType IndexSetType;
00203 
00204   protected:
00206     GridPartDefault(GridType& grid, const IndexSetType& iset) :
00207       GridPartInterface<GridPartTraits>(),
00208       grid_(grid),
00209       iset_(iset) {}
00210 
00211     ~GridPartDefault() {}
00212 
00213   public:  
00215     const GridType& grid() const { return grid_; }
00216 
00218     GridType& grid() { return grid_; }
00219 
00221     const IndexSetType& indexSet() const { return iset_; }
00222 
00223   private:
00224     GridType& grid_; 
00225     const IndexSetType& iset_;
00226   };
00227 
00229   template <class GridImp, PartitionIteratorType pitype = Interior_Partition>
00230   class LevelGridPart : 
00231     public GridPartDefault<LevelGridPartTraits<GridImp,pitype> > {
00232   public:
00233     //- Public typedefs and enums
00235     typedef LevelGridPartTraits<GridImp,pitype> Traits;
00237     typedef typename Traits::GridType GridType;
00239     typedef typename Traits::IndexSetType IndexSetType;
00240     
00242     typedef typename Traits::IntersectionIteratorType IntersectionIteratorType ;
00243     
00245     typedef IntersectionIteratorType IntersectionType;
00246     
00248     template <int cd>
00249     struct Codim {
00252       typedef typename Traits::template Codim<cd>::IteratorType IteratorType;
00253     };
00254     
00256     enum { conforming = Traits :: conforming };
00257   private:
00258     typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
00259 
00260   public:
00261     //- Public methods
00263     LevelGridPart(GridType& grid, int level ) :
00264       GridPartDefault<Traits>(grid,isetWrapper_),
00265       isetWrapper_(grid,level),
00266       level_(level) {}
00267     
00269     LevelGridPart(const GridType& grid) :
00270       GridPartDefault<Traits>(grid,isetWrapper_),
00271       isetWrapper_(grid,grid.maxLevel()),
00272       level_(grid.maxLevel()) {}
00273     
00275     template <int cd>
00276     typename Traits::template Codim<cd>::IteratorType begin() const {
00277       return this->grid().template lbegin<cd,pitype>(level_);
00278     }
00279 
00281     template <int cd>
00282     typename Traits::template Codim<cd>::IteratorType end() const {
00283       return this->grid().template lend<cd,pitype>(level_);
00284     }
00285     
00287     IntersectionIteratorType ibegin(const EntityCodim0Type & en) const 
00288     {
00289       return en.ilevelbegin();
00290     }
00291     
00293     IntersectionIteratorType iend(const EntityCodim0Type & en) const 
00294     {
00295       return en.ilevelend();
00296     }
00297 
00299     int level() const { return level_; }
00300 
00302     template <class DataHandleImp,class DataType>
00303     void communicate(CommDataHandleIF<DataHandleImp,DataType> & data, 
00304                      InterfaceType iftype, CommunicationDirection dir) const 
00305     {
00306       this->grid().communicate(data,iftype,dir,level());
00307     }
00308 
00309   private:
00311     IndexSetType isetWrapper_;
00312     const int level_;
00313   };
00314 
00316   template <class GridImp, PartitionIteratorType pitype>
00317   struct LevelGridPartTraits {
00318 
00320     typedef GridImp GridType;
00321 
00323     typedef LevelGridPart<GridImp,pitype> GridPartType;
00324 
00326     typedef WrappedLevelIndexSet<GridType> IndexSetType;
00327 
00329     typedef typename GridType::template Codim<0>::Entity::
00330       LevelIntersectionIterator IntersectionIteratorType;
00331 
00333     typedef IntersectionIteratorType IntersectionType;
00334 
00336     template <int cd>
00337     struct Codim {
00339       typedef typename GridImp::template Codim<cd>::template Partition<pitype>::LevelIterator IteratorType;
00340     };
00341 
00343     enum { conforming = Capabilities::isLevelwiseConforming<GridType>::v };
00344   };
00345 
00347   template <class GridImp, PartitionIteratorType pitype = Interior_Partition>
00348   class LeafGridPart :
00349     public GridPartDefault<LeafGridPartTraits<GridImp,pitype> > {
00350   public:
00351     //- Public typedefs and enums
00353     typedef LeafGridPartTraits<GridImp,pitype> Traits;
00355     typedef typename Traits::GridType GridType;
00357     typedef typename Traits::IndexSetType IndexSetType;
00358     
00360     typedef typename Traits::IntersectionIteratorType IntersectionIteratorType ;
00361     
00363     typedef IntersectionIteratorType IntersectionType;
00364 
00366     template <int cd>
00367     struct Codim {
00369       typedef typename Traits::template Codim<cd>::IteratorType IteratorType;
00370     };
00371     
00373     enum { conforming = Traits :: conforming };
00374   private:
00375     typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
00376 
00377   public:
00378     //- Public methods
00380     LeafGridPart(GridType& grid) :
00381       GridPartDefault<Traits>(grid, isetWrapper_),
00382       isetWrapper_(grid) {}
00383 
00385     template <int cd>
00386     typename Traits::template Codim<cd>::IteratorType begin() const {
00387       return this->grid().template leafbegin<cd,pitype>();
00388     }
00389 
00391     template <int cd>
00392     typename Traits::template Codim<cd>::IteratorType end() const {
00393       return this->grid().template leafend<cd,pitype>();
00394     }
00395 
00397     IntersectionIteratorType ibegin(const EntityCodim0Type & en) const 
00398     {
00399       return en.ileafbegin();
00400     }
00401     
00403     IntersectionIteratorType iend(const EntityCodim0Type & en) const 
00404     {
00405       return en.ileafend();
00406     }
00407 
00409     int level() const { return this->grid().maxLevel(); }
00410 
00412     template <class DataHandleImp,class DataType>
00413     void communicate(CommDataHandleIF<DataHandleImp,DataType> & data, 
00414                      InterfaceType iftype, CommunicationDirection dir) const 
00415     {
00416       this->grid().communicate(data,iftype,dir);
00417     }
00418 
00419   private: 
00421     IndexSetType isetWrapper_;
00422   };
00423 
00425   template <class GridImp,PartitionIteratorType pitype>
00426   struct LeafGridPartTraits {
00427 
00429     typedef GridImp GridType;
00430 
00432     typedef LeafGridPart<GridImp,pitype> GridPartType;
00433 
00435     typedef WrappedLeafIndexSet<GridType> IndexSetType;
00436 
00438     typedef typename GridType::template Codim<0>::Entity::
00439       LeafIntersectionIterator IntersectionIteratorType;
00440 
00442     typedef IntersectionIteratorType IntersectionType;
00443     
00445     template <int cd>
00446     struct Codim {
00448       typedef typename GridImp::template Codim<cd>::template Partition<pitype>::LeafIterator IteratorType;
00449     };
00450 
00452     enum { conforming = Capabilities::isLeafwiseConforming<GridType>::v };
00453   };
00454 
00455 
00456   //**************************************************************
00463   template <class GridImp, PartitionIteratorType pitype = Interior_Partition>
00464   class HierarchicGridPart :
00465     public GridPartDefault< HierarchicGridPartTraits<GridImp,pitype> > {
00466   public:
00467     //- Public typedefs and enums
00469     typedef HierarchicGridPartTraits<GridImp,pitype> Traits;
00471     typedef typename Traits::GridType GridType;
00473     typedef typename Traits::IndexSetType IndexSetType;
00474     
00476     typedef typename Traits::IntersectionIteratorType IntersectionIteratorType ;
00477     
00479     typedef IntersectionIteratorType IntersectionType;
00480     
00482     template <int cd>
00483     struct Codim {
00484       typedef typename Traits::template Codim<cd>::IteratorType IteratorType;
00485     };
00486 
00488     enum { conforming = Traits :: conforming };
00489   private:
00490     typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
00491 
00492   public:
00493     //- Public methods
00495     HierarchicGridPart(GridType& grid) :
00496       GridPartDefault<Traits>(grid, isetWrapper_),
00497       isetWrapper_(grid) {}
00498 
00500     HierarchicGridPart(GridType& grid, const IndexSetType & ) :
00501       GridPartDefault<Traits>(grid, isetWrapper_),
00502       isetWrapper_(grid) {}
00503 
00505     template <int cd>
00506     typename Traits::template Codim<cd>::IteratorType begin() const {
00507       return this->grid().template leafbegin<cd,pitype>();
00508     }
00509 
00511     template <int cd>
00512     typename Traits::template Codim<cd>::IteratorType end() const {
00513       return this->grid().template leafend<cd,pitype>();
00514     }
00515 
00517     IntersectionIteratorType ibegin(const EntityCodim0Type & en) const 
00518     {
00519       return en.ileafbegin();
00520     }
00521     
00523     IntersectionIteratorType iend(const EntityCodim0Type & en) const 
00524     {
00525       return en.ileafend();
00526     }
00527 
00529     int level() const { return this->grid().maxLevel(); }
00530 
00532     template <class DataHandleImp,class DataType>
00533     void communicate(CommDataHandleIF<DataHandleImp,DataType> & data, 
00534                      InterfaceType iftype, CommunicationDirection dir) const 
00535     {
00536       this->grid().communicate(data,iftype,dir);
00537     }
00538 
00539   private: 
00541     IndexSetType isetWrapper_;
00542   };
00543 
00545   template <class GridImp,PartitionIteratorType pitype>
00546   struct HierarchicGridPartTraits {
00548     typedef GridImp GridType;
00550     typedef HierarchicGridPart<GridImp,pitype> GridPartType;
00552     typedef WrappedHierarchicIndexSet<GridType> IndexSetType;
00554     typedef typename GridType::template Codim<0>::Entity::
00555       LeafIntersectionIterator IntersectionIteratorType;
00556 
00558     typedef IntersectionIteratorType IntersectionType;
00559     
00561     template <int cd>
00562     struct Codim {
00564       typedef typename GridImp::template Codim<cd>::template Partition<pitype>::LeafIterator IteratorType;
00565     };
00566 
00568     enum { conforming = Capabilities::isLeafwiseConforming<GridType>::v };
00569   };
00570 
00571 #undef CHECK_INTERFACE_IMPLEMENTATION
00572 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
00573 
00575 } // end namespace Dune
00576 
00577 #endif

Generated on 6 Nov 2008 with Doxygen (ver 1.5.6) [logfile].