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