Actual source code: snesngmres.h
1: #pragma once
3: #include <petsc/private/snesimpl.h>
5: /* Data structure for the Nonlinear GMRES method. */
6: typedef struct {
7: /* Solver parameters and counters */
8: PetscInt msize; /* maximum size of krylov space */
9: PetscInt restart_it; /* number of iterations the restart conditions persist before restart */
10: PetscViewer monitor; /* debugging output for NGMRES */
11: PetscInt restart_periodic; /* number of iterations to restart after */
13: SNESNGMRESRestartType restart_type;
14: SNESNGMRESSelectType select_type;
16: /* History and subspace data */
17: Vec *Fdot; /* residual history -- length msize */
18: Vec *Xdot; /* solution history -- length msize */
19: PetscReal *fnorms; /* the residual norm history */
20: PetscReal *xnorms; /* the solution norm history */
22: /* General minimization problem context */
23: PetscScalar *h; /* the constraint matrix */
24: PetscScalar *beta; /* rhs for the minimization problem */
25: PetscScalar *xi; /* the dot-product of the current and previous res. */
27: /* Line searches */
28: SNESLineSearch additive_linesearch; /* Line search for the additive variant */
29: PetscReal descent_ls_test; /* restart GMRES when X_A -X_M is not a descent direction */
31: /* Selection constants */
32: PetscBool candidate; /* use candidate storage approach */
33: PetscBool approxfunc; /* approximate the function rather than recomputing it */
34: PetscReal gammaA; /* Criterion A residual tolerance */
35: PetscReal epsilonB; /* Criterion B difference tolerance */
36: PetscReal deltaB; /* Criterion B residual tolerance */
37: PetscReal gammaC; /* Restart residual tolerance */
38: PetscBool restart_fm_rise; /* Restart on F_M residual increase */
40: PetscReal andersonBeta; /* Relaxation parameter for Anderson Mixing */
42: // Window of stored iterates that the least-squares problem uses
43: PetscInt window_size; /* maximum number of stored iterates in the window, at most msize */
44: PetscInt window_size_initial; /* initial window size of the adaptive strategy */
45: PetscBool adaptive; /* grow the window when theta predicts the residual reduction */
46: PetscReal adaptive_tol; /* tolerance on |theta - ||F_{k+1}|| / ||F_k||| that grows the window */
47: PetscReal lsnorm; /* least-squares objective, the norm of the minimized combination of residuals */
48: PetscReal theta; /* least-squares objective divided by the residual norm ||F_k|| of the current iterate */
49: PetscReal gamma; /* least-squares objective divided by the residual norm of the candidate solution */
50: PetscInt *window; /* history indices of the iterates in the window, in increasing order */
51: Vec *Fwindow; /* array of references to the residuals in the window, not new Vec objects */
52: Vec *Xwindow; /* array of references to the solutions in the window, not new Vec objects */
54: /* Least squares minimization solve context */
55: PetscScalar *q; /* the matrix formed as q_ij = (rdot_i, rdot_j) */
56: PetscBLASInt m; /* matrix dimension */
57: PetscBLASInt n; /* matrix dimension */
58: PetscBLASInt nrhs; /* the number of right-hand sides */
59: PetscBLASInt lda; /* the padded matrix dimension */
60: PetscBLASInt ldb; /* the padded vector dimension */
61: PetscReal *s; /* the singular values */
62: PetscReal rcond; /* the exit condition */
63: PetscBLASInt rank; /* the effective rank */
64: PetscScalar *work; /* the work vector */
65: PetscReal *rwork; /* the real work vector used for complex */
66: PetscBLASInt lwork; /* the size of the work vector */
68: PetscBool setup_called; /* indicates whether SNESSetUp_NGMRES() has been called */
69: } SNES_NGMRES;
71: #define H(i, j) ngmres->h[(i) * ngmres->msize + (j)]
72: #define Q(i, j) ngmres->q[(i) * ngmres->msize + (j)]
74: /* private functions that are shared components of the methods */
75: PETSC_INTERN PetscErrorCode SNESNGMRESUpdateSubspace_Private(SNES, PetscInt, PetscInt, Vec, PetscReal, Vec);
76: PETSC_INTERN PetscErrorCode SNESNGMRESFormCombinedSolution_Private(SNES, PetscInt, PetscInt, Vec, Vec, PetscReal, Vec, Vec, Vec);
77: PETSC_INTERN PetscErrorCode SNESNGMRESNorms_Private(SNES, PetscInt, Vec, Vec, Vec, Vec, Vec, Vec, Vec, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *);
78: PETSC_INTERN PetscErrorCode SNESNGMRESSelect_Private(SNES, PetscInt, Vec, Vec, PetscReal, PetscReal, PetscReal, PetscReal, Vec, Vec, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, Vec, Vec, Vec, PetscReal *, PetscReal *, PetscReal *);
79: PETSC_INTERN PetscErrorCode SNESNGMRESSelectRestart_Private(SNES, PetscInt, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscBool *);
81: PETSC_INTERN PetscErrorCode SNESNGMRESGetAdditiveLineSearch_Private(SNES, SNESLineSearch *);
82: PETSC_INTERN PetscErrorCode SNESDestroy_NGMRES(SNES);
83: PETSC_INTERN PetscErrorCode SNESReset_NGMRES(SNES);
84: PETSC_INTERN PetscErrorCode SNESSetUp_NGMRES(SNES);
85: PETSC_INTERN PetscErrorCode SNESView_NGMRES(SNES, PetscViewer);