xref: /petsc/src/snes/interface/snesj2.c (revision a5eb49655b3fdf389f9d65fc4214d6e1c240a941)
1*a5eb4965SSatish Balay #ifdef PETSC_RCS_HEADER
2*a5eb4965SSatish Balay static char vcid[] = "$Id: snesj2.c,v 1.6 1997/01/06 20:29:45 balay Exp balay $";
391627157SBarry Smith #endif
491627157SBarry Smith 
5639f9d9dSBarry Smith #include "src/mat/matimpl.h"      /*I  "mat.h"  I*/
6639f9d9dSBarry Smith #include "src/snes/snesimpl.h"    /*I  "snes.h"  I*/
791627157SBarry Smith 
891627157SBarry Smith 
95615d1e5SSatish Balay #undef __FUNC__
105615d1e5SSatish Balay #define __FUNC__ "SNESDefaultComputeJacobianWithColoring"
1191627157SBarry Smith /*@C
1291627157SBarry Smith      SNESDefaultComputeJacobianWithColoring
1391627157SBarry Smith 
1491627157SBarry Smith    Input Parameters:
1591627157SBarry Smith .    snes - nonlinear solver object
1691627157SBarry Smith .    x1 - location at which to evaluate Jacobian
1791627157SBarry Smith .    ctx - MatFDColoring contex
1891627157SBarry Smith 
1991627157SBarry Smith    Output Parameters:
2091627157SBarry Smith .    J - Jacobian matrix
2191627157SBarry Smith .    B - Jacobian preconditioner
2291627157SBarry Smith .    flag - flag indicating if the matrix nonzero structure has changed
2391627157SBarry Smith 
2491627157SBarry Smith .keywords: SNES, finite differences, Jacobian
2591627157SBarry Smith 
2691627157SBarry Smith .seealso: SNESSetJacobian(), SNESTestJacobian()
2791627157SBarry Smith @*/
2891627157SBarry Smith int SNESDefaultComputeJacobianWithColoring(SNES snes,Vec x1,Mat *JJ,Mat *B,MatStructure *flag,void *ctx)
2991627157SBarry Smith {
3091627157SBarry Smith   MatFDColoring color = (MatFDColoring) ctx;
3188389382SBarry Smith   Vec           w1,w2,w3;
3243a90d84SBarry Smith   int           (*f)(void *,Vec,Vec,void *) = (int (*)(void *,Vec,Vec,void *))snes->computefunction;
3343a90d84SBarry Smith   int           ierr;
3488389382SBarry Smith 
3588389382SBarry Smith   if (!snes->nvwork) {
3688389382SBarry Smith     ierr = VecDuplicateVecs(x1,3,&snes->vwork); CHKERRQ(ierr);
3788389382SBarry Smith     snes->nvwork = 3;
3888389382SBarry Smith     PLogObjectParents(snes,3,snes->vwork);
3988389382SBarry Smith   }
4088389382SBarry Smith   w1 = snes->vwork[0]; w2 = snes->vwork[1]; w3 = snes->vwork[2];
4188389382SBarry Smith   ierr = MatFDColoringApply(*B,color,x1,w1,w2,w3,f,snes,snes->funP); CHKERRQ(ierr);
4291627157SBarry Smith   *flag = SAME_NONZERO_PATTERN;
4391627157SBarry Smith   return 0;
4491627157SBarry Smith }
4591627157SBarry Smith 
4691627157SBarry Smith 
4791627157SBarry Smith 
48