How to monitor convergence?

Hi. Thanks for the wonderful software. I am wondering if there is a way to monitor the convergence of the solver. I am solving a quite large problem (just a plane wave scattering problem on an object at 8kHz - it takes about two days to finish running) and wondering if there is a way to monitor the progress. Like a residual vs iter_count. I am using gmres solver.
Thanks.

You can use the built-in logger of bempp to monitor the convergence of GMRES.
Instead of

from bempp.api.linalg import gmres
sol, info = gmres(lhs, rhs)

you can use

from bempp.api.linalg import gmres
bempp.api.enable_console_logging()
sol, info = gmres(lhs, rhs)

to monitor the iteration count. If you want to monitor the residual norm as well, use

from bempp.api.linalg import gmres
bempp.api.enable_console_logging()
sol, info, res = gmres(lhs, rhs, return_residuals=True)

Alternatively, you can use the Scipy implementation of Gmres and make a custom callback function:

from scipy.sparse.linalg import gmres
def my_callback(args):
    ...
    return
sol, info = gmres(lhs.strong_form(), rhs.coefficients, callback=my_callback)

This functionality also works with other iterative solvers like CG.

1 Like

Thank you so much @Elwin . That’s very helpful! I’ll enable the built-in logger with return_residuals=True and try it. Thank you!