Store error of iterations of solvers.CG


is there any possibility to store the printed error of the iterations of the solvers.CG solver? I want to make a plot of the error to show different convergence behavior in relation.

Thanks in advance!

It is quite an old thread but there are updates on this front, sorry for not answering earlier.
In the current nightly version there is a little rework of the cg solver, you can get it as a basematrix object now and use either its Solve method or do a matrix vector product. You can afterwards get the iteration count and the convergence history:

from ngsolve.krylovspace import CGSolver
solver = CGSolver(a.mat, pre.mat) = solver * f.vec
print("iteration count =", solver.iterations)
print("convergence history = ", solver.errors)

The design and names might still change, thats why it is not yet exposed to the solvers, but if you want to get anything else let us know.

Thank you, that is great news! For my application this fits perfectly.


sorry to dig out this old thread but I think it fits here: Is there any way to get the iterations and errors for the GMRes solver?

Thanks for your support!

With the current implementation not really, but you could just copy paste the GMRes solver from the file to your file and add that functionality.

Best Christopher