1 /* 2 Test DMCreateMatrix() for structure_only 3 */ 4 5 #include <petscdmda.h> 6 7 int main(int argc, char *argv[]) { 8 PetscInt nx = 6, ny = 6, nz = 6, dim = 1, dof = 2; 9 DM da; 10 Mat A; 11 PetscBool struct_only = PETSC_TRUE; 12 13 PetscFunctionBeginUser; 14 PetscCall(PetscInitialize(&argc, &argv, NULL, NULL)); 15 PetscCall(PetscOptionsGetInt(NULL, NULL, "-dim", &dim, NULL)); 16 PetscCall(PetscOptionsGetInt(NULL, NULL, "-dof", &dof, NULL)); 17 switch (dim) { 18 case 1: PetscCall(DMDACreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, nx, dof, 1, NULL, &da)); break; 19 case 2: PetscCall(DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DMDA_STENCIL_STAR, nx, ny, PETSC_DECIDE, PETSC_DECIDE, dof, 1, NULL, NULL, &da)); break; 20 default: PetscCall(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)); 21 } 22 23 PetscCall(DMSetFromOptions(da)); 24 PetscCall(DMSetUp(da)); 25 PetscCall(DMView(da, PETSC_VIEWER_STDOUT_WORLD)); 26 27 PetscCall(PetscOptionsGetBool(NULL, NULL, "-struct_only", &struct_only, NULL)); 28 PetscCall(DMSetMatrixStructureOnly(da, struct_only)); 29 PetscCall(DMCreateMatrix(da, &A)); 30 /* Set da->structure_only to default PETSC_FALSE in case da is being used to create new matrices */ 31 PetscCall(DMSetMatrixStructureOnly(da, PETSC_FALSE)); 32 33 PetscCall(MatView(A, PETSC_VIEWER_STDOUT_WORLD)); 34 PetscCall(MatDestroy(&A)); 35 PetscCall(DMDestroy(&da)); 36 PetscCall(PetscFinalize()); 37 return 0; 38 } 39 40 /*TEST 41 42 test: 43 44 test: 45 suffix: 2 46 args: -dm_mat_type baij -dim 2 47 48 TEST*/ 49