xref: /petsc/src/snes/interface/snesj2.c (revision bcff55d9c22a11117c657f321125d3821e9fb4a8)
1 #ifdef PETSC_RCS_HEADER
2 static char vcid[] = "$Id: snesj2.c,v 1.6 1997/01/06 20:29:45 balay Exp balay $";
3 #endif
4 
5 #include "src/mat/matimpl.h"      /*I  "mat.h"  I*/
6 #include "src/snes/snesimpl.h"    /*I  "snes.h"  I*/
7 
8 
9 #undef __FUNC__
10 #define __FUNC__ "SNESDefaultComputeJacobianWithColoring"
11 /*@C
12      SNESDefaultComputeJacobianWithColoring
13 
14    Input Parameters:
15 .    snes - nonlinear solver object
16 .    x1 - location at which to evaluate Jacobian
17 .    ctx - MatFDColoring contex
18 
19    Output Parameters:
20 .    J - Jacobian matrix
21 .    B - Jacobian preconditioner
22 .    flag - flag indicating if the matrix nonzero structure has changed
23 
24 .keywords: SNES, finite differences, Jacobian
25 
26 .seealso: SNESSetJacobian(), SNESTestJacobian()
27 @*/
28 int SNESDefaultComputeJacobianWithColoring(SNES snes,Vec x1,Mat *JJ,Mat *B,MatStructure *flag,void *ctx)
29 {
30   MatFDColoring color = (MatFDColoring) ctx;
31   Vec           w1,w2,w3;
32   int           (*f)(void *,Vec,Vec,void *) = (int (*)(void *,Vec,Vec,void *))snes->computefunction;
33   int           ierr;
34 
35   if (!snes->nvwork) {
36     ierr = VecDuplicateVecs(x1,3,&snes->vwork); CHKERRQ(ierr);
37     snes->nvwork = 3;
38     PLogObjectParents(snes,3,snes->vwork);
39   }
40   w1 = snes->vwork[0]; w2 = snes->vwork[1]; w3 = snes->vwork[2];
41   ierr = MatFDColoringApply(*B,color,x1,w1,w2,w3,f,snes,snes->funP); CHKERRQ(ierr);
42   *flag = SAME_NONZERO_PATTERN;
43   return 0;
44 }
45 
46 
47 
48