SNESSetUpdate — PETSc 3.25.2 documentation

Skip to main content
`Ctrl`+`K`

# SNESSetUpdate

Sets the general-purpose update function called at the beginning of every iteration of the nonlinear solve. Specifically it is called just before the Jacobian is “evaluated” and after the function evaluation.

## Synopsis

    #include "petscsnes.h"
    #include "petscsnes.h"
    PetscErrorCode SNESSetUpdate(SNES snes, SNESUpdateFn *func)

Logically Collective

## Input Parameters

- snes - The nonlinear solver context

- func - The update function; for calling sequence see `SNESUpdateFn`

## Notes

This is NOT what one uses to update the ghost points before a function evaluation, that should be done at the beginning of your function provided to `SNESSetFunction()`, or `SNESSetPicard()` This is not used by most users, and it is intended to provide a general hook that is run right before the direction step is computed.

Users are free to modify the current residual vector, the current linearization point, or any other vector associated to the specific solver used. If such modifications take place, it is the user responsibility to update all the relevant vectors. For example, if one is adjusting the model parameters at each Newton step their code may look like

      PetscErrorCode update(SNES snes, PetscInt iteration)
      {
        PetscFunctionBeginUser;
        if (iteration > 0) {
          // update the model parameters here
          Vec x,f;
          PetscCall(SNESGetSolution(snes,&x));
          PetcCall(SNESGetFunction(snes,&f,NULL,NULL));
          PetscCall(SNESComputeFunction(snes,x,f));
        }
        PetscFunctionReturn(PETSC_SUCCESS);
      }

There are a variety of function hooks one many set that are called at different stages of the nonlinear solution process, see the functions listed below.

## See Also

SNES: Nonlinear Solvers, `SNES`, `SNESSolve()`, `SNESSetJacobian()`, `SNESLineSearchSetPreCheck()`, `SNESLineSearchSetPostCheck()`, `SNESNewtonTRSetPreCheck()`, `SNESNewtonTRSetPostCheck()`, `SNESMonitorSet()`

## Level

advanced

## Location

src/snes/interface/snes.c

Index of all SNES routines
Table of Contents for all manual pages
Index of all manual pages