Actual source code: gmresimpl.h
1: /*
2: Private data structure used by the GMRES method. This data structure
3: must be identical to the beginning of the KSP_FGMRES data structure
4: so if you CHANGE anything here you must also change it there.
5: */
6: #ifndef PETSC_GMRESIMPL_H
7: #define PETSC_GMRESIMPL_H
9: #include <petsc/private/kspimpl.h>
11: #define KSPGMRESHEADER \
12: /* Hessenberg matrix and orthogonalization information. */ \
13: PetscScalar *hh_origin; /* holds hessenburg matrix that has been multiplied by plane rotations (upper tri) */ \
14: PetscScalar *hes_origin; /* holds the original (unmodified) hessenberg matrix which may be used to estimate the Singular Values of the matrix */ \
15: PetscScalar *hes_ritz; /* holds the last full Hessenberg matrix to compute (harmonic) Ritz pairs */ \
16: PetscScalar *cc_origin; /* holds cosines for rotation matrices */ \
17: PetscScalar *ss_origin; /* holds sines for rotation matrices */ \
18: PetscScalar *rs_origin; /* holds the right-hand-side of the Hessenberg system */ \
19: \
20: PetscScalar *orthogwork; /* holds dot products computed in orthogonalization */ \
21: \
22: /* Work space for computing eigenvalues/singular values */ \
23: PetscReal *Dsvd; \
24: PetscScalar *Rsvd; \
25: \
26: PetscReal haptol; /* tolerance for happy ending */ \
27: PetscInt max_k; /* number of vectors in Krylov space, restart size */ \
28: PetscInt nextra_vecs; /* number of extra vecs needed, e.g. for a pipeline */ \
29: \
30: PetscErrorCode (*orthog)(KSP, PetscInt); \
31: KSPGMRESCGSRefinementType cgstype; \
32: \
33: Vec *vecs; /* the work vectors */ \
34: Vec *vecb; /* holds the last full basis vectors of the Krylov subspace to compute (harmonic) Ritz pairs */ \
35: PetscInt q_preallocate; /* 0=don't preallocate space for work vectors */ \
36: PetscInt delta_allocate; /* number of vectors to preallocaate in each block if not preallocated */ \
37: PetscInt vv_allocated; /* number of allocated gmres direction vectors */ \
38: PetscInt vecs_allocated; /* total number of vecs available */ \
39: /* Since we may call the user "obtain_work_vectors" several times, we have to keep track of the pointers that it has returned */ \
40: Vec **user_work; \
41: PetscInt *mwork_alloc; /* Number of work vectors allocated as part of a work-vector chunk */ \
42: PetscInt nwork_alloc; /* Number of work vector chunks allocated */ \
43: \
44: /* Information for building solution */ \
45: PetscInt it; /* Current iteration: inside restart */ \
46: PetscInt fullcycle; /* Current number of complete cycle */ \
47: PetscScalar *nrs; /* temp that holds the coefficients of the Krylov vectors that form the minimum residual solution */ \
48: Vec sol_temp; /* used to hold temporary solution */ \
49: PetscReal rnorm0; /* residual norm at beginning of the GMRESCycle */ \
50: PetscReal breakdowntol; /* A relative tolerance is used for breakdown check in GMRESCycle */
52: typedef struct {
53: KSPGMRESHEADER
54: } KSP_GMRES;
56: PETSC_INTERN PetscErrorCode KSPView_GMRES(KSP, PetscViewer);
57: PETSC_INTERN PetscErrorCode KSPSetUp_GMRES(KSP);
58: PETSC_INTERN PetscErrorCode KSPSetFromOptions_GMRES(KSP, PetscOptionItems *PetscOptionsObject);
59: PETSC_INTERN PetscErrorCode KSPComputeExtremeSingularValues_GMRES(KSP, PetscReal *, PetscReal *);
60: PETSC_INTERN PetscErrorCode KSPComputeEigenvalues_GMRES(KSP, PetscInt, PetscReal *, PetscReal *, PetscInt *);
61: PETSC_INTERN PetscErrorCode KSPComputeRitz_GMRES(KSP, PetscBool, PetscBool, PetscInt *, Vec[], PetscReal *, PetscReal *);
62: PETSC_INTERN PetscErrorCode KSPReset_GMRES(KSP);
63: PETSC_INTERN PetscErrorCode KSPDestroy_GMRES(KSP);
64: PETSC_INTERN PetscErrorCode KSPGMRESGetNewVectors(KSP, PetscInt);
66: typedef PetscErrorCode (*FCN)(KSP, PetscInt); /* force argument to next function to not be extern C*/
68: PETSC_INTERN PetscErrorCode KSPGMRESSetHapTol_GMRES(KSP, PetscReal);
69: PETSC_INTERN PetscErrorCode KSPGMRESSetPreAllocateVectors_GMRES(KSP);
70: PETSC_INTERN PetscErrorCode KSPGMRESSetRestart_GMRES(KSP, PetscInt);
71: PETSC_INTERN PetscErrorCode KSPGMRESGetRestart_GMRES(KSP, PetscInt *);
72: PETSC_INTERN PetscErrorCode KSPGMRESSetOrthogonalization_GMRES(KSP, FCN);
73: PETSC_INTERN PetscErrorCode KSPGMRESGetOrthogonalization_GMRES(KSP, FCN *);
74: PETSC_INTERN PetscErrorCode KSPGMRESSetCGSRefinementType_GMRES(KSP, KSPGMRESCGSRefinementType);
75: PETSC_INTERN PetscErrorCode KSPGMRESGetCGSRefinementType_GMRES(KSP, KSPGMRESCGSRefinementType *);
77: /* These macros are guarded because they are redefined by derived implementations */
78: #if !defined(KSPGMRES_NO_MACROS)
79: #define HH(a, b) (gmres->hh_origin + (b) * (gmres->max_k + 2) + (a))
80: #define HES(a, b) (gmres->hes_origin + (b) * (gmres->max_k + 1) + (a))
81: #define CC(a) (gmres->cc_origin + (a))
82: #define SS(a) (gmres->ss_origin + (a))
83: #define GRS(a) (gmres->rs_origin + (a))
85: /* vector names */
86: #define VEC_OFFSET 2
87: #define VEC_TEMP gmres->vecs[0]
88: #define VEC_TEMP_MATOP gmres->vecs[1]
89: #define VEC_VV(i) gmres->vecs[VEC_OFFSET + i]
90: #endif
92: #endif // PETSC_GMRESIMPL_H