Actual source code: ex69.c

  1: static char help[] = "Tests for creation of cohesive meshes by transforms\n\n";

  3: #include <petscdmplex.h>
  4: #include <petscsf.h>

  6: #include <petsc/private/dmpleximpl.h>

  8: PETSC_EXTERN char tri_2_cv[];
  9: char              tri_2_cv[] = "\
 10: 2 4 6 3 1\n\
 11: 0 2 1\n\
 12: 1 2 3\n\
 13: 4 1 5\n\
 14: 4 0 1\n\
 15: -1.0  0.0 0.0  1\n\
 16:  0.0  1.0 0.0 -1\n\
 17:  0.0 -1.0 0.0  1\n\
 18:  1.0  0.0 0.0 -1\n\
 19: -2.0  1.0 0.0  1\n\
 20: -1.0  2.0 0.0 -1";

 22: /* List of test meshes

 24: Test tri_0: triangle

 26:  4-10--5      8-16--7-14--4
 27:  |\  1 |      |\     \  1 |
 28:  | \   |      | \     \   |
 29:  6  8  9  ->  9 12  2  11 13
 30:  |   \ |      |   \     \ |
 31:  | 0  \|      | 0  \     \|
 32:  2--7--3      3-10--6-15--5

 34: Test tri_1: triangle, not tensor

 36:  4-10--5      8-10--7-16--4
 37:  |\  1 |      |\     \  1 |
 38:  | \   |      | \     \   |
 39:  6  8  9  -> 11 14  2  13 15
 40:  |   \ |      |   \     \ |
 41:  | 0  \|      | 0  \     \|
 42:  2--7--3      3-12--6--9--5

 44: Test tri_2: 4 triangles, non-oriented surface

 46:            9
 47:           / \
 48:          /   \
 49:        17  2  16
 50:        /       \
 51:       /         \
 52:      8-----15----5
 53:       \         /|\
 54:        \       / | \
 55:        18  3  12 |  14
 56:          \   /   |   \
 57:           \ /    |    \
 58:            4  0 11  1  7
 59:             \    |    /
 60:              \   |   /
 61:              10  |  13
 62:                \ | /
 63:                 \|/
 64:                  6
 65:   becomes
 66:            8
 67:           / \
 68:          /   \
 69:         /     \
 70:       25   2   24
 71:       /         \
 72:      /           \
 73:    13-----18------9
 74: 28  |     5    26/ \
 75:    14----19----10   \
 76:      \         /|   |\
 77:       \       / |   | \
 78:       21  3  20 |   |  23
 79:         \   /   |   |   \
 80:          \ /    |   |    \
 81:           6  0 17 4 16 1  7
 82:            \    |   |    /
 83:             \   |   |   /
 84:             15  |   |  22
 85:               \ |   | /
 86:                \|   |/
 87:                12---11
 88:                  27

 90: Test tri_3: tri_2, in parallel

 92:            6
 93:           / \
 94:          /   \
 95:         /     \
 96:       12   1   11
 97:       /         \
 98:      /           \
 99:     5-----10------2
100:                    \
101:     5-----9-----3   2
102:      \         /|   |\
103:       \       / |   | \
104:       10  1  8  |   |  9
105:         \   /   |   |   \
106:          \ /    |   |    \
107:           2  0  7   7  0  4
108:            \    |   |    /
109:             \   |   |   /
110:              6  |   |  8
111:               \ |   | /
112:                \|   |/
113:                 4   3
114:   becomes
115:                  11
116:                 / \
117:                /   \
118:               /     \
119:             19   1   18
120:             /         \
121:            /           \
122:           8-----14------4
123:         22 \     3       |
124:             9------15    |\
125:                     \    | \
126:     9------14-----5  \  20 |
127:   20\    3     18/ \  \/   |
128:    10----15-----6   |  5   |
129:      \         /|   |  |   |\
130:       \       / |   |  |   | \
131:       17  1 16  |   |  |   |  17
132:         \   /   | 2 |  | 2 |   \
133:          \ /    |   |  |   |    \
134:           4  0  13 12  13  12 0 10
135:            \    |   |  |   |    /
136:             \   |   |  |   |   /
137:             11  |   |  |   |  16
138:               \ |   |  |   | /
139:                \|   |  |   |/
140:                 8---7  7---6
141:                  19      21

143: Test quad_0: quadrilateral

145:  5-10--6-11--7       5-12-10-20--9-14--6
146:  |     |     |       |     |     |     |
147: 12  0 13  1  14 --> 15  0 18  2 17  1  16
148:  |     |     |       |     |     |     |
149:  2--8--3--9--4       3-11--8-19--7-13--4

151: Test quad_1: quadrilateral, not tensor

153:  5-10--6-11--7       5-14-10-12--9-16--6
154:  |     |     |       |     |     |     |
155: 12  0 13  1  14 --> 17  0 20  2 19  1  18
156:  |     |     |       |     |     |     |
157:  2--8--3--9--4       3-13--8-11--7-15--4

159: Test quad_2: quadrilateral, 2 processes

161:  3--6--4  3--6--4       3--9--7-14--6   5-14--4--9--7
162:  |     |  |     |       |     |     |   |     |     |
163:  7  0  8  7  0  8  --> 10  0 12  1 11  12  1 11  0  10
164:  |     |  |     |       |     |     |   |     |     |
165:  1--5--2  1--5--2       2--8--5-13--4   3-13--2--8--6

167: Test quad_3: quadrilateral, 4 processes, non-oriented surface

169:  3--6--4  3--6--4      3--9--7-14--6   5-14--4--9--7
170:  |     |  |     |      |     |     |   |     |     |
171:  7  0  8  7  0  8     10  0  12 1  11 12  1 11  0  10
172:  |     |  |     |      |     |     |   |     |     |
173:  1--5--2  1--5--2      2--8--5-13--4   3-13--2--8--6
174:                    -->
175:  3--6--4  3--6--4      3--9--7-14--6   5-14--4--9--7
176:  |     |  |     |      |     |     |   |     |     |
177:  7  0  8  7  0  8     10  0  12 1  11 12  1 11  0  10
178:  |     |  |     |      |     |     |   |     |     |
179:  1--5--2  1--5--2      2--8--5-13--4   3-13--2--8--6

181: Test quad_4: embedded fault

183: 14-24-15-25-16-26--17
184:  |     |     |     |
185: 28  3 30  4 32  5  34
186:  |     |     |     |
187: 10-21-11-22-12-23--13
188:  |     |     |     |
189: 27  0 29  1 31  2  33
190:  |     |     |     |
191:  6-18--7-19--8-20--9

193: becomes

195:  13-26-14-27-15-28--16
196:   |     |     |     |
197:  30  3 32  4 39  5  40
198:   |     |     |     |
199:  12-25-17-36-19-38--21
200:         |     |     |
201:        41  6 42  7  43
202:         |     |     |
203:  12-25-17-35-18-37--20
204:   |     |     |     |
205:  29  0 31  1 33  2  34
206:   |     |     |     |
207:   8-22--9-23-10-24--11

209: Test quad_5: two faults

211: 14-24-15-25-16-26--17
212:  |     |     |     |
213: 28  3 30  4 32  5  34
214:  |     |     |     |
215: 10-21-11-22-12-23--13
216:  |     |     |     |
217: 27  0 29  1 31  2  33
218:  |     |     |     |
219:  6-18--7-19--8-20--9

221: becomes

223: 12-26-13-27-14-28--15
224:  |     |     |     |
225: 37  4 31  3 33  5  40
226:  |     |     |     |
227: 17-36-18-25-19-39--21
228:  |     |     |     |
229: 43  6  44   41  7  42
230:  |     |     |     |
231: 16-35-18-25-19-38--20
232:  |     |     |     |
233: 29  0 30  1 32  2  34
234:  |     |     |     |
235:  8-22--9-23-10-24--11

237: Test quad_6: T-junction

239: 14-24-15-25-16-26--17
240:  |     |     |     |
241: 28  3 30  4 32  5  34
242:  |     |     |     |
243: 10-21-11-22-12-23--13
244:  |     |     |     |
245: 27  0 29  1 31  2  33
246:  |     |     |     |
247:  6-18--7-19--8-20--9

249: becomes

251:  13-26-14-27-15-28--16
252:   |     |     |     |
253:  30  3 32  4 39  5  40
254:   |     |     |     |
255:  12-25-17-36-19-38--21
256:         |     |     |
257:        41  6 42  7  43
258:         |     |     |
259:  12-25-17-35-18-37--20
260:   |     |     |     |
261:  29  0 31  1 33  2  34
262:   |     |     |     |
263:   8-22--9-23-10-24--11

265: becomes

267:  14-28-15-41-21-44--20-29-16
268:   |     |     |     |     |
269:  31  3 33  5 43  8 42  4  40
270:   |     |     |     |     |
271:  13-27-17-37-23-46--23-39-19
272:         |     |     |     |
273:        47  6 48    48  7  49
274:         |     |     |     |
275:  13-27-17-36-22-45--22-38-18
276:   |     |     |     |     |
277:  30  0 32  1 34    34  2  35
278:   |     |     |     |     |
279:   9-24-10-25-11-----11-26-12

281: Test tet_0: Two tets sharing a face

283:  cell   5 _______    cell
284:  0    / | \      \      1
285:     19  |  16     20
286:     /  15   \      \
287:    2-17------4--22--6
288:     \   |   /      /
289:     18  |  14     21
290:       \ | /      /
291:         3-------

293: becomes

295:  cell  10 ___36____9______    cell
296:  0    / | \        |\      \     1
297:     29  |  27      | 26     31
298:     /  25   \     24  \      \
299:    3-28------8--35-----7--33--4
300:     \   |   /      |  /      /
301:     30  |  23      | 22     32
302:       \ | /        |/      /
303:         6----34----5------
304:          cell 2

306: Test tet_1: Two tets sharing a face in parallel

308:  cell   4          3______    cell
309:  0    / | \        |\      \     0
310:     14  |  11      | 11     12
311:     /  10   \     10  \      \
312:    1-12------3     |   2--14--4
313:     \   |   /      |  /      /
314:     13  |  9       | 9      13
315:       \ | /        |/      /
316:         2          1------

318: becomes
319:            cell 1              cell 1
320:  cell   8---28---7           7---28---6______    cell
321:  0    / | \      |\          |\       |\      \     0
322:     24  |  22    | 21        | 22     | 21     23
323:     /  20   \    |   \       |  \    19  \      \
324:    2-23------6---27---5     20  5---27---4--25--8
325:     \   |   /   19   /       |  /     |  /      /
326:     25  |  18    | 17        | 18     | 17     24
327:       \ | /      |/          |/       |/      /
328:         4---26---3           3---26---2------

330: Test hex_0: Two hexes sharing a face

332: cell  11-----31-----12-----32------13 cell
333: 0     /|            /|            /|     1
334:     36 |   22      37|   24      38|
335:     /  |          /  |          /  |
336:    8-----29------9-----30------10  |
337:    |   |     18  |   |     20  |   |
338:    |  42         |  43         |   44
339:    |14 |         |15 |         |16 |
340:   39   |  17    40   |   19   41   |
341:    |   5-----27--|---6-----28--|---7
342:    |  /          |  /          |  /
343:    | 33   21     | 34    23    | 35
344:    |/            |/            |/
345:    2-----25------3-----26------4

347: becomes

349:                          cell 2
350: cell   9-----38-----18-----62------17----42------10 cell
351: 0     /|            /|            /|            /|     1
352:     45 |   30      54|  32       53|   24      46|
353:     /  |          /  |          /  |          /  |
354:    7-----37-----16-----61------15--|-41------8   |
355:    |   |     28  |   |         |   |     22  |   |
356:    |  49         |  58         |   57        |   50
357:    |19 |         |26 |         |25 |         |20 |
358:   47   |  27    56   |        55   |   21   48   |
359:    |   5-----36--|--14-----60--|---13----40--|---6
360:    |  /          |  /          |  /          |  /
361:    | 43   29     | 52   31     | 51    23    | 44
362:    |/            |/            |/            |/
363:    3-----35-----12-----59------11----39------4

365: Test hex_1: Two hexes sharing a face, in parallel

367: cell   7-----18------8             7-----18------8 cell
368: 0     /|            /|            /|            /|    0
369:     21 |   14      22|           21|   14      22|
370:     /  |          /  |          /  |          /  |
371:    5-----17------6   |         5---|-17------6   |
372:    |   |     12  |   |         |   |     12  |   |
373:    |  25         |  26         |  25         |  26
374:    | 9 |         |10 |         | 9 |         |10 |
375:   23   |  11    24   |        23   |   11   24   |
376:    |   3-----16--|---4         |   3-----16--|---4
377:    |  /          |  /          |  /          |  /
378:    | 19   13     | 20          | 19    13    | 20
379:    |/            |/            |/            |/
380:    1-----15------2             1-----15------2

382: becomes
383:                         cell 1                      cell 1
384: cell   5-----28-----13-----44-----12             9-----44-----8-----28------13 cell
385: 0     /|            /|           /|             /|           /|            /|     0
386:     30 |   20      36|   22     35|            36|   22     35|   20      30|
387:     /  |          /  |         /  |           /  |         /  |          /  |
388:    4-----27-----11-----43-----10  |          7-----43-----6-----27------12  |
389:    |   |     18  |   |        |   |          |   |        |   |     18  |   |
390:    |  32         |  40        |   39         |  40        |   39        |   32
391:    |14 |         |16 |        | 15|          |15 |        |14 |         |16 |
392:   31   |  17    38   |        37  |         38   |       37   |   17   31   |
393:    |   3-----26--|---9-----42-|---8          |   5----42--|---4-----26--|---11
394:    |  /          |  /         |  /           |  /         |  /          |  /
395:    | 29   19     | 34    21   | 33           | 34    21   | 33    19    | 29
396:    |/            |/           |/             |/           |/            |/
397:    2-----25------7-----41-----6              3-----41-----2-----25------10

399: Test hex_2: hexahedra, 4 processes, non-oriented surface

401:           cell 0                  cell 0
402:        7-----18------8       7-----18------8
403:       /|            /|      /|            /|
404:     21 |   14      22|    21 |   14      22|
405:     /  |          /  |    /  |          /  |
406:    5-----17------6   |   5-----17------6   |
407:    |   |     12  |   |   |   |     12  |   |
408:    |  25         |  26   |  25         |   26
409:    |9  |         |10 |   |9  |         |10 |
410:   23   |  11    24   |  23   |  11    24   |
411:    |   3-----16--|---4   |   3-----16--|---4
412:    |  /          |  /    |  /          |  /
413:    | 19    13    | 20    | 19    13    | 20
414:    |/            |/      |/            |/
415:    1-----15------2       1-----15------2

417:        7-----18------8       7-----18------8
418:       /|            /|      /|            /|
419:     21 |   14      22|    21 |   14      22|
420:     /  |          /  |    /  |          /  |
421:    5-----17------6   |   5-----17------6   |
422:    |   |     12  |   |   |   |     12  |   |
423:    |  25         |  26   |  25         |  26
424:    |9  |         |10 |   |9  |         |10 |
425:   23   |  11    24   |  23   |   11   24   |
426:    |   3-----16--|---4   |   3-----16--|---4
427:    |  /          |  /    |  /          |  /
428:    | 19   13     | 20    | 19    13    | 20
429:    |/            |/      |/            |/
430:    1-----15------2       1-----15------2
431:       cell 0                cell 0

433: becomes

435:           cell 0         cell 1                cell 1        cell 0
436:        5-----28------13----44------12      9-----44------8-----28------13
437:       /|            /|            /|      /|            /|            /|
438:     30 |   20      36|   22      35|     36|   22     35 |   20      30|
439:     /  |          /  |          /  |    /  |          /  |          /  |
440:    4-----27------11----43------10  |   7-----43------6-----27------12  |
441:    |   |     18  |   |         |   |   |   |         |   |     18  |   |
442:    |  32         |  40         |  39   |  40         |  39         |   32
443:    |14 |         |16 |         |15 |   |15 |         |14 |         |16 |
444:   31   |  17    38   |         37  |   38  |        37   |  17    31   |
445:    |   3-----26--|---9-----42--|---8   |   5-----42--|---4-----26--|---11
446:    |  /          |  /          |  /    |  /          |  /          |  /
447:    | 29    19    | 34    21    |33     | 34    21    | 33    19    | 29
448:    |/            |/            |/      |/            |/            |/
449:    2-----25------7-----41------6       3-----41------2-----25------10

451:        5-----28------13----44------12      9-----44------8-----28------13
452:       /|            /|            /|      /|            /|            /|
453:     30 |   20      36|   22      35|     36|    22     35|   20      30|
454:     /  |          /  |          /  |    /  |          /  |          /  |
455:    4-----27------11----43------10  |   7-----43------6-----27------12  |
456:    |   |     18  |   |         |   |   |   |         |   |     18  |   |
457:    |  32         |  40         |   39  |   40        |  39         |   32
458:    |14 |         |16 |         |15 |   |15 |         |14 |         |16 |
459:   31   |  17    38   |         37  |   38  |        37   |  17    31   |
460:    |   3-----26--|---9-----42--|---8   |   5-----42--|---4-----26--|---11
461:    |  /          |  /          |  /    |  /          |  /          |  /
462:    | 29    19    | 34    21    |33     | 34    21    | 33    19    | 29
463:    |/            |/            |/      |/            |/            |/
464:    2-----25------7-----41------6       3-----41------2-----25------10
465:       cell 0         cell 1                cell 1        cell 0

467: Test hex_3: T-junction

469:       19-----52-----20-----53------21
470:       /|            /|            /|
471:     60 |   38      61|   41      62|
472:     /  |          /  |          /  |
473:   16-----50-----17-----51------18  |
474:    |   |     33  |   |     35  |   |
475:    |  70         |  72         |   74
476:    |25 |         |26 |         |27 |
477:   64   |  32    66   |  34    68   |
478:    |  13-----48--|--14-----49--|---15
479:    |  /|         |  /|         |  /|
480:    |57 |   37    | 58|   40    | 59|
481:    |/  |         |/  |         |/  |
482:   10-----46-----11-----47------12  |
483:    |   |     29  |   |     31  |   |
484:    |  69         |  71         |   73
485:    |22 |         |23 |         |24 |
486:   63   |  28    65   |   30   67   |
487:    |   7-----44--|---8-----45--|---9
488:    |  /          |  /          |  /
489:    | 54   36     | 55    39    | 56
490:    |/            |/            |/
491:    4-----42------5-----43------6
492:       cell 0         cell 1

494: becomes

496:       15----102-----28---112----___27-----73------16
497:       /|            /|         /   /             /|
498:     77 |   55     104|      ---  103    46      78|
499:     /  |          /  |     /     /             /  |
500:   13----101-----26---111--/----25-----72------14  |
501:    |   |     54  |   |  107   /           43  |   |
502:    |  81         |  108 / 51 /                |   82
503:    |40 |         |52 | /   105                |41 |
504:   79   |  53    106  |/   /            42    80   |
505:    |  21-----87--|--31---/-89------23-------/----/
506:    |  /|         |  /|  /         /|       /
507:    |91 |   47    |109|-- 49      93|  -----
508:    |/  |         |/ /|          /  | /
509:   17-----83-----29-----85------19----
510:    |   |         |   |         |   |
511:    |  120        |  121        |  122
512:    |   |         |26 |         |   |
513:  117   |        118  |        119  |
514:    |  22-----88--|--32-----90--|---24
515:    |  /|         |  /|         |  /|
516:    |92 |   48    |110|   50    | 94|
517:    |/  |         |/  |         |/  |
518:   18-----84-----30-----86------20  |
519:    |   |     37  |   |     39  |   |
520:    |  98         |  99         |   100
521:    |33 |         |34 |         |35 |
522:   95   |  36    96   |   38   97   |
523:    |  10-----70--|--11-----71--|---12
524:    |  /          |  /          |  /
525:    | 74   44     | 75    45    | 76
526:    |/            |/            |/
527:    7-----68------8-----69------9
528:       cell 0         cell 1

530: Test hex_4: Two non-intersecting faults

532:           cell 4         cell 5         cell 6        cell 7
533:       33-----96-----34-----97-----35-----98-----36-----99------37
534:       /|            /|            /|            /|            /|
535:     110|   66     111|   69     112|   72     113|   75     114|
536:     /  |          /  |          /  |          /  |          /  |
537:   28-----92-----29-----93-----30-----94-----31-----95------32  |
538:    |   |     57  |   |     59  |   |     61  |   |     63  |   |
539:    |  126        |  128        |  130        |  132        |  134
540:    |43 |         |44 |         |45 |         |46 |         |47 |
541:   116  |  56    118  |  58    120  |  60    122  |  62    124  |
542:    |  23-----88--|--24-----89--|--25-----90--|--26-----91--|---27
543:    |  /|         |  /|         |  /|         |  /|         |  /|
544:    |105|   65    |106|   68    |107|   71    |108|   74    |109|
545:    |/  |         |/  |         |/  |         |/  |         |/  |
546:   18-----84-----19-----95-----20-----86-----21-----87------22  |
547:    |   |     49  |   |     51  |   |     53  |   |     55  |   |
548:    |  125        |  127        |  129        |  131        |  133
549:    |38 |         |39 |         |40 |         |41 |         |42 |
550:   115  |  48    117  |  50    119  |  52    121  |  54    123  |
551:    |  13-----80--|--14-----81--|--15-----82--|--16-----83--|---17
552:    |  /          |  /          |  /          |  /          |  /
553:    |100    64    |101    67    |102    70    |103    73    |104
554:    |/            |/            |/            |/            |/
555:    8-----76------9-----77-----10-----78-----11-----79------12
556:       cell 0         cell 1        cell 2        cell 3

558: becomes

560:           cell 4         cell 5        cell 7        cell 10       cell 6
561:       27-----114----28-----115----29-----159----46-----170----45------116----30
562:       /|            /|            /|            /|            /|            /|
563:     123|   71     124|   73     125|   87     162|          161|    78    126|
564:     /  |          /  |          /  |          /  |          /  |          /  |
565:   23-----111----24-----112----25-----158----44-----169----43-----113-----26  |
566:    |   |     65  |   |    67   |   |    86   |   |         |   |     69  |   |
567:    |  134        |  135        |  137        |  166        |  165        |  140
568:    |56 |         |57 |         |58 |         |84 |         |83 |         |59 |
569:   127  |  64    128  |  66    130  |  85    164  |        163  |  68    133  |
570:    |  35-----143-|--37-----151-|--40-----109-|--42-----168-|--42-----110-|---22
571:    |  /|         |  /|         |  /|         |  /          |  /          |  /
572:    |145|   79    |147|   81    |153|   75    |160          |160    77    |122
573:    |/ 173        |/ 174        |/ 176        |/            |/            |/
574:   31-----141----33-----149----39-----107----41-----167----41-----108-----21
575: cell   |         |   |         |   | cell 9
576: 8  |  36-----144-|--38-----152-|--40-----109----42-----110-----22
577:   171 /|        172 /|        175 /|            /|            /|
578:    |146|   80    |148|   82    |153|    75    160|   77     122|
579:    |/  |         |/  |         |/  |          /  |          /  |
580:   32-----142----34-----150----39-----107----41-----108-----21  |
581:    |   |     50  |   |    52   |   |    61   |   |     63  |   |
582:    |  156        |  157        |  136        |  138        |  139
583:    |47 |         |48 |         |53 |         |54 |         |55 |
584:   154  |  49    155  |  51    129  |  60    131  |  62    132  |
585:    |  16-----103-|--17-----104-|--18-----105-|--19-----106-|---20
586:    |  /          |  /          |  /          |  /          |  /
587:    |117    70    |118    72    |119    74    |120    76    |121
588:    |/            |/            |/            |/            |/
589:   11-----99-----12-----100----13-----101----14-----102-----15
590:       cell 0         cell 1        cell 2        cell 3

592: */

594: typedef struct {
595:   PetscInt testNum; // The mesh to test
596: } AppCtx;

598: static PetscErrorCode ProcessOptions(MPI_Comm comm, AppCtx *options)
599: {
600:   PetscFunctionBegin;
601:   options->testNum = 0;

603:   PetscOptionsBegin(comm, "", "Cohesive Meshing Options", "DMPLEX");
604:   PetscCall(PetscOptionsBoundedInt("-test_num", "The particular mesh to test", "ex5.c", options->testNum, &options->testNum, NULL, 0));
605:   PetscOptionsEnd();
606:   PetscFunctionReturn(PETSC_SUCCESS);
607: }

609: static PetscErrorCode CreateQuadMesh1(MPI_Comm comm, AppCtx *user, DM *dm)
610: {
611:   const PetscInt faces[2] = {1, 1};
612:   PetscReal      lower[2], upper[2];
613:   DMLabel        label;
614:   PetscMPIInt    rank;
615:   void          *get_tmp;
616:   PetscInt64    *cidx;
617:   PetscMPIInt    flg;

619:   PetscFunctionBeginUser;
620:   PetscCallMPI(MPI_Comm_rank(comm, &rank));
621:   // Create serial mesh
622:   lower[0] = (PetscReal)(rank % 2);
623:   lower[1] = (PetscReal)(rank / 2);
624:   upper[0] = (PetscReal)(rank % 2) + 1.;
625:   upper[1] = (PetscReal)(rank / 2) + 1.;
626:   PetscCall(DMPlexCreateBoxMesh(PETSC_COMM_SELF, 2, PETSC_FALSE, faces, lower, upper, NULL, PETSC_TRUE, 0, PETSC_TRUE, dm));
627:   PetscCall(PetscObjectSetName((PetscObject)*dm, "box"));
628:   // Flip edges to make fault non-oriented
629:   switch (rank) {
630:   case 2:
631:     PetscCall(DMPlexOrientPoint(*dm, 8, -1));
632:     break;
633:   case 3:
634:     PetscCall(DMPlexOrientPoint(*dm, 7, -1));
635:     break;
636:   default:
637:     break;
638:   }
639:   // Need this so that all procs create the cell types
640:   PetscCall(DMPlexGetCellTypeLabel(*dm, &label));
641:   // Replace comm in object (copied from PetscHeaderCreate/Destroy())
642:   PetscCall(PetscCommDestroy(&(*dm)->hdr.comm));
643:   PetscCall(PetscCommDuplicate(comm, &(*dm)->hdr.comm, &(*dm)->hdr.tag));
644:   PetscCallMPI(MPI_Comm_get_attr((*dm)->hdr.comm, Petsc_CreationIdx_keyval, &get_tmp, &flg));
645:   PetscCheck(flg, (*dm)->hdr.comm, PETSC_ERR_ARG_CORRUPT, "MPI_Comm does not have an object creation index");
646:   cidx            = (PetscInt64 *)get_tmp;
647:   (*dm)->hdr.cidx = (*cidx)++;
648:   // Create new pointSF
649:   {
650:     PetscSF      sf;
651:     PetscInt    *local  = NULL;
652:     PetscSFNode *remote = NULL;
653:     PetscInt     Nl;

655:     PetscCall(PetscSFCreate(comm, &sf));
656:     switch (rank) {
657:     case 0:
658:       Nl = 5;
659:       PetscCall(PetscMalloc1(Nl, &local));
660:       PetscCall(PetscMalloc1(Nl, &remote));
661:       local[0]        = 2;
662:       remote[0].index = 1;
663:       remote[0].rank  = 1;
664:       local[1]        = 3;
665:       remote[1].index = 1;
666:       remote[1].rank  = 2;
667:       local[2]        = 4;
668:       remote[2].index = 1;
669:       remote[2].rank  = 3;
670:       local[3]        = 6;
671:       remote[3].index = 5;
672:       remote[3].rank  = 2;
673:       local[4]        = 8;
674:       remote[4].index = 7;
675:       remote[4].rank  = 1;
676:       break;
677:     case 1:
678:       Nl = 3;
679:       PetscCall(PetscMalloc1(Nl, &local));
680:       PetscCall(PetscMalloc1(Nl, &remote));
681:       local[0]        = 3;
682:       remote[0].index = 1;
683:       remote[0].rank  = 3;
684:       local[1]        = 4;
685:       remote[1].index = 2;
686:       remote[1].rank  = 3;
687:       local[2]        = 6;
688:       remote[2].index = 5;
689:       remote[2].rank  = 3;
690:       break;
691:     case 2:
692:       Nl = 3;
693:       PetscCall(PetscMalloc1(Nl, &local));
694:       PetscCall(PetscMalloc1(Nl, &remote));
695:       local[0]        = 2;
696:       remote[0].index = 1;
697:       remote[0].rank  = 3;
698:       local[1]        = 4;
699:       remote[1].index = 3;
700:       remote[1].rank  = 3;
701:       local[2]        = 8;
702:       remote[2].index = 7;
703:       remote[2].rank  = 3;
704:       break;
705:     case 3:
706:       Nl = 0;
707:       break;
708:     default:
709:       SETERRQ(comm, PETSC_ERR_SUP, "This example only supports 4 ranks");
710:     }
711:     PetscCall(PetscSFSetGraph(sf, 9, Nl, local, PETSC_OWN_POINTER, remote, PETSC_OWN_POINTER));
712:     PetscCall(DMSetPointSF(*dm, sf));
713:     PetscCall(PetscSFDestroy(&sf));
714:   }
715:   // Create fault label
716:   PetscCall(DMCreateLabel(*dm, "fault"));
717:   PetscCall(DMGetLabel(*dm, "fault", &label));
718:   switch (rank) {
719:   case 0:
720:   case 2:
721:     PetscCall(DMLabelSetValue(label, 8, 1));
722:     PetscCall(DMLabelSetValue(label, 2, 0));
723:     PetscCall(DMLabelSetValue(label, 4, 0));
724:     break;
725:   case 1:
726:   case 3:
727:     PetscCall(DMLabelSetValue(label, 7, 1));
728:     PetscCall(DMLabelSetValue(label, 1, 0));
729:     PetscCall(DMLabelSetValue(label, 3, 0));
730:     break;
731:   default:
732:     break;
733:   }
734:   PetscCall(DMPlexOrientLabel(*dm, label));
735:   PetscCall(DMPlexLabelCohesiveComplete(*dm, label, NULL, 1, PETSC_FALSE, PETSC_FALSE, NULL));
736:   PetscCall(DMPlexDistributeSetDefault(*dm, PETSC_FALSE));
737:   PetscFunctionReturn(PETSC_SUCCESS);
738: }

740: static PetscErrorCode CreateHexMesh1(MPI_Comm comm, AppCtx *user, DM *dm)
741: {
742:   const PetscInt faces[3] = {1, 1, 1};
743:   PetscReal      lower[3], upper[3];
744:   DMLabel        label;
745:   PetscMPIInt    rank;
746:   void          *get_tmp;
747:   PetscInt64    *cidx;
748:   PetscMPIInt    flg;

750:   PetscFunctionBeginUser;
751:   PetscCallMPI(MPI_Comm_rank(comm, &rank));
752:   // Create serial mesh
753:   lower[0] = (PetscReal)(rank % 2);
754:   lower[1] = 0.;
755:   lower[2] = (PetscReal)(rank / 2);
756:   upper[0] = (PetscReal)(rank % 2) + 1.;
757:   upper[1] = 1.;
758:   upper[2] = (PetscReal)(rank / 2) + 1.;
759:   PetscCall(DMPlexCreateBoxMesh(PETSC_COMM_SELF, 3, PETSC_FALSE, faces, lower, upper, NULL, PETSC_TRUE, 0, PETSC_TRUE, dm));
760:   PetscCall(PetscObjectSetName((PetscObject)*dm, "box"));
761:   // Flip edges to make fault non-oriented
762:   switch (rank) {
763:   case 2:
764:     PetscCall(DMPlexOrientPoint(*dm, 10, -1));
765:     break;
766:   case 3:
767:     PetscCall(DMPlexOrientPoint(*dm, 9, -1));
768:     break;
769:   default:
770:     break;
771:   }
772:   // Need this so that all procs create the cell types
773:   PetscCall(DMPlexGetCellTypeLabel(*dm, &label));
774:   // Replace comm in object (copied from PetscHeaderCreate/Destroy())
775:   PetscCall(PetscCommDestroy(&(*dm)->hdr.comm));
776:   PetscCall(PetscCommDuplicate(comm, &(*dm)->hdr.comm, &(*dm)->hdr.tag));
777:   PetscCallMPI(MPI_Comm_get_attr((*dm)->hdr.comm, Petsc_CreationIdx_keyval, &get_tmp, &flg));
778:   PetscCheck(flg, (*dm)->hdr.comm, PETSC_ERR_ARG_CORRUPT, "MPI_Comm does not have an object creation index");
779:   cidx            = (PetscInt64 *)get_tmp;
780:   (*dm)->hdr.cidx = (*cidx)++;
781:   // Create new pointSF
782:   {
783:     PetscSF      sf;
784:     PetscInt    *local  = NULL;
785:     PetscSFNode *remote = NULL;
786:     PetscInt     Nl;

788:     PetscCall(PetscSFCreate(comm, &sf));
789:     switch (rank) {
790:     case 0:
791:       Nl = 15;
792:       PetscCall(PetscMalloc1(Nl, &local));
793:       PetscCall(PetscMalloc1(Nl, &remote));
794:       local[0]         = 2;
795:       remote[0].index  = 1;
796:       remote[0].rank   = 1;
797:       local[1]         = 4;
798:       remote[1].index  = 3;
799:       remote[1].rank   = 1;
800:       local[2]         = 5;
801:       remote[2].index  = 1;
802:       remote[2].rank   = 2;
803:       local[3]         = 6;
804:       remote[3].index  = 1;
805:       remote[3].rank   = 3;
806:       local[4]         = 7;
807:       remote[4].index  = 3;
808:       remote[4].rank   = 2;
809:       local[5]         = 8;
810:       remote[5].index  = 3;
811:       remote[5].rank   = 3;
812:       local[6]         = 17;
813:       remote[6].index  = 15;
814:       remote[6].rank   = 2;
815:       local[7]         = 18;
816:       remote[7].index  = 16;
817:       remote[7].rank   = 2;
818:       local[8]         = 20;
819:       remote[8].index  = 19;
820:       remote[8].rank   = 1;
821:       local[9]         = 21;
822:       remote[9].index  = 19;
823:       remote[9].rank   = 2;
824:       local[10]        = 22;
825:       remote[10].index = 19;
826:       remote[10].rank  = 3;
827:       local[11]        = 24;
828:       remote[11].index = 23;
829:       remote[11].rank  = 1;
830:       local[12]        = 26;
831:       remote[12].index = 25;
832:       remote[12].rank  = 1;
833:       local[13]        = 10;
834:       remote[13].index = 9;
835:       remote[13].rank  = 1;
836:       local[14]        = 14;
837:       remote[14].index = 13;
838:       remote[14].rank  = 2;
839:       break;
840:     case 1:
841:       Nl = 9;
842:       PetscCall(PetscMalloc1(Nl, &local));
843:       PetscCall(PetscMalloc1(Nl, &remote));
844:       local[0]        = 5;
845:       remote[0].index = 1;
846:       remote[0].rank  = 3;
847:       local[1]        = 6;
848:       remote[1].index = 2;
849:       remote[1].rank  = 3;
850:       local[2]        = 7;
851:       remote[2].index = 3;
852:       remote[2].rank  = 3;
853:       local[3]        = 8;
854:       remote[3].index = 4;
855:       remote[3].rank  = 3;
856:       local[4]        = 17;
857:       remote[4].index = 15;
858:       remote[4].rank  = 3;
859:       local[5]        = 18;
860:       remote[5].index = 16;
861:       remote[5].rank  = 3;
862:       local[6]        = 21;
863:       remote[6].index = 19;
864:       remote[6].rank  = 3;
865:       local[7]        = 22;
866:       remote[7].index = 20;
867:       remote[7].rank  = 3;
868:       local[8]        = 14;
869:       remote[8].index = 13;
870:       remote[8].rank  = 3;
871:       break;
872:     case 2:
873:       Nl = 9;
874:       PetscCall(PetscMalloc1(Nl, &local));
875:       PetscCall(PetscMalloc1(Nl, &remote));
876:       local[0]        = 2;
877:       remote[0].index = 1;
878:       remote[0].rank  = 3;
879:       local[1]        = 4;
880:       remote[1].index = 3;
881:       remote[1].rank  = 3;
882:       local[2]        = 6;
883:       remote[2].index = 5;
884:       remote[2].rank  = 3;
885:       local[3]        = 8;
886:       remote[3].index = 7;
887:       remote[3].rank  = 3;
888:       local[4]        = 20;
889:       remote[4].index = 19;
890:       remote[4].rank  = 3;
891:       local[5]        = 22;
892:       remote[5].index = 21;
893:       remote[5].rank  = 3;
894:       local[6]        = 24;
895:       remote[6].index = 23;
896:       remote[6].rank  = 3;
897:       local[7]        = 26;
898:       remote[7].index = 25;
899:       remote[7].rank  = 3;
900:       local[8]        = 10;
901:       remote[8].index = 9;
902:       remote[8].rank  = 3;
903:       break;
904:     case 3:
905:       Nl = 0;
906:       break;
907:     default:
908:       SETERRQ(comm, PETSC_ERR_SUP, "This example only supports 4 ranks");
909:     }
910:     PetscCall(PetscSFSetGraph(sf, 27, Nl, local, PETSC_OWN_POINTER, remote, PETSC_OWN_POINTER));
911:     PetscCall(DMSetPointSF(*dm, sf));
912:     PetscCall(PetscSFDestroy(&sf));
913:   }
914:   // Create fault label
915:   PetscCall(DMCreateLabel(*dm, "fault"));
916:   PetscCall(DMGetLabel(*dm, "fault", &label));
917:   switch (rank) {
918:   case 0:
919:   case 2:
920:     PetscCall(DMLabelSetValue(label, 10, 2));
921:     PetscCall(DMLabelSetValue(label, 20, 1));
922:     PetscCall(DMLabelSetValue(label, 22, 1));
923:     PetscCall(DMLabelSetValue(label, 24, 1));
924:     PetscCall(DMLabelSetValue(label, 26, 1));
925:     PetscCall(DMLabelSetValue(label, 2, 0));
926:     PetscCall(DMLabelSetValue(label, 4, 0));
927:     PetscCall(DMLabelSetValue(label, 6, 0));
928:     PetscCall(DMLabelSetValue(label, 8, 0));
929:     break;
930:   case 1:
931:   case 3:
932:     PetscCall(DMLabelSetValue(label, 9, 2));
933:     PetscCall(DMLabelSetValue(label, 19, 1));
934:     PetscCall(DMLabelSetValue(label, 21, 1));
935:     PetscCall(DMLabelSetValue(label, 23, 1));
936:     PetscCall(DMLabelSetValue(label, 25, 1));
937:     PetscCall(DMLabelSetValue(label, 1, 0));
938:     PetscCall(DMLabelSetValue(label, 3, 0));
939:     PetscCall(DMLabelSetValue(label, 5, 0));
940:     PetscCall(DMLabelSetValue(label, 7, 0));
941:     break;
942:   default:
943:     break;
944:   }
945:   PetscCall(DMPlexOrientLabel(*dm, label));
946:   PetscCall(DMPlexLabelCohesiveComplete(*dm, label, NULL, 1, PETSC_FALSE, PETSC_FALSE, NULL));
947:   PetscCall(DMPlexDistributeSetDefault(*dm, PETSC_FALSE));
948:   PetscFunctionReturn(PETSC_SUCCESS);
949: }

951: static PetscErrorCode CreateMesh(MPI_Comm comm, AppCtx *user, DM *dm)
952: {
953:   PetscFunctionBegin;
954:   switch (user->testNum) {
955:   case 1:
956:     PetscCall(CreateQuadMesh1(comm, user, dm));
957:     break;
958:   case 2:
959:     PetscCall(CreateHexMesh1(comm, user, dm));
960:     break;
961:   default:
962:     PetscCall(DMCreate(comm, dm));
963:     PetscCall(DMSetType(*dm, DMPLEX));
964:     break;
965:   }
966:   PetscCall(DMSetFromOptions(*dm));
967:   {
968:     const char *prefix;

970:     // We cannot redistribute with cohesive cells in the SF
971:     PetscCall(DMPlexDistributeSetDefault(*dm, PETSC_FALSE));
972:     PetscCall(PetscObjectGetOptionsPrefix((PetscObject)*dm, &prefix));
973:     PetscCall(PetscObjectSetOptionsPrefix((PetscObject)*dm, "f0_"));
974:     PetscCall(DMSetFromOptions(*dm));
975:     PetscCall(PetscObjectSetOptionsPrefix((PetscObject)*dm, "f1_"));
976:     PetscCall(DMSetFromOptions(*dm));
977:     PetscCall(PetscObjectSetOptionsPrefix((PetscObject)*dm, prefix));
978:   }
979:   PetscCall(DMViewFromOptions(*dm, NULL, "-dm_view"));
980:   PetscFunctionReturn(PETSC_SUCCESS);
981: }

983: int main(int argc, char **argv)
984: {
985:   DM     dm;
986:   AppCtx user;

988:   PetscFunctionBeginUser;
989:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
990:   PetscCall(ProcessOptions(PETSC_COMM_WORLD, &user));
991:   PetscCall(CreateMesh(PETSC_COMM_WORLD, &user, &dm));
992:   PetscCall(DMDestroy(&dm));
993:   PetscCall(PetscFinalize());
994:   return 0;
995: }

997: /*TEST

999:   testset:
1000:     requires: triangle
1001:     args: -dm_refine 1 -dm_plex_transform_type cohesive_extrude \
1002:             -dm_plex_transform_active fault \
1003:           -dm_view ::ascii_info_detail -coarse_dm_view ::ascii_info_detail

1005:     test:
1006:       suffix: tri_0
1007:       args: -dm_plex_box_faces 1,1 -dm_plex_cohesive_label_fault 8
1008:     test:
1009:       suffix: tri_1
1010:       args: -dm_plex_box_faces 1,1 -dm_plex_cohesive_label_fault 8 \
1011:               -dm_plex_transform_extrude_use_tensor 0
1012:     test:
1013:       suffix: tri_2
1014:       args: -dm_plex_file_contents dat:tri_2_cv -dm_plex_cohesive_label_fault 11,15
1015:     test:
1016:       suffix: tri_3
1017:       nsize: 2
1018:       args: -dm_plex_file_contents dat:tri_2_cv -dm_plex_cohesive_label_fault 11,15 \
1019:               -petscpartitioner_type shell -petscpartitioner_shell_sizes 2,2 \
1020:               -petscpartitioner_shell_points 0,3,1,2

1022:   testset:
1023:     args: -dm_plex_simplex 0 -dm_plex_box_faces 2,1 \
1024:           -dm_refine 1 -dm_plex_transform_type cohesive_extrude \
1025:             -dm_plex_transform_active fault -dm_plex_cohesive_label_fault 13 \
1026:           -dm_view ::ascii_info_detail -coarse_dm_view ::ascii_info_detail

1028:     test:
1029:       suffix: quad_0
1030:     test:
1031:       suffix: quad_1
1032:       args: -dm_plex_transform_extrude_use_tensor 0
1033:     test:
1034:       suffix: quad_2
1035:       nsize: 2
1036:       args: -petscpartitioner_type simple

1038:   test:
1039:     suffix: quad_3
1040:     nsize: 4
1041:     args: -test_num 1 \
1042:           -dm_refine 1 -dm_plex_transform_type cohesive_extrude \
1043:             -dm_plex_transform_active fault \
1044:           -dm_view ::ascii_info_detail -coarse_dm_view ::ascii_info_detail \
1045:           -orientation_view -orientation_view_synchronized

1047:   test:
1048:     suffix: quad_4
1049:     args: -dm_plex_simplex 0 -dm_plex_box_faces 3,2 \
1050:           -dm_refine 1 -dm_plex_transform_type cohesive_extrude \
1051:             -dm_plex_transform_active fault -dm_plex_cohesive_label_fault 22,23 \
1052:           -dm_view ::ascii_info_detail -coarse_dm_view ::ascii_info_detail

1054:   test:
1055:     suffix: quad_5
1056:     args: -dm_plex_simplex 0 -dm_plex_box_faces 3,2 \
1057:             -dm_plex_cohesive_label_fault0 21 \
1058:             -dm_plex_cohesive_label_fault1 23 \
1059:           -f0_dm_refine 1 -f0_dm_plex_transform_type cohesive_extrude \
1060:             -f0_dm_plex_transform_active fault0  -f0_coarse_dm_view ::ascii_info_detail \
1061:           -f1_dm_refine 1 -f1_dm_plex_transform_type cohesive_extrude \
1062:             -f1_dm_plex_transform_active fault1  -f1_coarse_dm_view ::ascii_info_detail \
1063:           -dm_view ::ascii_info_detail

1065:   test:
1066:     suffix: quad_6
1067:     args: -dm_plex_simplex 0 -dm_plex_box_faces 3,2 \
1068:             -dm_plex_cohesive_label_fault0 22,23 \
1069:             -dm_plex_cohesive_label_fault1 32 \
1070:           -f0_dm_refine 1 -f0_dm_plex_transform_type cohesive_extrude \
1071:             -f0_dm_plex_transform_active fault0  -f0_coarse_dm_view ::ascii_info_detail \
1072:           -f1_dm_refine 1 -f1_dm_plex_transform_type cohesive_extrude \
1073:             -f1_dm_plex_transform_active fault1  -f1_coarse_dm_view ::ascii_info_detail \
1074:           -dm_view ::ascii_info_detail

1076:   test:
1077:     suffix: quad_6w
1078:     args: -dm_plex_simplex 0 -dm_plex_box_faces 3,2 \
1079:             -dm_plex_cohesive_label_fault0 22,23 \
1080:             -dm_plex_cohesive_label_fault1 32 \
1081:           -f0_dm_refine 1 -f0_dm_plex_transform_type cohesive_extrude \
1082:             -f0_dm_plex_transform_active fault0  -f0_coarse_dm_view ::ascii_info_detail \
1083:             -f0_dm_plex_transform_cohesive_width 0.05 \
1084:           -f1_dm_refine 1 -f1_dm_plex_transform_type cohesive_extrude \
1085:             -f1_dm_plex_transform_active fault1  -f1_coarse_dm_view ::ascii_info_detail \
1086:             -f1_dm_plex_transform_cohesive_width 0.05 \
1087:           -dm_view ::ascii_info_detail

1089:   testset:
1090:     args: -dm_plex_dim 3 -dm_plex_shape doublet \
1091:           -dm_refine 1 -dm_plex_transform_type cohesive_extrude \
1092:             -dm_plex_transform_active fault -dm_plex_cohesive_label_fault 7 \
1093:           -dm_view ::ascii_info_detail -coarse_dm_view ::ascii_info_detail

1095:     test:
1096:       suffix: tet_0
1097:     test:
1098:       suffix: tet_1
1099:       nsize: 2
1100:       args: -petscpartitioner_type simple

1102:   testset:
1103:     args: -dm_plex_dim 3 -dm_plex_simplex 0 -dm_plex_box_faces 2,1,1 -dm_plex_box_upper 2,1,1 \
1104:           -dm_refine 1 -dm_plex_transform_type cohesive_extrude \
1105:             -dm_plex_transform_active fault -dm_plex_cohesive_label_fault 15 \
1106:           -dm_view ::ascii_info_detail -coarse_dm_view ::ascii_info_detail

1108:     test:
1109:       suffix: hex_0
1110:     test:
1111:       suffix: hex_1
1112:       nsize: 2
1113:       args: -petscpartitioner_type simple

1115:   test:
1116:     suffix: hex_2
1117:     nsize: 4
1118:     args: -test_num 2 \
1119:           -dm_refine 1 -dm_plex_transform_type cohesive_extrude \
1120:             -dm_plex_transform_active fault \
1121:           -dm_view ::ascii_info_detail -coarse_dm_view ::ascii_info_detail \
1122:           -orientation_view -orientation_view_synchronized

1124:   test:
1125:     suffix: hex_3
1126:     args: -dm_plex_dim 3 -dm_plex_simplex 0 -dm_plex_box_faces 2,1,2 -dm_plex_box_upper 2.,1.,2. \
1127:             -dm_plex_cohesive_label_fault0 37,40 \
1128:             -dm_plex_cohesive_label_fault1 26 \
1129:           -f0_dm_refine 1 -f0_dm_plex_transform_type cohesive_extrude \
1130:             -f0_dm_plex_transform_active fault0  -f0_coarse_dm_view ::ascii_info_detail \
1131:           -f1_dm_refine 1 -f1_dm_plex_transform_type cohesive_extrude \
1132:             -f1_dm_plex_transform_active fault1  -f1_coarse_dm_view ::ascii_info_detail \
1133:           -dm_view ::ascii_info_detail

1135:   test:
1136:     suffix: hex_4
1137:     args: -dm_plex_dim 3 -dm_plex_simplex 0 -dm_plex_box_faces 4,1,2 -dm_plex_box_upper 4.,1.,2. \
1138:             -dm_plex_cohesive_label_fault0 65,68 \
1139:             -dm_plex_cohesive_label_fault1 46 \
1140:           -f0_dm_refine 1 -f0_dm_plex_transform_type cohesive_extrude \
1141:             -f0_dm_plex_transform_active fault0  -f0_coarse_dm_view ::ascii_info_detail \
1142:           -f1_dm_refine 1 -f1_dm_plex_transform_type cohesive_extrude \
1143:             -f1_dm_plex_transform_active fault1  -f1_coarse_dm_view ::ascii_info_detail \
1144:           -dm_view ::ascii_info_detail

1146: TEST*/