Dune Core Modules (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 
11 
13 #include <dune/grid/common/grid.hh>
15 
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>
46 
47  struct OneDGridFamily
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,
68  OneDGridLevelGridViewTraits,
69  OneDGridLeafGridViewTraits,
70  OneDGridEntitySeed>
71  Traits;
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 
140  typedef OneDGridFamily GridFamily;
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 
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 
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 geometry implementation for axis-aligned hypercubes.
A geometry implementation for axis-aligned hypercubes.
Definition: axisalignedcubegeometry.hh:49
CoordType ctype
Type used for single coordinate coefficients.
Definition: axisalignedcubegeometry.hh:61
Collective communication interface and sequential default implementation.
Definition: collectivecommunication.hh:79
Wrapper class for entities.
Definition: entity.hh:65
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:268
unsigned int dim() const
Return dimension of the type.
Definition: type.hh:565
Definition: grid.hh:920
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: grid.hh:1115
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
Provide a generic factory class for unstructured grids.
Definition: gridfactory.hh:263
GridFamily::Traits::CollectiveCommunication CollectiveCommunication
A type that is a model of Dune::CollectiveCommunication. It provides a portable way for collective co...
Definition: grid.hh:519
Id Set Interface.
Definition: indexidset.hh:402
Index Set Interface base class.
Definition: indexidset.hh:76
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:220
One-dimensional adaptive grid.
Definition: onedgrid.hh:92
OneDGridGeometry< 0, 1, OneDGrid >::ctype ctype
The type used to store coordinates.
Definition: onedgrid.hh:137
bool preAdapt()
Does nothing except return true if some element has been marked for refinement.
int size(GeometryType type) const
number of leaf entities per geometry type in this process
Definition: onedgrid.hh:198
OneDGrid(const std::vector< ctype > &coords)
Constructor with an explicit set of coordinates.
void postAdapt()
Adaptation post-processing: Reset all adaptation state flags.
bool adapt()
Triggers the grid refinement process.
RefinementType
The different forms of grid refinement supported by OneDGrid.
Definition: onedgrid.hh:303
@ COPY
New level consists of the refined elements and the unrefined ones, too.
Definition: onedgrid.hh:307
@ LOCAL
New level consists only of the refined elements.
Definition: onedgrid.hh:305
size_t numBoundarySegments() const
Return the number of coarse grid boundary segments.
Definition: onedgrid.hh:208
~OneDGrid()
Destructor.
const Traits::LevelIndexSet & levelIndexSet(int level) const
Get an index set for the given level.
Definition: onedgrid.hh:254
bool mark(int refCount, const Traits::Codim< 0 >::Entity &e)
Mark entity for refinement.
void setRefinementType(RefinementType type)
Sets the type of grid refinement.
Definition: onedgrid.hh:311
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
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: onedgrid.hh:172
OneDGrid(int numElements, const ctype &leftBoundary, const ctype &rightBoundary)
Constructor for a uniform grid.
int ghostSize(int codim) const
The processor ghost overlap for parallel computing. Always zero because this is a strictly sequential...
Definition: onedgrid.hh:223
int size(int codim) const
number of leaf entities per codim in this process
Definition: onedgrid.hh:185
const Traits::LeafIndexSet & leafIndexSet() const
Get an index set for the leaf level.
Definition: onedgrid.hh:266
OneDGridFamily GridFamily
GridFamily of OneDGrid.
Definition: onedgrid.hh:140
int maxLevel() const
Return maximum level defined in this grid.
Definition: onedgrid.hh:158
int getMark(const Traits::Codim< 0 >::Entity &e) const
return current adaptation marker of given entity
const Traits::GlobalIdSet & globalIdSet() const
Get the set of global ids.
Definition: onedgrid.hh:242
const Traits::LocalIdSet & localIdSet() const
Get the set of local ids.
Definition: onedgrid.hh:248
int overlapSize(int codim) const
The processor overlap for parallel computing. Always zero because this is a strictly sequential grid.
Definition: onedgrid.hh:216
void globalRefine(int refCount)
Does one uniform refinement step.
Implements an utility class that provides collective communication methods for sequential programs.
A set of traits classes to store static information about grid implementation.
Different resources needed by all grid implementations.
Provide a generic factory class for unstructured grids.
struct DUNE_DEPRECATED_MSG("Use <type_traits> instead!") ConstantVolatileTraits
Determines whether a type is const or volatile and provides the unqualified types.
Definition: typetraits.hh:57
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:168
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:84
Dune namespace.
Definition: alignment.hh:11
AxisAlignedCubeGeometry< double, mydim, coorddim > OneDGridGeometry
The type used to for OneDGrid geometries.
Definition: onedgrid.hh:45
Specialize with 'true' for all codims that a grid implements entities for. (default=false)
Definition: capabilities.hh:56
Specialize with 'true' for if the codimension 0 entity of the grid has only one possible geometry typ...
Definition: capabilities.hh:25
Specialize with 'true' if implementation guarantees a conforming leaf grid. (default=false)
Definition: capabilities.hh:87
Specialize with 'true' if implementation guarantees conforming level grids. (default=false)
Definition: capabilities.hh:78
Static tag representing a codimension.
Definition: dimension.hh:22
Traits associated with a specific codim.
Definition: grid.hh:1175
A traits struct that collects all associated types of one grid model.
Definition: grid.hh:1153
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)