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       indexSet_( &(grid.levelIndexSet( level )) ),
00105       level_( level )
00106     {}
00107 
00108 // use default implementation of copy constructor and assignment operator
00109 #if 0
00110     DefaultLevelGridView ( const ThisType &other ) 
00111     : grid_( other.grid_ ),
00112       indexSet_( other.indexSet_ ),
00113       level_( other.level_ )
00114     {}
00115 
00117     ThisType &operator= ( const ThisType & other)
00118     {
00119       grid_ = other.grid_;
00120       indexSet_ = other.indexSet_;
00121       level_ = other.level_;
00122     }
00123 #endif
00124 
00126     const Grid &grid () const
00127     {
00128       return *grid_;
00129     }
00130 
00132     const IndexSet &indexSet () const
00133     {
00134       return *indexSet_;
00135     }
00136     
00138     int size ( int codim ) const
00139     {
00140       return grid().size( level_, codim );
00141     }
00142 
00144     int size ( const GeometryType &type ) const
00145     {
00146       return grid().size( level_, type );
00147     }
00148 
00150     template< int cd >
00151     typename Codim< cd > :: Iterator begin () const
00152     {
00153       return grid().template lbegin< cd, pitype >( level_ );
00154     }
00155 
00157     template< int cd, PartitionIteratorType pit >
00158     typename Codim< cd > :: template Partition< pit > :: Iterator begin () const
00159     {
00160       return grid().template lbegin< cd, pit >( level_ );
00161     }
00162 
00164     template< int cd >
00165     typename Codim< cd > :: Iterator end () const
00166     {
00167       return grid().template lend< cd, pitype >( level_ );
00168     }
00169 
00171     template< int cd, PartitionIteratorType pit >
00172     typename Codim< cd > :: template Partition< pit > :: Iterator end () const
00173     {
00174       return grid().template lend< cd, pit >( level_ );
00175     }
00176 
00178     IntersectionIterator
00179     ibegin ( const typename Codim< 0 > :: Entity &entity ) const
00180     {
00181       return entity.ilevelbegin();
00182     }
00183 
00185     IntersectionIterator
00186     iend ( const typename Codim< 0 > :: Entity &entity ) const
00187     {
00188       return entity.ilevelend();
00189     }
00190 
00192     const CollectiveCommunication &comm () const
00193     {
00194       return grid().comm();
00195     }
00196 
00198     int overlapSize(int codim) const
00199     {
00200       return grid().overlapSize(level_, codim);
00201     }
00202 
00204     int ghostSize(int codim) const 
00205     {
00206       return grid().ghostSize(level_, codim);
00207     }
00208 
00210     template< class DataHandleImp, class DataType >
00211     void communicate ( CommDataHandleIF< DataHandleImp, DataType > &data,
00212                        InterfaceType iftype,
00213                        CommunicationDirection dir ) const
00214     {
00215       return grid().communicate( data, iftype, dir, level_ );
00216     }
00217 
00218   private:
00219     const Grid *grid_;
00220     const IndexSet *indexSet_;
00221     int level_;
00222   };
00223   
00224 
00225   template< class GridImp, PartitionIteratorType pitype >
00226   struct DefaultLeafGridViewTraits {
00227     typedef DefaultLeafGridView< GridImp, pitype > GridViewImp;
00228 
00230     typedef typename remove_const<GridImp>::type Grid;
00231 
00233     typedef typename Grid :: Traits :: LeafIndexSet IndexSet;
00234 
00236     typedef typename Grid :: Traits :: LeafIntersection Intersection;
00237 
00239     typedef typename Grid :: Traits :: LeafIntersectionIterator
00240       IntersectionIterator;
00241 
00243     typedef typename Grid :: Traits :: CollectiveCommunication CollectiveCommunication;
00244     
00245     template< int cd >
00246     struct Codim
00247     {
00248       typedef typename Grid :: Traits
00249         :: template Codim< cd > :: template Partition< pitype > :: LeafIterator
00250         Iterator;
00251 
00252       typedef typename Grid :: Traits :: template Codim< cd > :: Entity Entity;
00253       typedef typename Grid :: Traits :: template Codim< cd > :: EntityPointer
00254         EntityPointer;
00255 
00256       typedef typename Grid :: template Codim< cd > :: Geometry Geometry;
00257       typedef typename Grid :: template Codim< cd > :: LocalGeometry
00258         LocalGeometry;
00259       
00261       template <PartitionIteratorType pit >
00262       struct Partition
00263       {
00265         typedef typename Grid :: template Codim< cd >
00266           :: template Partition< pit > :: LeafIterator
00267           Iterator;
00268       };
00269     };
00270 
00271     enum { conforming = Capabilities :: isLeafwiseConforming< Grid > :: v };
00272   };
00273 
00274 
00275   template< class GridImp, PartitionIteratorType pitype >
00276   class DefaultLeafGridView 
00277   {
00278     typedef DefaultLeafGridView< GridImp, pitype > ThisType;
00279 
00280   public:
00281     typedef DefaultLeafGridViewTraits<GridImp,pitype> Traits;
00282 
00284     typedef typename Traits::Grid Grid;
00285 
00287     typedef typename Traits :: IndexSet IndexSet;
00288 
00290     typedef typename Traits :: Intersection Intersection;
00291 
00293     typedef typename Traits :: IntersectionIterator IntersectionIterator;
00294 
00296     typedef typename Traits :: CollectiveCommunication CollectiveCommunication;
00297     
00299     template< int cd >
00300     struct Codim : public Traits :: template Codim<cd> {};
00301  
00302     enum { conforming = Traits :: conforming };
00303 
00304   public:
00305     DefaultLeafGridView ( const Grid &grid )
00306     : grid_( &grid ),
00307       indexSet_( &(grid.leafIndexSet()) )
00308     {}
00309 
00310 // use default implementation of copy constructor and assignment operator
00311 #if 0
00312     DefaultLeafGridView ( const ThisType &other ) 
00313     : grid_( other.grid_ ),
00314       indexSet_( other.indexSet_ )
00315     {}
00316 
00318     ThisType &operator= ( const ThisType & other)
00319     {
00320       grid_ = other.grid_;
00321       indexSet_ = other.indexSet_;
00322     }
00323 #endif
00324 
00326     const Grid &grid () const
00327     {
00328       return *grid_;
00329     }
00330 
00332     const IndexSet &indexSet () const
00333     {
00334       return *indexSet_;
00335     }
00336 
00338     int size ( int codim ) const
00339     {
00340       return grid().size( codim );
00341     }
00342 
00344     int size ( const GeometryType &type ) const
00345     {
00346       return grid().size( type );
00347     }
00348 
00350     template< int cd >
00351     typename Codim< cd > :: Iterator begin () const
00352     {
00353       return grid().template leafbegin< cd, pitype >();
00354     }
00355 
00357     template< int cd, PartitionIteratorType pit >
00358     typename Codim< cd > :: template Partition< pit > :: Iterator begin () const
00359     {
00360       return grid().template leafbegin< cd, pit >();
00361     }
00362 
00364     template< int cd >
00365     typename Codim< cd > :: Iterator end () const
00366     {
00367       return grid().template leafend< cd, pitype >();
00368     }
00369 
00371     template< int cd, PartitionIteratorType pit >
00372     typename Codim< cd > :: template Partition< pit > :: Iterator end () const
00373     {
00374       return grid().template leafend< cd, pit >();
00375     }
00376 
00378     IntersectionIterator
00379     ibegin ( const typename Codim< 0 > :: Entity &entity ) const
00380     {
00381       return entity.ileafbegin();
00382     }
00383 
00385     IntersectionIterator
00386     iend ( const typename Codim< 0 > :: Entity &entity ) const
00387     {
00388       return entity.ileafend();
00389     }
00390 
00392     const CollectiveCommunication &comm () const
00393     {
00394       return grid().comm();
00395     }
00396 
00398     int overlapSize(int codim) const
00399     {
00400       return grid().overlapSize(codim);
00401     }
00402 
00404     int ghostSize(int codim) const 
00405     {
00406       return grid().ghostSize(codim);
00407     }
00408 
00410     template< class DataHandleImp, class DataType >
00411     void communicate ( CommDataHandleIF< DataHandleImp, DataType > &data,
00412                        InterfaceType iftype,
00413                        CommunicationDirection dir ) const
00414     {
00415       return grid().communicate( data, iftype, dir );
00416     }
00417 
00418   private:
00419     const Grid *grid_;
00420     const IndexSet *indexSet_;
00421   };
00422 
00423 }
00424 
00425 #endif

Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].