petsc-3.14.5 2021-03-03
Report Typos and Errors

# SNESLineSearchShellSetUserFunc

Sets the user function for the SNESLineSearch Shell 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

| linesearch | - the linesearch instance
| ctx | - the above mentioned context

### Usage

     PetscErrorCode shellfunc(SNESLineSearch linesearch,void * ctx)

     {

        Vec  X,Y,F,W,G;

        SNES snes;

        PetscFunctionBegin;

        ierr = SNESLineSearchGetSNES(linesearch,&snes);CHKERRQ(ierr);

        ierr = SNESLineSearchSetReason(linesearch,SNES_LINESEARCH_SUCCEEDED);CHKERRQ(ierr);

        ierr = SNESLineSearchGetVecs(linesearch,&X,&F,&Y,&W,&G);CHKERRQ(ierr);

        .. determine lambda using W and G as work vecs..

        ierr = VecAXPY(X,-lambda,Y);CHKERRQ(ierr);

        ierr = SNESComputeFunction(snes,X,F);CHKERRQ(ierr);

        ierr = SNESLineSearchComputeNorms(linesearch);CHKERRQ(ierr);

        PetscFunctionReturn(0);

     }

     ...

     ierr = SNESGetLineSearch(snes, &linesearch);CHKERRQ(ierr);

     ierr = SNESLineSearchSetType(linesearch, SNESLINESEARCHSHELL);CHKERRQ(ierr);

     ierr = SNESLineSearchShellSetUserFunc(linesearch, shellfunc, NULL);CHKERRQ(ierr);

.seealso: SNESLineSearchShellGetUserFunc(), SNESLINESEARCHSHELL

### Level

advanced

### Location

src/snes/linesearch/impls/shell/linesearchshell.c

### Examples

src/snes/tutorials/ex1f.F90.html
Index of all SNES routines
Table of Contents for all manual pages
Index of all manual pages