dune-grid
2.2.0
|
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 #if HAVE_ALBERTA 00007 00008 #include <dune/common/typetraits.hh> 00009 #include <dune/common/exceptions.hh> 00010 00011 #include <dune/grid/common/capabilities.hh> 00012 #include <dune/grid/common/gridview.hh> 00013 00014 #include <dune/grid/albertagrid/intersectioniterator.hh> 00015 00016 namespace Dune 00017 { 00018 00019 template< class GridImp, PartitionIteratorType pitype > 00020 class AlbertaLevelGridView; 00021 00022 template< class GridImp, PartitionIteratorType pitype > 00023 class AlbertaLeafGridView; 00024 00025 00026 template< class GridImp, PartitionIteratorType pitype > 00027 struct AlbertaLevelGridViewTraits 00028 { 00029 typedef AlbertaLevelGridView< GridImp, pitype > GridViewImp; 00030 00032 typedef typename remove_const<GridImp>::type Grid; 00033 00035 typedef typename Grid::Traits::LevelIndexSet IndexSet; 00036 00038 typedef typename Grid::Traits::LevelIntersection Intersection; 00039 00041 typedef typename Grid::Traits::LevelIntersectionIterator 00042 IntersectionIterator; 00043 00045 typedef typename Grid::Traits::CollectiveCommunication CollectiveCommunication; 00046 00047 template< int cd > 00048 struct Codim 00049 { 00050 typedef typename Grid::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator 00051 Iterator; 00052 00053 typedef typename Grid::Traits::template Codim< cd >::Entity Entity; 00054 typedef typename Grid::Traits::template Codim< cd >::EntityPointer 00055 EntityPointer; 00056 00057 typedef typename Grid::template Codim< cd >::Geometry Geometry; 00058 typedef typename Grid::template Codim< cd >::LocalGeometry 00059 LocalGeometry; 00060 00062 template< PartitionIteratorType pit > 00063 struct Partition 00064 { 00066 typedef typename Grid::template Codim< cd >::template Partition< pit >::LevelIterator 00067 Iterator; 00068 }; 00069 }; 00070 00071 enum { conforming = Capabilities::isLevelwiseConforming< Grid >::v }; 00072 }; 00073 00074 00075 template< class GridImp, PartitionIteratorType pitype > 00076 class AlbertaLevelGridView 00077 { 00078 typedef AlbertaLevelGridView< GridImp, pitype > ThisType; 00079 00080 public: 00081 typedef AlbertaLevelGridViewTraits<GridImp,pitype> Traits; 00082 00084 typedef typename Traits::Grid Grid; 00085 00087 typedef typename Traits::IndexSet IndexSet; 00088 00090 typedef typename Traits::Intersection Intersection; 00091 00093 typedef typename Traits::IntersectionIterator IntersectionIterator; 00094 00096 typedef typename Traits::CollectiveCommunication CollectiveCommunication; 00097 00099 template< int cd > 00100 struct Codim : public Traits::template Codim<cd> {}; 00101 00102 enum { conforming = Traits::conforming }; 00103 00104 private: 00105 typedef Alberta::ElementInfo< Grid::dimension > ElementInfo; 00106 00107 typedef Dune::AlbertaGridLeafIntersectionIterator< GridImp > IntersectionIteratorImpl; 00108 00109 public: 00110 AlbertaLevelGridView ( const Grid &grid, int level ) 00111 : grid_( &grid ), 00112 indexSet_( &(grid.levelIndexSet( level )) ), 00113 level_( level ) 00114 {} 00115 00116 // use default implementation of copy constructor and assignment operator 00117 #if 0 00118 AlbertaLevelGridView ( const ThisType &other ) 00119 : grid_( other.grid_ ), 00120 indexSet_( other.indexSet_ ), 00121 level_( other.level_ ) 00122 {} 00123 00125 ThisType &operator= ( const ThisType & other) 00126 { 00127 grid_ = other.grid_; 00128 indexSet_ = other.indexSet_; 00129 level_ = other.level_; 00130 } 00131 #endif 00132 00134 const Grid &grid () const 00135 { 00136 return *grid_; 00137 } 00138 00140 const IndexSet &indexSet () const 00141 { 00142 return *indexSet_; 00143 } 00144 00146 int size ( int codim ) const 00147 { 00148 return grid().size( level_, codim ); 00149 } 00150 00152 int size ( const GeometryType &type ) const 00153 { 00154 return grid().size( level_, type ); 00155 } 00156 00158 template< int cd > 00159 typename Codim< cd >::Iterator begin () const 00160 { 00161 return grid().template lbegin< cd, pitype >( level_ ); 00162 } 00163 00165 template< int cd, PartitionIteratorType pit > 00166 typename Codim< cd >::template Partition< pit >::Iterator begin () const 00167 { 00168 return grid().template lbegin< cd, pit >( level_ ); 00169 } 00170 00172 template< int cd > 00173 typename Codim< cd >::Iterator end () const 00174 { 00175 return grid().template lend< cd, pitype >( level_ ); 00176 } 00177 00179 template< int cd, PartitionIteratorType pit > 00180 typename Codim< cd >::template Partition< pit >::Iterator end () const 00181 { 00182 return grid().template lend< cd, pit >( level_ ); 00183 } 00184 00186 IntersectionIterator 00187 ibegin ( const typename Codim< 0 >::Entity &entity ) const 00188 { 00189 if( grid().maxLevel() == 0) 00190 { 00191 typename IntersectionIteratorImpl::Begin begin; 00192 return IntersectionIteratorImpl( Grid::getRealImplementation( entity ), begin ); 00193 } 00194 else 00195 { 00196 DUNE_THROW( NotImplemented, "method ibegin not implemented on LevelGridView for AlbertaGrid." ); 00197 typename IntersectionIteratorImpl::End end; 00198 return IntersectionIteratorImpl( Grid::getRealImplementation( entity ), end ); 00199 } 00200 } 00201 00203 IntersectionIterator 00204 iend ( const typename Codim< 0 >::Entity &entity ) const 00205 { 00206 typename IntersectionIteratorImpl::End end; 00207 return IntersectionIteratorImpl( Grid::getRealImplementation( entity ), end ); 00208 } 00209 00211 const CollectiveCommunication &comm () const 00212 { 00213 return grid().comm(); 00214 } 00215 00217 int overlapSize(int codim) const 00218 { 00219 return grid().overlapSize(level_, codim); 00220 } 00221 00223 int ghostSize(int codim) const 00224 { 00225 return grid().ghostSize(level_, codim); 00226 } 00227 00229 template< class DataHandleImp, class DataType > 00230 void communicate ( CommDataHandleIF< DataHandleImp, DataType > &data, 00231 InterfaceType iftype, 00232 CommunicationDirection dir ) const 00233 {} 00234 00235 private: 00236 const Grid *grid_; 00237 const IndexSet *indexSet_; 00238 int level_; 00239 }; 00240 00241 00242 template< class GridImp, PartitionIteratorType pitype > 00243 struct AlbertaLeafGridViewTraits 00244 { 00245 typedef AlbertaLeafGridView< GridImp, pitype > GridViewImp; 00246 00248 typedef typename remove_const<GridImp>::type Grid; 00249 00251 typedef typename Grid::Traits::LeafIndexSet IndexSet; 00252 00254 typedef typename Grid::Traits::LeafIntersection Intersection; 00255 00257 typedef typename Grid::Traits::LeafIntersectionIterator 00258 IntersectionIterator; 00259 00261 typedef typename Grid::Traits::CollectiveCommunication CollectiveCommunication; 00262 00263 template< int cd > 00264 struct Codim 00265 { 00266 typedef typename Grid::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator 00267 Iterator; 00268 00269 typedef typename Grid::Traits::template Codim< cd >::Entity Entity; 00270 typedef typename Grid::Traits::template Codim< cd >::EntityPointer 00271 EntityPointer; 00272 00273 typedef typename Grid::template Codim< cd >::Geometry Geometry; 00274 typedef typename Grid::template Codim< cd >::LocalGeometry 00275 LocalGeometry; 00276 00278 template <PartitionIteratorType pit > 00279 struct Partition 00280 { 00282 typedef typename Grid::template Codim< cd >::template Partition< pit >::LeafIterator 00283 Iterator; 00284 }; 00285 }; 00286 00287 enum { conforming = Capabilities::isLeafwiseConforming< Grid >::v }; 00288 }; 00289 00290 00291 template< class GridImp, PartitionIteratorType pitype > 00292 class AlbertaLeafGridView 00293 { 00294 typedef AlbertaLeafGridView< GridImp, pitype > ThisType; 00295 00296 public: 00297 typedef AlbertaLeafGridViewTraits<GridImp,pitype> Traits; 00298 00300 typedef typename Traits::Grid Grid; 00301 00303 typedef typename Traits::IndexSet IndexSet; 00304 00306 typedef typename Traits::Intersection Intersection; 00307 00309 typedef typename Traits::IntersectionIterator IntersectionIterator; 00310 00312 typedef typename Traits::CollectiveCommunication CollectiveCommunication; 00313 00315 template< int cd > 00316 struct Codim : public Traits::template Codim<cd> {}; 00317 00318 enum { conforming = Traits::conforming }; 00319 00320 private: 00321 typedef Alberta::ElementInfo< Grid::dimension > ElementInfo; 00322 00323 typedef Dune::AlbertaGridLeafIntersectionIterator< GridImp > IntersectionIteratorImpl; 00324 00325 public: 00326 AlbertaLeafGridView ( const Grid &grid ) 00327 : grid_( &grid ), 00328 indexSet_( &(grid.leafIndexSet()) ) 00329 {} 00330 00331 // use default implementation of copy constructor and assignment operator 00332 #if 0 00333 AlbertaLeafGridView ( const ThisType &other ) 00334 : grid_( other.grid_ ), 00335 indexSet_( other.indexSet_ ) 00336 {} 00337 00339 ThisType &operator= ( const ThisType & other) 00340 { 00341 grid_ = other.grid_; 00342 indexSet_ = other.indexSet_; 00343 } 00344 #endif 00345 00347 const Grid &grid () const 00348 { 00349 return *grid_; 00350 } 00351 00353 const IndexSet &indexSet () const 00354 { 00355 return *indexSet_; 00356 } 00357 00359 int size ( int codim ) const 00360 { 00361 return grid().size( codim ); 00362 } 00363 00365 int size ( const GeometryType &type ) const 00366 { 00367 return grid().size( type ); 00368 } 00369 00371 template< int cd > 00372 typename Codim< cd >::Iterator begin () const 00373 { 00374 return grid().template leafbegin< cd, pitype >(); 00375 } 00376 00378 template< int cd, PartitionIteratorType pit > 00379 typename Codim< cd >::template Partition< pit >::Iterator begin () const 00380 { 00381 return grid().template leafbegin< cd, pit >(); 00382 } 00383 00385 template< int cd > 00386 typename Codim< cd >::Iterator end () const 00387 { 00388 return grid().template leafend< cd, pitype >(); 00389 } 00390 00392 template< int cd, PartitionIteratorType pit > 00393 typename Codim< cd >::template Partition< pit >::Iterator end () const 00394 { 00395 return grid().template leafend< cd, pit >(); 00396 } 00397 00399 IntersectionIterator 00400 ibegin ( const typename Codim< 0 >::Entity &entity ) const 00401 { 00402 const ElementInfo elementInfo = Grid::getRealImplementation( entity ).elementInfo(); 00403 assert( !!elementInfo ); 00404 00405 #ifndef NDEBUG 00406 for( int i = 0; i <= Grid::dimension; ++i ) 00407 { 00408 if( elementInfo.elInfo().opp_vertex[ i ] == 127 ) 00409 DUNE_THROW( NotImplemented, "AlbertaGrid: Intersections on outside entities are not fully implemented, yet." ); 00410 } 00411 #endif // #ifndef NDEBUG 00412 00413 typename IntersectionIteratorImpl::Begin begin; 00414 return IntersectionIteratorImpl( Grid::getRealImplementation( entity ), begin ); 00415 } 00416 00418 IntersectionIterator 00419 iend ( const typename Codim< 0 >::Entity &entity ) const 00420 { 00421 assert( !!Grid::getRealImplementation( entity ).elementInfo() ); 00422 typename IntersectionIteratorImpl::End end; 00423 return IntersectionIteratorImpl( Grid::getRealImplementation( entity ), end ); 00424 } 00425 00427 const CollectiveCommunication &comm () const 00428 { 00429 return grid().comm(); 00430 } 00431 00433 int overlapSize(int codim) const 00434 { 00435 return grid().overlapSize(codim); 00436 } 00437 00439 int ghostSize(int codim) const 00440 { 00441 return grid().ghostSize(codim); 00442 } 00443 00445 template< class DataHandleImp, class DataType > 00446 void communicate ( CommDataHandleIF< DataHandleImp, DataType > &data, 00447 InterfaceType iftype, 00448 CommunicationDirection dir ) const 00449 {} 00450 00451 private: 00452 const Grid *grid_; 00453 const IndexSet *indexSet_; 00454 }; 00455 00456 } 00457 00458 #endif // #if HAVE_ALBERTA 00459 #endif // #ifndef DUNE_ALBERTAGRID_GRIDVIEW_HH