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