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 
00056 namespace Dune {
00063   // Forward declarations
00064   template <class GridImp, PartitionIteratorType pitype>
00065   class LevelGridPartTraits;
00066   template <class GridImp, PartitionIteratorType pitype>
00067   class LeafGridPartTraits;
00068   template <class GridImp, PartitionIteratorType pitype>
00069   class HierarchicGridPartTraits;
00070 
00078   template <class GridPartTraits>
00079   class GridPartInterface {
00080   public:
00082     typedef typename GridPartTraits::GridPartType GridPartType;
00083    
00085     typedef typename GridPartTraits::GridType GridType;
00086     
00088     typedef typename GridPartTraits::IndexSetType IndexSetType;
00089 
00091     typedef typename GridPartTraits::IntersectionIteratorType IntersectionIteratorType; 
00092 
00094     typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
00095     
00097     enum { conforming = GridPartTraits :: conforming };
00098   public:
00100     const GridType & grid () const 
00101     { 
00102       CHECK_INTERFACE_IMPLEMENTATION((asImp().grid()));
00103       return asImp().grid(); 
00104     }
00106     GridType & grid () 
00107     { 
00108       CHECK_INTERFACE_IMPLEMENTATION((asImp().grid()));
00109       return asImp().grid(); 
00110     }
00111     
00113     const IndexSetType& indexSet() const 
00114     { 
00115       CHECK_INTERFACE_IMPLEMENTATION((asImp().indexSet()));
00116       return asImp().indexSet(); 
00117     }
00118 
00122     template <int cd>
00123     typename GridPartTraits::template Codim<cd>::IteratorType
00124     begin() const 
00125     { 
00126       CHECK_INTERFACE_IMPLEMENTATION((asImp().begin()));
00127       return asImp().begin(); 
00128     }
00129 
00133     template <int cd>
00134     typename GridPartTraits::template Codim<cd>::IteratorType
00135     end() const 
00136     { 
00137       CHECK_INTERFACE_IMPLEMENTATION((asImp().end()));
00138       return asImp().end(); 
00139     }
00140 
00142     int level() const 
00143     { 
00144       CHECK_INTERFACE_IMPLEMENTATION((asImp().level()));
00145       return asImp().level(); 
00146     }
00147 
00149     IntersectionIteratorType ibegin(const EntityCodim0Type & en) const 
00150     {
00151       CHECK_INTERFACE_IMPLEMENTATION((asImp().ibegin(en)));
00152       return asImp().ibegin(en); 
00153     }
00154     
00156     IntersectionIteratorType iend(const EntityCodim0Type & en) const 
00157     {
00158       CHECK_INTERFACE_IMPLEMENTATION((asImp().iend(en)));
00159       return asImp().iend(en); 
00160     }
00161 
00163     template <class DataHandleImp,class DataType>
00164     void communicate(CommDataHandleIF<DataHandleImp,DataType> & data, 
00165                      InterfaceType iftype, CommunicationDirection dir) const 
00166     {
00167       CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().communicate(data,iftype,dir)));
00168     }
00169 
00170   protected: 
00172     GridPartInterface () {}  
00173 
00174   private:
00175     // Barton-Nackman 
00176     GridPartType& asImp() { 
00177       return static_cast<GridPartType&>(*this); 
00178     }
00179     
00180     // const Barton-Nackman 
00181     const GridPartType& asImp() const { 
00182       return static_cast<const GridPartType&>(*this);
00183     }
00184   };
00185 
00187   template <class GridPartTraits>
00188   class GridPartDefault : 
00189     public GridPartInterface<GridPartTraits> {
00190   public:
00192     typedef typename GridPartTraits::GridType GridType;
00194     typedef typename GridPartTraits::IndexSetType IndexSetType;
00195 
00196   protected:
00198     GridPartDefault(GridType& grid, const IndexSetType& iset) :
00199       GridPartInterface<GridPartTraits>(),
00200       grid_(grid),
00201       iset_(iset) {}
00202 
00203     ~GridPartDefault() {}
00204 
00205   public:  
00207     const GridType& grid() const { return grid_; }
00208 
00210     GridType& grid() { return grid_; }
00211 
00213     const IndexSetType& indexSet() const { return iset_; }
00214 
00215   private:
00216     GridType& grid_; 
00217     const IndexSetType& iset_;
00218   };
00219 
00221   template <class GridImp, PartitionIteratorType pitype = Interior_Partition>
00222   class LevelGridPart : 
00223     public GridPartDefault<LevelGridPartTraits<GridImp,pitype> > {
00224   public:
00225     //- Public typedefs and enums
00227     typedef LevelGridPartTraits<GridImp,pitype> Traits;
00229     typedef typename Traits::GridType GridType;
00231     typedef typename Traits::IndexSetType IndexSetType;
00232     
00234     typedef typename Traits::IntersectionIteratorType IntersectionIteratorType ;
00235     
00237     template <int cd>
00238     struct Codim {
00241       typedef typename Traits::template Codim<cd>::IteratorType IteratorType;
00242     };
00243     
00245     enum { conforming = Traits :: conforming };
00246   private:
00247     typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
00248 
00249   public:
00250     //- Public methods
00252     LevelGridPart(GridType& grid, int level ) :
00253       GridPartDefault<Traits>(grid,isetWrapper_),
00254       isetWrapper_(grid,level),
00255       level_(level) {}
00256     
00258     LevelGridPart(const GridType& grid) :
00259       GridPartDefault<Traits>(grid,isetWrapper_),
00260       isetWrapper_(grid,grid.maxLevel()),
00261       level_(grid.maxLevel()) {}
00262     
00264     template <int cd>
00265     typename Traits::template Codim<cd>::IteratorType begin() const {
00266       return this->grid().template lbegin<cd,pitype>(level_);
00267     }
00268 
00270     template <int cd>
00271     typename Traits::template Codim<cd>::IteratorType end() const {
00272       return this->grid().template lend<cd,pitype>(level_);
00273     }
00274     
00276     IntersectionIteratorType ibegin(const EntityCodim0Type & en) const 
00277     {
00278       return en.ilevelbegin();
00279     }
00280     
00282     IntersectionIteratorType iend(const EntityCodim0Type & en) const 
00283     {
00284       return en.ilevelend();
00285     }
00286 
00288     int level() const { return level_; }
00289 
00291     template <class DataHandleImp,class DataType>
00292     void communicate(CommDataHandleIF<DataHandleImp,DataType> & data, 
00293                      InterfaceType iftype, CommunicationDirection dir) const 
00294     {
00295       this->grid().communicate(data,iftype,dir,level());
00296     }
00297 
00298   private:
00300     IndexSetType isetWrapper_;
00301     const int level_;
00302   };
00303 
00305   template <class GridImp, PartitionIteratorType pitype>
00306   struct LevelGridPartTraits {
00307 
00309     typedef GridImp GridType;
00310 
00312     typedef LevelGridPart<GridImp,pitype> GridPartType;
00313 
00315     typedef WrappedLevelIndexSet<GridType> IndexSetType;
00316 
00318     typedef typename GridType::template Codim<0>::Entity::
00319       LevelIntersectionIterator IntersectionIteratorType;
00320 
00322     template <int cd>
00323     struct Codim {
00325       typedef typename GridImp::template Codim<cd>::template Partition<pitype>::LevelIterator IteratorType;
00326     };
00327 
00329     enum { conforming = Capabilities::isLevelwiseConforming<GridType>::v };
00330   };
00331 
00333   template <class GridImp, PartitionIteratorType pitype = Interior_Partition>
00334   class LeafGridPart :
00335     public GridPartDefault<LeafGridPartTraits<GridImp,pitype> > {
00336   public:
00337     //- Public typedefs and enums
00339     typedef LeafGridPartTraits<GridImp,pitype> Traits;
00341     typedef typename Traits::GridType GridType;
00343     typedef typename Traits::IndexSetType IndexSetType;
00344     
00346     typedef typename Traits::IntersectionIteratorType IntersectionIteratorType ;
00347     
00349     template <int cd>
00350     struct Codim {
00352       typedef typename Traits::template Codim<cd>::IteratorType IteratorType;
00353     };
00354     
00356     enum { conforming = Traits :: conforming };
00357   private:
00358     typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
00359 
00360   public:
00361     //- Public methods
00363     LeafGridPart(GridType& grid) :
00364       GridPartDefault<Traits>(grid, isetWrapper_),
00365       isetWrapper_(grid) {}
00366 
00368     template <int cd>
00369     typename Traits::template Codim<cd>::IteratorType begin() const {
00370       return this->grid().template leafbegin<cd,pitype>();
00371     }
00372 
00374     template <int cd>
00375     typename Traits::template Codim<cd>::IteratorType end() const {
00376       return this->grid().template leafend<cd,pitype>();
00377     }
00378 
00380     IntersectionIteratorType ibegin(const EntityCodim0Type & en) const 
00381     {
00382       return en.ileafbegin();
00383     }
00384     
00386     IntersectionIteratorType iend(const EntityCodim0Type & en) const 
00387     {
00388       return en.ileafend();
00389     }
00390 
00392     int level() const { return this->grid().maxLevel(); }
00393 
00395     template <class DataHandleImp,class DataType>
00396     void communicate(CommDataHandleIF<DataHandleImp,DataType> & data, 
00397                      InterfaceType iftype, CommunicationDirection dir) const 
00398     {
00399       this->grid().communicate(data,iftype,dir);
00400     }
00401 
00402   private: 
00404     IndexSetType isetWrapper_;
00405   };
00406 
00408   template <class GridImp,PartitionIteratorType pitype>
00409   struct LeafGridPartTraits {
00410 
00412     typedef GridImp GridType;
00413 
00415     typedef LeafGridPart<GridImp,pitype> GridPartType;
00416 
00418     typedef WrappedLeafIndexSet<GridType> IndexSetType;
00419 
00421     typedef typename GridType::template Codim<0>::Entity::
00422       LeafIntersectionIterator IntersectionIteratorType;
00423 
00425     template <int cd>
00426     struct Codim {
00428       typedef typename GridImp::template Codim<cd>::template Partition<pitype>::LeafIterator IteratorType;
00429     };
00430 
00432     enum { conforming = Capabilities::isLeafwiseConforming<GridType>::v };
00433   };
00434 
00435 
00436   //**************************************************************
00438   template <class GridImp, PartitionIteratorType pitype = Interior_Partition>
00439   class HierarchicGridPart :
00440     public GridPartDefault< HierarchicGridPartTraits<GridImp,pitype> > {
00441   public:
00442     //- Public typedefs and enums
00444     typedef HierarchicGridPartTraits<GridImp,pitype> Traits;
00446     typedef typename Traits::GridType GridType;
00448     typedef typename Traits::IndexSetType IndexSetType;
00449     
00451     typedef typename Traits::IntersectionIteratorType IntersectionIteratorType ;
00452     
00454     template <int cd>
00455     struct Codim {
00456       typedef typename Traits::template Codim<cd>::IteratorType IteratorType;
00457     };
00458 
00460     enum { conforming = Traits :: conforming };
00461   private:
00462     typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
00463 
00464   public:
00465     //- Public methods
00467     HierarchicGridPart(GridType& grid) :
00468       GridPartDefault<Traits>(grid, isetWrapper_),
00469       isetWrapper_(grid) {}
00470 
00472     HierarchicGridPart(GridType& grid, const IndexSetType & ) :
00473       GridPartDefault<Traits>(grid, isetWrapper_),
00474       isetWrapper_(grid) {}
00475 
00477     template <int cd>
00478     typename Traits::template Codim<cd>::IteratorType begin() const {
00479       return this->grid().template leafbegin<cd,pitype>();
00480     }
00481 
00483     template <int cd>
00484     typename Traits::template Codim<cd>::IteratorType end() const {
00485       return this->grid().template leafend<cd,pitype>();
00486     }
00487 
00489     IntersectionIteratorType ibegin(const EntityCodim0Type & en) const 
00490     {
00491       return en.ileafbegin();
00492     }
00493     
00495     IntersectionIteratorType iend(const EntityCodim0Type & en) const 
00496     {
00497       return en.ileafend();
00498     }
00499 
00501     int level() const { return this->grid().maxLevel(); }
00502 
00504     template <class DataHandleImp,class DataType>
00505     void communicate(CommDataHandleIF<DataHandleImp,DataType> & data, 
00506                      InterfaceType iftype, CommunicationDirection dir) const 
00507     {
00508       this->grid().communicate(data,iftype,dir);
00509     }
00510 
00511   private: 
00513     IndexSetType isetWrapper_;
00514   };
00515 
00517   template <class GridImp,PartitionIteratorType pitype>
00518   struct HierarchicGridPartTraits {
00519     typedef GridImp GridType;
00520     typedef HierarchicGridPart<GridImp,pitype> GridPartType;
00521     typedef WrappedHierarchicIndexSet<GridType> IndexSetType;
00522     typedef typename GridType::template Codim<0>::Entity::
00523       LeafIntersectionIterator IntersectionIteratorType;
00524 
00525     template <int cd>
00526     struct Codim {
00527       typedef typename GridImp::template Codim<cd>::template Partition<pitype>::LeafIterator IteratorType;
00528     };
00529 
00531     enum { conforming = Capabilities::isLeafwiseConforming<GridType>::v };
00532   };
00533 
00534 #undef CHECK_INTERFACE_IMPLEMENTATION
00535 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
00536 
00538 } // end namespace Dune
00539 
00540 #endif

Generated on 12 Dec 2007 with Doxygen (ver 1.5.1)