Dune Core Modules (2.9.0)

onedgrid.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 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>
73 Traits;
74 };
75
76 //**********************************************************************
77 //
78 // --OneDGrid
79 //
80 //**********************************************************************
81
93 class OneDGrid : public GridDefaultImplementation <1, 1,typename OneDGridGeometry<0,1,OneDGrid>::ctype, OneDGridFamily>
94 {
95 // Grid and world dimension are hardwired in this grid
96 constexpr static int dim = 1;
97 constexpr static int dimworld = 1;
98
99 template <int , PartitionIteratorType, class >
100 friend class OneDGridLevelIterator;
101
102 friend class OneDGridHierarchicIterator<const OneDGrid>;
103
104 template <int codim_, int dim_, class GridImp_>
105 friend class OneDGridEntity;
106 friend class OneDGridHierarchicIterator<OneDGrid>;
107 friend class OneDGridLeafIntersection<const OneDGrid>;
108 friend class OneDGridLevelIntersection<const OneDGrid>;
109 friend class OneDGridLeafIntersectionIterator<const OneDGrid>;
110 friend class OneDGridLevelIntersectionIterator<const OneDGrid>;
111
112 friend class OneDGridLevelIndexSet<const OneDGrid>;
113 friend class OneDGridLeafIndexSet<const OneDGrid>;
114 friend class OneDGridIdSet<const OneDGrid>;
115
116 template <int codim_, PartitionIteratorType PiType_, class GridImp_>
117 friend class OneDGridLeafIterator;
118
119 friend class OneDGridLeafGridView<const OneDGrid>;
120 friend class OneDGridLevelGridView<const OneDGrid>;
121
122 template <class GridType_>
123 friend class GridFactory;
124
125 template<int codim_, int dim_, class GridImp_, template<int,int,class> class EntityImp_>
126 friend class Entity;
127
129 OneDGrid();
130
131 // **********************************************************
132 // The Interface Methods
133 // **********************************************************
134
135 public:
136
140
142 typedef OneDGridFamily GridFamily;
143
144 //Provides the standard grid types
146
148 OneDGrid(const std::vector<ctype>& coords);
149
151 OneDGrid(int numElements, const ctype& leftBoundary, const ctype& rightBoundary);
152
155
160 int maxLevel() const {return entityImps_.size()-1;}
161
163 template <typename Seed>
164 static typename Traits::template Codim<Seed::codimension>::Entity
165 entity(const Seed& seed)
166 {
167 const int codim = Seed::codimension;
168 return typename Traits::template Codim<codim>::Entity(OneDGridEntity<codim,dim,const OneDGrid>(seed.impl().target()));
169 }
170
171
174 int size (int level, int codim) const {
175 switch (codim)
176 {
177 case 0:
178 return elements(level).size();
179 case 1:
180 return vertices(level).size();
181 default:
182 return 0;
183 }
184 }
185
186
187
189 int size (int codim) const
190 {
191 return leafIndexSet().size(codim);
192 }
193
195 int size (int level, GeometryType type) const
196 {
197 // There is only one type for each codim
198 return size(level,1-type.dim());
199 }
200
202 int size (GeometryType type) const
203 {
204 return leafIndexSet().size(type);
205 }
206
212 size_t numBoundarySegments() const
213 {
214 return 2;
215 }
216
219 {
220 return idSet_;
221 }
222
225 {
226 return idSet_;
227 }
228
230 const Traits::LevelIndexSet& levelIndexSet(int level) const
231 {
232 if (! levelIndexSets_[level]) {
233 levelIndexSets_[level] =
234 new OneDGridLevelIndexSet<const OneDGrid>(*this, level);
235 levelIndexSets_[level]->update();
236 }
237
238 return * levelIndexSets_[level];
239 }
240
243 {
244 return leafIndexSet_;
245 }
246
247
255 bool mark(int refCount, const Traits::Codim<0>::Entity& e );
256
263 int getMark(const Traits::Codim<0>::Entity& e ) const;
264
266 bool preAdapt();
267
269 bool adapt();
270
272 void postAdapt();
273
274 // **********************************************************
275 // End of Interface Methods
276 // **********************************************************
277
283 COPY
284 };
285
288 refinementType_ = type;
289 }
290
296 void globalRefine(int refCount);
297
298 // dummy parallel functions
299
300 const Communication &comm () const
301 {
302 return ccobj;
303 }
304
305
306 private:
307
309 OneDGridList<OneDEntityImp<0> >& vertices(int level) {
310 return std::get<0>(entityImps_[level]);
311 }
312
314 const OneDGridList<OneDEntityImp<0> >& vertices(int level) const {
315 return std::get<0>(entityImps_[level]);
316 }
317
319 OneDGridList<OneDEntityImp<1> >& elements(int level) {
320 return std::get<1>(entityImps_[level]);
321 }
322
324 const OneDGridList<OneDEntityImp<1> >& elements(int level) const {
325 return std::get<1>(entityImps_[level]);
326 }
327
328 Communication ccobj;
329
331 void setIndices();
332
335 unsigned int getNextFreeId()
336 {
337 return freeIdCounter_++;
338 }
339
341 RefinementType refinementType_;
342
343 OneDGridList<OneDEntityImp<0> >::iterator getLeftUpperVertex(const OneDEntityImp<1>* eIt);
344
345 OneDGridList<OneDEntityImp<0> >::iterator getRightUpperVertex(const OneDEntityImp<1>* eIt);
346
350 OneDGridList<OneDEntityImp<1> >::iterator getLeftNeighborWithSon(OneDGridList<OneDEntityImp<1> >::iterator eIt);
351
352 // The vertices and elements of the grid hierarchy
353 std::vector<std::tuple<OneDGridList<OneDEntityImp<0> >,
354 OneDGridList<OneDEntityImp<1> > > > entityImps_;
355
356 // Our set of level indices
357 mutable std::vector<OneDGridLevelIndexSet<const OneDGrid>* > levelIndexSets_;
358
359 OneDGridLeafIndexSet<const OneDGrid> leafIndexSet_;
360
361 OneDGridIdSet<const OneDGrid> idSet_;
362
363 // Every entity gets a unique id, unless it is a copy of an entity on a coarser level.
364 // This is the counter that we use to create the unique id.
365 unsigned int freeIdCounter_;
366
370 bool reversedBoundarySegmentNumbering_;
371
372 }; // end Class OneDGrid
373
374 namespace Capabilities
375 {
387 template< >
389 {
390 static const bool v = true;
391 static const unsigned int topologyId = GeometryTypes::cube(1).id();
392 };
393
394
398 template<int cdim>
399 struct hasEntity< OneDGrid, cdim >
400 {
401 static const bool v = true;
402 };
403
408 template<int codim>
410 {
411 static const bool v = true;
412 };
413
417 template<>
419 {
420 static const bool v = true;
421 };
422
426 template<>
428 {
429 static const bool v = true;
430 };
431
432 }
433
434} // namespace Dune
435
436// Include the GridFactory specialization for OneDGrid, so everybody
437// who includes the grid also gets the factory. Since OneDGrid is
438// not a template class, it needs to be a complete type before
439// GridFactory<OneDGrid> can be defined. This is why the #include-
440// directive is at _the end_ of this file.
441#include <dune/grid/onedgrid/onedgridfactory.hh>
442
443
444#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:125
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:371
constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:376
Definition: grid.hh:862
Provide a generic factory class for unstructured grids.
Definition: gridfactory.hh:314
detected_or_fallback_t< DeprecatedCollectiveCommunication_t, Communication_t, typename GridFamily::Traits > Communication
A type that is a model of Dune::Communication. It provides a portable way for communication on the se...
Definition: grid.hh:525
Id Set Interface.
Definition: indexidset.hh:452
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
One-dimensional adaptive grid.
Definition: onedgrid.hh:94
OneDGridGeometry< 0, 1, OneDGrid >::ctype ctype
The type used to store coordinates.
Definition: onedgrid.hh:139
const Traits::LevelIndexSet & levelIndexSet(int level) const
Get an index set for the given level.
Definition: onedgrid.hh:230
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:224
int size(GeometryType type) const
number of leaf entities per geometry type in this process
Definition: onedgrid.hh:202
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:279
@ COPY
New level consists of the refined elements and the unrefined ones, too.
Definition: onedgrid.hh:283
@ LOCAL
New level consists only of the refined elements.
Definition: onedgrid.hh:281
size_t numBoundarySegments() const
Return the number of coarse grid boundary segments.
Definition: onedgrid.hh:212
~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:287
int size(int level, GeometryType type) const
number of entities per level and geometry type in this process
Definition: onedgrid.hh:195
int size(int level, int codim) const
Number of grid entities per level and codim.
Definition: onedgrid.hh:174
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:242
const Traits::GlobalIdSet & globalIdSet() const
Get the set of global ids.
Definition: onedgrid.hh:218
static Traits::template Codim< Seed::codimension >::Entity entity(const Seed &seed)
Create an Entity from an EntitySeed.
Definition: onedgrid.hh:165
int size(int codim) const
number of leaf entities per codim in this process
Definition: onedgrid.hh:189
OneDGridFamily GridFamily
GridFamily of OneDGrid.
Definition: onedgrid.hh:142
int maxLevel() const
Return maximum level defined in this grid.
Definition: onedgrid.hh:160
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.
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:472
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:1017
A traits struct that collects all associated types of one grid model.
Definition: grid.hh:995
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 (Jul 15, 22:36, 2024)