dune-grid  2.11
onedgrid.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 #ifndef DUNE_ONE_D_GRID_HH
6 #define DUNE_ONE_D_GRID_HH
7 
8 #include <tuple>
9 #include <vector>
10 #include <list>
11 
12 #include <dune/common/parallel/communication.hh>
13 
15 #include <dune/grid/common/grid.hh>
17 
18 #include <dune/geometry/axisalignedcubegeometry.hh>
19 #include <dune/geometry/type.hh>
20 
25 #include "onedgrid/onedgridlist.hh"
26 #include "onedgrid/nulliteratorfactory.hh"
27 #include "onedgrid/onedgridentity.hh"
28 #include "onedgrid/onedgridentityseed.hh"
29 #include "onedgrid/onedgridintersections.hh"
30 #include "onedgrid/onedgridintersectioniterators.hh"
31 #include "onedgrid/onedgridleafiterator.hh"
32 #include "onedgrid/onedgridviews.hh"
33 #include "onedgrid/onedgridleveliterator.hh"
34 #include "onedgrid/onedgridhieriterator.hh"
35 #include "onedgrid/onedgridindexsets.hh"
36 
37 namespace Dune {
38 
39  class OneDGrid;
40 
46  template <int mydim, int coorddim, class GridImp>
47  using OneDGridGeometry = AxisAlignedCubeGeometry<double, mydim, coorddim>;
48 
50  {
51  typedef GridTraits<1, // Grid dimension
52  1, // Dimension of the physical space
55  OneDGridEntity,
56  OneDGridLevelIterator,
57  OneDGridLeafIntersection,
58  OneDGridLevelIntersection,
59  OneDGridLeafIntersectionIterator,
60  OneDGridLevelIntersectionIterator,
61  OneDGridHierarchicIterator,
62  OneDGridLeafIterator,
63  OneDGridLevelIndexSet<const OneDGrid>,
64  OneDGridLeafIndexSet<const OneDGrid>,
65  OneDGridIdSet<const OneDGrid>,
66  unsigned int,
67  OneDGridIdSet<const OneDGrid>,
68  unsigned int,
69  Communication<No_Comm>,
70  OneDGridLevelGridViewTraits,
71  OneDGridLeafGridViewTraits,
72  OneDGridEntitySeed,
74  unsigned int,
75  std::array<GeometryType,1> >
77  };
78 
79  //**********************************************************************
80  //
81  // --OneDGrid
82  //
83  //**********************************************************************
84 
96  class OneDGrid : public GridDefaultImplementation <1, 1,typename OneDGridGeometry<0,1,OneDGrid>::ctype, OneDGridFamily>
97  {
98  // Grid and world dimension are hardwired in this grid
99  constexpr static int dim = 1;
100  constexpr static int dimworld = 1;
101 
102  template <int , PartitionIteratorType, class >
103  friend class OneDGridLevelIterator;
104 
105  friend class OneDGridHierarchicIterator<const OneDGrid>;
106 
107  template <int codim_, int dim_, class GridImp_>
108  friend class OneDGridEntity;
109  friend class OneDGridHierarchicIterator<OneDGrid>;
110  friend class OneDGridLeafIntersection<const OneDGrid>;
111  friend class OneDGridLevelIntersection<const OneDGrid>;
112  friend class OneDGridLeafIntersectionIterator<const OneDGrid>;
113  friend class OneDGridLevelIntersectionIterator<const OneDGrid>;
114 
115  friend class OneDGridLevelIndexSet<const OneDGrid>;
116  friend class OneDGridLeafIndexSet<const OneDGrid>;
117  friend class OneDGridIdSet<const OneDGrid>;
118 
119  template <int codim_, PartitionIteratorType PiType_, class GridImp_>
120  friend class OneDGridLeafIterator;
121 
122  friend class OneDGridLeafGridView<const OneDGrid>;
123  friend class OneDGridLevelGridView<const OneDGrid>;
124 
125  template <class GridType_>
126  friend class GridFactory;
127 
128  template<int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
129  friend class Entity;
130 
132  OneDGrid();
133 
134  // **********************************************************
135  // The Interface Methods
136  // **********************************************************
137 
138  public:
139 
143 
146 
147  //Provides the standard grid types
149 
151  OneDGrid(const std::vector<ctype>& coords);
152 
154  OneDGrid(int numElements, const ctype& leftBoundary, const ctype& rightBoundary);
155 
157  ~OneDGrid();
158 
163  int maxLevel() const {return entityImps_.size()-1;}
164 
166  template <typename Seed>
167  static typename Traits::template Codim<Seed::codimension>::Entity
168  entity(const Seed& seed)
169  {
170  const int codim = Seed::codimension;
171  return typename Traits::template Codim<codim>::Entity(OneDGridEntity<codim,dim,const OneDGrid>(seed.impl().target()));
172  }
173 
174 
177  int size (int level, int codim) const {
178  switch (codim)
179  {
180  case 0:
181  return elements(level).size();
182  case 1:
183  return vertices(level).size();
184  default:
185  return 0;
186  }
187  }
188 
189 
190 
192  int size (int codim) const
193  {
194  return leafIndexSet().size(codim);
195  }
196 
198  int size (int level, GeometryType type) const
199  {
200  // There is only one type for each codim
201  return size(level,1-type.dim());
202  }
203 
205  int size (GeometryType type) const
206  {
207  return leafIndexSet().size(type);
208  }
209 
215  size_t numBoundarySegments() const
216  {
217  return 2;
218  }
219 
222  {
223  return idSet_;
224  }
225 
228  {
229  return idSet_;
230  }
231 
233  const Traits::LevelIndexSet& levelIndexSet(int level) const
234  {
235  if (! levelIndexSets_[level]) {
236  levelIndexSets_[level] =
237  new OneDGridLevelIndexSet<const OneDGrid>(*this, level);
238  levelIndexSets_[level]->update();
239  }
240 
241  return * levelIndexSets_[level];
242  }
243 
246  {
247  return leafIndexSet_;
248  }
249 
250 
258  bool mark(int refCount, const Traits::Codim<0>::Entity& e );
259 
266  int getMark(const Traits::Codim<0>::Entity& e ) const;
267 
269  bool preAdapt();
270 
272  bool adapt();
273 
275  void postAdapt();
276 
277  // **********************************************************
278  // End of Interface Methods
279  // **********************************************************
280 
287  };
288 
291  refinementType_ = type;
292  }
293 
299  void globalRefine(int refCount);
300 
301  // dummy parallel functions
302 
303  const Communication &comm () const
304  {
305  return ccobj;
306  }
307 
308 
310  template <class DataHandle>
311  void communicate (DataHandle& /*handle*/, InterfaceType /*iftype*/,
312  CommunicationDirection /*dir*/, int /*level*/) const
313  {
314  DUNE_THROW(Dune::NotImplemented, "communicate() for OneDGrid not implemented");
315  }
316 
318  template <class DataHandle>
319  void communicate (DataHandle& /*handle*/, InterfaceType /*iftype*/,
320  CommunicationDirection /*dir*/) const
321  {
322  DUNE_THROW(Dune::NotImplemented, "communicate() for OneDGrid not implemented");
323  }
324 
325 
326  private:
327 
329  OneDGridList<OneDEntityImp<0> >& vertices(int level) {
330  return std::get<0>(entityImps_[level]);
331  }
332 
334  const OneDGridList<OneDEntityImp<0> >& vertices(int level) const {
335  return std::get<0>(entityImps_[level]);
336  }
337 
339  OneDGridList<OneDEntityImp<1> >& elements(int level) {
340  return std::get<1>(entityImps_[level]);
341  }
342 
344  const OneDGridList<OneDEntityImp<1> >& elements(int level) const {
345  return std::get<1>(entityImps_[level]);
346  }
347 
348  Communication ccobj;
349 
351  void setIndices();
352 
355  unsigned int getNextFreeId()
356  {
357  return freeIdCounter_++;
358  }
359 
361  RefinementType refinementType_;
362 
363  OneDGridList<OneDEntityImp<0> >::iterator getLeftUpperVertex(const OneDEntityImp<1>* eIt);
364 
365  OneDGridList<OneDEntityImp<0> >::iterator getRightUpperVertex(const OneDEntityImp<1>* eIt);
366 
370  OneDGridList<OneDEntityImp<1> >::iterator getLeftNeighborWithSon(OneDGridList<OneDEntityImp<1> >::iterator eIt);
371 
372  // The vertices and elements of the grid hierarchy
373  std::vector<std::tuple<OneDGridList<OneDEntityImp<0> >,
374  OneDGridList<OneDEntityImp<1> > > > entityImps_;
375 
376  // Our set of level indices
377  mutable std::vector<OneDGridLevelIndexSet<const OneDGrid>* > levelIndexSets_;
378 
380 
382 
383  // Every entity gets a unique id, unless it is a copy of an entity on a coarser level.
384  // This is the counter that we use to create the unique id.
385  unsigned int freeIdCounter_;
386 
390  bool reversedBoundarySegmentNumbering_;
391 
392  }; // end Class OneDGrid
393 
394  namespace Capabilities
395  {
407  template< >
409  {
410  static const bool v = true;
411  static const unsigned int topologyId = GeometryTypes::cube(1).id();
412  };
413 
414 
418  template<int cdim>
419  struct hasEntity< OneDGrid, cdim >
420  {
421  static const bool v = true;
422  };
423 
428  template<int codim>
430  {
431  static const bool v = true;
432  };
433 
437  template<>
439  {
440  static const bool v = true;
441  };
442 
446  template<>
448  {
449  static const bool v = true;
450  };
451 
452  }
453 
454 } // namespace Dune
455 
456 // Include the GridFactory specialization for OneDGrid, so everybody
457 // who includes the grid also gets the factory. Since OneDGrid is
458 // not a template class, it needs to be a complete type before
459 // GridFactory<OneDGrid> can be defined. This is why the #include-
460 // directive is at _the end_ of this file.
461 #include <dune/grid/onedgrid/onedgridfactory.hh>
462 
463 
464 #endif
int maxLevel() const
Return maximum level defined in this grid.
Definition: onedgrid.hh:163
bool mark(int refCount, const Traits::Codim< 0 >::Entity &e)
Mark entity for refinement.
One-dimensional adaptive grid.
Definition: onedgrid.hh:96
RefinementType
The different forms of grid refinement supported by OneDGrid.
Definition: onedgrid.hh:282
int getMark(const Traits::Codim< 0 >::Entity &e) const
return current adaptation marker of given entity
bool adapt()
Triggers the grid refinement process.
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: common/indexidset.hh:223
typename GridFamily::Traits::Communication Communication
A type that is a model of Dune::Communication. It provides a portable way for communication on the se...
Definition: common/grid.hh:515
Index Set Interface base class.
Definition: common/grid.hh:348
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition: onedgrid.hh:198
friend class OneDGridLeafIterator
Definition: onedgrid.hh:120
Definition: onedgrid.hh:49
int size(GeometryType type) const
number of leaf entities per geometry type in this process
Definition: onedgrid.hh:205
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: onedgrid.hh:177
New level consists only of the refined elements.
Definition: onedgrid.hh:284
void setRefinementType(RefinementType type)
Sets the type of grid refinement.
Definition: onedgrid.hh:290
Specialize with &#39;true&#39; for if the codimension 0 entity of the grid has only one possible geometry typ...
Definition: common/capabilities.hh:26
friend class OneDGridLevelIndexSet< const OneDGrid >
Definition: onedgrid.hh:115
static const bool v
Definition: common/capabilities.hh:116
const Communication & comm() const
Definition: onedgrid.hh:303
New level consists of the refined elements and the unrefined ones, too.
Definition: onedgrid.hh:286
~OneDGrid()
Destructor.
Specialize with &#39;true&#39; for all codims that a grid implements entities for. (default=false) ...
Definition: common/capabilities.hh:57
void postAdapt()
Adaptation post-processing: Reset all adaptation state flags.
Provide a generic factory class for unstructured grids.
friend class OneDGridLevelIterator
Definition: onedgrid.hh:103
OneDGridFamily::Traits Traits
Definition: onedgrid.hh:148
Different resources needed by all grid implementations.
void communicate(DataHandle &, InterfaceType, CommunicationDirection) const
Communicate data of leaf gridView.
Definition: onedgrid.hh:319
Specialize with &#39;true&#39; if implementation guarantees a conforming leaf grid. (default=false) ...
Definition: common/capabilities.hh:114
AxisAlignedCubeGeometry< double, mydim, coorddim > OneDGridGeometry
The type used to for OneDGrid geometries.
Definition: onedgrid.hh:47
static Traits::template Codim< Seed::codimension >::Entity entity(const Seed &seed)
Create an Entity from an EntitySeed.
Definition: onedgrid.hh:168
OneDGridFamily GridFamily
GridFamily of OneDGrid.
Definition: onedgrid.hh:145
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:170
friend class OneDGridEntity
Definition: onedgrid.hh:108
Definition: common/geometry.hh:28
const Traits::GlobalIdSet & globalIdSet() const
Get the set of global ids.
Definition: onedgrid.hh:221
Include standard header files.
Definition: agrid.hh:59
int size(int codim) const
number of leaf entities per codim in this process
Definition: onedgrid.hh:192
static const bool v
Definition: common/capabilities.hh:75
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:86
Specialize with &#39;true&#39; if implementation guarantees conforming level grids. (default=false) ...
Definition: common/capabilities.hh:105
static const bool v
Definition: common/capabilities.hh:107
static const bool v
Definition: common/capabilities.hh:28
specialize with &#39;true&#39; for all codims that a grid provides an iterator for (default=hasEntity<codim>:...
Definition: common/capabilities.hh:73
A traits struct that collects all associated types of one grid model.
Definition: common/grid.hh:1012
static const bool v
Definition: common/capabilities.hh:59
static const unsigned int topologyId
Definition: common/capabilities.hh:31
void communicate(DataHandle &, InterfaceType, CommunicationDirection, int) const
Communicate data of level gridView.
Definition: onedgrid.hh:311
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:275
ct ctype
Define type used for coordinates in grid module.
Definition: common/grid.hh:518
Wrapper class for entities.
Definition: common/entity.hh:65
void globalRefine(int refCount)
Does one uniform refinement step.
friend class OneDGridLeafIndexSet< const OneDGrid >
Definition: onedgrid.hh:116
size_t numBoundarySegments() const
Return the number of coarse grid boundary segments.
Definition: onedgrid.hh:215
const Traits::LevelIndexSet & levelIndexSet(int level) const
Get an index set for the given level.
Definition: onedgrid.hh:233
GeometryType
Type representing VTK&#39;s entity geometry types.
Definition: common.hh:132
Dune::Entity< cd, dim, const GridImp, EntityImp > Entity
The type of the entity.
Definition: common/grid.hh:1046
A set of traits classes to store static information about grid implementation.
friend class OneDGridIdSet< const OneDGrid >
Definition: onedgrid.hh:117
GridFamily::Traits::template Codim< cd >::Entity Entity
A type that is a model of a Dune::Entity<cd,dim,...>.
Definition: common/grid.hh:419
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, Communication< No_Comm >, OneDGridLevelGridViewTraits, OneDGridLeafGridViewTraits, OneDGridEntitySeed, OneDGridGeometry, unsigned int, std::array< GeometryType, 1 > > Traits
Definition: onedgrid.hh:76
OneDGridGeometry< 0, 1, OneDGrid >::ctype ctype
The type used to store coordinates.
Definition: onedgrid.hh:142
const Traits::LeafIndexSet & leafIndexSet() const
Get an index set for the leaf level.
Definition: onedgrid.hh:245
Id Set Interface.
Definition: common/grid.hh:349
const Traits::LocalIdSet & localIdSet() const
Get the set of local ids.
Definition: onedgrid.hh:227
bool preAdapt()
Does nothing except return true if some element has been marked for refinement.