1 #ifndef DUNE_SPHEREGRID_GRIDVIEW_HH 2 #define DUNE_SPHEREGRID_GRIDVIEW_HH 3 4 //- dune-common includes 5 #include <dune/common/typetraits.hh> 6 7 //- dune-grid includes 8 #include <dune/grid/common/capabilities.hh> 9 #include <dune/grid/common/gridview.hh> 10 11 //- dune-metagrid includes 12 #include <dune/grid/spheregrid/datahandle.hh> 13 #include <dune/grid/spheregrid/indexset.hh> 14 #include <dune/grid/spheregrid/intersection.hh> 15 #include <dune/grid/spheregrid/intersectioniterator.hh> 16 #include <dune/grid/spheregrid/iterator.hh> 17 18 namespace Dune 19 { 20 21 // Internal Forward Declarations 22 // ----------------------------- 23 24 template< class HostGridView, class MapToSphere > 25 class SphereGridView; 26 27 28 29 // SphereGridViewTraits 30 // -------------------- 31 32 template< class HGV, class MapToSphere > 33 class SphereGridViewTraits 34 { 35 friend class SphereGridView< HGV, MapToSphere >; 36 37 typedef HGV HostGridView; 38 39 typedef typename HostGridView::Grid HostGrid; 40 41 public: 42 typedef SphereGridView< HostGridView, MapToSphere > GridViewImp; 43 44 typedef SphereGrid< HostGrid, MapToSphere > Grid; 45 46 typedef SphereGridIndexSet< const Grid, typename HostGridView::IndexSet > IndexSet; 47 48 typedef SphereGridIntersection< const Grid, typename HostGridView::Intersection > IntersectionImpl; 49 typedef Dune::Intersection< const Grid, IntersectionImpl > Intersection; 50 51 typedef SphereGridIntersectionIterator< const Grid, typename HostGridView::IntersectionIterator > IntersectionIteratorImpl; 52 typedef Dune::IntersectionIterator< const Grid, IntersectionIteratorImpl, IntersectionImpl > IntersectionIterator; 53 54 typedef typename HostGridView::CollectiveCommunication CollectiveCommunication; 55 56 template< int codim > 57 struct Codim 58 { 59 typedef typename Grid::Traits::template Codim< codim >::Entity Entity; 60 61 typedef typename Grid::template Codim< codim >::Geometry Geometry; 62 typedef typename Grid::template Codim< codim >::LocalGeometry LocalGeometry; 63 64 template< PartitionIteratorType pitype > 65 struct Partition 66 { 67 typedef typename HostGridView::template Codim< codim >::template Partition< pitype > HostPartition; 68 69 typedef SphereGridIterator< const Grid, typename HostPartition::Iterator > IteratorImpl; 70 typedef Dune::EntityIterator< codim, const Grid, IteratorImpl > Iterator; 71 }; 72 73 typedef typename Partition< All_Partition >::Iterator Iterator; 74 }; 75 76 static const bool conforming = HostGridView::conforming; 77 }; 78 79 80 81 // SphereGridView 82 // -------------- 83 84 template< class HGV, class MapToSphere > 85 class SphereGridView 86 { 87 typedef SphereGridView< HGV, MapToSphere > This; 88 89 public: 90 typedef SphereGridViewTraits< HGV, MapToSphere > Traits; 91 92 typedef typename Traits::HostGridView HostGridView; 93 94 typedef typename Traits::Grid Grid; 95 96 typedef typename Traits::IndexSet IndexSet; 97 98 typedef typename Traits::Intersection Intersection; 99 100 typedef typename Traits::IntersectionIterator IntersectionIterator; 101 102 typedef typename Traits::CollectiveCommunication CollectiveCommunication; 103 104 template< int codim > 105 struct Codim 106 : public Traits::template Codim< codim > 107 {}; 108 109 static const bool conforming = Traits::conforming; 110 SphereGridView(const Grid & grid,const HostGridView & hostGridView)111 SphereGridView ( const Grid &grid, const HostGridView &hostGridView ) 112 : grid_( &grid ), 113 hostGridView_( hostGridView ) 114 {} 115 grid() const116 const Grid &grid () const 117 { 118 assert( grid_ ); 119 return *grid_; 120 } 121 indexSet() const122 const IndexSet &indexSet () const 123 { 124 if( !indexSet_ ) 125 indexSet_ = IndexSet( hostGridView().indexSet() ); 126 return indexSet_; 127 } 128 size(int codim) const129 int size ( int codim ) const 130 { 131 return hostGridView().size( codim ); 132 } 133 size(const GeometryType & type) const134 int size ( const GeometryType &type ) const 135 { 136 return hostGridView().size( type ); 137 } 138 139 template< int codim > begin() const140 typename Codim< codim >::Iterator begin () const 141 { 142 return begin< codim, All_Partition >(); 143 } 144 145 template< int codim, PartitionIteratorType pitype > begin() const146 typename Codim< codim >::template Partition< pitype >::Iterator begin () const 147 { 148 typedef typename Traits::template Codim< codim >::template Partition< pitype >::IteratorImpl Impl; 149 return Impl( hostGridView().template begin< codim, pitype >(), mapToSphere() ); 150 } 151 152 template< int codim > end() const153 typename Codim< codim >::Iterator end () const 154 { 155 return end< codim, All_Partition >(); 156 } 157 158 template< int codim, PartitionIteratorType pitype > end() const159 typename Codim< codim >::template Partition< pitype >::Iterator end () const 160 { 161 typedef typename Traits::template Codim< codim >::template Partition< pitype >::IteratorImpl Impl; 162 return Impl( hostGridView().template end< codim, pitype >(), mapToSphere() ); 163 } 164 ibegin(const typename Codim<0>::Entity & entity) const165 IntersectionIterator ibegin ( const typename Codim< 0 >::Entity &entity ) const 166 { 167 typedef typename Traits::IntersectionIteratorImpl IntersectionIteratorImpl; 168 return IntersectionIteratorImpl( hostGridView().ibegin( entity.impl().hostEntity() ), mapToSphere() ); 169 } 170 iend(const typename Codim<0>::Entity & entity) const171 IntersectionIterator iend ( const typename Codim< 0 >::Entity &entity ) const 172 { 173 typedef typename Traits::IntersectionIteratorImpl IntersectionIteratorImpl; 174 return IntersectionIteratorImpl( hostGridView().iend( entity.impl().hostEntity() ), mapToSphere() ); 175 } 176 comm() const177 const CollectiveCommunication &comm () const 178 { 179 return hostGridView().comm(); 180 } 181 overlapSize(int codim) const182 int overlapSize ( int codim ) const 183 { 184 return hostGridView().overlapSize( codim ); 185 } 186 ghostSize(int codim) const187 int ghostSize ( int codim ) const 188 { 189 return hostGridView().ghostSize( codim ); 190 } 191 192 template< class DataHandle, class Data > communicate(CommDataHandleIF<DataHandle,Data> & dataHandle,InterfaceType interface,CommunicationDirection direction) const193 void communicate ( CommDataHandleIF< DataHandle, Data > &dataHandle, 194 InterfaceType interface, 195 CommunicationDirection direction ) const 196 { 197 typedef CommDataHandleIF< DataHandle, Data > DataHandleIF; 198 typedef SphereGridDataHandle< DataHandleIF, Grid > WrappedDataHandle; 199 200 WrappedDataHandle wrappedDataHandle( dataHandle, mapToSphere() ); 201 hostGridView().communicate( wrappedDataHandle, interface, direction ); 202 } 203 hostGridView() const204 const HostGridView &hostGridView () const { return hostGridView_; } 205 mapToSphere() const206 const MapToSphere &mapToSphere () const { return grid().mapToSphere(); } 207 208 private: 209 const Grid *grid_; 210 HostGridView hostGridView_; 211 mutable IndexSet indexSet_; 212 }; 213 214 } // namespace Dune 215 216 #endif // #ifndef DUNE_SPHEREGRID_GRIDVIEW_HH 217