Creating a custom PETScSNESSolver

I have a couple of questions.

  • Following the creation of a custom NewtonSolver as described here, is it possible to do a similar setup for a custom PETScSNESSolver.? Peeking at the underlying PETScSNESSolver.cpp I don’t see a solver_setup method (Am I missing anything)?

In that case, would simply instantiating the solver, and setting PETScOptions work ? Is there a minimum snippet in the demos anywhere (I couldn’t find), because

solver = PETScSNESSolver(mesh.mpi_comm(), "default")
# Setting the preconditioner options: ***********************

PETScOptions.set("pc_type", "gamg") # ?
PETScOptions.set("mg_levels_esteig_ksp_type", "cg")
PETScOptions.set("mg_levels_ksp_chebyshev_esteig_steps", 50)
solver.set_from_options()

is different from


snes_solver_parameters = {"linear_solver": "gmres",
                            "preconditioner": "petsc_amg"} 
solver = PETScSNESSolver(mesh.mpi_comm(), "default")
PETScOptions.set("mg_levels_esteig_ksp_type", "cg")
PETScOptions.set("mg_levels_ksp_chebyshev_esteig_steps", 50)
solver.set_from_options()
solver.parameters.update(snes_solver_parameters)
  • Isn’t PETSc’s algebraic multigrid referenced as gamg? Is there an alias for preconditioners from PETSc ?