Commits

Matt Knepley committed 2704771

SNES ex52: Upgraded to new interface and fixed output of all 2D tests

Hg-commit: 786cb6ce21ece98509c94ee6d16eb27f6cf97e0f

Comments (0)

Files changed (19)

src/snes/examples/tutorials/ex52.c

       *dm  = refinedMesh;
     }
     /* Distribute mesh over processes */
-    ierr = DMPlexDistribute(*dm, partitioner, &distributedMesh);CHKERRQ(ierr);
+    ierr = DMPlexDistribute(*dm, partitioner, 0, &distributedMesh);CHKERRQ(ierr);
     if (distributedMesh) {
       ierr = DMDestroy(dm);CHKERRQ(ierr);
       *dm  = distributedMesh;
   PetscFunctionBeginUser;
   if (dim != SPATIAL_DIM_0) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_SIZ, "Spatial dimension %d should be %d", dim, SPATIAL_DIM_0);
   ierr = DMPlexCreateSection(dm, dim, 1, numComp, numDof_0, numBC, NULL, NULL, &section);CHKERRQ(ierr);
-  ierr = DMPlexSetDefaultSection(dm, section);CHKERRQ(ierr);
+  ierr = DMSetDefaultSection(dm, section);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 
   PetscFunctionBeginUser;
   ierr = DMGetLocalVector(user->dm, &localX);CHKERRQ(ierr);
   ierr = DMPlexGetDepthStratum(user->dm, 0, &vStart, &vEnd);CHKERRQ(ierr);
-  ierr = DMPlexGetDefaultSection(user->dm, &section);CHKERRQ(ierr);
+  ierr = DMGetDefaultSection(user->dm, &section);CHKERRQ(ierr);
   ierr = DMPlexGetCoordinateSection(user->dm, &cSection);CHKERRQ(ierr);
-  ierr = DMPlexGetCoordinateVec(user->dm, &coordinates);CHKERRQ(ierr);
+  ierr = DMGetCoordinatesLocal(user->dm, &coordinates);CHKERRQ(ierr);
   for (v = vStart; v < vEnd; ++v) {
     PetscScalar values[3];
     PetscScalar *coords;
         elemVec[f] -= basis[q*numBasisFuncs+f]*0.0*PetscExpScalar(fieldVal)*quadWeights[q]*detJ;
       }
     }
+    ierr = DMPlexVecRestoreClosure(dm, NULL, X, c, NULL, &x);CHKERRQ(ierr);
     if (debug) {ierr = DMPrintCellVector(c, "Residual", numBasisFuncs, elemVec);CHKERRQ(ierr);}
     ierr = DMPlexVecSetClosure(dm, NULL, F, c, elemVec, ADD_VALUES);CHKERRQ(ierr);
   }
         }
       }
     }
+    ierr = DMPlexVecRestoreClosure(dm, NULL, X, c, NULL, &x);CHKERRQ(ierr);
     if (debug) {ierr = DMPrintCellVector(c, "Residual", numBasisFuncs*numBasisComps, elemVec);CHKERRQ(ierr);}
     ierr = DMPlexVecSetClosure(dm, NULL, F, c, elemVec, ADD_VALUES);CHKERRQ(ierr);
   }
     for (f = 0; f < numBasisFuncs*numBasisComps; ++f) {
       u[c*numBasisFuncs*numBasisComps+f] = x[f];
     }
+    ierr = DMPlexVecRestoreClosure(dm, NULL, X, c, NULL, &x);CHKERRQ(ierr);
   }
   /* Conforming batches */
   PetscInt blockSize  = numBasisFuncs*numQuadPoints;
   X   - The local input vector
   Jac - The output matrix
 */
-PetscErrorCode FormJacobianLocalLaplacian(DM dm, Vec X, Mat Jac, Mat JacPre, AppCtx *user)
+PetscErrorCode FormJacobianLocalLaplacian(DM dm, Vec X, Mat Jac, Mat JacPre, MatStructure *flag, AppCtx *user)
 {
   const PetscInt  debug         = user->debug;
   const PetscInt  dim           = user->dim;
         }
       }
     }
+    ierr = DMPlexVecRestoreClosure(dm, NULL, X, c, NULL, &x);CHKERRQ(ierr);
     if (debug) {ierr = DMPrintCellMatrix(c, "Jacobian", numBasisFuncs, numBasisFuncs, elemMat);CHKERRQ(ierr);}
     ierr = DMPlexMatSetClosure(dm, NULL, NULL, Jac, c, elemMat, ADD_VALUES);CHKERRQ(ierr);
   }
   X   - The local input vector
   Jac - The output matrix
 */
-PetscErrorCode FormJacobianLocalElasticity(DM dm, Vec X, Mat Jac, Mat JacPre, AppCtx *user)
+PetscErrorCode FormJacobianLocalElasticity(DM dm, Vec X, Mat Jac, Mat JacPre, MatStructure *flag, AppCtx *user)
 {
   const PetscInt  debug         = user->debug;
   const PetscInt  dim           = user->dim;
         }
       }
     }
+    ierr = DMPlexVecRestoreClosure(dm, NULL, X, c, NULL, &x);CHKERRQ(ierr);
     if (debug) {ierr = DMPrintCellMatrix(c, "Jacobian", numBasisFuncs, numBasisFuncs, elemMat);CHKERRQ(ierr);}
     ierr = DMPlexMatSetClosure(dm, NULL, NULL, Jac, c, elemMat, ADD_VALUES);CHKERRQ(ierr);
   }
   X   - The local input vector
   Jac - The output matrix
 */
-PetscErrorCode FormJacobianLocalBatch(DM dm, Vec X, Mat Jac, Mat JacPre, AppCtx *user)
+PetscErrorCode FormJacobianLocalBatch(DM dm, Vec X, Mat Jac, Mat JacPre, MatStructure *flag, AppCtx *user)
 {
   const PetscInt  debug         = user->debug;
   const PetscInt  dim           = user->dim;
         }
       }
     }
+    ierr = DMPlexVecRestoreClosure(dm, NULL, X, c, NULL, &x);CHKERRQ(ierr);
     if (debug) {ierr = DMPrintCellMatrix(c, "Jacobian", numBasisFuncs, numBasisFuncs, elemMat);CHKERRQ(ierr);}
     ierr = DMPlexMatSetClosure(dm, NULL, NULL, Jac, c, elemMat, ADD_VALUES);CHKERRQ(ierr);
   }
   ierr = SetupSection(dm, &user);CHKERRQ(ierr);
 
   ierr = SNESCreate(PETSC_COMM_WORLD, &snes);CHKERRQ(ierr);
+  ierr = SNESSetDM(snes, dm);CHKERRQ(ierr);
   if (user.computeFunction) {
     Vec X, F;
 
       default:
         SETERRQ1(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Invalid PDE operator %d", user.op);
       }
-      ierr = DMPlexSetLocalFunction(dm, (PetscErrorCode (*)(DM, Vec, Vec, void*))FormFunctionLocalBatch);CHKERRQ(ierr);
+      ierr = DMSNESSetFunctionLocal(dm, (PetscErrorCode (*)(DM, Vec, Vec, void*))FormFunctionLocalBatch, &user);CHKERRQ(ierr);
     } else {
       switch (user.op) {
       case LAPLACIAN:
         ierr = FormInitialGuess(X, quadratic_2d, INSERT_VALUES, &user);CHKERRQ(ierr);
-        ierr = DMPlexSetLocalFunction(dm, (PetscErrorCode (*)(DM, Vec, Vec, void*))FormFunctionLocalLaplacian);CHKERRQ(ierr);break;
+        ierr = DMSNESSetFunctionLocal(dm, (PetscErrorCode (*)(DM, Vec, Vec, void*))FormFunctionLocalLaplacian, &user);CHKERRQ(ierr);break;
       case ELASTICITY:
         ierr = FormInitialGuess(X, quadratic_2d_elas, INSERT_VALUES, &user);CHKERRQ(ierr);
-        ierr = DMPlexSetLocalFunction(dm, (PetscErrorCode (*)(DM, Vec, Vec, void*))FormFunctionLocalElasticity);CHKERRQ(ierr);break;
+        ierr = DMSNESSetFunctionLocal(dm, (PetscErrorCode (*)(DM, Vec, Vec, void*))FormFunctionLocalElasticity, &user);CHKERRQ(ierr);break;
       default:
         SETERRQ1(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Invalid PDE operator %d", user.op);
       }
     }
-    ierr = SNESDMPlexComputeFunction(snes, X, F, &user);CHKERRQ(ierr);
+    ierr = SNESComputeFunction(snes, X, F);CHKERRQ(ierr);
     ierr = DMRestoreGlobalVector(dm, &X);CHKERRQ(ierr);
     ierr = DMRestoreGlobalVector(dm, &F);CHKERRQ(ierr);
   }
     ierr = DMGetGlobalVector(dm, &X);CHKERRQ(ierr);
     ierr = DMCreateMatrix(dm, MATAIJ, &J);CHKERRQ(ierr);
     if (user.batch) {
-      ierr = DMPlexSetLocalJacobian(dm, (PetscErrorCode (*)(DM, Vec, Mat, Mat, void*))FormJacobianLocalBatch);CHKERRQ(ierr);
+      ierr = DMSNESSetJacobianLocal(dm, (PetscErrorCode (*)(DM, Vec, Mat, Mat, MatStructure*, void*))FormJacobianLocalBatch, &user);CHKERRQ(ierr);
     } else {
       switch (user.op) {
       case LAPLACIAN:
-        ierr = DMPlexSetLocalJacobian(dm, (PetscErrorCode (*)(DM, Vec, Mat, Mat, void*))FormJacobianLocalLaplacian);CHKERRQ(ierr);break;
+        ierr = DMSNESSetJacobianLocal(dm, (PetscErrorCode (*)(DM, Vec, Mat, Mat, MatStructure*, void*))FormJacobianLocalLaplacian, &user);CHKERRQ(ierr);break;
       case ELASTICITY:
-        ierr = DMPlexSetLocalJacobian(dm, (PetscErrorCode (*)(DM, Vec, Mat, Mat, void*))FormJacobianLocalElasticity);CHKERRQ(ierr);break;
+        ierr = DMSNESSetJacobianLocal(dm, (PetscErrorCode (*)(DM, Vec, Mat, Mat, MatStructure*, void*))FormJacobianLocalElasticity, &user);CHKERRQ(ierr);break;
       default:
         SETERRQ1(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Invalid PDE operator %d", user.op);
       }
     }
-    ierr = SNESDMPlexComputeJacobian(snes, X, &J, &J, &flag, &user);CHKERRQ(ierr);
+    ierr = SNESComputeJacobian(snes, X, &J, &J, &flag);CHKERRQ(ierr);
     ierr = MatDestroy(&J);CHKERRQ(ierr);
     ierr = DMRestoreGlobalVector(dm, &X);CHKERRQ(ierr);
   }

src/snes/examples/tutorials/output/ex52_0.out

 Mesh in 2 dimensions:
   0-cells: 9
   2-cells: 8
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (9, 8)
 Residual:
 Vector Object: 1 MPI processes
   type: seq

src/snes/examples/tutorials/output/ex52_1.out

 Mesh in 2 dimensions:
   0-cells: 9
   2-cells: 8
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (9, 8)
 Residual:
 Vector Object: 1 MPI processes
   type: seq

src/snes/examples/tutorials/output/ex52_10.out

 Mesh in 2 dimensions:
   0-cells: 9
   2-cells: 8
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (9, 8)
 Residual:
 Vector Object: 1 MPI processes
   type: seq

src/snes/examples/tutorials/output/ex52_11.out

 Mesh in 2 dimensions:
   0-cells: 9
   2-cells: 8
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (9, 8)
 GPU layout grid(1,2,1) block(6,1,1) with 1 batches
  N_t: 6, N_cb: 1
 Residual:

src/snes/examples/tutorials/output/ex52_12.out

 Mesh in 2 dimensions:
   0-cells: 9
   2-cells: 8
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (9, 8)
 GPU layout grid(1,1,1) block(6,1,1) with 2 batches
  N_t: 6, N_cb: 2
 Residual:

src/snes/examples/tutorials/output/ex52_13.out

 Mesh in 2 dimensions:
   0-cells: 13
   2-cells: 16
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (13, 16)
 Residual:
 Vector Object: 1 MPI processes
   type: seq

src/snes/examples/tutorials/output/ex52_14.out

 Mesh in 2 dimensions:
   0-cells: 13
   2-cells: 16
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (13, 16)
 Residual:
 Vector Object: 1 MPI processes
   type: seq

src/snes/examples/tutorials/output/ex52_15.out

 Mesh in 2 dimensions:
   0-cells: 13
   2-cells: 16
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (13, 16)
 GPU layout grid(1,5,1) block(6,1,1) with 1 batches
  N_t: 6, N_cb: 1
 Residual:

src/snes/examples/tutorials/output/ex52_16.out

 Mesh in 2 dimensions:
   0-cells: 13
   2-cells: 16
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (13, 16)
 GPU layout grid(1,2,1) block(6,1,1) with 2 batches
  N_t: 6, N_cb: 2
 Residual:

src/snes/examples/tutorials/output/ex52_17.out

 Mesh in 2 dimensions:
   0-cells: 13
   2-cells: 16
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (13, 16)
 GPU layout grid(1,1,1) block(6,1,1) with 4 batches
  N_t: 6, N_cb: 4
 Residual:

src/snes/examples/tutorials/output/ex52_2.out

 Mesh in 2 dimensions:
   0-cells: 9
   2-cells: 8
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (9, 8)
 GPU layout grid(1,2,1) block(3,1,1) with 1 batches
  N_t: 3, N_cb: 1
 Residual:

src/snes/examples/tutorials/output/ex52_3.out

 Mesh in 2 dimensions:
   0-cells: 9
   2-cells: 8
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (9, 8)
 GPU layout grid(1,1,1) block(3,1,1) with 2 batches
  N_t: 3, N_cb: 2
 Residual:

src/snes/examples/tutorials/output/ex52_4.out

 Mesh in 2 dimensions:
   0-cells: 13
   2-cells: 16
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (13, 16)
 Residual:
 Vector Object: 1 MPI processes
   type: seq

src/snes/examples/tutorials/output/ex52_5.out

 Mesh in 2 dimensions:
   0-cells: 13
   2-cells: 16
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (13, 16)
 Residual:
 Vector Object: 1 MPI processes
   type: seq

src/snes/examples/tutorials/output/ex52_6.out

 Mesh in 2 dimensions:
   0-cells: 13
   2-cells: 16
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (13, 16)
 GPU layout grid(1,5,1) block(3,1,1) with 1 batches
  N_t: 3, N_cb: 1
 Residual:

src/snes/examples/tutorials/output/ex52_7.out

 Mesh in 2 dimensions:
   0-cells: 13
   2-cells: 16
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (13, 16)
 GPU layout grid(1,2,1) block(3,1,1) with 2 batches
  N_t: 3, N_cb: 2
 Residual:

src/snes/examples/tutorials/output/ex52_8.out

 Mesh in 2 dimensions:
   0-cells: 13
   2-cells: 16
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (13, 16)
 GPU layout grid(1,1,1) block(3,1,1) with 4 batches
  N_t: 3, N_cb: 4
 Residual:

src/snes/examples/tutorials/output/ex52_9.out

 Mesh in 2 dimensions:
   0-cells: 9
   2-cells: 8
+Labels:
+  marker: 2 strata of sizes (8, 1)
+  depth: 2 strata of sizes (9, 8)
 Residual:
 Vector Object: 1 MPI processes
   type: seq