Dune Core Modules (2.3.1)

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 <vector>
7#include <list>
8
10#include <dune/common/tuples.hh>
11
15
16#include <dune/geometry/genericgeometry/topologytypes.hh>
17
22#include "onedgrid/onedgridlist.hh"
23#include "onedgrid/nulliteratorfactory.hh"
24#include "onedgrid/onedgridentity.hh"
25#include "onedgrid/onedgridentitypointer.hh"
26#include "onedgrid/onedgridentityseed.hh"
27#include "onedgrid/onedgridgeometry.hh"
28#include "onedgrid/onedgridintersections.hh"
29#include "onedgrid/onedgridintersectioniterators.hh"
30#include "onedgrid/onedgridleveliterator.hh"
31#include "onedgrid/onedgridleafiterator.hh"
32#include "onedgrid/onedgridhieriterator.hh"
33#include "onedgrid/onedgridindexsets.hh"
34
35namespace Dune {
36
37 class OneDGrid;
38
39 template<int dim, int dimw>
40 struct OneDGridFamily
41 {
42 typedef GridTraits<dim,dimw,Dune::OneDGrid,
43 OneDGridGeometry,
44 OneDGridEntity,
45 OneDGridEntityPointer,
46 OneDGridLevelIterator,
47 OneDGridLeafIntersection,
48 OneDGridLevelIntersection,
49 OneDGridLeafIntersectionIterator,
50 OneDGridLevelIntersectionIterator,
51 OneDGridHierarchicIterator,
52 OneDGridLeafIterator,
53 OneDGridLevelIndexSet<const OneDGrid>,
54 OneDGridLeafIndexSet<const OneDGrid>,
55 OneDGridIdSet<const OneDGrid>,
56 unsigned int,
57 OneDGridIdSet<const OneDGrid>,
58 unsigned int,
59 CollectiveCommunication<Dune::OneDGrid>,
60 DefaultLevelGridViewTraits,
61 DefaultLeafGridViewTraits,
62 OneDGridEntitySeed>
63 Traits;
64 };
65
66 //**********************************************************************
67 //
68 // --OneDGrid
69 //
70 //**********************************************************************
71
83 class OneDGrid : public GridDefaultImplementation <1, 1,double,OneDGridFamily<1,1> >
84 {
85 // Grid and world dimension are hardwired in this grid
86 enum {dim = 1};
87 enum {dimworld = 1};
88
89 template <int, class >
90 friend class OneDGridEntityPointer;
91
92 template <int , PartitionIteratorType, class >
93 friend class OneDGridLevelIterator;
94
95 friend class OneDGridHierarchicIterator<const OneDGrid>;
96
97 template <int codim_, int dim_, class GridImp_>
98 friend class OneDGridEntity;
99 friend class OneDGridHierarchicIterator<OneDGrid>;
100 friend class OneDGridLeafIntersection<const OneDGrid>;
101 friend class OneDGridLevelIntersection<const OneDGrid>;
102 friend class OneDGridLeafIntersectionIterator<const OneDGrid>;
103 friend class OneDGridLevelIntersectionIterator<const OneDGrid>;
104
105 friend class OneDGridLevelIndexSet<const OneDGrid>;
106 friend class OneDGridLeafIndexSet<const OneDGrid>;
107 friend class OneDGridIdSet<const OneDGrid>;
108
109 template <int codim_, PartitionIteratorType PiType_, class GridImp_>
110 friend class OneDGridLeafIterator;
111
112 template <class GridType_>
113 friend class GridFactory;
114
115 template<int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
116 friend class Entity;
117
119 OneDGrid();
120
121 // **********************************************************
122 // The Interface Methods
123 // **********************************************************
124
125 public:
126
133 typedef double ctype;
134
136 typedef OneDGridFamily<dim,dimworld> GridFamily;
137
138 //Provides the standard grid types
140
142 OneDGrid(const std::vector<ctype>& coords);
143
145 OneDGrid(int numElements, const ctype& leftBoundary, const ctype& rightBoundary);
146
149
154 int maxLevel() const {return entityImps_.size()-1;}
155
157 template<int codim>
158 typename Traits::template Codim<codim>::LevelIterator lbegin (int level) const;
159
161 template<int codim>
162 typename Traits::template Codim<codim>::LevelIterator lend (int level) const;
163
165 template<int codim, PartitionIteratorType PiType>
166 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lbegin (int level) const;
167
169 template<int codim, PartitionIteratorType PiType>
170 typename Traits::template Codim<codim>::template Partition<PiType>::LevelIterator lend (int level) const;
171
173 template<int codim>
174 typename Traits::template Codim<codim>::LeafIterator leafbegin () const;
175
177 template<int codim>
178 typename Traits::template Codim<codim>::LeafIterator leafend () const;
179
181 template<int codim, PartitionIteratorType PiType>
182 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafbegin() const;
183
185 template<int codim, PartitionIteratorType PiType>
186 typename Traits::template Codim<codim>::template Partition<PiType>::LeafIterator leafend() const;
187
189 template <typename Seed>
190 static typename Traits::template Codim<Seed::codimension>::EntityPointer
191 entityPointer(const Seed& seed)
192 {
193 enum {codim = Seed::codimension};
194 return typename Traits::template Codim<codim>::EntityPointer(OneDGridEntityPointer<codim,const OneDGrid>(OneDGrid::getRealImplementation(seed).target()));
195 }
196
197
200 int size (int level, int codim) const {
201 if (codim<0 || codim>1)
202 DUNE_THROW(GridError, "There are no codim " << codim << " entities in a OneDGrid!");
203
204 if (codim==0)
205 return elements(level).size();
206
207 return vertices(level).size();
208 }
209
210
211
213 int size (int codim) const
214 {
215 return leafIndexSet().size(codim);
216 }
217
219 int size (int level, GeometryType type) const
220 {
221 // There is only one type for each codim
222 return size(level,1-type.dim());
223 }
224
226 int size (GeometryType type) const
227 {
228 return leafIndexSet().size(type);
229 }
230
236 size_t numBoundarySegments() const
237 {
238 return 2;
239 }
240
243 int overlapSize(int codim) const {
244 return 0;
245 }
246
249 int ghostSize(int codim) const {
250 return 0;
251 }
252
255 int overlapSize(int level, int codim) const {
256 return 0;
257 }
258
261 int ghostSize(int level, int codim) const {
262 return 0;
263 }
264
267 {
268 return idSet_;
269 }
270
273 {
274 return idSet_;
275 }
276
278 const Traits::LevelIndexSet& levelIndexSet(int level) const
279 {
280 if (! levelIndexSets_[level]) {
281 levelIndexSets_[level] =
282 new OneDGridLevelIndexSet<const OneDGrid>(*this, level);
283 levelIndexSets_[level]->update();
284 }
285
286 return * levelIndexSets_[level];
287 }
288
291 {
292 return leafIndexSet_;
293 }
294
295
303 bool mark(int refCount, const Traits::Codim<0>::Entity& e );
304
311 int getMark(const Traits::Codim<0>::Entity& e ) const;
312
314 bool preAdapt();
315
317 bool adapt();
318
320 void postAdapt();
321
322 // **********************************************************
323 // End of Interface Methods
324 // **********************************************************
325
331 COPY
332 };
333
336 refinementType_ = type;
337 }
338
344 void globalRefine(int refCount);
345
346 // dummy parallel functions
347
348 template<class DataHandle>
349 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir, int level) const
350 {}
351
352 template<class DataHandle>
353 void communicate (DataHandle& data, InterfaceType iftype, CommunicationDirection dir) const
354 {}
355
356 const CollectiveCommunication &comm () const
357 {
358 return ccobj;
359 }
360
361
362 private:
363
365 OneDGridList<OneDEntityImp<0> >& vertices(int level) {
366 return Dune::get<0>(entityImps_[level]);
367 }
368
370 const OneDGridList<OneDEntityImp<0> >& vertices(int level) const {
371 return Dune::get<0>(entityImps_[level]);
372 }
373
375 OneDGridList<OneDEntityImp<1> >& elements(int level) {
376 return Dune::get<1>(entityImps_[level]);
377 }
378
380 const OneDGridList<OneDEntityImp<1> >& elements(int level) const {
381 return Dune::get<1>(entityImps_[level]);
382 }
383
385
387 void setIndices();
388
389 unsigned int getNextFreeId(int codim) {
390 return (codim==0) ? freeElementIdCounter_++ : freeVertexIdCounter_++;
391 }
392
394 RefinementType refinementType_;
395
396 OneDGridList<OneDEntityImp<0> >::iterator getLeftUpperVertex(const OneDEntityImp<1>* eIt);
397
398 OneDGridList<OneDEntityImp<0> >::iterator getRightUpperVertex(const OneDEntityImp<1>* eIt);
399
403 OneDGridList<OneDEntityImp<1> >::iterator getLeftNeighborWithSon(OneDGridList<OneDEntityImp<1> >::iterator eIt);
404
405 // The vertices and elements of the grid hierarchy
406 std::vector<tuple<OneDGridList<OneDEntityImp<0> >,
407 OneDGridList<OneDEntityImp<1> > > > entityImps_;
408
409 // Our set of level indices
410 mutable std::vector<OneDGridLevelIndexSet<const OneDGrid>* > levelIndexSets_;
411
412 OneDGridLeafIndexSet<const OneDGrid> leafIndexSet_;
413
414 OneDGridIdSet<const OneDGrid> idSet_;
415
416 unsigned int freeVertexIdCounter_;
417
418 unsigned int freeElementIdCounter_;
419
423 bool reversedBoundarySegmentNumbering_;
424
425 }; // end Class OneDGrid
426
427 namespace Capabilities
428 {
440 template< >
442 {
443 static const bool v = true;
444 static const unsigned int topologyId = GenericGeometry :: CubeTopology< 1 > :: type :: id ;
445 };
446
447
451 template<int cdim>
452 struct hasEntity< OneDGrid, cdim >
453 {
454 static const bool v = true;
455 };
456
460 template<>
462 {
463 static const bool v = false;
464 };
465
469 template<>
471 {
472 static const bool v = true;
473 };
474
478 template<>
480 {
481 static const bool v = true;
482 };
483
484 }
485
486} // namespace Dune
487
488// Include the GridFactory specialization for OneDGrid, so everybody
489// who includes the grid also gets the factory. Since OneDGrid is
490// not a template class, it needs to be a complete type before
491// GridFactory<OneDGrid> can be defined. This is why the #include-
492// directive is at _the end_ of this file.
493#include <dune/grid/onedgrid/onedgridfactory.hh>
494
495
496#endif
Wrapper class for entities.
Definition: entity.hh:57
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Definition: grid.hh:1017
static ReturnImplementationType< InterfaceType >::ImplementationType & getRealImplementation(InterfaceType &i)
return real implementation of interface class
Definition: grid.hh:1223
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:543
Id Set Interface.
Definition: indexidset.hh:403
Index Set Interface base class.
Definition: indexidset.hh:78
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:204
One-dimensional adaptive grid.
Definition: onedgrid.hh:84
Traits::template Codim< codim >::LevelIterator lend(int level) const
one past the end on this level
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafbegin() const
Iterator to first entity of given codim on level.
Traits::template Codim< codim >::template Partition< PiType >::LeafIterator leafend() const
one past the end on this level
const Traits::LevelIndexSet & levelIndexSet(int level) const
Get an index set for the given level.
Definition: onedgrid.hh:278
double ctype
The type used to store coordinates.
Definition: onedgrid.hh:133
bool preAdapt()
Does nothing except return true if some element has been marked for refinement.
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
const Traits::LocalIdSet & localIdSet() const
Get the set of local ids.
Definition: onedgrid.hh:272
int size(GeometryType type) const
number of leaf entities per geometry type in this process
Definition: onedgrid.hh:226
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:327
@ COPY
New level consists of the refined elements and the unrefined ones, too.
Definition: onedgrid.hh:331
@ LOCAL
New level consists only of the refined elements.
Definition: onedgrid.hh:329
size_t numBoundarySegments() const
Return the number of coarse grid boundary segments.
Definition: onedgrid.hh:236
int ghostSize(int level, int codim) const
The processor ghost overlap for parallel computing. Always zero because this is a strictly sequential...
Definition: onedgrid.hh:261
~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:335
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition: onedgrid.hh:219
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: onedgrid.hh:200
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:290
int ghostSize(int codim) const
The processor ghost overlap for parallel computing. Always zero because this is a strictly sequential...
Definition: onedgrid.hh:249
const Traits::GlobalIdSet & globalIdSet() const
Get the set of global ids.
Definition: onedgrid.hh:266
OneDGridFamily< dim, dimworld > GridFamily
GridFamily of OneDGrid.
Definition: onedgrid.hh:136
int size(int codim) const
number of leaf entities per codim in this process
Definition: onedgrid.hh:213
Traits::template Codim< codim >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
int overlapSize(int level, int codim) const
The processor overlap for parallel computing. Always zero because this is a strictly sequential grid.
Definition: onedgrid.hh:255
Traits::template Codim< codim >::LeafIterator leafbegin() const
Iterator to first entity of given codim on leaf level.
int maxLevel() const
Return maximum level defined in this grid.
Definition: onedgrid.hh:154
Traits::template Codim< codim >::LeafIterator leafend() const
one past the end on leaf level
int getMark(const Traits::Codim< 0 >::Entity &e) const
return current adaptation marker of given entity
Traits::template Codim< codim >::template Partition< PiType >::LevelIterator lend(int level) const
one past the end on this level
int overlapSize(int codim) const
The processor overlap for parallel computing. Always zero because this is a strictly sequential grid.
Definition: onedgrid.hh:243
void globalRefine(int refCount)
Does one uniform refinement step.
static Traits::template Codim< Seed::codimension >::EntityPointer entityPointer(const Seed &seed)
Create an EntityPointer from an EntitySeed.
Definition: onedgrid.hh:191
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:244
Dune namespace.
Definition: alignment.hh:14
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:164
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:80
Implements an utility class that provides collective communication methods for sequential programs.
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:96
Specialize with 'true' if implementation guarantees conforming level grids. (default=false)
Definition: capabilities.hh:87
Specialize with 'true' if implementation supports parallelism. (default=false)
Definition: capabilities.hh:65
Traits associated with a specific codim.
Definition: grid.hh:1283
A traits struct that collects all associated types of one grid model.
Definition: grid.hh:1261
Fallback implementation of the std::tuple class.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)