Skip to main content
`Ctrl`+`K`

# SNESSetApplicationContext

Sets the optional user-defined context for the nonlinear solvers.

## Synopsis

    #include "petscsnes.h"
    PetscErrorCode SNESSetApplicationContext(SNES snes, void *ctx)

Logically Collective

## Input Parameters

- snes - the `SNES` context

- ctx - the user context

## Notes

Users can provide a context when constructing the `SNES` options and then access it inside their function, Jacobian computation, or other evaluation function with `SNESGetApplicationContext()`

To provide a function that computes the context for you use `SNESSetComputeApplicationContext()`

## Fortran Note

This only works when `ctx` is a Fortran derived type (it cannot be a `PetscObject`), we recommend writing a Fortran interface definition for this function that tells the Fortran compiler the derived data type that is passed in as the `ctx` argument. See `SNESGetApplicationContext()` for an example.

## See Also

SNES: Nonlinear Solvers, `SNES`, `SNESSetComputeApplicationContext()`, `SNESGetApplicationContext()`

## Level

intermediate

## Location

src/snes/interface/snes.c

## Examples

src/snes/tutorials/ex4.c
src/snes/tutorials/ex73f90t.F90
src/snes/tutorials/ex5f90.F90
src/snes/tutorials/ex5f90t.F90

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