Commits

Matt Knepley committed 99f3bb6

DMPlex ex4: Reworked 2D simplex hybrid test

  • Participants
  • Parent commits 19d7d79

Comments (0)

Files changed (5)

File src/dm/impls/plex/examples/tests/ex4.c

       \ |      | /
         4--15--7
 */
-PetscErrorCode CreateSimplexHybrid_2D(MPI_Comm comm, DM dm)
+PetscErrorCode CreateSimplexHybrid_2D(MPI_Comm comm, PetscInt testNum, DM *dm)
 {
-  Vec            coordinates;
-  PetscSection   coordSection;
-  PetscScalar    *coords;
-  PetscInt       numVertices = 0, numEdges = 0, numCells = 0, cMax = PETSC_DETERMINE, fMax = PETSC_DETERMINE;
-  PetscInt       firstVertex, firstEdge, coordSize;
-  PetscInt       v, e;
+  DM             idm, hdm;
+  DMLabel        faultLabel, hybridLabel;
+  PetscInt       p;
   PetscMPIInt    rank;
   PetscErrorCode ierr;
 
   PetscFunctionBegin;
   ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr);
   if (!rank) {
-    numVertices = 3 + 3;
-    numEdges    = 6 + 2;
-    numCells    = 3;
-    cMax        = 2;
-    fMax        = 15;
-  }
-  firstVertex = numCells;
-  firstEdge   = numCells + numVertices;
-  ierr        = DMPlexSetChart(dm, 0, numCells+numEdges+numVertices);CHKERRQ(ierr);
-  if (numCells) {
-    ierr = DMPlexSetConeSize(dm, 0, 3);CHKERRQ(ierr);
-    ierr = DMPlexSetConeSize(dm, 1, 3);CHKERRQ(ierr);
-    ierr = DMPlexSetConeSize(dm, 2, 4);CHKERRQ(ierr);
-  }
-  for (e = firstEdge; e < firstEdge+numEdges; ++e) {
-    ierr = DMPlexSetConeSize(dm, e, 2);CHKERRQ(ierr);
-  }
-  ierr = DMSetUp(dm);CHKERRQ(ierr); /* Allocate space for cones */
-  ierr = DMPlexSetHybridBounds(dm, cMax, PETSC_DETERMINE, fMax, PETSC_DETERMINE);CHKERRQ(ierr); /* Indicate a hybrid mesh */
-  /* Build cells */
-  if (numCells > 0) {
-    const PetscInt cone[3] = {9, 10, 11};
-    const PetscInt ornt[3] = {0,  0,  0};
-    const PetscInt cell    = 0;
-
-    ierr = DMPlexSetCone(dm, cell, cone);CHKERRQ(ierr);
-    ierr = DMPlexSetConeOrientation(dm, cell, ornt);CHKERRQ(ierr);
-  }
-  if (numCells > 1) {
-    const PetscInt cone[3] = {12, 14, 13};
-    const PetscInt ornt[3] = { 0, -2,  0};
-    const PetscInt cell    = 1;
-
-    ierr = DMPlexSetCone(dm, cell, cone);CHKERRQ(ierr);
-    ierr = DMPlexSetConeOrientation(dm, cell, ornt);CHKERRQ(ierr);
-  }
-  if (numCells > 2) {
-    const PetscInt cone[4] = {10, 14, 15, 16};
-    const PetscInt ornt[4] = { 0,  0,  0,  0};
-    const PetscInt cell    = 2;
-
-    ierr = DMPlexSetCone(dm, cell, cone);CHKERRQ(ierr);
-    ierr = DMPlexSetConeOrientation(dm, cell, ornt);CHKERRQ(ierr);
-  }
-  /* Build edges*/
-  if (numEdges > 0) {
-    const PetscInt cone[2] = {3, 4};
-    const PetscInt edge    = 9;
-
-    ierr = DMPlexSetCone(dm, edge, cone);CHKERRQ(ierr);
-    ierr = DMPlexSetLabelValue(dm, "marker", edge, 1);CHKERRQ(ierr);
-  }
-  if (numEdges > 1) {
-    const PetscInt cone[2] = {4, 5};
-    const PetscInt edge    = 10;
-
-    ierr = DMPlexSetCone(dm, edge, cone);CHKERRQ(ierr);
-  }
-  if (numEdges > 2) {
-    const PetscInt cone[2] = {5, 3};
-    const PetscInt edge    = 11;
-
-    ierr = DMPlexSetCone(dm, edge, cone);CHKERRQ(ierr);
-    ierr = DMPlexSetLabelValue(dm, "marker", edge, 1);CHKERRQ(ierr);
-  }
-  if (numEdges > 3) {
-    const PetscInt cone[2] = {6, 8};
-    const PetscInt edge    = 12;
-
-    ierr = DMPlexSetCone(dm, edge, cone);CHKERRQ(ierr);
-    ierr = DMPlexSetLabelValue(dm, "marker", edge, 1);CHKERRQ(ierr);
-  }
-  if (numEdges > 4) {
-    const PetscInt cone[2] = {7, 6};
-    const PetscInt edge    = 13;
-
-    ierr = DMPlexSetCone(dm, edge, cone);CHKERRQ(ierr);
-    ierr = DMPlexSetLabelValue(dm, "marker", edge, 1);CHKERRQ(ierr);
-  }
-  if (numEdges > 5) {
-    const PetscInt cone[2] = {7, 8};
-    const PetscInt edge    = 14;
-
-    ierr = DMPlexSetCone(dm, edge, cone);CHKERRQ(ierr);
-  }
-  if (numEdges > 6) {
-    const PetscInt cone[2] = {4, 7};
-    const PetscInt edge    = 15;
+    switch (testNum) {
+    case 0:
+    {
+      PetscInt    numPoints[2]        = {4, 2};
+      PetscInt    coneSize[6]         = {3, 3, 0, 0, 0, 0};
+      PetscInt    cones[6]            = {2, 3, 4,  5, 4, 3};
+      PetscInt    coneOrientations[6] = {0, 0, 0,  0, 0, 0};
+      PetscScalar vertexCoords[8]     = {-1.0, -0.5,  0.0, -0.5,  0.0, 0.5,  1.0, 0.5};
+      PetscInt    faultPoints[2]      = {3, 4};
 
-    ierr = DMPlexSetCone(dm, edge, cone);CHKERRQ(ierr);
-  }
-  if (numEdges > 7) {
-    const PetscInt cone[2] = {5, 8};
-    const PetscInt edge    = 16;
+      ierr = DMPlexCreateFromDAG(*dm, 1, numPoints, coneSize, cones, coneOrientations, vertexCoords);CHKERRQ(ierr);
+      for(p = 0; p < 2; ++p) {ierr = DMPlexSetLabelValue(*dm, "fault", faultPoints[p], 1);CHKERRQ(ierr);}
+    }
+    break;
+    break;
+    default: SETERRQ1(comm, PETSC_ERR_ARG_OUTOFRANGE, "No test mesh %d", testNum);
+    }
+    ierr = DMPlexCheckSymmetry(*dm);CHKERRQ(ierr);
+    ierr = DMPlexInterpolate(*dm, &idm);CHKERRQ(ierr);
+    ierr = DMPlexCopyCoordinates(*dm, idm);CHKERRQ(ierr);
+    ierr = PetscObjectSetOptionsPrefix((PetscObject) idm, "in_");CHKERRQ(ierr);
+    ierr = DMSetFromOptions(idm);CHKERRQ(ierr);
+    ierr = DMPlexCheckSymmetry(idm);CHKERRQ(ierr);
+    ierr = DMPlexGetLabel(*dm, "fault", &faultLabel);CHKERRQ(ierr);
+    ierr = DMPlexCreateHybridMesh(idm, faultLabel, &hybridLabel, &hdm);CHKERRQ(ierr);
+    ierr = DMLabelDestroy(&hybridLabel);CHKERRQ(ierr);
+    ierr = DMDestroy(&idm);CHKERRQ(ierr);
+    ierr = DMDestroy(dm);CHKERRQ(ierr);
+    *dm  = hdm;
+  } else {
+    PetscInt numPoints[2] = {0, 0};
 
-    ierr = DMPlexSetCone(dm, edge, cone);CHKERRQ(ierr);
-  }
-  ierr = DMPlexSymmetrize(dm);CHKERRQ(ierr);
-  ierr = DMPlexStratify(dm);CHKERRQ(ierr);
-  /* Build coordinates */
-  ierr = DMPlexGetCoordinateSection(dm, &coordSection);CHKERRQ(ierr);
-  ierr = PetscSectionSetChart(coordSection, firstVertex, firstVertex+numVertices);CHKERRQ(ierr);
-  for (v = firstVertex; v < firstVertex+numVertices; ++v) {
-    ierr = PetscSectionSetDof(coordSection, v, 2);CHKERRQ(ierr);
-  }
-  ierr = PetscSectionSetUp(coordSection);CHKERRQ(ierr);
-  ierr = PetscSectionGetStorageSize(coordSection, &coordSize);CHKERRQ(ierr);
-  ierr = VecCreate(PetscObjectComm((PetscObject)dm), &coordinates);CHKERRQ(ierr);
-  ierr = VecSetSizes(coordinates, coordSize, PETSC_DETERMINE);CHKERRQ(ierr);
-  ierr = VecSetFromOptions(coordinates);CHKERRQ(ierr);
-  ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr);
-  if (numVertices) {
-    coords[0]  = -0.5; coords[1]  = 0.5;
-    coords[2]  = -0.2; coords[3]  = 0.0;
-    coords[4]  = -0.2; coords[5]  = 1.0;
-    coords[6]  =  0.5; coords[7]  = 0.5;
-    coords[8]  =  0.2; coords[9]  = 0.0;
-    coords[10] =  0.2; coords[11] = 1.0;
+    ierr = DMPlexCreateFromDAG(*dm, 1, numPoints, NULL, NULL, NULL, NULL);CHKERRQ(ierr);
+    ierr = DMPlexInterpolate(*dm, &idm);CHKERRQ(ierr);
+    ierr = DMPlexCopyCoordinates(*dm, idm);CHKERRQ(ierr);
+    ierr = PetscObjectSetOptionsPrefix((PetscObject) idm, "in_");CHKERRQ(ierr);
+    ierr = DMSetFromOptions(idm);CHKERRQ(ierr);
+    ierr = DMPlexCreateHybridMesh(idm, NULL, NULL, &hdm);CHKERRQ(ierr);
+    ierr = DMDestroy(&idm);CHKERRQ(ierr);
+    ierr = DMDestroy(dm);CHKERRQ(ierr);
+    *dm  = hdm;
   }
-  ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr);
-  ierr = DMSetCoordinatesLocal(dm, coordinates);CHKERRQ(ierr);
-  ierr = VecDestroy(&coordinates);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 
   case 2:
     if (cellSimplex) {
       if (cellHybrid) {
-        ierr = CreateSimplexHybrid_2D(comm, *dm);CHKERRQ(ierr);
+        ierr = CreateSimplexHybrid_2D(comm, user->testNum, dm);CHKERRQ(ierr);
       } else {
         ierr = CreateSimplex_2D(comm, dm);CHKERRQ(ierr);
       }

File src/dm/impls/plex/examples/tests/output/ex4_4.out

 [0]: 5 ----> 16
 [0]: 6 ----> 12
 [0]: 6 ----> 13
-[0]: 7 ----> 13
 [0]: 7 ----> 14
+[0]: 7 ----> 13
 [0]: 7 ----> 15
-[0]: 8 ----> 12
 [0]: 8 ----> 14
+[0]: 8 ----> 12
 [0]: 8 ----> 16
 [0]: 9 ----> 0
 [0]: 10 ----> 0
 [0]: 11 ----> 0
 [0]: 12 ----> 1
 [0]: 13 ----> 1
-[0]: 14 ----> 1
 [0]: 14 ----> 2
+[0]: 14 ----> 1
 [0]: 15 ----> 2
 [0]: 16 ----> 2
 base <-- cap:
 [0]: 15 <---- 7 (0)
 [0]: 16 <---- 5 (0)
 [0]: 16 <---- 8 (0)
-Vec_0x84000000_0
+coordinates with 1 fields
+  field 0 with 2 components
 Process 0:
-  (   3) dim  2 offset   0 -0.5 0.5
-  (   4) dim  2 offset   2 -0.2 0
-  (   5) dim  2 offset   4 -0.2 1
-  (   6) dim  2 offset   6 0.5 0.5
-  (   7) dim  2 offset   8 0.2 0
-  (   8) dim  2 offset  10 0.2 1
-Label 'marker':
-[0]: 9 (1)
-[0]: 11 (1)
-[0]: 12 (1)
-[0]: 13 (1)
+  (   3) dim  2 offset   0 -1 -0.5
+  (   4) dim  2 offset   2 0 -0.5
+  (   5) dim  2 offset   4 0 0.5
+  (   6) dim  2 offset   6 1 0.5
+  (   7) dim  2 offset   8 0 -0.5
+  (   8) dim  2 offset  10 0 0.5

File src/dm/impls/plex/examples/tests/output/ex4_5.out

 [0]: 12 ----> 41
 [0]: 13 ----> 28
 [0]: 13 ----> 31
-[0]: 14 ----> 30
 [0]: 14 ----> 32
+[0]: 14 ----> 30
 [0]: 14 ----> 40
-[0]: 15 ----> 29
 [0]: 15 ----> 33
+[0]: 15 ----> 29
 [0]: 15 ----> 41
 [0]: 16 ----> 22
 [0]: 16 ----> 23
 [0]: 20 ----> 39
 [0]: 21 ----> 32
 [0]: 21 ----> 33
+[0]: 21 ----> 42
 [0]: 21 ----> 37
 [0]: 21 ----> 38
-[0]: 21 ----> 42
 [0]: 22 ----> 0
 [0]: 23 ----> 1
 [0]: 24 ----> 1
 [0]: 29 ----> 5
 [0]: 30 ----> 6
 [0]: 31 ----> 4
-[0]: 32 ----> 6
 [0]: 32 ----> 8
-[0]: 33 ----> 5
+[0]: 32 ----> 6
 [0]: 33 ----> 9
+[0]: 33 ----> 5
 [0]: 34 ----> 1
 [0]: 34 ----> 3
 [0]: 35 ----> 2
 coordinates with 1 fields
   field 0 with 2 components
 Process 0:
-  (  10) dim  2 offset   0 -0.5 0.5
-  (  11) dim  2 offset   2 -0.2 0
-  (  12) dim  2 offset   4 -0.2 1
-  (  13) dim  2 offset   6 0.5 0.5
-  (  14) dim  2 offset   8 0.2 0
-  (  15) dim  2 offset  10 0.2 1
-  (  16) dim  2 offset  12 -0.35 0.25
-  (  17) dim  2 offset  14 -0.2 0.5
-  (  18) dim  2 offset  16 -0.35 0.75
-  (  19) dim  2 offset  18 0.35 0.75
-  (  20) dim  2 offset  20 0.35 0.25
-  (  21) dim  2 offset  22 0.2 0.5
-Label 'marker':
-[0]: 16 (1)
-[0]: 18 (1)
-[0]: 19 (1)
-[0]: 20 (1)
-[0]: 22 (1)
-[0]: 23 (1)
-[0]: 26 (1)
-[0]: 27 (1)
-[0]: 28 (1)
-[0]: 29 (1)
-[0]: 30 (1)
-[0]: 31 (1)
+  (  10) dim  2 offset   0 -1 -0.5
+  (  11) dim  2 offset   2 0 -0.5
+  (  12) dim  2 offset   4 0 0.5
+  (  13) dim  2 offset   6 1 0.5
+  (  14) dim  2 offset   8 0 -0.5
+  (  15) dim  2 offset  10 0 0.5
+  (  16) dim  2 offset  12 -0.5 -0.5
+  (  17) dim  2 offset  14 0 0
+  (  18) dim  2 offset  16 -0.5 0
+  (  19) dim  2 offset  18 0.5 0.5
+  (  20) dim  2 offset  20 0.5 0
+  (  21) dim  2 offset  22 0 0

File src/dm/impls/plex/examples/tests/output/ex4_6.out

 [1]: 11 <---- 5 (0)
 [1]: 12 <---- 4 (0)
 [1]: 12 <---- 6 (0)
-Vec_0x84000004_0
+coordinates with 1 fields
+  field 0 with 2 components
 Process 0:
-  (   1) dim  2 offset   0 0.5 0.5
-  (   2) dim  2 offset   2 0.2 0
-  (   3) dim  2 offset   4 0.2 1
+  (   1) dim  2 offset   0 1 0.5
+  (   2) dim  2 offset   2 0 -0.5
+  (   3) dim  2 offset   4 0 0.5
 Process 1:
-  (   2) dim  2 offset   0 -0.5 0.5
-  (   3) dim  2 offset   2 -0.2 0
-  (   4) dim  2 offset   4 -0.2 1
-  (   5) dim  2 offset   6 0.2 0
-  (   6) dim  2 offset   8 0.2 1
-Label 'marker':
-[0]: 4 (1)
-[0]: 5 (1)
-[1]: 7 (1)
-[1]: 9 (1)
+  (   2) dim  2 offset   0 -1 -0.5
+  (   3) dim  2 offset   2 0 -0.5
+  (   4) dim  2 offset   4 0 0.5
+  (   5) dim  2 offset   6 0 -0.5
+  (   6) dim  2 offset   8 0 0.5
 PetscSF Object: 2 MPI processes
   type: basic
     sort=rank-order
 [1]: 11 <---- 5 (0)
 [1]: 12 <---- 4 (0)
 [1]: 12 <---- 6 (0)
-Vec_0x84000004_0
+coordinates with 1 fields
+  field 0 with 2 components
 Process 0:
-  (   1) dim  2 offset   0 0.5 0.5
-  (   2) dim  2 offset   2 0.2 0
-  (   3) dim  2 offset   4 0.2 1
+  (   1) dim  2 offset   0 1 0.5
+  (   2) dim  2 offset   2 0 -0.5
+  (   3) dim  2 offset   4 0 0.5
 Process 1:
-  (   2) dim  2 offset   0 -0.5 0.5
-  (   3) dim  2 offset   2 -0.2 0
-  (   4) dim  2 offset   4 -0.2 1
-  (   5) dim  2 offset   6 0.2 0
-  (   6) dim  2 offset   8 0.2 1
-Label 'marker':
-[0]: 4 (1)
-[0]: 5 (1)
-[1]: 7 (1)
-[1]: 9 (1)
+  (   2) dim  2 offset   0 -1 -0.5
+  (   3) dim  2 offset   2 0 -0.5
+  (   4) dim  2 offset   4 0 0.5
+  (   5) dim  2 offset   6 0 -0.5
+  (   6) dim  2 offset   8 0 0.5
 PetscSF Object: 2 MPI processes
   type: basic
     sort=rank-order
   [0]    2 <- 5
   [0]    3 <- 6
   [0]    6 <- 10
-  [1] Roots referenced by my leaves, by rank
+  [1] Roots referenced by my leaves, by rank

File src/dm/impls/plex/examples/tests/output/ex4_7.out

 [1]: 11 <---- 5 (0)
 [1]: 12 <---- 4 (0)
 [1]: 12 <---- 6 (0)
-Vec_0x84000004_0
+coordinates with 1 fields
+  field 0 with 2 components
 Process 0:
-  (   1) dim  2 offset   0 0.5 0.5
-  (   2) dim  2 offset   2 0.2 0
-  (   3) dim  2 offset   4 0.2 1
+  (   1) dim  2 offset   0 1 0.5
+  (   2) dim  2 offset   2 0 -0.5
+  (   3) dim  2 offset   4 0 0.5
 Process 1:
-  (   2) dim  2 offset   0 -0.5 0.5
-  (   3) dim  2 offset   2 -0.2 0
-  (   4) dim  2 offset   4 -0.2 1
-  (   5) dim  2 offset   6 0.2 0
-  (   6) dim  2 offset   8 0.2 1
-Label 'marker':
-[0]: 4 (1)
-[0]: 5 (1)
-[1]: 7 (1)
-[1]: 9 (1)
+  (   2) dim  2 offset   0 -1 -0.5
+  (   3) dim  2 offset   2 0 -0.5
+  (   4) dim  2 offset   4 0 0.5
+  (   5) dim  2 offset   6 0 -0.5
+  (   6) dim  2 offset   8 0 0.5
 PetscSF Object: 2 MPI processes
   type: basic
     sort=rank-order
 coordinates with 1 fields
   field 0 with 2 components
 Process 0:
-  (   4) dim  2 offset   0 0.5 0.5
-  (   5) dim  2 offset   2 0.2 0
-  (   6) dim  2 offset   4 0.2 1
-  (   7) dim  2 offset   6 0.35 0.75
-  (   8) dim  2 offset   8 0.35 0.25
-  (   9) dim  2 offset  10 0.2 0.5
+  (   4) dim  2 offset   0 1 0.5
+  (   5) dim  2 offset   2 0 -0.5
+  (   6) dim  2 offset   4 0 0.5
+  (   7) dim  2 offset   6 0.5 0.5
+  (   8) dim  2 offset   8 0.5 0
+  (   9) dim  2 offset  10 0 0
 Process 1:
-  (   6) dim  2 offset   0 -0.5 0.5
-  (   7) dim  2 offset   2 -0.2 0
-  (   8) dim  2 offset   4 -0.2 1
-  (   9) dim  2 offset   6 0.2 0
-  (  10) dim  2 offset   8 0.2 1
-  (  11) dim  2 offset  10 -0.35 0.25
-  (  12) dim  2 offset  12 -0.2 0.5
-  (  13) dim  2 offset  14 -0.35 0.75
-  (  14) dim  2 offset  16 0.2 0.5
-Label 'marker':
-[0]: 7 (1)
-[0]: 8 (1)
-[0]: 10 (1)
-[0]: 11 (1)
-[0]: 12 (1)
-[0]: 13 (1)
-[1]: 11 (1)
-[1]: 13 (1)
-[1]: 15 (1)
-[1]: 16 (1)
-[1]: 19 (1)
-[1]: 20 (1)
+  (   6) dim  2 offset   0 -1 -0.5
+  (   7) dim  2 offset   2 0 -0.5
+  (   8) dim  2 offset   4 0 0.5
+  (   9) dim  2 offset   6 0 -0.5
+  (  10) dim  2 offset   8 0 0.5
+  (  11) dim  2 offset  10 -0.5 -0.5
+  (  12) dim  2 offset  12 0 0
+  (  13) dim  2 offset  14 -0.5 0
+  (  14) dim  2 offset  16 0 0
 PetscSF Object: 2 MPI processes
   type not yet set
   [0] Number of roots=19, leaves=5, remote ranks=1