# SNESSetFromOptions
Sets various `SNES` and `KSP` parameters from user options. 
## Synopsis
```
#include "petscsnes.h"  
PetscErrorCode SNESSetFromOptions(SNES snes)
```
Collective


## Input Parameter

- ***snes -*** the `SNES` context



## Options Database Keys

- ***-snes_type <type> -*** newtonls, newtontr, ngmres, ncg, nrichardson, qn, vi, fas, `SNESType` for complete list
- ***-snes_stol -*** convergence tolerance in terms of the norm
of the change in the solution between steps
- ***-snes_atol <abstol> -*** absolute tolerance of residual norm
- ***-snes_rtol <rtol> -*** relative decrease in tolerance norm from initial
- ***-snes_divergence_tolerance <divtol> -*** if the residual goes above divtol*rnorm0, exit with divergence
- ***-snes_force_iteration <force> -*** force SNESSolve() to take at least one iteration
- ***-snes_max_it <max_it> -*** maximum number of iterations
- ***-snes_max_funcs <max_funcs> -*** maximum number of function evaluations
- ***-snes_max_fail <max_fail> -*** maximum number of line search failures allowed before stopping, default is none
- ***-snes_max_linear_solve_fail -*** number of linear solver failures before SNESSolve() stops
- ***-snes_lag_preconditioner <lag> -*** how often preconditioner is rebuilt (use -1 to never rebuild)
- ***-snes_lag_preconditioner_persists <true,false> -*** retains the -snes_lag_preconditioner information across multiple SNESSolve()
- ***-snes_lag_jacobian <lag> -*** how often Jacobian is rebuilt (use -1 to never rebuild)
- ***-snes_lag_jacobian_persists <true,false> -*** retains the -snes_lag_jacobian information across multiple SNESSolve()
- ***-snes_trtol <trtol> -*** trust region tolerance
- ***-snes_convergence_test -*** <default,skip,correct_pressure> convergence test in nonlinear solver.
default `SNESConvergedDefault()`. skip `SNESConvergedSkip()` means continue iterating until max_it or some other criterion is reached, saving expense
of convergence test. correct_pressure S`NESConvergedCorrectPressure()` has special handling of a pressure null space.
- ***-snes_monitor [ascii][:filename][:viewer format] -*** prints residual norm at each iteration. if no filename given prints to stdout
- ***-snes_monitor_solution [ascii binary draw][:filename][:viewer format] -*** plots solution at each iteration
- ***-snes_monitor_residual [ascii binary draw][:filename][:viewer format] -*** plots residual (not its norm) at each iteration
- ***-snes_monitor_solution_update [ascii binary draw][:filename][:viewer format] -*** plots update to solution at each iteration
- ***-snes_monitor_lg_residualnorm -*** plots residual norm at each iteration
- ***-snes_monitor_lg_range -*** plots residual norm at each iteration
- ***-snes_monitor_pause_final -*** Pauses all monitor drawing after the solver ends
- ***-snes_fd -*** use finite differences to compute Jacobian; very slow, only for testing
- ***-snes_fd_color -*** use finite differences with coloring to compute Jacobian
- ***-snes_mf_ksp_monitor -*** if using matrix-free multiply then print h at each KSP iteration
- ***-snes_converged_reason -*** print the reason for convergence/divergence after each solve
- ***-npc_snes_type <type> -*** the SNES type to use as a nonlinear preconditioner
- ***-snes_test_jacobian <optional threshold> -*** compare the user provided Jacobian with one computed via finite differences to check for errors.  If a threshold is given, display only those entries whose difference is greater than the threshold.
- ***-snes_test_jacobian_view -*** display the user provided Jacobian, the finite difference Jacobian and the difference between them to help users detect the location of errors in the user provided Jacobian.



## Options Database Keys for Eisenstat-Walker method

- ***-snes_ksp_ew -*** use Eisenstat-Walker method for determining linear system convergence
- ***-snes_ksp_ew_version ver -*** version of  Eisenstat-Walker method
- ***-snes_ksp_ew_rtol0 <rtol0> -*** Sets rtol0
- ***-snes_ksp_ew_rtolmax <rtolmax> -*** Sets rtolmax
- ***-snes_ksp_ew_gamma <gamma> -*** Sets gamma
- ***-snes_ksp_ew_alpha <alpha> -*** Sets alpha
- ***-snes_ksp_ew_alpha2 <alpha2> -*** Sets alpha2
- ***-snes_ksp_ew_threshold <threshold> -*** Sets threshold



## Notes
To see all options, run your program with the -help option or consult the users manual

`SNES` supports three approaches for computing (approximate) Jacobians: user provided via `SNESSetJacobian()`, matrix free, and computing explicitly with
finite differences and coloring using `MatFDColoring`. It is also possible to use automatic differentiation and the `MatFDColoring` object.




## See Also
 `SNESType`, `SNESSetOptionsPrefix()`, `SNESResetFromOptions()`, `SNES`, `SNESCreate()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/interface/snes.c.html#SNESSetFromOptions">src/snes/interface/snes.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex1.c.html">src/snes/tutorials/ex1.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex12.c.html">src/snes/tutorials/ex12.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex13.c.html">src/snes/tutorials/ex13.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex14.c.html">src/snes/tutorials/ex14.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex15.c.html">src/snes/tutorials/ex15.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex16.c.html">src/snes/tutorials/ex16.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex17.c.html">src/snes/tutorials/ex17.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex18.c.html">src/snes/tutorials/ex18.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex19.c.html">src/snes/tutorials/ex19.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex1f.F90.html">src/snes/tutorials/ex1f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex2.c.html">src/snes/tutorials/ex2.c.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/composite/snescomposite.c.html#SNESSetFromOptions_Composite">SNESSetFromOptions_Composite in src/snes/impls/composite/snescomposite.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/fas/fas.c.html#SNESSetFromOptions_FAS">SNESSetFromOptions_FAS in src/snes/impls/fas/fas.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/gs/snesgs.c.html#SNESSetFromOptions_NGS">SNESSetFromOptions_NGS in src/snes/impls/gs/snesgs.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/ls/ls.c.html#SNESSetFromOptions_NEWTONLS">SNESSetFromOptions_NEWTONLS in src/snes/impls/ls/ls.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/ms/ms.c.html#SNESSetFromOptions_MS">SNESSetFromOptions_MS in src/snes/impls/ms/ms.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/multiblock/multiblock.c.html#SNESSetFromOptions_Multiblock">SNESSetFromOptions_Multiblock in src/snes/impls/multiblock/multiblock.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/nasm/nasm.c.html#SNESSetFromOptions_NASM">SNESSetFromOptions_NASM in src/snes/impls/nasm/nasm.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/ncg/snesncg.c.html#SNESSetFromOptions_NCG">SNESSetFromOptions_NCG in src/snes/impls/ncg/snesncg.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/ngmres/anderson.c.html#SNESSetFromOptions_Anderson">SNESSetFromOptions_Anderson in src/snes/impls/ngmres/anderson.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/ngmres/snesngmres.c.html#SNESSetFromOptions_NGMRES">SNESSetFromOptions_NGMRES in src/snes/impls/ngmres/snesngmres.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/ntrdc/ntrdc.c.html#SNESSetFromOptions_NEWTONTRDC">SNESSetFromOptions_NEWTONTRDC in src/snes/impls/ntrdc/ntrdc.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/patch/snespatch.c.html#SNESSetFromOptions_Patch">SNESSetFromOptions_Patch in src/snes/impls/patch/snespatch.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/qn/qn.c.html#SNESSetFromOptions_QN">SNESSetFromOptions_QN in src/snes/impls/qn/qn.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/richardson/snesrichardson.c.html#SNESSetFromOptions_NRichardson">SNESSetFromOptions_NRichardson in src/snes/impls/richardson/snesrichardson.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/shell/snesshell.c.html#SNESSetFromOptions_Shell">SNESSetFromOptions_Shell in src/snes/impls/shell/snesshell.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/tr/tr.c.html#SNESSetFromOptions_NEWTONTR">SNESSetFromOptions_NEWTONTR in src/snes/impls/tr/tr.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/vi/ss/viss.c.html#SNESSetFromOptions_VINEWTONSSLS">SNESSetFromOptions_VINEWTONSSLS in src/snes/impls/vi/ss/viss.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/impls/vi/vi.c.html#SNESSetFromOptions_VI">SNESSetFromOptions_VI in src/snes/impls/vi/vi.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/snes/interface/snes.c)


[Index of all SNES routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
