Actual source code: ex6.c

petsc-3.10.5 2019-03-28
Report Typos and Errors

  2: static char help[] = "Tests reordering a matrix.\n\n";

  4:  #include <petscmat.h>

  6: int main(int argc,char **args)
  7: {
  8:   Mat            C;
  9:   PetscInt       i,j,m = 5,n = 5,Ii,J;
 11:   PetscScalar    v;
 12:   IS             perm,iperm;

 14:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 15:   MatCreate(PETSC_COMM_SELF,&C);
 16:   MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,m*n,m*n);
 17:   MatSetFromOptions(C);
 18:   MatSetUp(C);

 20:   /* create the matrix for the five point stencil, YET AGAIN*/
 21:   for (i=0; i<m; i++) {
 22:     for (j=0; j<n; j++) {
 23:       v = -1.0;  Ii = j + n*i;
 24:       if (i>0)   {J = Ii - n; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 25:       if (i<m-1) {J = Ii + n; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 26:       if (j>0)   {J = Ii - 1; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 27:       if (j<n-1) {J = Ii + 1; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 28:       v = 4.0; MatSetValues(C,1,&Ii,1,&Ii,&v,INSERT_VALUES);
 29:     }
 30:   }
 31:   MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
 32:   MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);

 34:   MatGetOrdering(C,MATORDERINGND,&perm,&iperm);
 35:   ISView(perm,PETSC_VIEWER_STDOUT_SELF);
 36:   ISView(iperm,PETSC_VIEWER_STDOUT_SELF);
 37:   MatView(C,PETSC_VIEWER_STDOUT_SELF);

 39:   ISDestroy(&perm);
 40:   ISDestroy(&iperm);
 41:   MatDestroy(&C);
 42:   PetscFinalize();
 43:   return ierr;
 44: }


 47: /*TEST

 49:    test:

 51: TEST*/