Choose linear solver for nonlinear problem


Dear all,

for a nonlinear problem, I would like to work with a LU solver for the linearised system instead of the default Krylov solver.

I tried the following:

problem =NonlinearVariationalProblem(F,uc,bcs,j)
prm["newton_solver"]["error_on_nonconvergence"] = False
prm["newton_solver"]["linear_solver"]= "mumps"

But this didn’t work for me…


You can try this:

solver = NewtonSolver()
solver.parameters["linear_solver"] = "lu"

Thanks for your answer, Leo. Actually, I did just the same with the NonlinearVariationalSolver object.

In order to avoid running into new issues caused by using a NewtonSolver object instead of NonlinearVariationalSolver, e.g. because of having to solve a problem defined as NonlinearVariationalProblem and not as NonlinearProblem, I am wondering how to set the linear solver
when working with the NonlinearVariationalSolver .


Maybe this will help you for your problem. Please note, that I am using FEniCS version 2017.2.0:

problem = NonlinearVariationalProblem(F, u_k, bc, J)
solver = NonlinearVariationalSolver(problem)
solver.parameters[“newton_solver”][“linear_solver”] = “lu”
solver.parameters[“newton_solver”][“convergence_criterion”] = “residual”
solver.parameters[“newton_solver”][“absolute_tolerance”] = 1e-10
solver.parameters[“newton_solver”][“maximum_iterations”] = 5


Thank you for your answers.

Actually, I am wondering how to explicitly choose one of the solvers which can be displayed by


for the NonlinearVariationalProblem as described in the Fenics tutorial book (pp. 117–118) for linear problems.

Also, I am not sure if the method to change the solver proposed by zimtzucker is successfull as it is very similar to the command I had tried.
Is there a way to verify the type of the linear solver used or to display the NonlinearVariationalSolver’s parameters in general?



I tried the idea proposed by zimtzucker. His proposition did not work for me on Fenics 2018.1:

Although I set

prm["newton_solver"]["linear_solver"]= "lu"

I got the following error:

*** Error: Unable to solve linear system using PETSc Krylov solver.
*** Reason: Solution failed to converge in 0 iterations (PETSc reason DIVERGED_PCSETUP_FAILED, residual norm ||r|| = 0.000000e+00)

Apparently, a Krylov method was used although I tried to enforce the usage of a LU solver.
Actually, I am trying to avoid the error by applying a direct solution method instead of the Krylov solver.

Is there really nobody knowing how to use a direct method for nonlinear problems in Fenics? Please, I need your help. :hushed:



this works for a Navier-Stokes (in cylindrical coordinates) using Fenics 2018.1.0:

J = derivative(F, up )

problem = NonlinearVariationalProblem(F, up , dirichlet, J)
solver = NonlinearVariationalSolver(problem)

prm = solver.parameters
prm[“nonlinear_solver”] = “snes”
prm[“snes_solver”][“line_search”] = “bt”
prm[“snes_solver”][“linear_solver”] = “mumps”
#prm[“snes_solver”][“linear_solver”] = “gmres”
#prm[“snes_solver”][“preconditioner”] = “hypre_amg”
#prm[“snes_solver”][“krylov_solver”][“nonzero_initial_guess”] = False
prm[“snes_solver”][“report”] = True



Did you resolve this? I see this info as well. Thanks