dune-geometry  2.2.1
topologytypes.hh
Go to the documentation of this file.
1 #ifndef DUNE_GEOMETRY_GENERICGEOMETRY_TOPOLOGYTYPES_HH
2 #define DUNE_GEOMETRY_GENERICGEOMETRY_TOPOLOGYTYPES_HH
3 
4 #include <string>
5 
6 #include <dune/common/static_assert.hh>
7 #include <dune/common/typetraits.hh>
8 
9 namespace Dune
10 {
11 
12  namespace GenericGeometry
13  {
14 
15  struct Point
16  {
17  static const unsigned int dimension = 0;
18  static const unsigned int numCorners = 1;
19 
20  static const unsigned int id = 0;
21 
22  static std :: string name ()
23  {
24  return "p";
25  }
26  };
27 
28 
29  template< class BaseTopology >
30  struct Prism
31  {
32  static const unsigned int dimension = BaseTopology :: dimension + 1;
33  static const unsigned int numCorners = 2 * BaseTopology :: numCorners;
34 
35  static const unsigned int id = BaseTopology :: id + (1 << (dimension-1));
36 
37  static std :: string name ()
38  {
39  return BaseTopology :: name() + "l";
40  // return BaseTopology :: name() + "'";
41  }
42  };
43 
44 
45  template< class BaseTopology >
46  struct Pyramid
47  {
48  static const unsigned int dimension = BaseTopology :: dimension + 1;
49  static const unsigned int numCorners = BaseTopology :: numCorners + 1;
50 
51  static const unsigned int id = BaseTopology :: id;
52 
53  static std :: string name ()
54  {
55  return BaseTopology :: name() + "o";
56  // return BaseTopology :: name() + "°";
57  }
58  };
59 
60 
61 
62  template< class Topology >
63  struct BaseTopology;
64 
65  template< class Base >
66  struct BaseTopology< Prism< Base > >
67  {
68  typedef Base type;
69  };
70 
71  template< class Base >
72  struct BaseTopology< Pyramid< Base > >
73  {
74  typedef Base type;
75  };
76 
77 
78 
79  template< class Topology >
80  struct IsSimplex
81  {
82  static const bool value = ((Topology::id >> 1) == 0);
83  };
84 
85  template< class Topology >
86  struct IsCube
87  {
88  static const bool value = ((Topology::id | 1) == (1 << Topology::dimension) - 1);
89  };
90 
91  template< class Topology >
92  struct IsHybrid
93  {
94  static const bool value
96  };
97 
98  template< class Topology >
100  {
101  static const bool value = false;
102  };
103 
104  template< class BaseTopology >
105  struct IsGeneralizedPrism< Prism< BaseTopology > >
106  {
107  static const bool value
109  };
110 
111 
112 
113  // SimplexTopology
114  // ---------------
115 
116  template< unsigned int dim >
118  {
119  typedef Pyramid< typename SimplexTopology< dim-1 >::type > type;
120  };
121 
122  template<>
123  struct SimplexTopology< 0 >
124  {
125  typedef Point type;
126  };
127 
128 
129 
130  // CubeTopology
131  // ------------
132 
133  template< unsigned int dim >
135  {
136  typedef Prism< typename CubeTopology< dim-1 >::type > type;
137  };
138 
139  template<>
140  struct CubeTopology< 0 >
141  {
142  typedef Point type;
143  };
144 
145 
146 
147  // PyramidTopoogy
148  // --------------
149 
150  template< unsigned int dim >
152  {
153  typedef Pyramid< typename CubeTopology< dim-1 >::type > type;
154  };
155 
156 
157 
158  // PrismTopoogy
159  // --------------
160 
161  template< unsigned int dim >
163  {
164  typedef Prism< typename SimplexTopology< dim-1 >::type > type;
165  };
166 
167 
168 
169  // Topology
170  // --------
171 
172  template< unsigned int id, unsigned int dim >
173  class Topology
174  {
175  static const unsigned int dimension = dim;
176 
177  dune_static_assert( (id < (1 << dimension)), "id too large." );
178 
179  static const bool isPrism = ((id >> (dimension-1)) != 0);
180 
181  typedef typename Topology< (id & ~(1 << (dimension-1))), dimension-1 >::type
182  BaseTopology;
183 
184  template< bool >
185  struct Prism
186  {
188  };
189 
190  template< bool >
191  struct Pyramid
192  {
194  };
195 
196  public:
197  typedef typename SelectType< isPrism, Prism<true>, Pyramid<false> >::Type::type type;
198  };
199 
200  template< unsigned int id >
201  class Topology< id, 0 >
202  {
203  static const unsigned int dimension = 0;
204 
205  dune_static_assert( (id < (1 << dimension)), "id too large." );
206 
207  public:
208  typedef Point type;
209  };
210 
211 
212 
213  // IfTopology
214  // ----------
215 
216  template< template< class > class Operation, int dim, class Topology = Point >
218  {
219  typedef IfTopology< Operation, dim-1, Prism< Topology > > IfPrism;
220  typedef IfTopology< Operation, dim-1, Pyramid< Topology > > IfPyramid;
221 
222  public:
223  static void apply ( const unsigned int topologyId )
224  {
225  if( topologyId & 1 )
226  IfPrism::apply( topologyId >> 1 );
227  else
228  IfPyramid::apply( topologyId >> 1 );
229  }
230 
231  template< class T1 >
232  static void apply ( const unsigned int topologyId, T1 &p1 )
233  {
234  if( topologyId & 1 )
235  IfPrism::apply( topologyId >> 1, p1 );
236  else
237  IfPyramid::apply( topologyId >> 1, p1 );
238  }
239 
240  template< class T1, class T2 >
241  static void apply ( const unsigned int topologyId, T1 &p1, T2 &p2 )
242  {
243  if( topologyId & 1 )
244  IfPrism::apply( topologyId >> 1, p1, p2 );
245  else
246  IfPyramid::apply( topologyId >> 1, p1, p2 );
247  }
248 
249  template< class T1, class T2, class T3 >
250  static void apply ( const unsigned int topologyId, T1 &p1, T2 &p2, T3 &p3 )
251  {
252  if( topologyId & 1 )
253  IfPrism::apply( topologyId >> 1, p1, p2, p3 );
254  else
255  IfPyramid::apply( topologyId >> 1, p1, p2, p3 );
256  }
257 
258  template< class T1, class T2, class T3, class T4 >
259  static void apply ( const unsigned int topologyId, T1 &p1, T2 &p2, T3 &p3, T4 &p4 )
260  {
261  if( topologyId & 1 )
262  IfPrism::apply( topologyId >> 1, p1, p2, p3, p4 );
263  else
264  IfPyramid::apply( topologyId >> 1, p1, p2, p3, p4 );
265  }
266  };
267 
268  template< template< class > class Operation, class Topology >
269  class IfTopology< Operation, 0, Topology >
270  {
271  public:
272  static void apply ( const unsigned int topologyId )
273  {
275  }
276 
277  template< class T1 >
278  static void apply ( const unsigned int topologyId, T1 &p1 )
279  {
281  }
282 
283  template< class T1, class T2 >
284  static void apply ( const unsigned int topologyId, T1 &p1, T2 &p2 )
285  {
287  }
288 
289  template< class T1, class T2, class T3 >
290  static void apply ( const unsigned int topologyId, T1 &p1, T2 &p2, T3 &p3 )
291  {
292  Operation< Topology >::apply( p1, p2, p3 );
293  }
294 
295  template< class T1, class T2, class T3, class T4 >
296  static void apply ( const unsigned int topologyId, T1 &p1, T2 &p2, T3 &p3, T4 &p4 )
297  {
298  Operation< Topology >::apply( p1, p2, p3, p4 );
299  }
300  };
301 
302  }
303 
304 }
305 
306 #endif // DUNE_GEOMETRY_GENERICGEOMETRY_TOPOLOGYTYPES_HH