Dune Core Modules (2.4.1)

topologytypes.hh
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_GENERICGEOMETRY_TOPOLOGYTYPES_HH
4#define DUNE_GEOMETRY_GENERICGEOMETRY_TOPOLOGYTYPES_HH
5
6#include <cassert>
7#include <string>
8
10#include <dune/common/unused.hh>
11
12namespace Dune
13{
14
15 namespace GenericGeometry
16 {
17
18 enum TopologyConstruction { pyramidConstruction = 0, prismConstruction = 1 };
19
20
21
22 // Basic Topology Types
23 // --------------------
24
25 struct Point
26 {
27 static const unsigned int dimension = 0;
28 static const unsigned int numCorners = 1;
29
30 static const unsigned int id = 0;
31
32 static std :: string name ()
33 {
34 return "p";
35 }
36 };
37
38
39 template< class BaseTopology >
40 struct Prism
41 {
42 static const unsigned int dimension = BaseTopology :: dimension + 1;
43 static const unsigned int numCorners = 2 * BaseTopology :: numCorners;
44
45 static const unsigned int id = BaseTopology::id | ((unsigned int)prismConstruction << (dimension-1));
46
47 static std :: string name ()
48 {
49 return BaseTopology :: name() + "l";
50 // return BaseTopology :: name() + "'";
51 }
52 };
53
54
55 template< class BaseTopology >
56 struct Pyramid
57 {
58 static const unsigned int dimension = BaseTopology :: dimension + 1;
59 static const unsigned int numCorners = BaseTopology :: numCorners + 1;
60
61 static const unsigned int id = BaseTopology::id | ((unsigned int)pyramidConstruction << (dimension-1));
62
63 static std :: string name ()
64 {
65 return BaseTopology :: name() + "o";
66 // return BaseTopology :: name() + "°";
67 }
68 };
69
70
71
72 template< class Topology >
73 struct BaseTopology;
74
75 template< class Base >
76 struct BaseTopology< Prism< Base > >
77 {
78 typedef Base type;
79 };
80
81 template< class Base >
82 struct BaseTopology< Pyramid< Base > >
83 {
84 typedef Base type;
85 };
86
87
88
89 template< class Topology >
90 struct IsSimplex
91 {
92 static const bool value = ((Topology::id >> 1) == 0);
93 };
94
95 template< class Topology >
96 struct IsCube
97 {
98 static const bool value = ((Topology::id | 1) == (1 << Topology::dimension) - 1);
99 };
100
101 template< class Topology >
102 struct IsHybrid
103 {
104 static const bool value
105 = !(IsSimplex< Topology >::value || IsCube< Topology >::value);
106 };
107
108 template< class Topology >
109 struct IsGeneralizedPrism
110 {
111 static const bool value = false;
112 };
113
114 template< class BaseTopology >
115 struct IsGeneralizedPrism< Prism< BaseTopology > >
116 {
117 static const bool value
118 = (IsGeneralizedPrism< BaseTopology >::value || IsSimplex< BaseTopology >::value);
119 };
120
121
122
123 // Dynamic Topology Properties
124 // ---------------------------
125
134 inline unsigned int numTopologies ( int dim )
135 {
136 return (1u << dim);
137 }
138
150 inline bool isPyramid ( unsigned int topologyId, int dim, int codim = 0 )
151 {
152 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
153 assert( (0 <= codim) && (codim < dim) );
154 return (((topologyId & ~1) & (1u << (dim-codim-1))) == 0);
155 }
156
168 inline bool isPrism ( unsigned int topologyId, int dim, int codim = 0 )
169 {
170 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
171 assert( (0 <= codim) && (codim < dim) );
172 return (( (topologyId | 1) & (1u << (dim-codim-1))) != 0);
173 }
174
187 inline bool isTopology ( TopologyConstruction construction, unsigned int topologyId, int dim, int codim = 0 )
188 {
189 assert( (dim > 0) && (topologyId < numTopologies( dim )) );
190 assert( (0 <= codim) && (codim <= dim) );
191 return (codim >= (dim-1)) || (((topologyId >> (dim-codim-1)) & 1) == (unsigned int)construction);
192 }
193
201 inline unsigned int baseTopologyId ( unsigned int topologyId, int dim, int codim = 1 )
202 {
203 assert( (dim >= 0) && (topologyId < numTopologies( dim )) );
204 assert( (0 <= codim) && (codim <= dim) );
205 return topologyId & ((1u << (dim-codim)) - 1);
206 }
207
208
209
210 // SimplexTopology
211 // ---------------
212
213 template< unsigned int dim >
214 struct SimplexTopology
215 {
216 typedef Pyramid< typename SimplexTopology< dim-1 >::type > type;
217 };
218
219 template<>
220 struct SimplexTopology< 0 >
221 {
222 typedef Point type;
223 };
224
225
226
227 // CubeTopology
228 // ------------
229
230 template< unsigned int dim >
231 struct CubeTopology
232 {
233 typedef Prism< typename CubeTopology< dim-1 >::type > type;
234 };
235
236 template<>
237 struct CubeTopology< 0 >
238 {
239 typedef Point type;
240 };
241
242
243
244 // PyramidTopology
245 // --------------
246
247 template< unsigned int dim >
248 struct PyramidTopology
249 {
250 typedef Pyramid< typename CubeTopology< dim-1 >::type > type;
251 };
252
253
254
255 // PrismTopology
256 // --------------
257
258 template< unsigned int dim >
259 struct PrismTopology
260 {
261 typedef Prism< typename SimplexTopology< dim-1 >::type > type;
262 };
263
264
265
266 // Topology
267 // --------
268
269 template< unsigned int id, unsigned int dim >
270 class Topology
271 {
272 static const unsigned int dimension = dim;
273
274 static_assert((id < (1 << dimension)), "id too large.");
275
276 static const bool isPrism = ((id >> (dimension-1)) != 0);
277
278 typedef typename Topology< (id & ~(1 << (dimension-1))), dimension-1 >::type
279 BaseTopology;
280
281 template< bool >
282 struct Prism
283 {
284 typedef GenericGeometry :: Prism< BaseTopology > type;
285 };
286
287 template< bool >
288 struct Pyramid
289 {
290 typedef GenericGeometry :: Pyramid< BaseTopology > type;
291 };
292
293 public:
294 typedef typename conditional< isPrism, Prism<true>, Pyramid<false> >::type::type type;
295 };
296
297 template< unsigned int id >
298 class Topology< id, 0 >
299 {
300 static const unsigned int dimension = 0;
301
302 static_assert((id < (1 << dimension)), "id too large.");
303
304 public:
305 typedef Point type;
306 };
307
308
309
310 // IfTopology
311 // ----------
312
313 template< template< class > class Operation, int dim, class Topology = Point >
314 class IfTopology
315 {
316 typedef IfTopology< Operation, dim-1, Prism< Topology > > IfPrism;
317 typedef IfTopology< Operation, dim-1, Pyramid< Topology > > IfPyramid;
318
319 public:
320 static void apply ( const unsigned int topologyId )
321 {
322 if( topologyId & 1 )
323 IfPrism::apply( topologyId >> 1 );
324 else
325 IfPyramid::apply( topologyId >> 1 );
326 }
327
328 template< class T1 >
329 static void apply ( const unsigned int topologyId, T1 &p1 )
330 {
331 if( topologyId & 1 )
332 IfPrism::apply( topologyId >> 1, p1 );
333 else
334 IfPyramid::apply( topologyId >> 1, p1 );
335 }
336
337 template< class T1, class T2 >
338 static void apply ( const unsigned int topologyId, T1 &p1, T2 &p2 )
339 {
340 if( topologyId & 1 )
341 IfPrism::apply( topologyId >> 1, p1, p2 );
342 else
343 IfPyramid::apply( topologyId >> 1, p1, p2 );
344 }
345
346 template< class T1, class T2, class T3 >
347 static void apply ( const unsigned int topologyId, T1 &p1, T2 &p2, T3 &p3 )
348 {
349 if( topologyId & 1 )
350 IfPrism::apply( topologyId >> 1, p1, p2, p3 );
351 else
352 IfPyramid::apply( topologyId >> 1, p1, p2, p3 );
353 }
354
355 template< class T1, class T2, class T3, class T4 >
356 static void apply ( const unsigned int topologyId, T1 &p1, T2 &p2, T3 &p3, T4 &p4 )
357 {
358 if( topologyId & 1 )
359 IfPrism::apply( topologyId >> 1, p1, p2, p3, p4 );
360 else
361 IfPyramid::apply( topologyId >> 1, p1, p2, p3, p4 );
362 }
363 };
364
365 template< template< class > class Operation, class Topology >
366 class IfTopology< Operation, 0, Topology >
367 {
368 public:
369 static void apply ( const unsigned int topologyId )
370 {
371 DUNE_UNUSED_PARAMETER(topologyId);
372 Operation< Topology >::apply();
373 }
374
375 template< class T1 >
376 static void apply ( const unsigned int topologyId, T1 &p1 )
377 {
378 DUNE_UNUSED_PARAMETER(topologyId);
379 Operation< Topology >::apply( p1 );
380 }
381
382 template< class T1, class T2 >
383 static void apply ( const unsigned int topologyId, T1 &p1, T2 &p2 )
384 {
385 DUNE_UNUSED_PARAMETER(topologyId);
386 Operation< Topology >::apply( p1, p2 );
387 }
388
389 template< class T1, class T2, class T3 >
390 static void apply ( const unsigned int topologyId, T1 &p1, T2 &p2, T3 &p3 )
391 {
392 DUNE_UNUSED_PARAMETER(topologyId);
393 Operation< Topology >::apply( p1, p2, p3 );
394 }
395
396 template< class T1, class T2, class T3, class T4 >
397 static void apply ( const unsigned int topologyId, T1 &p1, T2 &p2, T3 &p3, T4 &p4 )
398 {
399 DUNE_UNUSED_PARAMETER(topologyId);
400 Operation< Topology >::apply( p1, p2, p3, p4 );
401 }
402 };
403
404 }
405
406}
407
408#endif // DUNE_GEOMETRY_GENERICGEOMETRY_TOPOLOGYTYPES_HH
Dune namespace.
Definition: alignment.hh:10
Traits for type conversions and type information.
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 (Nov 21, 23:30, 2024)