1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 // vi: set et ts=4 sw=2 sts=2: 3 #ifndef DUNE_GRID_COMMON_DEFAULTGRIDVIEW_HH 4 #define DUNE_GRID_COMMON_DEFAULTGRIDVIEW_HH 5 6 #include <dune/common/typetraits.hh> 7 #include <dune/common/exceptions.hh> 8 9 #include <dune/grid/common/capabilities.hh> 10 #include <dune/grid/common/gridview.hh> 11 12 namespace Dune 13 { 14 15 template< class GridImp > 16 class DefaultLevelGridView; 17 18 template< class GridImp > 19 class DefaultLeafGridView; 20 21 22 template< class GridImp > 23 struct DefaultLevelGridViewTraits 24 { 25 typedef DefaultLevelGridView< GridImp > GridViewImp; 26 27 /** \brief type of the grid */ 28 typedef typename std::remove_const<GridImp>::type Grid; 29 30 /** \brief type of the index set */ 31 typedef typename Grid :: Traits :: LevelIndexSet IndexSet; 32 33 /** \brief type of the intersection */ 34 typedef typename Grid :: Traits :: LevelIntersection Intersection; 35 36 /** \brief type of the intersection iterator */ 37 typedef typename Grid :: Traits :: LevelIntersectionIterator 38 IntersectionIterator; 39 40 /** \brief type of the collective communication */ 41 typedef typename Grid :: Traits :: CollectiveCommunication CollectiveCommunication; 42 43 template< int cd > 44 struct Codim 45 { 46 typedef typename Grid :: Traits 47 :: template Codim< cd > :: template Partition< All_Partition > :: LevelIterator 48 Iterator; 49 50 typedef typename Grid :: Traits :: template Codim< cd > :: Entity Entity; 51 52 typedef typename Grid :: template Codim< cd > :: Geometry Geometry; 53 typedef typename Grid :: template Codim< cd > :: LocalGeometry 54 LocalGeometry; 55 56 /** \brief Define types needed to iterate over entities of a given partition type */ 57 template< PartitionIteratorType pit > 58 struct Partition 59 { 60 /** \brief iterator over a given codim and partition type */ 61 typedef typename Grid :: template Codim< cd > 62 :: template Partition< pit > :: LevelIterator 63 Iterator; 64 }; 65 }; 66 67 enum { conforming = Capabilities :: isLevelwiseConforming< Grid > :: v }; 68 }; 69 70 71 template< class GridImp > 72 class DefaultLevelGridView 73 { 74 typedef DefaultLevelGridView< GridImp > ThisType; 75 76 public: 77 typedef DefaultLevelGridViewTraits<GridImp> Traits; 78 79 /** \brief type of the grid */ 80 typedef typename Traits::Grid Grid; 81 82 /** \brief type of the index set */ 83 typedef typename Traits :: IndexSet IndexSet; 84 85 /** \brief type of the intersection */ 86 typedef typename Traits :: Intersection Intersection; 87 88 /** \brief type of the intersection iterator */ 89 typedef typename Traits :: IntersectionIterator IntersectionIterator; 90 91 /** \brief type of the collective communication */ 92 typedef typename Traits :: CollectiveCommunication CollectiveCommunication; 93 94 /** \brief Codim Structure */ 95 template< int cd > 96 struct Codim : public Traits :: template Codim<cd> {}; 97 98 enum { conforming = Traits :: conforming }; 99 DefaultLevelGridView(const Grid & grid,int level)100 DefaultLevelGridView ( const Grid &grid, int level ) 101 : grid_( &grid ), 102 level_( level ) 103 {} 104 105 /** \brief obtain a const reference to the underlying hierarchic grid */ grid() const106 const Grid &grid () const 107 { 108 assert( grid_ ); 109 return *grid_; 110 } 111 112 /** \brief obtain the index set */ indexSet() const113 const IndexSet &indexSet () const 114 { 115 return grid().levelIndexSet( level_ ); 116 } 117 118 /** \brief obtain number of entities in a given codimension */ size(int codim) const119 int size ( int codim ) const 120 { 121 return grid().size( level_, codim ); 122 } 123 124 /** \brief obtain number of entities with a given geometry type */ size(const GeometryType & type) const125 int size ( const GeometryType &type ) const 126 { 127 return grid().size( level_, type ); 128 } 129 130 /** \brief obtain begin iterator for this view */ 131 template< int cd > begin() const132 typename Codim< cd > :: Iterator begin () const 133 { 134 return grid().template lbegin< cd, All_Partition >( level_ ); 135 } 136 137 /** \brief obtain begin iterator for this view */ 138 template< int cd, PartitionIteratorType pit > begin() const139 typename Codim< cd > :: template Partition< pit > :: Iterator begin () const 140 { 141 return grid().template lbegin< cd, pit >( level_ ); 142 } 143 144 /** \brief obtain end iterator for this view */ 145 template< int cd > end() const146 typename Codim< cd > :: Iterator end () const 147 { 148 return grid().template lend< cd, All_Partition >( level_ ); 149 } 150 151 /** \brief obtain end iterator for this view */ 152 template< int cd, PartitionIteratorType pit > end() const153 typename Codim< cd > :: template Partition< pit > :: Iterator end () const 154 { 155 return grid().template lend< cd, pit >( level_ ); 156 } 157 158 /** \brief obtain begin intersection iterator with respect to this view */ 159 IntersectionIterator ibegin(const typename Codim<0>::Entity & entity) const160 ibegin ( const typename Codim< 0 > :: Entity &entity ) const 161 { 162 return entity.impl().ilevelbegin(); 163 } 164 165 /** \brief obtain end intersection iterator with respect to this view */ 166 IntersectionIterator iend(const typename Codim<0>::Entity & entity) const167 iend ( const typename Codim< 0 > :: Entity &entity ) const 168 { 169 return entity.impl().ilevelend(); 170 } 171 172 /** \brief obtain collective communication object */ comm() const173 const CollectiveCommunication &comm () const 174 { 175 return grid().comm(); 176 } 177 178 /** \brief Return size of the overlap region for a given codim on the grid view. */ overlapSize(int codim) const179 int overlapSize(int codim) const 180 { 181 return grid().overlapSize(level_, codim); 182 } 183 184 /** \brief Return size of the ghost region for a given codim on the grid view. */ ghostSize(int codim) const185 int ghostSize(int codim) const 186 { 187 return grid().ghostSize(level_, codim); 188 } 189 190 /** communicate data on this view */ 191 template< class DataHandleImp, class DataType > communicate(CommDataHandleIF<DataHandleImp,DataType> & data,InterfaceType iftype,CommunicationDirection dir) const192 void communicate ( CommDataHandleIF< DataHandleImp, DataType > &data, 193 InterfaceType iftype, 194 CommunicationDirection dir ) const 195 { 196 return grid().communicate( data, iftype, dir, level_ ); 197 } 198 199 private: 200 const Grid *grid_; 201 int level_; 202 }; 203 204 205 template< class GridImp > 206 struct DefaultLeafGridViewTraits { 207 typedef DefaultLeafGridView< GridImp > GridViewImp; 208 209 /** \brief type of the grid */ 210 typedef typename std::remove_const<GridImp>::type Grid; 211 212 /** \brief type of the index set */ 213 typedef typename Grid :: Traits :: LeafIndexSet IndexSet; 214 215 /** \brief type of the intersection */ 216 typedef typename Grid :: Traits :: LeafIntersection Intersection; 217 218 /** \brief type of the intersection iterator */ 219 typedef typename Grid :: Traits :: LeafIntersectionIterator 220 IntersectionIterator; 221 222 /** \brief type of the collective communication */ 223 typedef typename Grid :: Traits :: CollectiveCommunication CollectiveCommunication; 224 225 template< int cd > 226 struct Codim 227 { 228 typedef typename Grid :: Traits 229 :: template Codim< cd > :: template Partition< All_Partition > :: LeafIterator 230 Iterator; 231 232 typedef typename Grid :: Traits :: template Codim< cd > :: Entity Entity; 233 234 typedef typename Grid :: template Codim< cd > :: Geometry Geometry; 235 typedef typename Grid :: template Codim< cd > :: LocalGeometry 236 LocalGeometry; 237 238 /** \brief Define types needed to iterate over entities of a given partition type */ 239 template <PartitionIteratorType pit > 240 struct Partition 241 { 242 /** \brief iterator over a given codim and partition type */ 243 typedef typename Grid :: template Codim< cd > 244 :: template Partition< pit > :: LeafIterator 245 Iterator; 246 }; 247 }; 248 249 enum { conforming = Capabilities :: isLeafwiseConforming< Grid > :: v }; 250 }; 251 252 253 template< class GridImp > 254 class DefaultLeafGridView 255 { 256 typedef DefaultLeafGridView< GridImp > ThisType; 257 258 public: 259 typedef DefaultLeafGridViewTraits<GridImp> Traits; 260 261 /** \brief type of the grid */ 262 typedef typename Traits::Grid Grid; 263 264 /** \brief type of the index set */ 265 typedef typename Traits :: IndexSet IndexSet; 266 267 /** \brief type of the intersection */ 268 typedef typename Traits :: Intersection Intersection; 269 270 /** \brief type of the intersection iterator */ 271 typedef typename Traits :: IntersectionIterator IntersectionIterator; 272 273 /** \brief type of the collective communication */ 274 typedef typename Traits :: CollectiveCommunication CollectiveCommunication; 275 276 /** \brief Codim Structure */ 277 template< int cd > 278 struct Codim : public Traits :: template Codim<cd> {}; 279 280 enum { conforming = Traits :: conforming }; 281 282 public: DefaultLeafGridView(const Grid & grid)283 DefaultLeafGridView ( const Grid &grid ) 284 : grid_( &grid ) 285 {} 286 287 /** \brief obtain a const reference to the underlying hierarchic grid */ grid() const288 const Grid &grid () const 289 { 290 assert( grid_ ); 291 return *grid_; 292 } 293 294 /** \brief obtain the index set */ indexSet() const295 const IndexSet &indexSet () const 296 { 297 return grid().leafIndexSet(); 298 } 299 300 /** \brief obtain number of entities in a given codimension */ size(int codim) const301 int size ( int codim ) const 302 { 303 return grid().size( codim ); 304 } 305 306 /** \brief obtain number of entities with a given geometry type */ size(const GeometryType & type) const307 int size ( const GeometryType &type ) const 308 { 309 return grid().size( type ); 310 } 311 312 /** \brief obtain begin iterator for this view */ 313 template< int cd > begin() const314 typename Codim< cd > :: Iterator begin () const 315 { 316 return grid().template leafbegin< cd, All_Partition >(); 317 } 318 319 /** \brief obtain begin iterator for this view */ 320 template< int cd, PartitionIteratorType pit > begin() const321 typename Codim< cd > :: template Partition< pit > :: Iterator begin () const 322 { 323 return grid().template leafbegin< cd, pit >(); 324 } 325 326 /** \brief obtain end iterator for this view */ 327 template< int cd > end() const328 typename Codim< cd > :: Iterator end () const 329 { 330 return grid().template leafend< cd, All_Partition >(); 331 } 332 333 /** \brief obtain end iterator for this view */ 334 template< int cd, PartitionIteratorType pit > end() const335 typename Codim< cd > :: template Partition< pit > :: Iterator end () const 336 { 337 return grid().template leafend< cd, pit >(); 338 } 339 340 /** \brief obtain begin intersection iterator with respect to this view */ 341 IntersectionIterator ibegin(const typename Codim<0>::Entity & entity) const342 ibegin ( const typename Codim< 0 > :: Entity &entity ) const 343 { 344 return entity.impl().ileafbegin(); 345 } 346 347 /** \brief obtain end intersection iterator with respect to this view */ 348 IntersectionIterator iend(const typename Codim<0>::Entity & entity) const349 iend ( const typename Codim< 0 > :: Entity &entity ) const 350 { 351 return entity.impl().ileafend(); 352 } 353 354 /** \brief obtain collective communication object */ comm() const355 const CollectiveCommunication &comm () const 356 { 357 return grid().comm(); 358 } 359 360 /** \brief Return size of the overlap region for a given codim on the grid view. */ overlapSize(int codim) const361 int overlapSize(int codim) const 362 { 363 return grid().overlapSize(codim); 364 } 365 366 /** \brief Return size of the ghost region for a given codim on the grid view. */ ghostSize(int codim) const367 int ghostSize(int codim) const 368 { 369 return grid().ghostSize(codim); 370 } 371 372 /** communicate data on this view */ 373 template< class DataHandleImp, class DataType > communicate(CommDataHandleIF<DataHandleImp,DataType> & data,InterfaceType iftype,CommunicationDirection dir) const374 void communicate ( CommDataHandleIF< DataHandleImp, DataType > &data, 375 InterfaceType iftype, 376 CommunicationDirection dir ) const 377 { 378 return grid().communicate( data, iftype, dir ); 379 } 380 381 private: 382 const Grid *grid_; 383 }; 384 385 } 386 387 #endif 388