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