dune-grid  2.3.1
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
void setRefinementType(RefinementType type)
Sets the type of grid refinement.
Definition: onedgrid.hh:335
const Traits::GlobalIdSet & globalIdSet() const
Get the set of global ids.
Definition: onedgrid.hh:266
New level consists of the refined elements and the unrefined ones, too.
Definition: onedgrid.hh:331
static ReturnImplementationType< InterfaceType >::ImplementationType & getRealImplementation(InterfaceType &i)
return real implementation of interface class
Definition: common/grid.hh:1223
static const bool v
Definition: common/capabilities.hh:57
Definition: defaultgridview.hh:223
bool adapt()
Triggers the grid refinement process.
friend class OneDGridLevelIndexSet< const OneDGrid >
Definition: onedgrid.hh:105
int size(GeometryType type) const
number of leaf entities per geometry type in this process
Definition: onedgrid.hh:226
New level consists only of the refined elements.
Definition: onedgrid.hh:329
Wrapper class for entities.
Definition: common/entity.hh:56
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
friend class OneDGridLeafIterator
Definition: onedgrid.hh:110
size_t numBoundarySegments() const
Return the number of coarse grid boundary segments.
Definition: onedgrid.hh:236
static const bool v
Definition: common/capabilities.hh:66
Index Set Interface base class.
Definition: common/grid.hh:359
static Traits::template Codim< Seed::codimension >::EntityPointer entityPointer(const Seed &seed)
Create an EntityPointer from an EntitySeed.
Definition: onedgrid.hh:191
OneDGridFamily< dim, dimworld > GridFamily
GridFamily of OneDGrid.
Definition: onedgrid.hh:136
bool mark(int refCount, const Traits::Codim< 0 >::Entity &e)
Mark entity for refinement.
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:263
Provide a generic factory class for unstructured grids.
const Traits::LocalIdSet & localIdSet() const
Get the set of local ids.
Definition: onedgrid.hh:272
GridFamily::Traits::CollectiveCommunication CollectiveCommunication
A type that is a model of Dune::CollectiveCommunication. It provides a portable way for collective co...
Definition: common/grid.hh:543
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:164
void communicate(DataHandle &data, InterfaceType iftype, CommunicationDirection dir, int level) const
Definition: onedgrid.hh:349
void globalRefine(int refCount)
Does one uniform refinement step.
Specialize with 'true' if implementation guarantees conforming level grids. (default=false) ...
Definition: common/capabilities.hh:86
OneDGridFamily< dim, dimworld >::Traits Traits
Definition: onedgrid.hh:139
double ctype
The type used to store coordinates.
Definition: onedgrid.hh:133
friend class OneDGridEntity
Definition: onedgrid.hh:98
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition: onedgrid.hh:219
friend class OneDGridIdSet< const OneDGrid >
Definition: onedgrid.hh:107
void communicate(DataHandle &data, InterfaceType iftype, CommunicationDirection dir) const
Definition: onedgrid.hh:353
Traits::template Codim< codim >::LevelIterator lend(int level) const
one past the end on this level
const CollectiveCommunication & comm() const
Definition: onedgrid.hh:356
Traits::template Codim< codim >::LeafIterator leafend() const
one past the end on leaf level
int getMark(const Traits::Codim< 0 >::Entity &e) const
return current adaptation marker of given entity
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: onedgrid.hh:200
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first entity of given codim on leaf level.
Definition: onedgrid.hh:40
const Traits::LeafIndexSet & leafIndexSet() const
Get an index set for the leaf level.
Definition: onedgrid.hh:290
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
Specialize with 'true' if implementation guarantees a conforming leaf grid. (default=false) ...
Definition: common/capabilities.hh:95
GridFamily::Traits::template Codim< cd >::EntityPointer EntityPointer
A type that is a model of Dune::EntityPointer.
Definition: common/grid.hh:447
int ghostSize(int level, int codim) const
The processor ghost overlap for parallel computing. Always zero because this is a strictly sequential...
Definition: onedgrid.hh:261
friend class OneDGridLeafIndexSet< const OneDGrid >
Definition: onedgrid.hh:106
int size(int codim) const
number of leaf entities per codim in this process
Definition: onedgrid.hh:213
A set of traits classes to store static information about grid implementation.
Specialize with 'true' if implementation supports parallelism. (default=false)
Definition: common/capabilities.hh:64
~OneDGrid()
Destructor.
int maxLevel() const
Return maximum level defined in this grid.
Definition: onedgrid.hh:154
void postAdapt()
Adaptation post-processing: Reset all adaptation state flags.
static const bool v
Definition: common/capabilities.hh:26
static const bool v
Definition: common/capabilities.hh:88
static const unsigned int topologyId
Definition: common/capabilities.hh:29
ct ctype
Define type used for coordinates in grid module.
Definition: common/grid.hh:546
friend class OneDGridEntityPointer
Definition: onedgrid.hh:90
Specialize with 'true' for all codims that a grid implements entities for. (default=false) ...
Definition: common/capabilities.hh:55
Different resources needed by all grid implementations.
A traits struct that collects all associated types of one grid model.
Definition: common/grid.hh:1260
static const bool v
Definition: common/capabilities.hh:97
One-dimensional adaptive grid.
Definition: onedgrid.hh:83
Definition: common/geometry.hh:24
int ghostSize(int codim) const
The processor ghost overlap for parallel computing. Always zero because this is a strictly sequential...
Definition: onedgrid.hh:249
int overlapSize(int level, int codim) const
The processor overlap for parallel computing. Always zero because this is a strictly sequential grid...
Definition: onedgrid.hh:255
GridTraits< dim, dimw, Dune::OneDGrid, OneDGridGeometry, OneDGridEntity, OneDGridEntityPointer, OneDGridLevelIterator, OneDGridLeafIntersection, OneDGridLevelIntersection, OneDGridLeafIntersectionIterator, OneDGridLevelIntersectionIterator, OneDGridHierarchicIterator, OneDGridLeafIterator, OneDGridLevelIndexSet< const OneDGrid >, OneDGridLeafIndexSet< const OneDGrid >, OneDGridIdSet< const OneDGrid >, unsigned int, OneDGridIdSet< const OneDGrid >, unsigned int, CollectiveCommunication< Dune::OneDGrid >, DefaultLevelGridViewTraits, DefaultLeafGridViewTraits, OneDGridEntitySeed > Traits
Definition: onedgrid.hh:63
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:80
RefinementType
The different forms of grid refinement supported by OneDGrid.
Definition: onedgrid.hh:327
Definition: defaultgridview.hh:23
friend class OneDGridLevelIterator
Definition: onedgrid.hh:93
Specialize with 'true' for if the codimension 0 entity of the grid has only one possible geometry typ...
Definition: common/capabilities.hh:24
Id Set Interface.
Definition: common/grid.hh:360
Traits::template Codim< codim >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
const Traits::LevelIndexSet & levelIndexSet(int level) const
Get an index set for the given level.
Definition: onedgrid.hh:278
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:204
bool preAdapt()
Does nothing except return true if some element has been marked for refinement.
int overlapSize(int codim) const
The processor overlap for parallel computing. Always zero because this is a strictly sequential grid...
Definition: onedgrid.hh:243