Dune Core Modules (2.6.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
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
35namespace 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 {
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
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
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:80
Wrapper class for entities.
Definition: entity.hh:64
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:277
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:572
Definition: grid.hh:855
static std::conditional< std::is_reference< InterfaceType >::value, typenamestd::add_lvalue_reference< typenameReturnImplementationType< typenamestd::remove_reference< InterfaceType >::type >::ImplementationType >::type, typenamestd::remove_const< typenameReturnImplementationType< typenamestd::remove_reference< InterfaceType >::type >::ImplementationType >::type >::type getRealImplementation(InterfaceType &&i)
return real implementation of interface class
Definition: grid.hh:1026
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:441
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
const Traits::LevelIndexSet & levelIndexSet(int level) const
Get an index set for the given level.
Definition: onedgrid.hh:226
bool preAdapt()
Does nothing except return true if some element has been marked for refinement.
const Traits::LocalIdSet & localIdSet() const
Get the set of local ids.
Definition: onedgrid.hh:220
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:275
@ COPY
New level consists of the refined elements and the unrefined ones, too.
Definition: onedgrid.hh:279
@ LOCAL
New level consists only of the refined elements.
Definition: onedgrid.hh:277
size_t numBoundarySegments() const
Return the number of coarse grid boundary segments.
Definition: onedgrid.hh:208
~OneDGrid()
Destructor.
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:283
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition: onedgrid.hh:191
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.
const Traits::LeafIndexSet & leafIndexSet() const
Get an index set for the leaf level.
Definition: onedgrid.hh:238
const Traits::GlobalIdSet & globalIdSet() const
Get the set of global ids.
Definition: onedgrid.hh:214
static Traits::template Codim< Seed::codimension >::Entity entity(const Seed &seed)
Create an Entity from an EntitySeed.
Definition: onedgrid.hh:163
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
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
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.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune namespace.
Definition: alignedallocator.hh:10
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 provides an iterator for (default=false)
Definition: capabilities.hh:72
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:113
Specialize with 'true' if implementation guarantees conforming level grids. (default=false)
Definition: capabilities.hh:104
Static tag representing a codimension.
Definition: dimension.hh:22
Traits associated with a specific codim.
Definition: grid.hh:1086
A traits struct that collects all associated types of one grid model.
Definition: grid.hh:1064
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.111.3 (Nov 24, 23:30, 2024)