defaultgridview.hh

00001 #ifndef DUNE_DEFAULTGRIDVIEW_HH
00002 #define DUNE_DEFAULTGRIDVIEW_HH
00003 
00004 #include <dune/common/typetraits.hh>
00005 
00006 #include <dune/grid/common/capabilities.hh>
00007 #include <dune/grid/common/gridview.hh>
00008 
00009 namespace Dune
00010 {
00011 
00012   template< class GridImp, PartitionIteratorType pitype >
00013   class DefaultLevelGridView;
00014 
00015   template< class GridImp, PartitionIteratorType pitype >
00016   class DefaultLeafGridView;
00017 
00018 
00019   template< class GridImp, PartitionIteratorType pitype >
00020   struct DefaultLevelGridViewTraits
00021   {
00022     typedef DefaultLevelGridView< GridImp, pitype > GridViewImp;
00023 
00025     typedef typename remove_const<GridImp>::type Grid;
00026 
00028     typedef typename Grid :: Traits :: LevelIndexSet IndexSet;
00029 
00031     typedef typename Grid :: Traits :: LevelIntersection Intersection;
00032 
00034     typedef typename Grid :: Traits :: LevelIntersectionIterator
00035       IntersectionIterator;
00036 
00038     typedef typename Grid :: Traits :: CollectiveCommunication CollectiveCommunication;
00039 
00040     template< int cd >
00041     struct Codim
00042     {
00043       typedef typename Grid :: Traits
00044         :: template Codim< cd > :: template Partition< pitype > :: LevelIterator
00045         Iterator;
00046 
00047       typedef typename Grid :: Traits :: template Codim< cd > :: Entity Entity;
00048       typedef typename Grid :: Traits :: template Codim< cd > :: EntityPointer
00049         EntityPointer;
00050 
00051       typedef typename Grid :: template Codim< cd > :: Geometry Geometry;
00052       typedef typename Grid :: template Codim< cd > :: LocalGeometry
00053         LocalGeometry;
00054 
00056       template< PartitionIteratorType pit >
00057       struct Partition
00058       {
00060         typedef typename Grid :: template Codim< cd >
00061           :: template Partition< pit > :: LevelIterator
00062           Iterator;
00063       };
00064     };
00065 
00066     enum { conforming = Capabilities :: isLevelwiseConforming< Grid > :: v };
00067   };
00068 
00069 
00070   template< class GridImp, PartitionIteratorType pitype >
00071   class DefaultLevelGridView 
00072   {
00073     typedef DefaultLevelGridView< GridImp, pitype > ThisType;
00074 
00075   public:
00076     typedef DefaultLevelGridViewTraits<GridImp,pitype> Traits;
00077 
00079     typedef typename Traits::Grid Grid;
00080 
00082     typedef typename Traits :: IndexSet IndexSet;
00083 
00085     typedef typename Traits :: Intersection Intersection;
00086 
00088     typedef typename Traits :: IntersectionIterator IntersectionIterator;
00089 
00091     typedef typename Traits :: CollectiveCommunication CollectiveCommunication;
00092 
00094     template< int cd >
00095     struct Codim : public Traits :: template Codim<cd> {};
00096  
00097     enum { conforming = Traits :: conforming };
00098 
00099   private:
00100     const Grid &grid_;
00101     const IndexSet &indexSet_;
00102     const int level_;
00103 
00104   public:
00105     DefaultLevelGridView ( const Grid &grid, int level )
00106     : grid_( grid ),
00107       indexSet_( grid.levelIndexSet( level ) ),
00108       level_( level )
00109     {}
00110 
00111     DefaultLevelGridView ( const ThisType &other ) 
00112     : grid_( other.grid_ ),
00113       indexSet_( other.indexSet_ ),
00114       level_( other.level_ )
00115     {}
00116 
00117   private:
00118     // prohibit assignment
00119     ThisType &operator= ( const ThisType & );
00120 
00121   public:
00123     const Grid &grid () const
00124     {
00125       return grid_;
00126     }
00127 
00129     const IndexSet &indexSet () const
00130     {
00131       return indexSet_;
00132     }
00133     
00135     int size ( int codim ) const
00136     {
00137       return grid().size( level_, codim );
00138     }
00139 
00141     int size ( const GeometryType &type ) const
00142     {
00143       return grid().size( level_, type );
00144     }
00145 
00147     template< int cd >
00148     typename Codim< cd > :: Iterator begin () const
00149     {
00150       return grid().template lbegin< cd, pitype >( level_ );
00151     }
00152 
00154     template< int cd, PartitionIteratorType pit >
00155     typename Codim< cd > :: template Partition< pit > :: Iterator begin () const
00156     {
00157       return grid().template lbegin< cd, pit >( level_ );
00158     }
00159 
00161     template< int cd >
00162     typename Codim< cd > :: Iterator end () const
00163     {
00164       return grid().template lend< cd, pitype >( level_ );
00165     }
00166 
00168     template< int cd, PartitionIteratorType pit >
00169     typename Codim< cd > :: template Partition< pit > :: Iterator end () const
00170     {
00171       return grid().template lend< cd, pit >( level_ );
00172     }
00173 
00175     IntersectionIterator
00176     ibegin ( const typename Codim< 0 > :: Entity &entity ) const
00177     {
00178       return entity.ilevelbegin();
00179     }
00180 
00182     IntersectionIterator
00183     iend ( const typename Codim< 0 > :: Entity &entity ) const
00184     {
00185       return entity.ilevelend();
00186     }
00187 
00189     const CollectiveCommunication &comm () const
00190     {
00191       return grid().comm();
00192     }
00193 
00195     template< class DataHandleImp, class DataType >
00196     void communicate ( CommDataHandleIF< DataHandleImp, DataType > &data,
00197                        InterfaceType iftype,
00198                        CommunicationDirection dir ) const
00199     {
00200       return grid().communicate( data, iftype, dir, level_ );
00201     }
00202   };
00203   
00204 
00205   template< class GridImp, PartitionIteratorType pitype >
00206   struct DefaultLeafGridViewTraits {
00207     typedef DefaultLeafGridView< GridImp, pitype > GridViewImp;
00208 
00210     typedef typename remove_const<GridImp>::type Grid;
00211 
00213     typedef typename Grid :: Traits :: LeafIndexSet IndexSet;
00214 
00216     typedef typename Grid :: Traits :: LeafIntersection Intersection;
00217 
00219     typedef typename Grid :: Traits :: LeafIntersectionIterator
00220       IntersectionIterator;
00221 
00223     typedef typename Grid :: Traits :: CollectiveCommunication CollectiveCommunication;
00224     
00225     template< int cd >
00226     struct Codim
00227     {
00228       typedef typename Grid :: Traits
00229         :: template Codim< cd > :: template Partition< pitype > :: LeafIterator
00230         Iterator;
00231 
00232       typedef typename Grid :: Traits :: template Codim< cd > :: Entity Entity;
00233       typedef typename Grid :: Traits :: template Codim< cd > :: EntityPointer
00234         EntityPointer;
00235 
00236       typedef typename Grid :: template Codim< cd > :: Geometry Geometry;
00237       typedef typename Grid :: template Codim< cd > :: LocalGeometry
00238         LocalGeometry;
00239       
00241       template <PartitionIteratorType pit >
00242       struct Partition
00243       {
00245         typedef typename Grid :: template Codim< cd >
00246           :: template Partition< pit > :: LeafIterator
00247           Iterator;
00248       };
00249     };
00250 
00251     enum { conforming = Capabilities :: isLeafwiseConforming< Grid > :: v };
00252   };
00253 
00254 
00255   template< class GridImp, PartitionIteratorType pitype >
00256   class DefaultLeafGridView 
00257   {
00258     typedef DefaultLeafGridView< GridImp, pitype > ThisType;
00259 
00260   public:
00261     typedef DefaultLeafGridViewTraits<GridImp,pitype> Traits;
00262 
00264     typedef typename Traits::Grid Grid;
00265 
00267     typedef typename Traits :: IndexSet IndexSet;
00268 
00270     typedef typename Traits :: Intersection Intersection;
00271 
00273     typedef typename Traits :: IntersectionIterator IntersectionIterator;
00274 
00276     typedef typename Traits :: CollectiveCommunication CollectiveCommunication;
00277     
00279     template< int cd >
00280     struct Codim : public Traits :: template Codim<cd> {};
00281  
00282     enum { conforming = Traits :: conforming };
00283 
00284   private:
00285     const Grid &grid_;
00286     const IndexSet &indexSet_;
00287 
00288   public:
00289     DefaultLeafGridView ( const Grid &grid )
00290     : grid_( grid ),
00291       indexSet_( grid.leafIndexSet() )
00292     {}
00293 
00294     DefaultLeafGridView ( const ThisType &other ) 
00295     : grid_( other.grid_ ),
00296       indexSet_( other.indexSet_ )
00297     {}
00298 
00299   private:
00300     // prohibit assignment
00301     ThisType &operator= ( const ThisType & );
00302 
00303   public:
00305     const Grid &grid () const
00306     {
00307       return grid_;
00308     }
00309 
00311     const IndexSet &indexSet () const
00312     {
00313       return indexSet_;
00314     }
00315 
00317     int size ( int codim ) const
00318     {
00319       return grid().size( codim );
00320     }
00321 
00323     int size ( const GeometryType &type ) const
00324     {
00325       return grid().size( type );
00326     }
00327 
00329     template< int cd >
00330     typename Codim< cd > :: Iterator begin () const
00331     {
00332       return grid().template leafbegin< cd, pitype >();
00333     }
00334 
00336     template< int cd, PartitionIteratorType pit >
00337     typename Codim< cd > :: template Partition< pit > :: Iterator begin () const
00338     {
00339       return grid().template leafbegin< cd, pit >();
00340     }
00341 
00343     template< int cd >
00344     typename Codim< cd > :: Iterator end () const
00345     {
00346       return grid().template leafend< cd, pitype >();
00347     }
00348 
00350     template< int cd, PartitionIteratorType pit >
00351     typename Codim< cd > :: template Partition< pit > :: Iterator end () const
00352     {
00353       return grid().template leafend< cd, pit >();
00354     }
00355 
00357     IntersectionIterator
00358     ibegin ( const typename Codim< 0 > :: Entity &entity ) const
00359     {
00360       return entity.ileafbegin();
00361     }
00362 
00364     IntersectionIterator
00365     iend ( const typename Codim< 0 > :: Entity &entity ) const
00366     {
00367       return entity.ileafend();
00368     }
00369 
00371     const CollectiveCommunication &comm () const
00372     {
00373       return grid().comm();
00374     }
00375 
00377     template< class DataHandleImp, class DataType >
00378     void communicate ( CommDataHandleIF< DataHandleImp, DataType > &data,
00379                        InterfaceType iftype,
00380                        CommunicationDirection dir ) const
00381     {
00382       return grid().communicate( data, iftype, dir );
00383     }
00384   };
00385 
00386 }
00387 
00388 #endif

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