Actual source code: snesmfj.h

  1: /* "$Id: snesmfj.h,v 1.19 2001/09/07 20:11:34 bsmith Exp $"; */
  2: /*
  3:     This file should be included in NEW routines that compute the
  4:     differencing parameter for finite difference based matrix-free
  5:     methods.  For example, such routines can compute h for use in
  6:     Jacobian-vector products of the form

  8:                        F(x+ha) - F(x)
  9:           F'(u)a  ~=  ----------------
 10:                             h
 11: */


 16:  #include include/petscsnes.h

 18: /*
 19:     Table of functions that manage the computation and understanding
 20:     of the parameter for finite difference based matrix-free computations
 21: */
 22: struct _MFOps {
 23:   int (*compute)(MatSNESMFCtx,Vec,Vec,PetscScalar *);
 24:   int (*view)(MatSNESMFCtx,PetscViewer);
 25:   int (*destroy)(MatSNESMFCtx);
 26:   int (*setfromoptions)(MatSNESMFCtx);
 27: };

 29: struct _p_MatSNESMFCtx {    /* context for default matrix-free SNES */
 30:   PETSCHEADER(struct _MFOps)
 31:   SNES             snes;                   /* nonlinear solver */
 32:   Vec              w;                      /* work vector */
 33:   MatNullSpace     sp;                     /* null space context */
 34:   PetscReal        error_rel;              /* square root of relative error in computing function */
 35:   PetscScalar      currenth;               /* last differencing parameter h used */
 36:   PetscScalar      *historyh;              /* history of differencing parameter h */
 37:   int              ncurrenth,maxcurrenth;
 38:   void             *hctx;
 39:   Mat              mat;                    /* back reference to shell matrix that contains this */
 40:   int              recomputeperiod;        /* how often the h is recomputed; default to 1 */
 41:   int              count;                  /* used by recomputeperiod */
 42:   void             *checkhctx;             /* optional context used by MatSNESMFSetCheckh() */
 43:   int              (*checkh)(Vec,Vec,PetscScalar*,void*);
 44:   /*
 45:         The next three are used only if user called MatSNESMFSetFunction()
 46:   */
 47:   int              (*func)(SNES,Vec,Vec,void*);  /* function used for matrix free */
 48:   void             *funcctx;                     /* the context for the function */
 49:   Vec              funcvec;                      /* location to store func(u) */
 50:   Vec              current_f;                    /* location of F(u); used with F(u+h) */
 51:   Vec              current_u;                    /* location of u; used with F(u+h) */

 53:   PetscTruth       usesnes;                      /* if false indicates that one should (*func) 
 54:                                                     instead of SNES even if snes is present */

 56:   int              (*funci)(int,Vec,PetscScalar*,void*);  /* Evaluates func_[i]() */
 57:   int              (*funcisetbase)(Vec,void*);            /* Sets base for future evaluations of func_[i]() */

 59:   PetscScalar      vscale,vshift;
 60: };

 62: EXTERN PetscFList      MatSNESMPetscFList;
 63: EXTERN PetscTruth MatSNESMFRegisterAllCalled;

 65: #endif