Access NewtonSolver residual in dolfinx 0.8.0

Hi,
How can I track the residuals of the cpp NewtonSolver in dolfinx 0.8.0?
Using log.set_log_level(log.LogLevel.INFO) I can obtain the values in the log, e.g.: NewtonSolver.cpp:38 INFO| Newton iteration 2: r (abs) = 0.0103137 (tol = 1e-07) r (rel) = 0.0187614(tol = 1e-06), but I would like to access them in Python directly if possible.

In this post @nate explains we can overwrite the converged function of the NewtonSolver, but this not possible here. Can we do a similar thing for the solve function?

One would have to expose set_convergence_check to Python: Code search results · GitHub
Feel free to add a Pull request to dolfinx doing this around: dolfinx/python/dolfinx/wrappers/petsc.cpp at main · FEniCS/dolfinx · GitHub
similar to the other functions above.
If you dont want to make a pull request, you can file an issue at:
Issues · FEniCS/dolfinx · GitHub
or use a custom newton solver:
Custom Newton solvers — FEniCSx tutorial

1 Like