# SNESSetLineSearchCheck

Sets a routine to check the validity of new iterate computed by the line search routine in the Newton-based method SNESLS.

### Synopsis

    PetscErrorCode SNESSetLineSearchCheck(SNES snes,PetscErrorCode (*func)(SNES,void*,Vec,PetscTruth*),void *checkctx)

### Input Parameters

| snes | - nonlinear context obtained from SNESCreate()
| func | - pointer to int function
| checkctx | - optional user-defined context for use by step checking routine

Collective on SNES

### Calling sequence of func

       int func (SNES snes, void *checkctx, Vec x, PetscTruth *flag)

where func returns an error code of 0 on success and a nonzero on failure.

### Input parameters for func

| snes | - nonlinear context
| checkctx | - optional user-defined context for use by step checking routine
| x | - current candidate iterate

### Output parameters for func

| x | - current iterate (possibly modified)
| flag | - flag indicating whether x has been modified (either PETSC_TRUE of PETSC_FALSE)

### Notes

SNESNoLineSearch() and SNESNoLineSearchNoNorms() accept the new iterate computed by the line search checking routine. In particular, these routines (1) compute a candidate iterate u_{i+1}, (2) pass control to the checking routine, and then (3) compute the corresponding nonlinear function f(u_{i+1}) with the (possibly altered) iterate u_{i+1}.

SNESQuadraticLineSearch() and SNESCubicLineSearch() also accept the new iterate computed by the line search checking routine. In particular, these routines (1) compute a candidate iterate u_{i+1} as well as a candidate nonlinear function f(u_{i+1}), (2) pass control to the checking routine, and then (3) force a re-evaluation of f(u_{i+1}) if any changes were made to the candidate iterate in the checking routine (as indicated by flag=PETSC_TRUE). The overhead of this function re-evaluation can be very costly, so use this feature with caution!

### Keywords

SNES, nonlinear, set, line search check, step check, routine

### See Also

SNESSetLineSearch()

Level:advanced
Location:src/snes/impls/ls/ls.c
Index of all SNES routines
Table of Contents for all manual pages
Index of all manual pages

### Examples

src/snes/examples/tutorials/ex3.c.html