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