Actual source code: petscksp.h

  1: /*
  2:    Defines the interface functions for the Krylov subspace accelerators.
  3: */
  4: #pragma once

  6: #include <petscpc.h>

  8: /* SUBMANSEC = KSP */

 10: PETSC_EXTERN PetscErrorCode KSPInitializePackage(void);
 11: PETSC_EXTERN PetscErrorCode KSPFinalizePackage(void);

 13: /*S
 14:    KSP - Abstract PETSc object that manages the linear solves in PETSc (even those such as direct factorization-based solvers that
 15:          do not use Krylov accelerators).

 17:    Level: beginner

 19:    Notes:
 20:    When a direct solver is used, but no Krylov solver is used, the `KSP` object is still used but with a
 21:    `KSPType` of `KSPPREONLY` (or equivalently `KSPNONE`), meaning that only application of the preconditioner is used as the linear solver.

 23:    Use `KSPSetType()` or the options database key `-ksp_type` to set the specific Krylov solver algorithm to use with a given `KSP` object

 25:    The `PC` object is used to control preconditioners in PETSc.

 27:   `KSP` can also be used to solve some least squares problems (over or under-determined linear systems), using, for example, `KSPLSQR`, see `PETSCREGRESSORLINEAR`
 28:   for additional methods that can be used to solve least squares problems and other linear regressions).

 30: .seealso: [](doc_linsolve), [](ch_ksp), `KSPCreate()`, `KSPSetType()`, `KSPType`, `SNES`, `TS`, `PC`, `KSP`, `KSPDestroy()`, `KSPCG`, `KSPGMRES`
 31: S*/
 32: typedef struct _p_KSP *KSP;

 34: /*J
 35:    KSPType - String with the name of a PETSc Krylov method. These are all the Krylov solvers that PETSc provides.

 37:    Level: beginner

 39: .seealso: [](doc_linsolve), [](ch_ksp), `KSPSetType()`, `KSP`, `KSPRegister()`, `KSPCreate()`, `KSPSetFromOptions()`
 40: J*/
 41: typedef const char *KSPType;
 42: #define KSPRICHARDSON "richardson"
 43: #define KSPCHEBYSHEV  "chebyshev"
 44: #define KSPCG         "cg"
 45: #define KSPGROPPCG    "groppcg"
 46: #define KSPPIPECG     "pipecg"
 47: #define KSPPIPECGRR   "pipecgrr"
 48: #define KSPPIPELCG    "pipelcg"
 49: #define KSPPIPEPRCG   "pipeprcg"
 50: #define KSPPIPECG2    "pipecg2"
 51: #define KSPCGNE       "cgne"
 52: #define KSPNASH       "nash"
 53: #define KSPSTCG       "stcg"
 54: #define KSPGLTR       "gltr"
 55: #define KSPCGNASH     PETSC_DEPRECATED_MACRO(3, 11, 0, "KSPNASH", ) "nash"
 56: #define KSPCGSTCG     PETSC_DEPRECATED_MACRO(3, 11, 0, "KSPSTCG", ) "stcg"
 57: #define KSPCGGLTR     PETSC_DEPRECATED_MACRO(3, 11, 0, "KSPSGLTR", ) "gltr"
 58: #define KSPFCG        "fcg"
 59: #define KSPPIPEFCG    "pipefcg"
 60: #define KSPGMRES      "gmres"
 61: #define KSPPIPEFGMRES "pipefgmres"
 62: #define KSPFGMRES     "fgmres"
 63: #define KSPLGMRES     "lgmres"
 64: #define KSPDGMRES     "dgmres"
 65: #define KSPPGMRES     "pgmres"
 66: #define KSPTCQMR      "tcqmr"
 67: #define KSPBCGS       "bcgs"
 68: #define KSPIBCGS      "ibcgs"
 69: #define KSPQMRCGS     "qmrcgs"
 70: #define KSPFBCGS      "fbcgs"
 71: #define KSPFBCGSR     "fbcgsr"
 72: #define KSPBCGSL      "bcgsl"
 73: #define KSPPIPEBCGS   "pipebcgs"
 74: #define KSPCGS        "cgs"
 75: #define KSPTFQMR      "tfqmr"
 76: #define KSPCR         "cr"
 77: #define KSPPIPECR     "pipecr"
 78: #define KSPLSQR       "lsqr"
 79: #define KSPPREONLY    "preonly"
 80: #define KSPNONE       "none"
 81: #define KSPQCG        "qcg"
 82: #define KSPBICG       "bicg"
 83: #define KSPMINRES     "minres"
 84: #define KSPSYMMLQ     "symmlq"
 85: #define KSPLCD        "lcd"
 86: #define KSPPYTHON     "python"
 87: #define KSPGCR        "gcr"
 88: #define KSPPIPEGCR    "pipegcr"
 89: #define KSPTSIRM      "tsirm"
 90: #define KSPCGLS       "cgls"
 91: #define KSPFETIDP     "fetidp"
 92: #define KSPHPDDM      "hpddm"
 93: #define KSPIDR        "idr"
 94: #define KSPEKSM       "eksm"

 96: /* Logging support */
 97: PETSC_EXTERN PetscClassId KSP_CLASSID;
 98: PETSC_EXTERN PetscClassId KSPGUESS_CLASSID;
 99: PETSC_EXTERN PetscClassId DMKSP_CLASSID;

101: PETSC_EXTERN PetscErrorCode KSPCreate(MPI_Comm, KSP *);
102: PETSC_EXTERN PetscErrorCode KSPSetType(KSP, KSPType);
103: PETSC_EXTERN PetscErrorCode KSPGetType(KSP, KSPType *);
104: PETSC_EXTERN PetscErrorCode KSPSetUp(KSP);
105: PETSC_EXTERN PetscErrorCode KSPSetUpOnBlocks(KSP);
106: PETSC_EXTERN PetscErrorCode KSPSolve(KSP, Vec, Vec);
107: PETSC_EXTERN PetscErrorCode KSPSolveTranspose(KSP, Vec, Vec);
108: PETSC_EXTERN PetscErrorCode KSPSetUseExplicitTranspose(KSP, PetscBool);
109: PETSC_EXTERN PetscErrorCode KSPMatSolve(KSP, Mat, Mat);
110: PETSC_EXTERN PetscErrorCode KSPMatSolveTranspose(KSP, Mat, Mat);
111: PETSC_EXTERN PetscErrorCode KSPSetMatSolveBatchSize(KSP, PetscInt);
112: PETSC_DEPRECATED_FUNCTION(3, 15, 0, "KSPSetMatSolveBatchSize()", ) static inline PetscErrorCode KSPSetMatSolveBlockSize(KSP ksp, PetscInt n)
113: {
114:   return KSPSetMatSolveBatchSize(ksp, n);
115: }
116: PETSC_EXTERN PetscErrorCode KSPGetMatSolveBatchSize(KSP, PetscInt *);
117: PETSC_DEPRECATED_FUNCTION(3, 15, 0, "KSPGetMatSolveBatchSize()", ) static inline PetscErrorCode KSPGetMatSolveBlockSize(KSP ksp, PetscInt *n)
118: {
119:   return KSPGetMatSolveBatchSize(ksp, n);
120: }
121: PETSC_EXTERN PetscErrorCode KSPReset(KSP);
122: PETSC_EXTERN PetscErrorCode KSPResetViewers(KSP);
123: PETSC_EXTERN PetscErrorCode KSPDestroy(KSP *);
124: PETSC_EXTERN PetscErrorCode KSPSetReusePreconditioner(KSP, PetscBool);
125: PETSC_EXTERN PetscErrorCode KSPGetReusePreconditioner(KSP, PetscBool *);
126: PETSC_EXTERN PetscErrorCode KSPSetSkipPCSetFromOptions(KSP, PetscBool);
127: PETSC_EXTERN PetscErrorCode KSPCheckSolve(KSP, PC, Vec);
128: PETSC_EXTERN PetscErrorCode KSPCheckMatSolve(KSP, PC, Mat);

130: PETSC_EXTERN PetscFunctionList KSPList;
131: PETSC_EXTERN PetscFunctionList KSPGuessList;
132: PETSC_EXTERN PetscFunctionList KSPMonitorList;
133: PETSC_EXTERN PetscFunctionList KSPMonitorCreateList;
134: PETSC_EXTERN PetscFunctionList KSPMonitorDestroyList;
135: PETSC_EXTERN PetscErrorCode    KSPRegister(const char[], PetscErrorCode (*)(KSP));

137: /*S
138:   KSPMonitorRegisterFn - A function prototype for functions provided to `KSPMonitorRegister()`

140:   Calling Sequence:
141: + ksp   - iterative solver obtained from `KSPCreate()`
142: . it    - iteration number
143: . rnorm - (estimated) 2-norm of (preconditioned) residual
144: - ctx   - `PetscViewerAndFormat` object

146:   Level: beginner

148:   Note:
149:   This is a `KSPMonitorFn` specialized for a context of `PetscViewerAndFormat`

151: .seealso: [](ch_snes), `KSP`, `KSPMonitorSet()`, `KSPMonitorRegister()`, `KSPMonitorFn`, `KSPMonitorRegisterCreateFn`, `KSPMonitorRegisterDestroyFn`
152: S*/
153: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPMonitorRegisterFn(KSP ksp, PetscInt it, PetscReal rnorm, PetscViewerAndFormat *ctx);

155: /*S
156:   KSPMonitorRegisterCreateFn - A function prototype for functions that do the creation when provided to `KSPMonitorRegister()`

158:   Calling Sequence:
159: + viewer - the viewer to be used with the `KSPMonitorRegisterFn`
160: . format - the format of the viewer
161: . ctx    - a context for the monitor
162: - result - a `PetscViewerAndFormat` object

164:   Level: beginner

166: .seealso: [](ch_snes), `KSPMonitorRegisterFn`, `KSP`, `KSPMonitorSet()`, `KSPMonitorRegister()`, `KSPMonitorFn`, `KSPMonitorRegisterDestroyFn`
167: S*/
168: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPMonitorRegisterCreateFn(PetscViewer viewer, PetscViewerFormat format, PetscCtx ctx, PetscViewerAndFormat **result);

170: /*S
171:   KSPMonitorRegisterDestroyFn - A function prototype for functions that do the after use destruction when provided to `KSPMonitorRegister()`

173:   Calling Sequence:
174: . vf - a `PetscViewerAndFormat` object to be destroyed, including any context

176:   Level: beginner

178: .seealso: [](ch_snes), `KSPMonitorRegisterFn`, `KSP`, `KSPMonitorSet()`, `KSPMonitorRegister()`, `KSPMonitorFn`, `KSPMonitorRegisterCreateFn`
179: S*/
180: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPMonitorRegisterDestroyFn(PetscViewerAndFormat **result);

182: PETSC_EXTERN PetscErrorCode KSPMonitorRegister(const char[], PetscViewerType, PetscViewerFormat, KSPMonitorRegisterFn *, KSPMonitorRegisterCreateFn *, KSPMonitorRegisterDestroyFn *);

184: PETSC_EXTERN PetscErrorCode KSPSetPCSide(KSP, PCSide);
185: PETSC_EXTERN PetscErrorCode KSPGetPCSide(KSP, PCSide *);
186: PETSC_EXTERN PetscErrorCode KSPSetTolerances(KSP, PetscReal, PetscReal, PetscReal, PetscInt);
187: PETSC_EXTERN PetscErrorCode KSPGetTolerances(KSP, PetscReal *, PetscReal *, PetscReal *, PetscInt *);
188: PETSC_EXTERN PetscErrorCode KSPSetMinimumIterations(KSP, PetscInt);
189: PETSC_EXTERN PetscErrorCode KSPGetMinimumIterations(KSP, PetscInt *);
190: PETSC_EXTERN PetscErrorCode KSPSetInitialGuessNonzero(KSP, PetscBool);
191: PETSC_EXTERN PetscErrorCode KSPGetInitialGuessNonzero(KSP, PetscBool *);
192: PETSC_EXTERN PetscErrorCode KSPSetErrorIfNotConverged(KSP, PetscBool);
193: PETSC_EXTERN PetscErrorCode KSPGetErrorIfNotConverged(KSP, PetscBool *);
194: PETSC_EXTERN PetscErrorCode KSPSetComputeEigenvalues(KSP, PetscBool);
195: PETSC_EXTERN PetscErrorCode KSPSetComputeRitz(KSP, PetscBool);
196: PETSC_EXTERN PetscErrorCode KSPGetComputeEigenvalues(KSP, PetscBool *);
197: PETSC_EXTERN PetscErrorCode KSPSetComputeSingularValues(KSP, PetscBool);
198: PETSC_EXTERN PetscErrorCode KSPGetComputeSingularValues(KSP, PetscBool *);
199: PETSC_EXTERN PetscErrorCode KSPGetRhs(KSP, Vec *);
200: PETSC_EXTERN PetscErrorCode KSPGetSolution(KSP, Vec *);
201: PETSC_EXTERN PetscErrorCode KSPGetResidualNorm(KSP, PetscReal *);
202: PETSC_EXTERN PetscErrorCode KSPGetIterationNumber(KSP, PetscInt *);
203: PETSC_EXTERN PetscErrorCode KSPGetTotalIterations(KSP, PetscInt *);
204: PETSC_EXTERN PetscErrorCode KSPCreateVecs(KSP, PetscInt, Vec **, PetscInt, Vec **);
205: PETSC_DEPRECATED_FUNCTION(3, 6, 0, "KSPCreateVecs()", ) static inline PetscErrorCode KSPGetVecs(KSP ksp, PetscInt n, Vec **x, PetscInt m, Vec **y)
206: {
207:   return KSPCreateVecs(ksp, n, x, m, y);
208: }

210: /*S
211:   KSPPSolveFn - A function prototype for functions provided to `KSPSetPreSolve()` and `KSPSetPostSolve()`

213:   Calling Sequence:
214: + ksp - the `KSP` context
215: . rhs - the right-hand side vector
216: . x   - the solution vector
217: - ctx - optional context that was provided with `KSPSetPreSolve()` or `KSPSetPostSolve()`

219:   Level: intermediate

221: .seealso: [](ch_snes), `KSP`, `KSPSetPreSolve()`, `KSPSetPostSolve()`, `PCShellPSolveFn`
222: S*/
223: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPPSolveFn(KSP ksp, Vec rhs, Vec x, PetscCtx ctx);

225: PETSC_EXTERN PetscErrorCode KSPSetPreSolve(KSP, KSPPSolveFn *, PetscCtx);
226: PETSC_EXTERN PetscErrorCode KSPSetPostSolve(KSP, KSPPSolveFn *, PetscCtx);
227: PETSC_EXTERN PetscErrorCode KSPPreSolve(KSP, Vec, Vec);
228: PETSC_EXTERN PetscErrorCode KSPPostSolve(KSP, Vec, Vec);

230: PETSC_EXTERN PetscErrorCode KSPSetPC(KSP, PC);
231: PETSC_EXTERN PetscErrorCode KSPGetPC(KSP, PC *);
232: PETSC_EXTERN PetscErrorCode KSPSetNestLevel(KSP, PetscInt);
233: PETSC_EXTERN PetscErrorCode KSPGetNestLevel(KSP, PetscInt *);

235: /*S
236:   KSPMonitorFn - A function prototype for functions provided to `KSPMonitorSet()`

238:   Calling Sequence:
239: + ksp   - iterative solver obtained from `KSPCreate()`
240: . it    - iteration number
241: . rnorm - (estimated) 2-norm of (preconditioned) residual
242: - ctx   - optional monitoring context, as provided with `KSPMonitorSet()`

244:   Level: beginner

246: .seealso: [](ch_snes), `KSP`, `KSPMonitorSet()`
247: S*/
248: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPMonitorFn(KSP ksp, PetscInt it, PetscReal rnorm, PetscCtx ctx);

250: PETSC_EXTERN PetscErrorCode KSPMonitor(KSP, PetscInt, PetscReal);
251: PETSC_EXTERN PetscErrorCode KSPMonitorSet(KSP, KSPMonitorFn *, PetscCtx, PetscCtxDestroyFn *);
252: PETSC_EXTERN PetscErrorCode KSPMonitorCancel(KSP);
253: PETSC_EXTERN PetscErrorCode KSPGetMonitorContext(KSP, PetscCtxRt);
254: PETSC_EXTERN PetscErrorCode KSPGetResidualHistory(KSP, const PetscReal *[], PetscInt *);
255: PETSC_EXTERN PetscErrorCode KSPSetResidualHistory(KSP, PetscReal[], PetscCount, PetscBool);
256: PETSC_EXTERN PetscErrorCode KSPGetErrorHistory(KSP, const PetscReal *[], PetscInt *);
257: PETSC_EXTERN PetscErrorCode KSPSetErrorHistory(KSP, PetscReal[], PetscCount, PetscBool);

259: PETSC_EXTERN PetscErrorCode KSPBuildSolutionDefault(KSP, Vec, Vec *);
260: PETSC_EXTERN PetscErrorCode KSPBuildSolutionFlexibleDefault(KSP, Vec, Vec *);
261: PETSC_EXTERN PetscErrorCode KSPBuildResidualDefault(KSP, Vec, Vec, Vec *);
262: PETSC_EXTERN PetscErrorCode KSPDestroyDefault(KSP);
263: PETSC_EXTERN PetscErrorCode KSPSetWorkVecs(KSP, PetscInt);

265: PETSC_EXTERN PetscErrorCode PCKSPGetKSP(PC, KSP *);
266: PETSC_EXTERN PetscErrorCode PCKSPSetKSP(PC, KSP);
267: PETSC_EXTERN PetscErrorCode PCBJacobiGetSubKSP(PC, PetscInt *, PetscInt *, KSP *[]);
268: PETSC_EXTERN PetscErrorCode PCASMGetSubKSP(PC, PetscInt *, PetscInt *, KSP *[]);
269: PETSC_EXTERN PetscErrorCode PCGASMGetSubKSP(PC, PetscInt *, PetscInt *, KSP *[]);
270: PETSC_EXTERN PetscErrorCode PCPatchGetSubKSP(PC, PetscInt *, KSP *[]);
271: PETSC_EXTERN PetscErrorCode PCFieldSplitGetSubKSP(PC, PetscInt *, KSP *[]);
272: PETSC_EXTERN PetscErrorCode PCFieldSplitSchurGetSubKSP(PC, PetscInt *, KSP *[]);
273: PETSC_EXTERN PetscErrorCode PCMGGetSmoother(PC, PetscInt, KSP *);
274: PETSC_EXTERN PetscErrorCode PCMGGetSmootherDown(PC, PetscInt, KSP *);
275: PETSC_EXTERN PetscErrorCode PCMGGetSmootherUp(PC, PetscInt, KSP *);
276: PETSC_EXTERN PetscErrorCode PCMGGetCoarseSolve(PC, KSP *);
277: PETSC_EXTERN PetscErrorCode PCGalerkinGetKSP(PC, KSP *);
278: PETSC_EXTERN PetscErrorCode PCDeflationGetCoarseKSP(PC, KSP *);

280: /*S
281:   PCMGCoarseSpaceConstructorFn - A function prototype for functions registered with `PCMGRegisterCoarseSpaceConstructor()`

283:   Calling Sequence:
284: + pc        - The `PC` object
285: . l         - The multigrid level, 0 is the coarse level
286: . dm        - The `DM` for this level
287: . smooth    - The level smoother
288: . Nc        - The size of the coarse space
289: . initGuess - Basis for an initial guess for the space
290: - coarseSp  - A basis for the computed coarse space

292:   Level: beginner

294: .seealso: [](ch_ksp), `PCMGRegisterCoarseSpaceConstructor()`, `PCMGGetCoarseSpaceConstructor()`
295: S*/
296: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode PCMGCoarseSpaceConstructorFn(PC pc, PetscInt l, DM dm, KSP smooth, PetscInt Nc, Mat initGuess, Mat *coarseSp);

298: PETSC_EXTERN PetscFunctionList PCMGCoarseList;
299: PETSC_EXTERN PetscErrorCode    PCMGRegisterCoarseSpaceConstructor(const char[], PCMGCoarseSpaceConstructorFn *);
300: PETSC_EXTERN PetscErrorCode    PCMGGetCoarseSpaceConstructor(const char[], PCMGCoarseSpaceConstructorFn **);

302: PETSC_EXTERN PetscErrorCode KSPBuildSolution(KSP, Vec, Vec *);
303: PETSC_EXTERN PetscErrorCode KSPBuildResidual(KSP, Vec, Vec, Vec *);

305: /*E
306:   KSPChebyshevKind - Which kind of Chebyshev polynomial to use with `KSPCHEBYSHEV`

308:   Values:
309: + `KSP_CHEBYSHEV_FIRST`      - "classic" first-kind Chebyshev polynomial
310: . `KSP_CHEBYSHEV_FOURTH`     - fourth-kind Chebyshev polynomial
311: - `KSP_CHEBYSHEV_OPT_FOURTH` - optimized fourth-kind Chebyshev polynomial

313:   Level: intermediate

315: .seealso: [](ch_ksp), `KSPCHEBYSHEV`, `KSPChebyshevSetKind()`, `KSPChebyshevGetKind()`
316: E*/
317: typedef enum {
318:   KSP_CHEBYSHEV_FIRST,
319:   KSP_CHEBYSHEV_FOURTH,
320:   KSP_CHEBYSHEV_OPT_FOURTH
321: } KSPChebyshevKind;

323: PETSC_EXTERN PetscErrorCode KSPRichardsonSetScale(KSP, PetscReal);
324: PETSC_EXTERN PetscErrorCode KSPRichardsonSetSelfScale(KSP, PetscBool);
325: PETSC_EXTERN PetscErrorCode KSPChebyshevSetEigenvalues(KSP, PetscReal, PetscReal);
326: PETSC_EXTERN PetscErrorCode KSPChebyshevEstEigSet(KSP, PetscReal, PetscReal, PetscReal, PetscReal);
327: PETSC_EXTERN PetscErrorCode KSPChebyshevEstEigSetUseNoisy(KSP, PetscBool);
328: PETSC_EXTERN PetscErrorCode KSPChebyshevSetKind(KSP, KSPChebyshevKind);
329: PETSC_EXTERN PetscErrorCode KSPChebyshevGetKind(KSP, KSPChebyshevKind *);
330: PETSC_EXTERN PetscErrorCode KSPChebyshevEstEigGetKSP(KSP, KSP *);
331: PETSC_EXTERN PetscErrorCode KSPComputeExtremeSingularValues(KSP, PetscReal *, PetscReal *);
332: PETSC_EXTERN PetscErrorCode KSPComputeEigenvalues(KSP, PetscInt, PetscReal[], PetscReal[], PetscInt *);
333: PETSC_EXTERN PetscErrorCode KSPComputeEigenvaluesExplicitly(KSP, PetscInt, PetscReal[], PetscReal[]);
334: PETSC_EXTERN PetscErrorCode KSPComputeRitz(KSP, PetscBool, PetscBool, PetscInt *, Vec[], PetscReal[], PetscReal[]);

336: /*E
337:   KSPFCDTruncationType - Define how stored directions are used to orthogonalize in flexible conjugate directions (FCD) methods

339:   Values:
340: + `KSP_FCD_TRUNC_TYPE_STANDARD` - uses all (up to `mmax`) stored directions
341: - `KSP_FCD_TRUNC_TYPE_NOTAY`    - uses the last `max(1,mod(i,mmax))` stored directions at iteration i = 0, 1, ...

343:    Level: intermediate

345:   Note:
346:   Function such as `KSPFCGSetMmax()`, `KSPPIPEGCRSetNMax()`, `KSPPIPEGCRSetNMax()`, and `KSPPIPEFCGSetNMax()` may be
347:   used to provide `nmax` or they may be provided with the option database.

349: .seealso: [](ch_ksp), `KSP`, `KSPFCG`, `KSPPIPEFCG`, `KSPPIPEGCR`, `KSPFCGSetTruncationType()`, `KSPFCGGetTruncationType()`,
350:           `KSPPIPEGCRSetTruncationType()`, `KSPPIPEGCRGetTruncationType()`,
351:           `KSPFCGSetMmax()`, `KSPPIPEGCRSetNMax()`, `KSPPIPEGCRGetNMax()`, `KSPPIPEFCGGetNMax()`
352: E*/
353: typedef enum {
354:   KSP_FCD_TRUNC_TYPE_STANDARD,
355:   KSP_FCD_TRUNC_TYPE_NOTAY
356: } KSPFCDTruncationType;
357: PETSC_EXTERN const char *const KSPFCDTruncationTypes[];

359: PETSC_EXTERN PetscErrorCode KSPFCGSetMmax(KSP, PetscInt);
360: PETSC_EXTERN PetscErrorCode KSPFCGGetMmax(KSP, PetscInt *);
361: PETSC_EXTERN PetscErrorCode KSPFCGSetNprealloc(KSP, PetscInt);
362: PETSC_EXTERN PetscErrorCode KSPFCGGetNprealloc(KSP, PetscInt *);
363: PETSC_EXTERN PetscErrorCode KSPFCGSetTruncationType(KSP, KSPFCDTruncationType);
364: PETSC_EXTERN PetscErrorCode KSPFCGGetTruncationType(KSP, KSPFCDTruncationType *);

366: PETSC_EXTERN PetscErrorCode KSPPIPEFCGSetMmax(KSP, PetscInt);
367: PETSC_EXTERN PetscErrorCode KSPPIPEFCGGetMmax(KSP, PetscInt *);
368: PETSC_EXTERN PetscErrorCode KSPPIPEFCGSetNprealloc(KSP, PetscInt);
369: PETSC_EXTERN PetscErrorCode KSPPIPEFCGGetNprealloc(KSP, PetscInt *);
370: PETSC_EXTERN PetscErrorCode KSPPIPEFCGSetTruncationType(KSP, KSPFCDTruncationType);
371: PETSC_EXTERN PetscErrorCode KSPPIPEFCGGetTruncationType(KSP, KSPFCDTruncationType *);

373: PETSC_EXTERN PetscErrorCode KSPPIPEGCRSetMmax(KSP, PetscInt);
374: PETSC_EXTERN PetscErrorCode KSPPIPEGCRGetMmax(KSP, PetscInt *);
375: PETSC_EXTERN PetscErrorCode KSPPIPEGCRSetNprealloc(KSP, PetscInt);
376: PETSC_EXTERN PetscErrorCode KSPPIPEGCRGetNprealloc(KSP, PetscInt *);
377: PETSC_EXTERN PetscErrorCode KSPPIPEGCRSetTruncationType(KSP, KSPFCDTruncationType);
378: PETSC_EXTERN PetscErrorCode KSPPIPEGCRGetTruncationType(KSP, KSPFCDTruncationType *);
379: PETSC_EXTERN PetscErrorCode KSPPIPEGCRSetUnrollW(KSP, PetscBool);
380: PETSC_EXTERN PetscErrorCode KSPPIPEGCRGetUnrollW(KSP, PetscBool *);

382: /*S
383:   KSPFlexibleModifyPCFn - A prototype of a function used to modify the preconditioner during the use of flexible `KSP` methods, such as `KSPFGMRES`

385:   Calling Sequence:
386: + ksp       - the `KSP` context being used.
387: . total_its - the total number of iterations that have occurred.
388: . local_its - the number of iterations since last restart if applicable
389: . res_norm  - the current residual norm
390: - ctx       - optional context variable set with `KSPFlexibleSetModifyPC()`

392:   Level: beginner

394: .seealso: [](ch_ksp), `KSP`, `KSPFlexibleSetModifyPC()`
395: S*/
396: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPFlexibleModifyPCFn(KSP ksp, PetscInt total_its, PetscInt local_its, PetscReal res_norm, PetscCtx ctx);

398: PETSC_EXTERN PetscErrorCode KSPFlexibleSetModifyPC(KSP, KSPFlexibleModifyPCFn *, PetscCtx, PetscCtxDestroyFn *);

400: PETSC_DEPRECATED_FUNCTION(3, 25, 0, "KSPFlexibleSetModifyPC()", ) static inline PetscErrorCode KSPPIPEGCRSetModifyPC(KSP ksp, KSPFlexibleModifyPCFn *fun, PetscCtx ctx, PetscCtxDestroyFn *dfun)
401: {
402:   return KSPFlexibleSetModifyPC(ksp, fun, ctx, dfun);
403: }

405: PETSC_EXTERN PetscErrorCode KSPGMRESSetRestart(KSP, PetscInt);
406: PETSC_EXTERN PetscErrorCode KSPGMRESGetRestart(KSP, PetscInt *);
407: PETSC_EXTERN PetscErrorCode KSPGMRESSetHapTol(KSP, PetscReal);
408: PETSC_EXTERN PetscErrorCode KSPGMRESSetBreakdownTolerance(KSP, PetscReal);

410: PETSC_EXTERN PetscErrorCode KSPGMRESSetVectorAllocationSize(KSP, PetscInt);
411: PETSC_EXTERN PetscErrorCode KSPGMRESSetPreAllocateVectors(KSP);

413: PETSC_EXTERN PetscErrorCode KSPLGMRESSetAugDim(KSP, PetscInt);
414: PETSC_EXTERN PetscErrorCode KSPLGMRESSetConstant(KSP);

416: PETSC_EXTERN PetscErrorCode KSPPIPEFGMRESSetShift(KSP, PetscScalar);

418: PETSC_EXTERN PetscErrorCode KSPGCRSetRestart(KSP, PetscInt);
419: PETSC_EXTERN PetscErrorCode KSPGCRGetRestart(KSP, PetscInt *);

421: PETSC_EXTERN PetscErrorCode KSPIDRSetS(KSP, PetscInt);
422: PETSC_EXTERN PetscErrorCode KSPIDRGetS(KSP, PetscInt *);
423: PETSC_EXTERN PetscErrorCode KSPIDRSetCosine(KSP, PetscReal);
424: PETSC_EXTERN PetscErrorCode KSPIDRGetCosine(KSP, PetscReal *);
425: PETSC_EXTERN PetscErrorCode KSPIDRSetRandom(KSP, PetscRandom);
426: PETSC_EXTERN PetscErrorCode KSPIDRGetRandom(KSP, PetscRandom *);

428: PETSC_EXTERN PetscErrorCode KSPEKSMSetHapTol(KSP, PetscReal);
429: PETSC_EXTERN PetscErrorCode KSPEKSMGetHapTol(KSP, PetscReal *);
430: PETSC_EXTERN PetscErrorCode KSPEKSMSetKSP(KSP, KSP, KSP);
431: PETSC_EXTERN PetscErrorCode KSPEKSMGetKSP(KSP, KSP *, KSP *);
432: PETSC_EXTERN PetscErrorCode KSPEKSMSetShift(KSP, PetscScalar);
433: PETSC_EXTERN PetscErrorCode KSPEKSMGetShift(KSP, PetscScalar *);

435: PETSC_DEPRECATED_FUNCTION(3, 25, 0, "KSPFlexibleSetModifyPC()", ) static inline PetscErrorCode KSPGCRSetModifyPC(KSP ksp, KSPFlexibleModifyPCFn *fun, PetscCtx ctx, PetscCtxDestroyFn *dfun)
436: {
437:   return KSPFlexibleSetModifyPC(ksp, fun, ctx, dfun);
438: }

440: PETSC_EXTERN PetscErrorCode KSPMINRESSetRadius(KSP, PetscReal);
441: PETSC_EXTERN PetscErrorCode KSPMINRESGetUseQLP(KSP, PetscBool *);
442: PETSC_EXTERN PetscErrorCode KSPMINRESSetUseQLP(KSP, PetscBool);

444: PETSC_EXTERN PetscErrorCode KSPFETIDPGetInnerBDDC(KSP, PC *);
445: PETSC_EXTERN PetscErrorCode KSPFETIDPSetInnerBDDC(KSP, PC);
446: PETSC_EXTERN PetscErrorCode KSPFETIDPGetInnerKSP(KSP, KSP *);
447: PETSC_EXTERN PetscErrorCode KSPFETIDPSetPressureOperator(KSP, Mat);

449: PETSC_EXTERN PetscErrorCode KSPHPDDMSetDeflationMat(KSP, Mat);
450: PETSC_EXTERN PetscErrorCode KSPHPDDMGetDeflationMat(KSP, Mat *);
451: #if PetscDefined(HAVE_HPDDM)
452: PETSC_DEPRECATED_FUNCTION(3, 18, 0, "KSPHPDDMSetDeflationMat()", ) static inline PetscErrorCode KSPHPDDMSetDeflationSpace(KSP ksp, Mat U)
453: {
454:   return KSPHPDDMSetDeflationMat(ksp, U);
455: }
456: PETSC_DEPRECATED_FUNCTION(3, 18, 0, "KSPHPDDMGetDeflationMat()", ) static inline PetscErrorCode KSPHPDDMGetDeflationSpace(KSP ksp, Mat *U)
457: {
458:   return KSPHPDDMGetDeflationMat(ksp, U);
459: }
460: #endif
461: PETSC_DEPRECATED_FUNCTION(3, 14, 0, "KSPMatSolve()", ) static inline PetscErrorCode KSPHPDDMMatSolve(KSP ksp, Mat B, Mat X)
462: {
463:   return KSPMatSolve(ksp, B, X);
464: }
465: /*E
466:     KSPHPDDMType - Type of Krylov method used by `KSPHPDDM`

468:     Values:
469: +   `KSP_HPDDM_TYPE_GMRES` (default) - Generalized Minimal Residual method
470: .   `KSP_HPDDM_TYPE_BGMRES`          - block GMRES
471: .   `KSP_HPDDM_TYPE_CG`              - Conjugate Gradient
472: .   `KSP_HPDDM_TYPE_BCG`             - block CG
473: .   `KSP_HPDDM_TYPE_GCRODR`          - Generalized Conjugate Residual method with inner Orthogonalization and Deflated Restarting
474: .   `KSP_HPDDM_TYPE_BGCRODR`         - block GCRODR
475: .   `KSP_HPDDM_TYPE_BFBCG`           - breakdown-free BCG
476: -   `KSP_HPDDM_TYPE_PREONLY`         - apply the preconditioner only

478:     Level: intermediate

480: .seealso: [](ch_ksp), `KSPHPDDM`, `KSPHPDDMSetType()`
481: E*/
482: typedef enum {
483:   KSP_HPDDM_TYPE_GMRES   = 0,
484:   KSP_HPDDM_TYPE_BGMRES  = 1,
485:   KSP_HPDDM_TYPE_CG      = 2,
486:   KSP_HPDDM_TYPE_BCG     = 3,
487:   KSP_HPDDM_TYPE_GCRODR  = 4,
488:   KSP_HPDDM_TYPE_BGCRODR = 5,
489:   KSP_HPDDM_TYPE_BFBCG   = 6,
490:   KSP_HPDDM_TYPE_PREONLY = 7
491: } KSPHPDDMType;
492: PETSC_EXTERN const char *const KSPHPDDMTypes[];

494: PETSC_EXTERN PetscErrorCode KSPHPDDMSetType(KSP, KSPHPDDMType);
495: PETSC_EXTERN PetscErrorCode KSPHPDDMGetType(KSP, KSPHPDDMType *);

497: /*S
498:   KSPOrthogonalizationFn - A function prototype for functions provided to `KSPOrthogonalizationSet()`

500:   Calling Sequence:
501: + ksp - the `KSP` context
502: . V   - array of previously computed orthonormal vectors
503: . n   - number of vectors
504: . x   - vector to be orthogonalized (may be `NULL`)
505: - h   - computed orthogonalization coefficients

507:   Level: intermediate

509:   Note:
510:   If no `x` is given, then the vector to be orthogonalized is assumed to be located at `V[n]`.

512: .seealso: [](ch_ksp), `KSP`, `KSPOrthogonalizationSet()`
513: S*/
514: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPOrthogonalizationFn(KSP ksp, Vec V[], PetscInt n, Vec x, PetscScalar h[]);

516: PETSC_EXTERN PetscErrorCode         KSPOrthogonalizationSet(KSP, KSPOrthogonalizationFn *);
517: PETSC_EXTERN PetscErrorCode         KSPOrthogonalizationGet(KSP, KSPOrthogonalizationFn **);
518: PETSC_EXTERN KSPOrthogonalizationFn KSPOrthogonalizationClassicalGramSchmidt;
519: PETSC_EXTERN KSPOrthogonalizationFn KSPOrthogonalizationModifiedGramSchmidt;

521: #define KSP_GMRES_CGS_REFINE_NEVER_DEPRECATED    KSP_GMRES_CGS_REFINE_NEVER PETSC_DEPRECATED_ENUM(3, 26, 0, "KSP_ORTHOGONALIZATION_CGS_REFINE_NEVER", )
522: #define KSP_GMRES_CGS_REFINE_IFNEEDED_DEPRECATED KSP_GMRES_CGS_REFINE_IFNEEDED PETSC_DEPRECATED_ENUM(3, 26, 0, "KSP_ORTHOGONALIZATION_CGS_REFINE_IFNEEDED", )
523: #define KSP_GMRES_CGS_REFINE_ALWAYS_DEPRECATED   KSP_GMRES_CGS_REFINE_ALWAYS PETSC_DEPRECATED_ENUM(3, 26, 0, "KSP_ORTHOGONALIZATION_CGS_REFINE_ALWAYS", )
524: /*E
525:    KSPOrthogonalizationCGSRefinementType - How the classical (unmodified) Gram-Schmidt is performed in the GMRES solvers

527:    Values:
528: +  `KSP_ORTHOGONALIZATION_CGS_REFINE_NEVER`    - one step of classical Gram-Schmidt
529: .  `KSP_ORTHOGONALIZATION_CGS_REFINE_IFNEEDED` - a second step is performed if the first step does not satisfy some criteria
530: -  `KSP_ORTHOGONALIZATION_CGS_REFINE_ALWAYS`   - always perform two steps

532:    Level: advanced

534: .seealso: [](ch_ksp), `KSP`, `KSPGMRES`, `KSPOrthogonalizationClassicalGramSchmidt()`, `KSPOrthogonalizationSet()`,
535:           `KSPOrthogonalizationGet()`,
536:           `KSPOrthogonalizationSetCGSRefinementType()`, `KSPOrthogonalizationGetCGSRefinementType()`, `KSPOrthogonalizationModifiedGramSchmidt()`
537: E*/
538: typedef enum {
539:   KSP_ORTHOGONALIZATION_CGS_REFINE_NEVER    = 0,
540:   KSP_ORTHOGONALIZATION_CGS_REFINE_IFNEEDED = 1,
541:   KSP_ORTHOGONALIZATION_CGS_REFINE_ALWAYS   = 2,
542:   KSP_GMRES_CGS_REFINE_NEVER_DEPRECATED     = 0,
543:   KSP_GMRES_CGS_REFINE_IFNEEDED_DEPRECATED  = 1,
544:   KSP_GMRES_CGS_REFINE_ALWAYS_DEPRECATED    = 2
545: } KSPOrthogonalizationCGSRefinementType;
546: PETSC_EXTERN const char *const KSPOrthogonalizationCGSRefinementTypes[];

548: /*MC
549:    KSP_ORTHOGONALIZATION_CGS_REFINE_NEVER - Do the classical (unmodified) Gram-Schmidt process

551:    Level: advanced

553:    Note:
554:    Possibly unstable, but the fastest to compute

556: .seealso: [](ch_ksp), `KSPGMRES`, `KSPOrthogonalizationCGSRefinementType`, `KSPOrthogonalizationClassicalGramSchmidt()`, `KSPOrthogonalizationSet()`,
557:           `KSP`, `KSPOrthogonalizationGet()`,
558:           `KSPOrthogonalizationSetCGSRefinementType()`, `KSPOrthogonalizationGetCGSRefinementType()`, `KSP_ORTHOGONALIZATION_CGS_REFINE_IFNEEDED`, `KSP_ORTHOGONALIZATION_CGS_REFINE_ALWAYS`,
559:           `KSPOrthogonalizationModifiedGramSchmidt()`
560: M*/

562: /*MC
563:     KSP_ORTHOGONALIZATION_CGS_REFINE_IFNEEDED - Do the classical (unmodified) Gram-Schmidt process and one step of
564:           iterative refinement if an estimate of the orthogonality of the resulting vectors indicates
565:           poor orthogonality.

567:    Level: advanced

569:    Note:
570:    This is slower than `KSP_ORTHOGONALIZATION_CGS_REFINE_NEVER` because it requires an extra norm computation to
571:    estimate the orthogonality but is more stable.

573: .seealso: [](ch_ksp), `KSPGMRES`, `KSPOrthogonalizationCGSRefinementType`, `KSPOrthogonalizationClassicalGramSchmidt()`, `KSPOrthogonalizationSet()`,
574:           `KSP`, `KSPOrthogonalizationGet()`,
575:           `KSPOrthogonalizationSetCGSRefinementType()`, `KSPOrthogonalizationGetCGSRefinementType()`, `KSP_ORTHOGONALIZATION_CGS_REFINE_NEVER`, `KSP_ORTHOGONALIZATION_CGS_REFINE_ALWAYS`,
576:           `KSPOrthogonalizationModifiedGramSchmidt()`
577: M*/

579: /*MC
580:    KSP_ORTHOGONALIZATION_CGS_REFINE_ALWAYS - Do two steps of the classical (unmodified) Gram-Schmidt process.

582:    Level: advanced

584:    Notes:
585:    This is roughly twice the cost of `KSP_ORTHOGONALIZATION_CGS_REFINE_NEVER` because it performs the process twice
586:    but it saves the extra norm calculation needed by `KSP_ORTHOGONALIZATION_CGS_REFINE_IFNEEDED`.

588:    You should only use this if you absolutely know that the iterative refinement is needed.

590: .seealso: [](ch_ksp), `KSPGMRES`, `KSPOrthogonalizationCGSRefinementType`, `KSPOrthogonalizationClassicalGramSchmidt()`, `KSPOrthogonalizationSet()`,
591:           `KSP`, `KSPOrthogonalizationGet()`,
592:           `KSPOrthogonalizationSetCGSRefinementType()`, `KSPOrthogonalizationGetCGSRefinementType()`, `KSP_ORTHOGONALIZATION_CGS_REFINE_IFNEEDED`, `KSP_ORTHOGONALIZATION_CGS_REFINE_ALWAYS`,
593:           `KSPOrthogonalizationModifiedGramSchmidt()`
594: M*/

596: PETSC_EXTERN PetscErrorCode KSPOrthogonalizationSetCGSRefinementType(KSP, KSPOrthogonalizationCGSRefinementType);
597: PETSC_EXTERN PetscErrorCode KSPOrthogonalizationGetCGSRefinementType(KSP, KSPOrthogonalizationCGSRefinementType *);

599: PETSC_DEPRECATED_FUNCTION(3, 26, 0, "KSPOrthogonalizationModifiedGramSchmidt()", ) static inline PetscErrorCode KSPGMRESModifiedGramSchmidtOrthogonalization(KSP ksp, PETSC_UNUSED PetscInt it)
600: {
601:   SETERRQ(PetscObjectComm((PetscObject)ksp), PETSC_ERR_SUP, "Use KSPOrthogonalizationModifiedGramSchmidt()");
602: }
603: PETSC_DEPRECATED_FUNCTION(3, 26, 0, "KSPOrthogonalizationClassicalGramSchmidt()", ) static inline PetscErrorCode KSPGMRESClassicalGramSchmidtOrthogonalization(KSP ksp, PETSC_UNUSED PetscInt it)
604: {
605:   SETERRQ(PetscObjectComm((PetscObject)ksp), PETSC_ERR_SUP, "Use KSPOrthogonalizationClassicalGramSchmidt()");
606: }
607: PETSC_DEPRECATED_FUNCTION(3, 26, 0, "KSPOrthogonalizationSet()", ) static inline PetscErrorCode KSPGMRESSetOrthogonalization(KSP ksp, PETSC_UNUSED PetscErrorCode (*orthog)(KSP, PetscInt))
608: {
609:   SETERRQ(PetscObjectComm((PetscObject)ksp), PETSC_ERR_SUP, "Use KSPOrthogonalizationSet()");
610: }
611: PETSC_DEPRECATED_FUNCTION(3, 26, 0, "KSPOrthogonalizationGet()", ) static inline PetscErrorCode KSPGMRESGetOrthogonalization(KSP ksp, PETSC_UNUSED PetscErrorCode (**orthog)(KSP, PetscInt))
612: {
613:   SETERRQ(PetscObjectComm((PetscObject)ksp), PETSC_ERR_SUP, "Use KSPOrthogonalizationGet()");
614: }
615: PETSC_DEPRECATED_TYPEDEF(3, 26, 0, "KSPOrthogonalizationCGSRefinementType", ) typedef KSPOrthogonalizationCGSRefinementType KSPGMRESCGSRefinementType;
616: PETSC_DEPRECATED_FUNCTION(3, 26, 0, "KSPOrthogonalizationSetCGSRefinementType()", )
617: static inline PetscErrorCode KSPGMRESSetCGSRefinementType(KSP ksp, KSPOrthogonalizationCGSRefinementType type)
618: {
619:   return KSPOrthogonalizationSetCGSRefinementType(ksp, type);
620: }
621: PETSC_DEPRECATED_FUNCTION(3, 26, 0, "KSPOrthogonalizationGetCGSRefinementType()", )
622: static inline PetscErrorCode KSPGMRESGetCGSRefinementType(KSP ksp, KSPOrthogonalizationCGSRefinementType *type)
623: {
624:   return KSPOrthogonalizationGetCGSRefinementType(ksp, type);
625: }

627: PETSC_EXTERN KSPFlexibleModifyPCFn KSPFlexibleModifyPCNoChange;
628: PETSC_EXTERN KSPFlexibleModifyPCFn KSPFlexibleModifyPCKSP;

630: PETSC_DEPRECATED_FUNCTION(3, 25, 0, "KSPFlexibleModifyPCNoChange()", ) static inline PetscErrorCode KSPFGMRESModifyPCNoChange(KSP ksp, PetscInt total_its, PetscInt loc_its, PetscReal res_norm, PetscCtx ctx)
631: {
632:   return KSPFlexibleModifyPCNoChange(ksp, total_its, loc_its, res_norm, ctx);
633: }

635: PETSC_DEPRECATED_FUNCTION(3, 25, 0, "KSPFlexibleModifyPCKSP()", ) static inline PetscErrorCode KSPFGMRESModifyPCKSP(KSP ksp, PetscInt total_its, PetscInt loc_its, PetscReal res_norm, PetscCtx ctx)
636: {
637:   return KSPFlexibleModifyPCKSP(ksp, total_its, loc_its, res_norm, ctx);
638: }

640: PETSC_EXTERN PetscErrorCode KSPQCGSetTrustRegionRadius(KSP, PetscReal);
641: PETSC_EXTERN PetscErrorCode KSPQCGGetQuadratic(KSP, PetscReal *);
642: PETSC_EXTERN PetscErrorCode KSPQCGGetTrialStepNorm(KSP, PetscReal *);

644: PETSC_EXTERN PetscErrorCode KSPBCGSLSetXRes(KSP, PetscReal);
645: PETSC_EXTERN PetscErrorCode KSPBCGSLSetPol(KSP, PetscBool);
646: PETSC_EXTERN PetscErrorCode KSPBCGSLSetEll(KSP, PetscInt);
647: PETSC_EXTERN PetscErrorCode KSPBCGSLSetUsePseudoinverse(KSP, PetscBool);

649: PETSC_EXTERN PetscErrorCode KSPSetFromOptions(KSP);
650: PETSC_EXTERN PetscErrorCode KSPResetFromOptions(KSP);

652: PETSC_EXTERN PetscErrorCode       KSPMonitorSetFromOptions(KSP, const char[], const char[], PetscCtx);
653: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorResidual;
654: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorResidualView;
655: PETSC_DEPRECATED_FUNCTION(3, 23, 0, "KSPMonitorResidualDraw()", ) static inline PetscErrorCode KSPMonitorResidualDraw(KSP ksp, PetscInt n, PetscReal rnorm, PetscViewerAndFormat *vf)
656: {
657:   return KSPMonitorResidualView(ksp, n, rnorm, vf);
658: }
659: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorResidualDrawLG;
660: PETSC_EXTERN PetscErrorCode       KSPMonitorResidualDrawLGCreate(PetscViewer, PetscViewerFormat, PetscCtx, PetscViewerAndFormat **);
661: PETSC_DEPRECATED_FUNCTION(3, 26, 0, "KSPMonitorResidual()", ) static inline PetscErrorCode KSPMonitorResidualShort(KSP ksp, PetscInt n, PetscReal rnorm, PetscViewerAndFormat *vf)
662: {
663:   return KSPMonitorResidual(ksp, n, rnorm, vf);
664: }
665: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorResidualRange;
666: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorTrueResidual;
667: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorTrueResidualView;
668: PETSC_DEPRECATED_FUNCTION(3, 23, 0, "KSPMonitorTrueResidualDraw()", ) static inline PetscErrorCode KSPMonitorTrueResidualDraw(KSP ksp, PetscInt n, PetscReal rnorm, PetscViewerAndFormat *vf)
669: {
670:   return KSPMonitorTrueResidualView(ksp, n, rnorm, vf);
671: }
672: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorTrueResidualDrawLG;
673: PETSC_EXTERN PetscErrorCode       KSPMonitorTrueResidualDrawLGCreate(PetscViewer, PetscViewerFormat, PetscCtx, PetscViewerAndFormat **);
674: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorTrueResidualMax;
675: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorError;
676: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorErrorDraw;
677: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorErrorDrawLG;
678: PETSC_EXTERN PetscErrorCode       KSPMonitorErrorDrawLGCreate(PetscViewer, PetscViewerFormat, PetscCtx, PetscViewerAndFormat **);
679: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorSolution;
680: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorSolutionDraw;
681: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorSolutionDrawLG;
682: PETSC_EXTERN PetscErrorCode       KSPMonitorSolutionDrawLGCreate(PetscViewer, PetscViewerFormat, PetscCtx, PetscViewerAndFormat **);
683: PETSC_EXTERN KSPMonitorRegisterFn KSPMonitorSingularValue;
684: PETSC_EXTERN PetscErrorCode       KSPMonitorSingularValueCreate(PetscViewer, PetscViewerFormat, PetscCtx, PetscViewerAndFormat **);
685: PETSC_DEPRECATED_FUNCTION(3, 15, 0, "KSPMonitorResidual()", ) static inline PetscErrorCode KSPMonitorDefault(KSP ksp, PetscInt n, PetscReal rnorm, PetscViewerAndFormat *vf)
686: {
687:   return KSPMonitorResidual(ksp, n, rnorm, vf);
688: }
689: PETSC_DEPRECATED_FUNCTION(3, 15, 0, "KSPMonitorTrueResidual()", ) static inline PetscErrorCode KSPMonitorTrueResidualNorm(KSP ksp, PetscInt n, PetscReal rnorm, PetscViewerAndFormat *vf)
690: {
691:   return KSPMonitorTrueResidual(ksp, n, rnorm, vf);
692: }
693: PETSC_DEPRECATED_FUNCTION(3, 15, 0, "KSPMonitorTrueResidualMax()", ) static inline PetscErrorCode KSPMonitorTrueResidualMaxNorm(KSP ksp, PetscInt n, PetscReal rnorm, PetscViewerAndFormat *vf)
694: {
695:   return KSPMonitorTrueResidualMax(ksp, n, rnorm, vf);
696: }

698: PETSC_EXTERN PetscErrorCode KSPGMRESMonitorKrylov(KSP, PetscInt, PetscReal, void *);
699: PETSC_EXTERN PetscErrorCode KSPMonitorDynamicTolerance(KSP, PetscInt, PetscReal, PetscCtx);
700: PETSC_EXTERN PetscErrorCode KSPMonitorDynamicToleranceDestroy(PetscCtxRt);
701: PETSC_EXTERN PetscErrorCode KSPMonitorDynamicToleranceCreate(void *);
702: PETSC_EXTERN PetscErrorCode KSPMonitorDynamicToleranceSetCoefficient(void *, PetscReal);
703: PETSC_EXTERN PetscErrorCode KSPMonitorSAWs(KSP, PetscInt, PetscReal, void *);
704: PETSC_EXTERN PetscErrorCode KSPMonitorSAWsCreate(KSP, void **);
705: PETSC_EXTERN PetscErrorCode KSPMonitorSAWsDestroy(PetscCtxRt);

707: PETSC_EXTERN PetscErrorCode KSPUnwindPreconditioner(KSP, Vec, Vec);
708: PETSC_EXTERN PetscErrorCode KSPInitialResidual(KSP, Vec, Vec, Vec, Vec, Vec);

710: PETSC_EXTERN PetscErrorCode KSPSetOperators(KSP, Mat, Mat);
711: PETSC_EXTERN PetscErrorCode KSPGetOperators(KSP, Mat *, Mat *);
712: PETSC_EXTERN PetscErrorCode KSPGetOperatorsSet(KSP, PetscBool *, PetscBool *);
713: PETSC_EXTERN PetscErrorCode KSPSetOptionsPrefix(KSP, const char[]);
714: PETSC_EXTERN PetscErrorCode KSPAppendOptionsPrefix(KSP, const char[]);
715: PETSC_EXTERN PetscErrorCode KSPGetOptionsPrefix(KSP, const char *[]);

717: /*S
718:   KSPConvergedReasonViewFn - A prototype of a function used with `KSPConvergedReasonViewSet()`

720:   Calling Sequence:
721: + ksp - the `KSP` object whose `KSPConvergedReason` is to be viewed
722: - ctx - context used by the function, set with `KSPConvergedReasonViewSet()`

724:   Level: beginner

726: .seealso: [](ch_ksp), `KSP`, `KSPConvergedReasonView()`, `KSPConvergedReasonViewSet()`, `KSPConvergedReasonViewFromOptions()`, `KSPView()`
727: S*/
728: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPConvergedReasonViewFn(KSP ksp, PetscCtx ctx);

730: PETSC_EXTERN PetscErrorCode KSPView(KSP, PetscViewer);
731: PETSC_EXTERN PetscErrorCode KSPLoad(KSP, PetscViewer);
732: PETSC_EXTERN PetscErrorCode KSPViewFromOptions(KSP, PetscObject, const char[]);
733: PETSC_EXTERN PetscErrorCode KSPConvergedReasonView(KSP, PetscViewer);
734: PETSC_EXTERN PetscErrorCode KSPConvergedReasonViewSet(KSP, KSPConvergedReasonViewFn *, void *, PetscCtxDestroyFn *);
735: PETSC_EXTERN PetscErrorCode KSPConvergedReasonViewFromOptions(KSP);
736: PETSC_EXTERN PetscErrorCode KSPConvergedReasonViewCancel(KSP);
737: PETSC_EXTERN PetscErrorCode KSPConvergedRateView(KSP, PetscViewer);

739: PETSC_DEPRECATED_FUNCTION(3, 14, 0, "KSPConvergedReasonView()", ) static inline PetscErrorCode KSPReasonView(KSP ksp, PetscViewer v)
740: {
741:   return KSPConvergedReasonView(ksp, v);
742: }
743: PETSC_DEPRECATED_FUNCTION(3, 14, 0, "KSPConvergedReasonViewFromOptions()", ) static inline PetscErrorCode KSPReasonViewFromOptions(KSP ksp)
744: {
745:   return KSPConvergedReasonViewFromOptions(ksp);
746: }

748: #define KSP_FILE_CLASSID 1211223

750: PETSC_EXTERN PetscErrorCode       KSPLSQRSetExactMatNorm(KSP, PetscBool);
751: PETSC_EXTERN PetscErrorCode       KSPLSQRSetComputeStandardErrorVec(KSP, PetscBool);
752: PETSC_EXTERN PetscErrorCode       KSPLSQRGetStandardErrorVec(KSP, Vec *);
753: PETSC_EXTERN PetscErrorCode       KSPLSQRGetNorms(KSP, PetscReal *, PetscReal *);
754: PETSC_EXTERN KSPMonitorRegisterFn KSPLSQRMonitorResidual;
755: PETSC_EXTERN KSPMonitorRegisterFn KSPLSQRMonitorResidualDrawLG;
756: PETSC_EXTERN PetscErrorCode       KSPLSQRMonitorResidualDrawLGCreate(PetscViewer, PetscViewerFormat, void *, PetscViewerAndFormat **);

758: PETSC_EXTERN PetscErrorCode PCRedundantGetKSP(PC, KSP *);
759: PETSC_EXTERN PetscErrorCode PCRedistributeGetKSP(PC, KSP *);
760: PETSC_EXTERN PetscErrorCode PCTelescopeGetKSP(PC, KSP *);
761: PETSC_EXTERN PetscErrorCode PCMPIGetKSP(PC, KSP *);

763: /*E
764:    KSPNormType - Norm calculated by the `KSP` and used in the Krylov convergence
765:        test routines.

767:    Values:
768: +  `KSP_NORM_DEFAULT`          - use the default for the current `KSPType`
769: .  `KSP_NORM_NONE`             - use no norm calculation
770: .  `KSP_NORM_PRECONDITIONED`   - use the preconditioned residual norm
771: .  `KSP_NORM_UNPRECONDITIONED` - use the unpreconditioned residual norm
772: -  `KSP_NORM_NATURAL`          - use an approximation of the natural norm (the norm induced by the linear operator) of the error

774:    Level: advanced

776:    Note:
777:    Each solver only supports a subset of these and some may support different ones
778:    depending on whether left or right preconditioning is used, see `KSPSetPCSide()`

780: .seealso: [](ch_ksp), `KSP`, `PCSide`, `KSPSolve()`, `KSPGetConvergedReason()`, `KSPSetNormType()`,
781:           `KSPSetConvergenceTest()`, `KSPSetPCSide()`, `KSP_NORM_DEFAULT`, `KSP_NORM_NONE`, `KSP_NORM_PRECONDITIONED`, `KSP_NORM_UNPRECONDITIONED`, `KSP_NORM_NATURAL`
782: E*/
783: typedef enum {
784:   KSP_NORM_DEFAULT          = -1,
785:   KSP_NORM_NONE             = 0,
786:   KSP_NORM_PRECONDITIONED   = 1,
787:   KSP_NORM_UNPRECONDITIONED = 2,
788:   KSP_NORM_NATURAL          = 3
789: } KSPNormType;
790: #define KSP_NORM_MAX (KSP_NORM_NATURAL + 1)
791: PETSC_EXTERN const char *const *const KSPNormTypes;

793: /*MC
794:    KSP_NORM_NONE - Do not compute a norm during the Krylov process. This will
795:    possibly save some computation but means the convergence test cannot
796:    be based on a norm of a residual etc.

798:    Level: advanced

800:    Note:
801:    Some Krylov methods need to compute a residual norm (such as `KPSGMRES`) and then this option is ignored

803: .seealso: [](ch_ksp), `KSPNormType`, `KSP`, `KSPSetNormType()`, `KSP_NORM_PRECONDITIONED`, `KSP_NORM_UNPRECONDITIONED`, `KSP_NORM_NATURAL`
804: M*/

806: /*MC
807:    KSP_NORM_PRECONDITIONED - Compute the norm of the preconditioned residual $B(b - Ax)$, if left preconditioning, and pass that to the
808:    convergence test routine.

810:    Level: advanced

812: .seealso: [](ch_ksp), `KSPNormType`, `KSP`, `KSPSetNormType()`, `KSP_NORM_NONE`, `KSP_NORM_UNPRECONDITIONED`, `KSP_NORM_NATURAL`, `KSPSetConvergenceTest()`
813: M*/

815: /*MC
816:    KSP_NORM_UNPRECONDITIONED - Compute the norm of the true residual $(b - Ax)$ and pass that to the
817:    convergence test routine.

819:    Level: advanced

821: .seealso: [](ch_ksp), `KSPNormType`, `KSP`, `KSPSetNormType()`, `KSP_NORM_NONE`, `KSP_NORM_PRECONDITIONED`, `KSP_NORM_NATURAL`, `KSPSetConvergenceTest()`
822: M*/

824: /*MC
825:   KSP_NORM_NATURAL - Computes $((b - Ax)^TB(b - Ax))^{1/2}$ and passes that to the
826:   convergence test routine.

828:   Level: advanced

830:   Notes:
831:   This is supported by the conjugate gradient-type methods `KSPCG`, `KSPCR`, `KSPCGNE`, `KSPCGS`, `KSPFCG`, `KSPPIPEFCG`, `KSPPIPELCG`, `KSPPIPEGCR`,
832:   `KSPPIPECGRR`, `KSPPIPECG`, `KSPPIPECG2`, `KSPPIPEPRCG`, `KSPGROPPCG`, `KSPGLTR`, and `KSPNASH`.

834:   `KSPFETIDP` and `KSPPREONLY` accept this setting for compatibility but do not use it directly.
835:   For `KSPFETIDP`, configure the norm type on the inner `KSP` returned by `KSPFETIDPGetInnerKSP()`.

837:   Since $(b - Ax)^TB(b - Ax) = e^TA^TBAe \approx e^TAe$, where $e$ is the error and $A$ is the discretization of the differential
838:   operator arising from the weak formulation of the governing equations, the code is approximating the norm that operator induces on the error.
839:   For many problems, the underlying norm is $H^1$, often
840:   called the energy norm.

842:   Since the application of $B$ to $(b - Ax)$ is already computed in the conjugate gradient and related routines, the use of `KSP_NORM_NATURAL` does not require
843:   any additional operations over using other `KSPNormType`s.

845: .seealso: [](ch_ksp), `KSPNormType`, `KSP`, `KSPSetNormType()`, `KSP_NORM_NONE`, `KSP_NORM_PRECONDITIONED`, `KSP_NORM_UNPRECONDITIONED`, `KSPSetConvergenceTest()`
846: M*/

848: PETSC_EXTERN PetscErrorCode KSPSetNormType(KSP, KSPNormType);
849: PETSC_EXTERN PetscErrorCode KSPGetNormType(KSP, KSPNormType *);
850: PETSC_EXTERN PetscErrorCode KSPSetSupportedNorm(KSP, KSPNormType, PCSide, PetscInt);
851: PETSC_EXTERN PetscErrorCode KSPSetCheckNormIteration(KSP, PetscInt);
852: PETSC_EXTERN PetscErrorCode KSPSetLagNorm(KSP, PetscBool);

854: #define KSP_CONVERGED_CG_NEG_CURVE_DEPRECATED   KSP_CONVERGED_CG_NEG_CURVE PETSC_DEPRECATED_ENUM(3, 19, 0, "KSP_CONVERGED_NEG_CURVE", )
855: #define KSP_CONVERGED_CG_CONSTRAINED_DEPRECATED KSP_CONVERGED_CG_CONSTRAINED PETSC_DEPRECATED_ENUM(3, 19, 0, "KSP_CONVERGED_STEP_LENGTH", )
856: #define KSP_CONVERGED_RTOL_NORMAL_DEPRECATED    KSP_CONVERGED_RTOL_NORMAL PETSC_DEPRECATED_ENUM(3, 24, 0, "KSP_CONVERGED_RTOL_NORMAL_EQUATIONS", )
857: #define KSP_CONVERGED_ATOL_NORMAL_DEPRECATED    KSP_CONVERGED_ATOL_NORMAL PETSC_DEPRECATED_ENUM(3, 24, 0, "KSP_CONVERGED_ATOL_NORMAL_EQUATIONS", )
858: /*E
859:    KSPConvergedReason - reason a Krylov method was determined to have converged or diverged

861:    Values:
862: +  `KSP_CONVERGED_RTOL_NORMAL_EQUATIONS` - requested decrease in the residual of the normal equations, for `KSPLSQR`
863: .  `KSP_CONVERGED_ATOL_NORMAL_EQUATIONS` - requested absolute value in the residual of the normal equations, for `KSPLSQR`
864: .  `KSP_CONVERGED_RTOL`                  - requested decrease in the residual
865: .  `KSP_CONVERGED_ATOL`                  - requested absolute value in the residual
866: .  `KSP_CONVERGED_ITS`                   - requested number of iterations
867: .  `KSP_CONVERGED_NEG_CURVE`             - see note below
868: .  `KSP_CONVERGED_STEP_LENGTH`           - see note below
869: .  `KSP_CONVERGED_HAPPY_BREAKDOWN`       - happy breakdown (meaning early convergence of the `KSPType` occurred).
870: .  `KSP_CONVERGED_USER`                  - the user has indicated convergence for an arbitrary reason
871: .  `KSP_DIVERGED_NULL`                   - breakdown when solving the Hessenberg system within `KSPGMRES`
872: .  `KSP_DIVERGED_ITS`                    - requested number of iterations
873: .  `KSP_DIVERGED_DTOL`                   - large increase in the residual norm indicating the solution is diverging
874: .  `KSP_DIVERGED_BREAKDOWN`              - breakdown in the Krylov method
875: .  `KSP_DIVERGED_BREAKDOWN_BICG`         - breakdown in the `KSPBCGS` Krylov method
876: .  `KSP_DIVERGED_NONSYMMETRIC`           - the operator or preonditioner was not symmetric for a `KSPType` that requires symmetry
877: .  `KSP_DIVERGED_INDEFINITE_PC`          - the preconditioner was indefinite for a `KSPType` that requires it be definite, such as `KSPCG`
878: .  `KSP_DIVERGED_NANORINF`               - a not a number of infinity was detected in a vector during the computation
879: .  `KSP_DIVERGED_INDEFINITE_MAT`         - the operator was indefinite for a `KSPType` that requires it be definite, such as `KSPCG`
880: .  `KSP_DIVERGED_PC_FAILED`              - the action of the preconditioner failed for some reason
881: .  `KSP_DIVERGED_USER`                   - the user has indicated divergence for an arbitrary reason
882: -  `KSP_DIVERGED_INNER_SOLVE_FAILED`     - the inner `KSPSolve()` failed for some reason

884:    Level: beginner

886:    Note:
887:    The values `KSP_CONVERGED_NEG_CURVE`, and `KSP_CONVERGED_STEP_LENGTH` are returned only by `KSPCG`, `KSPMINRES` and by
888:    the special `KSPNASH`, `KSPSTCG`, and `KSPGLTR` solvers which are used by the `SNESNEWTONTR` (trust region) solver.

890:    Developer Note:
891:    The string versions of these are `KSPConvergedReasons`; if you change
892:    any of the values here also change them that array of names.

894: .seealso: [](ch_ksp), `KSP`, `KSPSolve()`, `KSPGetConvergedReason()`, `KSPSetTolerances()`, `KSPConvergedReasonView()`
895: E*/
896: typedef enum { /* converged */
897:   KSP_CONVERGED_RTOL_NORMAL_DEPRECATED    = 1,
898:   KSP_CONVERGED_RTOL_NORMAL_EQUATIONS     = 1,
899:   KSP_CONVERGED_ATOL_NORMAL_DEPRECATED    = 9,
900:   KSP_CONVERGED_ATOL_NORMAL_EQUATIONS     = 9,
901:   KSP_CONVERGED_RTOL                      = 2,
902:   KSP_CONVERGED_ATOL                      = 3,
903:   KSP_CONVERGED_ITS                       = 4,
904:   KSP_CONVERGED_NEG_CURVE                 = 5,
905:   KSP_CONVERGED_CG_NEG_CURVE_DEPRECATED   = 5,
906:   KSP_CONVERGED_CG_CONSTRAINED_DEPRECATED = 6,
907:   KSP_CONVERGED_STEP_LENGTH               = 6,
908:   KSP_CONVERGED_HAPPY_BREAKDOWN           = 7,
909:   KSP_CONVERGED_USER                      = 8,
910:   /* diverged */
911:   KSP_DIVERGED_NULL                      = -2,
912:   KSP_DIVERGED_ITS                       = -3,
913:   KSP_DIVERGED_DTOL                      = -4,
914:   KSP_DIVERGED_BREAKDOWN                 = -5,
915:   KSP_DIVERGED_BREAKDOWN_BICG            = -6,
916:   KSP_DIVERGED_NONSYMMETRIC              = -7,
917:   KSP_DIVERGED_INDEFINITE_PC             = -8,
918:   KSP_DIVERGED_NANORINF                  = -9,
919:   KSP_DIVERGED_INDEFINITE_MAT            = -10,
920:   KSP_DIVERGED_PC_FAILED                 = -11,
921:   KSP_DIVERGED_PCSETUP_FAILED_DEPRECATED = -11,
922:   KSP_DIVERGED_USER                      = -12,
923:   KSP_DIVERGED_INNER_SOLVE_FAILED        = -13,

925:   KSP_CONVERGED_ITERATING = 0
926: } KSPConvergedReason;
927: PETSC_EXTERN const char *const *KSPConvergedReasons;

929: /*MC
930:    KSP_CONVERGED_RTOL - $\|r\| \le rtol \|b\|$ or $rtol \|b - A x_0\|$ if `KSPConvergedDefaultSetUIRNorm()` was called

932:    Level: beginner

934:    Notes:
935:    See `KSPNormType` and `KSPSetNormType()` for possible norms that may be used. By default
936:    for left preconditioning it is the 2-norm of the preconditioned residual, and the
937:    2-norm of the residual for right preconditioning

939:    See also `KSP_CONVERGED_ATOL` which may apply before this tolerance.

941: .seealso: [](ch_ksp), `KSPNormType`, `KSP_CONVERGED_ATOL`, `KSP_DIVERGED_DTOL`, `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
942: M*/

944: /*MC
945:    KSP_CONVERGED_ATOL - $\|r\| \le atol$

947:    Level: beginner

949:    Notes:
950:    See `KSPNormType` and `KSPSetNormType()` for possible norms that may be used. By default
951:    for left preconditioning it is the 2-norm of the preconditioned residual, and the
952:    2-norm of the residual for right preconditioning

954:    See also `KSP_CONVERGED_RTOL` which may apply before this tolerance.

956: .seealso: [](ch_ksp), `KSPNormType`, `KSP_CONVERGED_RTOL`, `KSP_DIVERGED_DTOL`, `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
957: M*/

959: /*MC
960:    KSP_DIVERGED_DTOL - $\|r\| \ge dtol \|b\|$

962:    Level: beginner

964:    Note:
965:    See `KSPNormType` and `KSPSetNormType()` for possible norms that may be used. By default
966:    for left preconditioning it is the 2-norm of the preconditioned residual, and the
967:    2-norm of the residual for right preconditioning

969: .seealso: [](ch_ksp), `KSPNormType`, `KSP_CONVERGED_ATOL`, `KSP_CONVERGED_RTOL`, `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
970: M*/

972: /*MC
973:    KSP_DIVERGED_ITS - Ran out of iterations before any convergence criteria was
974:    reached

976:    Level: beginner

978: .seealso: [](ch_ksp), `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
979: M*/

981: /*MC
982:    KSP_CONVERGED_ITS - Used by the `KSPPREONLY` solver after the single iteration of
983:    the preconditioner is applied. Also used when the `KSPConvergedSkip()` convergence
984:    test routine is set in `KSP`.

986:    Level: beginner

988: .seealso: [](ch_ksp), `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
989: M*/

991: /*MC
992:    KSP_DIVERGED_BREAKDOWN - A breakdown in the Krylov method was detected so the
993:    method could not continue to enlarge the Krylov space. Could be due to a singular matrix or
994:    preconditioner. In `KSPHPDDM`, this is also returned when some search directions within a block
995:    are collinear.

997:    Level: beginner

999: .seealso: [](ch_ksp), `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
1000: M*/

1002: /*MC
1003:    KSP_DIVERGED_BREAKDOWN_BICG - A breakdown in the `KSPBICG` method was detected so the
1004:    method could not continue to enlarge the Krylov space.

1006:    Level: beginner

1008: .seealso: [](ch_ksp), `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
1009: M*/

1011: /*MC
1012:    KSP_DIVERGED_NONSYMMETRIC - It appears the operator or preconditioner is not
1013:    symmetric and this Krylov method (`KSPCG`, `KSPMINRES`, `KSPCR`) requires symmetry

1015:    Level: beginner

1017: .seealso: [](ch_ksp), `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
1018: M*/

1020: /*MC
1021:    KSP_DIVERGED_INDEFINITE_PC - It appears the preconditioner is indefinite (has both
1022:    positive and negative eigenvalues) and this Krylov method (`KSPCG`) requires it to
1023:    be symmetric positive definite (SPD).

1025:    Level: beginner

1027:    Note:
1028:    This can happen with the `PCICC` preconditioner, use the options database option `-pc_factor_shift_positive_definite` to force
1029:    the `PCICC` preconditioner to generate a positive definite preconditioner

1031: .seealso: [](ch_ksp), `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
1032: M*/

1034: /*MC
1035:    KSP_DIVERGED_PC_FAILED - It was not possible to build or use the requested preconditioner. This is usually due to a
1036:    zero pivot in a factorization. It can also result from a failure in a subpreconditioner inside a nested preconditioner
1037:    such as `PCFIELDSPLIT`.

1039:    Level: beginner

1041:    Note:
1042:    Run with `-ksp_error_if_not_converged` to stop the program when the error is detected and print an error message with details.

1044: .seealso: [](ch_ksp), `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
1045: M*/

1047: /*MC
1048:    KSP_DIVERGED_USER - The user has indicated divergence for an arbitrary reason.

1050:    Level: beginner

1052: .seealso: [](ch_ksp), `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
1053: M*/

1055: /*MC
1056:    KSP_DIVERGED_INNER_SOLVE_FAILED - It was not possible to solve an inner linear system in solvers such as `KSPEKSM`.

1058:    Level: beginner

1060:    Note:
1061:    Run with `-ksp_error_if_not_converged` to stop the program when the error is detected and print an error message with details.

1063: .seealso: [](ch_ksp), `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
1064: M*/

1066: /*MC
1067:    KSP_CONVERGED_ITERATING - This flag is returned if `KSPGetConvergedReason()` is called
1068:    while `KSPSolve()` is still running.

1070:    Level: beginner

1072: .seealso: [](ch_ksp), `KSPSolve()`, `KSPGetConvergedReason()`, `KSPConvergedReason`, `KSPSetTolerances()`
1073: M*/

1075: /*S
1076:   KSPConvergenceTestFn - A prototype of a function used with `KSPSetConvergenceTest()`

1078:   Calling Sequence:
1079: + ksp    - iterative solver obtained from `KSPCreate()`
1080: . it     - iteration number
1081: . rnorm  - (estimated) 2-norm of (preconditioned) residual
1082: . reason - the reason why it has converged or diverged
1083: - ctx    - optional convergence context, as set by `KSPSetConvergenceTest()`

1085:   Level: beginner

1087: .seealso: [](ch_ksp), `KSP`, `KSPSetConvergenceTest()`, `KSPGetConvergenceTest()`
1088: S*/
1089: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPConvergenceTestFn(KSP ksp, PetscInt it, PetscReal rnorm, KSPConvergedReason *reason, PetscCtx ctx);

1091: PETSC_EXTERN PetscErrorCode       KSPSetConvergenceTest(KSP, KSPConvergenceTestFn *, void *, PetscCtxDestroyFn *);
1092: PETSC_EXTERN PetscErrorCode       KSPGetConvergenceTest(KSP, KSPConvergenceTestFn **, PetscCtxRt, PetscCtxDestroyFn **);
1093: PETSC_EXTERN PetscErrorCode       KSPGetAndClearConvergenceTest(KSP, KSPConvergenceTestFn **, PetscCtxRt, PetscCtxDestroyFn **);
1094: PETSC_EXTERN PetscErrorCode       KSPGetConvergenceContext(KSP, PetscCtxRt);
1095: PETSC_EXTERN KSPConvergenceTestFn KSPConvergedDefault;
1096: PETSC_EXTERN KSPConvergenceTestFn KSPLSQRConvergedDefault;
1097: PETSC_EXTERN PetscCtxDestroyFn    KSPConvergedDefaultDestroy;
1098: PETSC_EXTERN PetscErrorCode       KSPConvergedDefaultCreate(void **);
1099: PETSC_EXTERN PetscErrorCode       KSPConvergedDefaultSetUIRNorm(KSP);
1100: PETSC_EXTERN PetscErrorCode       KSPConvergedDefaultSetUMIRNorm(KSP);
1101: PETSC_EXTERN PetscErrorCode       KSPConvergedDefaultSetConvergedMaxits(KSP, PetscBool);
1102: PETSC_EXTERN PetscErrorCode       KSPConvergedSkip(KSP, PetscInt, PetscReal, KSPConvergedReason *, void *);
1103: PETSC_EXTERN PetscErrorCode       KSPGetConvergedReason(KSP, KSPConvergedReason *);
1104: PETSC_EXTERN PetscErrorCode       KSPGetConvergedReasonString(KSP, const char *[]);
1105: PETSC_EXTERN PetscErrorCode       KSPComputeConvergenceRate(KSP, PetscReal *, PetscReal *, PetscReal *, PetscReal *);
1106: PETSC_EXTERN PetscErrorCode       KSPSetConvergedNegativeCurvature(KSP, PetscBool);
1107: PETSC_EXTERN PetscErrorCode       KSPGetConvergedNegativeCurvature(KSP, PetscBool *);

1109: PETSC_DEPRECATED_FUNCTION(3, 5, 0, "KSPConvergedDefault()", ) static inline void KSPDefaultConverged(void)
1110: { /* never called */
1111: }
1112: #define KSPDefaultConverged (KSPDefaultConverged, KSPConvergedDefault)
1113: PETSC_DEPRECATED_FUNCTION(3, 5, 0, "KSPConvergedDefaultDestroy()", ) static inline void KSPDefaultConvergedDestroy(void)
1114: { /* never called */
1115: }
1116: #define KSPDefaultConvergedDestroy (KSPDefaultConvergedDestroy, KSPConvergedDefaultDestroy)
1117: PETSC_DEPRECATED_FUNCTION(3, 5, 0, "KSPConvergedDefaultCreate()", ) static inline void KSPDefaultConvergedCreate(void)
1118: { /* never called */
1119: }
1120: #define KSPDefaultConvergedCreate (KSPDefaultConvergedCreate, KSPConvergedDefaultCreate)
1121: PETSC_DEPRECATED_FUNCTION(3, 5, 0, "KSPConvergedDefaultSetUIRNorm()", ) static inline void KSPDefaultConvergedSetUIRNorm(void)
1122: { /* never called */
1123: }
1124: #define KSPDefaultConvergedSetUIRNorm (KSPDefaultConvergedSetUIRNorm, KSPConvergedDefaultSetUIRNorm)
1125: PETSC_DEPRECATED_FUNCTION(3, 5, 0, "KSPConvergedDefaultSetUMIRNorm()", ) static inline void KSPDefaultConvergedSetUMIRNorm(void)
1126: { /* never called */
1127: }
1128: #define KSPDefaultConvergedSetUMIRNorm (KSPDefaultConvergedSetUMIRNorm, KSPConvergedDefaultSetUMIRNorm)
1129: PETSC_DEPRECATED_FUNCTION(3, 5, 0, "KSPConvergedSkip()", ) static inline void KSPSkipConverged(void)
1130: { /* never called */
1131: }
1132: #define KSPSkipConverged (KSPSkipConverged, KSPConvergedSkip)

1134: PETSC_EXTERN PetscErrorCode KSPComputeOperator(KSP, MatType, Mat *);
1135: PETSC_DEPRECATED_FUNCTION(3, 12, 0, "KSPComputeOperator()", ) static inline PetscErrorCode KSPComputeExplicitOperator(KSP A, Mat *B)
1136: {
1137:   return KSPComputeOperator(A, PETSC_NULLPTR, B);
1138: }

1140: /*E
1141:    KSPCGType - Determines what type of `KSPCG` to use

1143:    Values:
1144:  + `KSP_CG_SYMMETRIC` - the matrix is complex symmetric
1145:  - `KSP_CG_HERMITIAN` - the matrix is complex Hermitian

1147:    Level: beginner

1149: .seealso: [](ch_ksp), `KSPCG`, `KSP`, `KSPCGSetType()`
1150: E*/
1151: typedef enum {
1152:   KSP_CG_SYMMETRIC = 0,
1153:   KSP_CG_HERMITIAN = 1
1154: } KSPCGType;
1155: PETSC_EXTERN const char *const KSPCGTypes[];

1157: PETSC_EXTERN PetscErrorCode KSPCGSetType(KSP, KSPCGType);
1158: PETSC_EXTERN PetscErrorCode KSPCGUseSingleReduction(KSP, PetscBool);

1160: /*E
1161:   KSPCGTRNormType - Norm used for the trust-region constraint in `KSPCG`, `KSPSTCG`, `KSPNASH`, and `KSPGLTR`

1163:   Values:
1164: + `KSP_CG_TR_NORM_PRECONDITIONED`   - use $\sqrt{x^H M x}$, where the preconditioner applies $M^{-1}$
1165: - `KSP_CG_TR_NORM_UNPRECONDITIONED` - use the Euclidean norm $\sqrt{x^H x}$ (default)

1167:   Level: advanced

1169:   Note:
1170:   These norms measure the solution vector $x$. The residual norm used for convergence is selected independently with `KSPSetNormType()`.

1172: .seealso: [](ch_ksp), `KSP`, `KSPCGSetTRNormType()`, `KSPCGGetTRNormType()`, `KSPCGGetTRSolutionNorm()`, `KSPCGSetRadius()`, `KSPNormType`
1173: E*/
1174: typedef enum {
1175:   KSP_CG_TR_NORM_PRECONDITIONED,
1176:   KSP_CG_TR_NORM_UNPRECONDITIONED
1177: } KSPCGTRNormType;
1178: PETSC_EXTERN const char *const KSPCGTRNormTypes[];

1180: PETSC_EXTERN PetscErrorCode KSPCGSetTRNormType(KSP, KSPCGTRNormType);
1181: PETSC_EXTERN PetscErrorCode KSPCGGetTRNormType(KSP, KSPCGTRNormType *);
1182: PETSC_EXTERN PetscErrorCode KSPCGSetRadius(KSP, PetscReal);
1183: PETSC_EXTERN PetscErrorCode KSPCGSetObjectiveTarget(KSP, PetscReal);
1184: PETSC_EXTERN PetscErrorCode KSPCGGetTRSolutionNorm(KSP, PetscReal *);
1185: PETSC_DEPRECATED_FUNCTION(3, 27, 0, "KSPCGGetTRSolutionNorm()", ) static inline PetscErrorCode KSPCGGetNormD(KSP ksp, PetscReal *norm)
1186: {
1187:   return KSPCGGetTRSolutionNorm(ksp, norm);
1188: }
1189: PETSC_EXTERN PetscErrorCode KSPCGGetObjFcn(KSP, PetscReal *);

1191: PETSC_EXTERN PetscErrorCode KSPGLTRGetMinEig(KSP, PetscReal *);
1192: PETSC_EXTERN PetscErrorCode KSPGLTRGetLambda(KSP, PetscReal *);
1193: PETSC_DEPRECATED_FUNCTION(3, 12, 0, "KSPGLTRGetMinEig()", ) static inline PetscErrorCode KSPCGGLTRGetMinEig(KSP ksp, PetscReal *x)
1194: {
1195:   return KSPGLTRGetMinEig(ksp, x);
1196: }
1197: PETSC_DEPRECATED_FUNCTION(3, 12, 0, "KSPGLTRGetLambda()", ) static inline PetscErrorCode KSPCGGLTRGetLambda(KSP ksp, PetscReal *x)
1198: {
1199:   return KSPGLTRGetLambda(ksp, x);
1200: }

1202: PETSC_EXTERN PetscErrorCode KSPPythonSetType(KSP, const char[]);
1203: PETSC_EXTERN PetscErrorCode KSPPythonGetType(KSP, const char *[]);

1205: PETSC_EXTERN PetscErrorCode PCPreSolve(PC, KSP);
1206: PETSC_EXTERN PetscErrorCode PCPostSolve(PC, KSP);

1208: PETSC_EXTERN PetscErrorCode KSPMonitorLGRange(KSP, PetscInt, PetscReal, void *);

1210: /*S
1211:   PCShellPSolveFn - A function prototype for functions provided to `PCShellSetPreSolve()` and `PCShellSetPostSolve()`

1213:   Calling Sequence:
1214: + pc  - the preconditioner `PC` context
1215: . ksp - the `KSP` context
1216: . xin  - input vector
1217: - xout - output vector

1219:   Level: intermediate

1221: .seealso: [](ch_snes), `KSPPSolveFn`, `KSP`, `PCShellSetPreSolve()`, `PCShellSetPostSolve()`
1222: S*/
1223: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode PCShellPSolveFn(PC pc, KSP ksp, Vec xim, Vec xout);

1225: PETSC_EXTERN PetscErrorCode PCShellSetPreSolve(PC, PCShellPSolveFn *);
1226: PETSC_EXTERN PetscErrorCode PCShellSetPostSolve(PC, PCShellPSolveFn *);

1228: /*S
1229:    KSPGuess - Abstract PETSc object that manages all initial guess generation methods for Krylov methods.

1231:    Level: intermediate

1233:    Note:
1234:    These methods generate initial guesses based on a series of previous, related, linear solves. For example,
1235:    in implicit time-stepping with `TS`.

1237: .seealso: [](ch_ksp), `KSPCreate()`, `KSPGuessSetType()`, `KSPGuessType`
1238: S*/
1239: typedef struct _p_KSPGuess *KSPGuess;

1241: /*J
1242:   KSPGuessType - String with the name of a PETSc initial guess approach for Krylov methods.

1244:   Values:
1245: + `KSPGUESSFISCHER` - methodology developed by Paul Fischer
1246: - `KSPGUESSPOD`     - methodology based on proper orthogonal decomposition (POD)

1248:   Options Database Key:
1249: . -ksp_guess_type (fischer|pod) - set the type

1251:   Level: intermediate

1253: .seealso: [](ch_ksp), `KSP`, `KSPGuess`, `KSPGuessSetType()`
1254: J*/
1255: typedef const char *KSPGuessType;
1256: #define KSPGUESSFISCHER "fischer"
1257: #define KSPGUESSPOD     "pod"

1259: PETSC_EXTERN PetscErrorCode KSPGuessRegister(const char[], PetscErrorCode (*)(KSPGuess));
1260: PETSC_EXTERN PetscErrorCode KSPSetGuess(KSP, KSPGuess);
1261: PETSC_EXTERN PetscErrorCode KSPGetGuess(KSP, KSPGuess *);
1262: PETSC_EXTERN PetscErrorCode KSPGuessView(KSPGuess, PetscViewer);
1263: PETSC_EXTERN PetscErrorCode KSPGuessDestroy(KSPGuess *);
1264: PETSC_EXTERN PetscErrorCode KSPGuessCreate(MPI_Comm, KSPGuess *);
1265: PETSC_EXTERN PetscErrorCode KSPGuessSetType(KSPGuess, KSPGuessType);
1266: PETSC_EXTERN PetscErrorCode KSPGuessGetType(KSPGuess, KSPGuessType *);
1267: PETSC_EXTERN PetscErrorCode KSPGuessSetTolerance(KSPGuess, PetscReal);
1268: PETSC_EXTERN PetscErrorCode KSPGuessSetUp(KSPGuess);
1269: PETSC_EXTERN PetscErrorCode KSPGuessUpdate(KSPGuess, Vec, Vec);
1270: PETSC_EXTERN PetscErrorCode KSPGuessFormGuess(KSPGuess, Vec, Vec);
1271: PETSC_EXTERN PetscErrorCode KSPGuessSetFromOptions(KSPGuess);
1272: PETSC_EXTERN PetscErrorCode KSPGuessFischerSetModel(KSPGuess, PetscInt, PetscInt);
1273: PETSC_EXTERN PetscErrorCode KSPSetUseFischerGuess(KSP, PetscInt, PetscInt);
1274: PETSC_EXTERN PetscErrorCode KSPSetInitialGuessKnoll(KSP, PetscBool);
1275: PETSC_EXTERN PetscErrorCode KSPGetInitialGuessKnoll(KSP, PetscBool *);

1277: /*E
1278:   MatSchurComplementAinvType - Determines how to approximate the inverse of the (0,0) block in Schur complement matrix assembly routines

1280:   Values:
1281: + `MAT_SCHUR_COMPLEMENT_AINV_DIAG`       - invert the diagonal of `A00`
1282: . `MAT_SCHUR_COMPLEMENT_AINV_LUMP`       - invert the diagonal matrix containing the row sums of `A00` (mass lumping)
1283: . `MAT_SCHUR_COMPLEMENT_AINV_BLOCK_DIAG` - invert the block diagonal of the matrix, where the blocks are determined by the block size of the matrix
1284: - `MAT_SCHUR_COMPLEMENT_AINV_FULL`       - invert the full matrix `A00`

1286:   Level: intermediate

1288:   Note:
1289:   In the documentation this inverse type is indicated with $inv(DIAGFORM(A00))$.

1291: .seealso: `MatSchurComplementGetAinvType()`, `MatSchurComplementSetAinvType()`, `MatSchurComplementGetPmat()`, `MatGetSchurComplement()`,
1292:           `MatCreateSchurComplementPmat()`, `MatCreateSchurComplement()`
1293: E*/
1294: typedef enum {
1295:   MAT_SCHUR_COMPLEMENT_AINV_DIAG,
1296:   MAT_SCHUR_COMPLEMENT_AINV_LUMP,
1297:   MAT_SCHUR_COMPLEMENT_AINV_BLOCK_DIAG,
1298:   MAT_SCHUR_COMPLEMENT_AINV_FULL
1299: } MatSchurComplementAinvType;
1300: PETSC_EXTERN const char *const MatSchurComplementAinvTypes[];

1302: PETSC_EXTERN PetscErrorCode MatCreateSchurComplement(Mat, Mat, Mat, Mat, Mat, Mat *);
1303: PETSC_EXTERN PetscErrorCode MatSchurComplementGetKSP(Mat, KSP *);
1304: PETSC_EXTERN PetscErrorCode MatSchurComplementSetKSP(Mat, KSP);
1305: PETSC_EXTERN PetscErrorCode MatSchurComplementSetSubMatrices(Mat, Mat, Mat, Mat, Mat, Mat);
1306: PETSC_EXTERN PetscErrorCode MatSchurComplementUpdateSubMatrices(Mat, Mat, Mat, Mat, Mat, Mat);
1307: PETSC_EXTERN PetscErrorCode MatSchurComplementGetSubMatrices(Mat, Mat *, Mat *, Mat *, Mat *, Mat *);
1308: PETSC_EXTERN PetscErrorCode MatSchurComplementSetAinvType(Mat, MatSchurComplementAinvType);
1309: PETSC_EXTERN PetscErrorCode MatSchurComplementGetAinvType(Mat, MatSchurComplementAinvType *);
1310: PETSC_EXTERN PetscErrorCode MatSchurComplementGetPmat(Mat, MatReuse, Mat *);
1311: PETSC_EXTERN PetscErrorCode MatSchurComplementComputeExplicitOperator(Mat, Mat *);
1312: PETSC_EXTERN PetscErrorCode MatGetSchurComplement(Mat, IS, IS, IS, IS, MatReuse, Mat *, MatSchurComplementAinvType, MatReuse, Mat *);
1313: PETSC_EXTERN PetscErrorCode MatCreateSchurComplementPmat(Mat, Mat, Mat, Mat, MatSchurComplementAinvType, MatReuse, Mat *);

1315: PETSC_EXTERN PetscErrorCode MatCreateLMVMDFP(MPI_Comm, PetscInt, PetscInt, Mat *);
1316: PETSC_EXTERN PetscErrorCode MatCreateLMVMBFGS(MPI_Comm, PetscInt, PetscInt, Mat *);
1317: PETSC_EXTERN PetscErrorCode MatCreateLMVMDBFGS(MPI_Comm, PetscInt, PetscInt, Mat *);
1318: PETSC_EXTERN PetscErrorCode MatCreateLMVMDDFP(MPI_Comm, PetscInt, PetscInt, Mat *);
1319: PETSC_EXTERN PetscErrorCode MatCreateLMVMDQN(MPI_Comm, PetscInt, PetscInt, Mat *);
1320: PETSC_EXTERN PetscErrorCode MatCreateLMVMSR1(MPI_Comm, PetscInt, PetscInt, Mat *);
1321: PETSC_EXTERN PetscErrorCode MatCreateLMVMBroyden(MPI_Comm, PetscInt, PetscInt, Mat *);
1322: PETSC_EXTERN PetscErrorCode MatCreateLMVMBadBroyden(MPI_Comm, PetscInt, PetscInt, Mat *);
1323: PETSC_EXTERN PetscErrorCode MatCreateLMVMSymBroyden(MPI_Comm, PetscInt, PetscInt, Mat *);
1324: PETSC_EXTERN PetscErrorCode MatCreateLMVMSymBadBroyden(MPI_Comm, PetscInt, PetscInt, Mat *);
1325: PETSC_EXTERN PetscErrorCode MatCreateLMVMDiagBroyden(MPI_Comm, PetscInt, PetscInt, Mat *);

1327: PETSC_EXTERN PetscErrorCode MatLMVMUpdate(Mat, Vec, Vec);
1328: PETSC_EXTERN PetscErrorCode MatLMVMIsAllocated(Mat, PetscBool *);
1329: PETSC_EXTERN PetscErrorCode MatLMVMAllocate(Mat, Vec, Vec);
1330: PETSC_EXTERN PetscErrorCode MatLMVMReset(Mat, PetscBool);
1331: PETSC_EXTERN PetscErrorCode MatLMVMResetShift(Mat);
1332: PETSC_EXTERN PetscErrorCode MatLMVMClearJ0(Mat);
1333: PETSC_EXTERN PetscErrorCode MatLMVMSetJ0(Mat, Mat);
1334: PETSC_EXTERN PetscErrorCode MatLMVMSetJ0Scale(Mat, PetscReal);
1335: PETSC_EXTERN PetscErrorCode MatLMVMSetJ0Diag(Mat, Vec);
1336: PETSC_EXTERN PetscErrorCode MatLMVMSetJ0PC(Mat, PC);
1337: PETSC_EXTERN PetscErrorCode MatLMVMSetJ0KSP(Mat, KSP);
1338: PETSC_EXTERN PetscErrorCode MatLMVMApplyJ0Fwd(Mat, Vec, Vec);
1339: PETSC_EXTERN PetscErrorCode MatLMVMApplyJ0Inv(Mat, Vec, Vec);
1340: PETSC_EXTERN PetscErrorCode MatLMVMGetLastUpdate(Mat, Vec *, Vec *);
1341: PETSC_EXTERN PetscErrorCode MatLMVMGetJ0(Mat, Mat *);
1342: PETSC_EXTERN PetscErrorCode MatLMVMGetJ0PC(Mat, PC *);
1343: PETSC_EXTERN PetscErrorCode MatLMVMGetJ0KSP(Mat, KSP *);
1344: PETSC_EXTERN PetscErrorCode MatLMVMSetHistorySize(Mat, PetscInt);
1345: PETSC_EXTERN PetscErrorCode MatLMVMGetHistorySize(Mat, PetscInt *);
1346: PETSC_EXTERN PetscErrorCode MatLMVMGetUpdateCount(Mat, PetscInt *);
1347: PETSC_EXTERN PetscErrorCode MatLMVMGetRejectCount(Mat, PetscInt *);
1348: PETSC_EXTERN PetscErrorCode MatLMVMSymBroydenSetDelta(Mat, PetscScalar);

1350: /*E
1351:   MatLMVMMultAlgorithm - The type of algorithm used for matrix-vector products and solves used internally by a `MatLMVM` matrix

1353:   Values:
1354: + `MAT_LMVM_MULT_RECURSIVE`     - Use recursive formulas for products and solves
1355: . `MAT_LMVM_MULT_DENSE`         - Use dense formulas for products and solves when possible
1356: - `MAT_LMVM_MULT_COMPACT_DENSE` - The same as `MATLMVM_MULT_DENSE`, but go further and ensure products and solves are computed in compact low-rank update form

1358:   Level: advanced

1360:   Options Database Keys:
1361: . -mat_lmvm_mult_algorithm (recursive|dense|compact_dense) - the algorithm to use for multiplication

1363: .seealso: [](ch_matrices), `MATLMVM`, `MatLMVMSetMultAlgorithm()`, `MatLMVMGetMultAlgorithm()`
1364: E*/
1365: typedef enum {
1366:   MAT_LMVM_MULT_RECURSIVE,
1367:   MAT_LMVM_MULT_DENSE,
1368:   MAT_LMVM_MULT_COMPACT_DENSE,
1369: } MatLMVMMultAlgorithm;

1371: PETSC_EXTERN const char *const MatLMVMMultAlgorithms[];

1373: PETSC_EXTERN PetscErrorCode MatLMVMSetMultAlgorithm(Mat, MatLMVMMultAlgorithm);
1374: PETSC_EXTERN PetscErrorCode MatLMVMGetMultAlgorithm(Mat, MatLMVMMultAlgorithm *);

1376: /*E
1377:   MatLMVMSymBroydenScaleType - Rescaling type for the initial Hessian of a symmetric Broyden matrix.

1379:   Values:
1380: + `MAT_LMVM_SYMBROYDEN_SCALE_NONE`     - no rescaling
1381: . `MAT_LMVM_SYMBROYDEN_SCALE_SCALAR`   - scalar rescaling
1382: . `MAT_LMVM_SYMBROYDEN_SCALE_DIAGONAL` - diagonal rescaling
1383: . `MAT_LMVM_SYMBROYDEN_SCALE_USER`     - same as `MAT_LMVM_SYMBROYDN_SCALE_NONE`
1384: - `MAT_LMVM_SYMBROYDEN_SCALE_DECIDE`   - let PETSc decide rescaling

1386:   Level: intermediate

1388: .seealso: [](ch_matrices), `MATLMVM`, `MatLMVMSymBroydenSetScaleType()`
1389: E*/
1390: typedef enum {
1391:   MAT_LMVM_SYMBROYDEN_SCALE_NONE     = 0,
1392:   MAT_LMVM_SYMBROYDEN_SCALE_SCALAR   = 1,
1393:   MAT_LMVM_SYMBROYDEN_SCALE_DIAGONAL = 2,
1394:   MAT_LMVM_SYMBROYDEN_SCALE_USER     = 3,
1395:   MAT_LMVM_SYMBROYDEN_SCALE_DECIDE   = 4
1396: } MatLMVMSymBroydenScaleType;
1397: PETSC_EXTERN const char *const MatLMVMSymBroydenScaleTypes[];

1399: PETSC_EXTERN PetscErrorCode MatLMVMSymBroydenSetScaleType(Mat, MatLMVMSymBroydenScaleType);
1400: PETSC_EXTERN PetscErrorCode MatLMVMSymBroydenGetPhi(Mat, PetscReal *);
1401: PETSC_EXTERN PetscErrorCode MatLMVMSymBroydenSetPhi(Mat, PetscReal);
1402: PETSC_EXTERN PetscErrorCode MatLMVMSymBadBroydenGetPsi(Mat, PetscReal *);
1403: PETSC_EXTERN PetscErrorCode MatLMVMSymBadBroydenSetPsi(Mat, PetscReal);

1405: /*E
1406:   MatLMVMDenseType - Memory storage strategy for dense variants of `MATLMVM`.

1408:   Values:
1409: + `MAT_LMVM_DENSE_REORDER` - reorders memory to minimize kernel launch
1410: - `MAT_LMVM_DENSE_INPLACE` - computes inplace to minimize memory movement

1412:   Level: intermediate

1414: .seealso: [](ch_matrices), `MatLMVM`, `MatLMVMDenseSetType()`
1415: E*/
1416: typedef enum {
1417:   MAT_LMVM_DENSE_REORDER,
1418:   MAT_LMVM_DENSE_INPLACE
1419: } MatLMVMDenseType;
1420: PETSC_EXTERN const char *const MatLMVMDenseTypes[];

1422: PETSC_EXTERN PetscErrorCode MatLMVMDenseSetType(Mat, MatLMVMDenseType);

1424: PETSC_EXTERN PetscErrorCode KSPSetDM(KSP, DM);

1426: /*E
1427:   KSPDMActive - Indicates if the `DM` attached to the `KSP` should be used to compute the operator, the right-hand side, or the initial guess

1429:   Values:
1430: + `KSP_DMACTIVE_OPERATOR`      - compute the operator
1431: . `KSP_DMACTIVE_RHS`           - compute the right-hand side
1432: . `KSP_DMACTIVE_INITIAL_GUESS` - compute the initial guess
1433: - `KSP_DMACTIVE_ALL`           - compute all of them

1435:   Level: intermediate

1437: .seealso: [](ch_ksp), `KSP`, `KSPSetDMActive()`, `KSPSetDM()`
1438: E*/
1439: typedef enum {
1440:   KSP_DMACTIVE_OPERATOR      = 1,
1441:   KSP_DMACTIVE_RHS           = 2,
1442:   KSP_DMACTIVE_INITIAL_GUESS = 4,
1443:   KSP_DMACTIVE_ALL           = 1 + 2 + 4
1444: } KSPDMActive;
1445: PETSC_EXTERN PetscErrorCode KSPSetDMActive(KSP, KSPDMActive, PetscBool);

1447: PETSC_EXTERN PetscErrorCode KSPGetDM(KSP, DM *);
1448: PETSC_EXTERN PetscErrorCode KSPSetApplicationContext(KSP, PetscCtx);
1449: PETSC_EXTERN PetscErrorCode KSPGetApplicationContext(KSP, PetscCtxRt);

1451: /*S
1452:   KSPComputeRHSFn - A prototype of a `KSP` evaluation function that would be passed to `KSPSetComputeRHS()`

1454:   Calling Sequence:
1455: + ksp  - `ksp` context
1456: . b    - output vector
1457: - ctx - [optional] user-defined function context

1459:   Level: beginner

1461: .seealso: [](ch_ksp), `KSP`, `KSPSetComputeRHS()`, `SNESGetFunction()`, `KSPComputeInitialGuessFn`, `KSPComputeOperatorsFn`
1462: S*/
1463: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPComputeRHSFn(KSP ksp, Vec b, PetscCtx ctx);

1465: PETSC_EXTERN PetscErrorCode KSPSetComputeRHS(KSP, KSPComputeRHSFn *, void *);

1467: /*S
1468:   KSPComputeOperatorsFn - A prototype of a `KSP` evaluation function that would be passed to `KSPSetComputeOperators()`

1470:   Calling Sequence:
1471: + ksp - `KSP` context
1472: . A   - the operator that defines the linear system
1473: . P   - an operator from which to build the preconditioner (often the same as `A`)
1474: - ctx - [optional] user-defined function context

1476:   Level: beginner

1478: .seealso: [](ch_ksp), `KSP`, `KSPSetComputeRHS()`, `SNESGetFunction()`, `KSPComputeRHSFn`, `KSPComputeInitialGuessFn`
1479: S*/
1480: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPComputeOperatorsFn(KSP ksp, Mat A, Mat P, PetscCtx ctx);

1482: PETSC_EXTERN PetscErrorCode KSPSetComputeOperators(KSP, KSPComputeOperatorsFn, void *);

1484: /*S
1485:   KSPCreateOperatorsFn - A prototype of a `KSP` operator creation function that would be passed to `DMKSPSetCreateOperators()`

1487:   Calling Sequence:
1488: + ksp - `KSP` context
1489: . A   - the created operator that defines the linear system
1490: . P   - the created operator from which to build the preconditioner, often the same as `A`
1491: - ctx - [optional] user-defined function context

1493:   Level: developer

1495:   Notes:
1496:   The returned matrices are owned by the caller, similar to `DMCreateMatrix()`.

1498:   `A` and `P` may be the same object. In such a case, users do not need to increase the reference count of `A`. If `P` is not returned, then we assume it is the same of `A`.

1500: .seealso: [](ch_ksp), `DMKSPSetCreateOperators()`, `DMKSPGetCreateOperators()`, `KSPComputeOperatorsFn`, `KSPSetOperators()`
1501: S*/
1502: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPCreateOperatorsFn(KSP ksp, Mat *A, Mat *P, PetscCtx ctx);

1504: /*S
1505:   KSPComputeInitialGuessFn - A prototype of a `KSP` evaluation function that would be passed to `KSPSetComputeInitialGuess()`

1507:   Calling Sequence:
1508: + ksp  - `ksp` context
1509: . x    - output vector
1510: - ctx - [optional] user-defined function context

1512:   Level: beginner

1514: .seealso: [](ch_ksp), `KSP`, `KSPSetComputeInitialGuess()`, `SNESGetFunction()`, `KSPComputeRHSFn`, `KSPComputeOperatorsFn`
1515: S*/
1516: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode KSPComputeInitialGuessFn(KSP ksp, Vec x, PetscCtx ctx);

1518: PETSC_EXTERN PetscErrorCode KSPSetComputeInitialGuess(KSP, KSPComputeInitialGuessFn *, void *);
1519: PETSC_EXTERN PetscErrorCode DMKSPSetComputeOperators(DM, KSPComputeOperatorsFn *, void *);
1520: PETSC_EXTERN PetscErrorCode DMKSPGetComputeOperators(DM, KSPComputeOperatorsFn **, void *);
1521: PETSC_EXTERN PetscErrorCode DMKSPSetCreateOperators(DM, KSPCreateOperatorsFn *, void *);
1522: PETSC_EXTERN PetscErrorCode DMKSPGetCreateOperators(DM, KSPCreateOperatorsFn **, void *);
1523: PETSC_EXTERN PetscErrorCode DMKSPSetComputeRHS(DM, KSPComputeRHSFn *, void *);
1524: PETSC_EXTERN PetscErrorCode DMKSPGetComputeRHS(DM, KSPComputeRHSFn **, void *);
1525: PETSC_EXTERN PetscErrorCode DMKSPSetComputeInitialGuess(DM, KSPComputeInitialGuessFn *, void *);
1526: PETSC_EXTERN PetscErrorCode DMKSPGetComputeInitialGuess(DM, KSPComputeInitialGuessFn **, void *);

1528: PETSC_EXTERN PetscErrorCode DMGlobalToLocalSolve(DM, Vec, Vec);
1529: PETSC_EXTERN PetscErrorCode DMSwarmProjectFields(DM, DM, PetscInt, const char *[], Vec[], ScatterMode);
1530: PETSC_EXTERN PetscErrorCode DMSwarmProjectGradientFields(DM, DM, PetscInt, const char *[], Vec[], ScatterMode);

1532: PETSC_EXTERN PetscErrorCode DMAdaptInterpolator(DM, DM, Mat, KSP, Mat, Mat, Mat *, void *);
1533: PETSC_EXTERN PetscErrorCode DMCheckInterpolator(DM, Mat, Mat, Mat, PetscReal);

1535: PETSC_EXTERN PetscErrorCode PCBJKOKKOSSetKSP(PC, KSP);
1536: PETSC_EXTERN PetscErrorCode PCBJKOKKOSGetKSP(PC, KSP *);

1538: PETSC_EXTERN PetscErrorCode DMCopyDMKSP(DM, DM);

1540: #include <petscdstypes.h>
1541: PETSC_EXTERN PetscErrorCode DMProjectField(DM, PetscReal, Vec, PetscPointFn **, InsertMode, Vec);