Unable to solve linear system using PETSc Krylov solver

Hello, everyone!
I’m trying to solve the equation in the from of “(B-rC)w=Bv” based on the ‘cg’ iteration method with the preconditioner ‘ilu’ or ‘Jacobi’. In the equation, B is a 307724 * 307724 PETScMatrix, and the corresponding code is:

``````import dolfin as df

D = df.PETScMatrix(B.mat() - C.mat() * r[j])
solver = df.PETScKrylovSolver("cg", "ilu")
solver.parameters["absolute_tolerance"] = 1e-17
solver.parameters["maximum_iterations"] = 10000
solver.solve(D, w[ti], B * v[j])
``````

After running the code, it reminded me an error shown in the below figure (the error is the same when the preconditioner is ‘ilu’ or ‘Jacobi’). What is the problem and how could I solve it?

Please provide a minimal working example reproducing the error. (I also note that you have posted about this in multiple threads: How to solve variational problem by iteration methods - #7 by adamson-lkx
Please avoid duplicate posts.

``````RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to solve linear system using PETSc Krylov solver.
*** Reason:  Solution failed to converge in 10000 iterations (PETSc reason DIVERGED_ITS, residual norm ||r|| = 1.365103e-11).
*** Where:   This error was encountered inside PETScKrylovSolver.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.1.0
*** Git changeset:  d0e78c11e813d2decc337bbee614a33128aa539f
``````

Sorry, I forgot to provide the error information. By the way, my example producing the error is too large to show here, and this error occurs when I use the iteration solver to solve the above equation for building the Krylov subspace basis to solve the electric diffusion equation.
Actually, I also tried to use the same way to solve 2D Possion equation, and no errors occur, but when I introduce the process to the above problem, the error suddenly occurs.

As you can see in your error

you are not able to achieve 10^{-17} in residual.
This tolerance is way too small. I would suggest trying something like 1e-9.

1 Like

Actually, I’ve tried to decrease the the value of the parameter “absolute_tolerance” to be 1e-10 for the preconditioner "jacobi’, it doesn’t return any error, but the calculation results are totally incorrect. While for the preconditioner ‘ilu’, it still returns error even without limiting the parameter “absolute_tolerance”, and the error is as follows:

``````RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to solve linear system using PETSc Krylov solver.
*** Reason:  Solution failed to converge in 3 iterations (PETSc reason DIVERGED_INDEFINITE_PC, residual norm ||r|| = 1.424454e-03).
*** Where:   This error was encountered inside PETScKrylovSolver.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.1.0
*** Git changeset:  d0e78c11e813d2decc337bbee614a33128aa539f
*** -------------------------------------------------------------------------
``````

I would suggest you have a look at: Default absolute tolerance and relative tolerance - #4 by nate
and also
PCILU — PETSc 3.18.2 documentation