dune-grid  2.6-git
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  {
216  return idSet_;
217  }
218 
221  {
222  return idSet_;
223  }
224 
226  const Traits::LevelIndexSet& levelIndexSet(int level) const
227  {
228  if (! levelIndexSets_[level]) {
229  levelIndexSets_[level] =
230  new OneDGridLevelIndexSet<const OneDGrid>(*this, level);
231  levelIndexSets_[level]->update();
232  }
233 
234  return * levelIndexSets_[level];
235  }
236 
239  {
240  return leafIndexSet_;
241  }
242 
243 
251  bool mark(int refCount, const Traits::Codim<0>::Entity& e );
252 
259  int getMark(const Traits::Codim<0>::Entity& e ) const;
260 
262  bool preAdapt();
263 
265  bool adapt();
266 
268  void postAdapt();
269 
270  // **********************************************************
271  // End of Interface Methods
272  // **********************************************************
273 
279  COPY
280  };
281 
284  refinementType_ = type;
285  }
286 
292  void globalRefine(int refCount);
293 
294  // dummy parallel functions
295 
296  const CollectiveCommunication &comm () const
297  {
298  return ccobj;
299  }
300 
301 
302  private:
303 
305  OneDGridList<OneDEntityImp<0> >& vertices(int level) {
306  return std::get<0>(entityImps_[level]);
307  }
308 
310  const OneDGridList<OneDEntityImp<0> >& vertices(int level) const {
311  return std::get<0>(entityImps_[level]);
312  }
313 
315  OneDGridList<OneDEntityImp<1> >& elements(int level) {
316  return std::get<1>(entityImps_[level]);
317  }
318 
320  const OneDGridList<OneDEntityImp<1> >& elements(int level) const {
321  return std::get<1>(entityImps_[level]);
322  }
323 
324  CollectiveCommunication ccobj;
325 
327  void setIndices();
328 
331  unsigned int getNextFreeId()
332  {
333  return freeIdCounter_++;
334  }
335 
337  RefinementType refinementType_;
338 
339  OneDGridList<OneDEntityImp<0> >::iterator getLeftUpperVertex(const OneDEntityImp<1>* eIt);
340 
341  OneDGridList<OneDEntityImp<0> >::iterator getRightUpperVertex(const OneDEntityImp<1>* eIt);
342 
346  OneDGridList<OneDEntityImp<1> >::iterator getLeftNeighborWithSon(OneDGridList<OneDEntityImp<1> >::iterator eIt);
347 
348  // The vertices and elements of the grid hierarchy
349  std::vector<std::tuple<OneDGridList<OneDEntityImp<0> >,
350  OneDGridList<OneDEntityImp<1> > > > entityImps_;
351 
352  // Our set of level indices
353  mutable std::vector<OneDGridLevelIndexSet<const OneDGrid>* > levelIndexSets_;
354 
355  OneDGridLeafIndexSet<const OneDGrid> leafIndexSet_;
356 
357  OneDGridIdSet<const OneDGrid> idSet_;
358 
359  // Every entity gets a unique id, unless it is a copy of an entity on a coarser level.
360  // This is the counter that we use to create the unique id.
361  unsigned int freeIdCounter_;
362 
366  bool reversedBoundarySegmentNumbering_;
367 
368  }; // end Class OneDGrid
369 
370  namespace Capabilities
371  {
383  template< >
385  {
386  static const bool v = true;
387  static const unsigned int topologyId = Impl::CubeTopology< 1 >::type::id;
388  };
389 
390 
394  template<int cdim>
395  struct hasEntity< OneDGrid, cdim >
396  {
397  static const bool v = true;
398  };
399 
404  template<int codim>
406  {
407  static const bool v = false;
408  };
409 
413  template<>
415  {
416  static const bool v = true;
417  };
418 
422  template<>
424  {
425  static const bool v = true;
426  };
427 
428  }
429 
430 } // namespace Dune
431 
432 // Include the GridFactory specialization for OneDGrid, so everybody
433 // who includes the grid also gets the factory. Since OneDGrid is
434 // not a template class, it needs to be a complete type before
435 // GridFactory<OneDGrid> can be defined. This is why the #include-
436 // directive is at _the end_ of this file.
437 #include <dune/grid/onedgrid/onedgridfactory.hh>
438 
439 
440 #endif
int maxLevel() const
Return maximum level defined in this grid.
Definition: onedgrid.hh:158
const Traits::LeafIndexSet & leafIndexSet() const
Get an index set for the leaf level.
Definition: onedgrid.hh:238
RefinementType
The different forms of grid refinement supported by OneDGrid.
Definition: onedgrid.hh:275
Traits associated with a specific codim.
Definition: common/grid.hh:1085
const Traits::GlobalIdSet & globalIdSet() const
Get the set of global ids.
Definition: onedgrid.hh:214
Specialize with &#39;true&#39; if implementation guarantees conforming level grids. (default=false) ...
Definition: common/capabilities.hh:103
One-dimensional adaptive grid.
Definition: onedgrid.hh:91
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
void setRefinementType(RefinementType type)
Sets the type of grid refinement.
Definition: onedgrid.hh:283
OneDGridFamily::Traits Traits
Definition: onedgrid.hh:143
OneDGridGeometry< 0, 1, OneDGrid >::ctype ctype
The type used to store coordinates.
Definition: onedgrid.hh:137
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: onedgrid.hh:172
const Traits::LevelIndexSet & levelIndexSet(int level) const
Get an index set for the given level.
Definition: onedgrid.hh:226
specialize with &#39;true&#39; for all codims that a grid provides an iterator for (default=false) ...
Definition: common/capabilities.hh:71
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
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
Wrapper class for entities.
Definition: common/entity.hh:63
A traits struct that collects all associated types of one grid model.
Definition: common/grid.hh:1063
Specialize with &#39;true&#39; for all codims that a grid implements entities for. (default=false) ...
Definition: common/capabilities.hh:55
Definition: onedgrid.hh:47
Id Set Interface.
Definition: common/grid.hh:347
AxisAlignedCubeGeometry< double, mydim, coorddim > OneDGridGeometry
The type used to for OneDGrid geometries.
Definition: onedgrid.hh:45
const Traits::LocalIdSet & localIdSet() const
Get the set of local ids.
Definition: onedgrid.hh:220
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:263
const CollectiveCommunication & comm() const
Definition: onedgrid.hh:296
Specialize with &#39;true&#39; if implementation guarantees a conforming leaf grid. (default=false) ...
Definition: common/capabilities.hh:112
GeometryType
Type representing VTK&#39;s entity geometry types.
Definition: common.hh:178
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:1026
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
size_t numBoundarySegments() const
Return the number of coarse grid boundary segments.
Definition: onedgrid.hh:208
Definition: common/geometry.hh:24
A set of traits classes to store static information about grid implementation.
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
New level consists only of the refined elements.
Definition: onedgrid.hh:277
Different resources needed by all grid implementations.
OneDGridFamily GridFamily
GridFamily of OneDGrid.
Definition: onedgrid.hh:140
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition: onedgrid.hh:191
static Traits::template Codim< Seed::codimension >::Entity entity(const Seed &seed)
Create an Entity from an EntitySeed.
Definition: onedgrid.hh:163
A Traits struct that collects all associated types of one implementation.
Definition: common/grid.hh:414
Include standard header files.
Definition: agrid.hh:58