# SNESComputeJacobianDefaultColor
Computes the Jacobian using finite differences and coloring to exploit matrix sparsity. 
## Synopsis
```
#include "petscsnes.h"  
#include "petscdm.h"    
PetscErrorCode SNESComputeJacobianDefaultColor(SNES snes, Vec x1, Mat J, Mat B, void *ctx)
```
Collective


## Input Parameters

- ***snes -*** nonlinear solver object
- ***x1 -*** location at which to evaluate Jacobian
- ***ctx -*** MatFDColoring context or NULL



## Output Parameters

- ***J -*** Jacobian matrix (not altered in this routine)
- ***B -*** newly computed Jacobian matrix to use with preconditioner (generally the same as J)





## Options Database Keys

- ***-snes_fd_color_use_mat -*** use a matrix coloring from the explicit matrix nonzero pattern instead of from the DM providing the matrix
- ***-snes_fd_color -*** Activates `SNESComputeJacobianDefaultColor()` in `SNESSetFromOptions()`
- ***-mat_fd_coloring_err <err> -*** Sets <err> (square root of relative error in the function)
- ***-mat_fd_coloring_umin <umin> -*** Sets umin, the minimum allowable u-value magnitude
- ***-mat_fd_type -*** Either wp or ds (see `MATMFFD_WP` or `MATMFFD_DS`)
- ***-snes_mf_operator -*** Use matrix free application of Jacobian
- ***-snes_mf -*** Use matrix free Jacobian with no explicit Jacobian representation



## Notes
If the coloring is not provided through the context, this will first try to get the
coloring from the `DM`.  If the `DM` has no coloring routine, then it will try to
get the coloring from the matrix.  This requires that the matrix have its nonzero locations already provided.

`SNES` supports three approaches for computing (approximate) Jacobians: user provided via `SNESSetJacobian()`, matrix-free via `SNESSetUseMatrixFree()`,
and computing explicitly with finite differences and coloring using `MatFDColoring`. It is also possible to use automatic differentiation
and the `MatFDColoring` object, see src/ts/tutorials/autodiff/ex16adj_tl.cxx

This function can be provided to `SNESSetJacobian()` along with an appropriate sparse matrix to hold the Jacobian


## See Also
 `SNES`, `SNESSetJacobian()`, `SNESTestJacobian()`, `SNESComputeJacobianDefault()`, `SNESSetUseMatrixFree()`,
`MatFDColoringCreate()`, `MatFDColoringSetFunction()`

## Level
intermediate

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

## Examples
<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/ts/tutorials/ex10.c.html">src/ts/tutorials/ex10.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex15.c.html">src/ts/tutorials/ex15.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex17.c.html">src/ts/tutorials/ex17.c.html</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/snes/interface/snesj2.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)  
