Nonlinear solver configuration in dolfinx

Hello,

I would like to configure the nonlinear solver in petxc, in the same spirit as what is done in the demo Solver configuration โ€” FEniCSx tutorial for linear solvers. I tried the following command

problem = dolfinx.fem.petsc.NonlinearProblem(residual, u, bcs=[bc],  petsc_options={"pc_type": "lu"})

but this yields an error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [25], line 2
      1 # We use dolfinx newton solver
----> 2 problem = dolfinx.fem.petsc.NonlinearProblem(residual, u, bcs=[bc],  petsc_options={"pc_type": "lu"})

TypeError: __init__() got an unexpected keyword argument 'petsc_options'

thank you in advance for your help!

See: Implementation โ€” FEniCSx tutorial
where you configure the krylov_solver directly, i.e.

solver = nls.petsc.NewtonSolver(MPI.COMM_WORLD, problem)

ksp = solver.krylov_solver
opts = PETSc.Options()
option_prefix = ksp.getOptionsPrefix()
opts[f"{option_prefix}ksp_type"] = "cg"
opts[f"{option_prefix}pc_type"] = "gamg"
opts[f"{option_prefix}pc_factor_mat_solver_type"] = "mumps"
ksp.setFromOptions()
1 Like

thanks! what if I want to configure options fot my nonlinear solver like

-snes_monitor

The NonLinear solver in DOLFINx does not use SNES, it uses the built-in Newton Solver.
See: dolfinx/test_newton.py at f55eadde9bba6272d5a111aac97bcb4d7f2b5231 ยท FEniCS/dolfinx ยท GitHub for how to interface with SNES

1 Like