1*d52ab7bdSBarry Smith /* 2*d52ab7bdSBarry Smith This file should be included in NEW routines that compute the 3*d52ab7bdSBarry Smith differencing parameter for finite difference based matrix-free 4*d52ab7bdSBarry Smith methods. For example, such routines can compute h for use in 5*d52ab7bdSBarry Smith Jacobian-vector products of the form 6*d52ab7bdSBarry Smith 7*d52ab7bdSBarry Smith F(x+ha) - F(x) 8*d52ab7bdSBarry Smith F'(u)a ~= ---------------- 9*d52ab7bdSBarry Smith h 10*d52ab7bdSBarry Smith */ 11*d52ab7bdSBarry Smith 12*d52ab7bdSBarry Smith #if !defined(__MFFD_H__) 13*d52ab7bdSBarry Smith #define __MFFD_H__ 14*d52ab7bdSBarry Smith 15*d52ab7bdSBarry Smith #include "petscmat.h" /*I "petscmat.h" I*/ 16*d52ab7bdSBarry Smith 17*d52ab7bdSBarry Smith /* 18*d52ab7bdSBarry Smith Table of functions that manage the computation and understanding 19*d52ab7bdSBarry Smith of the parameter for finite difference based matrix-free computations 20*d52ab7bdSBarry Smith */ 21*d52ab7bdSBarry Smith struct _MFOps { 22*d52ab7bdSBarry Smith PetscErrorCode (*compute)(MatMFFD,Vec,Vec,PetscScalar *,PetscTruth* zeroa); 23*d52ab7bdSBarry Smith PetscErrorCode (*view)(MatMFFD,PetscViewer); 24*d52ab7bdSBarry Smith PetscErrorCode (*destroy)(MatMFFD); 25*d52ab7bdSBarry Smith PetscErrorCode (*setfromoptions)(MatMFFD); 26*d52ab7bdSBarry Smith }; 27*d52ab7bdSBarry Smith 28*d52ab7bdSBarry Smith struct _p_MatMFFD { /* context for default matrix-free SNES */ 29*d52ab7bdSBarry Smith PETSCHEADER(struct _MFOps); 30*d52ab7bdSBarry Smith Vec w; /* work vector */ 31*d52ab7bdSBarry Smith MatNullSpace sp; /* null space context */ 32*d52ab7bdSBarry Smith PetscReal error_rel; /* square root of relative error in computing function */ 33*d52ab7bdSBarry Smith PetscScalar currenth; /* last differencing parameter h used */ 34*d52ab7bdSBarry Smith PetscScalar *historyh; /* history of differencing parameter h */ 35*d52ab7bdSBarry Smith PetscInt ncurrenth,maxcurrenth; 36*d52ab7bdSBarry Smith void *hctx; 37*d52ab7bdSBarry Smith Mat mat; /* back reference to shell matrix that contains this */ 38*d52ab7bdSBarry Smith PetscInt recomputeperiod; /* how often the h is recomputed; default to 1 */ 39*d52ab7bdSBarry Smith PetscInt count; /* used by recomputeperiod */ 40*d52ab7bdSBarry Smith PetscErrorCode (*checkh)(void*,Vec,Vec,PetscScalar*); 41*d52ab7bdSBarry Smith void *checkhctx; /* optional context used by MatMFFDSetCheckh() */ 42*d52ab7bdSBarry Smith 43*d52ab7bdSBarry Smith PetscErrorCode (*func)(void*,Vec,Vec); /* function used for matrix free */ 44*d52ab7bdSBarry Smith void *funcctx; /* the context for the function */ 45*d52ab7bdSBarry Smith Vec current_f; /* location of F(u); used with F(u+h) */ 46*d52ab7bdSBarry Smith Vec current_u; /* location of u; used with F(u+h) */ 47*d52ab7bdSBarry Smith 48*d52ab7bdSBarry Smith PetscErrorCode (*funci)(void*,PetscInt,Vec,PetscScalar*); /* Evaluates func_[i]() */ 49*d52ab7bdSBarry Smith PetscErrorCode (*funcisetbase)(void*,Vec); /* Sets base for future evaluations of func_[i]() */ 50*d52ab7bdSBarry Smith 51*d52ab7bdSBarry Smith PetscScalar vscale,vshift; 52*d52ab7bdSBarry Smith }; 53*d52ab7bdSBarry Smith 54*d52ab7bdSBarry Smith EXTERN PetscFList MatMFFDPetscFList; 55*d52ab7bdSBarry Smith EXTERN PetscTruth MatMFFDRegisterAllCalled; 56*d52ab7bdSBarry Smith 57*d52ab7bdSBarry Smith #endif 58