1 #ifndef DUNE_ALUGRID_3D_GRIDVIEW_HH 2 #define DUNE_ALUGRID_3D_GRIDVIEW_HH 3 4 #include <type_traits> 5 6 #include <dune/common/version.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, PartitionIteratorType pitype > 16 class ALU3dLevelGridView; 17 18 template< class GridImp, PartitionIteratorType pitype > 19 class ALU3dLeafGridView; 20 21 22 template< class GridImp, PartitionIteratorType pitype > 23 struct ALU3dLevelGridViewTraits 24 { 25 typedef ALU3dLevelGridView< GridImp, pitype > 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::template Codim< cd >::Twists Twists; 47 typedef typename Twists::Twist Twist; 48 49 typedef typename Grid :: Traits 50 :: template Codim< cd > :: template Partition< pitype > :: LevelIterator 51 Iterator; 52 53 typedef typename Grid :: Traits :: template Codim< cd > :: Entity Entity; 54 55 typedef typename Grid :: template Codim< cd > :: Geometry Geometry; 56 typedef typename Grid :: template Codim< cd > :: LocalGeometry 57 LocalGeometry; 58 59 /** \brief Define types needed to iterate over entities of a given partition type */ 60 template< PartitionIteratorType pit > 61 struct Partition 62 { 63 /** \brief iterator over a given codim and partition type */ 64 typedef typename Grid :: template Codim< cd > 65 :: template Partition< pit > :: LevelIterator 66 Iterator; 67 }; 68 }; 69 70 enum { conforming = Capabilities :: isLevelwiseConforming< Grid > :: v }; 71 }; 72 73 74 template< class GridImp, PartitionIteratorType pitype > 75 class ALU3dLevelGridView 76 { 77 typedef ALU3dLevelGridView< GridImp, pitype > ThisType; 78 79 public: 80 typedef ALU3dLevelGridViewTraits<GridImp,pitype> Traits; 81 82 /** \brief type of the grid */ 83 typedef typename Traits::Grid Grid; 84 85 /** \brief type of the index set */ 86 typedef typename Traits :: IndexSet IndexSet; 87 88 /** \brief type of the intersection */ 89 typedef typename Traits :: Intersection Intersection; 90 91 /** \brief type of the intersection iterator */ 92 typedef typename Traits :: IntersectionIterator IntersectionIterator; 93 94 /** \brief type of the collective communication */ 95 typedef typename Traits :: CollectiveCommunication CollectiveCommunication; 96 97 /** \brief Codim Structure */ 98 template< int cd > 99 struct Codim : public Traits :: template Codim<cd> {}; 100 101 enum { conforming = Traits :: conforming }; 102 ALU3dLevelGridView(const Grid & grid,int level)103 ALU3dLevelGridView ( const Grid &grid, int level ) 104 : grid_( &grid ), 105 level_( level ) 106 {} 107 108 /** \brief obtain a const reference to the underlying hierarchic grid */ grid() const109 const Grid &grid () const 110 { 111 assert( grid_ ); 112 return *grid_; 113 } 114 115 /** \brief obtain the index set */ indexSet() const116 const IndexSet &indexSet () const 117 { 118 return grid().levelIndexSet( level_ ); 119 } 120 121 /** \brief obtain number of entities in a given codimension */ size(int codim) const122 int size ( int codim ) const 123 { 124 return grid().size( level_, codim ); 125 } 126 127 /** \brief obtain number of entities with a given geometry type */ size(const GeometryType & type) const128 int size ( const GeometryType &type ) const 129 { 130 return grid().size( level_, type ); 131 } 132 133 /** \brief obtain begin iterator for this view */ 134 template< int cd > begin() const135 typename Codim< cd > :: Iterator begin () const 136 { 137 return grid().template lbegin< cd, pitype >( level_ ); 138 } 139 140 /** \brief obtain begin iterator for this view */ 141 template< int cd, PartitionIteratorType pit > begin() const142 typename Codim< cd > :: template Partition< pit > :: Iterator begin () const 143 { 144 return grid().template lbegin< cd, pit >( level_ ); 145 } 146 147 /** \brief obtain end iterator for this view */ 148 template< int cd > end() const149 typename Codim< cd > :: Iterator end () const 150 { 151 return grid().template lend< cd, pitype >( level_ ); 152 } 153 154 /** \brief obtain end iterator for this view */ 155 template< int cd, PartitionIteratorType pit > end() const156 typename Codim< cd > :: template Partition< pit > :: Iterator end () const 157 { 158 return grid().template lend< cd, pit >( level_ ); 159 } 160 161 /** \brief obtain begin intersection iterator with respect to this view */ 162 IntersectionIterator ibegin(const typename Codim<0>::Entity & entity) const163 ibegin ( const typename Codim< 0 > :: Entity &entity ) const 164 { 165 return grid().ilevelbegin( entity ); 166 } 167 168 /** \brief obtain end intersection iterator with respect to this view */ 169 IntersectionIterator iend(const typename Codim<0>::Entity & entity) const170 iend ( const typename Codim< 0 > :: Entity &entity ) const 171 { 172 return grid().ilevelend( entity ); 173 } 174 175 /** \brief obtain collective communication object */ comm() const176 const CollectiveCommunication &comm () const 177 { 178 return grid().comm(); 179 } 180 181 /** \brief Return size of the overlap region for a given codim on the grid view. */ overlapSize(int codim) const182 int overlapSize(int codim) const 183 { 184 return grid().overlapSize(level_, codim); 185 } 186 187 /** \brief Return size of the ghost region for a given codim on the grid view. */ ghostSize(int codim) const188 int ghostSize(int codim) const 189 { 190 return grid().ghostSize(level_, codim); 191 } 192 193 /** communicate data on this view */ 194 template< class DataHandle, class Data > communicate(CommDataHandleIF<DataHandle,Data> & data,InterfaceType iftype,CommunicationDirection dir) const195 typename Grid::LevelCommunication communicate ( CommDataHandleIF< DataHandle, Data > &data, 196 InterfaceType iftype, 197 CommunicationDirection dir ) const 198 { 199 return grid().communicate( data, iftype, dir, level_ ); 200 } 201 202 template< int cd > twists(GeometryType type) const203 typename Codim< cd >::Twists twists ( GeometryType type ) const 204 { 205 return grid().template twists< cd >( type ); 206 } 207 208 private: 209 const Grid *grid_; 210 int level_; 211 }; 212 213 214 template< class GridImp, PartitionIteratorType pitype > 215 struct ALU3dLeafGridViewTraits { 216 typedef ALU3dLeafGridView< GridImp, pitype > GridViewImp; 217 218 /** \brief type of the grid */ 219 typedef typename std::remove_const<GridImp>::type Grid; 220 221 /** \brief type of the index set */ 222 typedef typename Grid :: Traits :: LeafIndexSet IndexSet; 223 224 /** \brief type of the intersection */ 225 typedef typename Grid :: Traits :: LeafIntersection Intersection; 226 227 /** \brief type of the intersection iterator */ 228 typedef typename Grid :: Traits :: LeafIntersectionIterator 229 IntersectionIterator; 230 231 /** \brief type of the collective communication */ 232 typedef typename Grid :: Traits :: CollectiveCommunication CollectiveCommunication; 233 234 template< int cd > 235 struct Codim 236 { 237 typedef typename Grid::Traits::template Codim< cd >::Twists Twists; 238 typedef typename Twists::Twist Twist; 239 240 typedef typename Grid :: Traits 241 :: template Codim< cd > :: template Partition< pitype > :: LeafIterator 242 Iterator; 243 244 typedef typename Grid :: Traits :: template Codim< cd > :: Entity Entity; 245 246 typedef typename Grid :: template Codim< cd > :: Geometry Geometry; 247 typedef typename Grid :: template Codim< cd > :: LocalGeometry 248 LocalGeometry; 249 250 /** \brief Define types needed to iterate over entities of a given partition type */ 251 template <PartitionIteratorType pit > 252 struct Partition 253 { 254 /** \brief iterator over a given codim and partition type */ 255 typedef typename Grid :: template Codim< cd > 256 :: template Partition< pit > :: LeafIterator 257 Iterator; 258 }; 259 }; 260 261 enum { conforming = Capabilities :: isLeafwiseConforming< Grid > :: v }; 262 }; 263 264 265 template< class GridImp, PartitionIteratorType pitype > 266 class ALU3dLeafGridView 267 { 268 typedef ALU3dLeafGridView< GridImp, pitype > ThisType; 269 270 public: 271 typedef ALU3dLeafGridViewTraits<GridImp,pitype> Traits; 272 273 /** \brief type of the grid */ 274 typedef typename Traits::Grid Grid; 275 276 /** \brief type of the index set */ 277 typedef typename Traits :: IndexSet IndexSet; 278 279 /** \brief type of the intersection */ 280 typedef typename Traits :: Intersection Intersection; 281 282 /** \brief type of the intersection iterator */ 283 typedef typename Traits :: IntersectionIterator IntersectionIterator; 284 285 /** \brief type of the collective communication */ 286 typedef typename Traits :: CollectiveCommunication CollectiveCommunication; 287 288 /** \brief Codim Structure */ 289 template< int cd > 290 struct Codim : public Traits :: template Codim<cd> {}; 291 292 enum { conforming = Traits :: conforming }; 293 294 public: ALU3dLeafGridView(const Grid & grid)295 ALU3dLeafGridView ( const Grid &grid ) 296 : grid_( &grid ) 297 {} 298 299 /** \brief obtain a const reference to the underlying hierarchic grid */ grid() const300 const Grid &grid () const 301 { 302 assert( grid_ ); 303 return *grid_; 304 } 305 306 /** \brief obtain the index set */ indexSet() const307 const IndexSet &indexSet () const 308 { 309 return grid().leafIndexSet(); 310 } 311 312 /** \brief obtain number of entities in a given codimension */ size(int codim) const313 int size ( int codim ) const 314 { 315 return grid().size( codim ); 316 } 317 318 /** \brief obtain number of entities with a given geometry type */ size(const GeometryType & type) const319 int size ( const GeometryType &type ) const 320 { 321 return grid().size( type ); 322 } 323 324 /** \brief obtain begin iterator for this view */ 325 template< int cd > begin() const326 typename Codim< cd > :: Iterator begin () const 327 { 328 return grid().template leafbegin< cd, pitype >(); 329 } 330 331 /** \brief obtain begin iterator for this view */ 332 template< int cd, PartitionIteratorType pit > begin() const333 typename Codim< cd > :: template Partition< pit > :: Iterator begin () const 334 { 335 return grid().template leafbegin< cd, pit >(); 336 } 337 338 /** \brief obtain end iterator for this view */ 339 template< int cd > end() const340 typename Codim< cd > :: Iterator end () const 341 { 342 return grid().template leafend< cd, pitype >(); 343 } 344 345 /** \brief obtain end iterator for this view */ 346 template< int cd, PartitionIteratorType pit > end() const347 typename Codim< cd > :: template Partition< pit > :: Iterator end () const 348 { 349 return grid().template leafend< cd, pit >(); 350 } 351 352 /** \brief obtain begin intersection iterator with respect to this view */ 353 IntersectionIterator ibegin(const typename Codim<0>::Entity & entity) const354 ibegin ( const typename Codim< 0 > :: Entity &entity ) const 355 { 356 return grid().ileafbegin( entity ); 357 } 358 359 /** \brief obtain end intersection iterator with respect to this view */ 360 IntersectionIterator iend(const typename Codim<0>::Entity & entity) const361 iend ( const typename Codim< 0 > :: Entity &entity ) const 362 { 363 return grid().ileafend( entity ); 364 } 365 366 /** \brief obtain collective communication object */ comm() const367 const CollectiveCommunication &comm () const 368 { 369 return grid().comm(); 370 } 371 372 /** \brief Return size of the overlap region for a given codim on the grid view. */ overlapSize(int codim) const373 int overlapSize(int codim) const 374 { 375 return grid().overlapSize(codim); 376 } 377 378 /** \brief Return size of the ghost region for a given codim on the grid view. */ ghostSize(int codim) const379 int ghostSize(int codim) const 380 { 381 return grid().ghostSize(codim); 382 } 383 384 /** communicate data on this view */ 385 template< class DataHandle, class Data > communicate(CommDataHandleIF<DataHandle,Data> & data,InterfaceType iftype,CommunicationDirection dir) const386 typename Grid::LeafCommunication communicate ( CommDataHandleIF< DataHandle, Data > &data, 387 InterfaceType iftype, 388 CommunicationDirection dir ) const 389 { 390 return grid().communicate( data, iftype, dir ); 391 } 392 393 template< int cd > twists(GeometryType type) const394 typename Codim< cd >::Twists twists ( GeometryType type ) const 395 { 396 return grid().template twists< cd >( type ); 397 } 398 399 private: 400 const Grid *grid_; 401 }; 402 403 } // namespace Dune 404 405 #endif // #ifndef DUNE_ALUGRID_3D_GRIDVIEW_HH 406