dune-grid  2.2beta1
defaultgridview.hh
Go to the documentation of this file.
00001 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002 // vi: set et ts=8 sw=2 sts=2:
00003 #ifndef DUNE_DEFAULTGRIDVIEW_HH
00004 #define DUNE_DEFAULTGRIDVIEW_HH
00005 
00006 #include <dune/common/typetraits.hh>
00007 #include <dune/common/exceptions.hh>
00008 
00009 #include <dune/grid/common/capabilities.hh>
00010 #include <dune/grid/common/gridview.hh>
00011 
00012 namespace Dune
00013 {
00014 
00015   template< class GridImp, PartitionIteratorType pitype >
00016   class DefaultLevelGridView;
00017 
00018   template< class GridImp, PartitionIteratorType pitype >
00019   class DefaultLeafGridView;
00020 
00021 
00022   template< class GridImp, PartitionIteratorType pitype >
00023   struct DefaultLevelGridViewTraits
00024   {
00025     typedef DefaultLevelGridView< GridImp, pitype > GridViewImp;
00026 
00028     typedef typename remove_const<GridImp>::type Grid;
00029 
00031     typedef typename Grid :: Traits :: LevelIndexSet IndexSet;
00032 
00034     typedef typename Grid :: Traits :: LevelIntersection Intersection;
00035 
00037     typedef typename Grid :: Traits :: LevelIntersectionIterator
00038       IntersectionIterator;
00039 
00041     typedef typename Grid :: Traits :: CollectiveCommunication CollectiveCommunication;
00042 
00043     template< int cd >
00044     struct Codim
00045     {
00046       typedef typename Grid :: Traits
00047         :: template Codim< cd > :: template Partition< pitype > :: LevelIterator
00048         Iterator;
00049 
00050       typedef typename Grid :: Traits :: template Codim< cd > :: Entity Entity;
00051       typedef typename Grid :: Traits :: template Codim< cd > :: EntityPointer
00052         EntityPointer;
00053 
00054       typedef typename Grid :: template Codim< cd > :: Geometry Geometry;
00055       typedef typename Grid :: template Codim< cd > :: LocalGeometry
00056         LocalGeometry;
00057 
00059       template< PartitionIteratorType pit >
00060       struct Partition
00061       {
00063         typedef typename Grid :: template Codim< cd >
00064           :: template Partition< pit > :: LevelIterator
00065           Iterator;
00066       };
00067     };
00068 
00069     enum { conforming = Capabilities :: isLevelwiseConforming< Grid > :: v };
00070   };
00071 
00072 
00073   template< class GridImp, PartitionIteratorType pitype >
00074   class DefaultLevelGridView 
00075   {
00076     typedef DefaultLevelGridView< GridImp, pitype > ThisType;
00077 
00078   public:
00079     typedef DefaultLevelGridViewTraits<GridImp,pitype> Traits;
00080 
00082     typedef typename Traits::Grid Grid;
00083 
00085     typedef typename Traits :: IndexSet IndexSet;
00086 
00088     typedef typename Traits :: Intersection Intersection;
00089 
00091     typedef typename Traits :: IntersectionIterator IntersectionIterator;
00092 
00094     typedef typename Traits :: CollectiveCommunication CollectiveCommunication;
00095 
00097     template< int cd >
00098     struct Codim : public Traits :: template Codim<cd> {};
00099  
00100     enum { conforming = Traits :: conforming };
00101 
00102     DefaultLevelGridView ( const Grid &grid, int level )
00103     : grid_( &grid ),
00104       level_( level )
00105     {}
00106 
00107 // use default implementation of copy constructor and assignment operator
00108 #if 0
00109     DefaultLevelGridView ( const ThisType &other ) 
00110     : grid_( other.grid_ ),
00111       level_( other.level_ )
00112     {}
00113 
00115     ThisType &operator= ( const ThisType & other)
00116     {
00117       grid_ = other.grid_;
00118       level_ = other.level_;
00119     }
00120 #endif
00121 
00123     const Grid &grid () const
00124     {
00125       assert( grid_ );
00126       return *grid_;
00127     }
00128 
00130     const IndexSet &indexSet () const
00131     {
00132       return grid().levelIndexSet( level_ );
00133     }
00134     
00136     int size ( int codim ) const
00137     {
00138       return grid().size( level_, codim );
00139     }
00140 
00142     int size ( const GeometryType &type ) const
00143     {
00144       return grid().size( level_, type );
00145     }
00146 
00148     template< int cd >
00149     typename Codim< cd > :: Iterator begin () const
00150     {
00151       return grid().template lbegin< cd, pitype >( level_ );
00152     }
00153 
00155     template< int cd, PartitionIteratorType pit >
00156     typename Codim< cd > :: template Partition< pit > :: Iterator begin () const
00157     {
00158       return grid().template lbegin< cd, pit >( level_ );
00159     }
00160 
00162     template< int cd >
00163     typename Codim< cd > :: Iterator end () const
00164     {
00165       return grid().template lend< cd, pitype >( level_ );
00166     }
00167 
00169     template< int cd, PartitionIteratorType pit >
00170     typename Codim< cd > :: template Partition< pit > :: Iterator end () const
00171     {
00172       return grid().template lend< cd, pit >( level_ );
00173     }
00174 
00176     IntersectionIterator
00177     ibegin ( const typename Codim< 0 > :: Entity &entity ) const
00178     {
00179       return entity.ilevelbegin();
00180     }
00181 
00183     IntersectionIterator
00184     iend ( const typename Codim< 0 > :: Entity &entity ) const
00185     {
00186       return entity.ilevelend();
00187     }
00188 
00190     const CollectiveCommunication &comm () const
00191     {
00192       return grid().comm();
00193     }
00194 
00196     int overlapSize(int codim) const
00197     {
00198       return grid().overlapSize(level_, codim);
00199     }
00200 
00202     int ghostSize(int codim) const 
00203     {
00204       return grid().ghostSize(level_, codim);
00205     }
00206 
00208     template< class DataHandleImp, class DataType >
00209     void communicate ( CommDataHandleIF< DataHandleImp, DataType > &data,
00210                        InterfaceType iftype,
00211                        CommunicationDirection dir ) const
00212     {
00213       return grid().communicate( data, iftype, dir, level_ );
00214     }
00215 
00216   private:
00217     const Grid *grid_;
00218     int level_;
00219   };
00220   
00221 
00222   template< class GridImp, PartitionIteratorType pitype >
00223   struct DefaultLeafGridViewTraits {
00224     typedef DefaultLeafGridView< GridImp, pitype > GridViewImp;
00225 
00227     typedef typename remove_const<GridImp>::type Grid;
00228 
00230     typedef typename Grid :: Traits :: LeafIndexSet IndexSet;
00231 
00233     typedef typename Grid :: Traits :: LeafIntersection Intersection;
00234 
00236     typedef typename Grid :: Traits :: LeafIntersectionIterator
00237       IntersectionIterator;
00238 
00240     typedef typename Grid :: Traits :: CollectiveCommunication CollectiveCommunication;
00241     
00242     template< int cd >
00243     struct Codim
00244     {
00245       typedef typename Grid :: Traits
00246         :: template Codim< cd > :: template Partition< pitype > :: LeafIterator
00247         Iterator;
00248 
00249       typedef typename Grid :: Traits :: template Codim< cd > :: Entity Entity;
00250       typedef typename Grid :: Traits :: template Codim< cd > :: EntityPointer
00251         EntityPointer;
00252 
00253       typedef typename Grid :: template Codim< cd > :: Geometry Geometry;
00254       typedef typename Grid :: template Codim< cd > :: LocalGeometry
00255         LocalGeometry;
00256       
00258       template <PartitionIteratorType pit >
00259       struct Partition
00260       {
00262         typedef typename Grid :: template Codim< cd >
00263           :: template Partition< pit > :: LeafIterator
00264           Iterator;
00265       };
00266     };
00267 
00268     enum { conforming = Capabilities :: isLeafwiseConforming< Grid > :: v };
00269   };
00270 
00271 
00272   template< class GridImp, PartitionIteratorType pitype >
00273   class DefaultLeafGridView 
00274   {
00275     typedef DefaultLeafGridView< GridImp, pitype > ThisType;
00276 
00277   public:
00278     typedef DefaultLeafGridViewTraits<GridImp,pitype> Traits;
00279 
00281     typedef typename Traits::Grid Grid;
00282 
00284     typedef typename Traits :: IndexSet IndexSet;
00285 
00287     typedef typename Traits :: Intersection Intersection;
00288 
00290     typedef typename Traits :: IntersectionIterator IntersectionIterator;
00291 
00293     typedef typename Traits :: CollectiveCommunication CollectiveCommunication;
00294     
00296     template< int cd >
00297     struct Codim : public Traits :: template Codim<cd> {};
00298  
00299     enum { conforming = Traits :: conforming };
00300 
00301   public:
00302     DefaultLeafGridView ( const Grid &grid )
00303     : grid_( &grid )
00304     {}
00305 
00306 // use default implementation of copy constructor and assignment operator
00307 #if 0
00308     DefaultLeafGridView ( const ThisType &other ) 
00309     : grid_( other.grid_ )
00310     {}
00311 
00313     ThisType &operator= ( const ThisType & other)
00314     {
00315       grid_ = other.grid_;
00316     }
00317 #endif
00318 
00320     const Grid &grid () const
00321     {
00322       assert( grid_ );
00323       return *grid_;
00324     }
00325 
00327     const IndexSet &indexSet () const
00328     {
00329       return grid().leafIndexSet();
00330     }
00331 
00333     int size ( int codim ) const
00334     {
00335       return grid().size( codim );
00336     }
00337 
00339     int size ( const GeometryType &type ) const
00340     {
00341       return grid().size( type );
00342     }
00343 
00345     template< int cd >
00346     typename Codim< cd > :: Iterator begin () const
00347     {
00348       return grid().template leafbegin< cd, pitype >();
00349     }
00350 
00352     template< int cd, PartitionIteratorType pit >
00353     typename Codim< cd > :: template Partition< pit > :: Iterator begin () const
00354     {
00355       return grid().template leafbegin< cd, pit >();
00356     }
00357 
00359     template< int cd >
00360     typename Codim< cd > :: Iterator end () const
00361     {
00362       return grid().template leafend< cd, pitype >();
00363     }
00364 
00366     template< int cd, PartitionIteratorType pit >
00367     typename Codim< cd > :: template Partition< pit > :: Iterator end () const
00368     {
00369       return grid().template leafend< cd, pit >();
00370     }
00371 
00373     IntersectionIterator
00374     ibegin ( const typename Codim< 0 > :: Entity &entity ) const
00375     {
00376       return entity.ileafbegin();
00377     }
00378 
00380     IntersectionIterator
00381     iend ( const typename Codim< 0 > :: Entity &entity ) const
00382     {
00383       return entity.ileafend();
00384     }
00385 
00387     const CollectiveCommunication &comm () const
00388     {
00389       return grid().comm();
00390     }
00391 
00393     int overlapSize(int codim) const
00394     {
00395       return grid().overlapSize(codim);
00396     }
00397 
00399     int ghostSize(int codim) const 
00400     {
00401       return grid().ghostSize(codim);
00402     }
00403 
00405     template< class DataHandleImp, class DataType >
00406     void communicate ( CommDataHandleIF< DataHandleImp, DataType > &data,
00407                        InterfaceType iftype,
00408                        CommunicationDirection dir ) const
00409     {
00410       return grid().communicate( data, iftype, dir );
00411     }
00412 
00413   private:
00414     const Grid *grid_;
00415   };
00416 
00417 }
00418 
00419 #endif