1 2 static char help[] = "Tests the use of MatZeroRows() for uniprocessor matrices.\n\n"; 3 4 #include <petscmat.h> 5 6 int main(int argc,char **args) 7 { 8 Mat C; 9 PetscInt i,j,m = 5,n = 5,Ii,J; 10 PetscScalar v,five = 5.0; 11 IS isrow; 12 PetscBool keepnonzeropattern; 13 14 PetscFunctionBeginUser; 15 PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); 16 /* create the matrix for the five point stencil, YET AGAIN*/ 17 PetscCall(MatCreate(PETSC_COMM_SELF,&C)); 18 PetscCall(MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,m*n,m*n)); 19 PetscCall(MatSetFromOptions(C)); 20 PetscCall(MatSetUp(C)); 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; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} 25 if (i<m-1) {J = Ii + n; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} 26 if (j>0) {J = Ii - 1; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} 27 if (j<n-1) {J = Ii + 1; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} 28 v = 4.0; PetscCall(MatSetValues(C,1,&Ii,1,&Ii,&v,INSERT_VALUES)); 29 } 30 } 31 PetscCall(MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY)); 32 PetscCall(MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY)); 33 34 PetscCall(ISCreateStride(PETSC_COMM_SELF,(m*n)/2,0,2,&isrow)); 35 36 PetscCall(PetscOptionsHasName(NULL,NULL,"-keep_nonzero_pattern",&keepnonzeropattern)); 37 if (keepnonzeropattern) PetscCall(MatSetOption(C,MAT_KEEP_NONZERO_PATTERN,PETSC_TRUE)); 38 39 PetscCall(MatZeroRowsIS(C,isrow,five,0,0)); 40 41 PetscCall(MatView(C,PETSC_VIEWER_STDOUT_SELF)); 42 43 PetscCall(ISDestroy(&isrow)); 44 PetscCall(MatDestroy(&C)); 45 PetscCall(PetscFinalize()); 46 return 0; 47 } 48 49 /*TEST 50 51 test: 52 53 test: 54 suffix: 2 55 args: -mat_type seqbaij -mat_block_size 5 56 57 test: 58 suffix: 3 59 args: -keep_nonzero_pattern 60 61 test: 62 suffix: 4 63 args: -keep_nonzero_pattern -mat_type seqbaij -mat_block_size 5 64 65 TEST*/ 66