# SNES solver failing

391
views
1
13 months ago by
I have code solve a PDE using the default Newton solver but would like to transition to using SNES.  However, I'm having trouble tweaking my code to do so.  This code

auto F = std::make_shared<StressBalance::LinearForm>(space);
auto J = std::make_shared<StressBalance::JacobianForm>(space, space);
// set Expressions/Functions/Constants for F and J
auto prob = std::make_shared<dfn::NonlinearVariationalProblem>(F, u, std::vector<std::shared_ptr<const dfn::DirichletBC> >(1, dirichlet), J);
auto solver = std::make_shared<dfn::NonlinearVariationalSolver>(prob);
solver->solve();

gives me the (correct) result:

Solving nonlinear variational problem.
Newton iteration 0: r (abs) = 2.230e-04 (tol = 1.000e-10) r (rel) = 1.000e+00 (tol = 1.000e-09)
Newton iteration 1: r (abs) = 3.098e-06 (tol = 1.000e-10) r (rel) = 1.389e-02 (tol = 1.000e-09)
Newton iteration 2: r (abs) = 3.961e-09 (tol = 1.000e-10) r (rel) = 1.777e-05 (tol = 1.000e-09)
Newton iteration 3: r (abs) = 5.240e-14 (tol = 1.000e-10) r (rel) = 2.350e-10 (tol = 1.000e-09)
Newton solver finished in 3 iterations and 3 linear solver iterations.

solver->parameters["nonlinear_solver"] = "snes";
solver->parameters("snes_solver")["report"] = true;
solver->parameters("snes_solver")["maximum_iterations"] = (int)maxIt;
solver->parameters("snes_solver")["relative_tolerance"] = tol;
solver->parameters("snes_solver")["relative_tolerance"] = tol;
solver->parameters("snes_solver")["error_on_nonconvergence"] = false;
solver->parameters("snes_solver")["line_search"] = "bt";

Gives the error

Solving nonlinear variational problem.
unknown file: Failure
C++ exception with description "
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to successfully call PETSc function 'SNESSetFromOptions'.
*** Reason: PETSc error code is: 73 (Object is in wrong state).
*** Where: This error was encountered inside /Users/andy/software/fenics/dolfin/dolfin/nls/PETScSNESSolver.cpp.
*** Process: 0
***
*** DOLFIN version: 2017.1.0.dev0
*** -------------------------------------------------------------------------
" thrown in the test body.

Does anyone know what I'm doing wrong?