xref: /petsc/include/petscsnes.h (revision 97276fddab9e156c6aa2d4453777ea460476b6f0)
1f26ada1bSBarry Smith /*
2eef9c623SLois Curfman McInnes     User interface for the nonlinear solvers package.
3f26ada1bSBarry Smith */
4a4963045SJacob Faibussowitsch #pragma once
5ac09b921SBarry Smith 
62c8e378dSBarry Smith #include <petscksp.h>
71e25c274SJed Brown #include <petscdmtypes.h>
87ed8fce4SMatthew G. Knepley #include <petscfvtypes.h>
91e25c274SJed Brown #include <petscdmdatypes.h>
10e5148a0bSMatthew G. Knepley #include <petscsnestypes.h>
11b1f5cb9dSBarry Smith 
12ac09b921SBarry Smith /* SUBMANSEC = SNES */
13ac09b921SBarry Smith 
1476bdecfbSBarry Smith /*J
1516a05f60SBarry Smith    SNESType - String with the name of a PETSc `SNES` method.
16435da068SBarry Smith 
17435da068SBarry Smith    Level: beginner
18435da068SBarry Smith 
191cc06b55SBarry Smith .seealso: [](doc_nonlinsolve), [](ch_snes), `SNESSetType()`, `SNES`, `SNESCreate()`, `SNESDestroy()`, `SNESSetFromOptions()`
2076bdecfbSBarry Smith J*/
2119fd82e9SBarry Smith typedef const char *SNESType;
2204d7464bSBarry Smith #define SNESNEWTONLS         "newtonls"
2304d7464bSBarry Smith #define SNESNEWTONTR         "newtontr"
2441ba4c6cSHeeho Park #define SNESNEWTONTRDC       "newtontrdc"
251d6018f0SLisandro Dalcin #define SNESPYTHON           "python"
26d5c3842bSBarry Smith #define SNESNRICHARDSON      "nrichardson"
27b79b07cfSJed Brown #define SNESKSPONLY          "ksponly"
281ef27442SStefano Zampini #define SNESKSPTRANSPOSEONLY "ksptransposeonly"
29f450aa47SBarry Smith #define SNESVINEWTONRSLS     "vinewtonrsls"
30f450aa47SBarry Smith #define SNESVINEWTONSSLS     "vinewtonssls"
314a0c5b0cSMatthew G Knepley #define SNESNGMRES           "ngmres"
324b11644fSPeter Brune #define SNESQN               "qn"
33c5ae4b9aSBarry Smith #define SNESSHELL            "shell"
34be95d8f1SBarry Smith #define SNESNGS              "ngs"
35fef7b6d8SPeter Brune #define SNESNCG              "ncg"
36421d9b32SPeter Brune #define SNESFAS              "fas"
3737e1895aSJed Brown #define SNESMS               "ms"
38eaedb033SPeter Brune #define SNESNASM             "nasm"
39f31c9d25SPeter Brune #define SNESANDERSON         "anderson"
40d728fb7dSPeter Brune #define SNESASPIN            "aspin"
41eed5f15bSPeter Brune #define SNESCOMPOSITE        "composite"
42561742edSMatthew G. Knepley #define SNESPATCH            "patch"
43*97276fddSZach Atkins #define SNESNEWTONAL         "newtonal"
44d5c3842bSBarry Smith 
45deeb6e72SMatthew Knepley /* Logging support */
46014dd563SJed Brown PETSC_EXTERN PetscClassId SNES_CLASSID;
4722c6f798SBarry Smith PETSC_EXTERN PetscClassId DMSNES_CLASSID;
48deeb6e72SMatthew Knepley 
49607a6623SBarry Smith PETSC_EXTERN PetscErrorCode SNESInitializePackage(void);
504bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode SNESFinalizePackage(void);
51deeb6e72SMatthew Knepley 
52014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESCreate(MPI_Comm, SNES *);
5377e5a1f9SBarry Smith PETSC_EXTERN PetscErrorCode SNESParametersInitialize(SNES);
54014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESReset(SNES);
55014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESDestroy(SNES *);
5619fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetType(SNES, SNESType);
57014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitor(SNES, PetscInt, PetscReal);
58014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorSet(SNES, PetscErrorCode (*)(SNES, PetscInt, PetscReal, void *), void *, PetscErrorCode (*)(void **));
59d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorSetFromOptions(SNES, const char[], const char[], const char[], PetscErrorCode (*)(SNES, PetscInt, PetscReal, PetscViewerAndFormat *), PetscErrorCode (*)(SNES, PetscViewerAndFormat *));
60014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorCancel(SNES);
618a70d858SHong Zhang PETSC_EXTERN PetscErrorCode SNESMonitorSAWs(SNES, PetscInt, PetscReal, void *);
628a70d858SHong Zhang PETSC_EXTERN PetscErrorCode SNESMonitorSAWsCreate(SNES, void **);
638a70d858SHong Zhang PETSC_EXTERN PetscErrorCode SNESMonitorSAWsDestroy(void **);
64014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetConvergenceHistory(SNES, PetscReal[], PetscInt[], PetscInt, PetscBool);
65014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetConvergenceHistory(SNES, PetscReal *[], PetscInt *[], PetscInt *);
66014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetUp(SNES);
67014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSolve(SNES, Vec, Vec);
68014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetErrorIfNotConverged(SNES, PetscBool);
69014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetErrorIfNotConverged(SNES, PetscBool *);
702d157150SStefano Zampini PETSC_EXTERN PetscErrorCode SNESConverged(SNES, PetscInt, PetscReal, PetscReal, PetscReal);
71e113a28aSBarry Smith 
72fa0ddf94SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetWorkVecs(SNES, PetscInt);
7384cb2905SBarry Smith 
74014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESAddOptionsChecker(PetscErrorCode (*)(SNES));
754d8f6ca9SMatthew Knepley 
76bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode SNESRegister(const char[], PetscErrorCode (*)(SNES));
7730de9b25SBarry Smith 
78014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetKSP(SNES, KSP *);
79014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetKSP(SNES, KSP);
803cd8a7caSMatthew G. Knepley PETSC_EXTERN PetscErrorCode SNESSetSolution(SNES, Vec);
81014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetSolution(SNES, Vec *);
82014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetSolutionUpdate(SNES, Vec *);
83014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetRhs(SNES, Vec *);
84014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESView(SNES, PetscViewer);
8555849f57SBarry Smith PETSC_EXTERN PetscErrorCode SNESLoad(SNES, PetscViewer);
86c4421ceaSFande Kong PETSC_EXTERN PetscErrorCode SNESConvergedReasonViewSet(SNES, PetscErrorCode (*)(SNES, void *), void *, PetscErrorCode (*)(void **));
87fe2efc57SMark PETSC_EXTERN PetscErrorCode SNESViewFromOptions(SNES, PetscObject, const char[]);
8819a666eeSBarry Smith PETSC_EXTERN PetscErrorCode SNESConvergedReasonView(SNES, PetscViewer);
8919a666eeSBarry Smith PETSC_EXTERN PetscErrorCode SNESConvergedReasonViewFromOptions(SNES);
90c4421ceaSFande Kong PETSC_EXTERN PetscErrorCode SNESConvergedReasonViewCancel(SNES);
9119a666eeSBarry Smith 
92edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 14, 0, "SNESConvergedReasonView()", ) static inline PetscErrorCode SNESReasonView(SNES snes, PetscViewer v)
93d71ae5a4SJacob Faibussowitsch {
949371c9d4SSatish Balay   return SNESConvergedReasonView(snes, v);
959371c9d4SSatish Balay }
96edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 14, 0, "SNESConvergedReasonViewFromOptions()", ) static inline PetscErrorCode SNESReasonViewFromOptions(SNES snes)
97d71ae5a4SJacob Faibussowitsch {
989371c9d4SSatish Balay   return SNESConvergedReasonViewFromOptions(snes);
999371c9d4SSatish Balay }
10055849f57SBarry Smith 
10155849f57SBarry Smith #define SNES_FILE_CLASSID 1211224
1027bc3d0afSSatish Balay 
103014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetOptionsPrefix(SNES, const char[]);
104014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESAppendOptionsPrefix(SNES, const char[]);
105014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetOptionsPrefix(SNES, const char *[]);
106014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetFromOptions(SNES);
10787d6299eSMatthew G. Knepley PETSC_EXTERN PetscErrorCode SNESResetFromOptions(SNES);
10840191667SLois Curfman McInnes 
1093565c898SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetUseMatrixFree(SNES, PetscBool, PetscBool);
1103565c898SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetUseMatrixFree(SNES, PetscBool *, PetscBool *);
111014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSNESMF(SNES, Mat *);
112bc13fc8dSBarry Smith PETSC_EXTERN PetscErrorCode MatSNESMFGetSNES(Mat, SNES *);
113208be567SBarry Smith PETSC_EXTERN PetscErrorCode MatSNESMFSetReuseBase(Mat, PetscBool);
114208be567SBarry Smith PETSC_EXTERN PetscErrorCode MatSNESMFGetReuseBase(Mat, PetscBool *);
115d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode MatMFFDComputeJacobian(SNES, Vec, Mat, Mat, void *);
116f6dfbefdSBarry Smith PETSC_EXTERN PetscErrorCode MatCreateSNESMFMore(SNES, Vec, Mat *);
117f6dfbefdSBarry Smith PETSC_EXTERN PetscErrorCode MatSNESMFMoreSetParameters(Mat, PetscReal, PetscReal, PetscReal);
1188f6e3e37SBarry Smith 
11919fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetType(SNES, SNESType *);
120fbcc4530SMatthew G. Knepley PETSC_EXTERN PetscErrorCode SNESMonitorDefaultSetUp(SNES, PetscViewerAndFormat *);
121d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorDefault(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
1221f60017eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorScaling(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
123d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorRange(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
124d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorRatio(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
125d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorRatioSetUp(SNES, PetscViewerAndFormat *);
126d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorSolution(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
127d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorResidual(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
128d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorSolutionUpdate(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
129d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorDefaultShort(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
130d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorDefaultField(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
131d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorJacUpdateSpectrum(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
132d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorFields(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
133798534f6SMatthew G. Knepley PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidual(KSP, PetscInt, PetscReal, PetscViewerAndFormat *);
134798534f6SMatthew G. Knepley PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidualDrawLG(KSP, PetscInt, PetscReal, PetscViewerAndFormat *);
135798534f6SMatthew G. Knepley PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidualDrawLGCreate(PetscViewer, PetscViewerFormat, void *, PetscViewerAndFormat **);
136e5f7ee39SBarry Smith 
137014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetTolerances(SNES, PetscReal, PetscReal, PetscReal, PetscInt, PetscInt);
138e4d06f11SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESSetDivergenceTolerance(SNES, PetscReal);
139014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetTolerances(SNES, PetscReal *, PetscReal *, PetscReal *, PetscInt *, PetscInt *);
140e4d06f11SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESGetDivergenceTolerance(SNES, PetscReal *);
141014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetTrustRegionTolerance(SNES, PetscReal);
14285216dc7SFande Kong PETSC_EXTERN PetscErrorCode SNESGetForceIteration(SNES, PetscBool *);
143be5caee7SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetForceIteration(SNES, PetscBool);
144014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetIterationNumber(SNES, PetscInt *);
145014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetIterationNumber(SNES, PetscInt);
1463d4c4710SBarry Smith 
1474a221d59SStefano Zampini /*E
1484a221d59SStefano Zampini    SNESNewtonTRFallbackType - type of fallback in case the solution of the trust-region subproblem is outside of the radius
1494a221d59SStefano Zampini 
1504a221d59SStefano Zampini    Values:
1514a221d59SStefano Zampini +  `SNES_TR_FALLBACK_NEWTON` - use scaled Newton step
1524a221d59SStefano Zampini .  `SNES_TR_FALLBACK_CAUCHY` - use Cauchy direction
1534a221d59SStefano Zampini -  `SNES_TR_FALLBACK_DOGLEG` - use dogleg method
15416a05f60SBarry Smith 
15516a05f60SBarry Smith    Level: intermediate
15616a05f60SBarry Smith 
1571cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESNEWTONTR`, `SNESNEWTONTRDC`
1584a221d59SStefano Zampini E*/
1594a221d59SStefano Zampini typedef enum {
1604a221d59SStefano Zampini   SNES_TR_FALLBACK_NEWTON,
1614a221d59SStefano Zampini   SNES_TR_FALLBACK_CAUCHY,
1624a221d59SStefano Zampini   SNES_TR_FALLBACK_DOGLEG,
1634a221d59SStefano Zampini } SNESNewtonTRFallbackType;
1644a221d59SStefano Zampini 
1654a221d59SStefano Zampini PETSC_EXTERN const char *const SNESNewtonTRFallbackTypes[];
1664a221d59SStefano Zampini 
167c9368356SGlenn Hammond PETSC_EXTERN PetscErrorCode SNESNewtonTRSetPreCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, PetscBool *, void *), void *ctx);
168c9368356SGlenn Hammond PETSC_EXTERN PetscErrorCode SNESNewtonTRGetPreCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, PetscBool *, void *), void **ctx);
169c9368356SGlenn Hammond PETSC_EXTERN PetscErrorCode SNESNewtonTRSetPostCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void *ctx);
170c9368356SGlenn Hammond PETSC_EXTERN PetscErrorCode SNESNewtonTRGetPostCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void **ctx);
1714a221d59SStefano Zampini PETSC_EXTERN PetscErrorCode SNESNewtonTRSetFallbackType(SNES, SNESNewtonTRFallbackType);
1724a221d59SStefano Zampini PETSC_EXTERN PetscErrorCode SNESNewtonTRPreCheck(SNES, Vec, Vec, PetscBool *);
1734a221d59SStefano Zampini PETSC_EXTERN PetscErrorCode SNESNewtonTRPostCheck(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *);
17424fb275aSStefano Zampini PETSC_EXTERN PetscErrorCode SNESNewtonTRSetNormType(SNES, NormType);
17524fb275aSStefano Zampini 
17624fb275aSStefano Zampini /*E
17724fb275aSStefano Zampini     SNESNewtonTRQNType - type of quasi-Newton model to use
17824fb275aSStefano Zampini 
17924fb275aSStefano Zampini    Values:
18024fb275aSStefano Zampini +  `SNES_TR_QN_NONE` - do not use a quasi-Newton model
18124fb275aSStefano Zampini .  `SNES_TR_QN_SAME` - use the same quasi-Newton model for matrix and preconditioner
18224fb275aSStefano Zampini -  `SNES_TR_QN_DIFFERENT` - use different quasi-Newton models for matrix and preconditioner
18324fb275aSStefano Zampini 
18424fb275aSStefano Zampini    Level: intermediate
18524fb275aSStefano Zampini 
18624fb275aSStefano Zampini .seealso: [](ch_snes), `SNES`, `SNESNEWTONTR`
18724fb275aSStefano Zampini E*/
18824fb275aSStefano Zampini typedef enum {
18924fb275aSStefano Zampini   SNES_TR_QN_NONE,
19024fb275aSStefano Zampini   SNES_TR_QN_SAME,
19124fb275aSStefano Zampini   SNES_TR_QN_DIFFERENT,
19224fb275aSStefano Zampini } SNESNewtonTRQNType;
19324fb275aSStefano Zampini 
19424fb275aSStefano Zampini PETSC_EXTERN const char *const SNESNewtonTRQNTypes[];
19524fb275aSStefano Zampini 
19624fb275aSStefano Zampini PETSC_EXTERN PetscErrorCode SNESNewtonTRSetQNType(SNES, SNESNewtonTRQNType);
1977cb011f5SBarry Smith 
19841ba4c6cSHeeho Park PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetRhoFlag(SNES, PetscBool *);
19941ba4c6cSHeeho Park PETSC_EXTERN PetscErrorCode SNESNewtonTRDCSetPreCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, PetscBool *, void *), void *ctx);
20041ba4c6cSHeeho Park PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetPreCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, PetscBool *, void *), void **ctx);
20141ba4c6cSHeeho Park PETSC_EXTERN PetscErrorCode SNESNewtonTRDCSetPostCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void *ctx);
20241ba4c6cSHeeho Park PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetPostCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void **ctx);
20341ba4c6cSHeeho Park 
204014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetNonlinearStepFailures(SNES, PetscInt *);
205014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetMaxNonlinearStepFailures(SNES, PetscInt);
206014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetMaxNonlinearStepFailures(SNES, PetscInt *);
207014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetNumberFunctionEvals(SNES, PetscInt *);
208b850b91aSLisandro Dalcin 
209014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetLagPreconditioner(SNES, PetscInt);
210014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLagPreconditioner(SNES, PetscInt *);
211014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetLagJacobian(SNES, PetscInt);
212014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLagJacobian(SNES, PetscInt *);
21337ec4e1aSPeter Brune PETSC_EXTERN PetscErrorCode SNESSetLagPreconditionerPersists(SNES, PetscBool);
21437ec4e1aSPeter Brune PETSC_EXTERN PetscErrorCode SNESSetLagJacobianPersists(SNES, PetscBool);
215014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetGridSequence(SNES, PetscInt);
216fa19ca70SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetGridSequence(SNES, PetscInt *);
217a8054027SBarry Smith 
218014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLinearSolveIterations(SNES, PetscInt *);
219014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLinearSolveFailures(SNES, PetscInt *);
220014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetMaxLinearSolveFailures(SNES, PetscInt);
221014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetMaxLinearSolveFailures(SNES, PetscInt *);
222971e163fSPeter Brune PETSC_EXTERN PetscErrorCode SNESSetCountersReset(SNES, PetscBool);
2233d4c4710SBarry Smith 
224014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESKSPSetUseEW(SNES, PetscBool);
225014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESKSPGetUseEW(SNES, PetscBool *);
226014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESKSPSetParametersEW(SNES, PetscInt, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal);
227014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESKSPGetParametersEW(SNES, PetscInt *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *);
228eafb4bcbSBarry Smith 
2299804daf3SBarry Smith #include <petscdrawtypes.h>
230014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorLGRange(SNES, PetscInt, PetscReal, void *);
231eafb4bcbSBarry Smith 
232014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetApplicationContext(SNES, void *);
233014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetApplicationContext(SNES, void *);
234014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetComputeApplicationContext(SNES, PetscErrorCode (*)(SNES, void **), PetscErrorCode (*)(void **));
235184914b5SBarry Smith 
236014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESPythonSetType(SNES, const char[]);
237ebead697SStefano Zampini PETSC_EXTERN PetscErrorCode SNESPythonGetType(SNES, const char *[]);
2381d6018f0SLisandro Dalcin 
239014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetFunctionDomainError(SNES);
240014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetFunctionDomainError(SNES, PetscBool *);
241cc6b0f04SFande Kong PETSC_EXTERN PetscErrorCode SNESGetJacobianDomainError(SNES, PetscBool *);
242cc6b0f04SFande Kong PETSC_EXTERN PetscErrorCode SNESSetJacobianDomainError(SNES);
243b351a90bSFande Kong PETSC_EXTERN PetscErrorCode SNESSetCheckJacobianDomainError(SNES, PetscBool);
2448383d7d7SFande Kong PETSC_EXTERN PetscErrorCode SNESGetCheckJacobianDomainError(SNES, PetscBool *);
2456a388c36SPeter Brune 
246edd03b47SJacob Faibussowitsch #define SNES_CONVERGED_TR_DELTA_DEPRECATED SNES_CONVERGED_TR_DELTA PETSC_DEPRECATED_ENUM(3, 12, 0, "SNES_DIVERGED_TR_DELTA", )
247435da068SBarry Smith /*E
248dc4c0fb0SBarry Smith     SNESConvergedReason - reason a `SNESSolve()` was determined to have converged or diverged
249435da068SBarry Smith 
250dc4c0fb0SBarry Smith    Values:
251dc4c0fb0SBarry Smith +  `SNES_CONVERGED_FNORM_ABS`      - 2-norm(F) <= abstol
252dc4c0fb0SBarry Smith .  `SNES_CONVERGED_FNORM_RELATIVE` - 2-norm(F) <= rtol*2-norm(F(x_0)) where x_0 is the initial guess
253dc4c0fb0SBarry Smith .  `SNES_CONVERGED_SNORM_RELATIVE` - The 2-norm of the last step <= stol * 2-norm(x) where x is the current
254dc4c0fb0SBarry Smith .  `SNES_DIVERGED_FUNCTION_COUNT`  - The user provided function has been called more times than the maximum set in `SNESSetTolerances()`
255dc4c0fb0SBarry Smith .  `SNES_DIVERGED_DTOL`            - The norm of the function has increased by a factor of divtol set with `SNESSetDivergenceTolerance()`
256dc4c0fb0SBarry Smith .  `SNES_DIVERGED_FNORM_NAN`       - the 2-norm of the current function evaluation is not-a-number (NaN), this
257dc4c0fb0SBarry Smith                                      is usually caused by a division of 0 by 0.
258dc4c0fb0SBarry Smith .  `SNES_DIVERGED_MAX_IT`          - `SNESSolve()` has reached the maximum number of iterations requested
259dc4c0fb0SBarry Smith .  `SNES_DIVERGED_LINE_SEARCH`     - The line search has failed. This only occurs for `SNES` solvers that use a line search
260dc4c0fb0SBarry Smith .  `SNES_DIVERGED_LOCAL_MIN`       - the algorithm seems to have stagnated at a local minimum that is not zero.
261dc4c0fb0SBarry Smith -  `SNES_CONERGED_ITERATING`       - this only occurs if `SNESGetConvergedReason()` is called during the `SNESSolve()`
262f203c74bSBarry Smith 
26316a05f60SBarry Smith    Level: beginner
26416a05f60SBarry Smith 
265dc4c0fb0SBarry Smith     Notes:
266dc4c0fb0SBarry Smith    The two most common reasons for divergence are an incorrectly coded or computed Jacobian or failure or lack of convergence in the linear system (in this case we recommend
267dc4c0fb0SBarry Smith    testing with `-pc_type lu` to eliminate the linear solver as the cause of the problem).
268dc4c0fb0SBarry Smith 
269dc4c0fb0SBarry Smith    `SNES_DIVERGED_LOCAL_MIN` can only occur when using the line-search variant of `SNES`.
270f203c74bSBarry Smith    The line search wants to minimize Q(alpha) = 1/2 || F(x + alpha s) ||^2_2  this occurs
271f203c74bSBarry Smith    at Q'(alpha) = s^T F'(x+alpha s)^T F(x+alpha s) = 0. If s is the Newton direction - F'(x)^(-1)F(x) then
272f203c74bSBarry Smith    you get Q'(alpha) = -F(x)^T F'(x)^(-1)^T F'(x+alpha s)F(x+alpha s); when alpha = 0
273f203c74bSBarry Smith    Q'(0) = - ||F(x)||^2_2 which is always NEGATIVE if F'(x) is invertible. This means the Newton
274f203c74bSBarry Smith    direction is a descent direction and the line search should succeed if alpha is small enough.
275f203c74bSBarry Smith 
276f203c74bSBarry Smith    If F'(x) is NOT invertible AND F'(x)^T F(x) = 0 then Q'(0) = 0 and the Newton direction
277f203c74bSBarry Smith    is NOT a descent direction so the line search will fail. All one can do at this point
278f203c74bSBarry Smith    is change the initial guess and try again.
279f203c74bSBarry Smith 
280f203c74bSBarry Smith    An alternative explanation: Newton's method can be regarded as replacing the function with
281f203c74bSBarry Smith    its linear approximation and minimizing the 2-norm of that. That is F(x+s) approx F(x) + F'(x)s
282f203c74bSBarry Smith    so we minimize || F(x) + F'(x) s ||^2_2; do this using Least Squares. If F'(x) is invertible then
283f203c74bSBarry Smith    s = - F'(x)^(-1)F(x) otherwise F'(x)^T F'(x) s = -F'(x)^T F(x). If F'(x)^T F(x) is NOT zero then there
2846aad120cSJose E. Roman    exists a nontrivial (that is F'(x)s != 0) solution to the equation and this direction is
285f203c74bSBarry Smith    s = - [F'(x)^T F'(x)]^(-1) F'(x)^T F(x) so Q'(0) = - F(x)^T F'(x) [F'(x)^T F'(x)]^(-T) F'(x)^T F(x)
286f203c74bSBarry Smith    = - (F'(x)^T F(x)) [F'(x)^T F'(x)]^(-T) (F'(x)^T F(x)). Since we are assuming (F'(x)^T F(x)) != 0
287f203c74bSBarry Smith    and F'(x)^T F'(x) has no negative eigenvalues Q'(0) < 0 so s is a descent direction and the line
288f203c74bSBarry Smith    search should succeed for small enough alpha.
289f203c74bSBarry Smith 
290f203c74bSBarry Smith    Note that this RARELY happens in practice. Far more likely the linear system is not being solved
291f203c74bSBarry Smith    (well enough?) or the Jacobian is wrong.
292f203c74bSBarry Smith 
29387497f52SBarry Smith    `SNES_DIVERGED_MAX_IT` means that the solver reached the maximum number of iterations without satisfying any
29487497f52SBarry Smith    convergence criteria. `SNES_CONVERGED_ITS` means that `SNESConvergedSkip()` was chosen as the convergence test;
2954d0a8057SBarry Smith    thus the usual convergence criteria have not been checked and may or may not be satisfied.
296f203c74bSBarry Smith 
2971cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPConvergedReason`, `SNESSetConvergenceTest()`, `SNESSetTolerances()`
298435da068SBarry Smith E*/
299184914b5SBarry Smith typedef enum {                       /* converged */
30001b82886SBarry Smith   SNES_CONVERGED_FNORM_ABS      = 2, /* ||F|| < atol */
30101b82886SBarry Smith   SNES_CONVERGED_FNORM_RELATIVE = 3, /* ||F|| < rtol*||F_initial|| */
3025358d0d4SBarry Smith   SNES_CONVERGED_SNORM_RELATIVE = 4, /* Newton computed step size small; || delta x || < stol || x ||*/
3033f149594SLisandro Dalcin   SNES_CONVERGED_ITS            = 5, /* maximum iterations reached */
30441ba4c6cSHeeho Park   SNES_BREAKOUT_INNER_ITER      = 6, /* Flag to break out of inner loop after checking custom convergence. */
30541ba4c6cSHeeho Park                                      /* it is used in multi-phase flow when state changes */
306184914b5SBarry Smith   /* diverged */
30746a9e3ceSBarry Smith   SNES_DIVERGED_FUNCTION_DOMAIN      = -1, /* the new x location passed the function is not in the domain of F */
308184914b5SBarry Smith   SNES_DIVERGED_FUNCTION_COUNT       = -2,
30946a9e3ceSBarry Smith   SNES_DIVERGED_LINEAR_SOLVE         = -3, /* the linear solve failed */
310184914b5SBarry Smith   SNES_DIVERGED_FNORM_NAN            = -4,
311184914b5SBarry Smith   SNES_DIVERGED_MAX_IT               = -5,
312647a2e1fSBarry Smith   SNES_DIVERGED_LINE_SEARCH          = -6,  /* the line search failed */
3131e633543SBarry Smith   SNES_DIVERGED_INNER                = -7,  /* inner solve failed */
31458c775ebSBarry Smith   SNES_DIVERGED_LOCAL_MIN            = -8,  /* || J^T b || is small, implies converged to local minimum of F() */
315e37c518bSBarry Smith   SNES_DIVERGED_DTOL                 = -9,  /* || F || > divtol*||F_initial|| */
31607b62357SFande Kong   SNES_DIVERGED_JACOBIAN_DOMAIN      = -10, /* Jacobian calculation does not make sense */
3171c6b2ff8SBarry Smith   SNES_DIVERGED_TR_DELTA             = -11,
318c78072a7SPatrick Sanan   SNES_CONVERGED_TR_DELTA_DEPRECATED = -11,
319e37c518bSBarry Smith 
3209371c9d4SSatish Balay   SNES_CONVERGED_ITERATING = 0
3219371c9d4SSatish Balay } SNESConvergedReason;
322014dd563SJed Brown PETSC_EXTERN const char *const *SNESConvergedReasons;
323184914b5SBarry Smith 
324c838673bSBarry Smith /*MC
325c838673bSBarry Smith    SNES_CONVERGED_FNORM_ABS - 2-norm(F) <= abstol
326c838673bSBarry Smith 
327c838673bSBarry Smith    Level: beginner
328c838673bSBarry Smith 
3291cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
330c838673bSBarry Smith M*/
331c838673bSBarry Smith 
332c838673bSBarry Smith /*MC
333c838673bSBarry Smith    SNES_CONVERGED_FNORM_RELATIVE - 2-norm(F) <= rtol*2-norm(F(x_0)) where x_0 is the initial guess
334c838673bSBarry Smith 
335c838673bSBarry Smith    Level: beginner
336c838673bSBarry Smith 
3371cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
338c838673bSBarry Smith M*/
339c838673bSBarry Smith 
340c838673bSBarry Smith /*MC
341c60f73f4SPeter Brune   SNES_CONVERGED_SNORM_RELATIVE - The 2-norm of the last step <= stol * 2-norm(x) where x is the current
34287497f52SBarry Smith   solution and stol is the 4th argument to `SNESSetTolerances()`
343c838673bSBarry Smith 
344af27ebaaSBarry Smith   Options Database Key:
345ae9be289SBarry Smith   -snes_stol <stol> - the step tolerance
346ae9be289SBarry Smith 
347c838673bSBarry Smith    Level: beginner
348c838673bSBarry Smith 
3491cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
350c838673bSBarry Smith M*/
351c838673bSBarry Smith 
352c838673bSBarry Smith /*MC
353c838673bSBarry Smith    SNES_DIVERGED_FUNCTION_COUNT - The user provided function has been called more times then the final
35487497f52SBarry Smith    argument to `SNESSetTolerances()`
355c838673bSBarry Smith 
356c838673bSBarry Smith    Level: beginner
357c838673bSBarry Smith 
3581cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
359c838673bSBarry Smith M*/
360c838673bSBarry Smith 
361c838673bSBarry Smith /*MC
36287497f52SBarry Smith    SNES_DIVERGED_DTOL - The norm of the function has increased by a factor of divtol set with `SNESSetDivergenceTolerance()`
363e37c518bSBarry Smith 
364e37c518bSBarry Smith    Level: beginner
365e37c518bSBarry Smith 
3661cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`, `SNESSetDivergenceTolerance()`
367e37c518bSBarry Smith M*/
368e37c518bSBarry Smith 
369e37c518bSBarry Smith /*MC
370c838673bSBarry Smith    SNES_DIVERGED_FNORM_NAN - the 2-norm of the current function evaluation is not-a-number (NaN), this
371c838673bSBarry Smith    is usually caused by a division of 0 by 0.
372c838673bSBarry Smith 
373c838673bSBarry Smith    Level: beginner
374c838673bSBarry Smith 
3751cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
376c838673bSBarry Smith M*/
377c838673bSBarry Smith 
378c838673bSBarry Smith /*MC
379c838673bSBarry Smith    SNES_DIVERGED_MAX_IT - SNESSolve() has reached the maximum number of iterations requested
380c838673bSBarry Smith 
381c838673bSBarry Smith    Level: beginner
382c838673bSBarry Smith 
3831cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
384c838673bSBarry Smith M*/
385c838673bSBarry Smith 
386c838673bSBarry Smith /*MC
38787497f52SBarry Smith    SNES_DIVERGED_LINE_SEARCH - The line search has failed. This only occurs for a `SNES` solvers that use a line search
388c838673bSBarry Smith 
389c838673bSBarry Smith    Level: beginner
390c838673bSBarry Smith 
3911cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`, `SNESLineSearch`
392c838673bSBarry Smith M*/
393c838673bSBarry Smith 
394c838673bSBarry Smith /*MC
39546a9e3ceSBarry Smith    SNES_DIVERGED_LOCAL_MIN - the algorithm seems to have stagnated at a local minimum that is not zero.
39687497f52SBarry Smith    See the manual page for `SNESConvergedReason` for more details
397c838673bSBarry Smith 
398c838673bSBarry Smith    Level: beginner
399c838673bSBarry Smith 
4001cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
401c838673bSBarry Smith M*/
402c838673bSBarry Smith 
403c838673bSBarry Smith /*MC
40487497f52SBarry Smith    SNES_CONERGED_ITERATING - this only occurs if `SNESGetConvergedReason()` is called during the `SNESSolve()`
405c838673bSBarry Smith 
406c838673bSBarry Smith    Level: beginner
407c838673bSBarry Smith 
4081cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
409c838673bSBarry Smith M*/
410c838673bSBarry Smith 
411014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetConvergenceTest(SNES, PetscErrorCode (*)(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, void *), void *, PetscErrorCode (*)(void *));
4128d359177SBarry Smith PETSC_EXTERN PetscErrorCode SNESConvergedDefault(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, void *);
413e2a6519dSDmitry Karpeev PETSC_EXTERN PetscErrorCode SNESConvergedSkip(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, void *);
414649ef022SMatthew Knepley PETSC_EXTERN PetscErrorCode SNESConvergedCorrectPressure(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, void *);
415014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetConvergedReason(SNES, SNESConvergedReason *);
416c4421ceaSFande Kong PETSC_EXTERN PetscErrorCode SNESGetConvergedReasonString(SNES, const char **);
41733866048SMatthew G. Knepley PETSC_EXTERN PetscErrorCode SNESSetConvergedReason(SNES, SNESConvergedReason);
418ddbbdb52SLois Curfman McInnes 
419edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 5, 0, "SNESConvergedSkip()", ) static inline void SNESSkipConverged(void)
420d71ae5a4SJacob Faibussowitsch { /* never called */
4219371c9d4SSatish Balay }
4228ea1b3e6SJed Brown #define SNESSkipConverged (SNESSkipConverged, SNESConvergedSkip)
42311f088b5SMatthew G Knepley 
4249bcc50f1SBarry Smith /*S
4258434afd1SBarry Smith   SNESInitialGuessFn - A prototype of a `SNES` compute initial guess function that would be passed to `SNESSetComputeInitialGuess()`
4269bcc50f1SBarry Smith 
4279bcc50f1SBarry Smith   Calling Sequence:
4289bcc50f1SBarry Smith + snes  - `SNES` context
4299bcc50f1SBarry Smith . u   - output vector to contain initial guess
4309bcc50f1SBarry Smith - ctx - [optional] user-defined function context
4319bcc50f1SBarry Smith 
4329bcc50f1SBarry Smith   Level: beginner
4339bcc50f1SBarry Smith 
4348434afd1SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSetComputeInitialGuess()`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`, `SNESFunctionFn`
4359bcc50f1SBarry Smith S*/
4368434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESInitialGuessFn)(SNES snes, Vec u, void *ctx);
4379bcc50f1SBarry Smith 
4389bcc50f1SBarry Smith /*S
4398434afd1SBarry Smith   SNESFunctionFn - A prototype of a `SNES` evaluation function that would be passed to `SNESSetFunction()`
4409bcc50f1SBarry Smith 
4419bcc50f1SBarry Smith   Calling Sequence:
4429bcc50f1SBarry Smith + snes  - `SNES` context
4439bcc50f1SBarry Smith . u   - input vector
4449bcc50f1SBarry Smith . F   - function vector
4459bcc50f1SBarry Smith - ctx - [optional] user-defined function context
4469bcc50f1SBarry Smith 
4479bcc50f1SBarry Smith   Level: beginner
4489bcc50f1SBarry Smith 
4498434afd1SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`, `SNESNGSFn`
4509bcc50f1SBarry Smith S*/
4518434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESFunctionFn)(SNES snes, Vec u, Vec F, void *ctx);
4529bcc50f1SBarry Smith 
4539bcc50f1SBarry Smith /*S
4548434afd1SBarry Smith   SNESObjectiveFn - A prototype of a `SNES` objective evaluation function that would be passed to `SNESSetObjective()`
4559bcc50f1SBarry Smith 
4569bcc50f1SBarry Smith   Calling Sequence:
4579bcc50f1SBarry Smith + snes  - `SNES` context
4589bcc50f1SBarry Smith . u   - input vector
4599bcc50f1SBarry Smith . o   - output value
4609bcc50f1SBarry Smith - ctx - [optional] user-defined function context
4619bcc50f1SBarry Smith 
4629bcc50f1SBarry Smith   Level: beginner
4639bcc50f1SBarry Smith 
4648434afd1SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`, `SNESNGSFn`
4659bcc50f1SBarry Smith S*/
4668434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESObjectiveFn)(SNES snes, Vec u, PetscReal *o, void *ctx);
4679bcc50f1SBarry Smith 
4689bcc50f1SBarry Smith /*S
4698434afd1SBarry Smith   SNESJacobianFn - A prototype of a `SNES` Jacobian evaluation function that would be passed to `SNESSetJacobian()`
4709bcc50f1SBarry Smith 
4719bcc50f1SBarry Smith   Calling Sequence:
4729bcc50f1SBarry Smith + snes   - the `SNES` context obtained from `SNESCreate()`
4739bcc50f1SBarry Smith . u    - input vector
4749bcc50f1SBarry Smith . Amat - (approximate) Jacobian matrix
4759bcc50f1SBarry Smith . Pmat - matrix used to construct the preconditioner, often the same as `Amat`
4769bcc50f1SBarry Smith - ctx  - [optional] user-defined context for matrix evaluation routine
4779bcc50f1SBarry Smith 
4789bcc50f1SBarry Smith   Level: beginner
4799bcc50f1SBarry Smith 
4808434afd1SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSetJacobian()`, `SNESGetJacobian()`, `SNESFunctionFn`, `SNESNGSFn`
4819bcc50f1SBarry Smith S*/
4828434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESJacobianFn)(SNES snes, Vec u, Mat Amat, Mat Pmat, void *ctx);
4839bcc50f1SBarry Smith 
4849bcc50f1SBarry Smith /*S
4858434afd1SBarry Smith   SNESNGSFn - A prototype of a `SNES` nonlinear Gauss-Seidel function that would be passed to `SNESSetNGS()`
4869bcc50f1SBarry Smith 
4879bcc50f1SBarry Smith   Calling Sequence:
4889bcc50f1SBarry Smith + snes   - the `SNES` context obtained from `SNESCreate()`
4899bcc50f1SBarry Smith . u    - the current solution, updated in place
490dd8e379bSPierre Jolivet . b    - the right-hand side vector (which may be `NULL`)
4919bcc50f1SBarry Smith - ctx  - [optional] user-defined context for matrix evaluation routine
4929bcc50f1SBarry Smith 
4939bcc50f1SBarry Smith   Level: beginner
4949bcc50f1SBarry Smith 
4958434afd1SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSetJacobian()`, `SNESGetJacobian()`, `SNESFunctionFn`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`
4969bcc50f1SBarry Smith S*/
4978434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESNGSFn)(SNES snes, Vec u, Vec b, void *ctx);
4989bcc50f1SBarry Smith 
49953e5d35bSStefano Zampini /*S
50053e5d35bSStefano Zampini   SNESUpdateFn - A prototype of a `SNES` update function that would be passed to `SNESSetUpdate()`
50153e5d35bSStefano Zampini 
50253e5d35bSStefano Zampini   Calling Sequence:
50353e5d35bSStefano Zampini + snes - `SNES` context
50453e5d35bSStefano Zampini - step - the current iteration index
50553e5d35bSStefano Zampini 
50653e5d35bSStefano Zampini   Level: advanced
50753e5d35bSStefano Zampini 
50853e5d35bSStefano Zampini .seealso: [](ch_snes), `SNES`, `SNESSetUpdate()`
50953e5d35bSStefano Zampini S*/
51053e5d35bSStefano Zampini PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESUpdateFn)(SNES snes, PetscInt step);
51153e5d35bSStefano Zampini 
512b67197daSBarry Smith /* --------- Solving systems of nonlinear equations --------------- */
5138434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetFunction(SNES, Vec, SNESFunctionFn *, void *);
5148434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetFunction(SNES, Vec *, SNESFunctionFn **, void **);
515014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESComputeFunction(SNES, Vec, Vec);
516bbc1464cSBarry Smith PETSC_EXTERN PetscErrorCode SNESComputeMFFunction(SNES, Vec, Vec);
51725acbd8eSLisandro Dalcin PETSC_EXTERN PetscErrorCode SNESSetInitialFunction(SNES, Vec);
51832f3f7c2SPeter Brune 
5198434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetJacobian(SNES, Mat, Mat, SNESJacobianFn *, void *);
5208434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetJacobian(SNES, Mat *, Mat *, SNESJacobianFn **, void **);
5218434afd1SBarry Smith PETSC_EXTERN SNESFunctionFn SNESObjectiveComputeFunctionDefaultFD;
5228434afd1SBarry Smith PETSC_EXTERN SNESJacobianFn SNESComputeJacobianDefault;
5238434afd1SBarry Smith PETSC_EXTERN SNESJacobianFn SNESComputeJacobianDefaultColor;
52478e7fe0eSHong Zhang PETSC_EXTERN PetscErrorCode SNESPruneJacobianColor(SNES, Mat, Mat);
5258434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetComputeInitialGuess(SNES, SNESInitialGuessFn *, void *);
5268434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetPicard(SNES, Vec, SNESFunctionFn *, Mat, Mat, SNESJacobianFn *, void *);
5278434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetPicard(SNES, Vec *, SNESFunctionFn **, Mat *, Mat *, SNESJacobianFn **, void **);
5288434afd1SBarry Smith PETSC_EXTERN SNESFunctionFn SNESPicardComputeFunction;
5298434afd1SBarry Smith PETSC_EXTERN SNESFunctionFn SNESPicardComputeMFFunction;
5308434afd1SBarry Smith PETSC_EXTERN SNESJacobianFn SNESPicardComputeJacobian;
53117bae607SBarry Smith 
5328434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetObjective(SNES, SNESObjectiveFn *, void *);
5338434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetObjective(SNES, SNESObjectiveFn **, void **);
5342a4ee8f2SPeter Brune PETSC_EXTERN PetscErrorCode SNESComputeObjective(SNES, Vec, PetscReal *);
5352a4ee8f2SPeter Brune 
53653e5d35bSStefano Zampini PETSC_EXTERN PetscErrorCode SNESSetUpdate(SNES, SNESUpdateFn *);
53753e5d35bSStefano Zampini 
538534ebe21SPeter Brune /*E
53916a05f60SBarry Smith    SNESNormSchedule - Frequency with which the norm is computed during a nonliner solve
540534ebe21SPeter Brune 
541dc4c0fb0SBarry Smith    Values:
542dc4c0fb0SBarry Smith +   `SNES_NORM_DEFAULT`            - use the default behavior for the current `SNESType`
543dc4c0fb0SBarry Smith .   `SNES_NORM_NONE`               - avoid all norm computations
544dc4c0fb0SBarry Smith .   `SNES_NORM_ALWAYS`             - compute the norms whenever possible
545dc4c0fb0SBarry Smith .   `SNES_NORM_INITIAL_ONLY`       - compute the norm only when the algorithm starts
546dc4c0fb0SBarry Smith .   `SNES_NORM_FINAL_ONLY`         - compute the norm only when the algorithm finishes
547dc4c0fb0SBarry Smith -   `SNES_NORM_INITIAL_FINAL_ONLY` - compute the norm at the start and end of the algorithm
548534ebe21SPeter Brune 
54916a05f60SBarry Smith    Level: advanced
55016a05f60SBarry Smith 
551534ebe21SPeter Brune    Notes:
552dc4c0fb0SBarry Smith    Support for these is highly dependent on the solver.
553dc4c0fb0SBarry Smith 
554dc4c0fb0SBarry Smith    Some options limit the convergence tests that can be used.
555dc4c0fb0SBarry Smith 
556dc4c0fb0SBarry Smith    The `SNES_NORM_NONE` option is most commonly used when the nonlinear solver is being used as a smoother, for example for `SNESFAS`
557dc4c0fb0SBarry Smith 
558534ebe21SPeter Brune    This is primarily used to turn off extra norm and function computation
559534ebe21SPeter Brune    when the solvers are composed.
560534ebe21SPeter Brune 
5611cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPSetNormType()`,
562db781477SPatrick Sanan           `KSPSetConvergenceTest()`, `KSPSetPCSide()`
563534ebe21SPeter Brune E*/
5649371c9d4SSatish Balay typedef enum {
5659371c9d4SSatish Balay   SNES_NORM_DEFAULT            = -1,
566fdacfa88SPeter Brune   SNES_NORM_NONE               = 0,
567365a6726SPeter Brune   SNES_NORM_ALWAYS             = 1,
568fdacfa88SPeter Brune   SNES_NORM_INITIAL_ONLY       = 2,
569fdacfa88SPeter Brune   SNES_NORM_FINAL_ONLY         = 3,
5709371c9d4SSatish Balay   SNES_NORM_INITIAL_FINAL_ONLY = 4
5719371c9d4SSatish Balay } SNESNormSchedule;
572365a6726SPeter Brune PETSC_EXTERN const char *const *const SNESNormSchedules;
5731957e957SBarry Smith 
574534ebe21SPeter Brune /*MC
57516a05f60SBarry Smith    SNES_NORM_NONE - Don't compute function and its L2 norm when possible
576534ebe21SPeter Brune 
577534ebe21SPeter Brune    Level: advanced
578534ebe21SPeter Brune 
579dc4c0fb0SBarry Smith    Note:
580534ebe21SPeter Brune    This is most useful for stationary solvers with a fixed number of iterations used as smoothers.
581534ebe21SPeter Brune 
5821cc06b55SBarry Smith .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_DEFAULT`
583534ebe21SPeter Brune M*/
584534ebe21SPeter Brune 
585fdacfa88SPeter Brune /*MC
586365a6726SPeter Brune    SNES_NORM_ALWAYS - Compute the function and its L2 norm at each iteration.
587534ebe21SPeter Brune 
588fdacfa88SPeter Brune    Level: advanced
589fdacfa88SPeter Brune 
590dc4c0fb0SBarry Smith    Note:
591fdacfa88SPeter Brune    Most solvers will use this no matter what norm type is passed to them.
592fdacfa88SPeter Brune 
5931cc06b55SBarry Smith .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_NONE`
594fdacfa88SPeter Brune M*/
595534ebe21SPeter Brune 
596534ebe21SPeter Brune /*MC
597534ebe21SPeter Brune    SNES_NORM_INITIAL_ONLY - Compute the function and its L2 at iteration 0, but do not update it.
598534ebe21SPeter Brune 
599534ebe21SPeter Brune    Level: advanced
600534ebe21SPeter Brune 
601534ebe21SPeter Brune    Notes:
602dc4c0fb0SBarry Smith    This method is useful in composed methods, when a true solution might actually be found before `SNESSolve()` is called.
603534ebe21SPeter Brune    This option enables the solve to abort on the zeroth iteration if this is the case.
604534ebe21SPeter Brune 
605534ebe21SPeter Brune    For solvers that require the computation of the L2 norm of the function as part of the method, this merely cancels
606534ebe21SPeter Brune    the norm computation at the last iteration (if possible).
607534ebe21SPeter Brune 
6081cc06b55SBarry Smith .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_FINAL_ONLY`, `SNES_NORM_INITIAL_FINAL_ONLY`
609534ebe21SPeter Brune M*/
610534ebe21SPeter Brune 
611534ebe21SPeter Brune /*MC
612534ebe21SPeter Brune    SNES_NORM_FINAL_ONLY - Compute the function and its L2 norm on only the final iteration.
613534ebe21SPeter Brune 
614534ebe21SPeter Brune    Level: advanced
615534ebe21SPeter Brune 
616dc4c0fb0SBarry Smith    Note:
617534ebe21SPeter Brune    For solvers that require the computation of the L2 norm of the function as part of the method, behaves
61887497f52SBarry Smith    exactly as `SNES_NORM_DEFAULT`.  This method is useful when the function is gotten after `SNESSolve()` and
619534ebe21SPeter Brune    used in subsequent computation for methods that do not need the norm computed during the rest of the
620534ebe21SPeter Brune    solution procedure.
621534ebe21SPeter Brune 
6221cc06b55SBarry Smith .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_INITIAL_ONLY`, `SNES_NORM_INITIAL_FINAL_ONLY`
623534ebe21SPeter Brune M*/
624534ebe21SPeter Brune 
625534ebe21SPeter Brune /*MC
626534ebe21SPeter Brune    SNES_NORM_INITIAL_FINAL_ONLY - Compute the function and its L2 norm on only the initial and final iterations.
627534ebe21SPeter Brune 
628534ebe21SPeter Brune    Level: advanced
629534ebe21SPeter Brune 
630dc4c0fb0SBarry Smith    Note:
63187497f52SBarry Smith    This method combines the benefits of `SNES_NORM_INITIAL_ONLY` and `SNES_NORM_FINAL_ONLY`.
632534ebe21SPeter Brune 
6331cc06b55SBarry Smith .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_SNES_NORM_INITIAL_ONLY`, `SNES_NORM_FINAL_ONLY`
634534ebe21SPeter Brune M*/
635534ebe21SPeter Brune 
636365a6726SPeter Brune PETSC_EXTERN PetscErrorCode SNESSetNormSchedule(SNES, SNESNormSchedule);
637365a6726SPeter Brune PETSC_EXTERN PetscErrorCode SNESGetNormSchedule(SNES, SNESNormSchedule *);
638c5ce4427SMatthew G. Knepley PETSC_EXTERN PetscErrorCode SNESSetFunctionNorm(SNES, PetscReal);
639c5ce4427SMatthew G. Knepley PETSC_EXTERN PetscErrorCode SNESGetFunctionNorm(SNES, PetscReal *);
640c1e67a49SFande Kong PETSC_EXTERN PetscErrorCode SNESGetUpdateNorm(SNES, PetscReal *);
641c1e67a49SFande Kong PETSC_EXTERN PetscErrorCode SNESGetSolutionNorm(SNES, PetscReal *);
642534ebe21SPeter Brune 
64347073ea2SPeter Brune /*E
64447073ea2SPeter Brune    SNESFunctionType - Type of function computed
64547073ea2SPeter Brune 
646dc4c0fb0SBarry Smith    Values:
647dc4c0fb0SBarry Smith +  `SNES_FUNCTION_DEFAULT`          - the default behavior for the current `SNESType`
648dc4c0fb0SBarry Smith .  `SNES_FUNCTION_UNPRECONDITIONED` - the original function provided
649dc4c0fb0SBarry Smith -  `SNES_FUNCTION_PRECONDITIONED`   - the modification of the function by the preconditioner
65047073ea2SPeter Brune 
65116a05f60SBarry Smith    Level: advanced
65216a05f60SBarry Smith 
653dc4c0fb0SBarry Smith    Note:
654dc4c0fb0SBarry Smith    Support for these is dependent on the solver.
655dc4c0fb0SBarry Smith 
6561cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPSetNormType()`,
657db781477SPatrick Sanan           `KSPSetConvergenceTest()`, `KSPSetPCSide()`
65847073ea2SPeter Brune E*/
6599371c9d4SSatish Balay typedef enum {
6609371c9d4SSatish Balay   SNES_FUNCTION_DEFAULT          = -1,
66147073ea2SPeter Brune   SNES_FUNCTION_UNPRECONDITIONED = 0,
6629371c9d4SSatish Balay   SNES_FUNCTION_PRECONDITIONED   = 1
6639371c9d4SSatish Balay } SNESFunctionType;
66447073ea2SPeter Brune PETSC_EXTERN const char *const *const SNESFunctionTypes;
66547073ea2SPeter Brune 
66647073ea2SPeter Brune PETSC_EXTERN PetscErrorCode SNESSetFunctionType(SNES, SNESFunctionType);
66747073ea2SPeter Brune PETSC_EXTERN PetscErrorCode SNESGetFunctionType(SNES, SNESFunctionType *);
668f1c6b773SPeter Brune 
6698434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetNGS(SNES, SNESNGSFn *, void *);
6708434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetNGS(SNES, SNESNGSFn **, void **);
671be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESComputeNGS(SNES, Vec, Vec);
672b6266c6eSPeter Brune 
673be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESNGSSetSweeps(SNES, PetscInt);
674be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESNGSGetSweeps(SNES, PetscInt *);
675be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESNGSSetTolerances(SNES, PetscReal, PetscReal, PetscReal, PetscInt);
676be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESNGSGetTolerances(SNES, PetscReal *, PetscReal *, PetscReal *, PetscInt *);
677badc63e7SPeter Brune 
6784fc747eaSLawrence Mitchell PETSC_EXTERN PetscErrorCode SNESSetAlwaysComputesFinalResidual(SNES, PetscBool);
6794fc747eaSLawrence Mitchell PETSC_EXTERN PetscErrorCode SNESGetAlwaysComputesFinalResidual(SNES, PetscBool *);
6804fc747eaSLawrence Mitchell 
6813ec1f749SStefano Zampini PETSC_EXTERN PetscErrorCode SNESShellGetContext(SNES, void *);
682014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESShellSetContext(SNES, void *);
683014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESShellSetSolve(SNES, PetscErrorCode (*)(SNES, Vec));
684646217ecSPeter Brune 
685c5ae4b9aSBarry Smith /* --------- Routines specifically for line search methods --------------- */
686c5ae4b9aSBarry Smith 
687872b6db9SPeter Brune /*S
68887497f52SBarry Smith    SNESLineSearch - Abstract PETSc object that manages line-search operations for nonlinear solvers
6899e764e56SPeter Brune 
6909e764e56SPeter Brune    Level: beginner
6919e764e56SPeter Brune 
6921cc06b55SBarry Smith .seealso: [](ch_snes), `SNESLineSearchType`, `SNESLineSearchCreate()`, `SNESLineSearchSetType()`, `SNES`
6939e764e56SPeter Brune S*/
694907376e6SBarry Smith typedef struct _p_LineSearch *SNESLineSearch;
6959e764e56SPeter Brune 
6969e764e56SPeter Brune /*J
697dc4c0fb0SBarry Smith    SNESLineSearchType - String with the name of a PETSc line search method `SNESLineSearch`
6989e764e56SPeter Brune 
699ceaaa498SBarry Smith    Values:
700ceaaa498SBarry Smith +  `SNESLINESEARCHBASIC`   - (or equivalently `SNESLINESEARCHNONE`) Simple damping line search, defaults to using the full Newton step
701ceaaa498SBarry Smith .  `SNESLINESEARCHBT`      - Backtracking line search over the L2 norm of the function
702ceaaa498SBarry Smith .  `SNESLINESEARCHL2`      - Secant line search over the L2 norm of the function
703ceaaa498SBarry Smith .  `SNESLINESEARCHCP`      - Critical point secant line search assuming F(x) = grad G(x) for some unknown G(x)
704ceaaa498SBarry Smith .  `SNESLINESEARCHNLEQERR` - Affine-covariant error-oriented linesearch
705ceaaa498SBarry Smith -  `SNESLINESEARCHSHELL`   - User provided `SNESLineSearch` implementation
706ceaaa498SBarry Smith 
70795bd0b28SBarry Smith    Level: beginner
70895bd0b28SBarry Smith 
7091cc06b55SBarry Smith .seealso: [](ch_snes), `SNESLineSearch`, `SNESLineSearchSetType()`, `SNES`
7109e764e56SPeter Brune J*/
71119fd82e9SBarry Smith typedef const char *SNESLineSearchType;
7129e764e56SPeter Brune #define SNESLINESEARCHBT        "bt"
713d4c6564cSPatrick Farrell #define SNESLINESEARCHNLEQERR   "nleqerr"
714c87759e9SPeter Brune #define SNESLINESEARCHBASIC     "basic"
7150b00b554SBarry Smith #define SNESLINESEARCHNONE      "none"
7169e764e56SPeter Brune #define SNESLINESEARCHL2        "l2"
7179e764e56SPeter Brune #define SNESLINESEARCHCP        "cp"
7189e764e56SPeter Brune #define SNESLINESEARCHSHELL     "shell"
719b5badacbSBarry Smith #define SNESLINESEARCHNCGLINEAR "ncglinear"
7209e764e56SPeter Brune 
721140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList SNESList;
722014dd563SJed Brown PETSC_EXTERN PetscClassId      SNESLINESEARCH_CLASSID;
723140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList SNESLineSearchList;
7249e764e56SPeter Brune 
725b000cd8dSPeter Brune #define SNES_LINESEARCH_ORDER_LINEAR    1
726b000cd8dSPeter Brune #define SNES_LINESEARCH_ORDER_QUADRATIC 2
727b000cd8dSPeter Brune #define SNES_LINESEARCH_ORDER_CUBIC     3
7289e764e56SPeter Brune 
7299bcc50f1SBarry Smith /*S
7308434afd1SBarry Smith   SNESLineSearchVIProjectFn - A prototype of a `SNES` function that projects a vector onto the VI bounds, passed to `SNESLineSearchSetVIFunctions()`
7319bcc50f1SBarry Smith 
7329bcc50f1SBarry Smith   Calling Sequence:
7339bcc50f1SBarry Smith + snes  - `SNES` context
7349bcc50f1SBarry Smith - u     - the vector to project to the bounds
7359bcc50f1SBarry Smith 
7369bcc50f1SBarry Smith   Level: advanced
7379bcc50f1SBarry Smith 
7389bcc50f1SBarry Smith   Note:
7398434afd1SBarry Smith   The deprecated `SNESLineSearchVIProjectFunc` still works as a replacement for `SNESLineSearchVIProjectFn` *.
7409bcc50f1SBarry Smith 
7419bcc50f1SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESLineSearch`
7429bcc50f1SBarry Smith S*/
7438434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESLineSearchVIProjectFn)(SNES snes, Vec u);
7448434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef SNESLineSearchVIProjectFn *SNESLineSearchVIProjectFunc; // deprecated
7459bcc50f1SBarry Smith 
7469bcc50f1SBarry Smith /*S
7478434afd1SBarry Smith   SNESLineSearchVIProjectFn - A prototype of a `SNES` function that computes the norm of the active set variables in a vector in a VI solve,
7489bcc50f1SBarry Smith   passed to `SNESLineSearchSetVIFunctions()`
7499bcc50f1SBarry Smith 
7509bcc50f1SBarry Smith   Calling Sequence:
7519bcc50f1SBarry Smith + snes  - `SNES` context
7529bcc50f1SBarry Smith . f     - the vector to compute the norm of
7539bcc50f1SBarry Smith . u     - the current solution, entries that are on the VI bounds are ignored
7549bcc50f1SBarry Smith - fnorm - the resulting norm
7559bcc50f1SBarry Smith 
7569bcc50f1SBarry Smith   Level: advanced
7579bcc50f1SBarry Smith 
7589bcc50f1SBarry Smith   Note:
7598434afd1SBarry Smith   The deprecated `SNESLineSearchVINormFunc` still works as a replacement for `SNESLineSearchVINormFn` *.
7609bcc50f1SBarry Smith 
7619bcc50f1SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESLineSearch`
7629bcc50f1SBarry Smith S*/
7638434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESLineSearchVINormFn)(SNES snes, Vec f, Vec u, PetscReal *fnorm);
7648434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef SNESLineSearchVINormFn *SNESLineSearchVINormFunc; // deprecated
7659bcc50f1SBarry Smith 
7668434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESLineSearchApplyFn)(SNESLineSearch);
7678434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef SNESLineSearchApplyFn *SNESLineSearchApplyFunc; // deprecated
7688434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESLineSearchShellApplyFn)(SNESLineSearch, void *);
7698434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef SNESLineSearchShellApplyFn *SNESLineSearchUserFunc; // deprecated
7709e764e56SPeter Brune 
771014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchCreate(MPI_Comm, SNESLineSearch *);
772014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchReset(SNESLineSearch);
773014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchView(SNESLineSearch, PetscViewer);
774014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchDestroy(SNESLineSearch *);
775a80ff896SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetType(SNESLineSearch, SNESLineSearchType *);
77619fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetType(SNESLineSearch, SNESLineSearchType);
777014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetFromOptions(SNESLineSearch);
778ed07d7d7SPeter Brune PETSC_EXTERN PetscErrorCode SNESLineSearchSetFunction(SNESLineSearch, PetscErrorCode (*)(SNES, Vec, Vec));
779014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetUp(SNESLineSearch);
780014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchApply(SNESLineSearch, Vec, Vec, PetscReal *, Vec);
781014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchPreCheck(SNESLineSearch, Vec, Vec, PetscBool *);
782014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchPostCheck(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *);
783fa0ddf94SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetWorkVecs(SNESLineSearch, PetscInt);
7849e764e56SPeter Brune 
7859bd66eb0SPeter Brune /* set the functions for precheck and postcheck */
78686d74e61SPeter Brune 
787f190f2fcSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetPreCheck(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, Vec, Vec, PetscBool *, void *), void *ctx);
788f190f2fcSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetPostCheck(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void *ctx);
7899e764e56SPeter Brune 
790f190f2fcSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchGetPreCheck(SNESLineSearch, PetscErrorCode (**)(SNESLineSearch, Vec, Vec, PetscBool *, void *), void **ctx);
791f190f2fcSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchGetPostCheck(SNESLineSearch, PetscErrorCode (**)(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void **ctx);
7929e764e56SPeter Brune 
7939bd66eb0SPeter Brune /* set the functions for VI-specific line search operations */
7949bd66eb0SPeter Brune 
7958434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFn *, SNESLineSearchVINormFn *);
7968434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchGetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFn **, SNESLineSearchVINormFn **);
7979bd66eb0SPeter Brune 
7989e764e56SPeter Brune /* pointers to the associated SNES in order to be able to get the function evaluation out */
799014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetSNES(SNESLineSearch, SNES);
800014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetSNES(SNESLineSearch, SNES *);
8019e764e56SPeter Brune 
8029e764e56SPeter Brune /* set and get the parameters and vectors */
803014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetTolerances(SNESLineSearch, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscInt *);
804014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetTolerances(SNESLineSearch, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscInt);
8059e764e56SPeter Brune 
806014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchPreCheckPicard(SNESLineSearch, Vec, Vec, PetscBool *, void *);
80786d74e61SPeter Brune 
808014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetLambda(SNESLineSearch, PetscReal *);
809014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetLambda(SNESLineSearch, PetscReal);
8109e764e56SPeter Brune 
811014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetDamping(SNESLineSearch, PetscReal *);
812014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetDamping(SNESLineSearch, PetscReal);
8139e764e56SPeter Brune 
814014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetOrder(SNESLineSearch, PetscInt *order);
815014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetOrder(SNESLineSearch, PetscInt order);
81659405d5eSPeter Brune 
817422a814eSBarry Smith /*E
818dc4c0fb0SBarry Smith     SNESLineSearchReason - indication if the line search has succeeded or failed and why
819422a814eSBarry Smith 
820dc4c0fb0SBarry Smith   Values:
821dc4c0fb0SBarry Smith +  `SNES_LINESEARCH_SUCCEEDED`       - the line search succeeded
822dc4c0fb0SBarry Smith .  `SNES_LINESEARCH_FAILED_NANORINF` - a not a number of infinity appeared in the computions
823dc4c0fb0SBarry Smith .  `SNES_LINESEARCH_FAILED_DOMAIN`   - the function was evaluated outside of its domain, see `SNESSetFunctionDomainError()` and `SNESSetJacobianDomainError()`
824dc4c0fb0SBarry Smith .  `SNES_LINESEARCH_FAILED_REDUCT`   - the linear search failed to get the requested decrease in its norm or objective
825dc4c0fb0SBarry Smith .  `SNES_LINESEARCH_FAILED_USER`     - used by `SNESLINESEARCHNLEQERR` to indicate the user changed the search direction inappropriately
826dc4c0fb0SBarry Smith -  `SNES_LINESEARCH_FAILED_FUNCTION` - indicates the maximum number of function evaluations allowed has been surpassed, `SNESConvergedReason` is also
827dc4c0fb0SBarry Smith                                        set to `SNES_DIVERGED_FUNCTION_COUNT`
828422a814eSBarry Smith 
82916a05f60SBarry Smith    Level: intermediate
83016a05f60SBarry Smith 
831dc4c0fb0SBarry Smith    Developer Note:
832dc4c0fb0SBarry Smith    Some of these reasons overlap with values of `SNESConvergedReason`
833422a814eSBarry Smith 
8341cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPConvergedReason`, `SNESSetConvergenceTest()`,
835dc4c0fb0SBarry Smith           `SNESSetFunctionDomainError()` and `SNESSetJacobianDomainError()`
836422a814eSBarry Smith E*/
8379371c9d4SSatish Balay typedef enum {
8389371c9d4SSatish Balay   SNES_LINESEARCH_SUCCEEDED,
839422a814eSBarry Smith   SNES_LINESEARCH_FAILED_NANORINF,
840e9b602ebSSatish Balay   SNES_LINESEARCH_FAILED_DOMAIN,
841d5b43468SJose E. Roman   SNES_LINESEARCH_FAILED_REDUCT, /* INSUFFICIENT REDUCTION */
842e9b602ebSSatish Balay   SNES_LINESEARCH_FAILED_USER,
8439371c9d4SSatish Balay   SNES_LINESEARCH_FAILED_FUNCTION
8449371c9d4SSatish Balay } SNESLineSearchReason;
845422a814eSBarry Smith 
846422a814eSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchGetReason(SNESLineSearch, SNESLineSearchReason *);
847422a814eSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetReason(SNESLineSearch, SNESLineSearchReason);
8489e764e56SPeter Brune 
849014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetVecs(SNESLineSearch, Vec *, Vec *, Vec *, Vec *, Vec *);
850014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetVecs(SNESLineSearch, Vec, Vec, Vec, Vec, Vec);
8519e764e56SPeter Brune 
852014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetNorms(SNESLineSearch, PetscReal *, PetscReal *, PetscReal *);
853014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetNorms(SNESLineSearch, PetscReal, PetscReal, PetscReal);
854014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchComputeNorms(SNESLineSearch);
855014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetComputeNorms(SNESLineSearch, PetscBool);
8569e764e56SPeter Brune 
857dcf2fd19SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchMonitor(SNESLineSearch);
858dcf2fd19SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSet(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, void *), void *, PetscErrorCode (*)(void **));
859d12e167eSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSetFromOptions(SNESLineSearch, const char[], const char[], const char[], PetscErrorCode (*)(SNESLineSearch, PetscViewerAndFormat *), PetscErrorCode (*)(SNESLineSearch, PetscViewerAndFormat *));
860dcf2fd19SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorCancel(SNESLineSearch);
861dcf2fd19SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetDefaultMonitor(SNESLineSearch, PetscViewer);
862dcf2fd19SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchGetDefaultMonitor(SNESLineSearch, PetscViewer *);
863d12e167eSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSolutionUpdate(SNESLineSearch, PetscViewerAndFormat *);
8649e764e56SPeter Brune 
865014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchAppendOptionsPrefix(SNESLineSearch, const char prefix[]);
866014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetOptionsPrefix(SNESLineSearch, const char *prefix[]);
8679e764e56SPeter Brune 
8689e764e56SPeter Brune /* Shell interface functions */
8698434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchShellSetApply(SNESLineSearch, SNESLineSearchShellApplyFn, void *);
8708434afd1SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchShellGetApply(SNESLineSearch, SNESLineSearchShellApplyFn **, void **);
8719bcc50f1SBarry Smith 
8729bcc50f1SBarry Smith PETSC_DEPRECATED_FUNCTION(3, 21, 0, "SNESLinesearchShellSetApply()", ) static inline PetscErrorCode SNESLineSearchShellSetUserFunc(SNESLineSearch ls, SNESLineSearchUserFunc f, void *ctx)
8739bcc50f1SBarry Smith {
8749bcc50f1SBarry Smith   return SNESLineSearchShellSetApply(ls, f, ctx);
8759bcc50f1SBarry Smith }
8769bcc50f1SBarry Smith 
8779bcc50f1SBarry Smith PETSC_DEPRECATED_FUNCTION(3, 21, 0, "SNESLinesearchShellGetApply()", ) static inline PetscErrorCode SNESLineSearchShellGetUserFunc(SNESLineSearch ls, SNESLineSearchUserFunc *f, void **ctx)
8789bcc50f1SBarry Smith {
8799bcc50f1SBarry Smith   return SNESLineSearchShellGetApply(ls, f, ctx);
8809bcc50f1SBarry Smith }
8819e764e56SPeter Brune 
8822f4102e2SPeter Brune /* BT interface functions */
883014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchBTSetAlpha(SNESLineSearch, PetscReal);
884014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchBTGetAlpha(SNESLineSearch, PetscReal *);
8852f4102e2SPeter Brune 
8869e764e56SPeter Brune /*register line search types */
887bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchRegister(const char[], PetscErrorCode (*)(SNESLineSearch));
8889e764e56SPeter Brune 
889720c9a41SShri Abhyankar /* Routines for VI solver */
890014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVISetVariableBounds(SNES, Vec, Vec);
891cf836535SBlaise Bourdin PETSC_EXTERN PetscErrorCode SNESVIGetVariableBounds(SNES, Vec *, Vec *);
892014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVISetComputeVariableBounds(SNES, PetscErrorCode (*)(SNES, Vec, Vec));
893014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVIGetInactiveSet(SNES, IS *);
894014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVIGetActiveSetIS(SNES, Vec, Vec, IS *);
895014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVIComputeInactiveSetFnorm(SNES, Vec, Vec, PetscReal *);
896014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVISetRedundancyCheck(SNES, PetscErrorCode (*)(SNES, IS, IS *, void *), void *);
897f6dfbefdSBarry Smith PETSC_EXTERN PetscErrorCode SNESVIComputeMeritFunction(Vec, PetscReal *, PetscReal *);
898f6dfbefdSBarry Smith PETSC_EXTERN PetscErrorCode SNESVIComputeFunction(SNES, Vec, Vec, void *);
899f6dfbefdSBarry Smith PETSC_EXTERN PetscErrorCode DMSetVI(DM, IS);
900f6dfbefdSBarry Smith PETSC_EXTERN PetscErrorCode DMDestroyVI(DM);
901f5ea5bd2SShri Abhyankar 
902014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESTestLocalMin(SNES);
903da9b6338SBarry Smith 
904eef9c623SLois Curfman McInnes /* Should this routine be private? */
905d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode SNESComputeJacobian(SNES, Vec, Mat, Mat);
906e885f1abSBarry Smith PETSC_EXTERN PetscErrorCode SNESTestJacobian(SNES);
907494a190aSStefano Zampini PETSC_EXTERN PetscErrorCode SNESTestFunction(SNES);
908ddbbdb52SLois Curfman McInnes 
909014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetDM(SNES, DM);
910014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetDM(SNES, DM *);
911be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetNPC(SNES, SNES);
912be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetNPC(SNES, SNES *);
9133ad1a0b9SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESHasNPC(SNES, PetscBool *);
914be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESApplyNPC(SNES, Vec, Vec, Vec);
915be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetNPCFunction(SNES, Vec, PetscReal *);
916be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESComputeFunctionDefaultNPC(SNES, Vec, Vec);
917be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetNPCSide(SNES, PCSide);
918be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetNPCSide(SNES, PCSide *);
9197601faf0SJed Brown PETSC_EXTERN PetscErrorCode SNESSetLineSearch(SNES, SNESLineSearch);
9207601faf0SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLineSearch(SNES, SNESLineSearch *);
9216c699258SBarry Smith 
922edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 4, 0, "SNESGetLineSearch()", ) static inline PetscErrorCode SNESGetSNESLineSearch(SNES snes, SNESLineSearch *ls)
923d71ae5a4SJacob Faibussowitsch {
9249371c9d4SSatish Balay   return SNESGetLineSearch(snes, ls);
9259371c9d4SSatish Balay }
926edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 4, 0, "SNESSetLineSearch()", ) static inline PetscErrorCode SNESSetSNESLineSearch(SNES snes, SNESLineSearch ls)
927d71ae5a4SJacob Faibussowitsch {
9289371c9d4SSatish Balay   return SNESSetLineSearch(snes, ls);
9299371c9d4SSatish Balay }
9308b7b3213SJed Brown 
931014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetUpMatrices(SNES);
9328434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetFunction(DM, SNESFunctionFn *, void *);
9338434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetFunction(DM, SNESFunctionFn **, void **);
934800f99ffSJeremy L Thompson PETSC_EXTERN PetscErrorCode DMSNESSetFunctionContextDestroy(DM, PetscErrorCode (*)(void *));
9358434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetMFFunction(DM, SNESFunctionFn *, void *);
9368434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetNGS(DM, SNESNGSFn *, void *);
9378434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetNGS(DM, SNESNGSFn **, void **);
9388434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetJacobian(DM, SNESJacobianFn *, void *);
9398434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetJacobian(DM, SNESJacobianFn **, void **);
940800f99ffSJeremy L Thompson PETSC_EXTERN PetscErrorCode DMSNESSetJacobianContextDestroy(DM, PetscErrorCode (*)(void *));
9418434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetPicard(DM, SNESFunctionFn *, SNESJacobianFn *, void *);
9428434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetPicard(DM, SNESFunctionFn **, SNESJacobianFn **, void **);
9438434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetObjective(DM, SNESObjectiveFn *, void *);
9448434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetObjective(DM, SNESObjectiveFn **, void **);
9454dd50a75SBarry Smith PETSC_EXTERN PetscErrorCode DMCopyDMSNES(DM, DM);
9466cab3a1bSJed Brown 
9478434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(DMDASNESFunctionFn)(DMDALocalInfo *, void *, void *, void *);
9488434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(DMDASNESJacobianFn)(DMDALocalInfo *, void *, Mat, Mat, void *);
9498434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(DMDASNESObjectiveFn)(DMDALocalInfo *, void *, PetscReal *, void *);
950c9d099b5SPeter Brune 
9518434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(DMDASNESFunctionVecFn)(DMDALocalInfo *, Vec, Vec, void *);
9528434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(DMDASNESJacobianVecFn)(DMDALocalInfo *, Vec, Mat, Mat, void *);
9538434afd1SBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(DMDASNESObjectiveVecFn)(DMDALocalInfo *, Vec, PetscReal *, void *);
9545505f7afSJunchao Zhang 
9558434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMDASNESSetFunctionLocal(DM, InsertMode, DMDASNESFunctionFn *, void *);
9568434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMDASNESSetJacobianLocal(DM, DMDASNESJacobianFn *, void *);
9578434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMDASNESSetObjectiveLocal(DM, DMDASNESObjectiveFn *, void *);
9588434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMDASNESSetPicardLocal(DM, InsertMode, DMDASNESFunctionFn *, DMDASNESJacobianFn, void *);
9596cab3a1bSJed Brown 
9608434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMDASNESSetFunctionLocalVec(DM, InsertMode, DMDASNESFunctionVecFn *, void *);
9618434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMDASNESSetJacobianLocalVec(DM, DMDASNESJacobianVecFn *, void *);
9628434afd1SBarry Smith PETSC_EXTERN PetscErrorCode DMDASNESSetObjectiveLocalVec(DM, DMDASNESObjectiveVecFn *, void *);
9635505f7afSJunchao Zhang 
964bdd6f66aSToby Isaac PETSC_EXTERN PetscErrorCode DMSNESSetBoundaryLocal(DM, PetscErrorCode (*)(DM, Vec, void *), void *);
9656493148fSStefano Zampini PETSC_EXTERN PetscErrorCode DMSNESSetObjectiveLocal(DM, PetscErrorCode (*)(DM, Vec, PetscReal *, void *), void *);
966ff35dfedSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetFunctionLocal(DM, PetscErrorCode (*)(DM, Vec, Vec, void *), void *);
967d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetJacobianLocal(DM, PetscErrorCode (*)(DM, Vec, Mat, Mat, void *), void *);
96828d58a37SPierre Jolivet PETSC_EXTERN PetscErrorCode DMSNESGetBoundaryLocal(DM, PetscErrorCode (**)(DM, Vec, void *), void **);
9696493148fSStefano Zampini PETSC_EXTERN PetscErrorCode DMSNESGetObjectiveLocal(DM, PetscErrorCode (**)(DM, Vec, PetscReal *, void *), void **);
97028d58a37SPierre Jolivet PETSC_EXTERN PetscErrorCode DMSNESGetFunctionLocal(DM, PetscErrorCode (**)(DM, Vec, Vec, void *), void **);
97128d58a37SPierre Jolivet PETSC_EXTERN PetscErrorCode DMSNESGetJacobianLocal(DM, PetscErrorCode (**)(DM, Vec, Mat, Mat, void *), void **);
972ff35dfedSBarry Smith 
973b665c654SMatthew G Knepley /* Routines for Multiblock solver */
974014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMultiblockSetFields(SNES, const char[], PetscInt, const PetscInt *);
975014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMultiblockSetIS(SNES, const char[], IS);
976014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMultiblockSetBlockSize(SNES, PetscInt);
977014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMultiblockSetType(SNES, PCCompositeType);
9784bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode SNESMultiblockGetSubSNES(SNES, PetscInt *, SNES *[]);
979aeed3662SMatthew G Knepley 
98037e1895aSJed Brown /*J
98187497f52SBarry Smith    SNESMSType - String with the name of a PETSc `SNESMS` method.
98237e1895aSJed Brown 
98337e1895aSJed Brown    Level: intermediate
98437e1895aSJed Brown 
9851cc06b55SBarry Smith .seealso: [](ch_snes), `SNESMS`, `SNESMSGetType()`, `SNESMSSetType()`, `SNES`
98637e1895aSJed Brown J*/
98719fd82e9SBarry Smith typedef const char *SNESMSType;
98837e1895aSJed Brown #define SNESMSM62       "m62"
98937e1895aSJed Brown #define SNESMSEULER     "euler"
990a97cb6bcSJed Brown #define SNESMSJAMESON83 "jameson83"
9913847c725SLisandro Dalcin #define SNESMSVLTP11    "vltp11"
992a97cb6bcSJed Brown #define SNESMSVLTP21    "vltp21"
993a97cb6bcSJed Brown #define SNESMSVLTP31    "vltp31"
994a97cb6bcSJed Brown #define SNESMSVLTP41    "vltp41"
995a97cb6bcSJed Brown #define SNESMSVLTP51    "vltp51"
996a97cb6bcSJed Brown #define SNESMSVLTP61    "vltp61"
99737e1895aSJed Brown 
99819fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESMSRegister(SNESMSType, PetscInt, PetscInt, PetscReal, const PetscReal[], const PetscReal[], const PetscReal[]);
9994bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode SNESMSRegisterAll(void);
100057715debSLisandro Dalcin PETSC_EXTERN PetscErrorCode SNESMSGetType(SNES, SNESMSType *);
100119fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESMSSetType(SNES, SNESMSType);
100257715debSLisandro Dalcin PETSC_EXTERN PetscErrorCode SNESMSGetDamping(SNES, PetscReal *);
100357715debSLisandro Dalcin PETSC_EXTERN PetscErrorCode SNESMSSetDamping(SNES, PetscReal);
1004014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMSFinalizePackage(void);
1005607a6623SBarry Smith PETSC_EXTERN PetscErrorCode SNESMSInitializePackage(void);
1006014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMSRegisterDestroy(void);
100737e1895aSJed Brown 
1008ceaaa498SBarry Smith /*MC
1009ceaaa498SBarry Smith    SNESNGMRESRestartType - the restart approach used by `SNESNGMRES`
101013a62661SPeter Brune 
1011ceaaa498SBarry Smith   Values:
1012ceaaa498SBarry Smith +   `SNES_NGMRES_RESTART_NONE`       - never restart
1013ceaaa498SBarry Smith .   `SNES_NGMRES_RESTART_DIFFERENCE` - restart based upon difference criteria
1014ceaaa498SBarry Smith -   `SNES_NGMRES_RESTART_PERIODIC`   - restart after a fixed number of iterations
1015ceaaa498SBarry Smith 
1016ceaaa498SBarry Smith   Options Database Keys:
1017ceaaa498SBarry Smith + -snes_ngmres_restart_type <difference,periodic,none> - set the restart type
1018af27ebaaSBarry Smith - -snes_ngmres_restart <30>                            - sets the number of iterations before restart for periodic
1019ceaaa498SBarry Smith 
102095bd0b28SBarry Smith    Level: intermediate
102195bd0b28SBarry Smith 
1022ceaaa498SBarry Smith .seealso: `SNES, `SNESNGMRES`, `SNESNGMRESSetSelectType()`, `SNESNGMRESGetSelectType()`, `SNESNGMRESSetRestartType()`,
1023ceaaa498SBarry Smith           `SNESNGMRESGetRestartType()`, `SNESNGMRESSelectType`
1024ceaaa498SBarry Smith M*/
102513a62661SPeter Brune typedef enum {
102613a62661SPeter Brune   SNES_NGMRES_RESTART_NONE       = 0,
102713a62661SPeter Brune   SNES_NGMRES_RESTART_PERIODIC   = 1,
10289371c9d4SSatish Balay   SNES_NGMRES_RESTART_DIFFERENCE = 2
10299371c9d4SSatish Balay } SNESNGMRESRestartType;
10306a6fc655SJed Brown PETSC_EXTERN const char *const SNESNGMRESRestartTypes[];
103113a62661SPeter Brune 
1032ceaaa498SBarry Smith /*MC
1033ceaaa498SBarry Smith    SNESNGMRESSelectType - the approach used by `SNESNGMRES` to determine how the candidate solution and
1034ceaaa498SBarry Smith   combined solution are used to create the next iterate.
1035ceaaa498SBarry Smith 
1036ceaaa498SBarry Smith    Values:
1037ceaaa498SBarry Smith +   `SNES_NGMRES_SELECT_NONE`       - choose the combined solution all the time
1038ceaaa498SBarry Smith .   `SNES_NGMRES_SELECT_DIFFERENCE` - choose based upon the selection criteria
1039ceaaa498SBarry Smith -   `SNES_NGMRES_SELECT_LINESEARCH` - choose based upon line search combination
1040ceaaa498SBarry Smith 
1041ceaaa498SBarry Smith   Options Database Key:
1042ceaaa498SBarry Smith . -snes_ngmres_select_type<difference,none,linesearch> - select type
1043ceaaa498SBarry Smith 
104495bd0b28SBarry Smith    Level: intermediate
104595bd0b28SBarry Smith 
1046ceaaa498SBarry Smith .seealso: `SNES, `SNESNGMRES`, `SNESNGMRESSetSelectType()`, `SNESNGMRESGetSelectType()`, `SNESNGMRESSetRestartType()`,
1047ceaaa498SBarry Smith           `SNESNGMRESGetRestartType()`, `SNESNGMRESRestartType`
1048ceaaa498SBarry Smith M*/
104913a62661SPeter Brune typedef enum {
105013a62661SPeter Brune   SNES_NGMRES_SELECT_NONE       = 0,
105113a62661SPeter Brune   SNES_NGMRES_SELECT_DIFFERENCE = 1,
10529371c9d4SSatish Balay   SNES_NGMRES_SELECT_LINESEARCH = 2
10539371c9d4SSatish Balay } SNESNGMRESSelectType;
10546a6fc655SJed Brown PETSC_EXTERN const char *const SNESNGMRESSelectTypes[];
105513a62661SPeter Brune 
1056014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESNGMRESSetRestartType(SNES, SNESNGMRESRestartType);
1057014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESNGMRESSetSelectType(SNES, SNESNGMRESSelectType);
105823b3e82cSAsbjørn Nilsen Riseth PETSC_EXTERN PetscErrorCode SNESNGMRESSetRestartFmRise(SNES, PetscBool);
105923b3e82cSAsbjørn Nilsen Riseth PETSC_EXTERN PetscErrorCode SNESNGMRESGetRestartFmRise(SNES, PetscBool *);
106013a62661SPeter Brune 
1061ceaaa498SBarry Smith /*MC
1062ceaaa498SBarry Smith    SNESNCGType - the conjugate update approach for `SNESNCG`
10630a844d1aSPeter Brune 
1064ceaaa498SBarry Smith    Values:
1065ceaaa498SBarry Smith +   `SNES_NCG_FR`  - Fletcher-Reeves update
1066ceaaa498SBarry Smith .   `SNES_NCG_PRP` - Polak-Ribiere-Polyak update, the default and the only one that tolerates generalized search directions
1067ceaaa498SBarry Smith .   `SNES_NCG_HS`  - Hestenes-Steifel update
1068ceaaa498SBarry Smith .   `SNES_NCG_DY`  - Dai-Yuan update
1069ceaaa498SBarry Smith -   `SNES_NCG_CD`  - Conjugate Descent update
1070ceaaa498SBarry Smith 
1071ceaaa498SBarry Smith   Options Database Key:
1072ceaaa498SBarry Smith . -snes_ncg_type<fr,prp,hs,dy,cd> - select type
1073ceaaa498SBarry Smith 
107495bd0b28SBarry Smith    Level: intermediate
107595bd0b28SBarry Smith 
1076ceaaa498SBarry Smith .seealso: `SNES, `SNESNCG`, `SNESNCGSetType()`
1077ceaaa498SBarry Smith M*/
10780a844d1aSPeter Brune typedef enum {
10790de8b71eSPeter Brune   SNES_NCG_FR  = 0,
10800de8b71eSPeter Brune   SNES_NCG_PRP = 1,
10810de8b71eSPeter Brune   SNES_NCG_HS  = 2,
10820de8b71eSPeter Brune   SNES_NCG_DY  = 3,
10839371c9d4SSatish Balay   SNES_NCG_CD  = 4
10849371c9d4SSatish Balay } SNESNCGType;
10856a6fc655SJed Brown PETSC_EXTERN const char *const SNESNCGTypes[];
10860a844d1aSPeter Brune 
1087014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESNCGSetType(SNES, SNESNCGType);
108813a62661SPeter Brune 
1089ceaaa498SBarry Smith /*MC
1090ceaaa498SBarry Smith    SNESQNScaleType - the scaling type used by `SNESQN`
1091ceaaa498SBarry Smith 
1092ceaaa498SBarry Smith    Values:
1093ceaaa498SBarry Smith +   `SNES_QN_SCALE_NONE`     - don't scale the problem
1094ceaaa498SBarry Smith .   `SNES_QN_SCALE_SCALAR`   - use Shanno scaling
1095ceaaa498SBarry Smith .   `SNES_QN_SCALE_DIAGONAL` - scale with a diagonalized BFGS formula (see Gilbert and Lemarechal 1989), available
1096ceaaa498SBarry Smith -   `SNES_QN_SCALE_JACOBIAN` - scale by solving a linear system coming from the Jacobian you provided with `SNESSetJacobian()`
1097ceaaa498SBarry Smith                                computed at the first iteration of `SNESQN` and at ever restart.
1098ceaaa498SBarry Smith 
1099ceaaa498SBarry Smith     Options Database Key:
1100ceaaa498SBarry Smith . -snes_qn_scale_type <diagonal,none,scalar,jacobian> - Scaling type
1101ceaaa498SBarry Smith 
110295bd0b28SBarry Smith    Level: intermediate
110395bd0b28SBarry Smith 
1104ceaaa498SBarry Smith .seealso: `SNES, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNType`, `SNESQNSetType()`, `SNESQNSetRestartType()`, `SNESQNRestartType`
1105ceaaa498SBarry Smith M*/
11069371c9d4SSatish Balay typedef enum {
11079371c9d4SSatish Balay   SNES_QN_SCALE_DEFAULT  = 0,
11081efc8c45SPeter Brune   SNES_QN_SCALE_NONE     = 1,
110992f76d53SAlp Dener   SNES_QN_SCALE_SCALAR   = 2,
111092f76d53SAlp Dener   SNES_QN_SCALE_DIAGONAL = 3,
11119371c9d4SSatish Balay   SNES_QN_SCALE_JACOBIAN = 4
11129371c9d4SSatish Balay } SNESQNScaleType;
11136a6fc655SJed Brown PETSC_EXTERN const char *const SNESQNScaleTypes[];
1114ceaaa498SBarry Smith 
1115ceaaa498SBarry Smith /*MC
1116ceaaa498SBarry Smith    SNESQNRestartType - the restart approached used by `SNESQN`
1117ceaaa498SBarry Smith 
1118ceaaa498SBarry Smith    Values:
1119ceaaa498SBarry Smith +   `SNES_QN_RESTART_NONE`     - never restart
1120ceaaa498SBarry Smith .   `SNES_QN_RESTART_POWELL`   - restart based upon descent criteria
1121ceaaa498SBarry Smith -   `SNES_QN_RESTART_PERIODIC` - restart after a fixed number of iterations
1122ceaaa498SBarry Smith 
1123ceaaa498SBarry Smith   Options Database Keys:
1124ceaaa498SBarry Smith + -snes_qn_restart_type <powell,periodic,none> - set the restart type
1125ceaaa498SBarry Smith - -snes_qn_m <m>                               - sets the number of stored updates and the restart period for periodic
1126ceaaa498SBarry Smith 
112795bd0b28SBarry Smith    Level: intermediate
112895bd0b28SBarry Smith 
1129ceaaa498SBarry Smith .seealso: `SNES, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNType`, `SNESQNSetType()`, `SNESQNSetRestartType()`, `SNESQNScaleType`
1130ceaaa498SBarry Smith M*/
11319371c9d4SSatish Balay typedef enum {
11329371c9d4SSatish Balay   SNES_QN_RESTART_DEFAULT  = 0,
11331efc8c45SPeter Brune   SNES_QN_RESTART_NONE     = 1,
11341efc8c45SPeter Brune   SNES_QN_RESTART_POWELL   = 2,
11359371c9d4SSatish Balay   SNES_QN_RESTART_PERIODIC = 3
11369371c9d4SSatish Balay } SNESQNRestartType;
11376a6fc655SJed Brown PETSC_EXTERN const char *const SNESQNRestartTypes[];
1138ceaaa498SBarry Smith 
1139ceaaa498SBarry Smith /*MC
1140ceaaa498SBarry Smith    SNESQNType - the type used by `SNESQN`
1141ceaaa498SBarry Smith 
1142ceaaa498SBarry Smith   Values:
1143ceaaa498SBarry Smith +   `SNES_QN_LBFGS`      - LBFGS variant
1144ceaaa498SBarry Smith .   `SNES_QN_BROYDEN`    - Broyden variant
1145ceaaa498SBarry Smith -   `SNES_QN_BADBROYDEN` - Bad Broyden variant
1146ceaaa498SBarry Smith 
1147ceaaa498SBarry Smith   Options Database Key:
1148ceaaa498SBarry Smith . -snes_qn_type <lbfgs,broyden,badbroyden> - quasi-Newton type
1149ceaaa498SBarry Smith 
115095bd0b28SBarry Smith    Level: intermediate
115195bd0b28SBarry Smith 
1152ceaaa498SBarry Smith .seealso: `SNES, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNSetType()`, `SNESQNScaleType`, `SNESQNRestartType`, `SNESQNSetRestartType()`
1153ceaaa498SBarry Smith M*/
11549371c9d4SSatish Balay typedef enum {
11559371c9d4SSatish Balay   SNES_QN_LBFGS      = 0,
11561efc8c45SPeter Brune   SNES_QN_BROYDEN    = 1,
11571efc8c45SPeter Brune   SNES_QN_BADBROYDEN = 2
11581efc8c45SPeter Brune } SNESQNType;
11591efc8c45SPeter Brune PETSC_EXTERN const char *const SNESQNTypes[];
11600c777b0cSPeter Brune 
11611efc8c45SPeter Brune PETSC_EXTERN PetscErrorCode SNESQNSetType(SNES, SNESQNType);
1162014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESQNSetScaleType(SNES, SNESQNScaleType);
1163014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESQNSetRestartType(SNES, SNESQNRestartType);
11640c777b0cSPeter Brune 
1165e0331734SPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMGetType(SNES, PCASMType *);
1166e0331734SPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMSetType(SNES, PCASMType);
116776857b2aSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMGetSubdomains(SNES, PetscInt *, SNES **, VecScatter **, VecScatter **, VecScatter **);
116876857b2aSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMSetSubdomains(SNES, PetscInt, SNES *, VecScatter *, VecScatter *, VecScatter *);
1169610116beSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMSetDamping(SNES, PetscReal);
1170610116beSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMGetDamping(SNES, PetscReal *);
117176857b2aSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMGetSubdomainVecs(SNES, PetscInt *, Vec **, Vec **, Vec **, Vec **);
1172d728fb7dSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMSetComputeFinalJacobian(SNES, PetscBool);
1173d2dc0b00SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESNASMGetSNES(SNES, PetscInt, SNES *);
1174d2dc0b00SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESNASMGetNumber(SNES, PetscInt *);
1175f10b3e88SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESNASMSetWeight(SNES, Vec);
11760c777b0cSPeter Brune 
1177ad05f2b7SBarry Smith /*E
1178ad05f2b7SBarry Smith   SNESCompositeType - Determines how two or more preconditioners are composed with the `SNESType` of `SNESCOMPOSITE`
1179ad05f2b7SBarry Smith 
1180ad05f2b7SBarry Smith   Values:
1181ad05f2b7SBarry Smith + `SNES_COMPOSITE_ADDITIVE`        - results from application of all preconditioners are added together
1182ad05f2b7SBarry Smith . `SNES_COMPOSITE_MULTIPLICATIVE`  - preconditioners are applied sequentially to the residual freshly
1183ad05f2b7SBarry Smith                                      computed after the previous preconditioner application
1184ad05f2b7SBarry Smith - `SNES_COMPOSITE_ADDITIVEOPTIMAL` - uses a linear combination of the solutions obtained with each preconditioner that approximately minimize the function
1185ad05f2b7SBarry Smith                                      value at the new iteration.
1186ad05f2b7SBarry Smith 
1187ad05f2b7SBarry Smith    Level: beginner
1188ad05f2b7SBarry Smith 
1189ad05f2b7SBarry Smith .seealso: [](sec_pc), `PCCOMPOSITE`, `PCFIELDSPLIT`, `PC`, `PCCompositeSetType()`, `PCCompositeType`
1190ad05f2b7SBarry Smith E*/
11919371c9d4SSatish Balay typedef enum {
11929371c9d4SSatish Balay   SNES_COMPOSITE_ADDITIVE,
11939371c9d4SSatish Balay   SNES_COMPOSITE_MULTIPLICATIVE,
11949371c9d4SSatish Balay   SNES_COMPOSITE_ADDITIVEOPTIMAL
11959371c9d4SSatish Balay } SNESCompositeType;
1196eed5f15bSPeter Brune PETSC_EXTERN const char *const SNESCompositeTypes[];
1197eed5f15bSPeter Brune 
1198eed5f15bSPeter Brune PETSC_EXTERN PetscErrorCode SNESCompositeSetType(SNES, SNESCompositeType);
1199eed5f15bSPeter Brune PETSC_EXTERN PetscErrorCode SNESCompositeAddSNES(SNES, SNESType);
1200eed5f15bSPeter Brune PETSC_EXTERN PetscErrorCode SNESCompositeGetSNES(SNES, PetscInt, SNES *);
1201a6b47ab3SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESCompositeGetNumber(SNES, PetscInt *);
12028f626970SPeter Brune PETSC_EXTERN PetscErrorCode SNESCompositeSetDamping(SNES, PetscInt, PetscReal);
1203eed5f15bSPeter Brune 
120468e6d53eSPatrick Farrell PETSC_EXTERN PetscErrorCode SNESPatchSetDiscretisationInfo(SNES, PetscInt, DM *, PetscInt *, PetscInt *, const PetscInt **, const PetscInt *, PetscInt, const PetscInt *, PetscInt, const PetscInt *);
12054d04e9f1SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESPatchSetComputeOperator(SNES, PetscErrorCode (*func)(PC, PetscInt, Vec, Mat, IS, PetscInt, const PetscInt *, const PetscInt *, void *), void *);
120639fd2e8aSPatrick Farrell PETSC_EXTERN PetscErrorCode SNESPatchSetComputeFunction(SNES, PetscErrorCode (*func)(PC, PetscInt, Vec, Vec, IS, PetscInt, const PetscInt *, const PetscInt *, void *), void *);
120768e6d53eSPatrick Farrell PETSC_EXTERN PetscErrorCode SNESPatchSetConstructType(SNES, PCPatchConstructType, PetscErrorCode (*func)(PC, PetscInt *, IS **, IS *, void *), void *);
120868e6d53eSPatrick Farrell PETSC_EXTERN PetscErrorCode SNESPatchSetCellNumbering(SNES, PetscSection);
1209561742edSMatthew G. Knepley 
1210a055c8caSBarry Smith /*E
1211a055c8caSBarry Smith     SNESFASType - Determines the type of nonlinear multigrid method that is run.
1212a055c8caSBarry Smith 
1213a055c8caSBarry Smith    Values:
121487497f52SBarry Smith +  `SNES_FAS_MULTIPLICATIVE` (default) - traditional V or W cycle as determined by `SNESFASSetCycles()`
121587497f52SBarry Smith .  `SNES_FAS_ADDITIVE`                 - additive FAS cycle
121687497f52SBarry Smith .  `SNES_FAS_FULL`                     - full FAS cycle
121787497f52SBarry Smith -  `SNES_FAS_KASKADE`                  - Kaskade FAS cycle
1218a055c8caSBarry Smith 
121916a05f60SBarry Smith    Level: beginner
122016a05f60SBarry Smith 
12211cc06b55SBarry Smith .seealso: [](ch_snes), `SNESFAS`, `PCMGSetType()`, `PCMGType`
1222a055c8caSBarry Smith E*/
12239371c9d4SSatish Balay typedef enum {
12249371c9d4SSatish Balay   SNES_FAS_MULTIPLICATIVE,
12259371c9d4SSatish Balay   SNES_FAS_ADDITIVE,
12269371c9d4SSatish Balay   SNES_FAS_FULL,
12279371c9d4SSatish Balay   SNES_FAS_KASKADE
12289371c9d4SSatish Balay } SNESFASType;
1229a055c8caSBarry Smith PETSC_EXTERN const char *const SNESFASTypes[];
1230a055c8caSBarry Smith 
1231a055c8caSBarry Smith /* called on the finest level FAS instance*/
1232a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetType(SNES, SNESFASType);
1233a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetType(SNES, SNESFASType *);
1234a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetLevels(SNES, PetscInt, MPI_Comm *);
1235a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetLevels(SNES, PetscInt *);
1236a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetCycleSNES(SNES, PetscInt, SNES *);
1237a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetNumberSmoothUp(SNES, PetscInt);
1238a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetNumberSmoothDown(SNES, PetscInt);
1239a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetCycles(SNES, PetscInt);
1240d142ab34SLawrence Mitchell PETSC_EXTERN PetscErrorCode SNESFASSetMonitor(SNES, PetscViewerAndFormat *, PetscBool);
1241a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetLog(SNES, PetscBool);
1242a055c8caSBarry Smith 
1243a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetGalerkin(SNES, PetscBool);
1244a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetGalerkin(SNES, PetscBool *);
124525acbd8eSLisandro Dalcin PETSC_EXTERN PetscErrorCode SNESFASGalerkinFunctionDefault(SNES, Vec, Vec, void *);
1246a055c8caSBarry Smith 
1247a055c8caSBarry Smith /* called on any level -- "Cycle" FAS instance */
1248a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmoother(SNES, SNES *);
1249a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmootherUp(SNES, SNES *);
1250a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmootherDown(SNES, SNES *);
1251a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetCorrection(SNES, SNES *);
1252a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetInterpolation(SNES, Mat *);
1253a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetRestriction(SNES, Mat *);
1254a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetInjection(SNES, Mat *);
1255a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetRScale(SNES, Vec *);
1256a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleSetCycles(SNES, PetscInt);
1257a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleIsFine(SNES, PetscBool *);
1258a055c8caSBarry Smith 
1259a055c8caSBarry Smith /* called on the (outer) finest level FAS to set/get parameters on any level instance */
1260a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetInterpolation(SNES, PetscInt, Mat);
1261a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetInterpolation(SNES, PetscInt, Mat *);
1262a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetRestriction(SNES, PetscInt, Mat);
1263a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetRestriction(SNES, PetscInt, Mat *);
1264a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetInjection(SNES, PetscInt, Mat);
1265a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetInjection(SNES, PetscInt, Mat *);
1266a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetRScale(SNES, PetscInt, Vec);
1267a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetRScale(SNES, PetscInt, Vec *);
1268020631bcSPeter Brune PETSC_EXTERN PetscErrorCode SNESFASSetContinuation(SNES, PetscBool);
1269a055c8caSBarry Smith 
1270a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetSmoother(SNES, PetscInt, SNES *);
1271a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetSmootherUp(SNES, PetscInt, SNES *);
1272a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetSmootherDown(SNES, PetscInt, SNES *);
1273a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetCoarseSolve(SNES, SNES *);
1274a055c8caSBarry Smith 
1275a055c8caSBarry Smith /* parameters for full FAS */
1276a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASFullSetDownSweep(SNES, PetscBool);
1277a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCreateCoarseVec(SNES, Vec *);
1278a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASRestrict(SNES, Vec, Vec);
12796dfbafefSToby Isaac PETSC_EXTERN PetscErrorCode SNESFASFullSetTotal(SNES, PetscBool);
12806dfbafefSToby Isaac PETSC_EXTERN PetscErrorCode SNESFASFullGetTotal(SNES, PetscBool *);
1281a055c8caSBarry Smith 
1282f2cacb80SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMSNESCheckDiscretization(SNES, DM, PetscReal, Vec, PetscReal, PetscReal[]);
1283f3c94560SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMSNESCheckResidual(SNES, DM, Vec, PetscReal, PetscReal *);
1284f3c94560SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMSNESCheckJacobian(SNES, DM, Vec, PetscReal, PetscBool *, PetscReal *);
12857f96f943SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMSNESCheckFromOptions(SNES, Vec);
12868e3a2eefSMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMSNESComputeJacobianAction(DM, Vec, Vec, Vec, void *);
12878e3a2eefSMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMSNESCreateJacobianMF(DM, Vec, void *, Mat *);
1288*97276fddSZach Atkins 
1289*97276fddSZach Atkins PETSC_EXTERN PetscErrorCode SNESNewtonALSetFunction(SNES, SNESFunctionFn *, void *ctx);
1290*97276fddSZach Atkins PETSC_EXTERN PetscErrorCode SNESNewtonALGetFunction(SNES, SNESFunctionFn **, void **ctx);
1291*97276fddSZach Atkins PETSC_EXTERN PetscErrorCode SNESNewtonALComputeFunction(SNES, Vec, Vec);
1292*97276fddSZach Atkins PETSC_EXTERN PetscErrorCode SNESNewtonALGetLoadParameter(SNES, PetscReal *);
1293*97276fddSZach Atkins 
1294*97276fddSZach Atkins /*MC
1295*97276fddSZach Atkins    SNESNewtonALCorrectionType - the approach used by `SNESNEWTONAL` to determine
1296*97276fddSZach Atkins    the correction to the current increment. While the exact correction satisfies
1297*97276fddSZach Atkins    the constraint surface at every iteration, it also requires solving a quadratic
1298*97276fddSZach Atkins    equation which may not have real roots. Conversely, the normal correction is more
1299*97276fddSZach Atkins    efficient and always yields a real correction and is the default.
1300*97276fddSZach Atkins 
1301*97276fddSZach Atkins    Values:
1302*97276fddSZach Atkins +   `SNES_NEWTONAL_CORRECTION_EXACT` - choose the correction which exactly satisfies the constraint
1303*97276fddSZach Atkins -   `SNES_NEWTONAL_CORRECTION_NORMAL` - choose the correction in the updated normal hyper-surface to the contraint surface
1304*97276fddSZach Atkins 
1305*97276fddSZach Atkins    Options Database Key:
1306*97276fddSZach Atkins . -snes_newtonal_correction_type <exact> - select type from <exact,normal>
1307*97276fddSZach Atkins 
1308*97276fddSZach Atkins    Level: intermediate
1309*97276fddSZach Atkins 
1310*97276fddSZach Atkins .seealso: `SNES`, `SNESNEWTONAL`, `SNESNewtonALSetCorrectionType()`
1311*97276fddSZach Atkins M*/
1312*97276fddSZach Atkins typedef enum {
1313*97276fddSZach Atkins   SNES_NEWTONAL_CORRECTION_EXACT  = 0,
1314*97276fddSZach Atkins   SNES_NEWTONAL_CORRECTION_NORMAL = 1,
1315*97276fddSZach Atkins } SNESNewtonALCorrectionType;
1316*97276fddSZach Atkins PETSC_EXTERN const char *const SNESNewtonALCorrectionTypes[];
1317*97276fddSZach Atkins 
1318*97276fddSZach Atkins PETSC_EXTERN PetscErrorCode SNESNewtonALSetCorrectionType(SNES, SNESNewtonALCorrectionType);
1319