Generalize NewtonSolver and NonlinearProblem to handle preconditioners etc.

Issue #714 resolved
Jan Blechta created an issue

NewtonSolver passes single operator to linear solver every nonlinear step. There needs to be a mechanism to pass second preconditioning operator. Obvious fix is to add NonlinearProblem::J_pc.

More serious problem is that user might want an access to linear solver during setup callbacks. Current available mechanisms

virtual bool NewtonSolver::converged(const GenericVector& r, const NonlinearProblem& nonlinear_problem, std::size_t iteration)
virtual void NonlinearProblem::form(GenericMatrix& A, GenericVector& b, const GenericVector& x) 
virtual void NonlinearProblem::F(GenericVector& b, const GenericVector& x) 
virtual void NonlinearProblem::J(GenericMatrix& A, const GenericVector& x)

don't allow to access linear solver. We could think about something like

virtual void NewtonSolver::solver_setup(std::shared_ptr<GenericLinearSolver> solver,
                                        const NonlinearProblem& nonlinear_problem,
                                        std::size_t iteration)

which would be called after this line to allow overriding linear_solver.set_operator(A).

Modification of relaxation parameter has been suggested @nate-sime at 118250c. I'd suggest to handle this by accessing this->parameters["relaxation_parameter"] in user's overload of NewtonSolver::solver_setup.

Comments (9)

  1. Jan Blechta reporter

    What about extending NonlinearProblem which can be hooked to both NewtonSolver and PETScSNESSolver?

  2. Jan Blechta reporter

    Merge branch 'jan/fix-issue-714'

    • Allow preconditioner matrix in NonlinearProblem and OptimisationProblem interface and use that by NewtonSolver, PETScSNESSolver and PETScTAOSolver, see test/unit/python/nls/test_PETScSNES_solver.py for usage. NonlinearProblem::form(A, b, x) is deprecated in favour of form(A, P, b, x) and NonlinearProblem::J_pc(P, x) is added.

    • Avoid reallocating matrices on subsequent SNES solves - should fix #786.

    • Add PetscErrorCode checks in PETScSNESSolver.

    • Add NewtonSolver::solver_setup(A, P, nonlinear_problem, interation) to allow user to do magic between subsequent Newton steps. This could be subsequently moved into GenericNonlinearSolver when implementing #556.

    • Add NewtonSolver::get/set_relaxation_parameter which in a combination NewtonSolver::solver_setup can be used for tweaking the parameter between the steps, see #714.

    • Add NewtonSolver::update_solution(x, dx, relaxation_parameter, nonlinear_problem, iteration) to allow user to do magic between subsequent Newton steps. This could be subsequently moved into GenericNonlinearSolver when implementing #556.

    • See also #814.

    → <<cset fc5621655379>>

  3. Log in to comment