This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

make KrylovSolver fail on nonconvergence

+1 vote

When using the Krylov solver

solver = KrylovSolver('gmres', 'ilu')
solver.parameters['relative_tolerance'] = 1.0e-13
solver.parameters['absolute_tolerance'] = 0.0
solver.parameters['maximum_iterations'] = 100
solver.set_operator(A)

u = Function(self.V)
solver.solve(u.vector(), b)

it doesn't fail on nonconvergence; it rather prints a warning on screen

*** Warning: Krylov solver did not converge in 100 iterations (PETSc reason DIVERGED_ITS, residual norm ||r|| = 4.626070e+04).

that is easy to miss if there a lot of output.

How can I make this an error/exception?

asked Apr 3, 2017 by nschloe FEniCS User (7,120 points)

1 Answer

+4 votes
 
Best answer

Try the error_on_nonconvergence parameter:

solver.parameters['error_on_nonconvergence'] = True
answered Apr 3, 2017 by johannr FEniCS Expert (17,350 points)
selected Apr 4, 2017 by nschloe
...