Set tolerance in Krylov solver

Very basic question here: I would like to set the tolerance on a KrylovSolver solve. Neither the object itself nor the solve() method accept a tol argument. I need to use KrylovSolver to get the number of performed steps.

solver = KrylovSolver("cg", "none")

x = Function(V)
x_vec = x.vector()
num_steps = solver.solve(A, x_vec, b)

Any hints?

Considering the output of

from dolfin import *

solver = KrylovSolver('cg', 'none')

print(solver.parameters.keys())

I think you may want to try something like

solver.parameters['absolute_tolerance'] = 1e-5
solver.parameters['relative_tolerance'] = 1e-5

and see if it works.

1 Like