xref: /petsc/src/snes/interface/snesj2.c (revision 43a90d8472dff9fb76015431d971d6cf7e7ec88a)
191627157SBarry Smith 
291627157SBarry Smith #ifndef lint
3*43a90d84SBarry Smith static char vcid[] = "$Id: snesj2.c,v 1.3 1996/11/20 20:34:51 bsmith Exp bsmith $";
491627157SBarry Smith #endif
591627157SBarry Smith 
6639f9d9dSBarry Smith #include "src/mat/matimpl.h"      /*I  "mat.h"  I*/
7639f9d9dSBarry Smith #include "src/snes/snesimpl.h"    /*I  "snes.h"  I*/
891627157SBarry Smith 
991627157SBarry Smith 
1091627157SBarry Smith /*@C
1191627157SBarry Smith      SNESDefaultComputeJacobianWithColoring
1291627157SBarry Smith 
1391627157SBarry Smith    Input Parameters:
1491627157SBarry Smith .    snes - nonlinear solver object
1591627157SBarry Smith .    x1 - location at which to evaluate Jacobian
1691627157SBarry Smith .    ctx - MatFDColoring contex
1791627157SBarry Smith 
1891627157SBarry Smith    Output Parameters:
1991627157SBarry Smith .    J - Jacobian matrix
2091627157SBarry Smith .    B - Jacobian preconditioner
2191627157SBarry Smith .    flag - flag indicating if the matrix nonzero structure has changed
2291627157SBarry Smith 
2391627157SBarry Smith .keywords: SNES, finite differences, Jacobian
2491627157SBarry Smith 
2591627157SBarry Smith .seealso: SNESSetJacobian(), SNESTestJacobian()
2691627157SBarry Smith @*/
2791627157SBarry Smith int SNESDefaultComputeJacobianWithColoring(SNES snes,Vec x1,Mat *JJ,Mat *B,MatStructure *flag,void *ctx)
2891627157SBarry Smith {
2991627157SBarry Smith   MatFDColoring color = (MatFDColoring) ctx;
3088389382SBarry Smith   Vec           w1,w2,w3;
31*43a90d84SBarry Smith   int           (*f)(void *,Vec,Vec,void *) = (int (*)(void *,Vec,Vec,void *))snes->computefunction;
32*43a90d84SBarry Smith   int           ierr;
3388389382SBarry Smith 
3488389382SBarry Smith   if (!snes->nvwork) {
3588389382SBarry Smith     ierr = VecDuplicateVecs(x1,3,&snes->vwork); CHKERRQ(ierr);
3688389382SBarry Smith     snes->nvwork = 3;
3788389382SBarry Smith     PLogObjectParents(snes,3,snes->vwork);
3888389382SBarry Smith   }
3988389382SBarry Smith   w1 = snes->vwork[0]; w2 = snes->vwork[1]; w3 = snes->vwork[2];
4088389382SBarry Smith   ierr = MatFDColoringApply(*B,color,x1,w1,w2,w3,f,snes,snes->funP); CHKERRQ(ierr);
4191627157SBarry Smith   *flag = SAME_NONZERO_PATTERN;
4291627157SBarry Smith   return 0;
4391627157SBarry Smith }
4491627157SBarry Smith 
4591627157SBarry Smith 
4691627157SBarry Smith 
47