Actual source code: snesmfj.h

      1: /*
      2:     This file should be included in NEW routines that compute the
      3:     differencing parameter for finite difference based matrix-free
      4:     methods.  For example, such routines can compute h for use in
      5:     Jacobian-vector products of the form

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

     15:  #include include/petscsnes.h

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

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

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

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

     58:   PetscScalar      vscale,vshift;
     59: };

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

     64: #endif