xref: /petsc/include/petscksp.h (revision a174af7ba5ddcd7958fb849d9fff48e4dcd911a7)
1 /*
2    Defines the interface functions for the Krylov subspace accelerators.
3 */
4 #ifndef __PETSCKSP_H
5 #define __PETSCKSP_H
6 #include <petscpc.h>
7 
8 PETSC_EXTERN PetscErrorCode KSPInitializePackage(const char[]);
9 
10 /*S
11      KSP - Abstract PETSc object that manages all Krylov methods
12 
13    Level: beginner
14 
15   Concepts: Krylov methods
16 
17 .seealso:  KSPCreate(), KSPSetType(), KSPType, SNES, TS, PC, KSP
18 S*/
19 typedef struct _p_KSP*     KSP;
20 
21 /*J
22     KSPType - String with the name of a PETSc Krylov method or the creation function
23        with an optional dynamic library name, for example
24        http://www.mcs.anl.gov/petsc/lib.a:mykspcreate()
25 
26    Level: beginner
27 
28 .seealso: KSPSetType(), KSP
29 J*/
30 typedef const char* KSPType;
31 #define KSPRICHARDSON "richardson"
32 #define KSPCHEBYSHEV  "chebyshev"
33 #define KSPCG         "cg"
34 #define   KSPCGNE       "cgne"
35 #define   KSPNASH       "nash"
36 #define   KSPSTCG       "stcg"
37 #define   KSPGLTR       "gltr"
38 #define KSPGMRES      "gmres"
39 #define   KSPFGMRES     "fgmres"
40 #define   KSPLGMRES     "lgmres"
41 #define   KSPDGMRES     "dgmres"
42 #define   KSPPGMRES     "pgmres"
43 #define KSPTCQMR      "tcqmr"
44 #define KSPBCGS       "bcgs"
45 #define   KSPIBCGS      "ibcgs"
46 #define   KSPFBCGS      "fbcgs"
47 #define   KSPIFBCGS     "ifbcgs"
48 #define   KSPTFIBCGS    "tfibcgs"
49 #define   KSPBCGSL      "bcgsl"
50 #define KSPCGS        "cgs"
51 #define KSPTFQMR      "tfqmr"
52 #define KSPCR         "cr"
53 #define KSPLSQR       "lsqr"
54 #define KSPPREONLY    "preonly"
55 #define KSPQCG        "qcg"
56 #define KSPBICG       "bicg"
57 #define KSPMINRES     "minres"
58 #define KSPSYMMLQ     "symmlq"
59 #define KSPLCD        "lcd"
60 #define KSPPYTHON     "python"
61 #define KSPGCR        "gcr"
62 #define KSPSPECEST    "specest"
63 
64 /* Logging support */
65 PETSC_EXTERN PetscClassId KSP_CLASSID;
66 
67 PETSC_EXTERN PetscErrorCode KSPCreate(MPI_Comm,KSP *);
68 PETSC_EXTERN PetscErrorCode KSPSetType(KSP,KSPType);
69 PETSC_EXTERN PetscErrorCode KSPSetUp(KSP);
70 PETSC_EXTERN PetscErrorCode KSPSetUpOnBlocks(KSP);
71 PETSC_EXTERN PetscErrorCode KSPSolve(KSP,Vec,Vec);
72 PETSC_EXTERN PetscErrorCode KSPSolveTranspose(KSP,Vec,Vec);
73 PETSC_EXTERN PetscErrorCode KSPReset(KSP);
74 PETSC_EXTERN PetscErrorCode KSPDestroy(KSP*);
75 
76 PETSC_EXTERN PetscFList KSPList;
77 PETSC_EXTERN PetscBool KSPRegisterAllCalled;
78 PETSC_EXTERN PetscErrorCode KSPRegisterAll(const char[]);
79 PETSC_EXTERN PetscErrorCode KSPRegisterDestroy(void);
80 PETSC_EXTERN PetscErrorCode KSPRegister(const char[],const char[],const char[],PetscErrorCode (*)(KSP));
81 PETSC_EXTERN PetscErrorCode KSPMatRegisterAll(const char[]);
82 
83 /*MC
84    KSPRegisterDynamic - Adds a method to the Krylov subspace solver package.
85 
86    Synopsis:
87    PetscErrorCode KSPRegisterDynamic(const char *name_solver,const char *path,const char *name_create,PetscErrorCode (*routine_create)(KSP))
88 
89    Not Collective
90 
91    Input Parameters:
92 +  name_solver - name of a new user-defined solver
93 .  path - path (either absolute or relative) the library containing this solver
94 .  name_create - name of routine to create method context
95 -  routine_create - routine to create method context
96 
97    Notes:
98    KSPRegisterDynamic() may be called multiple times to add several user-defined solvers.
99 
100    If dynamic libraries are used, then the fourth input argument (routine_create)
101    is ignored.
102 
103    Sample usage:
104 .vb
105    KSPRegisterDynamic("my_solver",/home/username/my_lib/lib/libO/solaris/mylib.a,
106                "MySolverCreate",MySolverCreate);
107 .ve
108 
109    Then, your solver can be chosen with the procedural interface via
110 $     KSPSetType(ksp,"my_solver")
111    or at runtime via the option
112 $     -ksp_type my_solver
113 
114    Level: advanced
115 
116    Notes: Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR},
117           and others of the form ${any_environmental_variable} occuring in pathname will be
118           replaced with appropriate values.
119          If your function is not being put into a shared library then use KSPRegister() instead
120 
121 .keywords: KSP, register
122 
123 .seealso: KSPRegisterAll(), KSPRegisterDestroy()
124 
125 M*/
126 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
127 #define KSPRegisterDynamic(a,b,c,d) KSPRegister(a,b,c,0)
128 #else
129 #define KSPRegisterDynamic(a,b,c,d) KSPRegister(a,b,c,d)
130 #endif
131 
132 PETSC_EXTERN PetscErrorCode KSPGetType(KSP,KSPType *);
133 PETSC_EXTERN PetscErrorCode KSPSetPCSide(KSP,PCSide);
134 PETSC_EXTERN PetscErrorCode KSPGetPCSide(KSP,PCSide*);
135 PETSC_EXTERN PetscErrorCode KSPGetTolerances(KSP,PetscReal*,PetscReal*,PetscReal*,PetscInt*);
136 PETSC_EXTERN PetscErrorCode KSPSetTolerances(KSP,PetscReal,PetscReal,PetscReal,PetscInt);
137 PETSC_EXTERN PetscErrorCode KSPSetInitialGuessNonzero(KSP,PetscBool );
138 PETSC_EXTERN PetscErrorCode KSPGetInitialGuessNonzero(KSP,PetscBool  *);
139 PETSC_EXTERN PetscErrorCode KSPSetInitialGuessKnoll(KSP,PetscBool );
140 PETSC_EXTERN PetscErrorCode KSPGetInitialGuessKnoll(KSP,PetscBool *);
141 PETSC_EXTERN PetscErrorCode KSPSetErrorIfNotConverged(KSP,PetscBool );
142 PETSC_EXTERN PetscErrorCode KSPGetErrorIfNotConverged(KSP,PetscBool  *);
143 PETSC_EXTERN PetscErrorCode KSPGetComputeEigenvalues(KSP,PetscBool *);
144 PETSC_EXTERN PetscErrorCode KSPSetComputeEigenvalues(KSP,PetscBool );
145 PETSC_EXTERN PetscErrorCode KSPGetComputeSingularValues(KSP,PetscBool *);
146 PETSC_EXTERN PetscErrorCode KSPSetComputeSingularValues(KSP,PetscBool );
147 PETSC_EXTERN PetscErrorCode KSPGetRhs(KSP,Vec *);
148 PETSC_EXTERN PetscErrorCode KSPGetSolution(KSP,Vec *);
149 PETSC_EXTERN PetscErrorCode KSPGetResidualNorm(KSP,PetscReal*);
150 PETSC_EXTERN PetscErrorCode KSPGetIterationNumber(KSP,PetscInt*);
151 PETSC_EXTERN PetscErrorCode KSPSetNullSpace(KSP,MatNullSpace);
152 PETSC_EXTERN PetscErrorCode KSPGetNullSpace(KSP,MatNullSpace*);
153 PETSC_EXTERN PetscErrorCode KSPGetVecs(KSP,PetscInt,Vec**,PetscInt,Vec**);
154 
155 PETSC_EXTERN PetscErrorCode KSPSetPC(KSP,PC);
156 PETSC_EXTERN PetscErrorCode KSPGetPC(KSP,PC*);
157 
158 PETSC_EXTERN PetscErrorCode KSPMonitor(KSP,PetscInt,PetscReal);
159 PETSC_EXTERN PetscErrorCode KSPMonitorSet(KSP,PetscErrorCode (*)(KSP,PetscInt,PetscReal,void*),void *,PetscErrorCode (*)(void**));
160 PETSC_EXTERN PetscErrorCode KSPMonitorCancel(KSP);
161 PETSC_EXTERN PetscErrorCode KSPGetMonitorContext(KSP,void **);
162 PETSC_EXTERN PetscErrorCode KSPGetResidualHistory(KSP,PetscReal*[],PetscInt *);
163 PETSC_EXTERN PetscErrorCode KSPSetResidualHistory(KSP,PetscReal[],PetscInt,PetscBool );
164 
165 /* not sure where to put this */
166 PETSC_EXTERN PetscErrorCode PCKSPGetKSP(PC,KSP*);
167 PETSC_EXTERN PetscErrorCode PCBJacobiGetSubKSP(PC,PetscInt*,PetscInt*,KSP*[]);
168 PETSC_EXTERN PetscErrorCode PCASMGetSubKSP(PC,PetscInt*,PetscInt*,KSP*[]);
169 PETSC_EXTERN PetscErrorCode PCGASMGetSubKSP(PC,PetscInt*,PetscInt*,KSP*[]);
170 PETSC_EXTERN PetscErrorCode PCFieldSplitGetSubKSP(PC,PetscInt*,KSP*[]);
171 
172 PETSC_EXTERN PetscErrorCode PCGalerkinGetKSP(PC,KSP *);
173 
174 PETSC_EXTERN PetscErrorCode KSPBuildSolution(KSP,Vec,Vec *);
175 PETSC_EXTERN PetscErrorCode KSPBuildResidual(KSP,Vec,Vec,Vec *);
176 
177 PETSC_EXTERN PetscErrorCode KSPRichardsonSetScale(KSP,PetscReal);
178 PETSC_EXTERN PetscErrorCode KSPRichardsonSetSelfScale(KSP,PetscBool );
179 PETSC_EXTERN PetscErrorCode KSPChebyshevSetEigenvalues(KSP,PetscReal,PetscReal);
180 PETSC_EXTERN PetscErrorCode KSPChebyshevSetEstimateEigenvalues(KSP,PetscReal,PetscReal,PetscReal,PetscReal);
181 PETSC_EXTERN PetscErrorCode KSPChebyshevSetNewMatrix(KSP);
182 PETSC_EXTERN PetscErrorCode KSPComputeExtremeSingularValues(KSP,PetscReal*,PetscReal*);
183 PETSC_EXTERN PetscErrorCode KSPComputeEigenvalues(KSP,PetscInt,PetscReal*,PetscReal*,PetscInt *);
184 PETSC_EXTERN PetscErrorCode KSPComputeEigenvaluesExplicitly(KSP,PetscInt,PetscReal*,PetscReal*);
185 
186 PETSC_EXTERN PetscErrorCode KSPGMRESSetRestart(KSP, PetscInt);
187 PETSC_EXTERN PetscErrorCode KSPGMRESGetRestart(KSP, PetscInt*);
188 PETSC_EXTERN PetscErrorCode KSPGMRESSetHapTol(KSP,PetscReal);
189 
190 PETSC_EXTERN PetscErrorCode KSPGMRESSetPreAllocateVectors(KSP);
191 PETSC_EXTERN PetscErrorCode KSPGMRESSetOrthogonalization(KSP,PetscErrorCode (*)(KSP,PetscInt));
192 PETSC_EXTERN PetscErrorCode KSPGMRESGetOrthogonalization(KSP,PetscErrorCode (**)(KSP,PetscInt));
193 PETSC_EXTERN PetscErrorCode KSPGMRESModifiedGramSchmidtOrthogonalization(KSP,PetscInt);
194 PETSC_EXTERN PetscErrorCode KSPGMRESClassicalGramSchmidtOrthogonalization(KSP,PetscInt);
195 
196 PETSC_EXTERN PetscErrorCode KSPLGMRESSetAugDim(KSP,PetscInt);
197 PETSC_EXTERN PetscErrorCode KSPLGMRESSetConstant(KSP);
198 
199 PETSC_EXTERN PetscErrorCode KSPGCRSetRestart(KSP,PetscInt);
200 PETSC_EXTERN PetscErrorCode KSPGCRGetRestart(KSP,PetscInt*);
201 PETSC_EXTERN PetscErrorCode KSPGCRSetModifyPC(KSP,PetscErrorCode (*)(KSP,PetscInt,PetscReal,void*),void*,PetscErrorCode(*)(void*));
202 
203 /*E
204     KSPGMRESCGSRefinementType - How the classical (unmodified) Gram-Schmidt is performed.
205 
206    Level: advanced
207 
208 .seealso: KSPGMRESClassicalGramSchmidtOrthogonalization(), KSPGMRESSetOrthogonalization(), KSPGMRESGetOrthogonalization(),
209           KSPGMRESSetCGSRefinementType(), KSPGMRESGetCGSRefinementType(), KSPGMRESModifiedGramSchmidtOrthogonalization()
210 
211 E*/
212 typedef enum {KSP_GMRES_CGS_REFINE_NEVER, KSP_GMRES_CGS_REFINE_IFNEEDED, KSP_GMRES_CGS_REFINE_ALWAYS} KSPGMRESCGSRefinementType;
213 PETSC_EXTERN const char *const KSPGMRESCGSRefinementTypes[];
214 /*MC
215     KSP_GMRES_CGS_REFINE_NEVER - Just do the classical (unmodified) Gram-Schmidt process
216 
217    Level: advanced
218 
219    Note: Possible unstable, but the fastest to compute
220 
221 .seealso: KSPGMRESClassicalGramSchmidtOrthogonalization(), KSPGMRESSetOrthogonalization(), KSPGMRESGetOrthogonalization(),
222           KSPGMRESSetCGSRefinementType(), KSPGMRESGetCGSRefinementType(), KSP_GMRES_CGS_REFINE_IFNEEDED, KSP_GMRES_CGS_REFINE_ALWAYS,
223           KSPGMRESModifiedGramSchmidtOrthogonalization()
224 M*/
225 
226 /*MC
227     KSP_GMRES_CGS_REFINE_IFNEEDED - Do the classical (unmodified) Gram-Schmidt process and one step of
228           iterative refinement if an estimate of the orthogonality of the resulting vectors indicates
229           poor orthogonality.
230 
231    Level: advanced
232 
233    Note: This is slower than KSP_GMRES_CGS_REFINE_NEVER because it requires an extra norm computation to
234      estimate the orthogonality but is more stable.
235 
236 .seealso: KSPGMRESClassicalGramSchmidtOrthogonalization(), KSPGMRESSetOrthogonalization(), KSPGMRESGetOrthogonalization(),
237           KSPGMRESSetCGSRefinementType(), KSPGMRESGetCGSRefinementType(), KSP_GMRES_CGS_REFINE_NEVER, KSP_GMRES_CGS_REFINE_ALWAYS,
238           KSPGMRESModifiedGramSchmidtOrthogonalization()
239 M*/
240 
241 /*MC
242     KSP_GMRES_CGS_REFINE_NEVER - Do two steps of the classical (unmodified) Gram-Schmidt process.
243 
244    Level: advanced
245 
246    Note: This is roughly twice the cost of KSP_GMRES_CGS_REFINE_NEVER because it performs the process twice
247      but it saves the extra norm calculation needed by KSP_GMRES_CGS_REFINE_IFNEEDED.
248 
249         You should only use this if you absolutely know that the iterative refinement is needed.
250 
251 .seealso: KSPGMRESClassicalGramSchmidtOrthogonalization(), KSPGMRESSetOrthogonalization(), KSPGMRESGetOrthogonalization(),
252           KSPGMRESSetCGSRefinementType(), KSPGMRESGetCGSRefinementType(), KSP_GMRES_CGS_REFINE_IFNEEDED, KSP_GMRES_CGS_REFINE_ALWAYS,
253           KSPGMRESModifiedGramSchmidtOrthogonalization()
254 M*/
255 
256 PETSC_EXTERN PetscErrorCode KSPGMRESSetCGSRefinementType(KSP,KSPGMRESCGSRefinementType);
257 PETSC_EXTERN PetscErrorCode KSPGMRESGetCGSRefinementType(KSP,KSPGMRESCGSRefinementType*);
258 
259 PETSC_EXTERN PetscErrorCode KSPFGMRESModifyPCNoChange(KSP,PetscInt,PetscInt,PetscReal,void*);
260 PETSC_EXTERN PetscErrorCode KSPFGMRESModifyPCKSP(KSP,PetscInt,PetscInt,PetscReal,void*);
261 PETSC_EXTERN PetscErrorCode KSPFGMRESSetModifyPC(KSP,PetscErrorCode (*)(KSP,PetscInt,PetscInt,PetscReal,void*),void*,PetscErrorCode(*)(void*));
262 
263 PETSC_EXTERN PetscErrorCode KSPQCGSetTrustRegionRadius(KSP,PetscReal);
264 PETSC_EXTERN PetscErrorCode KSPQCGGetQuadratic(KSP,PetscReal*);
265 PETSC_EXTERN PetscErrorCode KSPQCGGetTrialStepNorm(KSP,PetscReal*);
266 
267 PETSC_EXTERN PetscErrorCode KSPBCGSLSetXRes(KSP,PetscReal);
268 PETSC_EXTERN PetscErrorCode KSPBCGSLSetPol(KSP,PetscBool );
269 PETSC_EXTERN PetscErrorCode KSPBCGSLSetEll(KSP,PetscInt);
270 
271 PETSC_EXTERN PetscErrorCode KSPSetFromOptions(KSP);
272 PETSC_EXTERN PetscErrorCode KSPAddOptionsChecker(PetscErrorCode (*)(KSP));
273 
274 PETSC_EXTERN PetscErrorCode KSPMonitorSingularValue(KSP,PetscInt,PetscReal,void *);
275 PETSC_EXTERN PetscErrorCode KSPMonitorDefault(KSP,PetscInt,PetscReal,void *);
276 PETSC_EXTERN PetscErrorCode KSPLSQRMonitorDefault(KSP,PetscInt,PetscReal,void *);
277 PETSC_EXTERN PetscErrorCode KSPMonitorRange(KSP,PetscInt,PetscReal,void *);
278 PETSC_EXTERN PetscErrorCode KSPMonitorDynamicTolerance(KSP ksp,PetscInt its,PetscReal fnorm,void *dummy);
279 PETSC_EXTERN PetscErrorCode KSPMonitorDynamicToleranceDestroy(void **dummy);
280 PETSC_EXTERN PetscErrorCode KSPMonitorTrueResidualNorm(KSP,PetscInt,PetscReal,void *);
281 PETSC_EXTERN PetscErrorCode KSPMonitorTrueResidualMaxNorm(KSP,PetscInt,PetscReal,void *);
282 PETSC_EXTERN PetscErrorCode KSPMonitorDefaultShort(KSP,PetscInt,PetscReal,void *);
283 PETSC_EXTERN PetscErrorCode KSPMonitorSolution(KSP,PetscInt,PetscReal,void *);
284 PETSC_EXTERN PetscErrorCode KSPMonitorAMS(KSP,PetscInt,PetscReal,void*);
285 PETSC_EXTERN PetscErrorCode KSPMonitorAMSCreate(KSP,const char*,void**);
286 PETSC_EXTERN PetscErrorCode KSPMonitorAMSDestroy(void**);
287 PETSC_EXTERN PetscErrorCode KSPGMRESMonitorKrylov(KSP,PetscInt,PetscReal,void *);
288 
289 PETSC_EXTERN PetscErrorCode KSPUnwindPreconditioner(KSP,Vec,Vec);
290 PETSC_EXTERN PetscErrorCode KSPDefaultBuildSolution(KSP,Vec,Vec*);
291 PETSC_EXTERN PetscErrorCode KSPDefaultBuildResidual(KSP,Vec,Vec,Vec *);
292 PETSC_EXTERN PetscErrorCode KSPInitialResidual(KSP,Vec,Vec,Vec,Vec,Vec);
293 
294 PETSC_EXTERN PetscErrorCode KSPSetOperators(KSP,Mat,Mat,MatStructure);
295 PETSC_EXTERN PetscErrorCode KSPGetOperators(KSP,Mat*,Mat*,MatStructure*);
296 PETSC_EXTERN PetscErrorCode KSPGetOperatorsSet(KSP,PetscBool *,PetscBool *);
297 PETSC_EXTERN PetscErrorCode KSPSetOptionsPrefix(KSP,const char[]);
298 PETSC_EXTERN PetscErrorCode KSPAppendOptionsPrefix(KSP,const char[]);
299 PETSC_EXTERN PetscErrorCode KSPGetOptionsPrefix(KSP,const char*[]);
300 PETSC_EXTERN PetscErrorCode KSPSetTabLevel(KSP,PetscInt);
301 PETSC_EXTERN PetscErrorCode KSPGetTabLevel(KSP,PetscInt*);
302 
303 PETSC_EXTERN PetscErrorCode KSPSetDiagonalScale(KSP,PetscBool );
304 PETSC_EXTERN PetscErrorCode KSPGetDiagonalScale(KSP,PetscBool *);
305 PETSC_EXTERN PetscErrorCode KSPSetDiagonalScaleFix(KSP,PetscBool );
306 PETSC_EXTERN PetscErrorCode KSPGetDiagonalScaleFix(KSP,PetscBool *);
307 
308 PETSC_EXTERN PetscErrorCode KSPView(KSP,PetscViewer);
309 
310 PETSC_EXTERN PetscErrorCode KSPLSQRSetStandardErrorVec(KSP,Vec);
311 PETSC_EXTERN PetscErrorCode KSPLSQRGetStandardErrorVec(KSP,Vec*);
312 
313 PETSC_EXTERN PetscErrorCode PCRedundantGetKSP(PC,KSP*);
314 PETSC_EXTERN PetscErrorCode PCRedistributeGetKSP(PC,KSP*);
315 
316 /*E
317     KSPNormType - Norm that is passed in the Krylov convergence
318        test routines.
319 
320    Level: advanced
321 
322    Each solver only supports a subset of these and some may support different ones
323    depending on left or right preconditioning, see KSPSetPCSide()
324 
325    Notes: this must match finclude/petscksp.h
326 
327 .seealso: KSPSolve(), KSPGetConvergedReason(), KSPSetNormType(),
328           KSPSetConvergenceTest(), KSPSetPCSide()
329 E*/
330 typedef enum {KSP_NORM_DEFAULT = -1,KSP_NORM_NONE = 0,KSP_NORM_PRECONDITIONED = 1,KSP_NORM_UNPRECONDITIONED = 2,KSP_NORM_NATURAL = 3} KSPNormType;
331 #define KSP_NORM_MAX (KSP_NORM_NATURAL + 1)
332 PETSC_EXTERN const char *const*const KSPNormTypes;
333 
334 /*MC
335     KSP_NORM_NONE - Do not compute a norm during the Krylov process. This will
336           possibly save some computation but means the convergence test cannot
337           be based on a norm of a residual etc.
338 
339    Level: advanced
340 
341     Note: Some Krylov methods need to compute a residual norm and then this option is ignored
342 
343 .seealso: KSPNormType, KSPSetNormType(), KSP_NORM_PRECONDITIONED, KSP_NORM_UNPRECONDITIONED, KSP_NORM_NATURAL
344 M*/
345 
346 /*MC
347     KSP_NORM_PRECONDITIONED - Compute the norm of the preconditioned residual and pass that to the
348        convergence test routine.
349 
350    Level: advanced
351 
352 .seealso: KSPNormType, KSPSetNormType(), KSP_NORM_NONE, KSP_NORM_UNPRECONDITIONED, KSP_NORM_NATURAL, KSPSetConvergenceTest()
353 M*/
354 
355 /*MC
356     KSP_NORM_UNPRECONDITIONED - Compute the norm of the true residual (b - A*x) and pass that to the
357        convergence test routine.
358 
359    Level: advanced
360 
361 .seealso: KSPNormType, KSPSetNormType(), KSP_NORM_NONE, KSP_NORM_PRECONDITIONED, KSP_NORM_NATURAL, KSPSetConvergenceTest()
362 M*/
363 
364 /*MC
365     KSP_NORM_NATURAL - Compute the 'natural norm' of residual sqrt((b - A*x)*B*(b - A*x)) and pass that to the
366        convergence test routine. This is only supported by  KSPCG, KSPCR, KSPCGNE, KSPCGS
367 
368    Level: advanced
369 
370 .seealso: KSPNormType, KSPSetNormType(), KSP_NORM_NONE, KSP_NORM_PRECONDITIONED, KSP_NORM_UNPRECONDITIONED, KSPSetConvergenceTest()
371 M*/
372 
373 PETSC_EXTERN PetscErrorCode KSPSetNormType(KSP,KSPNormType);
374 PETSC_EXTERN PetscErrorCode KSPGetNormType(KSP,KSPNormType*);
375 PETSC_EXTERN PetscErrorCode KSPSetSupportedNorm(KSP ksp,KSPNormType,PCSide,PetscInt);
376 PETSC_EXTERN PetscErrorCode KSPSetCheckNormIteration(KSP,PetscInt);
377 PETSC_EXTERN PetscErrorCode KSPSetLagNorm(KSP,PetscBool );
378 
379 /*E
380     KSPConvergedReason - reason a Krylov method was said to
381          have converged or diverged
382 
383    Level: beginner
384 
385    Notes: See KSPGetConvergedReason() for explanation of each value
386 
387    Developer notes: this must match finclude/petscksp.h
388 
389       The string versions of these are KSPConvergedReasons; if you change
390       any of the values here also change them that array of names.
391 
392 .seealso: KSPSolve(), KSPGetConvergedReason(), KSPSetTolerances()
393 E*/
394 typedef enum {/* converged */
395               KSP_CONVERGED_RTOL_NORMAL        =  1,
396               KSP_CONVERGED_ATOL_NORMAL        =  9,
397               KSP_CONVERGED_RTOL               =  2,
398               KSP_CONVERGED_ATOL               =  3,
399               KSP_CONVERGED_ITS                =  4,
400               KSP_CONVERGED_CG_NEG_CURVE       =  5,
401               KSP_CONVERGED_CG_CONSTRAINED     =  6,
402               KSP_CONVERGED_STEP_LENGTH        =  7,
403               KSP_CONVERGED_HAPPY_BREAKDOWN    =  8,
404               /* diverged */
405               KSP_DIVERGED_NULL                = -2,
406               KSP_DIVERGED_ITS                 = -3,
407               KSP_DIVERGED_DTOL                = -4,
408               KSP_DIVERGED_BREAKDOWN           = -5,
409               KSP_DIVERGED_BREAKDOWN_BICG      = -6,
410               KSP_DIVERGED_NONSYMMETRIC        = -7,
411               KSP_DIVERGED_INDEFINITE_PC       = -8,
412               KSP_DIVERGED_NAN                 = -9,
413               KSP_DIVERGED_INDEFINITE_MAT      = -10,
414 
415               KSP_CONVERGED_ITERATING          =  0} KSPConvergedReason;
416 PETSC_EXTERN const char *const*KSPConvergedReasons;
417 
418 /*MC
419      KSP_CONVERGED_RTOL - norm(r) <= rtol*norm(b)
420 
421    Level: beginner
422 
423    See KSPNormType and KSPSetNormType() for possible norms that may be used. By default
424        for left preconditioning it is the 2-norm of the preconditioned residual, and the
425        2-norm of the residual for right preconditioning
426 
427 .seealso:  KSPSolve(), KSPGetConvergedReason(), KSPConvergedReason, KSPSetTolerances()
428 
429 M*/
430 
431 /*MC
432      KSP_CONVERGED_ATOL - norm(r) <= atol
433 
434    Level: beginner
435 
436    See KSPNormType and KSPSetNormType() for possible norms that may be used. By default
437        for left preconditioning it is the 2-norm of the preconditioned residual, and the
438        2-norm of the residual for right preconditioning
439 
440    Level: beginner
441 
442 .seealso:  KSPSolve(), KSPGetConvergedReason(), KSPConvergedReason, KSPSetTolerances()
443 
444 M*/
445 
446 /*MC
447      KSP_DIVERGED_DTOL - norm(r) >= dtol*norm(b)
448 
449    Level: beginner
450 
451    See KSPNormType and KSPSetNormType() for possible norms that may be used. By default
452        for left preconditioning it is the 2-norm of the preconditioned residual, and the
453        2-norm of the residual for right preconditioning
454 
455    Level: beginner
456 
457 .seealso:  KSPSolve(), KSPGetConvergedReason(), KSPConvergedReason, KSPSetTolerances()
458 
459 M*/
460 
461 /*MC
462      KSP_DIVERGED_ITS - Ran out of iterations before any convergence criteria was
463       reached
464 
465    Level: beginner
466 
467 .seealso:  KSPSolve(), KSPGetConvergedReason(), KSPConvergedReason, KSPSetTolerances()
468 
469 M*/
470 
471 /*MC
472      KSP_CONVERGED_ITS - Used by the KSPPREONLY solver after the single iteration of
473            the preconditioner is applied. Also used when the KSPSkipConverged() convergence
474            test routine is set in KSP.
475 
476 
477    Level: beginner
478 
479 
480 .seealso:  KSPSolve(), KSPGetConvergedReason(), KSPConvergedReason, KSPSetTolerances()
481 
482 M*/
483 
484 /*MC
485      KSP_DIVERGED_BREAKDOWN - A breakdown in the Krylov method was detected so the
486           method could not continue to enlarge the Krylov space. Could be due to a singlular matrix or
487           preconditioner.
488 
489    Level: beginner
490 
491 .seealso:  KSPSolve(), KSPGetConvergedReason(), KSPConvergedReason, KSPSetTolerances()
492 
493 M*/
494 
495 /*MC
496      KSP_DIVERGED_BREAKDOWN_BICG - A breakdown in the KSPBICG method was detected so the
497           method could not continue to enlarge the Krylov space.
498 
499 
500    Level: beginner
501 
502 
503 .seealso:  KSPSolve(), KSPGetConvergedReason(), KSPConvergedReason, KSPSetTolerances()
504 
505 M*/
506 
507 /*MC
508      KSP_DIVERGED_NONSYMMETRIC - It appears the operator or preconditioner is not
509         symmetric and this Krylov method (KSPCG, KSPMINRES, KSPCR) requires symmetry
510 
511    Level: beginner
512 
513 .seealso:  KSPSolve(), KSPGetConvergedReason(), KSPConvergedReason, KSPSetTolerances()
514 
515 M*/
516 
517 /*MC
518      KSP_DIVERGED_INDEFINITE_PC - It appears the preconditioner is indefinite (has both
519         positive and negative eigenvalues) and this Krylov method (KSPCG) requires it to
520         be positive definite
521 
522    Level: beginner
523 
524      Notes: This can happen with the PCICC preconditioner, use -pc_factor_shift_positive_definite to force
525   the PCICC preconditioner to generate a positive definite preconditioner
526 
527 .seealso:  KSPSolve(), KSPGetConvergedReason(), KSPConvergedReason, KSPSetTolerances()
528 
529 M*/
530 
531 /*MC
532      KSP_CONVERGED_ITERATING - This flag is returned if you call KSPGetConvergedReason()
533         while the KSPSolve() is still running.
534 
535    Level: beginner
536 
537 .seealso:  KSPSolve(), KSPGetConvergedReason(), KSPConvergedReason, KSPSetTolerances()
538 
539 M*/
540 
541 PETSC_EXTERN PetscErrorCode KSPSetConvergenceTest(KSP,PetscErrorCode (*)(KSP,PetscInt,PetscReal,KSPConvergedReason*,void*),void *,PetscErrorCode (*)(void*));
542 PETSC_EXTERN PetscErrorCode KSPGetConvergenceContext(KSP,void **);
543 PETSC_EXTERN PetscErrorCode KSPDefaultConverged(KSP,PetscInt,PetscReal,KSPConvergedReason*,void *);
544 PETSC_EXTERN PetscErrorCode KSPConvergedLSQR(KSP,PetscInt,PetscReal,KSPConvergedReason*,void *);
545 PETSC_EXTERN PetscErrorCode KSPDefaultConvergedDestroy(void *);
546 PETSC_EXTERN PetscErrorCode KSPDefaultConvergedCreate(void **);
547 PETSC_EXTERN PetscErrorCode KSPDefaultConvergedSetUIRNorm(KSP);
548 PETSC_EXTERN PetscErrorCode KSPDefaultConvergedSetUMIRNorm(KSP);
549 PETSC_EXTERN PetscErrorCode KSPSkipConverged(KSP,PetscInt,PetscReal,KSPConvergedReason*,void *);
550 PETSC_EXTERN PetscErrorCode KSPGetConvergedReason(KSP,KSPConvergedReason *);
551 
552 PETSC_EXTERN PetscErrorCode KSPComputeExplicitOperator(KSP,Mat *);
553 
554 /*E
555     KSPCGType - Determines what type of CG to use
556 
557    Level: beginner
558 
559 .seealso: KSPCGSetType()
560 E*/
561 typedef enum {KSP_CG_SYMMETRIC=0,KSP_CG_HERMITIAN=1} KSPCGType;
562 PETSC_EXTERN const char *const KSPCGTypes[];
563 
564 PETSC_EXTERN PetscErrorCode KSPCGSetType(KSP,KSPCGType);
565 PETSC_EXTERN PetscErrorCode KSPCGUseSingleReduction(KSP,PetscBool );
566 
567 PETSC_EXTERN PetscErrorCode KSPNASHSetRadius(KSP,PetscReal);
568 PETSC_EXTERN PetscErrorCode KSPNASHGetNormD(KSP,PetscReal *);
569 PETSC_EXTERN PetscErrorCode KSPNASHGetObjFcn(KSP,PetscReal *);
570 
571 PETSC_EXTERN PetscErrorCode KSPSTCGSetRadius(KSP,PetscReal);
572 PETSC_EXTERN PetscErrorCode KSPSTCGGetNormD(KSP,PetscReal *);
573 PETSC_EXTERN PetscErrorCode KSPSTCGGetObjFcn(KSP,PetscReal *);
574 
575 PETSC_EXTERN PetscErrorCode KSPGLTRSetRadius(KSP,PetscReal);
576 PETSC_EXTERN PetscErrorCode KSPGLTRGetNormD(KSP,PetscReal *);
577 PETSC_EXTERN PetscErrorCode KSPGLTRGetObjFcn(KSP,PetscReal *);
578 PETSC_EXTERN PetscErrorCode KSPGLTRGetMinEig(KSP,PetscReal *);
579 PETSC_EXTERN PetscErrorCode KSPGLTRGetLambda(KSP,PetscReal *);
580 
581 PETSC_EXTERN PetscErrorCode KSPPythonSetType(KSP,const char[]);
582 
583 PETSC_EXTERN PetscErrorCode PCPreSolve(PC,KSP);
584 PETSC_EXTERN PetscErrorCode PCPostSolve(PC,KSP);
585 
586 PETSC_EXTERN PetscErrorCode KSPMonitorLGResidualNormCreate(const char[],const char[],int,int,int,int,PetscDrawLG*);
587 PETSC_EXTERN PetscErrorCode KSPMonitorLGResidualNorm(KSP,PetscInt,PetscReal,void*);
588 PETSC_EXTERN PetscErrorCode KSPMonitorLGResidualNormDestroy(PetscDrawLG*);
589 PETSC_EXTERN PetscErrorCode KSPMonitorLGTrueResidualNormCreate(MPI_Comm,const char[],const char[],int,int,int,int,PetscDrawLG*);
590 PETSC_EXTERN PetscErrorCode KSPMonitorLGTrueResidualNorm(KSP,PetscInt,PetscReal,void*);
591 PETSC_EXTERN PetscErrorCode KSPMonitorLGTrueResidualNormDestroy(PetscDrawLG*);
592 PETSC_EXTERN PetscErrorCode KSPMonitorLGRange(KSP,PetscInt,PetscReal,void*);
593 
594 PETSC_EXTERN PetscErrorCode PCShellSetPreSolve(PC,PetscErrorCode (*)(PC,KSP,Vec,Vec));
595 PETSC_EXTERN PetscErrorCode PCShellSetPostSolve(PC,PetscErrorCode (*)(PC,KSP,Vec,Vec));
596 
597 /* see src/ksp/ksp/interface/iguess.c */
598 typedef struct _p_KSPFischerGuess {PetscInt method,curl,maxl,refcnt;PetscBool  monitor;Mat mat; KSP ksp;}* KSPFischerGuess;
599 
600 PETSC_EXTERN PetscErrorCode KSPFischerGuessCreate(KSP,PetscInt,PetscInt,KSPFischerGuess*);
601 PETSC_EXTERN PetscErrorCode KSPFischerGuessDestroy(KSPFischerGuess*);
602 PETSC_EXTERN PetscErrorCode KSPFischerGuessReset(KSPFischerGuess);
603 PETSC_EXTERN PetscErrorCode KSPFischerGuessUpdate(KSPFischerGuess,Vec);
604 PETSC_EXTERN PetscErrorCode KSPFischerGuessFormGuess(KSPFischerGuess,Vec,Vec);
605 PETSC_EXTERN PetscErrorCode KSPFischerGuessSetFromOptions(KSPFischerGuess);
606 
607 PETSC_EXTERN PetscErrorCode KSPSetUseFischerGuess(KSP,PetscInt,PetscInt);
608 PETSC_EXTERN PetscErrorCode KSPSetFischerGuess(KSP,KSPFischerGuess);
609 PETSC_EXTERN PetscErrorCode KSPGetFischerGuess(KSP,KSPFischerGuess*);
610 
611 PETSC_EXTERN PetscErrorCode MatCreateSchurComplement(Mat,Mat,Mat,Mat,Mat,Mat*);
612 PETSC_EXTERN PetscErrorCode MatSchurComplementGetKSP(Mat,KSP*);
613 PETSC_EXTERN PetscErrorCode MatSchurComplementSetKSP(Mat,KSP);
614 PETSC_EXTERN PetscErrorCode MatSchurComplementSet(Mat,Mat,Mat,Mat,Mat,Mat);
615 PETSC_EXTERN PetscErrorCode MatSchurComplementUpdate(Mat,Mat,Mat,Mat,Mat,Mat,MatStructure);
616 PETSC_EXTERN PetscErrorCode MatSchurComplementGetSubmatrices(Mat,Mat*,Mat*,Mat*,Mat*,Mat*);
617 PETSC_EXTERN PetscErrorCode MatGetSchurComplement(Mat,IS,IS,IS,IS,MatReuse,Mat *,MatReuse,Mat *);
618 
619 PETSC_EXTERN PetscErrorCode MatGetSchurComplement_Basic(Mat mat,IS isrow0,IS iscol0,IS isrow1,IS iscol1,MatReuse mreuse,Mat *newmat,MatReuse preuse,Mat *newpmat);
620 
621 PETSC_EXTERN PetscErrorCode KSPSetDM(KSP,DM);
622 PETSC_EXTERN PetscErrorCode KSPSetDMActive(KSP,PetscBool );
623 PETSC_EXTERN PetscErrorCode KSPGetDM(KSP,DM*);
624 PETSC_EXTERN PetscErrorCode KSPSetApplicationContext(KSP,void*);
625 PETSC_EXTERN PetscErrorCode KSPGetApplicationContext(KSP,void*);
626 PETSC_EXTERN PetscErrorCode KSPSetComputeOperators(KSP,PetscErrorCode(*)(KSP,Mat,Mat,MatStructure*,void*),void*);
627 PETSC_EXTERN PetscErrorCode KSPSetComputeRHS(KSP,PetscErrorCode(*)(KSP,Vec,void*),void*);
628 PETSC_EXTERN PetscErrorCode DMKSPSetComputeOperators(DM,PetscErrorCode(*)(KSP,Mat,Mat,MatStructure*,void*),void*);
629 PETSC_EXTERN PetscErrorCode DMKSPGetComputeOperators(DM,PetscErrorCode(**)(KSP,Mat,Mat,MatStructure*,void*),void*);
630 PETSC_EXTERN PetscErrorCode DMKSPSetComputeRHS(DM,PetscErrorCode(*)(KSP,Vec,void*),void*);
631 PETSC_EXTERN PetscErrorCode DMKSPGetComputeRHS(DM,PetscErrorCode(**)(KSP,Vec,void*),void*);
632 
633 #endif
634