dune-grid  2.1.1
albertagrid/gridview.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_ALBERTAGRID_GRIDVIEW_HH
00004 #define DUNE_ALBERTAGRID_GRIDVIEW_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 #include <dune/grid/albertagrid/intersectioniterator.hh>
00013 
00014 namespace Dune
00015 {
00016 
00017   template< class GridImp, PartitionIteratorType pitype >
00018   class AlbertaLevelGridView;
00019 
00020   template< class GridImp, PartitionIteratorType pitype >
00021   class AlbertaLeafGridView;
00022 
00023 
00024   template< class GridImp, PartitionIteratorType pitype >
00025   struct AlbertaLevelGridViewTraits
00026   {
00027     typedef AlbertaLevelGridView< GridImp, pitype > GridViewImp;
00028 
00030     typedef typename remove_const<GridImp>::type Grid;
00031 
00033     typedef typename Grid::Traits::LevelIndexSet IndexSet;
00034 
00036     typedef typename Grid::Traits::LevelIntersection Intersection;
00037 
00039     typedef typename Grid::Traits::LevelIntersectionIterator
00040       IntersectionIterator;
00041 
00043     typedef typename Grid::Traits::CollectiveCommunication CollectiveCommunication;
00044 
00045     template< int cd >
00046     struct Codim
00047     {
00048       typedef typename Grid::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator
00049         Iterator;
00050 
00051       typedef typename Grid::Traits::template Codim< cd >::Entity Entity;
00052       typedef typename Grid::Traits::template Codim< cd >::EntityPointer
00053         EntityPointer;
00054 
00055       typedef typename Grid::template Codim< cd >::Geometry Geometry;
00056       typedef typename Grid::template Codim< cd >::LocalGeometry
00057         LocalGeometry;
00058 
00060       template< PartitionIteratorType pit >
00061       struct Partition
00062       {
00064         typedef typename Grid::template Codim< cd >::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 AlbertaLevelGridView 
00075   {
00076     typedef AlbertaLevelGridView< GridImp, pitype > ThisType;
00077 
00078   public:
00079     typedef AlbertaLevelGridViewTraits<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   private:
00103     typedef Alberta::ElementInfo< Grid::dimension > ElementInfo;
00104 
00105     typedef Dune::AlbertaGridLeafIntersectionIterator< GridImp > IntersectionIteratorImpl;
00106 
00107   public:
00108     AlbertaLevelGridView ( const Grid &grid, int level )
00109     : grid_( &grid ),
00110       indexSet_( &(grid.levelIndexSet( level )) ),
00111       level_( level )
00112     {}
00113 
00114 // use default implementation of copy constructor and assignment operator
00115 #if 0
00116     AlbertaLevelGridView ( const ThisType &other ) 
00117     : grid_( other.grid_ ),
00118       indexSet_( other.indexSet_ ),
00119       level_( other.level_ )
00120     {}
00121 
00123     ThisType &operator= ( const ThisType & other)
00124     {
00125       grid_ = other.grid_;
00126       indexSet_ = other.indexSet_;
00127       level_ = other.level_;
00128     }
00129 #endif
00130 
00132     const Grid &grid () const
00133     {
00134       return *grid_;
00135     }
00136 
00138     const IndexSet &indexSet () const
00139     {
00140       return *indexSet_;
00141     }
00142     
00144     int size ( int codim ) const
00145     {
00146       return grid().size( level_, codim );
00147     }
00148 
00150     int size ( const GeometryType &type ) const
00151     {
00152       return grid().size( level_, type );
00153     }
00154 
00156     template< int cd >
00157     typename Codim< cd >::Iterator begin () const
00158     {
00159       return grid().template lbegin< cd, pitype >( level_ );
00160     }
00161 
00163     template< int cd, PartitionIteratorType pit >
00164     typename Codim< cd >::template Partition< pit >::Iterator begin () const
00165     {
00166       return grid().template lbegin< cd, pit >( level_ );
00167     }
00168 
00170     template< int cd >
00171     typename Codim< cd >::Iterator end () const
00172     {
00173       return grid().template lend< cd, pitype >( level_ );
00174     }
00175 
00177     template< int cd, PartitionIteratorType pit >
00178     typename Codim< cd >::template Partition< pit >::Iterator end () const
00179     {
00180       return grid().template lend< cd, pit >( level_ );
00181     }
00182 
00184     IntersectionIterator
00185     ibegin ( const typename Codim< 0 >::Entity &entity ) const
00186     {
00187       DUNE_THROW( NotImplemented, "method ibegin not implemented on LevelGridView for AlbertaGrid." );
00188       typename IntersectionIteratorImpl::End end;
00189       return IntersectionIteratorImpl( Grid::getRealImplementation( entity ), end );
00190     }
00191 
00193     IntersectionIterator
00194     iend ( const typename Codim< 0 >::Entity &entity ) const
00195     {
00196       DUNE_THROW( NotImplemented, "method iend not implemented on LevelGridView for AlbertaGrid." );
00197       typename IntersectionIteratorImpl::End end;
00198       return IntersectionIteratorImpl( Grid::getRealImplementation( entity ), end );
00199     }
00200 
00202     const CollectiveCommunication &comm () const
00203     {
00204       return grid().comm();
00205     }
00206 
00208     int overlapSize(int codim) const
00209     {
00210       return grid().overlapSize(level_, codim);
00211     }
00212 
00214     int ghostSize(int codim) const 
00215     {
00216       return grid().ghostSize(level_, codim);
00217     }
00218 
00220     template< class DataHandleImp, class DataType >
00221     void communicate ( CommDataHandleIF< DataHandleImp, DataType > &data,
00222                        InterfaceType iftype,
00223                        CommunicationDirection dir ) const
00224     {}
00225 
00226   private:
00227     const Grid *grid_;
00228     const IndexSet *indexSet_;
00229     int level_;
00230   };
00231   
00232 
00233   template< class GridImp, PartitionIteratorType pitype >
00234   struct AlbertaLeafGridViewTraits
00235   {
00236     typedef AlbertaLeafGridView< GridImp, pitype > GridViewImp;
00237 
00239     typedef typename remove_const<GridImp>::type Grid;
00240 
00242     typedef typename Grid::Traits::LeafIndexSet IndexSet;
00243 
00245     typedef typename Grid::Traits::LeafIntersection Intersection;
00246 
00248     typedef typename Grid::Traits::LeafIntersectionIterator
00249       IntersectionIterator;
00250 
00252     typedef typename Grid::Traits::CollectiveCommunication CollectiveCommunication;
00253     
00254     template< int cd >
00255     struct Codim
00256     {
00257       typedef typename Grid::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
00258         Iterator;
00259 
00260       typedef typename Grid::Traits::template Codim< cd >::Entity Entity;
00261       typedef typename Grid::Traits::template Codim< cd >::EntityPointer
00262         EntityPointer;
00263 
00264       typedef typename Grid::template Codim< cd >::Geometry Geometry;
00265       typedef typename Grid::template Codim< cd >::LocalGeometry
00266         LocalGeometry;
00267       
00269       template <PartitionIteratorType pit >
00270       struct Partition
00271       {
00273         typedef typename Grid::template Codim< cd >::template Partition< pit >::LeafIterator
00274           Iterator;
00275       };
00276     };
00277 
00278     enum { conforming = Capabilities::isLeafwiseConforming< Grid >::v };
00279   };
00280 
00281 
00282   template< class GridImp, PartitionIteratorType pitype >
00283   class AlbertaLeafGridView 
00284   {
00285     typedef AlbertaLeafGridView< GridImp, pitype > ThisType;
00286 
00287   public:
00288     typedef AlbertaLeafGridViewTraits<GridImp,pitype> Traits;
00289 
00291     typedef typename Traits::Grid Grid;
00292 
00294     typedef typename Traits::IndexSet IndexSet;
00295 
00297     typedef typename Traits::Intersection Intersection;
00298 
00300     typedef typename Traits::IntersectionIterator IntersectionIterator;
00301 
00303     typedef typename Traits::CollectiveCommunication CollectiveCommunication;
00304     
00306     template< int cd >
00307     struct Codim : public Traits::template Codim<cd> {};
00308  
00309     enum { conforming = Traits::conforming };
00310 
00311   private:
00312     typedef Alberta::ElementInfo< Grid::dimension > ElementInfo;
00313 
00314     typedef Dune::AlbertaGridLeafIntersectionIterator< GridImp > IntersectionIteratorImpl;
00315 
00316   public:
00317     AlbertaLeafGridView ( const Grid &grid )
00318     : grid_( &grid ),
00319       indexSet_( &(grid.leafIndexSet()) )
00320     {}
00321 
00322 // use default implementation of copy constructor and assignment operator
00323 #if 0
00324     AlbertaLeafGridView ( const ThisType &other ) 
00325     : grid_( other.grid_ ),
00326       indexSet_( other.indexSet_ )
00327     {}
00328 
00330     ThisType &operator= ( const ThisType & other)
00331     {
00332       grid_ = other.grid_;
00333       indexSet_ = other.indexSet_;
00334     }
00335 #endif
00336 
00338     const Grid &grid () const
00339     {
00340       return *grid_;
00341     }
00342 
00344     const IndexSet &indexSet () const
00345     {
00346       return *indexSet_;
00347     }
00348 
00350     int size ( int codim ) const
00351     {
00352       return grid().size( codim );
00353     }
00354 
00356     int size ( const GeometryType &type ) const
00357     {
00358       return grid().size( type );
00359     }
00360 
00362     template< int cd >
00363     typename Codim< cd >::Iterator begin () const
00364     {
00365       return grid().template leafbegin< cd, pitype >();
00366     }
00367 
00369     template< int cd, PartitionIteratorType pit >
00370     typename Codim< cd >::template Partition< pit >::Iterator begin () const
00371     {
00372       return grid().template leafbegin< cd, pit >();
00373     }
00374 
00376     template< int cd >
00377     typename Codim< cd >::Iterator end () const
00378     {
00379       return grid().template leafend< cd, pitype >();
00380     }
00381 
00383     template< int cd, PartitionIteratorType pit >
00384     typename Codim< cd >::template Partition< pit >::Iterator end () const
00385     {
00386       return grid().template leafend< cd, pit >();
00387     }
00388 
00390     IntersectionIterator
00391     ibegin ( const typename Codim< 0 >::Entity &entity ) const
00392     {
00393       const ElementInfo elementInfo = Grid::getRealImplementation( entity ).elementInfo();
00394       assert( !!elementInfo );
00395 
00396 #ifndef NDEBUG 
00397       for( int i = 0; i <= Grid::dimension; ++i )
00398       {
00399         if( elementInfo.elInfo().opp_vertex[ i ] == 127 )
00400           DUNE_THROW( NotImplemented, "AlbertaGrid: Intersections on outside entities are not fully implemented, yet." );
00401       }
00402 #endif // #ifndef NDEBUG 
00403 
00404       typename IntersectionIteratorImpl::Begin begin;
00405       return IntersectionIteratorImpl( Grid::getRealImplementation( entity ), begin );
00406     }
00407 
00409     IntersectionIterator
00410     iend ( const typename Codim< 0 >::Entity &entity ) const
00411     {
00412       assert( !!Grid::getRealImplementation( entity ).elementInfo() );
00413       typename IntersectionIteratorImpl::End end;
00414       return IntersectionIteratorImpl( Grid::getRealImplementation( entity ), end );
00415     }
00416 
00418     const CollectiveCommunication &comm () const
00419     {
00420       return grid().comm();
00421     }
00422 
00424     int overlapSize(int codim) const
00425     {
00426       return grid().overlapSize(codim);
00427     }
00428 
00430     int ghostSize(int codim) const 
00431     {
00432       return grid().ghostSize(codim);
00433     }
00434 
00436     template< class DataHandleImp, class DataType >
00437     void communicate ( CommDataHandleIF< DataHandleImp, DataType > &data,
00438                        InterfaceType iftype,
00439                        CommunicationDirection dir ) const
00440     {}
00441 
00442   private:
00443     const Grid *grid_;
00444     const IndexSet *indexSet_;
00445   };
00446 
00447 }
00448 
00449 #endif // #ifndef DUNE_ALBERTAGRID_GRIDVIEW_HH