Dune Core Modules (2.4.1)

type.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_GEOMETRY_TYPE_HH
4#define DUNE_GEOMETRY_TYPE_HH
5
10#include <cassert>
11
13#include <dune/common/unused.hh>
14
15namespace Dune
16{
25 {
26 public:
29 enum BasicType {
35 none
36 };
37
39 enum Binary {
40 b0001 = 1,
41 b0011 = 3,
42 b0101 = 5,
43 b0111 = 7
44 };
45 private:
46
48 unsigned int topologyId_;
49
51 unsigned char dim_ : 7;
52
54 bool none_ : 1;
55
56 public:
59 : topologyId_(0), dim_(0), none_(true)
60 {}
61
63 GeometryType(BasicType basicType, unsigned int dim)
64 : topologyId_(0), dim_(dim), none_((basicType == GeometryType::none) ? true : false)
65 {
66 if (dim < 2)
67 return;
68 switch( basicType )
69 {
72 break;
75 break;
77 if (dim == 3)
79 else
81 "Invalid basic geometry type: no pyramids for dimension " << dim << "." );
82 break;
84 if (dim == 3)
85 makePrism();
86 else
88 "Invalid basic geometry type: no prisms for dimension " << dim << "." );
89 break;
91 break;
92 default :
94 "Invalid basic geometry type: " << basicType << " for dimension " << dim << "." );
95 }
96 }
97
103 GeometryType(unsigned int topologyId, unsigned int dim)
104 : topologyId_(topologyId), dim_(dim), none_(false)
105 {}
106
117 template<class TopologyType>
118 explicit GeometryType(TopologyType t)
119 : topologyId_(TopologyType::id), dim_(TopologyType::dimension), none_(false)
120 {
122 }
123
125 explicit GeometryType(unsigned int dim)
126 : topologyId_(0), dim_(dim), none_(false)
127 {
128 assert(dim < 2);
129 }
130
132 // We need this constructor for "int" and "unsigned int",
133 // because otherwise GeometryType(int) would try to call the
134 // generic GeometryType(TopologyType) constructor
135 explicit GeometryType(int dim)
136 : topologyId_(0), dim_(dim), none_(false)
137 {
138 assert(dim < 2);
139 }
140
143
145 void makeVertex() {
146 none_ = false;
147 dim_ = 0;
148 topologyId_ = 0;
149 }
150
152 void makeLine() {
153 none_ = false;
154 dim_ = 1;
155 topologyId_ = 0;
156 }
157
160 makeSimplex(2);
161 }
162
165 makeCube(2);
166 }
167
170 makeSimplex(3);
171 }
172
174 void makePyramid() {
175 none_ = false;
176 dim_ = 3;
177 topologyId_ = b0011;
178 }
179
181 void makePrism() {
182 none_ = false;
183 dim_ = 3;
184 topologyId_ = b0101; // (1 << (dim_-1)) - 1;
185 }
186
189 makeCube(3);
190 }
191
193 void makeSimplex(unsigned int dim) {
194 none_ = false;
195 dim_ = dim;
196 topologyId_ = 0;
197 }
198
200 void makeCube(unsigned int dim) {
201 none_ = false;
202 dim_ = dim;
203 topologyId_ = ((dim>1) ? ((1 << dim) - 1) : 0);
204 }
205
207 void makeNone(unsigned int dim) {
208 none_ = true;
209 dim_ = dim;
210 topologyId_ = 0;
211 }
212
217 void makeFromVertices(unsigned int dim, unsigned int vertices)
218 {
219 switch (dim)
220 {
221 case 0 :
222 makeVertex();
223 return;
224 case 1 :
225 makeLine();
226 return;
227 case 2 :
228 switch (vertices) {
229 case 3 :
230 makeSimplex(2);
231 return;
232 case 4 :
233 makeCube(2);
234 return;
235 default :
236 DUNE_THROW(NotImplemented, "2d elements with " << vertices << " corners are not supported!");
237 }
238 case 3 :
239 switch (vertices) {
240 case 4 :
241 makeSimplex(3);
242 return;
243 case 5 :
244 makePyramid();
245 return;
246 case 6 :
247 makePrism();
248 return;
249 case 8 :
250 makeCube(3);
251 return;
252 default :
253 DUNE_THROW(NotImplemented, "3d elements with " << vertices << " corners are not supported!");
254 }
255 default :
256 DUNE_THROW(NotImplemented, "makeFromVertices only implemented up to 3d");
257 }
258 }
259
266 bool isVertex() const {
267 return dim_==0;
268 }
269
271 bool isLine() const {
272 return dim_==1;
273 }
274
276 bool isTriangle() const {
277 return ! none_ && dim_==2 && (topologyId_ | 1) == b0001;
278 }
279
281 bool isQuadrilateral() const {
282 return ! none_ && dim_==2 && (topologyId_ | 1) == b0011;
283 }
284
286 bool isTetrahedron() const {
287 return ! none_ && dim_==3 && (topologyId_ | 1) == b0001;
288 }
289
291 bool isPyramid() const {
292 return ! none_ && dim_==3 && (topologyId_ | 1) == b0011;
293 }
294
296 bool isPrism() const {
297 return ! none_ && dim_==3 && (topologyId_ | 1) == b0101;
298 }
299
301 bool isHexahedron() const {
302 return ! none_ && dim_==3 && (topologyId_ | 1) == b0111;
303 }
304
306 bool isSimplex() const {
307 return ! none_ && (topologyId_ | 1) == 1;
308 }
309
311 bool isCube() const {
312 return ! none_ && ((topologyId_ ^ ((1 << dim_)-1)) >> 1 == 0);
313 }
314
316 bool isNone() const {
317 return none_;
318 }
319
321 unsigned int dim() const {
322 return dim_;
323 }
324
326 unsigned int id() const {
327 return topologyId_;
328 }
329
335 bool operator==(const GeometryType& other) const {
336 return ( ( none_ == other.none_ )
337 && ( ( none_ == true )
338 || ( ( dim_ == other.dim_ )
339 && ( (topologyId_ >> 1) == (other.topologyId_ >> 1) )
340 )
341 )
342 );
343 }
344
346 bool operator!=(const GeometryType& other) const {
347 return ! ((*this)==other);
348 }
349
351 bool operator < (const GeometryType& other) const {
352 return ( ( none_ < other.none_ )
353 || ( !( other.none_ < none_ )
354 && ( ( dim_ < other.dim_ )
355 || ( (other.dim_ == dim_)
356 && ((topologyId_ >> 1) < (other.topologyId_ >> 1) )
357 )
358 )
359 )
360 );
361 }
362 };
363
365 inline std::ostream& operator<< (std::ostream& s, const GeometryType& a)
366 {
367 if (a.isSimplex())
368 {
369 s << "(simplex, " << a.dim() << ")";
370 return s;
371 }
372 if (a.isCube())
373 {
374 s << "(cube, " << a.dim() << ")";
375 return s;
376 }
377 if (a.isPyramid())
378 {
379 s << "(pyramid, 3)";
380 return s;
381 }
382 if (a.isPrism())
383 {
384 s << "(prism, 3)";
385 return s;
386 }
387 if (a.isNone())
388 {
389 s << "(none, " << a.dim() << ")";
390 return s;
391 }
392 s << "(other [" << a.id() << "], " << a.dim() << ")";
393 return s;
394 }
395
397 inline std::ostream& operator<< (std::ostream& s, GeometryType::BasicType type)
398 {
399 switch (type) {
401 s << "simplex";
402 break;
403 case GeometryType::cube :
404 s << "cube";
405 break;
407 s << "pyramid";
408 break;
410 s << "prism";
411 break;
413 s << "other";
414 case GeometryType::none :
415 s << "none";
416 break;
417 default :
418 DUNE_THROW(Exception, "invalid GeometryType::BasicType");
419 }
420 return s;
421 }
422} // namespace Dune
423
424#endif // DUNE_GEOMETRY_TYPE_HH
Base class for Dune-Exceptions.
Definition: exceptions.hh:91
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
unsigned int dim() const
Return dimension of the type.
Definition: type.hh:321
bool isPrism() const
Return true if entity is a prism.
Definition: type.hh:296
void makeTriangle()
Make a triangle.
Definition: type.hh:159
bool isNone() const
Return true if entity is a singular of any dimension.
Definition: type.hh:316
Binary
A few binary constants.
Definition: type.hh:39
bool isLine() const
Return true if entity is a line segment.
Definition: type.hh:271
bool isCube() const
Return true if entity is a cube of any dimension.
Definition: type.hh:311
GeometryType(BasicType basicType, unsigned int dim)
Constructor, using the basic type and the dimension.
Definition: type.hh:63
void makeQuadrilateral()
Make a quadrilateral.
Definition: type.hh:164
bool isPyramid() const
Return true if entity is a pyramid.
Definition: type.hh:291
bool isTetrahedron() const
Return true if entity is a tetrahedron.
Definition: type.hh:286
void makeSimplex(unsigned int dim)
Make a simplex of given dimension.
Definition: type.hh:193
void makeTetrahedron()
Make a tetrahedron.
Definition: type.hh:169
void makeLine()
Make a line segment.
Definition: type.hh:152
GeometryType(int dim)
Constructor for vertices and segments.
Definition: type.hh:135
bool isVertex() const
Return true if entity is a vertex.
Definition: type.hh:266
void makePyramid()
Make a pyramid.
Definition: type.hh:174
void makeHexahedron()
Make a hexahedron.
Definition: type.hh:188
void makeFromVertices(unsigned int dim, unsigned int vertices)
Construct the correct geometry type given the dimension and the number of vertices.
Definition: type.hh:217
BasicType
Each entity can be tagged by one of these basic types plus its space dimension.
Definition: type.hh:29
@ cube
Cube element in any nonnegative dimension.
Definition: type.hh:31
@ simplex
Simplicial element in any nonnegative dimension.
Definition: type.hh:30
@ pyramid
Four sided pyramid in three dimensions.
Definition: type.hh:32
@ extended
Other, more general geometry, representable as topologyId.
Definition: type.hh:34
@ none
Generic element in any nonnegative dimension.
Definition: type.hh:35
@ prism
Prism element in three dimensions.
Definition: type.hh:33
void makePrism()
Make a prism.
Definition: type.hh:181
GeometryType()
Default constructor, not initializing anything.
Definition: type.hh:58
bool isHexahedron() const
Return true if entity is a hexahedron.
Definition: type.hh:301
void makeNone(unsigned int dim)
Make a singular of given dimension.
Definition: type.hh:207
void makeVertex()
Make a vertex.
Definition: type.hh:145
unsigned int id() const
Return the topology id the type.
Definition: type.hh:326
bool operator==(const GeometryType &other) const
Check for equality. This method knows that in dimension 0 and 1 all BasicTypes are equal.
Definition: type.hh:335
void makeCube(unsigned int dim)
Make a hypercube of given dimension.
Definition: type.hh:200
GeometryType(TopologyType t)
Constructor from static TopologyType class.
Definition: type.hh:118
bool operator!=(const GeometryType &other) const
Check for inequality.
Definition: type.hh:346
bool isQuadrilateral() const
Return true if entity is a quadrilateral.
Definition: type.hh:281
bool isTriangle() const
Return true if entity is a triangle.
Definition: type.hh:276
GeometryType(unsigned int topologyId, unsigned int dim)
Constructor, using the topologyId (integer) and the dimension.
Definition: type.hh:103
bool operator<(const GeometryType &other) const
less-than operation for use with maps
Definition: type.hh:351
bool isSimplex() const
Return true if entity is a simplex of any dimension.
Definition: type.hh:306
GeometryType(unsigned int dim)
Constructor for vertices and segments.
Definition: type.hh:125
Default exception for dummy implementations.
Definition: exceptions.hh:288
Default exception class for range errors.
Definition: exceptions.hh:279
A few common exception classes.
std::ostream & operator<<(std::ostream &s, const array< T, N > &e)
Output operator for array.
Definition: array.hh:26
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
Dune namespace.
Definition: alignment.hh:10
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)