Monitor the convergence process of linear solvers in Netwon iteration

I am now using Netwon to solve a nonlinear equation and I would like to try different solvers

Jac = derivative(F, U, dU)
problem = NonlinearVariationalProblem(F, U, bcs, Jac)
solver = NonlinearVariationalSolver(problem)
prm = solver.parameters

prm['newton_solver']['linear_solver'] = 'cg' #'gmres'  'mumps', 'gmres', 'bicgstab'
prm['newton_solver']['preconditioner'] = 'amg'   # 'hypre_euclid'


prm['newton_solver']['maximum_iterations'] = 50 #50
prm['newton_solver']['krylov_solver']['maximum_iterations'] = 100
prm['newton_solver']['relaxation_parameter'] = 0.9 #0.9
prm['newton_solver']['absolute_tolerance'] = 1E-6
prm['newton_solver']['relative_tolerance'] = 1E-8 #tol_tstep * tol_fac #0.01

prm['newton_solver']['report'] = True
prm['newton_solver']['error_on_nonconvergence'] = True

prm['newton_solver']['krylov_solver']['report'] = True
prm['newton_solver']['krylov_solver']['monitor_convergence'] = True
prm['newton_solver']['krylov_solver']['nonzero_initial_guess'] = True
prm['newton_solver']['krylov_solver']['error_on_nonconvergence'] = True

However, the linear solver does not converge, which shows:

Newton iteration 0: r (abs) = 5.819e+02 (tol = 1.000e-06) r (rel) = 1.000e+00 (tol = 1.000e-08)
Solving linear system of size 781072 x 781072 (PETSc Krylov solver).
PETSc Krylov solver starting to solve 781072 x 781072 system.

RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***     fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to solve linear system using PETSc Krylov solver.
*** Reason:  Solution failed to converge in 0 iterations (PETSc reason DIVERGED_NANORINF, residual norm ||r|| = 0.000000e+00).
*** Where:   This error was encountered inside PETScKrylovSolver.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.1.0
*** Git changeset:
*** ------------------------------------------------------------------------

My question is: why the output does not include the convergence process of linear solvers? I would like to see the error of every linear iteration and the number of iterations, etc… I have thought that prm['newton_solver']['krylov_solver']['monitor_convergence'] = True should do this job, but it seems not.

Thanks,
Leon

1 Like