Dune Core Modules (2.9.0)

entity.hh
1#ifndef DUNE_SPGRID_ENTITY_HH
2#define DUNE_SPGRID_ENTITY_HH
3
4#include <utility>
5
7
8#include <dune/grid/common/gridenums.hh>
9
11#include <dune/grid/spgrid/geometry.hh>
12
13namespace Dune
14{
15
16 // Internal Forward Declarations
17 // -----------------------------
18
19 template< int codim, int dim, class Grid >
20 class SPEntity;
21
22
23
24 // External Forward Declarations
25 // -----------------------------
26
27 template< class, int >
28 class SPHierarchicIterator;
29
30
31
32 // SPBasicEntity
33 // -------------
34
35 template< int codim, class Grid >
36 class SPBasicEntity
37 {
38 typedef SPBasicEntity< codim, Grid > This;
39
40 public:
41 typedef __SPGrid::EntityInfo< Grid, codim > EntityInfo;
42 typedef typename EntityInfo::GridLevel GridLevel;
43 typedef typename EntityInfo::Traits Traits;
44
45 static const int dimension = EntityInfo::dimension;
46 static const int codimension = EntityInfo::codimension;
47 static const int mydimension = EntityInfo::mydimension;
48
49 typedef typename Traits::template Codim< codimension >::Entity Entity;
50 typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed;
51 typedef typename Traits::template Codim< codimension >::Geometry Geometry;
52 typedef typename Traits::template Codim< codimension >::LocalGeometry LocalGeometry;
53
54 typedef typename Traits::HierarchicIterator HierarchicIterator;
55
56 protected:
57 typedef SPGeometry< mydimension, dimension, Grid > GeometryImpl;
58 typedef SPEntitySeed< codimension, Grid > EntitySeedImpl;
59
60 typedef SPHierarchicIterator< Grid, codimension > HierarchicIteratorImpl;
61
62 public:
63 SPBasicEntity () {}
64
65 explicit SPBasicEntity ( const EntityInfo &entityInfo )
66 : entityInfo_( entityInfo )
67 {}
68
69 int level () const
70 {
71 return gridLevel().level();
72 }
73
74 bool isLeaf () const
75 {
76 return (level() == entityInfo().gridLevel().grid().maxLevel());
77 }
78
79 PartitionType partitionType () const
80 {
81 return entityInfo().partitionType();
82 }
83
84 GeometryType type () const { return GeometryTypes::cube( mydimension ); }
85
86 Geometry geometry () const
87 {
88 return Geometry( GeometryImpl( entityInfo_ ) );
89 }
90
91 bool equals ( const This &other ) const
92 {
93 return entityInfo().equals( other.entityInfo() );
94 }
95
96 EntitySeed seed () const
97 {
98 return EntitySeed( EntitySeedImpl( level(), entityInfo().id(), entityInfo().partitionNumber() ) );
99 }
100
101 unsigned int subEntities ( unsigned int cd ) const
102 {
103 return gridLevel().template referenceCube< codim >().count( cd-codim );
104 }
105
106 bool hasFather () const { return ((level() > 0) && entityInfo().hasFather()); }
107
108 Entity father () const
109 {
110 SPEntity< codimension, dimension, Grid > father( entityInfo() );
111 father.entityInfo().up();
112 return Entity( std::move( father ) );
113 }
114
115 HierarchicIterator hbegin ( int maxlevel ) const
116 {
117 assert( maxlevel >= level() );
118 return HierarchicIteratorImpl( entityInfo(), maxlevel );
119 }
120
121 HierarchicIterator hend ( int maxlevel ) const
122 {
123 assert( maxlevel >= level() );
124 return HierarchicIteratorImpl( entityInfo(), level() );
125 }
126
127 const EntityInfo &entityInfo () const { return entityInfo_; }
128 EntityInfo &entityInfo () { return entityInfo_; }
129
130 const GridLevel &gridLevel () const { return entityInfo().gridLevel(); }
131
132 const Grid &grid () const { return gridLevel().grid(); }
133
134 private:
135 EntityInfo entityInfo_;
136 };
137
138
139
140 // SPEntity
141 // --------
142
143 template< int codim, int dim, class Grid >
144 class SPEntity
145 : public SPBasicEntity< codim, Grid >
146 {
147 typedef SPEntity< codim, dim, Grid > This;
148 typedef SPBasicEntity< codim, Grid > Base;
149
150 public:
151 typedef typename Base::EntityInfo EntityInfo;
152 typedef typename Base::GridLevel GridLevel;
153
154 typedef typename GridLevel::MultiIndex MultiIndex;
155
156 SPEntity () {}
157
158 explicit SPEntity ( const EntityInfo &entityInfo )
159 : Base( entityInfo )
160 {}
161
162 SPEntity ( const GridLevel &gridLevel, const MultiIndex &id, unsigned int partitionNumber )
163 : Base( EntityInfo( gridLevel, id, partitionNumber ) )
164 {}
165 };
166
167
168
169 // SPEntity (for codimension 0)
170 // ----------------------------
171
172 template< int dim, class Grid >
173 class SPEntity< 0, dim, Grid >
174 : public SPBasicEntity< 0, Grid >
175 {
176 typedef SPEntity< 0, dim, Grid > This;
177 typedef SPBasicEntity< 0, Grid > Base;
178
179 public:
180 typedef typename Base::EntityInfo EntityInfo;
181 typedef typename Base::GridLevel GridLevel;
182 typedef typename Base::Traits Traits;
183
184 static const int dimension = Base::dimension;
185
186 typedef typename Base::Geometry Geometry;
187 typedef typename Base::LocalGeometry LocalGeometry;
188
189 template< int codim >
190 struct Codim
191 {
192 typedef typename Traits::template Codim< codim >::Entity Entity;
193 };
194
195 typedef typename GridLevel::MultiIndex MultiIndex;
196
197 protected:
198 typedef typename GridLevel::Mesh Mesh;
199
200 static const int numFaces = GridLevel::ReferenceCube::numFaces;
201
202 public:
203 SPEntity () {}
204
205 explicit SPEntity ( const EntityInfo &entityInfo )
206 : Base( entityInfo )
207 {}
208
209 SPEntity ( const GridLevel &gridLevel, const MultiIndex &id, unsigned int partitionNumber )
210 : Base( EntityInfo( gridLevel, id, partitionNumber ) )
211 {}
212
213 using Base::entityInfo;
214 using Base::gridLevel;
215
216 template< int codim >
217 typename Codim< codim >::Entity subEntity ( int i ) const;
218
219 bool hasBoundaryIntersections () const;
220
221 LocalGeometry geometryInFather () const
222 {
223 return gridLevel().geometryInFather( entityInfo().id() );
224 }
225
226 bool isRegular () const { return true; }
227 bool isNew () const { return false; }
228 bool mightVanish () const { return false; }
229 };
230
231
232
233 // Implementation of SPEntity (for codimension 0)
234 // ----------------------------------------------
235
236
237 template< int dim, class Grid >
238 template< int codim >
239 inline typename SPEntity< 0, dim, Grid >::template Codim< codim >::Entity
240 SPEntity< 0, dim, Grid >::subEntity ( int i ) const
241 {
242 typedef typename SPEntity< 0, dim, Grid >::template Codim< codim >::Entity SubEntity;
243 typedef SPEntity< codim, dimension, Grid > SubEntityImpl;
244
245 // warning: this is only true for closed partitions
246 const unsigned int partitionNumber = entityInfo().partitionNumber();
247 MultiIndex id = entityInfo().id();
248 id += gridLevel().referenceCube().subId( codim, i );
249 __SPGrid::EntityInfo< Grid, codim > subInfo( gridLevel(), id, partitionNumber );
250 return SubEntity( SubEntityImpl( std::move( subInfo ) ) );
251 }
252
253
254 template< int dim, class Grid >
255 inline bool SPEntity< 0, dim, Grid >::hasBoundaryIntersections () const
256 {
257 const Mesh &globalMesh = gridLevel().globalMesh();
258 const MultiIndex &id = entityInfo().id();
259
260 bool hasBoundaryIntersections = false;
261 for( int i = 0; i < dimension; ++i )
262 {
263 hasBoundaryIntersections |= (id[ i ] == 2*globalMesh.begin()[ i ] + 1);
264 hasBoundaryIntersections |= (id[ i ] == 2*globalMesh.end()[ i ] - 1);
265 }
266 return hasBoundaryIntersections;
267 }
268
269} // namespace Dune
270
271#endif // #ifndef DUNE_SPGRID_ENTITY_HH
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
entity seed for SPGrid
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:30
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:472
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:402
Dune namespace.
Definition: alignedallocator.hh:13
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)