Actual source code: snesmfj.h

  1: /* "$Id: snesmfj.h,v 1.14 2001/01/15 21:47:52 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,Scalar *);
 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:   double           error_rel;              /* square root of relative error in computing function */
 35:   Scalar           currenth;               /* last differencing parameter h used */
 36:   Scalar           *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:   /*
 43:         The next three are used only if user called MatSNESMFSetFunction()
 44:   */
 45:   int              (*func)(SNES,Vec,Vec,void*);  /* function used for matrix free */
 46:   void             *funcctx;                     /* the context for the function */
 47:   Vec              funcvec;                      /* location to store func(u) */
 48:   Vec              current_f;                    /* location of F(u); used with F(u+h) */
 49:   Vec              current_u;                    /* location of u; used with F(u+h) */

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

 55: EXTERN PetscFList      MatSNESMPetscFList;
 56: EXTERN PetscTruth MatSNESMFRegisterAllCalled;

 58: #endif