gridpart.hh

00001 #ifndef DUNE_GRIDPART_HH
00002 #define DUNE_GRIDPART_HH
00003 
00004 #warning "GridParts are deprecated. Use GridViews instead."
00005 #warning "For more information see dune/grid/common/gridview.hh."
00006 
00007 //- System includes
00008 
00009 //- Dune includes
00010 #include <dune/grid/common/grid.hh>
00011 #include <dune/grid/common/defaultindexsets.hh>
00012 #include <dune/grid/common/datahandleif.hh>
00013 
00014 #include <dune/common/bartonnackmanifcheck.hh>
00015 #include <dune/common/deprecated.hh>
00016 
00017 /*  @file
00018   @author Robert Kloefkorn
00019   @brief Provides views of grid via grid parts, heavily used in the
00020   dune-fem module.  
00021 */
00022 /*  @addtogroup GridPart
00023     @ingroup Grid
00024   
00025   @section GridPart1 What is a GridPart ?
00026   <!--============================-->
00027   A Dune::GridPart define a view for a given grid, which can basically be seen
00028   as a container for entities of different co-dimensions. The most
00029   prominent example of such views are Leafgrids and Levelgrids - but
00030   also a set of entities satisfying a certain constraint, e.g., belonging
00031   to a certain domain, can be accessed using the GridParts interface. 
00032  
00033   The Dune::Grid instance is passed to the GridPart which then
00034   provides iterators over the entities in the view; also intersection iterators
00035   suitable for element in the view can be obtained from the GridPart. 
00036   Finally the GridPart provides a Dune::IndexSet with indices for all 
00037   entities in the view. For parallel computations the GridPart interface
00038   also provides the suitable communication method.   
00039 
00040   @section GridPart3 GridPart Interface and available Implementations
00041   <!--==========================-->
00042 
00043   This interface is implemented by the class template Dune::GridPartInterface. 
00044   For a full documentation see the description of this class.
00045   A short list of the most important methods is:
00046   - The pair of methods begin()/end() provide begin and end iterators
00047     for the entities.
00048   - The methods ibegin(entity)/iend(entity) 
00049     begin and end intersection iterators for a given entity. 
00050   - The index set is accessed via the method indexSet() and the underlying
00051     grid using the method grid().
00052   .
00053 
00054   For a level or leaf view of the grid use the implementations
00055   Dune::LevelGridPart and Dune::LeafGridPart, respectively. A first
00056   implementation of a view using a general filter is available 
00057   in the dune-fem package (Dune::FilteredGridPart).
00058 */
00059 
00060 namespace Dune {
00061   /* 
00062    * @addtogroup GridPart
00063    *
00064    * @{ 
00065    */
00066 
00067   // Forward declarations
00068   template <class GridImp, PartitionIteratorType pitype>
00069   class LevelGridPartTraits;
00070   template <class GridImp, PartitionIteratorType pitype>
00071   class LeafGridPartTraits;
00072   template <class GridImp, PartitionIteratorType pitype>
00073   class HierarchicGridPartTraits;
00074 
00075   //  \brief Interface for the GridPart classes
00076   //  A GridPart class allows to access only a specific subset of a grid's
00077   //  entities. A GridPart implementation provides the corresponding index set
00078   //  and a begin/end iterator pair for accessing those entities, the
00079   //  corresponding intersection iterators and a appropriate communication
00080   //  method. 
00081   //  GridParts are used to parametrize spaces (see DiscreteFunctionSpaceDefault [in dune-fem]).
00082   template <class GridPartTraits>
00083   class GridPartInterface {
00084   public:
00086     typedef GridPartTraits Traits;
00087 
00089     typedef typename GridPartTraits::GridPartType GridPartType;
00090 
00091    
00093     typedef typename GridPartTraits::GridType GridType;
00094     
00096     typedef typename GridPartTraits::IndexSetType IndexSetType;
00097 
00099     typedef typename GridPartTraits::IntersectionIteratorType IntersectionIteratorType; 
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 
00194   //  \brief Default implementation for the GridPart classes
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 
00228   //  \brief Selects a specific level of a grid
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::IntersectionType IntersectionType ;
00243     
00245     typedef typename Traits::IntersectionIteratorType IntersectionIteratorType ;
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     LevelGridPart(const LevelGridPart& other) :
00276       GridPartDefault<Traits>(other.grid_,isetWrapper_),
00277       isetWrapper_(other.grid_,other.level_),
00278       level_(other.level_) {}
00279     
00281     template <int cd>
00282     typename Traits::template Codim<cd>::IteratorType begin() const {
00283       return this->grid().template lbegin<cd,pitype>(level_);
00284     }
00285 
00287     template <int cd>
00288     typename Traits::template Codim<cd>::IteratorType end() const {
00289       return this->grid().template lend<cd,pitype>(level_);
00290     }
00291     
00293     IntersectionIteratorType ibegin(const EntityCodim0Type & en) const 
00294     {
00295       return en.ilevelbegin();
00296     }
00297     
00299     IntersectionIteratorType iend(const EntityCodim0Type & en) const 
00300     {
00301       return en.ilevelend();
00302     }
00303 
00305     int level() const { return level_; }
00306 
00308     template <class DataHandleImp,class DataType>
00309     void communicate(CommDataHandleIF<DataHandleImp,DataType> & data, 
00310                      InterfaceType iftype, CommunicationDirection dir) const 
00311     {
00312       this->grid().communicate(data,iftype,dir,level());
00313     }
00314 
00315   private:
00317     IndexSetType isetWrapper_;
00318     const int level_;
00319   };
00320 
00321   //  Type definitions for the LevelGridPart class
00322   template <class GridImp, PartitionIteratorType pitype>
00323   struct LevelGridPartTraits {
00324 
00326     typedef GridImp GridType;
00327 
00329     typedef LevelGridPart<GridImp,pitype> GridPartType;
00330 
00332     typedef WrappedLevelIndexSet<GridType> IndexSetType;
00333 
00335     typedef typename GridType::Traits::
00336       LevelIntersection IntersectionType;
00337 
00339     typedef typename GridType::template Codim<0>::Entity::
00340       LevelIntersectionIterator IntersectionIteratorType;
00341 
00343     template <int cd>
00344     struct Codim {
00346       typedef typename GridImp::template Codim<cd>::template Partition<pitype>::LevelIterator IteratorType;
00347     };
00348 
00350     enum { conforming = Capabilities::isLevelwiseConforming<GridType>::v };
00351   };
00352 
00353   //  \brief Selects the leaf level of a grid
00354   template <class GridImp, PartitionIteratorType pitype = Interior_Partition>
00355   class LeafGridPart :
00356     public GridPartDefault<LeafGridPartTraits<GridImp,pitype> > {
00357   public:
00358     //- Public typedefs and enums
00360     typedef LeafGridPartTraits<GridImp,pitype> Traits;
00362     typedef typename Traits::GridType GridType;
00364     typedef typename Traits::IndexSetType IndexSetType;
00365     
00367     typedef typename Traits::IntersectionType IntersectionType ;
00368     
00370     typedef typename Traits::IntersectionIteratorType IntersectionIteratorType ;
00371     
00373     template <int cd>
00374     struct Codim {
00376       typedef typename Traits::template Codim<cd>::IteratorType IteratorType;
00377     };
00378     
00380     enum { conforming = Traits :: conforming };
00381   private:
00382     typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
00383 
00384   public:
00385     //- Public methods
00387     LeafGridPart(GridType& grid) :
00388       GridPartDefault<Traits>(grid, isetWrapper_),
00389       isetWrapper_(grid) {}
00390 
00392     LeafGridPart(const LeafGridPart& other) :
00393       GridPartDefault<Traits>(other.grid_,isetWrapper_),
00394       isetWrapper_(other.grid_) 
00395     {}
00396     
00398     template <int cd>
00399     typename Traits::template Codim<cd>::IteratorType begin() const {
00400       return this->grid().template leafbegin<cd,pitype>();
00401     }
00402 
00404     template <int cd>
00405     typename Traits::template Codim<cd>::IteratorType end() const {
00406       return this->grid().template leafend<cd,pitype>();
00407     }
00408 
00410     IntersectionIteratorType ibegin(const EntityCodim0Type & en) const 
00411     {
00412       return en.ileafbegin();
00413     }
00414     
00416     IntersectionIteratorType iend(const EntityCodim0Type & en) const 
00417     {
00418       return en.ileafend();
00419     }
00420 
00422     int level() const { return this->grid().maxLevel(); }
00423 
00425     template <class DataHandleImp,class DataType>
00426     void communicate(CommDataHandleIF<DataHandleImp,DataType> & data, 
00427                      InterfaceType iftype, CommunicationDirection dir) const 
00428     {
00429       this->grid().communicate(data,iftype,dir);
00430     }
00431 
00432   private: 
00434     IndexSetType isetWrapper_;
00435   };
00436 
00437   //  Type definitions for the LeafGridPart class
00438   template <class GridImp,PartitionIteratorType pitype>
00439   struct LeafGridPartTraits {
00440 
00442     typedef GridImp GridType;
00443 
00445     typedef LeafGridPart<GridImp,pitype> GridPartType;
00446 
00448     typedef WrappedLeafIndexSet<GridType> IndexSetType;
00449 
00451     typedef typename GridType::Traits::
00452       LeafIntersection IntersectionType;
00453 
00455     typedef typename GridType::template Codim<0>::Entity::
00456       LeafIntersectionIterator IntersectionIteratorType;
00457 
00459     template <int cd>
00460     struct Codim {
00462       typedef typename GridImp::template Codim<cd>::template Partition<pitype>::LeafIterator IteratorType;
00463     };
00464 
00466     enum { conforming = Capabilities::isLeafwiseConforming<GridType>::v };
00467   };
00468 
00469 
00470   //**************************************************************
00471   /*  \brief Selects the leaf level of a grid together with the 
00472       HierarchicIndexSet available for ALUGrid and AlbertaGrid. 
00473       The HierarchicIndexSet is basically the LocalIdSet of the grid 
00474       extended by a size method to implement the IndexSet interface. 
00475       For all other grids the default LeafIndexSet is selected.
00476 
00477       \deprecated
00478   */
00479   template <class GridImp, PartitionIteratorType pitype = Interior_Partition>
00480   class HierarchicGridPart :
00481     public GridPartDefault< HierarchicGridPartTraits<GridImp,pitype> > {
00482   public:
00483     //- Public typedefs and enums
00485     typedef HierarchicGridPartTraits<GridImp,pitype> Traits;
00487     typedef typename Traits::GridType GridType;
00489     typedef typename Traits::IndexSetType IndexSetType;
00490     
00492     typedef typename Traits::IntersectionIteratorType IntersectionIteratorType ;
00493     
00495     template <int cd>
00496     struct Codim {
00497       typedef typename Traits::template Codim<cd>::IteratorType IteratorType;
00498     };
00499 
00501     enum { conforming = Traits :: conforming };
00502   private:
00503     typedef typename GridType::template Codim<0>::Entity EntityCodim0Type;
00504 
00505   public:
00506     //- Public methods
00508     HierarchicGridPart(GridType& grid) :
00509       GridPartDefault<Traits>(grid, isetWrapper_),
00510       isetWrapper_(grid) {}
00511 
00513     HierarchicGridPart(GridType& grid, const IndexSetType & ) :
00514       GridPartDefault<Traits>(grid, isetWrapper_),
00515       isetWrapper_(grid) {}
00516 
00518     HierarchicGridPart(const HierarchicGridPart& other) :
00519       GridPartDefault<Traits>(other.grid_, isetWrapper_),
00520       isetWrapper_(other.grid_) {}
00521 
00523     template <int cd>
00524     typename Traits::template Codim<cd>::IteratorType begin() const {
00525       return this->grid().template leafbegin<cd,pitype>();
00526     }
00527 
00529     template <int cd>
00530     typename Traits::template Codim<cd>::IteratorType end() const {
00531       return this->grid().template leafend<cd,pitype>();
00532     }
00533 
00535     IntersectionIteratorType ibegin(const EntityCodim0Type & en) const 
00536     {
00537       return en.ileafbegin();
00538     }
00539     
00541     IntersectionIteratorType iend(const EntityCodim0Type & en) const 
00542     {
00543       return en.ileafend();
00544     }
00545 
00547     int level() const { return this->grid().maxLevel(); }
00548 
00550     template <class DataHandleImp,class DataType>
00551     void communicate(CommDataHandleIF<DataHandleImp,DataType> & data, 
00552                      InterfaceType iftype, CommunicationDirection dir) const 
00553     {
00554       this->grid().communicate(data,iftype,dir);
00555     }
00556 
00557   private: 
00559     IndexSetType isetWrapper_;
00560   };
00561 
00562   //  Type definitions for the HierarchicGridPart class
00563   /*  \deprecated */
00564   template <class GridImp,PartitionIteratorType pitype>
00565   struct HierarchicGridPartTraits {
00567     typedef GridImp GridType;
00569     typedef HierarchicGridPart<GridImp,pitype> GridPartType;
00571     typedef WrappedHierarchicIndexSet<GridType> IndexSetType;
00573     typedef typename GridType::template Codim<0>::Entity::
00574       LeafIntersectionIterator IntersectionIteratorType;
00575 
00577     template <int cd>
00578     struct Codim {
00580       typedef typename GridImp::template Codim<cd>::template Partition<pitype>::LeafIterator IteratorType;
00581     };
00582 
00584     enum { conforming = Capabilities::isLeafwiseConforming<GridType>::v };
00585   };
00586 
00587 #undef CHECK_INTERFACE_IMPLEMENTATION
00588 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
00589   /*  @} */
00590 
00591 } // end namespace Dune
00592 
00593 #endif
00594 
00595 
00596 // Error Message for dune-fem
00597 //
00598 // This message can only be triggered by users of dune-fem and tells them which
00599 // file to include in the future
00600 #ifdef DUNE_FEM_GRIDPART_HH
00601 #error "Including <dune/grid/common/gridpart.hh> is deprecated."
00602 #error "Include <dune/fem/gridpart/gridpart.hh> instead."
00603 #endif

Generated on Sun Nov 15 22:28:41 2009 for dune-grid by  doxygen 1.5.6