Actual source code: lmvm.h

      1: #pragma once
      2: #include <petscksp.h>
      3: #include <petsc/private/matimpl.h>
      4: #include <petsc/private/vecimpl.h>

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

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

     17: typedef struct _MatOps_LMVM *MatOps_LMVM;
     18: struct _MatOps_LMVM {
     19:   PetscErrorCode (*update)(Mat, Vec, Vec);
     20:   PetscErrorCode (*allocate)(Mat, Vec, Vec);
     21:   PetscErrorCode (*reset)(Mat, PetscBool);
     22:   PetscErrorCode (*mult)(Mat, Vec, Vec);
     23:   PetscErrorCode (*solve)(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(Mat, PetscOptionItems *PetscOptionsObject);
     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: PETSC_EXTERN PetscErrorCode MatCreate_LMVMDFP(Mat);
     69: PETSC_EXTERN PetscErrorCode MatCreate_LMVMDDFP(Mat);
     70: PETSC_EXTERN PetscErrorCode MatCreate_LMVMBFGS(Mat);
     71: PETSC_EXTERN PetscErrorCode MatCreate_LMVMDBFGS(Mat);
     72: PETSC_EXTERN PetscErrorCode MatCreate_LMVMDQN(Mat);
     73: PETSC_EXTERN PetscErrorCode MatCreate_LMVMSR1(Mat);
     74: PETSC_EXTERN PetscErrorCode MatCreate_LMVMBrdn(Mat);
     75: PETSC_EXTERN PetscErrorCode MatCreate_LMVMBadBrdn(Mat);
     76: PETSC_EXTERN PetscErrorCode MatCreate_LMVMSymBrdn(Mat);
     77: PETSC_EXTERN PetscErrorCode MatCreate_LMVMSymBadBrdn(Mat);
     78: PETSC_EXTERN PetscErrorCode MatCreate_LMVMDiagBrdn(Mat);

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

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