xref: /petsc/src/dm/impls/plex/tests/ex47.c (revision 09b68a49ed2854d1e4985cc2aa6af33c7c4e69b3)
1 static char help[] = "The main goal of this code is to retrieve the original element numbers as found in the "
2                      "initial partitions (sInitialPartition)... but after the call to DMPlexDistribute";
3 
4 #include <petsc.h>
5 
6 /* Coordinates of a 2x5 rectangular mesh of quads : */
7 PetscReal sCoords2x5Mesh[18][2] = {
8   {0.00000000000000000e+00, 0.00000000000000000e+00},
9   {2.00000000000000000e+00, 0.00000000000000000e+00},
10   {0.00000000000000000e+00, 1.00000000000000000e+00},
11   {2.00000000000000000e+00, 1.00000000000000000e+00},
12   {9.99999999997387978e-01, 0.00000000000000000e+00},
13   {9.99999999997387978e-01, 1.00000000000000000e+00},
14   {0.00000000000000000e+00, 2.00000000000000011e-01},
15   {0.00000000000000000e+00, 4.00000000000000022e-01},
16   {0.00000000000000000e+00, 5.99999999999999978e-01},
17   {0.00000000000000000e+00, 8.00000000000000044e-01},
18   {2.00000000000000000e+00, 2.00000000000000011e-01},
19   {2.00000000000000000e+00, 4.00000000000000022e-01},
20   {2.00000000000000000e+00, 5.99999999999999978e-01},
21   {2.00000000000000000e+00, 8.00000000000000044e-01},
22   {9.99999999997387756e-01, 2.00000000000000011e-01},
23   {9.99999999997387978e-01, 4.00000000000000022e-01},
24   {9.99999999997387978e-01, 6.00000000000000089e-01},
25   {9.99999999997388089e-01, 8.00000000000000044e-01}
26 };
27 
28 /* Connectivity of a 2x5 rectangular mesh of quads : */
29 const PetscInt sConnectivity2x5Mesh[10][4] = {
30   {0,  4,  14, 6 },
31   {6,  14, 15, 7 },
32   {7,  15, 16, 8 },
33   {8,  16, 17, 9 },
34   {9,  17, 5,  2 },
35   {4,  1,  10, 14},
36   {14, 10, 11, 15},
37   {15, 11, 12, 16},
38   {16, 12, 13, 17},
39   {17, 13, 3,  5 }
40 };
41 
42 /* Partitions of a 2x5 rectangular mesh of quads : */
43 const PetscInt sInitialPartition2x5Mesh[2][5] = {
44   {0, 2, 4, 6, 8},
45   {1, 3, 5, 7, 9}
46 };
47 
48 const PetscInt sNLoclCells2x5Mesh = 5;
49 const PetscInt sNGlobVerts2x5Mesh = 18;
50 
51 /* Mixed mesh : quads and triangles  (4 first quads above divided into triangles*/
52 /* Connectivity of a 2x5 rectangular mesh of quads : */
53 const PetscInt sConnectivityMixedTQMesh[14][4] = {
54   {0,  4,  6,  -1},
55   {4,  14, 6,  -1},
56   {6,  14, 7,  -1},
57   {14, 15, 7,  -1},
58   {7,  15, 8,  -1},
59   {15, 16, 8,  -1},
60   {8,  16, 9,  -1},
61   {16, 17, 9,  -1},
62   {9,  17, 5,  2 },
63   {4,  1,  10, 14},
64   {14, 10, 11, 15},
65   {15, 11, 12, 16},
66   {16, 12, 13, 17},
67   {17, 13, 3,  5 }
68 };
69 
70 /* Partitions for the rectangular mesh of quads and triangles: */
71 const PetscInt sInitialPartitionMixedTQMesh[2][7] = {
72   {0, 1, 4, 5, 8, 10, 12},
73   {2, 3, 6, 7, 9, 11, 13}
74 };
75 
76 const PetscInt sNLoclCellsMixedTQMesh = 7;
77 const PetscInt sNGlobVertsMixedTQMesh = 18;
78 
79 /* Prisms mesh */
80 PetscReal sCoordsPrismsMesh[125][3] = {
81   {2.24250931694056355e-01, 0.00000000000000000e+00, 0.00000000000000000e+00},
82   {2.20660660151932697e-01, 2.87419338850266937e-01, 0.00000000000000000e+00},
83   {0.00000000000000000e+00, 0.00000000000000000e+00, 2.70243537720639027e-01},
84   {2.32445727460992402e-01, 0.00000000000000000e+00, 2.60591845015572310e-01},
85   {2.41619971105419079e-01, 2.69894910706158231e-01, 2.42844781736072490e-01},
86   {0.00000000000000000e+00, 2.46523339883120779e-01, 2.69072907562752262e-01},
87   {0.00000000000000000e+00, 0.00000000000000000e+00, 0.00000000000000000e+00},
88   {1.00000000000000000e+00, 2.75433417601945563e-01, 0.00000000000000000e+00},
89   {1.00000000000000000e+00, 0.00000000000000000e+00, 2.33748605950385602e-01},
90   {7.32445727460992457e-01, 0.00000000000000000e+00, 2.42344379130445597e-01},
91   {1.00000000000000000e+00, 2.78258478013028610e-01, 2.57379172987105553e-01},
92   {1.00000000000000000e+00, 0.00000000000000000e+00, 0.00000000000000000e+00},
93   {7.49586880891153995e-01, 1.00000000000000000e+00, 0.00000000000000000e+00},
94   {1.00000000000000000e+00, 1.00000000000000000e+00, 2.51949651266657582e-01},
95   {7.41619971105419107e-01, 7.69894910706158120e-01, 2.33697838509081768e-01},
96   {1.00000000000000000e+00, 7.78258478013028610e-01, 2.66479695645241543e-01},
97   {7.55042653233710115e-01, 1.00000000000000000e+00, 2.58019637386860512e-01},
98   {1.00000000000000000e+00, 1.00000000000000000e+00, 0.00000000000000000e+00},
99   {0.00000000000000000e+00, 7.59235710423095789e-01, 0.00000000000000000e+00},
100   {0.00000000000000000e+00, 1.00000000000000000e+00, 2.17232187874490473e-01},
101   {0.00000000000000000e+00, 7.46523339883120807e-01, 2.42567232639677999e-01},
102   {2.55042653233710115e-01, 1.00000000000000000e+00, 2.40660905690776916e-01},
103   {0.00000000000000000e+00, 1.00000000000000000e+00, 0.00000000000000000e+00},
104   {2.38934376044866809e-01, 0.00000000000000000e+00, 1.00000000000000000e+00},
105   {2.18954188589218168e-01, 2.26916038449581692e-01, 1.00000000000000000e+00},
106   {2.39787449636397643e-01, 0.00000000000000000e+00, 7.60591845015572310e-01},
107   {2.40766735324061815e-01, 2.39643260505815608e-01, 7.42844781736072490e-01},
108   {0.00000000000000000e+00, 2.57448248192627016e-01, 7.69072907562752262e-01},
109   {0.00000000000000000e+00, 0.00000000000000000e+00, 1.00000000000000000e+00},
110   {1.00000000000000000e+00, 2.38666970143638080e-01, 1.00000000000000000e+00},
111   {7.39787449636397643e-01, 0.00000000000000000e+00, 7.42344379130445597e-01},
112   {1.00000000000000000e+00, 2.59875254283874868e-01, 7.57379172987105553e-01},
113   {1.00000000000000000e+00, 0.00000000000000000e+00, 1.00000000000000000e+00},
114   {7.76318984007844159e-01, 1.00000000000000000e+00, 1.00000000000000000e+00},
115   {7.40766735324061787e-01, 7.39643260505815636e-01, 7.33697838509081768e-01},
116   {1.00000000000000000e+00, 7.59875254283874924e-01, 7.66479695645241543e-01},
117   {7.68408704792055142e-01, 1.00000000000000000e+00, 7.58019637386860512e-01},
118   {1.00000000000000000e+00, 1.00000000000000000e+00, 1.00000000000000000e+00},
119   {0.00000000000000000e+00, 7.81085527042108207e-01, 1.00000000000000000e+00},
120   {0.00000000000000000e+00, 7.57448248192627016e-01, 7.42567232639678054e-01},
121   {2.68408704792055197e-01, 1.00000000000000000e+00, 7.40660905690776916e-01},
122   {0.00000000000000000e+00, 1.00000000000000000e+00, 1.00000000000000000e+00},
123   {7.24250931694056410e-01, 0.00000000000000000e+00, 0.00000000000000000e+00},
124   {7.24250931694056410e-01, 2.75433417601945563e-01, 0.00000000000000000e+00},
125   {4.44911591845989052e-01, 2.87419338850266937e-01, 0.00000000000000000e+00},
126   {4.64891454921984804e-01, 0.00000000000000000e+00, 2.50940152310505593e-01},
127   {4.74065698566411453e-01, 2.69894910706158231e-01, 2.33193089031005774e-01},
128   {4.48501863388112709e-01, 0.00000000000000000e+00, 0.00000000000000000e+00},
129   {7.20660660151932753e-01, 7.87419338850266937e-01, 0.00000000000000000e+00},
130   {7.20660660151932753e-01, 5.62852756452212555e-01, 0.00000000000000000e+00},
131   {2.20660660151932697e-01, 5.46655049273362614e-01, 0.00000000000000000e+00},
132   {4.83239942210838158e-01, 5.39789821412316462e-01, 2.15446025751505982e-01},
133   {7.41619971105419107e-01, 5.48153388719186951e-01, 2.48227882887665785e-01},
134   {2.41619971105419079e-01, 5.16418250589278927e-01, 2.41674151578185781e-01},
135   {4.41321320303865394e-01, 5.74838677700533873e-01, 0.00000000000000000e+00},
136   {1.00000000000000000e+00, 7.75433417601945507e-01, 0.00000000000000000e+00},
137   {1.00000000000000000e+00, 5.56516956026057219e-01, 2.81009740023825560e-01},
138   {7.32445727460992457e-01, 2.78258478013028610e-01, 2.65974946167165549e-01},
139   {1.00000000000000000e+00, 5.50866835203891125e-01, 0.00000000000000000e+00},
140   {0.00000000000000000e+00, 2.59235710423095733e-01, 0.00000000000000000e+00},
141   {0.00000000000000000e+00, 4.93046679766241558e-01, 2.67902277404865552e-01},
142   {2.55042653233710115e-01, 7.46523339883120807e-01, 2.65995950455964469e-01},
143   {0.00000000000000000e+00, 5.18471420846191466e-01, 0.00000000000000000e+00},
144   {2.49586880891154023e-01, 1.00000000000000000e+00, 0.00000000000000000e+00},
145   {2.49586880891154023e-01, 7.59235710423095789e-01, 0.00000000000000000e+00},
146   {4.70247541043086748e-01, 7.87419338850266937e-01, 0.00000000000000000e+00},
147   {5.10085306467420230e-01, 1.00000000000000000e+00, 2.64089623507063387e-01},
148   {4.96662624339129222e-01, 7.69894910706158231e-01, 2.39767824629284698e-01},
149   {4.99173761782308045e-01, 1.00000000000000000e+00, 0.00000000000000000e+00},
150   {0.00000000000000000e+00, 0.00000000000000000e+00, 7.70243537720639027e-01},
151   {2.40640523227928449e-01, 0.00000000000000000e+00, 5.21183690031144620e-01},
152   {2.62579282058905461e-01, 2.52370482562049525e-01, 4.85689563472144981e-01},
153   {0.00000000000000000e+00, 2.33810969343145825e-01, 5.38145815125504523e-01},
154   {0.00000000000000000e+00, 0.00000000000000000e+00, 5.40487075441278053e-01},
155   {1.00000000000000000e+00, 0.00000000000000000e+00, 7.33748605950385602e-01},
156   {7.40640523227928504e-01, 0.00000000000000000e+00, 4.84688758260891195e-01},
157   {1.00000000000000000e+00, 2.81083538424111656e-01, 5.14758345974211107e-01},
158   {1.00000000000000000e+00, 0.00000000000000000e+00, 4.67497211900771203e-01},
159   {7.38934376044866781e-01, 0.00000000000000000e+00, 1.00000000000000000e+00},
160   {4.79574899272795285e-01, 0.00000000000000000e+00, 7.50940152310505593e-01},
161   {4.77868752089733617e-01, 0.00000000000000000e+00, 1.00000000000000000e+00},
162   {1.00000000000000000e+00, 1.00000000000000000e+00, 7.51949651266657582e-01},
163   {7.62579282058905461e-01, 7.52370482562049525e-01, 4.67395677018163536e-01},
164   {1.00000000000000000e+00, 7.81083538424111712e-01, 5.32959391290483087e-01},
165   {7.60498425576266124e-01, 1.00000000000000000e+00, 5.16039274773721024e-01},
166   {1.00000000000000000e+00, 1.00000000000000000e+00, 5.03899302533315163e-01},
167   {7.18954188589218113e-01, 7.26916038449581636e-01, 1.00000000000000000e+00},
168   {4.81533470648123629e-01, 4.79286521011631217e-01, 7.15446025751505954e-01},
169   {4.57888564634085005e-01, 2.26916038449581692e-01, 1.00000000000000000e+00},
170   {4.95273172597062383e-01, 7.26916038449581636e-01, 1.00000000000000000e+00},
171   {4.37908377178436337e-01, 4.53832076899163384e-01, 1.00000000000000000e+00},
172   {1.00000000000000000e+00, 7.38666970143638135e-01, 1.00000000000000000e+00},
173   {1.00000000000000000e+00, 5.19750508567749736e-01, 7.81009740023825616e-01},
174   {7.38934376044866781e-01, 2.38666970143638080e-01, 1.00000000000000000e+00},
175   {7.18954188589218113e-01, 4.65583008593219771e-01, 1.00000000000000000e+00},
176   {1.00000000000000000e+00, 4.77333940287276159e-01, 1.00000000000000000e+00},
177   {0.00000000000000000e+00, 1.00000000000000000e+00, 7.17232187874490501e-01},
178   {0.00000000000000000e+00, 7.33810969343145825e-01, 4.85134465279355998e-01},
179   {2.60498425576266179e-01, 1.00000000000000000e+00, 4.81321811381553832e-01},
180   {0.00000000000000000e+00, 1.00000000000000000e+00, 4.34464375748980947e-01},
181   {0.00000000000000000e+00, 2.81085527042108152e-01, 1.00000000000000000e+00},
182   {0.00000000000000000e+00, 5.14896496385254032e-01, 7.67902277404865607e-01},
183   {2.76318984007844215e-01, 7.81085527042108207e-01, 1.00000000000000000e+00},
184   {2.18954188589218168e-01, 5.08001565491689844e-01, 1.00000000000000000e+00},
185   {0.00000000000000000e+00, 5.62171054084216304e-01, 1.00000000000000000e+00},
186   {2.76318984007844215e-01, 1.00000000000000000e+00, 1.00000000000000000e+00},
187   {5.36817409584110394e-01, 1.00000000000000000e+00, 7.64089623507063331e-01},
188   {5.52637968015688430e-01, 1.00000000000000000e+00, 1.00000000000000000e+00},
189   {5.03219805286833965e-01, 2.52370482562049525e-01, 4.66386178062011547e-01},
190   {4.80554184960459430e-01, 2.39643260505815608e-01, 7.33193089031005774e-01},
191   {4.81281046455856898e-01, 0.00000000000000000e+00, 5.01880304621011186e-01},
192   {7.62579282058905461e-01, 5.33454020986161126e-01, 4.96455765775331570e-01},
193   {2.62579282058905461e-01, 4.86181451905195350e-01, 4.83348303156371562e-01},
194   {7.40766735324061787e-01, 4.99518514789690449e-01, 7.48227882887665841e-01},
195   {2.40766735324061815e-01, 4.97091508698442541e-01, 7.41674151578185725e-01},
196   {5.25158564117810922e-01, 5.04740965124099050e-01, 4.30892051503011964e-01},
197   {7.40640523227928504e-01, 2.81083538424111656e-01, 5.31949892334331098e-01},
198   {7.39787449636397643e-01, 2.59875254283874868e-01, 7.65974946167165549e-01},
199   {1.00000000000000000e+00, 5.62167076848223313e-01, 5.62019480047651121e-01},
200   {2.60498425576266179e-01, 7.33810969343145825e-01, 5.31991900911928939e-01},
201   {2.68408704792055197e-01, 7.57448248192627016e-01, 7.65995950455964469e-01},
202   {0.00000000000000000e+00, 4.67621938686291649e-01, 5.35804554809731104e-01},
203   {5.23077707635171585e-01, 7.52370482562049525e-01, 4.79535649258569396e-01},
204   {5.09175440116116929e-01, 7.39643260505815636e-01, 7.39767824629284698e-01},
205   {5.20996851152532359e-01, 1.00000000000000000e+00, 5.28179247014126774e-01}
206 };
207 
208 const PetscInt sConnectivityPrismsMesh[128][6] = {
209   /* rank 0 */
210   {11,  7,   42,  8,   10,  9  },
211   {47,  42,  43,  45,  9,   57 },
212   {8,   10,  9,   77,  76,  75 },
213   {45,  9,   57,  110, 75,  116},
214   {17,  48,  55,  13,  14,  15 },
215   {58,  55,  49,  56,  15,  52 },
216   {13,  14,  15,  85,  82,  83 },
217   {56,  15,  52,  118, 83,  111},
218   {6,   0,   1,   2,   3,   4  },
219   {54,  1,   44,  51,  4,   46 },
220   {2,   3,   4,   73,  70,  71 },
221   {51,  4,   46,  115, 71,  108},
222   {58,  49,  43,  56,  52,  57 },
223   {47,  43,  44,  45,  57,  46 },
224   {56,  52,  57,  118, 111, 116},
225   {45,  57,  46,  110, 116, 108},
226   {77,  76,  75,  74,  31,  30 },
227   {110, 75,  116, 79,  30,  117},
228   {74,  31,  30,  32,  29,  78 },
229   {79,  30,  117, 80,  78,  93 },
230   {85,  82,  83,  81,  34,  35 },
231   {118, 83,  111, 92,  35,  113},
232   {81,  34,  35,  37,  86,  91 },
233   {92,  35,  113, 95,  91,  94 },
234   {73,  70,  71,  69,  25,  26 },
235   {115, 71,  108, 87,  26,  109},
236   {69,  25,  26,  28,  23,  24 },
237   {87,  26,  109, 90,  24,  88 },
238   {118, 111, 116, 92,  113, 117},
239   {110, 116, 108, 79,  117, 109},
240   {92,  113, 117, 95,  94,  93 },
241   {79,  117, 109, 80,  93,  88 },
242   {22,  18,  63,  19,  20,  21 },
243   {68,  63,  64,  66,  21,  61 },
244   {19,  20,  21,  99,  97,  98 },
245   {66,  21,  61,  124, 98,  119},
246   {6,   1,   59,  2,   4,   5  },
247   {62,  59,  50,  60,  5,   53 },
248   {2,   4,   5,   73,  71,  72 },
249   {60,  5,   53,  121, 72,  112},
250   {17,  12,  48,  13,  16,  14 },
251   {54,  48,  65,  51,  14,  67 },
252   {13,  16,  14,  85,  84,  82 },
253   {51,  14,  67,  115, 82,  122},
254   {62,  50,  64,  60,  53,  61 },
255   {68,  64,  65,  66,  61,  67 },
256   {60,  53,  61,  121, 112, 119},
257   {66,  61,  67,  124, 119, 122},
258   {99,  97,  98,  96,  39,  40 },
259   {124, 98,  119, 106, 40,  120},
260   {96,  39,  40,  41,  38,  105},
261   {106, 40,  120, 107, 105, 102},
262   {73,  71,  72,  69,  26,  27 },
263   {121, 72,  112, 101, 27,  114},
264   {69,  26,  27,  28,  24,  100},
265   {101, 27,  114, 104, 100, 103},
266   {85,  84,  82,  81,  36,  34 },
267   {115, 82,  122, 87,  34,  123},
268   {81,  36,  34,  37,  33,  86 },
269   {87,  34,  123, 90,  86,  89 },
270   {121, 112, 119, 101, 114, 120},
271   {124, 119, 122, 106, 120, 123},
272   {101, 114, 120, 104, 103, 102},
273   {106, 120, 123, 107, 102, 89 },
274   /* rank 1 */
275   {58,  43,  7,   56,  57,  10 },
276   {7,   43,  42,  10,  57,  9  },
277   {56,  57,  10,  118, 116, 76 },
278   {10,  57,  9,   76,  116, 75 },
279   {54,  49,  48,  51,  52,  14 },
280   {48,  49,  55,  14,  52,  15 },
281   {51,  52,  14,  115, 111, 82 },
282   {14,  52,  15,  82,  111, 83 },
283   {47,  44,  0,   45,  46,  3  },
284   {0,   44,  1,   3,   46,  4  },
285   {45,  46,  3,   110, 108, 70 },
286   {3,   46,  4,   70,  108, 71 },
287   {54,  44,  49,  51,  46,  52 },
288   {49,  44,  43,  52,  46,  57 },
289   {51,  46,  52,  115, 108, 111},
290   {52,  46,  57,  111, 108, 116},
291   {118, 116, 76,  92,  117, 31 },
292   {76,  116, 75,  31,  117, 30 },
293   {92,  117, 31,  95,  93,  29 },
294   {31,  117, 30,  29,  93,  78 },
295   {115, 111, 82,  87,  113, 34 },
296   {82,  111, 83,  34,  113, 35 },
297   {87,  113, 34,  90,  94,  86 },
298   {34,  113, 35,  86,  94,  91 },
299   {110, 108, 70,  79,  109, 25 },
300   {70,  108, 71,  25,  109, 26 },
301   {79,  109, 25,  80,  88,  23 },
302   {25,  109, 26,  23,  88,  24 },
303   {115, 108, 111, 87,  109, 113},
304   {111, 108, 116, 113, 109, 117},
305   {87,  109, 113, 90,  88,  94 },
306   {113, 109, 117, 94,  88,  93 },
307   {62,  64,  18,  60,  61,  20 },
308   {18,  64,  63,  20,  61,  21 },
309   {60,  61,  20,  121, 119, 97 },
310   {20,  61,  21,  97,  119, 98 },
311   {54,  50,  1,   51,  53,  4  },
312   {1,   50,  59,  4,   53,  5  },
313   {51,  53,  4,   115, 112, 71 },
314   {4,   53,  5,   71,  112, 72 },
315   {68,  65,  12,  66,  67,  16 },
316   {12,  65,  48,  16,  67,  14 },
317   {66,  67,  16,  124, 122, 84 },
318   {16,  67,  14,  84,  122, 82 },
319   {54,  65,  50,  51,  67,  53 },
320   {50,  65,  64,  53,  67,  61 },
321   {51,  67,  53,  115, 122, 112},
322   {53,  67,  61,  112, 122, 119},
323   {121, 119, 97,  101, 120, 39 },
324   {97,  119, 98,  39,  120, 40 },
325   {101, 120, 39,  104, 102, 38 },
326   {39,  120, 40,  38,  102, 105},
327   {115, 112, 71,  87,  114, 26 },
328   {71,  112, 72,  26,  114, 27 },
329   {87,  114, 26,  90,  103, 24 },
330   {26,  114, 27,  24,  103, 100},
331   {124, 122, 84,  106, 123, 36 },
332   {84,  122, 82,  36,  123, 34 },
333   {106, 123, 36,  107, 89,  33 },
334   {36,  123, 34,  33,  89,  86 },
335   {115, 122, 112, 87,  123, 114},
336   {112, 122, 119, 114, 123, 120},
337   {87,  123, 114, 90,  89,  103},
338   {114, 123, 120, 103, 89,  102}
339 };
340 
341 /* Partitions of prisms mesh : */
342 const PetscInt sInitialPartitionPrismsMesh[2][64] = {
343   {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63 },
344   {64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
345    96,                                                                                                                                 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127}
346 };
347 
348 const PetscInt sNLoclCellsPrismsMesh = 64;
349 const PetscInt sNGlobVertsPrismsMesh = 125;
350 
351 /* Coordinates for hexa+prism mesh */
352 PetscReal sCoordsHexPrismMesh[10][3] = {
353   {2.00000000000000000e+00, 2.00000000000000000e+00, 0.00000000000000000e+00},
354   {2.00000000000000000e+00, 0.00000000000000000e+00, 2.00000000000000000e+00},
355   {2.00000000000000000e+00, 2.00000000000000000e+00, 2.00000000000000000e+00},
356   {4.00000000000000000e+00, 2.00000000000000000e+00, 0.00000000000000000e+00},
357   {4.00000000000000000e+00, 2.00000000000000000e+00, 2.00000000000000000e+00},
358   {4.00000000000000000e+00, 0.00000000000000000e+00, 2.00000000000000000e+00},
359   {4.00000000000000000e+00, 0.00000000000000000e+00, 4.00000000000000000e+00},
360   {4.00000000000000000e+00, 2.00000000000000000e+00, 4.00000000000000000e+00},
361   {2.00000000000000000e+00, 2.00000000000000000e+00, 4.00000000000000000e+00},
362   {2.00000000000000000e+00, 0.00000000000000000e+00, 4.00000000000000000e+00}
363 };
364 
365 const PetscInt sConnectivityHexPrismMesh[2][8] = {
366   {1, 2, 8, 9, 5, 4, 7,  6 },
367   {0, 2, 1, 3, 4, 5, -1, -1}
368 };
369 /* Partitions of prisms mesh : */
370 const PetscInt sInitialPartitionHexPrismMesh[2][2] = {
371   {-1, -1},
372   {0,  1 }
373 };
374 
375 const PetscInt sNLoclCellsHexPrismMesh[2] = {0, 2};
376 const PetscInt sNGlobVertsHexPrismMesh    = 10;
377 
main(int argc,char ** argv)378 int main(int argc, char **argv)
379 {
380   PetscInt         Nc = 0;
381   const PetscInt  *InitPartForRank[2];
382   DM               dm, idm, ddm;
383   PetscSF          sfVert, sfMig, sfPart;
384   PetscPartitioner part;
385   PetscSection     s;
386   PetscInt        *cells, c;
387   PetscMPIInt      size, rank;
388   PetscBool        box = PETSC_FALSE, field = PETSC_FALSE, quadsmesh = PETSC_FALSE, trisquadsmesh = PETSC_FALSE, prismsmesh = PETSC_FALSE, hexprismmesh = PETSC_FALSE;
389 
390   PetscFunctionBeginUser;
391   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
392   PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
393   PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
394   PetscCheck(size == 2, PETSC_COMM_WORLD, PETSC_ERR_SUP, "This is a 2 processors example only");
395   PetscCall(PetscOptionsGetBool(NULL, NULL, "-field", &field, NULL));
396   PetscCall(PetscOptionsGetBool(NULL, NULL, "-box", &box, NULL));
397   PetscCall(PetscOptionsGetBool(NULL, NULL, "-quadsmesh", &quadsmesh, NULL));
398   PetscCall(PetscOptionsGetBool(NULL, NULL, "-trisquadsmesh", &trisquadsmesh, NULL));
399   PetscCall(PetscOptionsGetBool(NULL, NULL, "-prismsmesh", &prismsmesh, NULL));
400   PetscCall(PetscOptionsGetBool(NULL, NULL, "-hexprismmesh", &hexprismmesh, NULL));
401   PetscCheck(1 == (box ? 1 : 0) + (quadsmesh ? 1 : 0) + (trisquadsmesh ? 1 : 0) + (prismsmesh ? 1 : 0) + (hexprismmesh ? 1 : 0), PETSC_COMM_WORLD, PETSC_ERR_SUP, "Specify one and only one of -box, -quadsmesh or -prismsmesh");
402 
403   PetscCall(DMPlexCreate(PETSC_COMM_WORLD, &dm));
404   if (box) {
405     PetscCall(DMSetType(dm, DMPLEX));
406     PetscCall(DMSetFromOptions(dm));
407   } else {
408     if (quadsmesh) {
409       Nc                        = sNLoclCells2x5Mesh; //Same on each rank for this example...
410       PetscInt Nv               = sNGlobVerts2x5Mesh;
411       InitPartForRank[0]        = &sInitialPartition2x5Mesh[0][0];
412       InitPartForRank[1]        = &sInitialPartition2x5Mesh[1][0];
413       const PetscInt (*Conn)[4] = sConnectivity2x5Mesh;
414 
415       const PetscInt Ncor = 4;
416       const PetscInt dim  = 2;
417 
418       PetscCall(PetscMalloc1(Nc * Ncor, &cells));
419       for (c = 0; c < Nc; ++c) {
420         PetscInt cell = (InitPartForRank[rank])[c], cor;
421 
422         for (cor = 0; cor < Ncor; ++cor) cells[c * Ncor + cor] = Conn[cell][cor];
423       }
424       PetscCall(DMSetDimension(dm, dim));
425       PetscCall(DMPlexBuildFromCellListParallel(dm, Nc, PETSC_DECIDE, Nv, Ncor, cells, &sfVert, NULL));
426     } else if (trisquadsmesh) {
427       Nc                        = sNLoclCellsMixedTQMesh; //Same on each rank for this example...
428       PetscInt Nv               = sNGlobVertsMixedTQMesh;
429       InitPartForRank[0]        = &sInitialPartitionMixedTQMesh[0][0];
430       InitPartForRank[1]        = &sInitialPartitionMixedTQMesh[1][0];
431       const PetscInt (*Conn)[4] = sConnectivityMixedTQMesh;
432 
433       const PetscInt NcorMax = 4;
434       const PetscInt dim     = 2;
435 
436       /* Create a PetscSection and taking care to exclude nodes with "-1" into element connectivity: */
437       PetscSection s;
438       PetscInt     vStart = 0, vEnd = Nc;
439       PetscCall(PetscSectionCreate(PETSC_COMM_WORLD, &s));
440       PetscCall(PetscSectionSetNumFields(s, 1));
441       PetscCall(PetscSectionSetFieldComponents(s, 0, 1));
442       PetscCall(PetscSectionSetChart(s, vStart, vEnd));
443 
444       PetscCall(PetscMalloc1(Nc * NcorMax, &cells));
445       PetscInt count = 0;
446       for (c = 0; c < Nc; ++c) {
447         PetscInt cell         = (InitPartForRank[rank])[c], cor;
448         PetscInt nbElemVertex = ((-1 == Conn[cell][NcorMax - 1]) ? 3 : 4);
449         for (cor = 0; cor < nbElemVertex; ++cor) {
450           cells[count] = Conn[cell][cor];
451           ++count;
452         }
453         PetscCall(PetscSectionSetDof(s, c, nbElemVertex));
454         PetscCall(PetscSectionSetFieldDof(s, c, 0, nbElemVertex));
455       }
456       PetscCall(PetscSectionSetUp(s));
457       PetscCall(DMSetDimension(dm, dim));
458       PetscCall(PetscSectionView(s, PETSC_VIEWER_STDOUT_WORLD));
459       PetscCall(DMPlexBuildFromCellSectionParallel(dm, Nc, PETSC_DECIDE, Nv, s, cells, &sfVert, NULL));
460       PetscCall(PetscSectionDestroy(&s));
461     } else if (prismsmesh) {
462       Nc                        = sNLoclCellsPrismsMesh; //Same on each rank for this example...
463       PetscInt Nv               = sNGlobVertsPrismsMesh;
464       InitPartForRank[0]        = &sInitialPartitionPrismsMesh[0][0];
465       InitPartForRank[1]        = &sInitialPartitionPrismsMesh[1][0];
466       const PetscInt (*Conn)[6] = sConnectivityPrismsMesh;
467 
468       const PetscInt Ncor = 6;
469       const PetscInt dim  = 3;
470 
471       PetscCall(PetscMalloc1(Nc * Ncor, &cells));
472       for (c = 0; c < Nc; ++c) {
473         PetscInt cell = (InitPartForRank[rank])[c], cor;
474 
475         for (cor = 0; cor < Ncor; ++cor) cells[c * Ncor + cor] = Conn[cell][cor];
476       }
477       PetscCall(DMSetDimension(dm, dim));
478       PetscCall(DMPlexBuildFromCellListParallel(dm, Nc, PETSC_DECIDE, Nv, Ncor, cells, &sfVert, NULL));
479     } else if (hexprismmesh) {
480       Nc                        = sNLoclCellsHexPrismMesh[rank]; //Same on each rank for this example...
481       PetscInt Nv               = sNGlobVertsHexPrismMesh;
482       InitPartForRank[0]        = &sInitialPartitionHexPrismMesh[0][0];
483       InitPartForRank[1]        = &sInitialPartitionHexPrismMesh[1][0];
484       const PetscInt (*Conn)[8] = sConnectivityHexPrismMesh;
485 
486       const PetscInt NcorMax = 8;
487       const PetscInt dim     = 3;
488 
489       /* Create a PetscSection and taking care to exclude nodes with "-1" into element connectivity: */
490       PetscSection s;
491       PetscInt     vStart = 0, vEnd = Nc;
492       PetscCall(PetscSectionCreate(PETSC_COMM_WORLD, &s));
493       PetscCall(PetscSectionSetNumFields(s, 1));
494       PetscCall(PetscSectionSetFieldComponents(s, 0, 1));
495       PetscCall(PetscSectionSetChart(s, vStart, vEnd));
496 
497       PetscCall(PetscMalloc1(Nc * NcorMax, &cells));
498       PetscInt count = 0;
499       for (c = 0; c < Nc; ++c) {
500         PetscInt cell         = (InitPartForRank[rank])[c], cor;
501         PetscInt nbElemVertex = ((-1 == Conn[cell][NcorMax - 1]) ? 6 : 8);
502         for (cor = 0; cor < nbElemVertex; ++cor) {
503           cells[count] = Conn[cell][cor];
504           ++count;
505         }
506         PetscCall(PetscSectionSetDof(s, c, nbElemVertex));
507         PetscCall(PetscSectionSetFieldDof(s, c, 0, nbElemVertex));
508       }
509       PetscCall(PetscSectionSetUp(s));
510       PetscCall(DMSetDimension(dm, dim));
511       PetscCall(PetscSectionView(s, PETSC_VIEWER_STDOUT_WORLD));
512       PetscCall(DMPlexBuildFromCellSectionParallel(dm, Nc, PETSC_DECIDE, Nv, s, cells, &sfVert, NULL));
513       PetscCall(PetscSectionDestroy(&s));
514     }
515     PetscCall(PetscSFDestroy(&sfVert));
516     PetscCall(PetscFree(cells));
517     PetscCall(DMPlexSetInterpolatePreferTensor(dm, PETSC_FALSE));
518     PetscCall(DMPlexInterpolate(dm, &idm));
519     PetscCall(DMDestroy(&dm));
520     dm = idm;
521   }
522   PetscCall(DMSetUseNatural(dm, PETSC_TRUE));
523   PetscCall(DMViewFromOptions(dm, NULL, "-dm_view"));
524 
525   if (field) {
526     const PetscInt Nf         = 1;
527     const PetscInt numBC      = 0;
528     const PetscInt numComp[1] = {1};
529     PetscInt       numDof[4]  = {0, 0, 0, 0};
530     PetscInt       dim;
531 
532     PetscCall(DMGetDimension(dm, &dim));
533     numDof[dim] = 1;
534 
535     PetscCall(DMSetNumFields(dm, Nf));
536     PetscCall(DMPlexCreateSection(dm, NULL, numComp, numDof, numBC, NULL, NULL, NULL, NULL, &s));
537     PetscCall(DMSetLocalSection(dm, s));
538     /*PetscCall(PetscSectionView(s, PETSC_VIEWER_STDOUT_WORLD));*/
539     PetscCall(PetscSectionDestroy(&s));
540   }
541 
542   PetscCall(DMPlexGetPartitioner(dm, &part));
543   PetscCall(PetscPartitionerSetFromOptions(part));
544 
545   PetscCall(DMPlexDistribute(dm, 0, &sfMig, &ddm));
546   PetscCall(PetscSFView(sfMig, PETSC_VIEWER_STDOUT_WORLD));
547   PetscCall(PetscSFCreateInverseSF(sfMig, &sfPart));
548   PetscCall(PetscObjectSetName((PetscObject)sfPart, "Inverse Migration SF"));
549   PetscCall(PetscSFView(sfPart, PETSC_VIEWER_STDOUT_WORLD));
550 
551   Vec          lGlobalVec, lNatVec;
552   PetscScalar *lNatVecArray;
553 
554   {
555     PetscSection s;
556 
557     PetscCall(DMGetGlobalSection(dm, &s));
558     PetscCall(PetscSectionView(s, PETSC_VIEWER_STDOUT_WORLD));
559   }
560   PetscCall(DMGetGlobalVector(dm, &lNatVec));
561   PetscCall(PetscObjectSetName((PetscObject)lNatVec, "Natural Vector (initial partition)"));
562 
563   //Copying the initial partition into the "natural" vector:
564   PetscCall(VecZeroEntries(lNatVec));
565   PetscCall(VecGetArray(lNatVec, &lNatVecArray));
566   for (c = 0; c < Nc; ++c) lNatVecArray[c] = (InitPartForRank[rank])[c];
567   PetscCall(VecRestoreArray(lNatVec, &lNatVecArray));
568 
569   PetscCall(DMGetGlobalVector(ddm, &lGlobalVec));
570   PetscCall(PetscObjectSetName((PetscObject)lGlobalVec, "Global Vector (reordered element numbers in the PETSc distributed order)"));
571   PetscCall(VecZeroEntries(lGlobalVec));
572 
573   // The call to DMPlexNaturalToGlobalBegin/End does not produce our expected result...
574   // In lGlobalVec, we expect to have:
575   /*
576    * Process [0]
577    * 2.
578    * 4.
579    * 8.
580    * 3.
581    * 9.
582    * Process [1]
583    * 1.
584    * 5.
585    * 7.
586    * 0.
587    * 6.
588    *
589    * but we obtained:
590    *
591    * Process [0]
592    * 2.
593    * 4.
594    * 8.
595    * 0.
596    * 0.
597    * Process [1]
598    * 0.
599    * 0.
600    * 0.
601    * 0.
602    * 0.
603    */
604 
605   {
606     PetscSF nsf;
607 
608     PetscCall(DMGetNaturalSF(ddm, &nsf));
609     PetscCall(PetscSFView(nsf, NULL));
610   }
611   PetscCall(DMPlexNaturalToGlobalBegin(ddm, lNatVec, lGlobalVec));
612   PetscCall(DMPlexNaturalToGlobalEnd(ddm, lNatVec, lGlobalVec));
613 
614   PetscCall(VecView(lNatVec, PETSC_VIEWER_STDOUT_WORLD));
615   PetscCall(VecView(lGlobalVec, PETSC_VIEWER_STDOUT_WORLD));
616 
617   PetscCall(DMRestoreGlobalVector(dm, &lNatVec));
618   PetscCall(DMRestoreGlobalVector(ddm, &lGlobalVec));
619 
620   const PetscBool lUseCone    = PETSC_FALSE;
621   const PetscBool lUseClosure = PETSC_TRUE;
622   PetscCall(DMSetBasicAdjacency(ddm, lUseCone, lUseClosure));
623   const PetscInt lNbCellsInOverlap = 1;
624   PetscSF        lSFMigrationOvl;
625   DM             ddm_with_overlap;
626 
627   PetscCall(DMPlexDistributeOverlap(ddm, lNbCellsInOverlap, &lSFMigrationOvl, &ddm_with_overlap));
628 
629   IS lISCellWithOvl = 0;
630   /* This is the buggy call with prisms since commit 5ae96e2b862 */
631   PetscCall(DMPlexCreateCellNumbering(ddm_with_overlap, PETSC_TRUE, &lISCellWithOvl));
632   /* Here, we can see the elements in the overlap within the IS: they are the ones with negative indices */
633   PetscCall(ISView(lISCellWithOvl, PETSC_VIEWER_STDOUT_WORLD));
634   PetscCall(ISDestroy(&lISCellWithOvl));
635 
636   PetscCall(PetscSFDestroy(&lSFMigrationOvl));
637   PetscCall(DMDestroy(&ddm_with_overlap));
638   PetscCall(PetscSFDestroy(&sfMig));
639   PetscCall(PetscSFDestroy(&sfPart));
640   PetscCall(DMDestroy(&dm));
641   PetscCall(DMDestroy(&ddm));
642   PetscCall(PetscFinalize());
643   return 0;
644 }
645 
646 /*TEST
647 
648   testset:
649     args: -field -petscpartitioner_type simple
650     nsize: 2
651 
652     test:
653       suffix: 0
654       args: -quadsmesh
655       output_file: output/ex47_0.out
656 
657     test:
658       suffix: 1
659       args: -box -dm_plex_simplex 0 -dm_plex_box_faces 2,5 -dm_distribute
660       output_file: output/ex47_1.out
661 
662     test:
663       suffix: 2
664       args: -prismsmesh
665       output_file: output/ex47_2.out
666 
667     test:
668       suffix: 3
669       args: -trisquadsmesh
670       output_file: output/ex47_3.out
671 
672     test:
673       suffix: 4
674       args: -hexprismmesh
675       output_file: output/ex47_4.out
676 
677 TEST*/
678