petsc-3.3-p7 2013-05-11

SNESSetJacobian

Sets the function to compute Jacobian as well as the location to store the matrix.

Synopsis

#include "petscsnes.h"  
#include "petscdmshell.h" 
#include "petscsys.h" 
PetscErrorCode  SNESSetJacobian(SNES snes,Mat A,Mat B,PetscErrorCode (*func)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *ctx)
Logically Collective on SNES and Mat

Input Parameters

snes - the SNES context
A - Jacobian matrix
B - preconditioner matrix (usually same as the Jacobian)
func - Jacobian evaluation routine (if PETSC_NULL then SNES retains any previously set value)
ctx - [optional] user-defined context for private data for the Jacobian evaluation routine (may be PETSC_NULL) (if PETSC_NULL then SNES retains any previously set value)

Calling sequence of func

    func (SNES snes,Vec x,Mat *A,Mat *B,int *flag,void *ctx);

x - input vector
A - Jacobian matrix
B - preconditioner matrix, usually the same as A
flag - flag indicating information about the preconditioner matrix structure (same as flag in KSPSetOperators()), one of SAME_NONZERO_PATTERN,DIFFERENT_NONZERO_PATTERN,SAME_PRECONDITIONER
ctx - [optional] user-defined Jacobian context

Notes

See KSPSetOperators() for important information about setting the flag output parameter in the routine func(). Be sure to read this information!

The routine func() takes Mat * as the matrix arguments rather than Mat. This allows the Jacobian evaluation routine to replace A and/or B with a completely new new matrix structure (not just different matrix elements) when appropriate, for instance, if the nonzero structure is changing throughout the global iterations.

If the A matrix and B matrix are different you must call MatAssemblyBegin/End() on each matrix.

If using SNESDefaultComputeJacobianColor() to assemble a Jacobian, the ctx argument must be a MatFDColoring.

Other defect-correction schemes can be used by computing a different matrix in place of the Jacobian. One common example is to use the "Picard linearization" which only differentiates through the highest order parts of each term.

Keywords

SNES, nonlinear, set, Jacobian, matrix

See Also

KSPSetOperators(), SNESSetFunction(), MatMFFDComputeJacobian(), SNESDefaultComputeJacobianColor(), MatStructure

Level:beginner
Location:
src/snes/interface/snes.c
Index of all SNES routines
Table of Contents for all manual pages
Index of all manual pages

Examples

src/snes/examples/tutorials/ex1.c.html
src/snes/examples/tutorials/ex2.c.html
src/snes/examples/tutorials/ex3.c.html
src/snes/examples/tutorials/ex5s.c.html
src/snes/examples/tutorials/ex6.c.html
src/snes/examples/tutorials/ex10.c.html
src/snes/examples/tutorials/ex12.c.html
src/snes/examples/tutorials/ex14.c.html
src/snes/examples/tutorials/ex18.c.html
src/snes/examples/tutorials/ex20.c.html
src/snes/examples/tutorials/ex28.c.html