DUNE PDELab (git)

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
13
17
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
37namespace Dune {
38
39 class OneDGrid;
40
46 template <int mydim, int coorddim, class GridImp>
48
49 struct OneDGridFamily
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,
70 OneDGridLevelGridViewTraits,
71 OneDGridLeafGridViewTraits,
72 OneDGridEntitySeed,
74 unsigned int,
75 std::array<GeometryType,1> >
76 Traits;
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
145 typedef OneDGridFamily GridFamily;
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
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
286 COPY
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
379 OneDGridLeafIndexSet<const OneDGrid> leafIndexSet_;
380
381 OneDGridIdSet<const OneDGrid> idSet_;
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
A geometry implementation for axis-aligned hypercubes.
A geometry implementation for axis-aligned hypercubes.
Definition: axisalignedcubegeometry.hh:50
CoordType ctype
Type used for single coordinate coefficients.
Definition: axisalignedcubegeometry.hh:62
Wrapper class for entities.
Definition: entity.hh:66
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:360
constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:365
Definition: grid.hh:848
Provide a generic factory class for unstructured grids.
Definition: gridfactory.hh:275
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: grid.hh:515
Id Set Interface.
Definition: indexidset.hh:447
Index Set Interface base class.
Definition: indexidset.hh:78
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:223
Default exception for dummy implementations.
Definition: exceptions.hh:263
One-dimensional adaptive grid.
Definition: onedgrid.hh:97
OneDGridGeometry< 0, 1, OneDGrid >::ctype ctype
The type used to store coordinates.
Definition: onedgrid.hh:142
const Traits::LevelIndexSet & levelIndexSet(int level) const
Get an index set for the given level.
Definition: onedgrid.hh:233
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:227
int size(GeometryType type) const
number of leaf entities per geometry type in this process
Definition: onedgrid.hh:205
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:282
@ COPY
New level consists of the refined elements and the unrefined ones, too.
Definition: onedgrid.hh:286
@ LOCAL
New level consists only of the refined elements.
Definition: onedgrid.hh:284
size_t numBoundarySegments() const
Return the number of coarse grid boundary segments.
Definition: onedgrid.hh:215
~OneDGrid()
Destructor.
void communicate(DataHandle &, InterfaceType, CommunicationDirection, int) const
Communicate data of level gridView.
Definition: onedgrid.hh:311
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:290
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition: onedgrid.hh:198
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: onedgrid.hh:177
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:245
const Traits::GlobalIdSet & globalIdSet() const
Get the set of global ids.
Definition: onedgrid.hh:221
static Traits::template Codim< Seed::codimension >::Entity entity(const Seed &seed)
Create an Entity from an EntitySeed.
Definition: onedgrid.hh:168
void communicate(DataHandle &, InterfaceType, CommunicationDirection) const
Communicate data of leaf gridView.
Definition: onedgrid.hh:319
int size(int codim) const
number of leaf entities per codim in this process
Definition: onedgrid.hh:192
OneDGridFamily GridFamily
GridFamily of OneDGrid.
Definition: onedgrid.hh:145
int maxLevel() const
Return maximum level defined in this grid.
Definition: onedgrid.hh:163
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.
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.
Implements an utility class that provides collective communication methods for sequential programs.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:170
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:86
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:462
Dune namespace.
Definition: alignedallocator.hh:13
AxisAlignedCubeGeometry< double, mydim, coorddim > OneDGridGeometry
The type used to for OneDGrid geometries.
Definition: onedgrid.hh:47
specialize with 'true' for all codims that a grid provides an iterator for (default=hasEntity<codim>:...
Definition: capabilities.hh:74
Specialize with 'true' for all codims that a grid implements entities for. (default=false)
Definition: capabilities.hh:58
Specialize with 'true' for if the codimension 0 entity of the grid has only one possible geometry typ...
Definition: capabilities.hh:27
Specialize with 'true' if implementation guarantees a conforming leaf grid. (default=false)
Definition: capabilities.hh:115
Specialize with 'true' if implementation guarantees conforming level grids. (default=false)
Definition: capabilities.hh:106
Static tag representing a codimension.
Definition: dimension.hh:24
Traits associated with a specific codim.
Definition: grid.hh:1035
A traits struct that collects all associated types of one grid model.
Definition: grid.hh:1013
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)