omega_h
Reliable mesh adaptation
Omega_h_simplex.hpp
1 #ifndef OMEGA_H_SIMPLEX_HPP
2 #define OMEGA_H_SIMPLEX_HPP
3 
5 
6 /* \file Omega_h_simplex.hpp
7  \brief Describes the canonical local boundary connectivity
8  orderings for a single simplex, and other related properties
9  \details A simplex is a generalization of a triangle in arbitrary dimensions.
10  In Omega_h the relevant simplices are vertices, edges, triangles, and
11  tetrahedra.
12  */
13 
14 namespace Omega_h {
15 
23 constexpr OMEGA_H_INLINE Int simplex_down_template(
24  Int elem_dim, Int bdry_dim, Int which_bdry, Int which_vert) {
25  // clang-format off
26  return (elem_dim == 3 ?
27  (bdry_dim == 2 ?
28  (which_bdry == 0 ?
29  (which_vert == 0 ? 0 :
30  (which_vert == 1 ? 2 :
31  (which_vert == 2 ? 1 : -1))) :
32  (which_bdry == 1 ?
33  (which_vert == 0 ? 0 :
34  (which_vert == 1 ? 1 :
35  (which_vert == 2 ? 3 : -1))) :
36  (which_bdry == 2 ?
37  (which_vert == 0 ? 1 :
38  (which_vert == 1 ? 2 :
39  (which_vert == 2 ? 3 : -1))) :
40  (which_bdry == 3 ?
41  (which_vert == 0 ? 2 :
42  (which_vert == 1 ? 0 :
43  (which_vert == 2 ? 3 : -1))) : -1)))) :
44  (bdry_dim == 1 ?
45  (which_bdry == 0 ?
46  (which_vert == 0 ? 0 :
47  (which_vert == 1 ? 1 : -1)) :
48  (which_bdry == 1 ?
49  (which_vert == 0 ? 1 :
50  (which_vert == 1 ? 2 : -1)) :
51  (which_bdry == 2 ?
52  (which_vert == 0 ? 2 :
53  (which_vert == 1 ? 0 : -1)) :
54  (which_bdry == 3 ?
55  (which_vert == 0 ? 0 :
56  (which_vert == 1 ? 3 : -1)) :
57  (which_bdry == 4 ?
58  (which_vert == 0 ? 1 :
59  (which_vert == 1 ? 3 : -1)) :
60  (which_bdry == 5 ?
61  (which_vert == 0 ? 2 :
62  (which_vert == 1 ? 3 : -1)) : -1)))))) :
63  (bdry_dim == 0 ?
64  (which_bdry == 0 ? 0 :
65  (which_bdry == 1 ? 1 :
66  (which_bdry == 2 ? 2 :
67  (which_bdry == 3 ? 3 : -1)))) : -1))) :
68  (elem_dim == 2 ?
69  (bdry_dim == 1 ?
70  (which_bdry == 0 ?
71  (which_vert == 0 ? 0 :
72  (which_vert == 1 ? 1 : -1)) :
73  (which_bdry == 1 ?
74  (which_vert == 0 ? 1 :
75  (which_vert == 1 ? 2 : -1)) :
76  (which_bdry == 2 ?
77  (which_vert == 0 ? 2 :
78  (which_vert == 1 ? 0 : -1)) : -1))) :
79  (bdry_dim == 0 ?
80  (which_bdry == 0 ? 0 :
81  (which_bdry == 1 ? 1 :
82  (which_bdry == 2 ? 2 : -1))) : -1)) :
83  (elem_dim == 1 ?
84  (bdry_dim == 0 ?
85  (which_bdry == 0 ? 0 :
86  (which_bdry == 1 ? 1 : -1)) : -1) : -1)));
87  // clang-format on
88 }
89 
90 /* TODO: make these constexpr, either with C++14 or lots of
91  ternary operators */
92 
93 OMEGA_H_INLINE TemplateUp simplex_up_template(
94  Int elem_dim, Int bdry_dim, Int which_bdry, Int which_up) {
95  switch (elem_dim) {
96  case 3:
97  switch (bdry_dim) {
98  case 0:
99  switch (which_bdry) {
100  case 0:
101  switch (which_up) {
102  case 0:
103  return {0, 0, 0};
104  case 1:
105  return {2, 1, 0};
106  case 2:
107  return {3, 0, 0};
108  }
109  return {-1, -1, 0};
110  case 1:
111  switch (which_up) {
112  case 0:
113  return {1, 0, 0};
114  case 1:
115  return {0, 1, 0};
116  case 2:
117  return {4, 0, 0};
118  }
119  return {-1, -1, 0};
120  case 2:
121  switch (which_up) {
122  case 0:
123  return {2, 0, 0};
124  case 1:
125  return {1, 1, 0};
126  case 2:
127  return {5, 0, 0};
128  }
129  return {-1, -1, 0};
130  case 3:
131  switch (which_up) {
132  case 0:
133  return {5, 1, 0};
134  case 1:
135  return {4, 1, 0};
136  case 2:
137  return {3, 1, 0};
138  }
139  return {-1, -1, 0};
140  }
141  return {-1, -1, 0};
142  case 1:
143  switch (which_bdry) {
144  case 0:
145  switch (which_up) {
146  case 0:
147  return {0, 2, 1};
148  case 1:
149  return {1, 0, 0};
150  }
151  return {-1, -1, 0};
152  case 1:
153  switch (which_up) {
154  case 0:
155  return {0, 1, 1};
156  case 1:
157  return {2, 0, 0};
158  }
159  return {-1, -1, 0};
160  case 2:
161  switch (which_up) {
162  case 0:
163  return {0, 0, 1};
164  case 1:
165  return {3, 0, 0};
166  }
167  return {-1, -1, 0};
168  case 3:
169  switch (which_up) {
170  case 0:
171  return {1, 2, 1};
172  case 1:
173  return {3, 1, 0};
174  }
175  return {-1, -1, 0};
176  case 4:
177  switch (which_up) {
178  case 0:
179  return {2, 2, 1};
180  case 1:
181  return {1, 1, 0};
182  }
183  return {-1, -1, 0};
184  case 5:
185  switch (which_up) {
186  case 0:
187  return {3, 2, 1};
188  case 1:
189  return {2, 1, 0};
190  }
191  return {-1, -1, 0};
192  }
193  return {-1, -1, 0};
194  }
195  return {-1, -1, 0};
196  case 2:
197  switch (bdry_dim) {
198  case 0:
199  switch (which_bdry) {
200  case 0:
201  switch (which_up) {
202  case 0:
203  return {0, 0, 0};
204  case 1:
205  return {2, 1, 0};
206  }
207  return {-1, -1, 0};
208  case 1:
209  switch (which_up) {
210  case 0:
211  return {1, 0, 0};
212  case 1:
213  return {0, 1, 0};
214  }
215  return {-1, -1, 0};
216  case 2:
217  switch (which_up) {
218  case 0:
219  return {2, 0, 0};
220  case 1:
221  return {1, 1, 0};
222  }
223  return {-1, -1, 0};
224  }
225  return {-1, -1, 0};
226  }
227  return {-1, -1, 0};
228  }
229  return {-1, -1, 0};
230 };
231 
232 OMEGA_H_INLINE Int simplex_opposite_template(
233  Int elem_dim, Int bdry_dim, Int which_bdry) {
234  switch (elem_dim) {
235  case 3:
236  switch (bdry_dim) {
237  case 0:
238  switch (which_bdry) {
239  case 0:
240  return 2;
241  case 1:
242  return 3;
243  case 2:
244  return 1;
245  case 3:
246  return 0;
247  }
248  return -1;
249  case 1:
250  switch (which_bdry) {
251  case 0:
252  return 5;
253  case 1:
254  return 3;
255  case 2:
256  return 4;
257  case 3:
258  return 1;
259  case 4:
260  return 2;
261  case 5:
262  return 0;
263  }
264  return -1;
265  case 2:
266  switch (which_bdry) {
267  case 0:
268  return 3;
269  case 1:
270  return 2;
271  case 2:
272  return 0;
273  case 3:
274  return 1;
275  }
276  return -1;
277  }
278  return -1;
279  case 2:
280  switch (bdry_dim) {
281  case 0:
282  switch (which_bdry) {
283  case 0:
284  return 1;
285  case 1:
286  return 2;
287  case 2:
288  return 0;
289  }
290  return -1;
291  case 1:
292  switch (which_bdry) {
293  case 0:
294  return 2;
295  case 1:
296  return 0;
297  case 2:
298  return 1;
299  }
300  return -1;
301  }
302  return -1;
303  case 1:
304  switch (bdry_dim) {
305  case 0:
306  return (1 - which_bdry);
307  }
308  return -1;
309  }
310  return -1;
311 }
312 
313 OMEGA_H_INLINE constexpr Int simplex_degree(Int from_dim, Int to_dim) {
314  // clang-format off
315  return (from_dim == 0 ? 1 :
316  (from_dim == 1 ?
317  (to_dim == 0 ? 2 :
318  (to_dim == 1 ? 1 : -1)) :
319  (from_dim == 2 ?
320  (to_dim == 0 ? 3 :
321  (to_dim == 1 ? 3 :
322  (to_dim == 2 ? 1 : -1))) :
323  (from_dim == 3 ?
324  (to_dim == 0 ? 4 :
325  (to_dim == 1 ? 6 :
326  (to_dim == 2 ? 4 :
327  (to_dim == 3 ? 1 : -1)))) : -1))));
328  // clang-format on
329 }
330 
331 constexpr char const* simplex_singular_name(Int dim) {
332  return (dim == 3 ? "tet"
333  : (dim == 2 ? "triangle"
334  : (dim == 1 ? "edge"
335  : (dim == 0 ? "vertex" : nullptr))));
336 }
337 
338 constexpr char const* simplex_plural_name(Int dim) {
339  return (dim == 3
340  ? "tets"
341  : (dim == 2 ? "triangles"
342  : (dim == 1 ? "edges"
343  : (dim == 0 ? "vertices" : nullptr))));
344 }
345 
346 template <Int dim, Int low, Int high>
348 
349 template <>
350 struct SimplexAvgDegree<1, 0, 1> {
351  static constexpr Int value = 2;
352 };
353 
354 template <>
355 struct SimplexAvgDegree<2, 0, 1> {
356  static constexpr Int value = 6;
357 };
358 
359 template <>
360 struct SimplexAvgDegree<2, 0, 2> {
361  static constexpr Int value = 6;
362 };
363 
364 template <>
365 struct SimplexAvgDegree<3, 0, 1> {
366  static constexpr Int value = 14;
367 };
368 
369 template <>
370 struct SimplexAvgDegree<3, 0, 3> {
371  static constexpr Int value = 24;
372 };
373 
374 } // end namespace Omega_h
375 
376 #endif
Defines the TemplateUp class.
Definition: amr_mpi_test.cpp:6
constexpr OMEGA_H_INLINE Int simplex_down_template(Int elem_dim, Int bdry_dim, Int which_bdry, Int which_vert)
Relates bounding simplex vertices to the parent simplex's vertices.
Definition: Omega_h_simplex.hpp:23
Definition: Omega_h_simplex.hpp:347