dune-grid  2.2.1
onedgrid.hh
Go to the documentation of this file.
1 #ifndef DUNE_ONE_D_GRID_HH
2 #define DUNE_ONE_D_GRID_HH
3 
4 #include <vector>
5 #include <list>
6 
7 #include <dune/common/misc.hh>
8 #include <dune/common/collectivecommunication.hh>
9 #include <dune/common/tuples.hh>
10 
12 #include <dune/grid/common/grid.hh>
14 
15 #include <dune/geometry/genericgeometry/topologytypes.hh>
16 
21 #include "onedgrid/onedgridlist.hh"
22 #include "onedgrid/nulliteratorfactory.hh"
23 #include "onedgrid/onedgridentity.hh"
24 #include "onedgrid/onedgridentitypointer.hh"
25 #include "onedgrid/onedgridentityseed.hh"
26 #include "onedgrid/onedgridgeometry.hh"
27 #include "onedgrid/onedgridintersections.hh"
28 #include "onedgrid/onedgridintersectioniterators.hh"
29 #include "onedgrid/onedgridleveliterator.hh"
30 #include "onedgrid/onedgridleafiterator.hh"
31 #include "onedgrid/onedgridhieriterator.hh"
32 #include "onedgrid/onedgridindexsets.hh"
33 
34 namespace Dune {
35 
36  class OneDGrid;
37 
38 template<int dim, int dimw>
40 {
41  typedef GridTraits<dim,dimw,Dune::OneDGrid,
42  OneDGridGeometry,
43  OneDGridEntity,
44  OneDGridEntityPointer,
45  OneDGridLevelIterator,
46  OneDGridLeafIntersection,
47  OneDGridLevelIntersection,
48  OneDGridLeafIntersectionIterator,
49  OneDGridLevelIntersectionIterator,
50  OneDGridHierarchicIterator,
51  OneDGridLeafIterator,
52  OneDGridLevelIndexSet<const OneDGrid>,
53  OneDGridLeafIndexSet<const OneDGrid>,
54  OneDGridIdSet<const OneDGrid>,
55  unsigned int,
56  OneDGridIdSet<const OneDGrid>,
57  unsigned int,
58  CollectiveCommunication<Dune::OneDGrid>,
61  OneDGridEntitySeed>
63 };
64 
65 //**********************************************************************
66 //
67 // --OneDGrid
68 //
69 //**********************************************************************
70 
81 class OneDGrid : public GridDefaultImplementation <1, 1,double,OneDGridFamily<1,1> >
82 {
83  // Grid and world dimension are hardwired in this grid
84  enum {dim = 1};
85  enum {dimworld = 1};
86 
87  template <int, class >
88  friend class OneDGridEntityPointer;
89 
90  template <int , PartitionIteratorType, class >
91  friend class OneDGridLevelIterator;
92 
93  friend class OneDGridHierarchicIterator<const OneDGrid>;
94 
95  template <int codim_, int dim_, class GridImp_>
96  friend class OneDGridEntity;
97  friend class OneDGridHierarchicIterator<OneDGrid>;
98  friend class OneDGridLeafIntersection<const OneDGrid>;
99  friend class OneDGridLevelIntersection<const OneDGrid>;
100  friend class OneDGridLeafIntersectionIterator<const OneDGrid>;
101  friend class OneDGridLevelIntersectionIterator<const OneDGrid>;
102 
103  friend class OneDGridLevelIndexSet<const OneDGrid>;
104  friend class OneDGridLeafIndexSet<const OneDGrid>;
105  friend class OneDGridIdSet<const OneDGrid>;
106 
107  template <int codim_, PartitionIteratorType PiType_, class GridImp_>
108  friend class OneDGridLeafIterator;
109 
110  template <class GridType_>
111  friend class GridFactory;
112 
113  template<int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
114  friend class Entity;
115 
117  OneDGrid();
118 
119  // **********************************************************
120  // The Interface Methods
121  // **********************************************************
122 
123 public:
124 
131  typedef double ctype;
132 
135 
136  //Provides the standard grid types
138 
140  OneDGrid(const std::vector<ctype>& coords);
141 
143  OneDGrid(int numElements, const ctype& leftBoundary, const ctype& rightBoundary);
144 
146  ~OneDGrid();
147 
152  int maxLevel() const {return entityImps_.size()-1;}
153 
155  template<int codim>
156  typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const;
157 
159  template<int codim>
160  typename Traits::template Codim<codim>::LevelIterator lend (int level) const;
161 
163  template<int codim, PartitionIteratorType PiType>
164  typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
165 
167  template<int codim, PartitionIteratorType PiType>
168  typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const;
169 
171  template<int codim>
172  typename Traits::template Codim<codim>::LeafIterator leafbegin () const;
173 
175  template<int codim>
176  typename Traits::template Codim<codim>::LeafIterator leafend () const;
177 
179  template<int codim, PartitionIteratorType PiType>
180  typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const;
181 
183  template<int codim, PartitionIteratorType PiType>
184  typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const;
185 
187  template <int codim>
188  static typename Traits::template Codim<codim>::EntityPointer
189  entityPointer(const OneDGridEntitySeed<codim, const OneDGrid>& seed)
190  {
191  return typename Traits::template Codim<codim>::EntityPointer(seed.target());
192  }
193 
194 
197  int size (int level, int codim) const {
198  if (codim<0 || codim>1)
199  DUNE_THROW(GridError, "There are no codim " << codim << " entities in a OneDGrid!");
200 
201  if (codim==0)
202  return elements(level).size();
203 
204  return vertices(level).size();
205  }
206 
207 
208 
210  int size (int codim) const
211  {
212  return leafIndexSet().size(codim);
213  }
214 
216  int size (int level, GeometryType type) const
217  {
218  // There is only one type for each codim
219  return size(level,1-type.dim());
220  }
221 
223  int size (GeometryType type) const
224  {
225  return leafIndexSet().size(type);
226  }
227 
233  size_t numBoundarySegments() const
234  {
235  return 2;
236  }
237 
240  int overlapSize(int codim) const {
241  return 0;
242  }
243 
246  int ghostSize(int codim) const {
247  return 0;
248  }
249 
252  int overlapSize(int level, int codim) const {
253  return 0;
254  }
255 
258  int ghostSize(int level, int codim) const {
259  return 0;
260  }
261 
264  {
265  return idSet_;
266  }
267 
270  {
271  return idSet_;
272  }
273 
275  const Traits::LevelIndexSet& levelIndexSet(int level) const
276  {
277  if (! levelIndexSets_[level]) {
278  levelIndexSets_[level] =
279  new OneDGridLevelIndexSet<const OneDGrid>(*this, level);
280  levelIndexSets_[level]->update();
281  }
282 
283  return * levelIndexSets_[level];
284  }
285 
288  {
289  return leafIndexSet_;
290  }
291 
292 
300  bool mark(int refCount, const Traits::Codim<0>::Entity& e );
301 
308  int getMark(const Traits::Codim<0>::Entity& e ) const;
309 
311  bool preAdapt();
312 
314  bool adapt();
315 
317  void postAdapt();
318 
319  // **********************************************************
320  // End of Interface Methods
321  // **********************************************************
322 
329 
332  refinementType_ = type;
333  }
334 
340  void globalRefine(int refCount);
341 
342  // dummy parallel functions
343 
344  template<class DataHandle>
345  void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
346  {
347  }
348 
349  template<class DataHandle>
350  void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
351  {
352  }
353 
355  {
356  return ccobj;
357  }
358 
359 
360 private:
361 
363  OneDGridList<OneDEntityImp<0> >& vertices(int level) {
364  return Dune::get<0>(entityImps_[level]);
365  }
366 
368  const OneDGridList<OneDEntityImp<0> >& vertices(int level) const {
369  return Dune::get<0>(entityImps_[level]);
370  }
371 
373  OneDGridList<OneDEntityImp<1> >& elements(int level) {
374  return Dune::get<1>(entityImps_[level]);
375  }
376 
378  const OneDGridList<OneDEntityImp<1> >& elements(int level) const {
379  return Dune::get<1>(entityImps_[level]);
380  }
381 
383 
385  void setIndices();
386 
387  unsigned int getNextFreeId(int codim) {
388  return (codim==0) ? freeElementIdCounter_++ : freeVertexIdCounter_++;
389  }
390 
392  RefinementType refinementType_;
393 
394  OneDGridList<OneDEntityImp<0> >::iterator getLeftUpperVertex(const OneDEntityImp<1>* eIt);
395 
396  OneDGridList<OneDEntityImp<0> >::iterator getRightUpperVertex(const OneDEntityImp<1>* eIt);
397 
401  OneDGridList<OneDEntityImp<1> >::iterator getLeftNeighborWithSon(OneDGridList<OneDEntityImp<1> >::iterator eIt);
402 
403  // The vertices and elements of the grid hierarchy
404  std::vector<tuple<OneDGridList<OneDEntityImp<0> >,
405  OneDGridList<OneDEntityImp<1> > > > entityImps_;
406 
407  // Our set of level indices
408  mutable std::vector<OneDGridLevelIndexSet<const OneDGrid>* > levelIndexSets_;
409 
411 
413 
414  unsigned int freeVertexIdCounter_;
415 
416  unsigned int freeElementIdCounter_;
417 
421  bool reversedBoundarySegmentNumbering_;
422 
423 }; // end Class OneDGrid
424 
425 namespace Capabilities
426 {
438  template< >
440  {
441  static const bool v = true;
442  static const unsigned int topologyId = GenericGeometry :: CubeTopology< 1 > :: type :: id ;
443  };
444 
445 
449  template<int cdim>
450  struct hasEntity< OneDGrid, cdim >
451  {
452  static const bool v = true;
453  };
454 
458  template<>
460  {
461  static const bool v = false;
462  };
463 
467  template<>
469  {
470  static const bool v = true;
471  };
472 
476  template<>
478  {
479  static const bool v = true;
480  };
481 
482 }
483 
484 } // namespace Dune
485 
486 // Include the GridFactory specialization for OneDGrid, so everybody
487 // who includes the grid also gets the factory. Since OneDGrid is
488 // not a template class, it needs to be a complete type before
489 // GridFactory<OneDGrid> can be defined. This is why the #include-
490 // directive is at _the end_ of this file.
491 #include <dune/grid/onedgrid/onedgridfactory.hh>
492 
493 
494 #endif