dune-grid  2.3beta2
geometrygrid/gridview.hh
Go to the documentation of this file.
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_GEOGRID_GRIDVIEW_HH
4 #define DUNE_GEOGRID_GRIDVIEW_HH
5 
6 #include <dune/common/typetraits.hh>
7 #include <dune/common/exceptions.hh>
8 
16 
17 namespace Dune
18 {
19 
20  namespace GeoGrid
21  {
22 
23  // Internal Forward Declarations
24  // -----------------------------
25 
26  template< class HGV, class CoordFunction, class Allocator, PartitionIteratorType pitype >
27  class GridView;
28 
29 
30 
31  // GridViewTraits
32  // --------------
33 
34  template< class HGV, class CoordFunction, class Allocator, PartitionIteratorType pitype >
36  {
37  friend class GridView< HGV, CoordFunction, Allocator, pitype >;
38 
39  typedef HGV HostGridView;
40 
41  typedef typename HostGridView::Grid HostGrid;
42  typedef typename HostGridView::Intersection HostIntersection;
43  typedef typename HostGridView::IntersectionIterator HostIntersectionIterator;
44 
45  public:
47 
49 
51 
53 
57 
58  typedef typename HostGridView::CollectiveCommunication CollectiveCommunication;
59 
60  template< int codim >
61  struct Codim
62  {
65 
66  typedef typename Grid::Traits::template Codim< codim >::Entity Entity;
67  typedef typename Grid::Traits::template Codim< codim >::EntityPointer EntityPointer;
68 
69  typedef typename Grid::template Codim< codim >::Geometry Geometry;
70  typedef typename Grid::template Codim< codim >::LocalGeometry LocalGeometry;
71 
72  template< PartitionIteratorType pit >
73  struct Partition
74  {
77  };
78  };
79 
80  static const bool conforming = HostGridView::conforming;
81  };
82 
83 
84 
85  // GridView
86  // --------
87 
88  template< class HGV, class CoordFunction, class Allocator, PartitionIteratorType pitype >
89  class GridView
90  {
92 
93  public:
95 
96  typedef typename Traits::HostGridView HostGridView;
97 
98  typedef typename Traits::Grid Grid;
99 
100  typedef typename Traits::IndexSet IndexSet;
101 
103 
105 
107 
108  template< int codim >
109  struct Codim
110  : public Traits::template Codim< codim >
111  {};
112 
113  static const bool conforming = Traits::conforming;
114 
116  : grid_( &grid ),
117  hostGridView_( hostGridView )
118  {}
119 
120  const Grid &grid () const
121  {
122  assert( grid_ );
123  return *grid_;
124  }
125 
126  const IndexSet &indexSet () const
127  {
128  if( !indexSet_ )
129  indexSet_ = IndexSet( hostGridView().indexSet() );
130  return indexSet_;
131  }
132 
133  int size ( int codim ) const
134  {
135  return hostGridView().size( codim );
136  }
137 
138  int size ( const GeometryType &type ) const
139  {
140  return hostGridView().size( type );
141  }
142 
143  template< int codim >
144  typename Codim< codim >::Iterator begin () const
145  {
146  typedef typename Traits::template Codim< codim >::template Partition< pitype >::IteratorTraits IteratorTraits;
147  return GeoGrid::Iterator< IteratorTraits >( grid(), hostGridView(), IteratorTraits::begin );
148  }
149 
150  template< int codim, PartitionIteratorType pit >
151  typename Codim< codim >::template Partition< pit >::Iterator begin () const
152  {
153  typedef typename Traits::template Codim< codim >::template Partition< pit >::IteratorTraits IteratorTraits;
154  return GeoGrid::Iterator< IteratorTraits >( grid(), hostGridView(), IteratorTraits::begin );
155  }
156 
157  template< int codim >
158  typename Codim< codim >::Iterator end () const
159  {
160  typedef typename Traits::template Codim< codim >::template Partition< pitype >::IteratorTraits IteratorTraits;
161  return GeoGrid::Iterator< IteratorTraits >( grid(), hostGridView(), IteratorTraits::end );
162  }
163 
164  template< int codim, PartitionIteratorType pit >
165  typename Codim< codim >::template Partition< pit >::Iterator end () const
166  {
167  typedef typename Traits::template Codim< codim >::template Partition< pit >::IteratorTraits IteratorTraits;
168  return GeoGrid::Iterator< IteratorTraits >( grid(), hostGridView(), IteratorTraits::end );
169  }
170 
171  IntersectionIterator ibegin ( const typename Codim< 0 >::Entity &entity ) const
172  {
174  return IntersectionIteratorImpl( entity, hostGridView().ibegin( Grid::getRealImplementation( entity ).hostEntity() ) );
175  }
176 
177  IntersectionIterator iend ( const typename Codim< 0 >::Entity &entity ) const
178  {
180  return IntersectionIteratorImpl( entity, hostGridView().iend( Grid::getRealImplementation( entity ).hostEntity() ) );
181  }
182 
184  {
185  return hostGridView().comm();
186  }
187 
188  int overlapSize ( int codim ) const
189  {
190  return hostGridView().overlapSize( codim );
191  }
192 
193  int ghostSize ( int codim ) const
194  {
195  return hostGridView().ghostSize( codim );
196  }
197 
198  template< class DataHandle, class Data >
200  InterfaceType interface,
201  CommunicationDirection direction ) const
202  {
203  typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
204  typedef GeoGrid::CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
205 
206  WrappedDataHandle wrappedDataHandle( grid(), dataHandle );
207  hostGridView().communicate( wrappedDataHandle, interface, direction );
208  }
209 
210  const HostGridView &hostGridView () const { return hostGridView_; }
211 
212  private:
213  const Grid *grid_;
214  HostGridView hostGridView_;
215  mutable IndexSet indexSet_;
216  };
217 
218  } // namespace GeoGrid
219 
220 } // namespace Dune
221 
222 #endif // #ifndef DUNE_GEOGRID_GRIDVIEW_HH