Actual source code: snesj2.c

  1: /*$Id: snesj2.c,v 1.27 2001/03/23 23:24:07 balay Exp $*/

 3:  #include src/mat/matimpl.h
 4:  #include src/snes/snesimpl.h

  6: /*@C
  7:     SNESDefaultComputeJacobianColor - Computes the Jacobian using
  8:     finite differences and coloring to exploit matrix sparsity. 
  9:   
 10:     Collective on SNES

 12:     Input Parameters:
 13: +   snes - nonlinear solver object
 14: .   x1 - location at which to evaluate Jacobian
 15: -   ctx - coloring context, where ctx must have type MatFDColoring, 
 16:           as created via MatFDColoringCreate()

 18:     Output Parameters:
 19: +   J - Jacobian matrix (not altered in this routine)
 20: .   B - newly computed Jacobian matrix to use with preconditioner (generally the same as J)
 21: -   flag - flag indicating whether the matrix sparsity structure has changed

 23:     Options Database Keys:
 24: .  -mat_fd_coloring_freq <freq> - Activates SNESDefaultComputeJacobianColor()

 26:     Level: intermediate

 28: .keywords: SNES, finite differences, Jacobian, coloring, sparse

 30: .seealso: SNESSetJacobian(), SNESTestJacobian(), SNESDefaultComputeJacobian()
 31:           TSDefaultComputeJacobianColor(), MatFDColoringCreate(),
 32:           MatFDColoringSetFunction()

 34: @*/
 35: int SNESDefaultComputeJacobianColor(SNES snes,Vec x1,Mat *J,Mat *B,MatStructure *flag,void *ctx)
 36: {
 37:   MatFDColoring color = (MatFDColoring) ctx;
 38:   int           ierr,freq,it;

 41:   MatFDColoringGetFrequency(color,&freq);
 42:   SNESGetIterationNumber(snes,&it);

 44:   if ((freq > 1) && ((it % freq) != 1)) {
 45:     PetscLogInfo(color,"SNESDefaultComputeJacobianColor:Skipping Jacobian, it %d, freq %dn",it,freq);
 46:     *flag = SAME_PRECONDITIONER;
 47:     return(0);
 48:   } else {
 49:     PetscLogInfo(color,"SNESDefaultComputeJacobianColor:Computing Jacobian, it %d, freq %dn",it,freq);
 50:     *flag = SAME_NONZERO_PATTERN;
 51:   }


 54:   PetscLogEventBegin(SNES_FunctionEval,snes,x1,0,0);
 55:   PetscStackPush("SNES user function");
 56:   MatFDColoringApply(*B,color,x1,flag,snes);
 57:   PetscStackPop;
 58:   snes->nfuncs++;
 59:   PetscLogEventEnd(SNES_FunctionEval,snes,x1,0,0);
 60:   return(0);
 61: }