Dune Core Modules (2.3.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_(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;
92 break;
93 default :
95 "Invalid basic geometry type: " << basicType << " for dimension " << dim << "." );
96 }
97 }
98
104 GeometryType(unsigned int topologyId, unsigned int dim)
105 : topologyId_(topologyId), dim_(dim), none_(false)
106 {}
107
118 template<class TopologyType>
119 explicit GeometryType(TopologyType t)
120 : topologyId_(TopologyType::id), dim_(TopologyType::dimension), none_(false)
121 {
123 }
124
126 explicit GeometryType(unsigned int dim)
127 : topologyId_(0), dim_(dim), none_(false)
128 {
129 assert(dim < 2);
130 }
131
133 // We need this constructor for "int" and "unsigned int",
134 // because otherwise GeometryType(int) would try to call the
135 // generic GeometryType(TopologyType) constructor
136 explicit GeometryType(int dim)
137 : topologyId_(0), dim_(dim), none_(false)
138 {
139 assert(dim < 2);
140 }
141
144
146 void makeVertex() {
147 none_ = false;
148 dim_ = 0;
149 topologyId_ = 0;
150 }
151
153 void makeLine() {
154 none_ = false;
155 dim_ = 1;
156 topologyId_ = 0;
157 }
158
161 makeSimplex(2);
162 }
163
166 makeCube(2);
167 }
168
171 makeSimplex(3);
172 }
173
175 void makePyramid() {
176 none_ = false;
177 dim_ = 3;
178 topologyId_ = b0011;
179 }
180
182 void makePrism() {
183 none_ = false;
184 dim_ = 3;
185 topologyId_ = b0101; // (1 << (dim_-1)) - 1;
186 }
187
190 makeCube(3);
191 }
192
194 void makeSimplex(unsigned int dim) {
195 none_ = false;
196 dim_ = dim;
197 topologyId_ = 0;
198 }
199
201 void makeCube(unsigned int dim) {
202 none_ = false;
203 dim_ = dim;
204 topologyId_ = ((dim>1) ? ((1 << dim) - 1) : 0);
205 }
206
208 void makeNone(unsigned int dim) {
209 none_ = true;
210 dim_ = dim;
211 topologyId_ = 0;
212 }
213
218 void makeFromVertices(unsigned int dim, unsigned int vertices)
219 {
220 switch (dim)
221 {
222 case 0 :
223 makeVertex();
224 return;
225 case 1 :
226 makeLine();
227 return;
228 case 2 :
229 switch (vertices) {
230 case 3 :
231 makeSimplex(2);
232 return;
233 case 4 :
234 makeCube(2);
235 return;
236 default :
237 DUNE_THROW(NotImplemented, "2d elements with " << vertices << " corners are not supported!");
238 }
239 case 3 :
240 switch (vertices) {
241 case 4 :
242 makeSimplex(3);
243 return;
244 case 5 :
245 makePyramid();
246 return;
247 case 6 :
248 makePrism();
249 return;
250 case 8 :
251 makeCube(3);
252 return;
253 default :
254 DUNE_THROW(NotImplemented, "3d elements with " << vertices << " corners are not supported!");
255 }
256 default :
257 DUNE_THROW(NotImplemented, "makeFromVertices only implemented up to 3d");
258 }
259 }
260
267 bool isVertex() const {
268 return dim_==0;
269 }
270
272 bool isLine() const {
273 return dim_==1;
274 }
275
277 bool isTriangle() const {
278 return ! none_ && dim_==2 && (topologyId_ | 1) == b0001;
279 }
280
282 bool isQuadrilateral() const {
283 return ! none_ && dim_==2 && (topologyId_ | 1) == b0011;
284 }
285
287 bool isTetrahedron() const {
288 return ! none_ && dim_==3 && (topologyId_ | 1) == b0001;
289 }
290
292 bool isPyramid() const {
293 return ! none_ && dim_==3 && (topologyId_ | 1) == b0011;
294 }
295
297 bool isPrism() const {
298 return ! none_ && dim_==3 && (topologyId_ | 1) == b0101;
299 }
300
302 bool isHexahedron() const {
303 return ! none_ && dim_==3 && (topologyId_ | 1) == b0111;
304 }
305
307 bool isSimplex() const {
308 return ! none_ && (topologyId_ | 1) == 1;
309 }
310
312 bool isCube() const {
313 return ! none_ && ((topologyId_ ^ ((1 << dim_)-1)) >> 1 == 0);
314 }
315
317 bool isNone() const {
318 return none_;
319 }
320
322 unsigned int dim() const {
323 return dim_;
324 }
325
327 unsigned int id() const {
328 return topologyId_;
329 }
330
336 bool operator==(const GeometryType& other) const {
337 return ( ( none_ == other.none_ )
338 && ( ( none_ == true )
339 || ( ( dim_ == other.dim_ )
340 && ( (topologyId_ >> 1) == (other.topologyId_ >> 1) )
341 )
342 )
343 );
344 }
345
347 bool operator!=(const GeometryType& other) const {
348 return ! ((*this)==other);
349 }
350
352 bool operator < (const GeometryType& other) const {
353 return ( ( none_ < other.none_ )
354 || ( !( other.none_ < none_ )
355 && ( ( dim_ < other.dim_ )
356 || ( (other.dim_ == dim_)
357 && ((topologyId_ >> 1) < (other.topologyId_ >> 1) )
358 )
359 )
360 )
361 );
362 }
363 };
364
366 inline std::ostream& operator<< (std::ostream& s, const GeometryType& a)
367 {
368 if (a.isSimplex())
369 {
370 s << "(simplex, " << a.dim() << ")";
371 return s;
372 }
373 if (a.isCube())
374 {
375 s << "(cube, " << a.dim() << ")";
376 return s;
377 }
378 if (a.isPyramid())
379 {
380 s << "(pyramid, 3)";
381 return s;
382 }
383 if (a.isPrism())
384 {
385 s << "(prism, 3)";
386 return s;
387 }
388 if (a.isNone())
389 {
390 s << "(none, " << a.dim() << ")";
391 return s;
392 }
393 s << "(other [" << a.id() << "], " << a.dim() << ")";
394 return s;
395 }
396
398 inline std::ostream& operator<< (std::ostream& s, GeometryType::BasicType type)
399 {
400 switch (type) {
402 s << "simplex";
403 break;
404 case GeometryType::cube :
405 s << "cube";
406 break;
408 s << "pyramid";
409 break;
411 s << "prism";
412 break;
414 s << "other";
415 case GeometryType::none :
416 s << "none";
417 break;
418 default :
419 DUNE_THROW(Exception, "invalid GeometryType::BasicType");
420 }
421 return s;
422 }
423} // namespace Dune
424
425#endif // DUNE_GEOMETRY_TYPE_HH
Base class for Dune-Exceptions.
Definition: exceptions.hh:92
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:322
bool isPrism() const
Return true if entity is a prism.
Definition: type.hh:297
void makeTriangle()
Make a triangle.
Definition: type.hh:160
bool isNone() const
Return true if entity is a singular of any dimension.
Definition: type.hh:317
Binary
A few binary constants.
Definition: type.hh:39
bool isLine() const
Return true if entity is a line segment.
Definition: type.hh:272
bool isCube() const
Return true if entity is a cube of any dimension.
Definition: type.hh:312
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:165
bool isPyramid() const
Return true if entity is a pyramid.
Definition: type.hh:292
bool isTetrahedron() const
Return true if entity is a tetrahedron.
Definition: type.hh:287
void makeSimplex(unsigned int dim)
Make a simplex of given dimension.
Definition: type.hh:194
void makeTetrahedron()
Make a tetrahedron.
Definition: type.hh:170
void makeLine()
Make a line segment.
Definition: type.hh:153
GeometryType(int dim)
Constructor for vertices and segments.
Definition: type.hh:136
bool isVertex() const
Return true if entity is a vertex.
Definition: type.hh:267
void makePyramid()
Make a pyramid.
Definition: type.hh:175
void makeHexahedron()
Make a hexahedron.
Definition: type.hh:189
void makeFromVertices(unsigned int dim, unsigned int vertices)
Construct the correct geometry type given the dimension and the number of vertices.
Definition: type.hh:218
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:182
GeometryType()
Default constructor, not initializing anything.
Definition: type.hh:58
bool isHexahedron() const
Return true if entity is a hexahedron.
Definition: type.hh:302
void makeNone(unsigned int dim)
Make a singular of given dimension.
Definition: type.hh:208
void makeVertex()
Make a vertex.
Definition: type.hh:146
unsigned int id() const
Return the topology id the type.
Definition: type.hh:327
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:336
void makeCube(unsigned int dim)
Make a hypercube of given dimension.
Definition: type.hh:201
GeometryType(TopologyType t)
Constructor from static TopologyType class.
Definition: type.hh:119
bool operator!=(const GeometryType &other) const
Check for inequality.
Definition: type.hh:347
bool isQuadrilateral() const
Return true if entity is a quadrilateral.
Definition: type.hh:282
bool isTriangle() const
Return true if entity is a triangle.
Definition: type.hh:277
GeometryType(unsigned int topologyId, unsigned int dim)
Constructor, using the topologyId (integer) and the dimension.
Definition: type.hh:104
bool operator<(const GeometryType &other) const
less-than operation for use with maps
Definition: type.hh:352
bool isSimplex() const
Return true if entity is a simplex of any dimension.
Definition: type.hh:307
GeometryType(unsigned int dim)
Constructor for vertices and segments.
Definition: type.hh:126
Default exception for dummy implementations.
Definition: exceptions.hh:289
Default exception class for range errors.
Definition: exceptions.hh:280
A few common exception classes.
std::ostream & operator<<(std::ostream &s, const array< T, N > &e)
Output operator for array.
Definition: array.hh:159
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Dune namespace.
Definition: alignment.hh:14
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 (Jul 15, 22:36, 2024)