Actual source code: lmvm.h
petsc-3.11.4 2019-09-28
3: #include <petscksp.h>
4: #include <petsc/private/matimpl.h>
5: #include <petsc/private/vecimpl.h>
8: /*
9: MATLMVM format - a base matrix-type that represents Limited-Memory
10: Variable Metric (LMVM) approximations of a Jacobian.
11:
12: LMVM approximations can be symmetric, symmetric positive-definite,
13: rectangular, or otherwise square with no determinable properties.
14: Each derived LMVM type should automatically set its matrix properties
15: if its construction can guarantee symmetry (MAT_SYMMETRIC) or symmetric
16: positive-definiteness (MAT_SPD).
17: */
19: typedef struct _MatOps_LMVM *MatOps_LMVM;
20: struct _MatOps_LMVM {
21: PetscErrorCode (*update)(Mat,Vec,Vec);
22: PetscErrorCode (*allocate)(Mat,Vec,Vec);
23: PetscErrorCode (*reset)(Mat,PetscBool);
24: PetscErrorCode (*mult)(Mat,Vec,Vec);
25: PetscErrorCode (*copy)(Mat,Mat,MatStructure);
26: };
28: typedef struct {
29: /* Core data structures for stored updates */
30: PETSCHEADER(struct _MatOps_LMVM);
31: PetscBool allocated, prev_set;
32: PetscInt m, k, nupdates, nrejects, nresets;
33: Vec *S, *Y;
34: Vec Xprev, Fprev;
35:
36: /* User-defined initial Jacobian tools */
37: PetscBool user_pc, user_ksp, user_scale;
38: PetscReal ksp_rtol, ksp_atol;
39: PetscInt ksp_max_it;
40: PetscReal J0scalar;
41: Vec J0diag;
42: Mat J0;
43: PC J0pc;
44: KSP J0ksp;
45:
46: /* Data structures to support common Mat functions */
47: PetscReal shift;
48:
49: /* Miscellenous parameters */
50: PetscBool square; /* flag for defining the LMVM approximation as a square matrix */
51: PetscReal eps; /* (default: PetscPowReal(PETSC_MACHINE_EPSILON, 2.0/3.0)) */
52: void *ctx; /* implementation specific context */
53: } Mat_LMVM;
55: /* Shared internal functions for LMVM matrices */
56: PETSC_INTERN PetscErrorCode MatUpdateKernel_LMVM(Mat, Vec, Vec);
57: PETSC_INTERN PetscErrorCode MatUpdate_LMVM(Mat, Vec, Vec);
58: PETSC_INTERN PetscErrorCode MatAllocate_LMVM(Mat, Vec, Vec);
59: PETSC_INTERN PetscErrorCode MatReset_LMVM(Mat, PetscBool);
61: /* LMVM implementations of core Mat functionality */
62: PETSC_INTERN PetscErrorCode MatSetFromOptions_LMVM(PetscOptionItems *PetscOptionsObject, Mat);
63: PETSC_INTERN PetscErrorCode MatSetUp_LMVM(Mat);
64: PETSC_INTERN PetscErrorCode MatView_LMVM(Mat, PetscViewer);
65: PETSC_INTERN PetscErrorCode MatDestroy_LMVM(Mat);
66: PETSC_INTERN PetscErrorCode MatCreate_LMVM(Mat);
68: /* Create functions for derived LMVM types
69: NOTE: MatCreateXYZ() declarations for subtypes live under petsctao.h */
70: PETSC_EXTERN PetscErrorCode MatCreate_LMVMDFP(Mat);
71: PETSC_EXTERN PetscErrorCode MatCreate_LMVMBFGS(Mat);
72: PETSC_EXTERN PetscErrorCode MatCreate_LMVMSR1(Mat);
73: PETSC_EXTERN PetscErrorCode MatCreate_LMVMBrdn(Mat);
74: PETSC_EXTERN PetscErrorCode MatCreate_LMVMBadBrdn(Mat);
75: PETSC_EXTERN PetscErrorCode MatCreate_LMVMSymBrdn(Mat);
76: PETSC_EXTERN PetscErrorCode MatCreate_LMVMSymBadBrdn(Mat);
77: PETSC_EXTERN PetscErrorCode MatCreate_LMVMDiagBrdn(Mat);
79: /* Solve functions for derived LMVM types (necessary only for DFP and BFGS for re-use under SymBrdn) */
80: PETSC_INTERN PetscErrorCode MatSolve_LMVMDFP(Mat, Vec, Vec);
81: PETSC_INTERN PetscErrorCode MatSolve_LMVMBFGS(Mat, Vec, Vec);
83: /* Mult functions for derived LMVM types (necessary only for DFP and BFGS for re-use under SymBrdn) */
84: PETSC_INTERN PetscErrorCode MatMult_LMVMDFP(Mat, Vec, Vec);
85: PETSC_INTERN PetscErrorCode MatMult_LMVMBFGS(Mat, Vec, Vec);
87: #endif