omega_h
Reliable mesh adaptation
Omega_h_hypercube.hpp
Go to the documentation of this file.
1 #ifndef OMEGA_H_HYPERCUBE_HPP
2 #define OMEGA_H_HYPERCUBE_HPP
3 
5 
14 namespace Omega_h {
15 
16 /* TODO: make these constexpr, either with C++14 or lots of
17  ternary operators */
18 
26 OMEGA_H_INLINE Int hypercube_down_template(
27  Int elem_dim, Int bdry_dim, Int which_bdry, Int which_vert) {
28  switch (elem_dim) {
29  case 1:
30  switch (bdry_dim) {
31  case 0:
32  return which_bdry;
33  }
34  return -1;
35  case 2:
36  switch (bdry_dim) {
37  case 0:
38  return which_bdry;
39  case 1:
40  switch (which_bdry) {
41  case 0:
42  switch (which_vert) {
43  case 0:
44  return 0;
45  case 1:
46  return 1;
47  }
48  return -1;
49  case 1:
50  switch (which_vert) {
51  case 0:
52  return 1;
53  case 1:
54  return 2;
55  }
56  return -1;
57  case 2:
58  switch (which_vert) {
59  case 0:
60  return 2;
61  case 1:
62  return 3;
63  }
64  return -1;
65  case 3:
66  switch (which_vert) {
67  case 0:
68  return 3;
69  case 1:
70  return 0;
71  }
72  return -1;
73  }
74  }
75  return -1;
76  case 3:
77  switch (bdry_dim) {
78  case 0:
79  return which_bdry;
80  case 1:
81  switch (which_bdry) {
82  case 0:
83  switch (which_vert) {
84  case 0:
85  return 0;
86  case 1:
87  return 1;
88  }
89  return -1;
90  case 1:
91  switch (which_vert) {
92  case 0:
93  return 1;
94  case 1:
95  return 2;
96  }
97  return -1;
98  case 2:
99  switch (which_vert) {
100  case 0:
101  return 2;
102  case 1:
103  return 3;
104  }
105  return -1;
106  case 3:
107  switch (which_vert) {
108  case 0:
109  return 3;
110  case 1:
111  return 0;
112  }
113  return -1;
114  case 4:
115  switch (which_vert) {
116  case 0:
117  return 0;
118  case 1:
119  return 4;
120  }
121  return -1;
122  case 5:
123  switch (which_vert) {
124  case 0:
125  return 1;
126  case 1:
127  return 5;
128  }
129  return -1;
130  case 6:
131  switch (which_vert) {
132  case 0:
133  return 2;
134  case 1:
135  return 6;
136  }
137  return -1;
138  case 7:
139  switch (which_vert) {
140  case 0:
141  return 3;
142  case 1:
143  return 7;
144  }
145  return -1;
146  case 8:
147  switch (which_vert) {
148  case 0:
149  return 4;
150  case 1:
151  return 5;
152  }
153  return -1;
154  case 9:
155  switch (which_vert) {
156  case 0:
157  return 5;
158  case 1:
159  return 6;
160  }
161  return -1;
162  case 10:
163  switch (which_vert) {
164  case 0:
165  return 6;
166  case 1:
167  return 7;
168  }
169  return -1;
170  case 11:
171  switch (which_vert) {
172  case 0:
173  return 7;
174  case 1:
175  return 4;
176  }
177  return -1;
178  }
179  return -1;
180  case 2:
181  switch (which_bdry) {
182  case 0:
183  switch (which_vert) {
184  case 0:
185  return 1;
186  case 1:
187  return 0;
188  case 2:
189  return 3;
190  case 3:
191  return 2;
192  }
193  return -1;
194  case 1:
195  switch (which_vert) {
196  case 0:
197  return 0;
198  case 1:
199  return 1;
200  case 2:
201  return 5;
202  case 3:
203  return 4;
204  }
205  return -1;
206  case 2:
207  switch (which_vert) {
208  case 0:
209  return 1;
210  case 1:
211  return 2;
212  case 2:
213  return 6;
214  case 3:
215  return 5;
216  }
217  return -1;
218  case 3:
219  switch (which_vert) {
220  case 0:
221  return 2;
222  case 1:
223  return 3;
224  case 2:
225  return 7;
226  case 3:
227  return 6;
228  }
229  return -1;
230  case 4:
231  switch (which_vert) {
232  case 0:
233  return 3;
234  case 1:
235  return 0;
236  case 2:
237  return 4;
238  case 3:
239  return 7;
240  }
241  return -1;
242  case 5:
243  switch (which_vert) {
244  case 0:
245  return 4;
246  case 1:
247  return 5;
248  case 2:
249  return 6;
250  case 3:
251  return 7;
252  }
253  return -1;
254  }
255  return -1;
256  }
257  return -1;
258  }
259  return -1;
260 }
261 
262 OMEGA_H_INLINE TemplateUp hypercube_up_template(
263  Int elem_dim, Int bdry_dim, Int which_bdry, Int which_up) {
264  switch (elem_dim) {
265  case 3:
266  switch (bdry_dim) {
267  case 0:
268  switch (which_bdry) {
269  case 0:
270  switch (which_up) {
271  case 0:
272  return {0, 0, 0};
273  case 1:
274  return {3, 1, 0};
275  case 2:
276  return {4, 0, 0};
277  }
278  return {-1, -1, 0};
279  case 1:
280  switch (which_up) {
281  case 0:
282  return {1, 0, 0};
283  case 1:
284  return {0, 1, 0};
285  case 2:
286  return {5, 0, 0};
287  }
288  return {-1, -1, 0};
289  case 2:
290  switch (which_up) {
291  case 0:
292  return {2, 0, 0};
293  case 1:
294  return {1, 1, 0};
295  case 2:
296  return {6, 0, 0};
297  }
298  return {-1, -1, 0};
299  case 3:
300  switch (which_up) {
301  case 0:
302  return {3, 0, 0};
303  case 1:
304  return {2, 1, 0};
305  case 2:
306  return {7, 0, 0};
307  }
308  return {-1, -1, 0};
309  case 4:
310  switch (which_up) {
311  case 0:
312  return {8, 0, 0};
313  case 1:
314  return {11, 1, 0};
315  case 2:
316  return {4, 1, 0};
317  }
318  return {-1, -1, 0};
319  case 5:
320  switch (which_up) {
321  case 0:
322  return {9, 0, 0};
323  case 1:
324  return {8, 1, 0};
325  case 2:
326  return {5, 1, 0};
327  }
328  return {-1, -1, 0};
329  case 6:
330  switch (which_up) {
331  case 0:
332  return {10, 0, 0};
333  case 1:
334  return {9, 1, 0};
335  case 2:
336  return {6, 1, 0};
337  }
338  return {-1, -1, 0};
339  case 7:
340  switch (which_up) {
341  case 0:
342  return {11, 0, 0};
343  case 1:
344  return {10, 1, 0};
345  case 2:
346  return {7, 1, 0};
347  }
348  return {-1, -1, 0};
349  }
350  return {-1, -1, 0};
351  case 1:
352  switch (which_bdry) {
353  case 0:
354  switch (which_up) {
355  case 0:
356  return {0, 0, 1};
357  case 1:
358  return {1, 0, 0};
359  }
360  return {-1, -1, 0};
361  case 1:
362  switch (which_up) {
363  case 0:
364  return {0, 3, 1};
365  case 1:
366  return {2, 0, 0};
367  }
368  return {-1, -1, 0};
369  case 2:
370  switch (which_up) {
371  case 0:
372  return {0, 2, 1};
373  case 1:
374  return {3, 0, 0};
375  }
376  return {-1, -1, 0};
377  case 3:
378  switch (which_up) {
379  case 0:
380  return {0, 1, 1};
381  case 1:
382  return {4, 0, 0};
383  }
384  return {-1, -1, 0};
385  case 4:
386  switch (which_up) {
387  case 0:
388  return {1, 3, 1};
389  case 1:
390  return {4, 1, 0};
391  }
392  return {-1, -1, 0};
393  case 5:
394  switch (which_up) {
395  case 0:
396  return {2, 3, 1};
397  case 1:
398  return {1, 1, 0};
399  }
400  return {-1, -1, 0};
401  case 6:
402  switch (which_up) {
403  case 0:
404  return {3, 3, 1};
405  case 1:
406  return {2, 1, 0};
407  }
408  return {-1, -1, 0};
409  case 7:
410  switch (which_up) {
411  case 0:
412  return {4, 3, 1};
413  case 1:
414  return {3, 1, 0};
415  }
416  return {-1, -1, 0};
417  case 8:
418  switch (which_up) {
419  case 0:
420  return {5, 0, 0};
421  case 1:
422  return {1, 2, 1};
423  }
424  return {-1, -1, 0};
425  case 9:
426  switch (which_up) {
427  case 0:
428  return {5, 1, 0};
429  case 1:
430  return {2, 2, 1};
431  }
432  return {-1, -1, 0};
433  case 10:
434  switch (which_up) {
435  case 0:
436  return {5, 2, 0};
437  case 1:
438  return {3, 2, 1};
439  }
440  return {-1, -1, 0};
441  case 11:
442  switch (which_up) {
443  case 0:
444  return {5, 3, 0};
445  case 1:
446  return {4, 2, 1};
447  }
448  return {-1, -1, 0};
449  }
450  }
451  return {-1, -1, 0};
452  case 2:
453  switch (bdry_dim) {
454  case 0:
455  switch (which_bdry) {
456  case 0:
457  switch (which_up) {
458  case 0:
459  return {3, 1, 0};
460  case 1:
461  return {0, 0, 0};
462  }
463  return {-1, -1, 0};
464  case 1:
465  switch (which_up) {
466  case 0:
467  return {0, 1, 0};
468  case 1:
469  return {1, 0, 0};
470  }
471  return {-1, -1, 0};
472  case 2:
473  switch (which_up) {
474  case 0:
475  return {1, 1, 0};
476  case 1:
477  return {2, 0, 0};
478  }
479  return {-1, -1, 0};
480  case 3:
481  switch (which_up) {
482  case 0:
483  return {2, 1, 0};
484  case 1:
485  return {3, 0, 0};
486  }
487  return {-1, -1, 0};
488  }
489  }
490  }
491  return {-1, -1, 0};
492 };
493 
494 OMEGA_H_INLINE constexpr Int hypercube_degree(Int from_dim, Int to_dim) {
495  // clang-format off
496  return (from_dim == 0 ?
497  (to_dim == 0 ? 1 : -1) :
498  (from_dim == 1 ?
499  (to_dim == 0 ? 2 :
500  (to_dim == 1 ? 1 : -1)) :
501  (from_dim == 2 ?
502  (to_dim == 0 ? 4 :
503  (to_dim == 1 ? 4 :
504  (to_dim == 2 ? 1 : -1))) :
505  (from_dim == 3 ?
506  (to_dim == 0 ? 8 :
507  (to_dim == 1 ? 12 :
508  (to_dim == 2 ? 6 :
509  (to_dim == 3 ? 1 : -1)))) : -1))));
510  // clang-format on
511 }
512 
513 constexpr char const* hypercube_singular_name(Int dim) {
514  return (dim == 3 ? "hex"
515  : (dim == 2 ? "quad"
516  : (dim == 1 ? "edge"
517  : (dim == 0 ? "vertex" : nullptr))));
518 }
519 
520 constexpr char const* hypercube_plural_name(Int dim) {
521  return (dim == 3
522  ? "hexes"
523  : (dim == 2 ? "quads"
524  : (dim == 1 ? "edges"
525  : (dim == 0 ? "vertices" : nullptr))));
526 }
527 
528 // every interior split entity can be seen as the dual of a corresponding
529 // boundary entity
530 OMEGA_H_INLINE constexpr Int hypercube_split_degree(
531  Int parent_dim, Int child_dim) {
532  return hypercube_degree(parent_dim, parent_dim - child_dim);
533 }
534 
535 OMEGA_H_INLINE SplitVertex hypercube_split_template(
536  Int parent_dim, Int child_dim, Int which_child, Int which_child_vtx) {
537  switch (parent_dim) {
538  case 1:
539  switch (child_dim) {
540  case 0:
541  return {1, 0};
542  case 1:
543  switch (which_child) {
544  case 0:
545  switch (which_child_vtx) {
546  case 0:
547  return {0, 0};
548  case 1:
549  return {1, 0};
550  }
551  return {-1, -1};
552  case 1:
553  switch (which_child_vtx) {
554  case 0:
555  return {1, 0};
556  case 1:
557  return {0, 1};
558  }
559  return {-1, -1};
560  }
561  }
562  return {-1, -1};
563  case 2:
564  switch (child_dim) {
565  case 0:
566  return {2, 0};
567  case 1:
568  switch (which_child_vtx) {
569  case 0:
570  return {1, which_child};
571  case 1:
572  return {2, 0};
573  }
574  return {-1, -1};
575  case 2:
576  switch (which_child) {
577  case 0:
578  switch (which_child_vtx) {
579  case 0:
580  return {0, 0};
581  case 1:
582  return {1, 0};
583  case 2:
584  return {2, 0};
585  case 3:
586  return {1, 3};
587  }
588  return {-1, -1};
589  case 1:
590  switch (which_child_vtx) {
591  case 0:
592  return {1, 0};
593  case 1:
594  return {0, 1};
595  case 2:
596  return {1, 1};
597  case 3:
598  return {2, 0};
599  }
600  return {-1, -1};
601  case 2:
602  switch (which_child_vtx) {
603  case 0:
604  return {2, 0};
605  case 1:
606  return {1, 1};
607  case 2:
608  return {0, 2};
609  case 3:
610  return {1, 2};
611  }
612  return {-1, -1};
613  case 3:
614  switch (which_child_vtx) {
615  case 0:
616  return {1, 3};
617  case 1:
618  return {2, 0};
619  case 2:
620  return {1, 2};
621  case 3:
622  return {0, 3};
623  }
624  return {-1, -1};
625  }
626  }
627  return {-1, -1};
628  case 3:
629  switch (child_dim) {
630  case 0:
631  return {3, 0};
632  case 1:
633  switch (which_child_vtx) {
634  case 0:
635  return {2, which_child};
636  case 1:
637  return {3, 0};
638  }
639  return {-1, -1};
640  case 2:
641  switch (which_child) {
642  case 0:
643  switch (which_child_vtx) {
644  case 0:
645  return {1, 0};
646  case 1:
647  return {2, 0};
648  case 2:
649  return {3, 0};
650  case 3:
651  return {2, 1};
652  }
653  return {-1, -1};
654  case 1:
655  switch (which_child_vtx) {
656  case 0:
657  return {2, 0};
658  case 1:
659  return {1, 1};
660  case 2:
661  return {2, 2};
662  case 3:
663  return {3, 0};
664  }
665  return {-1, -1};
666  case 2:
667  switch (which_child_vtx) {
668  case 0:
669  return {2, 0};
670  case 1:
671  return {1, 2};
672  case 2:
673  return {2, 3};
674  case 3:
675  return {3, 0};
676  }
677  return {-1, -1};
678  case 3:
679  switch (which_child_vtx) {
680  case 0:
681  return {1, 3};
682  case 1:
683  return {2, 0};
684  case 2:
685  return {3, 0};
686  case 3:
687  return {2, 4};
688  }
689  return {-1, -1};
690  case 4:
691  switch (which_child_vtx) {
692  case 0:
693  return {1, 4};
694  case 1:
695  return {2, 1};
696  case 2:
697  return {3, 0};
698  case 3:
699  return {2, 4};
700  }
701  return {-1, -1};
702  case 5:
703  switch (which_child_vtx) {
704  case 0:
705  return {2, 1};
706  case 1:
707  return {1, 5};
708  case 2:
709  return {2, 2};
710  case 3:
711  return {3, 0};
712  }
713  return {-1, -1};
714  case 6:
715  switch (which_child_vtx) {
716  case 0:
717  return {3, 0};
718  case 1:
719  return {2, 2};
720  case 2:
721  return {1, 6};
722  case 3:
723  return {2, 3};
724  }
725  return {-1, -1};
726  case 7:
727  switch (which_child_vtx) {
728  case 0:
729  return {2, 4};
730  case 1:
731  return {3, 0};
732  case 2:
733  return {2, 3};
734  case 3:
735  return {1, 7};
736  }
737  return {-1, -1};
738  case 8:
739  switch (which_child_vtx) {
740  case 0:
741  return {2, 1};
742  case 1:
743  return {3, 0};
744  case 2:
745  return {2, 5};
746  case 3:
747  return {1, 8};
748  }
749  return {-1, -1};
750  case 9:
751  switch (which_child_vtx) {
752  case 0:
753  return {3, 0};
754  case 1:
755  return {2, 2};
756  case 2:
757  return {1, 9};
758  case 3:
759  return {2, 5};
760  }
761  return {-1, -1};
762  case 10:
763  switch (which_child_vtx) {
764  case 0:
765  return {3, 0};
766  case 1:
767  return {2, 3};
768  case 2:
769  return {1, 10};
770  case 3:
771  return {2, 5};
772  }
773  return {-1, -1};
774  case 11:
775  switch (which_child_vtx) {
776  case 0:
777  return {2, 4};
778  case 1:
779  return {3, 0};
780  case 2:
781  return {2, 5};
782  case 3:
783  return {1, 11};
784  }
785  return {-1, -1};
786  }
787  return {-1, -1};
788  case 3:
789  switch (which_child) {
790  case 0:
791  switch (which_child_vtx) {
792  case 0:
793  return {0, 0};
794  case 1:
795  return {1, 0};
796  case 2:
797  return {2, 0};
798  case 3:
799  return {1, 3};
800  case 4:
801  return {1, 4};
802  case 5:
803  return {2, 1};
804  case 6:
805  return {3, 0};
806  case 7:
807  return {2, 4};
808  }
809  return {-1, -1};
810  case 1:
811  switch (which_child_vtx) {
812  case 0:
813  return {1, 0};
814  case 1:
815  return {0, 1};
816  case 2:
817  return {1, 1};
818  case 3:
819  return {2, 0};
820  case 4:
821  return {2, 1};
822  case 5:
823  return {1, 5};
824  case 6:
825  return {2, 2};
826  case 7:
827  return {3, 0};
828  }
829  return {-1, -1};
830  case 2:
831  switch (which_child_vtx) {
832  case 0:
833  return {2, 0};
834  case 1:
835  return {1, 1};
836  case 2:
837  return {0, 2};
838  case 3:
839  return {1, 2};
840  case 4:
841  return {3, 0};
842  case 5:
843  return {2, 2};
844  case 6:
845  return {1, 6};
846  case 7:
847  return {2, 3};
848  }
849  return {-1, -1};
850  case 3:
851  switch (which_child_vtx) {
852  case 0:
853  return {1, 3};
854  case 1:
855  return {2, 0};
856  case 2:
857  return {1, 2};
858  case 3:
859  return {0, 3};
860  case 4:
861  return {2, 4};
862  case 5:
863  return {3, 0};
864  case 6:
865  return {2, 3};
866  case 7:
867  return {1, 7};
868  }
869  return {-1, -1};
870  case 4:
871  switch (which_child_vtx) {
872  case 0:
873  return {1, 4};
874  case 1:
875  return {2, 1};
876  case 2:
877  return {3, 0};
878  case 3:
879  return {2, 4};
880  case 4:
881  return {0, 4};
882  case 5:
883  return {1, 8};
884  case 6:
885  return {2, 5};
886  case 7:
887  return {1, 11};
888  }
889  return {-1, -1};
890  case 5:
891  switch (which_child_vtx) {
892  case 0:
893  return {2, 1};
894  case 1:
895  return {1, 5};
896  case 2:
897  return {2, 2};
898  case 3:
899  return {3, 0};
900  case 4:
901  return {1, 8};
902  case 5:
903  return {0, 5};
904  case 6:
905  return {1, 9};
906  case 7:
907  return {2, 5};
908  }
909  return {-1, -1};
910  case 6:
911  switch (which_child_vtx) {
912  case 0:
913  return {3, 0};
914  case 1:
915  return {2, 2};
916  case 2:
917  return {1, 6};
918  case 3:
919  return {2, 3};
920  case 4:
921  return {2, 5};
922  case 5:
923  return {1, 9};
924  case 6:
925  return {0, 6};
926  case 7:
927  return {1, 10};
928  }
929  return {-1, -1};
930  case 7:
931  switch (which_child_vtx) {
932  case 0:
933  return {2, 4};
934  case 1:
935  return {3, 0};
936  case 2:
937  return {2, 3};
938  case 3:
939  return {1, 7};
940  case 4:
941  return {1, 11};
942  case 5:
943  return {2, 5};
944  case 6:
945  return {1, 10};
946  case 7:
947  return {0, 7};
948  }
949  return {-1, -1};
950  }
951  return {-1, -1};
952  }
953  return {-1, -1};
954  }
955  return {-1, -1};
956 }
957 
958 } // end namespace Omega_h
959 
960 #endif
Defines the TemplateUp class.
Definition: amr_mpi_test.cpp:6
OMEGA_H_INLINE Int hypercube_down_template(Int elem_dim, Int bdry_dim, Int which_bdry, Int which_vert)
Relates bounding hypercube vertices the parent hypercube's vertices.
Definition: Omega_h_hypercube.hpp:26