Actual source code: ex5.c

  1: /*
  2:   Test DMCreateMatrix() for structure_only
  3: */

  5: #include <petscdmda.h>

  7: int main(int argc, char *argv[])
  8: {
  9:   PetscInt  nx = 6, ny = 6, nz = 6, dim = 1, dof = 2;
 10:   DM        da;
 11:   Mat       A;
 12:   PetscBool struct_only = PETSC_TRUE;

 15:   PetscInitialize(&argc, &argv, NULL, NULL);
 16:   PetscOptionsGetInt(NULL, NULL, "-dim", &dim, NULL);
 17:   PetscOptionsGetInt(NULL, NULL, "-dof", &dof, NULL);
 18:   switch (dim) {
 19:   case 1:
 20:     DMDACreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, nx, dof, 1, NULL, &da);
 21:     break;
 22:   case 2:
 23:     DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DMDA_STENCIL_STAR, nx, ny, PETSC_DECIDE, PETSC_DECIDE, dof, 1, NULL, NULL, &da);
 24:     break;
 25:   default:
 26:     DMDACreate3d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DMDA_STENCIL_BOX, nx, ny, nz, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, dof, 2, NULL, NULL, NULL, &da);
 27:   }

 29:   DMSetFromOptions(da);
 30:   DMSetUp(da);
 31:   DMView(da, PETSC_VIEWER_STDOUT_WORLD);

 33:   PetscOptionsGetBool(NULL, NULL, "-struct_only", &struct_only, NULL);
 34:   DMSetMatrixStructureOnly(da, struct_only);
 35:   DMCreateMatrix(da, &A);
 36:   /* Set da->structure_only to default PETSC_FALSE in case da is being used to create new matrices */
 37:   DMSetMatrixStructureOnly(da, PETSC_FALSE);

 39:   MatView(A, PETSC_VIEWER_STDOUT_WORLD);
 40:   MatDestroy(&A);
 41:   DMDestroy(&da);
 42:   PetscFinalize();
 43:   return 0;
 44: }

 46: /*TEST

 48:    test:

 50:    test:
 51:       suffix: 2
 52:       args: -dm_mat_type baij -dim 2

 54: TEST*/