xref: /petsc/src/snes/interface/snesj2.c (revision 5615d1e584023db9367fb782d85b1b4ebbb8df18)
191627157SBarry Smith 
291627157SBarry Smith #ifndef lint
3*5615d1e5SSatish Balay static char vcid[] = "$Id: snesj2.c,v 1.5 1996/12/16 20:43:19 balay Exp balay $";
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 
10*5615d1e5SSatish Balay #undef __FUNC__
11*5615d1e5SSatish Balay #define __FUNC__ "SNESDefaultComputeJacobianWithColoring"
1291627157SBarry Smith /*@C
1391627157SBarry Smith      SNESDefaultComputeJacobianWithColoring
1491627157SBarry Smith 
1591627157SBarry Smith    Input Parameters:
1691627157SBarry Smith .    snes - nonlinear solver object
1791627157SBarry Smith .    x1 - location at which to evaluate Jacobian
1891627157SBarry Smith .    ctx - MatFDColoring contex
1991627157SBarry Smith 
2091627157SBarry Smith    Output Parameters:
2191627157SBarry Smith .    J - Jacobian matrix
2291627157SBarry Smith .    B - Jacobian preconditioner
2391627157SBarry Smith .    flag - flag indicating if the matrix nonzero structure has changed
2491627157SBarry Smith 
2591627157SBarry Smith .keywords: SNES, finite differences, Jacobian
2691627157SBarry Smith 
2791627157SBarry Smith .seealso: SNESSetJacobian(), SNESTestJacobian()
2891627157SBarry Smith @*/
2991627157SBarry Smith int SNESDefaultComputeJacobianWithColoring(SNES snes,Vec x1,Mat *JJ,Mat *B,MatStructure *flag,void *ctx)
3091627157SBarry Smith {
3191627157SBarry Smith   MatFDColoring color = (MatFDColoring) ctx;
3288389382SBarry Smith   Vec           w1,w2,w3;
3343a90d84SBarry Smith   int           (*f)(void *,Vec,Vec,void *) = (int (*)(void *,Vec,Vec,void *))snes->computefunction;
3443a90d84SBarry Smith   int           ierr;
3588389382SBarry Smith 
3688389382SBarry Smith   if (!snes->nvwork) {
3788389382SBarry Smith     ierr = VecDuplicateVecs(x1,3,&snes->vwork); CHKERRQ(ierr);
3888389382SBarry Smith     snes->nvwork = 3;
3988389382SBarry Smith     PLogObjectParents(snes,3,snes->vwork);
4088389382SBarry Smith   }
4188389382SBarry Smith   w1 = snes->vwork[0]; w2 = snes->vwork[1]; w3 = snes->vwork[2];
4288389382SBarry Smith   ierr = MatFDColoringApply(*B,color,x1,w1,w2,w3,f,snes,snes->funP); CHKERRQ(ierr);
4391627157SBarry Smith   *flag = SAME_NONZERO_PATTERN;
4491627157SBarry Smith   return 0;
4591627157SBarry Smith }
4691627157SBarry Smith 
4791627157SBarry Smith 
4891627157SBarry Smith 
49