:orphan:
# SNESLineSearchShellSetUserFunc
Sets the user function for the `SNESLINESEARCHSHELL` implementation.
## Synopsis
```
PetscErrorCode SNESLineSearchShellSetUserFunc(SNESLineSearch linesearch, SNESLineSearchUserFunc func, void *ctx)
```
Not Collective
## Input Parameters
- ***linesearch -*** `SNESLineSearch` context
- ***func -*** function implementing the linesearch shell.
- ***ctx -*** context for func
## Calling sequence of `func`
```none
PetscErrorCode func(SNESLinesearch, void *ctx)
```
- ***linesearch -*** the linesearch instance
- ***ctx -*** the above mentioned context
## Usage
```none
PetscErrorCode shellfunc(SNESLineSearch linesearch,void * ctx)
{
Vec X,Y,F,W,G;
SNES snes;
PetscFunctionBegin;
PetscCall(SNESLineSearchGetSNES(linesearch,&snes));
PetscCall(SNESLineSearchSetReason(linesearch,SNES_LINESEARCH_SUCCEEDED));
PetscCall(SNESLineSearchGetVecs(linesearch,&X,&F,&Y,&W,&G));
.. determine lambda using W and G as work vecs..
PetscCall(VecAXPY(X,-lambda,Y));
PetscCall(SNESComputeFunction(snes,X,F));
PetscCall(SNESLineSearchComputeNorms(linesearch));
PetscFunctionReturn(PETSC_SUCCESS);
}
...
PetscCall(SNESGetLineSearch(snes, &linesearch));
PetscCall(SNESLineSearchSetType(linesearch, SNESLINESEARCHSHELL));
PetscCall(SNESLineSearchShellSetUserFunc(linesearch, shellfunc, NULL));
```
## See Also
`SNESLineSearchShellGetUserFunc()`, `SNESLINESEARCHSHELL`, `SNESLineSearchType`, `SNESLineSearch`
## Level
advanced
## Location
src/snes/linesearch/impls/shell/linesearchshell.c
## Examples
src/snes/tutorials/ex1f.F90
---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/snes/linesearch/impls/shell/linesearchshell.c)
[Index of all SNES routines](index.md)
[Table of Contents for all manual pages](/manualpages/index.md)
[Index of all manual pages](/manualpages/singleindex.md)