plexreorder.c (cfd92c66bdae16b66d27a6336fb90fa54c459cc4) plexreorder.c (d02c7345ebed081476ce6bcdfd784b34c024d6ef)
1#include <petsc/private/dmpleximpl.h> /*I "petscdmplex.h" I*/
2#include <petsc/private/matorderimpl.h> /*I "petscmat.h" I*/
3#include <petsc/private/dmlabelimpl.h>
4
5static PetscErrorCode DMPlexCreateOrderingClosure_Static(DM dm, PetscInt numPoints, const PetscInt pperm[], PetscInt **clperm, PetscInt **invclperm)
6{
7 PetscInt *perm, *iperm;
8 PetscInt depth, d, pStart, pEnd, fStart, fMax, fEnd, p;

--- 414 unchanged lines hidden (view full) ---

423PetscErrorCode DMPlexReorderGetDefault(DM dm, DMPlexReorderDefaultFlag *reorder)
424{
425 PetscFunctionBegin;
426 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
427 PetscAssertPointer(reorder, 2);
428 PetscUseMethod(dm, "DMPlexReorderGetDefault_C", (DM, DMPlexReorderDefaultFlag *), (dm, reorder));
429 PetscFunctionReturn(PETSC_SUCCESS);
430}
1#include <petsc/private/dmpleximpl.h> /*I "petscdmplex.h" I*/
2#include <petsc/private/matorderimpl.h> /*I "petscmat.h" I*/
3#include <petsc/private/dmlabelimpl.h>
4
5static PetscErrorCode DMPlexCreateOrderingClosure_Static(DM dm, PetscInt numPoints, const PetscInt pperm[], PetscInt **clperm, PetscInt **invclperm)
6{
7 PetscInt *perm, *iperm;
8 PetscInt depth, d, pStart, pEnd, fStart, fMax, fEnd, p;

--- 414 unchanged lines hidden (view full) ---

423PetscErrorCode DMPlexReorderGetDefault(DM dm, DMPlexReorderDefaultFlag *reorder)
424{
425 PetscFunctionBegin;
426 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
427 PetscAssertPointer(reorder, 2);
428 PetscUseMethod(dm, "DMPlexReorderGetDefault_C", (DM, DMPlexReorderDefaultFlag *), (dm, reorder));
429 PetscFunctionReturn(PETSC_SUCCESS);
430}
431
432// Reorder to group split nodes
433PetscErrorCode DMPlexCreateSectionPermutation_Internal(DM dm, IS *permutation, PetscBT *blockStarts)
434{
435 IS permIS;
436 PetscBT bt, blst;
437 PetscInt *perm;
438 PetscInt pStart, pEnd, i = 0;
439
440 PetscFunctionBegin;
441 *permutation = NULL;
442 *blockStarts = NULL;
443 {
444 DMPlexReorderDefaultFlag reorder;
445 PetscCall(DMPlexReorderSectionGetDefault(dm, &reorder));
446 if (reorder != DMPLEX_REORDER_DEFAULT_TRUE) PetscFunctionReturn(PETSC_SUCCESS);
447 }
448 PetscCall(DMPlexGetChart(dm, &pStart, &pEnd));
449 PetscCall(PetscMalloc1(pEnd - pStart, &perm));
450 PetscCall(PetscBTCreate(pEnd - pStart, &bt));
451 PetscCall(PetscBTCreate(pEnd - pStart, &blst));
452 for (PetscInt p = pStart; p < pEnd; ++p) {
453 const PetscInt *supp, *cone;
454 PetscInt suppSize;
455
456 if (PetscBTLookupSet(bt, p)) continue;
457 PetscCall(PetscBTSet(blst, p));
458 perm[i++] = p;
459 // Check for tensor cells in the support
460 PetscCall(DMPlexGetSupport(dm, p, &supp));
461 PetscCall(DMPlexGetSupportSize(dm, p, &suppSize));
462 for (PetscInt s = 0; s < suppSize; ++s) {
463 DMPolytopeType ct;
464 PetscInt q, qq;
465
466 PetscCall(DMPlexGetCellType(dm, supp[s], &ct));
467 switch (ct) {
468 case DM_POLYTOPE_POINT_PRISM_TENSOR:
469 case DM_POLYTOPE_SEG_PRISM_TENSOR:
470 case DM_POLYTOPE_TRI_PRISM_TENSOR:
471 case DM_POLYTOPE_QUAD_PRISM_TENSOR:
472 // If found, move up the split partner of the tensor cell, and the cell itself
473 PetscCall(DMPlexGetCone(dm, supp[s], &cone));
474 qq = supp[s];
475 q = (cone[0] == p) ? cone[1] : cone[0];
476 if (!PetscBTLookupSet(bt, q)) {
477 perm[i++] = q;
478 s = suppSize;
479 }
480 if (!PetscBTLookupSet(bt, qq)) {
481 perm[i++] = qq;
482 s = suppSize;
483 }
484 break;
485 default:
486 break;
487 }
488 }
489 }
490 PetscCall(PetscBTDestroy(&bt));
491 PetscCheck(i == pEnd - pStart, PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Number of points in permutation %" PetscInt_FMT " does not match chart size %" PetscInt_FMT, i, pEnd - pStart);
492 PetscCall(ISCreateGeneral(PETSC_COMM_SELF, pEnd - pStart, perm, PETSC_OWN_POINTER, &permIS));
493 PetscCall(ISSetPermutation(permIS));
494 *permutation = permIS;
495 *blockStarts = blst;
496 PetscFunctionReturn(PETSC_SUCCESS);
497}
498
499PetscErrorCode DMPlexReorderSectionSetDefault_Plex(DM dm, DMPlexReorderDefaultFlag reorder)
500{
501 DM_Plex *mesh = (DM_Plex *)dm->data;
502
503 PetscFunctionBegin;
504 mesh->reorderSection = reorder;
505 PetscFunctionReturn(PETSC_SUCCESS);
506}
507
508/*@
509 DMPlexReorderSectionSetDefault - Set flag indicating whether the local section should be reordered by default
510
511 Logically collective
512
513 Input Parameters:
514+ dm - The DM
515- reorder - Flag for reordering
516
517 Level: intermediate
518
519.seealso: `DMPlexReorderSectionGetDefault()`
520@*/
521PetscErrorCode DMPlexReorderSectionSetDefault(DM dm, DMPlexReorderDefaultFlag reorder)
522{
523 PetscFunctionBegin;
524 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
525 PetscTryMethod(dm, "DMPlexReorderSectionSetDefault_C", (DM, DMPlexReorderDefaultFlag), (dm, reorder));
526 PetscFunctionReturn(PETSC_SUCCESS);
527}
528
529PetscErrorCode DMPlexReorderSectionGetDefault_Plex(DM dm, DMPlexReorderDefaultFlag *reorder)
530{
531 DM_Plex *mesh = (DM_Plex *)dm->data;
532
533 PetscFunctionBegin;
534 *reorder = mesh->reorderSection;
535 PetscFunctionReturn(PETSC_SUCCESS);
536}
537
538/*@
539 DMPlexReorderSectionGetDefault - Get flag indicating whether the local section should be reordered by default
540
541 Not collective
542
543 Input Parameter:
544. dm - The DM
545
546 Output Parameter:
547. reorder - Flag for reordering
548
549 Level: intermediate
550
551.seealso: `DMPlexReorderSetDefault()`
552@*/
553PetscErrorCode DMPlexReorderSectionGetDefault(DM dm, DMPlexReorderDefaultFlag *reorder)
554{
555 PetscFunctionBegin;
556 PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
557 PetscAssertPointer(reorder, 2);
558 PetscUseMethod(dm, "DMPlexReorderSectionGetDefault_C", (DM, DMPlexReorderDefaultFlag *), (dm, reorder));
559 PetscFunctionReturn(PETSC_SUCCESS);
560}