Actual source code: lmvmmat.h
petsc-3.9.4 2018-09-11
1: #ifndef __LMVMMAT_H
4: #include <petscksp.h>
6: #define MatLMVM_Scale_None 0
7: #define MatLMVM_Scale_Scalar 1
8: #define MatLMVM_Scale_Broyden 2
9: #define MatLMVM_Scale_H0 3
10: #define MatLMVM_Scale_Types 4
12: #define MatLMVM_Rescale_None 0
13: #define MatLMVM_Rescale_Scalar 1
14: #define MatLMVM_Rescale_GL 2
15: #define MatLMVM_Rescale_Types 3
17: #define MatLMVM_Limit_None 0
18: #define MatLMVM_Limit_Average 1
19: #define MatLMVM_Limit_Relative 2
20: #define MatLMVM_Limit_Absolute 3
21: #define MatLMVM_Limit_Types 4
23: #define TAO_ZERO_SAFEGUARD 1e-8
24: #define TAO_INF_SAFEGUARD 1e+8
26: typedef struct{
27: PetscBool allocated;
28: PetscInt lm;
29: PetscReal eps;
30: PetscInt limitType;
31: PetscInt scaleType;
32: PetscInt rScaleType;
34: PetscReal s_alpha; /* Factor for scalar scaling */
35: PetscReal r_alpha; /* Factor on scalar for rescaling diagonal matrix */
36: PetscReal r_beta; /* Factor on diagonal for rescaling diagonal matrix */
37: PetscReal mu; /* Factor for using historical information */
38: PetscReal nu; /* Factor for using historical information */
39: PetscReal phi; /* Factor for Broyden scaling */
41: PetscInt scalar_history; /* Amount of history to keep for scalar scaling */
42: PetscReal *yy_history; /* Past information for scalar scaling */
43: PetscReal *ys_history; /* Past information for scalar scaling */
44: PetscReal *ss_history; /* Past information for scalar scaling */
46: PetscInt rescale_history; /* Amount of history to keep for rescaling diagonal */
47: PetscReal *yy_rhistory; /* Past information for scalar rescaling */
48: PetscReal *ys_rhistory; /* Past information for scalar rescaling */
49: PetscReal *ss_rhistory; /* Past information for scalar rescaling */
51: PetscReal delta_max; /* Maximum value for delta */
52: PetscReal delta_min; /* Minimum value for delta */
54: PetscInt lmnow;
55: PetscInt iter;
56: PetscInt nupdates;
57: PetscInt nrejects;
59: Vec *S;
60: Vec *Y;
61: Vec Gprev;
62: Vec Xprev;
64: Vec D;
65: Vec U;
66: Vec V;
67: Vec W;
68: Vec P;
69: Vec Q;
71: PetscReal delta;
72: PetscReal sigma;
73: PetscReal theta;
74: PetscReal *rho;
75: PetscReal *beta;
77: PetscBool useDefaultH0;
78: Mat H0_mat;
79: KSP H0_ksp;
80: Vec H0_norm;
82: PetscBool useScale;
83: Vec scale;
84:
85: PetscBool recycle;
87: } MatLMVMCtx;
89: PETSC_EXTERN PetscErrorCode MatCreateLMVM(MPI_Comm,PetscInt,PetscInt,Mat*);
91: /* PETSc Mat overrides */
92: PETSC_EXTERN PetscErrorCode MatView_LMVM(Mat, PetscViewer);
93: PETSC_EXTERN PetscErrorCode MatDestroy_LMVM(Mat);
95: /*
96: int MatMultTranspose_LMVM(Mat,Vec,Vec);
97: int MatDiagonalShift_LMVM(Vec,Mat);
98: int MatDestroy_LMVM(Mat);
99: int MatShift_LMVM(Mat,PetscReal);
100: int MatDuplicate_LMVM(Mat,MatDuplicateOption,Mat*);
101: int MatEqual_LMVM(Mat,Mat,PetscBool*);
102: int MatScale_LMVM(Mat,PetscReal);
103: int MatGetCreateMatrix_LMVM(Mat,IS,IS,int,MatReuse,Mat *);
104: int MatCreateSubMatrices_LMVM(Mat,int,IS*,IS*,MatReuse,Mat**);
105: int MatTranspose_LMVM(Mat,Mat*);
106: int MatGetDiagonal_LMVM(Mat,Vec);
107: int MatGetColumnVector_LMVM(Mat,Vec, int);
108: int MatNorm_LMVM(Mat,NormType,PetscReal *);
109: */
111: /* Functions used by TAO */
112: PETSC_EXTERN PetscErrorCode MatLMVMReset(Mat);
113: PETSC_EXTERN PetscErrorCode MatLMVMGetUpdates(Mat, PetscInt *);
114: PETSC_EXTERN PetscErrorCode MatLMVMSetRecycleFlag(Mat, PetscBool);
115: PETSC_EXTERN PetscErrorCode MatLMVMGetRecycleFlag(Mat, PetscBool *);
116: PETSC_EXTERN PetscErrorCode MatLMVMUpdate(Mat, Vec, Vec);
117: PETSC_EXTERN PetscErrorCode MatLMVMSetDelta(Mat, PetscReal);
118: PETSC_EXTERN PetscErrorCode MatLMVMSetScale(Mat, Vec);
119: PETSC_EXTERN PetscErrorCode MatLMVMGetRejects(Mat, PetscInt *);
120: PETSC_EXTERN PetscErrorCode MatLMVMSetH0(Mat, Mat);
121: PETSC_EXTERN PetscErrorCode MatLMVMGetH0(Mat, Mat *);
122: PETSC_EXTERN PetscErrorCode MatLMVMGetH0KSP(Mat, KSP *);
123: PETSC_EXTERN PetscErrorCode MatLMVMSetPrev(Mat, Vec, Vec);
124: PETSC_EXTERN PetscErrorCode MatLMVMGetX0(Mat, Vec);
125: PETSC_EXTERN PetscErrorCode MatLMVMRefine(Mat, Mat, Vec, Vec);
126: PETSC_EXTERN PetscErrorCode MatLMVMAllocateVectors(Mat m, Vec v);
127: PETSC_EXTERN PetscErrorCode MatLMVMSolve(Mat, Vec, Vec);
129: #endif