dune-grid  2.5.0
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 <tuple>
7 #include <vector>
8 #include <list>
9 
10 #include <dune/common/parallel/collectivecommunication.hh>
11 
13 #include <dune/grid/common/grid.hh>
15 
16 #include <dune/geometry/axisalignedcubegeometry.hh>
17 #include <dune/geometry/type.hh>
18 
23 #include "onedgrid/onedgridlist.hh"
24 #include "onedgrid/nulliteratorfactory.hh"
25 #include "onedgrid/onedgridentity.hh"
26 #include "onedgrid/onedgridentityseed.hh"
27 #include "onedgrid/onedgridintersections.hh"
28 #include "onedgrid/onedgridintersectioniterators.hh"
29 #include "onedgrid/onedgridleafiterator.hh"
30 #include "onedgrid/onedgridviews.hh"
31 #include "onedgrid/onedgridleveliterator.hh"
32 #include "onedgrid/onedgridhieriterator.hh"
33 #include "onedgrid/onedgridindexsets.hh"
34 
35 namespace Dune {
36 
37  class OneDGrid;
38 
44  template <int mydim, int coorddim, class GridImp>
45  using OneDGridGeometry = AxisAlignedCubeGeometry<double, mydim, coorddim>;
46 
48  {
49  typedef GridTraits<1, // Grid dimension
50  1, // Dimension of the physical space
53  OneDGridEntity,
54  OneDGridLevelIterator,
55  OneDGridLeafIntersection,
56  OneDGridLevelIntersection,
57  OneDGridLeafIntersectionIterator,
58  OneDGridLevelIntersectionIterator,
59  OneDGridHierarchicIterator,
60  OneDGridLeafIterator,
61  OneDGridLevelIndexSet<const OneDGrid>,
62  OneDGridLeafIndexSet<const OneDGrid>,
63  OneDGridIdSet<const OneDGrid>,
64  unsigned int,
65  OneDGridIdSet<const OneDGrid>,
66  unsigned int,
67  CollectiveCommunication<Dune::OneDGrid>,
68  OneDGridLevelGridViewTraits,
69  OneDGridLeafGridViewTraits,
70  OneDGridEntitySeed>
72  };
73 
74  //**********************************************************************
75  //
76  // --OneDGrid
77  //
78  //**********************************************************************
79 
91  class OneDGrid : public GridDefaultImplementation <1, 1,typename OneDGridGeometry<0,1,OneDGrid>::ctype, OneDGridFamily>
92  {
93  // Grid and world dimension are hardwired in this grid
94  enum {dim = 1};
95  enum {dimworld = 1};
96 
97  template <int , PartitionIteratorType, class >
98  friend class OneDGridLevelIterator;
99 
100  friend class OneDGridHierarchicIterator<const OneDGrid>;
101 
102  template <int codim_, int dim_, class GridImp_>
103  friend class OneDGridEntity;
104  friend class OneDGridHierarchicIterator<OneDGrid>;
105  friend class OneDGridLeafIntersection<const OneDGrid>;
106  friend class OneDGridLevelIntersection<const OneDGrid>;
107  friend class OneDGridLeafIntersectionIterator<const OneDGrid>;
108  friend class OneDGridLevelIntersectionIterator<const OneDGrid>;
109 
110  friend class OneDGridLevelIndexSet<const OneDGrid>;
111  friend class OneDGridLeafIndexSet<const OneDGrid>;
112  friend class OneDGridIdSet<const OneDGrid>;
113 
114  template <int codim_, PartitionIteratorType PiType_, class GridImp_>
115  friend class OneDGridLeafIterator;
116 
117  friend class OneDGridLeafGridView<const OneDGrid>;
118  friend class OneDGridLevelGridView<const OneDGrid>;
119 
120  template <class GridType_>
121  friend class GridFactory;
122 
123  template<int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
124  friend class Entity;
125 
127  OneDGrid();
128 
129  // **********************************************************
130  // The Interface Methods
131  // **********************************************************
132 
133  public:
134 
138 
141 
142  //Provides the standard grid types
144 
146  OneDGrid(const std::vector<ctype>& coords);
147 
149  OneDGrid(int numElements, const ctype& leftBoundary, const ctype& rightBoundary);
150 
152  ~OneDGrid();
153 
158  int maxLevel() const {return entityImps_.size()-1;}
159 
161  template <typename Seed>
162  static typename Traits::template Codim<Seed::codimension>::Entity
163  entity(const Seed& seed)
164  {
165  const int codim = Seed::codimension;
166  return typename Traits::template Codim<codim>::Entity(OneDGridEntity<codim,dim,const OneDGrid>(OneDGrid::getRealImplementation(seed).target()));
167  }
168 
169 
172  int size (int level, int codim) const {
173  if (codim<0 || codim>1)
174  DUNE_THROW(GridError, "There are no codim " << codim << " entities in a OneDGrid!");
175 
176  if (codim==0)
177  return elements(level).size();
178 
179  return vertices(level).size();
180  }
181 
182 
183 
185  int size (int codim) const
186  {
187  return leafIndexSet().size(codim);
188  }
189 
191  int size (int level, GeometryType type) const
192  {
193  // There is only one type for each codim
194  return size(level,1-type.dim());
195  }
196 
198  int size (GeometryType type) const
199  {
200  return leafIndexSet().size(type);
201  }
202 
208  size_t numBoundarySegments() const
209  {
210  return 2;
211  }
212 
215  DUNE_DEPRECATED_MSG("overlapSize() is deprecated. Use the method on the LeafGridView instead.")
216  int overlapSize(int codim) const {
217  return 0;
218  }
219 
222  DUNE_DEPRECATED_MSG("ghostSize() is deprecated. Use the method on the LeafGridView instead.")
223  int ghostSize(int codim) const {
224  return 0;
225  }
226 
229  DUNE_DEPRECATED_MSG("overlapSize() is deprecated. Use the method on the LevelGridView instead.")
230  int overlapSize(int level, int codim) const {
231  return 0;
232  }
233 
236  DUNE_DEPRECATED_MSG("ghostSize() is deprecated. Use the method on the LevelGridView instead.")
237  int ghostSize(int level, int codim) const {
238  return 0;
239  }
240 
243  {
244  return idSet_;
245  }
246 
249  {
250  return idSet_;
251  }
252 
254  const Traits::LevelIndexSet& levelIndexSet(int level) const
255  {
256  if (! levelIndexSets_[level]) {
257  levelIndexSets_[level] =
258  new OneDGridLevelIndexSet<const OneDGrid>(*this, level);
259  levelIndexSets_[level]->update();
260  }
261 
262  return * levelIndexSets_[level];
263  }
264 
267  {
268  return leafIndexSet_;
269  }
270 
271 
279  bool mark(int refCount, const Traits::Codim<0>::Entity& e );
280 
287  int getMark(const Traits::Codim<0>::Entity& e ) const;
288 
290  bool preAdapt();
291 
293  bool adapt();
294 
296  void postAdapt();
297 
298  // **********************************************************
299  // End of Interface Methods
300  // **********************************************************
301 
307  COPY
308  };
309 
312  refinementType_ = type;
313  }
314 
320  void globalRefine(int refCount);
321 
322  // dummy parallel functions
323 
324  template<class DataHandle>
325  DUNE_DEPRECATED_MSG("communicate() is deprecated. Use the method on the LevelGridView instead.")
326  void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
327  {}
328 
329  template<class DataHandle>
330  DUNE_DEPRECATED_MSG("communicate() is deprecated. Use the method on the LeafGridView instead.")
331  void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
332  {}
333 
334  const CollectiveCommunication &comm () const
335  {
336  return ccobj;
337  }
338 
339 
340  private:
341 
343  OneDGridList<OneDEntityImp<0> >& vertices(int level) {
344  return std::get<0>(entityImps_[level]);
345  }
346 
348  const OneDGridList<OneDEntityImp<0> >& vertices(int level) const {
349  return std::get<0>(entityImps_[level]);
350  }
351 
353  OneDGridList<OneDEntityImp<1> >& elements(int level) {
354  return std::get<1>(entityImps_[level]);
355  }
356 
358  const OneDGridList<OneDEntityImp<1> >& elements(int level) const {
359  return std::get<1>(entityImps_[level]);
360  }
361 
362  CollectiveCommunication ccobj;
363 
365  void setIndices();
366 
367  unsigned int getNextFreeId(int codim) {
368  return (codim==0) ? freeElementIdCounter_++ : freeVertexIdCounter_++;
369  }
370 
372  RefinementType refinementType_;
373 
374  OneDGridList<OneDEntityImp<0> >::iterator getLeftUpperVertex(const OneDEntityImp<1>* eIt);
375 
376  OneDGridList<OneDEntityImp<0> >::iterator getRightUpperVertex(const OneDEntityImp<1>* eIt);
377 
381  OneDGridList<OneDEntityImp<1> >::iterator getLeftNeighborWithSon(OneDGridList<OneDEntityImp<1> >::iterator eIt);
382 
383  // The vertices and elements of the grid hierarchy
384  std::vector<std::tuple<OneDGridList<OneDEntityImp<0> >,
385  OneDGridList<OneDEntityImp<1> > > > entityImps_;
386 
387  // Our set of level indices
388  mutable std::vector<OneDGridLevelIndexSet<const OneDGrid>* > levelIndexSets_;
389 
390  OneDGridLeafIndexSet<const OneDGrid> leafIndexSet_;
391 
392  OneDGridIdSet<const OneDGrid> idSet_;
393 
394  unsigned int freeVertexIdCounter_;
395 
396  unsigned int freeElementIdCounter_;
397 
401  bool reversedBoundarySegmentNumbering_;
402 
403  }; // end Class OneDGrid
404 
405  namespace Capabilities
406  {
418  template< >
420  {
421  static const bool v = true;
422  static const unsigned int topologyId = Impl::CubeTopology< 1 >::type::id;
423  };
424 
425 
429  template<int cdim>
430  struct hasEntity< OneDGrid, cdim >
431  {
432  static const bool v = true;
433  };
434 
438  template<>
440  {
441  static const bool v = true;
442  };
443 
447  template<>
449  {
450  static const bool v = true;
451  };
452 
453  }
454 
455 } // namespace Dune
456 
457 // Include the GridFactory specialization for OneDGrid, so everybody
458 // who includes the grid also gets the factory. Since OneDGrid is
459 // not a template class, it needs to be a complete type before
460 // GridFactory<OneDGrid> can be defined. This is why the #include-
461 // directive is at _the end_ of this file.
462 #include <dune/grid/onedgrid/onedgridfactory.hh>
463 
464 
465 #endif
A traits struct that collects all associated types of one grid model.
Definition: common/grid.hh:1152
const Traits::LocalIdSet & localIdSet() const
Get the set of local ids.
Definition: onedgrid.hh:248
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: onedgrid.hh:172
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:263
const Traits::GlobalIdSet & globalIdSet() const
Get the set of global ids.
Definition: onedgrid.hh:242
const CollectiveCommunication & comm() const
Definition: onedgrid.hh:334
GeometryType
Type representing VTK&#39;s entity geometry types.
Definition: common.hh:178
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:168
AxisAlignedCubeGeometry< double, mydim, coorddim > OneDGridGeometry
The type used to for OneDGrid geometries.
Definition: onedgrid.hh:45
OneDGridFamily::Traits Traits
Definition: onedgrid.hh:143
Definition: common/geometry.hh:24
const Traits::LeafIndexSet & leafIndexSet() const
Get an index set for the leaf level.
Definition: onedgrid.hh:266
Provide a generic factory class for unstructured grids.
int size(int codim) const
number of leaf entities per codim in this process
Definition: onedgrid.hh:185
OneDGridFamily GridFamily
GridFamily of OneDGrid.
Definition: onedgrid.hh:140
New level consists only of the refined elements.
Definition: onedgrid.hh:305
void setRefinementType(RefinementType type)
Sets the type of grid refinement.
Definition: onedgrid.hh:311
Definition: onedgrid.hh:47
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition: onedgrid.hh:191
A set of traits classes to store static information about grid implementation.
int maxLevel() const
Return maximum level defined in this grid.
Definition: onedgrid.hh:158
static Traits::template Codim< Seed::codimension >::Entity entity(const Seed &seed)
Create an Entity from an EntitySeed.
Definition: onedgrid.hh:163
Include standard header files.
Definition: agrid.hh:59
Id Set Interface.
Definition: common/grid.hh:347
Specialize with &#39;true&#39; for if the codimension 0 entity of the grid has only one possible geometry typ...
Definition: common/capabilities.hh:24
static std::conditional< std::is_reference< InterfaceType >::value, typename std::add_lvalue_reference< typename ReturnImplementationType< typename std::remove_reference< InterfaceType >::type >::ImplementationType >::type, typename std::remove_const< typename ReturnImplementationType< typename std::remove_reference< InterfaceType >::type >::ImplementationType >::type >::type getRealImplementation(InterfaceType &&i)
return real implementation of interface class
Definition: common/grid.hh:1115
const Traits::LevelIndexSet & levelIndexSet(int level) const
Get an index set for the given level.
Definition: onedgrid.hh:254
Wrapper class for entities.
Definition: common/entity.hh:64
Specialize with &#39;true&#39; if implementation guarantees a conforming leaf grid. (default=false) ...
Definition: common/capabilities.hh:86
A Traits struct that collects all associated types of one implementation.
Definition: common/grid.hh:414
Specialize with &#39;true&#39; for all codims that a grid implements entities for. (default=false) ...
Definition: common/capabilities.hh:55
int size(GeometryType type) const
number of leaf entities per geometry type in this process
Definition: onedgrid.hh:198
Index Set Interface base class.
Definition: common/grid.hh:346
OneDGridGeometry< 0, 1, OneDGrid >::ctype ctype
The type used to store coordinates.
Definition: onedgrid.hh:137
One-dimensional adaptive grid.
Definition: onedgrid.hh:91
Traits associated with a specific codim.
Definition: common/grid.hh:1174
Different resources needed by all grid implementations.
Specialize with &#39;true&#39; if implementation guarantees conforming level grids. (default=false) ...
Definition: common/capabilities.hh:77
RefinementType
The different forms of grid refinement supported by OneDGrid.
Definition: onedgrid.hh:303
GridTraits< 1, 1, Dune::OneDGrid, OneDGridGeometry, OneDGridEntity, 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 >, OneDGridLevelGridViewTraits, OneDGridLeafGridViewTraits, OneDGridEntitySeed > Traits
Definition: onedgrid.hh:71
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:84
size_t numBoundarySegments() const
Return the number of coarse grid boundary segments.
Definition: onedgrid.hh:208