Actual source code: lmvm.h

      3: #include <petscksp.h>
      4: #include <petsc/private/matimpl.h>
      5: #include <petsc/private/vecimpl.h>

      7: /*
      8:   MATLMVM format - a base matrix-type that represents Limited-Memory
      9:   Variable Metric (LMVM) approximations of a Jacobian.

     11:   LMVM approximations can be symmetric, symmetric positive-definite,
     12:   rectangular, or otherwise square with no determinable properties.
     13:   Each derived LMVM type should automatically set its matrix properties
     14:   if its construction can guarantee symmetry (MAT_SYMMETRIC) or symmetric
     15:   positive-definiteness (MAT_SPD).
     16: */

     18: typedef struct _MatOps_LMVM *MatOps_LMVM;
     19: struct _MatOps_LMVM {
     20:   PetscErrorCode (*update)(Mat,Vec,Vec);
     21:   PetscErrorCode (*allocate)(Mat,Vec,Vec);
     22:   PetscErrorCode (*reset)(Mat,PetscBool);
     23:   PetscErrorCode (*mult)(Mat,Vec,Vec);
     24:   PetscErrorCode (*copy)(Mat,Mat,MatStructure);
     25: };

     27: typedef struct {
     28:   /* Core data structures for stored updates */
     29:   PETSCHEADER(struct _MatOps_LMVM);
     30:   PetscBool allocated, prev_set;
     31:   PetscInt m_old, m, k, nupdates, nrejects, nresets;
     32:   Vec *S, *Y;
     33:   Vec Xprev, Fprev;

     35:   /* User-defined initial Jacobian tools */
     36:   PetscBool user_pc, user_ksp, user_scale;
     37:   PetscReal ksp_rtol, ksp_atol;
     38:   PetscInt ksp_max_it;
     39:   PetscReal J0scalar;
     40:   Vec J0diag;
     41:   Mat J0;
     42:   PC J0pc;
     43:   KSP J0ksp;

     45:   /* Data structures to support common Mat functions */
     46:   PetscReal shift;

     48:   /* Miscellenous parameters */
     49:   PetscBool square; /* flag for defining the LMVM approximation as a square matrix */
     50:   PetscReal eps; /* (default: PetscPowReal(PETSC_MACHINE_EPSILON, 2.0/3.0)) */
     51:   void *ctx; /* implementation specific context */
     52: } Mat_LMVM;

     54: /* Shared internal functions for LMVM matrices */
     55: PETSC_INTERN PetscErrorCode MatUpdateKernel_LMVM(Mat, Vec, Vec);
     56: PETSC_INTERN PetscErrorCode MatUpdate_LMVM(Mat, Vec, Vec);
     57: PETSC_INTERN PetscErrorCode MatAllocate_LMVM(Mat, Vec, Vec);
     58: PETSC_INTERN PetscErrorCode MatReset_LMVM(Mat, PetscBool);

     60: /* LMVM implementations of core Mat functionality */
     61: PETSC_INTERN PetscErrorCode MatSetFromOptions_LMVM(PetscOptionItems *PetscOptionsObject, Mat);
     62: PETSC_INTERN PetscErrorCode MatSetUp_LMVM(Mat);
     63: PETSC_INTERN PetscErrorCode MatView_LMVM(Mat, PetscViewer);
     64: PETSC_INTERN PetscErrorCode MatDestroy_LMVM(Mat);
     65: PETSC_INTERN PetscErrorCode MatCreate_LMVM(Mat);

     67: /* Create functions for derived LMVM types
     68:    NOTE: MatCreateXYZ() declarations for subtypes live under petsctao.h */
     69: PETSC_EXTERN PetscErrorCode MatCreate_LMVMDFP(Mat);
     70: PETSC_EXTERN PetscErrorCode MatCreate_LMVMBFGS(Mat);
     71: PETSC_EXTERN PetscErrorCode MatCreate_LMVMSR1(Mat);
     72: PETSC_EXTERN PetscErrorCode MatCreate_LMVMBrdn(Mat);
     73: PETSC_EXTERN PetscErrorCode MatCreate_LMVMBadBrdn(Mat);
     74: PETSC_EXTERN PetscErrorCode MatCreate_LMVMSymBrdn(Mat);
     75: PETSC_EXTERN PetscErrorCode MatCreate_LMVMSymBadBrdn(Mat);
     76: PETSC_EXTERN PetscErrorCode MatCreate_LMVMDiagBrdn(Mat);

     78: /* Solve functions for derived LMVM types (necessary only for DFP and BFGS for re-use under SymBrdn) */
     79: PETSC_INTERN PetscErrorCode MatSolve_LMVMDFP(Mat, Vec, Vec);
     80: PETSC_INTERN PetscErrorCode MatSolve_LMVMBFGS(Mat, Vec, Vec);

     82: /* Mult functions for derived LMVM types (necessary only for DFP and BFGS for re-use under SymBrdn) */
     83: PETSC_INTERN PetscErrorCode MatMult_LMVMDFP(Mat, Vec, Vec);
     84: PETSC_INTERN PetscErrorCode MatMult_LMVMBFGS(Mat, Vec, Vec);

     86: #endif