Skip to main content
`Ctrl`+`K`

# SNESComputeJacobian

Computes the Jacobian matrix that has been set with `SNESSetJacobian()`.

## Synopsis

    #include "petscsnes.h"
    #include "petscsnes.h"
    PetscErrorCode SNESComputeJacobian(SNES snes, Vec X, Mat A, Mat B)

Collective

## Input Parameters

- snes - the `SNES` context

- X - input vector

## Output Parameters

- A - Jacobian matrix

- B - optional matrix for building the preconditioner, usually the same as `A`

## Options Database Keys

- -snes_lag_preconditioner lag - how often to rebuild preconditioner

- -snes_lag_jacobian lag - how often to rebuild Jacobian

- -snes_test_jacobian [threshold] - compare the user provided Jacobian with one compute 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 [viewer] - 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

- -snes_compare_explicit - Compare the computed Jacobian to the finite difference Jacobian and output the differences

- -snes_compare_explicit_draw - Compare the computed Jacobian to the finite difference Jacobian and draw the result

- -snes_compare_explicit_contour - Compare the computed Jacobian to the finite difference Jacobian and draw a contour plot with the result

- -snes_compare_operator - Make the comparison options above use the operator instead of the matrix used to construct the preconditioner

- -snes_compare_coloring - Compute the finite difference Jacobian using coloring and display norms of difference

- -snes_compare_coloring_display - Compute the finite difference Jacobian using coloring and display verbose differences

- -snes_compare_coloring_threshold - Display only those matrix entries that differ by more than a given threshold

- -snes_compare_coloring_threshold_atol - Absolute tolerance for difference in matrix entries to be displayed by `-snes_compare_coloring_threshold`

- -snes_compare_coloring_threshold_rtol - Relative tolerance for difference in matrix entries to be displayed by `-snes_compare_coloring_threshold`

- -snes_compare_coloring_draw - Compute the finite difference Jacobian using coloring and draw differences

- -snes_compare_coloring_draw_contour - Compute the finite difference Jacobian using coloring and show contours of matrices and differences

## Note

Most users should not need to explicitly call this routine, as it is used internally within the nonlinear solvers.

## Developer Note

This has duplicative ways of checking the accuracy of the user provided Jacobian (see the options above). This is for historical reasons, the routine `SNESTestJacobian()` use to used with the `SNESType` of test that has been removed.

## See Also

SNES: Nonlinear Solvers, `SNESSetJacobian()`, `KSPSetOperators()`, `MatStructure`, `SNESSetLagPreconditioner()`, `SNESSetLagJacobian()`, `SNESSetJacobianDomainError()`, `SNESCheckJacobianDomainError()`, `SNESSetCheckJacobianDomainError()`

## Level

developer

## Location

src/snes/interface/snes.c

## Examples

src/snes/tutorials/ex56.c
src/snes/tutorials/ex12.c
src/snes/tutorials/ex77.c

## Implementations

SNESComputeJacobian_MATLMVM() in src/snes/impls/tr/tr.c

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