AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
DefaultGridView.hpp
1 #pragma once
2 
3 #include <dune/common/typetraits.hh>
4 #include <dune/common/exceptions.hh>
5 
6 #include <dune/grid/common/capabilities.hh>
7 #include <dune/grid/common/gridview.hh>
8 
9 namespace AMDiS
10 {
11  /*
12  * NOTE: this is a modification of dune/grid/common/defaultgridview.hh since we
13  * want all implementation specific methods to be put into the grid class and not
14  * into the entity class. See ibegin(), iend().
15  */
16 
17  template <class GridImp>
19 
20  template <class GridImp>
22 
23 
24  template <class GridImp>
26  {
28 
30  using Grid = std::remove_const_t<GridImp>;
31 
33  using IndexSet = typename Grid::Traits::LevelIndexSet;
34 
36  using Intersection = typename Grid::Traits::LevelIntersection;
37 
39  using IntersectionIterator = typename Grid::Traits::LevelIntersectionIterator;
40 
42  using CollectiveCommunication = typename Grid::Traits::CollectiveCommunication;
43 
44  template <int cd>
45  struct Codim
46  {
47  using Entity = typename Grid::Traits::template Codim<cd>::Entity;
48  using Geometry = typename Grid::template Codim<cd>::Geometry;
49  using LocalGeometry = typename Grid::template Codim<cd>::LocalGeometry;
50 
52  template <Dune::PartitionIteratorType pit>
53  struct Partition
54  {
57  };
58 
60  };
61 
62  enum { conforming = Dune::Capabilities::isLevelwiseConforming<Grid>::v };
63  };
64 
65 
66  template <class GridImp>
68  {
69  public:
71  using Grid = typename Traits::Grid;
72  using IndexSet = typename Traits::IndexSet;
73  using Intersection = typename Traits::Intersection;
74  using IntersectionIterator = typename Traits::IntersectionIterator;
75  using CollectiveCommunication = typename Traits::CollectiveCommunication;
76 
77  template <int cd>
78  using Codim = typename Traits::template Codim<cd>;
79 
80  enum { conforming = Traits::conforming };
81 
82  public:
83  DefaultLevelGridView(Grid const& grid, int level)
84  : grid_(&grid)
85  , level_(level)
86  {}
87 
89  Grid const& grid() const
90  {
91  assert(grid_);
92  return *grid_;
93  }
94 
96  IndexSet const& indexSet() const
97  {
98  return grid().levelIndexSet(level_);
99  }
100 
102  int size(int codim) const
103  {
104  return grid().size(level_, codim);
105  }
106 
108  int size(Dune::GeometryType const& type) const
109  {
110  return grid().size(level_, type);
111  }
112 
114  template <int cd, Dune::PartitionIteratorType pit = Dune::All_Partition>
115  typename Codim<cd>::template Partition<pit>::Iterator begin() const
116  {
117  return grid().template lbegin<cd, pit>(level_);
118  }
119 
121  template <int cd, Dune::PartitionIteratorType pit = Dune::All_Partition>
122  typename Codim<cd>::template Partition<pit>::Iterator end() const
123  {
124  return grid().template lend<cd, pit>(level_);
125  }
126 
128  IntersectionIterator ibegin(typename Codim<0>::Entity const& entity) const
129  {
130  return grid().ilevelbegin(entity);
131  }
132 
134  IntersectionIterator iend(typename Codim<0>::Entity const& entity) const
135  {
136  return grid().ilevelend(entity);
137  }
138 
140  CollectiveCommunication const& comm() const
141  {
142  return grid().comm();
143  }
144 
146  int overlapSize(int codim) const
147  {
148  return grid().overlapSize(level_, codim);
149  }
150 
152  int ghostSize(int codim) const
153  {
154  return grid().ghostSize(level_, codim);
155  }
156 
158  template <class DataHandleImp, class DataType>
159  void communicate(Dune::CommDataHandleIF<DataHandleImp, DataType>& data,
160  Dune::InterfaceType iftype,
161  Dune::CommunicationDirection dir) const
162  {
163  return grid().communicate(data, iftype, dir, level_);
164  }
165 
166  private:
167  Grid const* grid_;
168  int level_;
169  };
170 
171 
172  template <class GridImp>
174  {
176 
178  using Grid = std::remove_const_t<GridImp>;
179 
181  using IndexSet = typename Grid::Traits::LeafIndexSet;
182 
184  using Intersection = typename Grid::Traits::LeafIntersection;
185 
187  using IntersectionIterator = typename Grid::Traits::LeafIntersectionIterator;
188 
190  using CollectiveCommunication = typename Grid::Traits::CollectiveCommunication;
191 
192  template <int cd>
193  struct Codim
194  {
195  using Entity = typename Grid::Traits::template Codim<cd>::Entity;
196  using Geometry = typename Grid::template Codim<cd>::Geometry;
197  using LocalGeometry = typename Grid::template Codim<cd>::LocalGeometry;
198 
200  template <Dune::PartitionIteratorType pit>
201  struct Partition
202  {
205  };
206 
208  };
209 
210  enum { conforming = Dune::Capabilities::isLeafwiseConforming<Grid>::v };
211  };
212 
213 
214  template <class GridImp>
215  class DefaultLeafGridView
216  {
217  public:
219  using Grid = typename Traits::Grid;
220  using IndexSet = typename Traits::IndexSet;
221  using Intersection = typename Traits::Intersection;
222  using IntersectionIterator = typename Traits::IntersectionIterator;
223  using CollectiveCommunication = typename Traits::CollectiveCommunication;
224 
225  template <int cd>
226  using Codim = typename Traits::template Codim<cd>;
227 
228  enum { conforming = Traits::conforming };
229 
230  public:
231  DefaultLeafGridView(Grid const& grid)
232  : grid_(&grid)
233  {}
234 
236  Grid const& grid() const
237  {
238  assert(grid_);
239  return *grid_;
240  }
241 
243  IndexSet const& indexSet() const
244  {
245  return grid().leafIndexSet();
246  }
247 
249  int size(int codim) const
250  {
251  return grid().size(codim);
252  }
253 
255  int size(Dune::GeometryType const& type) const
256  {
257  return grid().size(type);
258  }
259 
260 
262  template <int cd, Dune::PartitionIteratorType pit = Dune::All_Partition>
263  typename Codim<cd>::template Partition<pit>::Iterator begin() const
264  {
265  return grid().template leafbegin<cd, pit>();
266  }
267 
269  template <int cd, Dune::PartitionIteratorType pit = Dune::All_Partition>
270  typename Codim<cd>::template Partition<pit>::Iterator end() const
271  {
272  return grid().template leafend<cd, pit>();
273  }
274 
276  IntersectionIterator ibegin(typename Codim<0>::Entity const& entity) const
277  {
278  return grid().ileafbegin(entity);
279  }
280 
282  IntersectionIterator iend(typename Codim<0>::Entity const& entity) const
283  {
284  return grid().ileafend(entity);
285  }
286 
288  CollectiveCommunication const& comm() const
289  {
290  return grid().comm();
291  }
292 
294  int overlapSize(int codim) const
295  {
296  return grid().overlapSize(codim);
297  }
298 
300  int ghostSize(int codim) const
301  {
302  return grid().ghostSize(codim);
303  }
304 
306  template <class DataHandleImp, class DataType>
307  void communicate(Dune::CommDataHandleIF<DataHandleImp, DataType>& data,
308  Dune::InterfaceType iftype,
309  Dune::CommunicationDirection dir) const
310  {
311  return grid().communicate(data, iftype, dir);
312  }
313 
314  private:
315  Grid const* grid_;
316  };
317 
318 } // end namespace AMDiS
std::remove_const_t< GridImp > Grid
type of the grid
Definition: DefaultGridView.hpp:178
Definition: DefaultGridView.hpp:25
Definition: DefaultGridView.hpp:21
Definition: DefaultGridView.hpp:45
typename Grid::Traits::CollectiveCommunication CollectiveCommunication
type of the collective communication
Definition: DefaultGridView.hpp:190
typename Grid::Traits::LeafIntersection Intersection
type of the intersection
Definition: DefaultGridView.hpp:184
Codim< cd >::template Partition< pit >::Iterator end() const
Obtain end iterator for this view.
Definition: DefaultGridView.hpp:122
int size(int codim) const
Obtain number of entities in a given codimension.
Definition: DefaultGridView.hpp:249
CollectiveCommunication const & comm() const
Obtain collective communication object.
Definition: DefaultGridView.hpp:140
int ghostSize(int codim) const
Return size of the ghost region for a given codim on the grid view.
Definition: DefaultGridView.hpp:300
Codim< cd >::template Partition< pit >::Iterator begin() const
Obtain begin iterator for this view.
Definition: DefaultGridView.hpp:263
int overlapSize(int codim) const
Return size of the overlap region for a given codim on the grid view.
Definition: DefaultGridView.hpp:294
IndexSet const & indexSet() const
Obtain the index set.
Definition: DefaultGridView.hpp:96
Grid const & grid() const
Obtain a const reference to the underlying hierarchic grid.
Definition: DefaultGridView.hpp:89
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
IntersectionIterator iend(typename Codim< 0 >::Entity const &entity) const
Obtain end intersection iterator with respect to this view.
Definition: DefaultGridView.hpp:282
typename Grid::Traits::LevelIntersectionIterator IntersectionIterator
type of the intersection iterator
Definition: DefaultGridView.hpp:39
int ghostSize(int codim) const
Return size of the ghost region for a given codim on the grid view.
Definition: DefaultGridView.hpp:152
Codim< cd >::template Partition< pit >::Iterator begin() const
Obtain begin iterator for this view.
Definition: DefaultGridView.hpp:115
IntersectionIterator iend(typename Codim< 0 >::Entity const &entity) const
Obtain end intersection iterator with respect to this view.
Definition: DefaultGridView.hpp:134
int size(Dune::GeometryType const &type) const
Obtain number of entities with a given geometry type.
Definition: DefaultGridView.hpp:255
Define types needed to iterate over entities of a given partition type.
Definition: DefaultGridView.hpp:53
std::remove_const_t< GridImp > Grid
type of the grid
Definition: DefaultGridView.hpp:30
IntersectionIterator ibegin(typename Codim< 0 >::Entity const &entity) const
Obtain begin intersection iterator with respect to this view.
Definition: DefaultGridView.hpp:128
Definition: DefaultGridView.hpp:193
Define types needed to iterate over entities of a given partition type.
Definition: DefaultGridView.hpp:201
Definition: DefaultGridView.hpp:18
typename Grid::Traits::LevelIndexSet IndexSet
type of the index set
Definition: DefaultGridView.hpp:33
typename Grid::Traits::LeafIndexSet IndexSet
type of the index set
Definition: DefaultGridView.hpp:181
IndexSet const & indexSet() const
Obtain the index set.
Definition: DefaultGridView.hpp:243
typename Grid::Traits::LeafIntersectionIterator IntersectionIterator
type of the intersection iterator
Definition: DefaultGridView.hpp:187
typename Grid::Traits::CollectiveCommunication CollectiveCommunication
type of the collective communication
Definition: DefaultGridView.hpp:42
typename Grid::template Codim< cd >::template Partition< pit >::LevelIterator Iterator
iterator over a given codim and partition type
Definition: DefaultGridView.hpp:56
Codim< cd >::template Partition< pit >::Iterator end() const
Obtain end iterator for this view.
Definition: DefaultGridView.hpp:270
Grid const & grid() const
obtain a const reference to the underlying hierarchic grid
Definition: DefaultGridView.hpp:236
void communicate(Dune::CommDataHandleIF< DataHandleImp, DataType > &data, Dune::InterfaceType iftype, Dune::CommunicationDirection dir) const
Communicate data on this view.
Definition: DefaultGridView.hpp:307
IntersectionIterator ibegin(typename Codim< 0 >::Entity const &entity) const
Obtain begin intersection iterator with respect to this view.
Definition: DefaultGridView.hpp:276
void communicate(Dune::CommDataHandleIF< DataHandleImp, DataType > &data, Dune::InterfaceType iftype, Dune::CommunicationDirection dir) const
Communicate data on this view.
Definition: DefaultGridView.hpp:159
int size(Dune::GeometryType const &type) const
Obtain number of entities with a given geometry type.
Definition: DefaultGridView.hpp:108
typename Grid::template Codim< cd >::template Partition< pit >::LeafIterator Iterator
iterator over a given codim and partition type
Definition: DefaultGridView.hpp:204
int size(int codim) const
Obtain number of entities in a given codimension.
Definition: DefaultGridView.hpp:102
typename Grid::Traits::LevelIntersection Intersection
type of the intersection
Definition: DefaultGridView.hpp:36
CollectiveCommunication const & comm() const
Obtain collective communication object.
Definition: DefaultGridView.hpp:288
Definition: DefaultGridView.hpp:173
int overlapSize(int codim) const
Return size of the overlap region for a given codim on the grid view.
Definition: DefaultGridView.hpp:146