Actual source code: ex5.c

petsc-3.9.4 2018-09-11
Report Typos and Errors
  1: /* 
  2:   Test DMCreateMatrix() for structure_only
  3: */

  5:  #include <petscdmda.h>

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

 15:   PetscInitialize(&argc,&argv,NULL,NULL);if (ierr) return ierr;
 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,
 27:                       PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,dof,2,NULL,NULL,NULL,&da);
 28:   }

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

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

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


 48: /*TEST

 50:    test:

 52:    test:
 53:       suffix: 2
 54:       args: -dm_mat_type baij -dim 2

 56: TEST*/