int main(int argc,char *argv[]) { PetscErrorCode ierr; Mat A,S = NULL,Sexplicit = NULL; IS is0,is1; ierr = PetscInitialize(&argc,&argv,0,help);if (ierr) return ierr; /* Test the Schur complement one way */ ierr = Create(PETSC_COMM_WORLD,&A,&is0,&is1);CHKERRQ(ierr); ierr = MatView(A,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = ISView(is0,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = ISView(is1,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = MatGetSchurComplement(A,is0,is0,is1,is1,MAT_INITIAL_MATRIX,&S,MAT_SCHUR_COMPLEMENT_AINV_DIAG,MAT_IGNORE_MATRIX,NULL);CHKERRQ(ierr); ierr = MatComputeExplicitOperator(S,&Sexplicit);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"\nExplicit Schur complement of (0,0) in (1,1)\n");CHKERRQ(ierr); ierr = MatView(Sexplicit,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = Destroy(&A,&is0,&is1);CHKERRQ(ierr); ierr = MatDestroy(&S);CHKERRQ(ierr); ierr = MatDestroy(&Sexplicit);CHKERRQ(ierr); /* And the other */ ierr = Create(PETSC_COMM_WORLD,&A,&is0,&is1);CHKERRQ(ierr); ierr = MatGetSchurComplement(A,is1,is1,is0,is0,MAT_INITIAL_MATRIX,&S,MAT_SCHUR_COMPLEMENT_AINV_DIAG,MAT_IGNORE_MATRIX,NULL);CHKERRQ(ierr); ierr = MatComputeExplicitOperator(S,&Sexplicit);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"\nExplicit Schur complement of (1,1) in (0,0)\n");CHKERRQ(ierr); ierr = MatView(Sexplicit,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = Destroy(&A,&is0,&is1);CHKERRQ(ierr); ierr = MatDestroy(&S);CHKERRQ(ierr); ierr = MatDestroy(&Sexplicit);CHKERRQ(ierr); /* This time just the preconditioning matrix. */ ierr = Create(PETSC_COMM_WORLD,&A,&is0,&is1);CHKERRQ(ierr); ierr = MatGetSchurComplement(A,is0,is0,is1,is1,MAT_IGNORE_MATRIX,NULL,MAT_SCHUR_COMPLEMENT_AINV_DIAG,MAT_INITIAL_MATRIX,&S);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"\nPreconditioning Schur complement of (0,0) in (1,1)\n");CHKERRQ(ierr); ierr = MatView(S,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); /* Modify and refresh */ ierr = MatShift(A,1.);CHKERRQ(ierr); ierr = MatGetSchurComplement(A,is0,is0,is1,is1,MAT_IGNORE_MATRIX,NULL,MAT_SCHUR_COMPLEMENT_AINV_DIAG,MAT_REUSE_MATRIX,&S);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"\nAfter update\n");CHKERRQ(ierr); ierr = MatView(S,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = Destroy(&A,&is0,&is1);CHKERRQ(ierr); ierr = MatDestroy(&S);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; }
int main(int argc,char *argv[]) { PetscErrorCode ierr; Mat A,S,Sexplicit; IS is0,is1; ierr = PetscInitialize(&argc,&argv,0,help);CHKERRQ(ierr); /* Test the Schur complement one way */ ierr = Create(PETSC_COMM_WORLD,&A,&is0,&is1);CHKERRQ(ierr); ierr = MatView(A,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = ISView(is0,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = ISView(is1,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = MatGetSchurComplement(A,is0,is0,is1,is1,MAT_INITIAL_MATRIX,&S,MAT_IGNORE_MATRIX,PETSC_NULL);CHKERRQ(ierr); ierr = MatComputeExplicitOperator(S,&Sexplicit);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"\nExplicit Schur complement of (0,0) in (1,1)\n");CHKERRQ(ierr); ierr = MatView(Sexplicit,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = Destroy(A,is0,is1);CHKERRQ(ierr); ierr = MatDestroy(S);CHKERRQ(ierr); ierr = MatDestroy(Sexplicit);CHKERRQ(ierr); /* And the other */ ierr = Create(PETSC_COMM_WORLD,&A,&is0,&is1);CHKERRQ(ierr); ierr = MatGetSchurComplement(A,is1,is1,is0,is0,MAT_INITIAL_MATRIX,&S,MAT_IGNORE_MATRIX,PETSC_NULL);CHKERRQ(ierr); ierr = MatComputeExplicitOperator(S,&Sexplicit);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"\nExplicit Schur complement of (1,1) in (0,0)\n");CHKERRQ(ierr); ierr = MatView(Sexplicit,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = Destroy(A,is0,is1);CHKERRQ(ierr); ierr = MatDestroy(S);CHKERRQ(ierr); ierr = MatDestroy(Sexplicit);CHKERRQ(ierr); /* This time just the preconditioner */ ierr = Create(PETSC_COMM_WORLD,&A,&is0,&is1);CHKERRQ(ierr); ierr = MatGetSchurComplement(A,is0,is0,is1,is1,MAT_IGNORE_MATRIX,PETSC_NULL,MAT_INITIAL_MATRIX,&S);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"\nPreconditioning Schur complement of (0,0) in (1,1)\n");CHKERRQ(ierr); ierr = MatView(S,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = Destroy(A,is0,is1);CHKERRQ(ierr); ierr = MatDestroy(S);CHKERRQ(ierr); ierr = PetscFinalize();CHKERRQ(ierr); return 0; }