I meet a problem that fenics show ‘Newton solver did not converge because maximum number of iterations reached.’ Can I increase this iteration number?
Traceback (most recent call last):
File "/mnt/c/Users/Danie/OneDrive/桌面/ID1/PhaseFieldFracture.py", line 244, in <module>
problem_u.solve(u.vector())
File "/usr/local/lib/python3.6/site-packages/mgis/fenics/nonlinear_problem.py", line 486, in solve
solv_out = self.solver.solve(self, x)
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 nonlinear system with NewtonSolver.
*** Reason: Newton solver did not converge because maximum number of iterations reached.
*** Where: This error was encountered inside NewtonSolver.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.1.0
*** Git changeset: unknown
*** -------------------------------------------------------------------------
from dolfin import *
# Set up some simple demonstration nonlinear problem:
mesh = UnitIntervalMesh(10)
V = FunctionSpace(mesh,"CG",1)
u = Function(V)
v = TestFunction(V)
x = SpatialCoordinate(mesh)
F = (u+1)**2*dot(grad(u),grad(v))*dx + u*v*dx - sin(x[0])*v*dx
problem = NonlinearVariationalProblem(F,u,J=derivative(F,u),bcs=[])
# Create solver:
solver = NonlinearVariationalSolver(problem)
stype = 'newton'
solver.parameters['nonlinear_solver']=stype
sprms = solver.parameters[stype+'_solver']
# Set maximum iterations:
sprms['maximum_iterations'] = 100
# Force solver to reach maximum iterations for demonstration:
sprms['relative_tolerance'] = 0.0
sprms['absolute_tolerance'] = 0.0
# Print out other available options:
info(solver.parameters,True)
# Run solver:
solver.solve()
Thanks kamensky. After increasing the maximum number of iterations, error is eliminated.
Additionally, besides increasing the number of elements, which else ways can reduce newton iterations?
Other than the linear setting where you will converge in one iteration, Newton’s method converges optimally at least at a quadratic rate. If you aren’t achieving a quadratic convergence rate you likely have a malformed Jacobian, the update of the solution vector is not exact or your solution iterate is stuck in a saddle point and not an attractor region. Basic info available here.
Hi, as @kamensky states in the example, tolerances are set to 0.0 to reach maximum number of iterations for demonstration. However the solver converges if you relax the tolerance requirements:
from dolfin import *
# Set up some simple demonstration nonlinear problem:
mesh = UnitIntervalMesh(10)
V = FunctionSpace(mesh,"CG",1)
u = Function(V)
v = TestFunction(V)
x = SpatialCoordinate(mesh)
F = (u+1)**2*dot(grad(u),grad(v))*dx + u*v*dx - sin(x[0])*v*dx
problem = NonlinearVariationalProblem(F,u,J=derivative(F,u),bcs=[])
# Create solver:
solver = NonlinearVariationalSolver(problem)
stype = 'newton'
solver.parameters['nonlinear_solver']=stype
sprms = solver.parameters[stype+'_solver']
# Set maximum iterations:
sprms['maximum_iterations'] = 100
# Force solver to reach maximum iterations for demonstration:
sprms['relative_tolerance'] = 1e-14
sprms['absolute_tolerance'] = 0.0
# Print out other available options:
info(solver.parameters,True)
# Run solver:
solver.solve()
Result:
Solving nonlinear variational problem.
Newton iteration 0: r (abs) = 1.596e-01 (tol = 0.000e+00) r (rel) = 1.000e+00 (tol = 1.000e-14)
Newton iteration 1: r (abs) = 7.413e-02 (tol = 0.000e+00) r (rel) = 4.646e-01 (tol = 1.000e-14)
Newton iteration 2: r (abs) = 1.576e-03 (tol = 0.000e+00) r (rel) = 9.876e-03 (tol = 1.000e-14)
Newton iteration 3: r (abs) = 1.785e-07 (tol = 0.000e+00) r (rel) = 1.119e-06 (tol = 1.000e-14)
Newton iteration 4: r (abs) = 1.538e-15 (tol = 0.000e+00) r (rel) = 9.639e-15 (tol = 1.000e-14)
Newton solver finished in 4 iterations and 4 linear solver iterations.