dune-grid  2.3beta2
onedgrid.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_ONE_D_GRID_HH
4 #define DUNE_ONE_D_GRID_HH
5 
6 #include <vector>
7 #include <list>
8 
9 #include <dune/common/parallel/collectivecommunication.hh>
10 #include <dune/common/tuples.hh>
11 
13 #include <dune/grid/common/grid.hh>
15 
16 #include <dune/geometry/genericgeometry/topologytypes.hh>
17 
22 #include "onedgrid/onedgridlist.hh"
23 #include "onedgrid/nulliteratorfactory.hh"
24 #include "onedgrid/onedgridentity.hh"
25 #include "onedgrid/onedgridentitypointer.hh"
26 #include "onedgrid/onedgridentityseed.hh"
27 #include "onedgrid/onedgridgeometry.hh"
28 #include "onedgrid/onedgridintersections.hh"
29 #include "onedgrid/onedgridintersectioniterators.hh"
30 #include "onedgrid/onedgridleveliterator.hh"
31 #include "onedgrid/onedgridleafiterator.hh"
32 #include "onedgrid/onedgridhieriterator.hh"
33 #include "onedgrid/onedgridindexsets.hh"
34 
35 namespace Dune {
36 
37  class OneDGrid;
38 
39  template<int dim, int dimw>
41  {
42  typedef GridTraits<dim,dimw,Dune::OneDGrid,
43  OneDGridGeometry,
44  OneDGridEntity,
45  OneDGridEntityPointer,
46  OneDGridLevelIterator,
47  OneDGridLeafIntersection,
48  OneDGridLevelIntersection,
49  OneDGridLeafIntersectionIterator,
50  OneDGridLevelIntersectionIterator,
51  OneDGridHierarchicIterator,
52  OneDGridLeafIterator,
53  OneDGridLevelIndexSet<const OneDGrid>,
54  OneDGridLeafIndexSet<const OneDGrid>,
55  OneDGridIdSet<const OneDGrid>,
56  unsigned int,
57  OneDGridIdSet<const OneDGrid>,
58  unsigned int,
59  CollectiveCommunication<Dune::OneDGrid>,
62  OneDGridEntitySeed>
64  };
65 
66  //**********************************************************************
67  //
68  // --OneDGrid
69  //
70  //**********************************************************************
71 
83  class OneDGrid : public GridDefaultImplementation <1, 1,double,OneDGridFamily<1,1> >
84  {
85  // Grid and world dimension are hardwired in this grid
86  enum {dim = 1};
87  enum {dimworld = 1};
88 
89  template <int, class >
90  friend class OneDGridEntityPointer;
91 
92  template <int , PartitionIteratorType, class >
93  friend class OneDGridLevelIterator;
94 
95  friend class OneDGridHierarchicIterator<const OneDGrid>;
96 
97  template <int codim_, int dim_, class GridImp_>
98  friend class OneDGridEntity;
99  friend class OneDGridHierarchicIterator<OneDGrid>;
100  friend class OneDGridLeafIntersection<const OneDGrid>;
101  friend class OneDGridLevelIntersection<const OneDGrid>;
102  friend class OneDGridLeafIntersectionIterator<const OneDGrid>;
103  friend class OneDGridLevelIntersectionIterator<const OneDGrid>;
104 
105  friend class OneDGridLevelIndexSet<const OneDGrid>;
106  friend class OneDGridLeafIndexSet<const OneDGrid>;
107  friend class OneDGridIdSet<const OneDGrid>;
108 
109  template <int codim_, PartitionIteratorType PiType_, class GridImp_>
110  friend class OneDGridLeafIterator;
111 
112  template <class GridType_>
113  friend class GridFactory;
114 
115  template<int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
116  friend class Entity;
117 
119  OneDGrid();
120 
121  // **********************************************************
122  // The Interface Methods
123  // **********************************************************
124 
125  public:
126 
133  typedef double ctype;
134 
137 
138  //Provides the standard grid types
140 
142  OneDGrid(const std::vector<ctype>& coords);
143 
145  OneDGrid(int numElements, const ctype& leftBoundary, const ctype& rightBoundary);
146 
148  ~OneDGrid();
149 
154  int maxLevel() const {return entityImps_.size()-1;}
155 
157  template<int codim>
158  typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const;
159 
161  template<int codim>
162  typename Traits::template Codim<codim>::LevelIterator lend (int level) const;
163 
165  template<int codim, PartitionIteratorType PiType>
166  typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
167 
169  template<int codim, PartitionIteratorType PiType>
170  typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const;
171 
173  template<int codim>
174  typename Traits::template Codim<codim>::LeafIterator leafbegin () const;
175 
177  template<int codim>
178  typename Traits::template Codim<codim>::LeafIterator leafend () const;
179 
181  template<int codim, PartitionIteratorType PiType>
182  typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const;
183 
185  template<int codim, PartitionIteratorType PiType>
186  typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const;
187 
189  template <typename Seed>
190  static typename Traits::template Codim<Seed::codimension>::EntityPointer
191  entityPointer(const Seed& seed)
192  {
193  enum {codim = Seed::codimension};
194  return typename Traits::template Codim<codim>::EntityPointer(OneDGridEntityPointer<codim,const OneDGrid>(OneDGrid::getRealImplementation(seed).target()));
195  }
196 
197 
200  int size (int level, int codim) const {
201  if (codim<0 || codim>1)
202  DUNE_THROW(GridError, "There are no codim " << codim << " entities in a OneDGrid!");
203 
204  if (codim==0)
205  return elements(level).size();
206 
207  return vertices(level).size();
208  }
209 
210 
211 
213  int size (int codim) const
214  {
215  return leafIndexSet().size(codim);
216  }
217 
219  int size (int level, GeometryType type) const
220  {
221  // There is only one type for each codim
222  return size(level,1-type.dim());
223  }
224 
226  int size (GeometryType type) const
227  {
228  return leafIndexSet().size(type);
229  }
230 
236  size_t numBoundarySegments() const
237  {
238  return 2;
239  }
240 
243  int overlapSize(int codim) const {
244  return 0;
245  }
246 
249  int ghostSize(int codim) const {
250  return 0;
251  }
252 
255  int overlapSize(int level, int codim) const {
256  return 0;
257  }
258 
261  int ghostSize(int level, int codim) const {
262  return 0;
263  }
264 
267  {
268  return idSet_;
269  }
270 
273  {
274  return idSet_;
275  }
276 
278  const Traits::LevelIndexSet& levelIndexSet(int level) const
279  {
280  if (! levelIndexSets_[level]) {
281  levelIndexSets_[level] =
282  new OneDGridLevelIndexSet<const OneDGrid>(*this, level);
283  levelIndexSets_[level]->update();
284  }
285 
286  return * levelIndexSets_[level];
287  }
288 
291  {
292  return leafIndexSet_;
293  }
294 
295 
303  bool mark(int refCount, const Traits::Codim<0>::Entity& e );
304 
311  int getMark(const Traits::Codim<0>::Entity& e ) const;
312 
314  bool preAdapt();
315 
317  bool adapt();
318 
320  void postAdapt();
321 
322  // **********************************************************
323  // End of Interface Methods
324  // **********************************************************
325 
332  };
333 
336  refinementType_ = type;
337  }
338 
344  void globalRefine(int refCount);
345 
346  // dummy parallel functions
347 
348  template<class DataHandle>
349  void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
350  {}
351 
352  template<class DataHandle>
353  void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
354  {}
355 
357  {
358  return ccobj;
359  }
360 
361 
362  private:
363 
365  OneDGridList<OneDEntityImp<0> >& vertices(int level) {
366  return Dune::get<0>(entityImps_[level]);
367  }
368 
370  const OneDGridList<OneDEntityImp<0> >& vertices(int level) const {
371  return Dune::get<0>(entityImps_[level]);
372  }
373 
375  OneDGridList<OneDEntityImp<1> >& elements(int level) {
376  return Dune::get<1>(entityImps_[level]);
377  }
378 
380  const OneDGridList<OneDEntityImp<1> >& elements(int level) const {
381  return Dune::get<1>(entityImps_[level]);
382  }
383 
385 
387  void setIndices();
388 
389  unsigned int getNextFreeId(int codim) {
390  return (codim==0) ? freeElementIdCounter_++ : freeVertexIdCounter_++;
391  }
392 
394  RefinementType refinementType_;
395 
396  OneDGridList<OneDEntityImp<0> >::iterator getLeftUpperVertex(const OneDEntityImp<1>* eIt);
397 
398  OneDGridList<OneDEntityImp<0> >::iterator getRightUpperVertex(const OneDEntityImp<1>* eIt);
399 
403  OneDGridList<OneDEntityImp<1> >::iterator getLeftNeighborWithSon(OneDGridList<OneDEntityImp<1> >::iterator eIt);
404 
405  // The vertices and elements of the grid hierarchy
406  std::vector<tuple<OneDGridList<OneDEntityImp<0> >,
407  OneDGridList<OneDEntityImp<1> > > > entityImps_;
408 
409  // Our set of level indices
410  mutable std::vector<OneDGridLevelIndexSet<const OneDGrid>* > levelIndexSets_;
411 
413 
415 
416  unsigned int freeVertexIdCounter_;
417 
418  unsigned int freeElementIdCounter_;
419 
423  bool reversedBoundarySegmentNumbering_;
424 
425  }; // end Class OneDGrid
426 
427  namespace Capabilities
428  {
440  template< >
442  {
443  static const bool v = true;
444  static const unsigned int topologyId = GenericGeometry :: CubeTopology< 1 > :: type :: id ;
445  };
446 
447 
451  template<int cdim>
452  struct hasEntity< OneDGrid, cdim >
453  {
454  static const bool v = true;
455  };
456 
460  template<>
462  {
463  static const bool v = false;
464  };
465 
469  template<>
471  {
472  static const bool v = true;
473  };
474 
478  template<>
480  {
481  static const bool v = true;
482  };
483 
484  }
485 
486 } // namespace Dune
487 
488 // Include the GridFactory specialization for OneDGrid, so everybody
489 // who includes the grid also gets the factory. Since OneDGrid is
490 // not a template class, it needs to be a complete type before
491 // GridFactory<OneDGrid> can be defined. This is why the #include-
492 // directive is at _the end_ of this file.
493 #include <dune/grid/onedgrid/onedgridfactory.hh>
494 
495 
496 #endif