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