PETSc - MatLUFactor - Problem for `mpiaij` matrix and replace by SuperLU

115 Views Asked by At

I am a beginner in using PETSc and I am trying to develop a function to reverse a PETSc matrix. However, as I am using a mpiaij matrix, PETSc shows no support for this type.

[0]PETSC ERROR: No support for this operation for this object type
[0]PETSC ERROR: Mat type mpiaij

I've found a similar question in this answer but after downloading and configuring the SuperLU package, nothing works. I think we need to change the original MatLUFactor but no documentation in SuperLU is founded. I have tried by configuring PCFactorSetMatSolverType to SuperLU in PETSc but it doesn't work.

Thanks a lot for your help!

Here is my code:

void inv_PETSC_matrix(Mat& matrix,  Mat &inv_matrix)
{

  Mat             Ones;
  PetscInt        petsc_m=0, petsc_n=0,i,j;
  PetscErrorCode  ierr=0;
  PetscScalar     v = 1.0;
  ierr = MatGetSize(matrix, &petsc_m, &petsc_n);

    //Create a Ones matrix
  MatCreateSeqDense(PETSC_COMM_SELF,petsc_m,petsc_n,NULL,&Ones);
    //Create a Solution matrix
  MatCreateSeqDense(PETSC_COMM_SELF,petsc_m,petsc_n,NULL,&inv_matrix);

    //Factorisation LU
  MatLUFactor(matrix,NULL,NULL,NULL);

    //Affect value to the matrix Ones
  for(i = 0; i<petsc_m; i++)
    for(j=0; j<petsc_n; j++)
      MatSetValues(Ones,1,&i,1,&j,&v,INSERT_VALUES);

      //Inversion
  MatMatSolve(matrix, Ones, inv_matrix);
}
0

There are 0 best solutions below