Actual source code: petscsnes.h

  1: /*
  2:     User interface for the nonlinear solvers package.
  3: */
  4: #pragma once

  6: #include <petscksp.h>
  7: #include <petscdmtypes.h>
  8: #include <petscfvtypes.h>
  9: #include <petscdmdatypes.h>
 10: #include <petscsnestypes.h>

 12: /* SUBMANSEC = SNES */

 14: /*J
 15:    SNESType - String with the name of a PETSc `SNES` method. These are all the nonlinear solvers that PETSc provides.

 17:    Level: beginner

 19:    Note:
 20:    Use `SNESSetType()` or the options database key `-snes_type` to set the specific nonlinear solver algorithm to use with a given `SNES` object

 22: .seealso: [](doc_nonlinsolve), [](ch_snes), `SNESSetType()`, `SNES`, `SNESCreate()`, `SNESDestroy()`, `SNESSetFromOptions()`
 23: J*/
 24: typedef const char *SNESType;
 25: #define SNESNEWTONLS         "newtonls"
 26: #define SNESNEWTONTR         "newtontr"
 27: #define SNESNEWTONTRDC       "newtontrdc"
 28: #define SNESPYTHON           "python"
 29: #define SNESNRICHARDSON      "nrichardson"
 30: #define SNESKSPONLY          "ksponly"
 31: #define SNESKSPTRANSPOSEONLY "ksptransposeonly"
 32: #define SNESVINEWTONRSLS     "vinewtonrsls"
 33: #define SNESVINEWTONSSLS     "vinewtonssls"
 34: #define SNESNGMRES           "ngmres"
 35: #define SNESQN               "qn"
 36: #define SNESSHELL            "shell"
 37: #define SNESNGS              "ngs"
 38: #define SNESNCG              "ncg"
 39: #define SNESFAS              "fas"
 40: #define SNESMS               "ms"
 41: #define SNESNASM             "nasm"
 42: #define SNESANDERSON         "anderson"
 43: #define SNESASPIN            "aspin"
 44: #define SNESCOMPOSITE        "composite"
 45: #define SNESPATCH            "patch"
 46: #define SNESNEWTONAL         "newtonal"

 48: /* Logging support */
 49: PETSC_EXTERN PetscClassId SNES_CLASSID;
 50: PETSC_EXTERN PetscClassId DMSNES_CLASSID;

 52: PETSC_EXTERN PetscErrorCode SNESInitializePackage(void);
 53: PETSC_EXTERN PetscErrorCode SNESFinalizePackage(void);

 55: PETSC_EXTERN PetscErrorCode SNESCreate(MPI_Comm, SNES *);
 56: PETSC_EXTERN PetscErrorCode SNESParametersInitialize(SNES);
 57: PETSC_EXTERN PetscErrorCode SNESReset(SNES);
 58: PETSC_EXTERN PetscErrorCode SNESDestroy(SNES *);
 59: PETSC_EXTERN PetscErrorCode SNESSetType(SNES, SNESType);
 60: PETSC_EXTERN PetscErrorCode SNESMonitor(SNES, PetscInt, PetscReal);
 61: PETSC_EXTERN PetscErrorCode SNESMonitorSet(SNES, PetscErrorCode (*)(SNES, PetscInt, PetscReal, PetscCtx), PetscCtx, PetscCtxDestroyFn *);
 62: PETSC_EXTERN PetscErrorCode SNESMonitorSetFromOptions(SNES, const char[], const char[], const char[], PetscErrorCode (*)(SNES, PetscInt, PetscReal, PetscViewerAndFormat *), PetscErrorCode (*)(SNES, PetscViewerAndFormat *));
 63: PETSC_EXTERN PetscErrorCode SNESMonitorCancel(SNES);
 64: PETSC_EXTERN PetscErrorCode SNESMonitorSAWs(SNES, PetscInt, PetscReal, PetscCtx);
 65: PETSC_EXTERN PetscErrorCode SNESMonitorSAWsCreate(SNES, void **);
 66: PETSC_EXTERN PetscErrorCode SNESMonitorSAWsDestroy(PetscCtxRt);
 67: PETSC_EXTERN PetscErrorCode SNESSetConvergenceHistory(SNES, PetscReal[], PetscInt[], PetscInt, PetscBool);
 68: PETSC_EXTERN PetscErrorCode SNESGetConvergenceHistory(SNES, PetscReal *[], PetscInt *[], PetscInt *);
 69: PETSC_EXTERN PetscErrorCode SNESSetUp(SNES);
 70: PETSC_EXTERN PetscErrorCode SNESSolve(SNES, Vec, Vec);
 71: PETSC_EXTERN PetscErrorCode SNESSetErrorIfNotConverged(SNES, PetscBool);
 72: PETSC_EXTERN PetscErrorCode SNESGetErrorIfNotConverged(SNES, PetscBool *);
 73: PETSC_EXTERN PetscErrorCode SNESConverged(SNES, PetscInt, PetscReal, PetscReal, PetscReal);

 75: PETSC_EXTERN PetscErrorCode SNESSetWorkVecs(SNES, PetscInt);

 77: PETSC_EXTERN PetscErrorCode SNESAddOptionsChecker(PetscErrorCode (*)(SNES));

 79: PETSC_EXTERN PetscErrorCode SNESRegister(const char[], PetscErrorCode (*)(SNES));

 81: PETSC_EXTERN PetscErrorCode SNESGetKSP(SNES, KSP *);
 82: PETSC_EXTERN PetscErrorCode SNESSetKSP(SNES, KSP);
 83: PETSC_EXTERN PetscErrorCode SNESSetSolution(SNES, Vec);
 84: PETSC_EXTERN PetscErrorCode SNESGetSolution(SNES, Vec *);
 85: PETSC_EXTERN PetscErrorCode SNESGetSolutionUpdate(SNES, Vec *);
 86: PETSC_EXTERN PetscErrorCode SNESGetRhs(SNES, Vec *);
 87: PETSC_EXTERN PetscErrorCode SNESView(SNES, PetscViewer);
 88: PETSC_EXTERN PetscErrorCode SNESLoad(SNES, PetscViewer);
 89: PETSC_EXTERN PetscErrorCode SNESConvergedReasonViewSet(SNES, PetscErrorCode (*)(SNES, PetscCtx), PetscCtx, PetscCtxDestroyFn *);
 90: PETSC_EXTERN PetscErrorCode SNESViewFromOptions(SNES, PetscObject, const char[]);
 91: PETSC_EXTERN PetscErrorCode SNESConvergedReasonView(SNES, PetscViewer);
 92: PETSC_EXTERN PetscErrorCode SNESConvergedReasonViewFromOptions(SNES);
 93: PETSC_EXTERN PetscErrorCode SNESConvergedReasonViewCancel(SNES);

 95: PETSC_DEPRECATED_FUNCTION(3, 14, 0, "SNESConvergedReasonView()", ) static inline PetscErrorCode SNESReasonView(SNES snes, PetscViewer v)
 96: {
 97:   return SNESConvergedReasonView(snes, v);
 98: }
 99: PETSC_DEPRECATED_FUNCTION(3, 14, 0, "SNESConvergedReasonViewFromOptions()", ) static inline PetscErrorCode SNESReasonViewFromOptions(SNES snes)
100: {
101:   return SNESConvergedReasonViewFromOptions(snes);
102: }

104: #define SNES_FILE_CLASSID 1211224

106: PETSC_EXTERN PetscErrorCode SNESSetOptionsPrefix(SNES, const char[]);
107: PETSC_EXTERN PetscErrorCode SNESAppendOptionsPrefix(SNES, const char[]);
108: PETSC_EXTERN PetscErrorCode SNESGetOptionsPrefix(SNES, const char *[]);
109: PETSC_EXTERN PetscErrorCode SNESSetFromOptions(SNES);
110: PETSC_EXTERN PetscErrorCode SNESResetFromOptions(SNES);

112: PETSC_EXTERN PetscErrorCode SNESSetUseMatrixFree(SNES, PetscBool, PetscBool);
113: PETSC_EXTERN PetscErrorCode SNESGetUseMatrixFree(SNES, PetscBool *, PetscBool *);
114: PETSC_EXTERN PetscErrorCode MatCreateSNESMF(SNES, Mat *);
115: PETSC_EXTERN PetscErrorCode MatSNESMFGetSNES(Mat, SNES *);
116: PETSC_EXTERN PetscErrorCode MatSNESMFSetReuseBase(Mat, PetscBool);
117: PETSC_EXTERN PetscErrorCode MatSNESMFGetReuseBase(Mat, PetscBool *);
118: PETSC_EXTERN PetscErrorCode MatMFFDComputeJacobian(SNES, Vec, Mat, Mat, void *);
119: PETSC_EXTERN PetscErrorCode MatCreateSNESMFMore(SNES, Vec, Mat *);
120: PETSC_EXTERN PetscErrorCode MatSNESMFMoreSetParameters(Mat, PetscReal, PetscReal, PetscReal);

122: PETSC_EXTERN PetscErrorCode SNESGetType(SNES, SNESType *);
123: PETSC_EXTERN PetscErrorCode SNESMonitorDefaultSetUp(SNES, PetscViewerAndFormat *);
124: PETSC_EXTERN PetscErrorCode SNESMonitorDefault(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
125: PETSC_EXTERN PetscErrorCode SNESMonitorScaling(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
126: PETSC_EXTERN PetscErrorCode SNESMonitorRange(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
127: PETSC_EXTERN PetscErrorCode SNESMonitorRatio(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
128: PETSC_EXTERN PetscErrorCode SNESMonitorRatioSetUp(SNES, PetscViewerAndFormat *);
129: PETSC_EXTERN PetscErrorCode SNESMonitorSolution(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
130: PETSC_EXTERN PetscErrorCode SNESMonitorResidual(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
131: PETSC_EXTERN PetscErrorCode SNESMonitorSolutionUpdate(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
132: PETSC_EXTERN PetscErrorCode SNESMonitorDefaultShort(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
133: PETSC_EXTERN PetscErrorCode SNESMonitorDefaultField(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
134: PETSC_EXTERN PetscErrorCode SNESMonitorJacUpdateSpectrum(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
135: PETSC_EXTERN PetscErrorCode SNESMonitorFields(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
136: PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidual(KSP, PetscInt, PetscReal, PetscViewerAndFormat *);
137: PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidualDrawLG(KSP, PetscInt, PetscReal, PetscViewerAndFormat *);
138: PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidualDrawLGCreate(PetscViewer, PetscViewerFormat, PetscCtx, PetscViewerAndFormat **);

140: PETSC_EXTERN PetscErrorCode SNESSetTolerances(SNES, PetscReal, PetscReal, PetscReal, PetscInt, PetscInt);
141: PETSC_EXTERN PetscErrorCode SNESSetDivergenceTolerance(SNES, PetscReal);
142: PETSC_EXTERN PetscErrorCode SNESGetTolerances(SNES, PetscReal *, PetscReal *, PetscReal *, PetscInt *, PetscInt *);
143: PETSC_EXTERN PetscErrorCode SNESGetDivergenceTolerance(SNES, PetscReal *);
144: PETSC_EXTERN PetscErrorCode SNESGetForceIteration(SNES, PetscBool *);
145: PETSC_EXTERN PetscErrorCode SNESSetForceIteration(SNES, PetscBool);
146: PETSC_EXTERN PetscErrorCode SNESGetIterationNumber(SNES, PetscInt *);
147: PETSC_EXTERN PetscErrorCode SNESSetIterationNumber(SNES, PetscInt);

149: /*E
150:    SNESNewtonTRFallbackType - type of fallback in case the solution of the trust-region subproblem is outside of the radius

152:    Values:
153: +  `SNES_TR_FALLBACK_NEWTON` - use scaled Newton step
154: .  `SNES_TR_FALLBACK_CAUCHY` - use Cauchy direction
155: -  `SNES_TR_FALLBACK_DOGLEG` - use dogleg method

157:    Level: intermediate

159: .seealso: [](ch_snes), `SNES`, `SNESNEWTONTR`, `SNESNEWTONTRDC`
160: E*/
161: typedef enum {
162:   SNES_TR_FALLBACK_NEWTON,
163:   SNES_TR_FALLBACK_CAUCHY,
164:   SNES_TR_FALLBACK_DOGLEG,
165: } SNESNewtonTRFallbackType;

167: PETSC_EXTERN const char *const SNESNewtonTRFallbackTypes[];

169: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetPreCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, PetscBool *, PetscCtx), PetscCtx);
170: PETSC_EXTERN PetscErrorCode SNESNewtonTRGetPreCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, PetscBool *, PetscCtx), PetscCtxRt);
171: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetPostCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, PetscCtx), PetscCtx);
172: PETSC_EXTERN PetscErrorCode SNESNewtonTRGetPostCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, PetscCtx), PetscCtxRt);
173: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetFallbackType(SNES, SNESNewtonTRFallbackType);
174: PETSC_EXTERN PetscErrorCode SNESNewtonTRPreCheck(SNES, Vec, Vec, PetscBool *);
175: PETSC_EXTERN PetscErrorCode SNESNewtonTRPostCheck(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *);
176: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetNormType(SNES, NormType);

178: /*E
179:     SNESNewtonTRQNType - type of quasi-Newton model to use

181:    Values:
182: +  `SNES_TR_QN_NONE` - do not use a quasi-Newton model
183: .  `SNES_TR_QN_SAME` - use the same quasi-Newton model for matrix and preconditioner
184: -  `SNES_TR_QN_DIFFERENT` - use different quasi-Newton models for matrix and preconditioner

186:    Level: intermediate

188: .seealso: [](ch_snes), `SNES`, `SNESNEWTONTR`
189: E*/
190: typedef enum {
191:   SNES_TR_QN_NONE,
192:   SNES_TR_QN_SAME,
193:   SNES_TR_QN_DIFFERENT,
194: } SNESNewtonTRQNType;

196: PETSC_EXTERN const char *const SNESNewtonTRQNTypes[];

198: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetQNType(SNES, SNESNewtonTRQNType);

200: PETSC_EXTERN PETSC_DEPRECATED_FUNCTION(3, 22, 0, "SNESNewtonTRSetTolerances()", ) PetscErrorCode SNESSetTrustRegionTolerance(SNES, PetscReal);
201: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetTolerances(SNES, PetscReal, PetscReal, PetscReal);
202: PETSC_EXTERN PetscErrorCode SNESNewtonTRGetTolerances(SNES, PetscReal *, PetscReal *, PetscReal *);
203: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetUpdateParameters(SNES, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal);
204: PETSC_EXTERN PetscErrorCode SNESNewtonTRGetUpdateParameters(SNES, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *);

206: PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetRhoFlag(SNES, PetscBool *);
207: PETSC_EXTERN PetscErrorCode SNESNewtonTRDCSetPreCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, PetscBool *, PetscCtx), PetscCtx);
208: PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetPreCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, PetscBool *, PetscCtx), PetscCtxRt);
209: PETSC_EXTERN PetscErrorCode SNESNewtonTRDCSetPostCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, PetscCtx), PetscCtx);
210: PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetPostCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, PetscCtx), PetscCtxRt);

212: PETSC_EXTERN PetscErrorCode SNESGetNonlinearStepFailures(SNES, PetscInt *);
213: PETSC_EXTERN PetscErrorCode SNESSetMaxNonlinearStepFailures(SNES, PetscInt);
214: PETSC_EXTERN PetscErrorCode SNESGetMaxNonlinearStepFailures(SNES, PetscInt *);
215: PETSC_EXTERN PetscErrorCode SNESGetNumberFunctionEvals(SNES, PetscInt *);

217: PETSC_EXTERN PetscErrorCode SNESSetLagPreconditioner(SNES, PetscInt);
218: PETSC_EXTERN PetscErrorCode SNESGetLagPreconditioner(SNES, PetscInt *);
219: PETSC_EXTERN PetscErrorCode SNESSetLagJacobian(SNES, PetscInt);
220: PETSC_EXTERN PetscErrorCode SNESGetLagJacobian(SNES, PetscInt *);
221: PETSC_EXTERN PetscErrorCode SNESSetLagPreconditionerPersists(SNES, PetscBool);
222: PETSC_EXTERN PetscErrorCode SNESSetLagJacobianPersists(SNES, PetscBool);
223: PETSC_EXTERN PetscErrorCode SNESSetGridSequence(SNES, PetscInt);
224: PETSC_EXTERN PetscErrorCode SNESGetGridSequence(SNES, PetscInt *);

226: PETSC_EXTERN PetscErrorCode SNESGetLinearSolveIterations(SNES, PetscInt *);
227: PETSC_EXTERN PetscErrorCode SNESGetLinearSolveFailures(SNES, PetscInt *);
228: PETSC_EXTERN PetscErrorCode SNESSetMaxLinearSolveFailures(SNES, PetscInt);
229: PETSC_EXTERN PetscErrorCode SNESGetMaxLinearSolveFailures(SNES, PetscInt *);
230: PETSC_EXTERN PetscErrorCode SNESSetCountersReset(SNES, PetscBool);
231: PETSC_EXTERN PetscErrorCode SNESResetCounters(SNES);

233: PETSC_EXTERN PetscErrorCode SNESKSPSetUseEW(SNES, PetscBool);
234: PETSC_EXTERN PetscErrorCode SNESKSPGetUseEW(SNES, PetscBool *);
235: PETSC_EXTERN PetscErrorCode SNESKSPSetParametersEW(SNES, PetscInt, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal);
236: PETSC_EXTERN PetscErrorCode SNESKSPGetParametersEW(SNES, PetscInt *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *);

238: PETSC_EXTERN PetscErrorCode SNESMonitorLGRange(SNES, PetscInt, PetscReal, PetscCtx);

240: PETSC_EXTERN PetscErrorCode SNESSetApplicationContext(SNES, PetscCtx);
241: PETSC_EXTERN PetscErrorCode SNESGetApplicationContext(SNES, PetscCtxRt);
242: PETSC_EXTERN PetscErrorCode SNESSetComputeApplicationContext(SNES, PetscErrorCode (*)(SNES, PetscCtxRt), PetscCtxDestroyFn *);

244: PETSC_EXTERN PetscErrorCode SNESPythonSetType(SNES, const char[]);
245: PETSC_EXTERN PetscErrorCode SNESPythonGetType(SNES, const char *[]);

247: PETSC_EXTERN PetscErrorCode SNESSetFunctionDomainError(SNES);
248: PETSC_EXTERN PetscErrorCode SNESSetObjectiveDomainError(SNES);
249: PETSC_EXTERN PetscErrorCode SNESSetJacobianDomainError(SNES);
250: PETSC_EXTERN PetscErrorCode SNESSetCheckJacobianDomainError(SNES, PetscBool);
251: PETSC_EXTERN PetscErrorCode SNESGetCheckJacobianDomainError(SNES, PetscBool *);

253: #define SNES_CONVERGED_TR_DELTA_DEPRECATED SNES_CONVERGED_TR_DELTA PETSC_DEPRECATED_ENUM(3, 12, 0, "SNES_DIVERGED_TR_DELTA", )
254: #define SNES_DIVERGED_FNORM_NAN_DEPRECATED SNES_DIVERGED_FNORM_NAN PETSC_DEPRECATED_ENUM(3, 25, 0, "SNES_DIVERGED_FUNCTION_NANORINF", )
255: /*E
256:     SNESConvergedReason - reason a `SNESSolve()` was determined to have converged or diverged

258:    Values:
259: +  `SNES_CONVERGED_FNORM_ABS`         - $ ||F|| \le abstol $
260: .  `SNES_CONVERGED_FNORM_RELATIVE`    - $ ||F|| <= rtol*||F(x_0))|| $ where $x_0 $ is the initial guess
261: .  `SNES_CONVERGED_SNORM_RELATIVE`    - The 2-norm of the last step $ \le stol * ||x|| $ where $ x $ is the current solution
262: .  `SNES_CONVERGED_USER`              - The user has indicated convergence for an arbitrary reason
263: .  `SNES_DIVERGED_FUNCTION_COUNT`     - The user provided function has been called more times than the maximum set in `SNESSetTolerances()`
264: .  `SNES_DIVERGED_DTOL`               - The norm of the function has increased by a factor of divtol set with `SNESSetDivergenceTolerance()`
265: .  `SNES_DIVERGED_FUNCTION_NANORINF`  - the 2-norm of the current function evaluation is not-a-number (NaN) or infinity, (this
266:                                         is usually caused by a division of 0 by 0) and the solver could not recover from this (by, for example, cutting the step size)
267: .  `SNES_DIVERGED_OBJECTIVE_NANORINF` - the object function evaluation is not-a-number (NaN) or infinity, (this
268:                                         is usually caused by a division of 0 by 0) and the solver could not recover from this (by, for example, cutting the step size)
269: .  `SNES_DIVERGED_FUNCTION_DOMAIN`    - the function evaluation occurred outside the function's domain (function callback provided by
270:                                         `SNESSetFunction()` called `SNESSetObjectiveDomainError()`) and the solver could not recover from this (by, for example, cutting the step size)
271: .  `SNES_DIVERGED_OBJECTIVE_DOMAIN`   - the object function evaluation occurred outside the function's domain (function callback provided by
272:                                         `SNESSetObjective()` called `SNESSetObjectiveDomainError()`) and the solver could not recover from this (by, for example, cutting the step size)
273: .  `SNES_DIVERGED_JACOBIAN_DOMAIN`    - the Jacobian evaluation occurred outside the function's domain (function callback provided by
274:                                         `SNESSetJacobian()` called `SNESSetJacobianDomainError()`)
275: .  `SNES_DIVERGED_MAX_IT`             - `SNESSolve()` has reached the maximum number of iterations requested
276: .  `SNES_DIVERGED_LINE_SEARCH`        - The line search has failed. This only occurs for `SNES` solvers that use a line search
277: .  `SNES_DIVERGED_LOCAL_MIN`          - the algorithm seems to have stagnated at a local minimum that is not zero.
278: -  `SNES_CONVERGED_ITERATING          - this only occurs if `SNESGetConvergedReason()` is called during the `SNESSolve()`

280:    Level: beginner

282:     Notes:
283:    The two most common reasons for divergence are an incorrectly coded or computed Jacobian or failure or lack of convergence in the linear system
284:    (in this case we recommend
285:    testing with `-pc_type lu` to eliminate the linear solver as the cause of the problem).

287:    `SNES_DIVERGED_LOCAL_MIN` can only occur when using a `SNES` solver that uses a line search (`SNESLineSearch`).
288:    The line search wants to $ \min Q(\alpha) = 1/2 || F(x + \alpha s) ||^2_2 $  this occurs
289:    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
290:    $ Q'(\alpha) = -F(x)^T F'(x)^(-1)^T F'(x+\alpha s)F(x+\alpha s)$; when $\alpha = 0$
291:    $Q'(0) = - ||F(x)||^2_2 $ which is always NEGATIVE if $F'(x)$ is invertible. This means the Newton
292:    direction is a descent direction and the line search should succeed if $\alpha $ is small enough.

294:    If $F'(x)$ is NOT invertible AND $F'(x)^T F(x) = 0 $ then $Q'(0) = 0 $ and the Newton direction
295:    is NOT a descent direction so the line search will fail. All one can do at this point
296:    is change the initial guess and try again.

298:    An alternative explanation: Newton's method can be regarded as replacing the function with
299:    its linear approximation and minimizing the 2-norm of that. That is $F(x+s) \approx F(x) + F'(x)s$
300:    so we minimize $ || F(x) + F'(x) s ||^2_2$ using Least Squares. If $F'(x)$ is invertible then
301:    $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
302:    exists a nontrivial (that is $F'(x)s \ne 0$) solution to the equation and this direction is
303:    $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)
304:    = - (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)) \ne 0$
305:    and $F'(x)^T F'(x)$ has no negative eigenvalues $Q'(0) < 0$ so $s$ is a descent direction and the line
306:    search should succeed for small enough $\alpha$.

308:    Note that this RARELY happens in practice. Far more likely the linear system is not being solved
309:    (well enough?) or the Jacobian is wrong.

311:    `SNES_DIVERGED_MAX_IT` means that the solver reached the maximum number of iterations without satisfying any
312:    convergence criteria. `SNES_CONVERGED_ITS` means that `SNESConvergedSkip()` was chosen as the convergence test;
313:    thus the usual convergence criteria have not been checked and may or may not be satisfied.

315: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPConvergedReason`, `SNESSetConvergenceTest()`, `SNESSetTolerances()`
316: E*/
317: typedef enum {                       /* converged */
318:   SNES_CONVERGED_FNORM_ABS      = 2, /* ||F|| < atol */
319:   SNES_CONVERGED_FNORM_RELATIVE = 3, /* ||F|| < rtol*||F_initial|| */
320:   SNES_CONVERGED_SNORM_RELATIVE = 4, /* Newton computed step size small; || delta x || < stol || x || */
321:   SNES_CONVERGED_ITS            = 5, /* maximum iterations reached */
322:   SNES_BREAKOUT_INNER_ITER      = 6, /* Flag to break out of inner loop after checking custom convergence, used in multi-phase flow when state changes */
323:   SNES_CONVERGED_USER           = 7, /* The user has indicated convergence for an arbitrary reason */
324:   /* diverged */
325:   SNES_DIVERGED_FUNCTION_DOMAIN      = -1, /* the new x location passed the function is not in the domain of F */
326:   SNES_DIVERGED_FUNCTION_COUNT       = -2,
327:   SNES_DIVERGED_LINEAR_SOLVE         = -3, /* the linear solve failed */
328:   SNES_DIVERGED_FUNCTION_NANORINF    = -4,
329:   SNES_DIVERGED_FNORM_NAN_DEPRECATED = -4,
330:   SNES_DIVERGED_MAX_IT               = -5,
331:   SNES_DIVERGED_LINE_SEARCH          = -6,  /* the line search failed */
332:   SNES_DIVERGED_INNER                = -7,  /* inner solve failed */
333:   SNES_DIVERGED_LOCAL_MIN            = -8,  /* || J^T b || is small, implies converged to local minimum of F() */
334:   SNES_DIVERGED_DTOL                 = -9,  /* || F || > divtol*||F_initial|| */
335:   SNES_DIVERGED_JACOBIAN_DOMAIN      = -10, /* Jacobian calculation does not make sense */
336:   SNES_DIVERGED_TR_DELTA             = -11,
337:   SNES_CONVERGED_TR_DELTA_DEPRECATED = -11,
338:   SNES_DIVERGED_USER                 = -12, /* The user has indicated divergence for an arbitrary reason */
339:   SNES_DIVERGED_OBJECTIVE_DOMAIN     = -13,
340:   SNES_DIVERGED_OBJECTIVE_NANORINF   = -14,

342:   SNES_CONVERGED_ITERATING = 0
343: } SNESConvergedReason;
344: PETSC_EXTERN const char *const *SNESConvergedReasons;

346: /*MC
347:    SNES_CONVERGED_FNORM_ABS - $||F|| \le abstol$

349:    Level: beginner

351: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
352: M*/

354: /*MC
355:    SNES_CONVERGED_FNORM_RELATIVE - $||F|| \le rtol*||F(x_0)||$ where $x_0$ is the initial guess

357:    Level: beginner

359: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
360: M*/

362: /*MC
363:   SNES_CONVERGED_SNORM_RELATIVE - The 2-norm of the last step $\le stol * ||x||$ where `x` is the current
364:   solution and `stol` is the 4th argument to `SNESSetTolerances()`

366:   Options Database Key:
367:   -snes_stol stol - the step tolerance

369:    Level: beginner

371: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
372: M*/

374: /*MC
375:    SNES_DIVERGED_FUNCTION_COUNT - The user provided function has been called more times then the final
376:    argument to `SNESSetTolerances()`

378:    Level: beginner

380: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
381: M*/

383: /*MC
384:    SNES_DIVERGED_DTOL - The norm of the function has increased by a factor of divtol set with `SNESSetDivergenceTolerance()`

386:    Level: beginner

388: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`, `SNESSetDivergenceTolerance()`
389: M*/

391: /*MC
392:    SNES_DIVERGED_FUNCTION_NANORINF - the 2-norm of the current function evaluation is not-a-number (NaN) or infinity, this
393:    is usually caused by a division of 0 by 0, or infinity.  See `SNESSetFunctionDomainError()`

395:    Level: beginner

397: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
398: M*/

400: /*MC
401:    SNES_DIVERGED_FUNCTION_DOMAIN - the function provided with `SNESSetFunction()` called `SNESSetFunctionDomainError()` and
402:    the solver could not recoverer.

404:    Level: beginner

406: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
407: M*/

409: /*MC
410:    SNES_DIVERGED_OBJECTIVE_DOMAIN - the function provided with `SNESSetObjective()` called `SNESSetObjectiveDomainError()` and
411:    the solver could not recoverer.

413:    Level: beginner

415: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
416: M*/

418: /*MC
419:    SNES_DIVERGED_JACOBIAN_DOMAIN - the function provided with `SNESSetJacobian()` called `SNESSetJacobianDomainError()`

421:    Level: beginner

423: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
424: M*/

426: /*MC
427:    SNES_DIVERGED_MAX_IT - SNESSolve() has reached the maximum number of iterations requested

429:    Level: beginner

431: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
432: M*/

434: /*MC
435:    SNES_DIVERGED_LINE_SEARCH - The line search has failed. This only occurs for a `SNES` solvers that use a line search

437:    Level: beginner

439: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`, `SNESLineSearch`
440: M*/

442: /*MC
443:    SNES_DIVERGED_LOCAL_MIN - the algorithm seems to have stagnated at a local minimum that is not zero.
444:    See the manual page for `SNESConvergedReason` for more details

446:    Level: beginner

448: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
449: M*/

451: /*MC
452:    SNES_CONERGED_ITERATING - this only occurs if `SNESGetConvergedReason()` is called during the `SNESSolve()`

454:    Level: beginner

456: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
457: M*/

459: PETSC_EXTERN PetscErrorCode SNESSetConvergenceTest(SNES, PetscErrorCode (*)(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, PetscCtx), PetscCtx, PetscCtxDestroyFn *);
460: PETSC_EXTERN PetscErrorCode SNESConvergedDefault(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, PetscCtx);
461: PETSC_EXTERN PetscErrorCode SNESConvergedSkip(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, PetscCtx);
462: PETSC_EXTERN PetscErrorCode SNESConvergedCorrectPressure(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, PetscCtx);
463: PETSC_EXTERN PetscErrorCode SNESGetConvergedReason(SNES, SNESConvergedReason *);
464: PETSC_EXTERN PetscErrorCode SNESGetConvergedReasonString(SNES, const char *[]);
465: PETSC_EXTERN PetscErrorCode SNESSetConvergedReason(SNES, SNESConvergedReason);

467: PETSC_DEPRECATED_FUNCTION(3, 5, 0, "SNESConvergedSkip()", ) static inline void SNESSkipConverged(void)
468: { /* never called */
469: }
470: #define SNESSkipConverged (SNESSkipConverged, SNESConvergedSkip)

472: /*S
473:   SNESInitialGuessFn - A prototype of a `SNES` compute initial guess function that would be passed to `SNESSetComputeInitialGuess()`

475:   Calling Sequence:
476: + snes - `SNES` context
477: . u    - output vector to contain initial guess
478: - ctx  - [optional] user-defined function context

480:   Level: beginner

482: .seealso: [](ch_snes), `SNES`, `SNESSetComputeInitialGuess()`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`, `SNESFunctionFn`
483: S*/
484: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESInitialGuessFn(SNES snes, Vec u, PetscCtx ctx);

486: /*S
487:   SNESFunctionFn - A prototype of a `SNES` evaluation function that would be passed to `SNESSetFunction()`

489:   Calling Sequence:
490: + snes - `SNES` context
491: . u    - input vector
492: . F    - function vector
493: - ctx  - [optional] user-defined function context

495:   Level: beginner

497: .seealso: [](ch_snes), `SNES`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`, `SNESNGSFn`
498: S*/
499: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESFunctionFn(SNES snes, Vec u, Vec F, PetscCtx ctx);

501: /*S
502:   SNESObjectiveFn - A prototype of a `SNES` objective evaluation function that would be passed to `SNESSetObjective()`

504:   Calling Sequence:
505: + snes - `SNES` context
506: . u    - input vector
507: . o    - output value
508: - ctx  - [optional] user-defined function context

510:   Level: beginner

512: .seealso: [](ch_snes), `SNES`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`, `SNESNGSFn`
513: S*/
514: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESObjectiveFn(SNES snes, Vec u, PetscReal *o, PetscCtx ctx);

516: /*S
517:   SNESJacobianFn - A prototype of a `SNES` Jacobian evaluation function that would be passed to `SNESSetJacobian()`

519:   Calling Sequence:
520: + snes - the `SNES` context obtained from `SNESCreate()`
521: . u    - input vector
522: . Amat - (approximate) Jacobian matrix
523: . Pmat - matrix used to construct the preconditioner, often the same as `Amat`
524: - ctx  - [optional] user-defined context for matrix evaluation routine

526:   Level: beginner

528: .seealso: [](ch_snes), `SNES`, `SNESSetJacobian()`, `SNESGetJacobian()`, `SNESFunctionFn`, `SNESNGSFn`
529: S*/
530: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESJacobianFn(SNES snes, Vec u, Mat Amat, Mat Pmat, PetscCtx ctx);

532: /*S
533:   SNESNGSFn - A prototype of a `SNES` nonlinear Gauss-Seidel function that would be passed to `SNESSetNGS()`

535:   Calling Sequence:
536: + snes - the `SNES` context obtained from `SNESCreate()`
537: . u    - the current solution, updated in place
538: . b    - the right-hand side vector (which may be `NULL`)
539: - ctx  - [optional] user-defined context for matrix evaluation routine

541:   Level: beginner

543: .seealso: [](ch_snes), `SNES`, `SNESSetJacobian()`, `SNESGetJacobian()`, `SNESFunctionFn`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`
544: S*/
545: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESNGSFn(SNES snes, Vec u, Vec b, PetscCtx ctx);

547: /*S
548:   SNESUpdateFn - A prototype of a `SNES` update function that would be passed to `SNESSetUpdate()`

550:   Calling Sequence:
551: + snes - `SNES` context
552: - step - the current iteration index

554:   Level: advanced

556: .seealso: [](ch_snes), `SNES`, `SNESSetUpdate()`
557: S*/
558: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESUpdateFn(SNES snes, PetscInt step);

560: /* --------- Solving systems of nonlinear equations --------------- */
561: PETSC_EXTERN PetscErrorCode SNESSetFunction(SNES, Vec, SNESFunctionFn *, PetscCtx);
562: PETSC_EXTERN PetscErrorCode SNESGetFunction(SNES, Vec *, SNESFunctionFn **, PetscCtxRt);
563: PETSC_EXTERN PetscErrorCode SNESComputeFunction(SNES, Vec, Vec);
564: PETSC_EXTERN PetscErrorCode SNESComputeMFFunction(SNES, Vec, Vec);
565: PETSC_EXTERN PetscErrorCode SNESSetInitialFunction(SNES, Vec);

567: PETSC_EXTERN PetscErrorCode SNESSetJacobian(SNES, Mat, Mat, SNESJacobianFn *, PetscCtx);
568: PETSC_EXTERN PetscErrorCode SNESGetJacobian(SNES, Mat *, Mat *, SNESJacobianFn **, PetscCtxRt);
569: PETSC_EXTERN SNESFunctionFn SNESObjectiveComputeFunctionDefaultFD;
570: PETSC_EXTERN SNESJacobianFn SNESComputeJacobianDefault;
571: PETSC_EXTERN SNESJacobianFn SNESComputeJacobianDefaultColor;
572: PETSC_EXTERN PetscErrorCode SNESPruneJacobianColor(SNES, Mat, Mat);
573: PETSC_EXTERN PetscErrorCode SNESSetComputeInitialGuess(SNES, SNESInitialGuessFn *, PetscCtx);
574: PETSC_EXTERN PetscErrorCode SNESSetPicard(SNES, Vec, SNESFunctionFn *, Mat, Mat, SNESJacobianFn *, PetscCtx);
575: PETSC_EXTERN PetscErrorCode SNESGetPicard(SNES, Vec *, SNESFunctionFn **, Mat *, Mat *, SNESJacobianFn **, PetscCtxRt);
576: PETSC_EXTERN SNESFunctionFn SNESPicardComputeFunction;
577: PETSC_EXTERN SNESFunctionFn SNESPicardComputeMFFunction;
578: PETSC_EXTERN SNESJacobianFn SNESPicardComputeJacobian;

580: PETSC_EXTERN PetscErrorCode SNESSetObjective(SNES, SNESObjectiveFn *, PetscCtx);
581: PETSC_EXTERN PetscErrorCode SNESGetObjective(SNES, SNESObjectiveFn **, PetscCtxRt);
582: PETSC_EXTERN PetscErrorCode SNESComputeObjective(SNES, Vec, PetscReal *);

584: PETSC_EXTERN PetscErrorCode SNESSetUpdate(SNES, SNESUpdateFn *);

586: /*E
587:    SNESNormSchedule - Frequency with which the norm is computed during a nonliner solve

589:    Values:
590: +   `SNES_NORM_DEFAULT`            - use the default behavior for the current `SNESType`
591: .   `SNES_NORM_NONE`               - avoid all norm computations
592: .   `SNES_NORM_ALWAYS`             - compute the norms whenever possible
593: .   `SNES_NORM_INITIAL_ONLY`       - compute the norm only when the algorithm starts
594: .   `SNES_NORM_FINAL_ONLY`         - compute the norm only when the algorithm finishes
595: -   `SNES_NORM_INITIAL_FINAL_ONLY` - compute the norm at the start and end of the algorithm

597:    Level: advanced

599:    Notes:
600:    Support for these is highly dependent on the solver.

602:    Some options limit the convergence tests that can be used.

604:    The `SNES_NORM_NONE` option is most commonly used when the nonlinear solver is being used as a smoother, for example for `SNESFAS`

606:    This is primarily used to turn off extra norm and function computation
607:    when the solvers are composed.

609: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPSetNormType()`,
610:           `KSPSetConvergenceTest()`, `KSPSetPCSide()`
611: E*/
612: typedef enum {
613:   SNES_NORM_DEFAULT            = -1,
614:   SNES_NORM_NONE               = 0,
615:   SNES_NORM_ALWAYS             = 1,
616:   SNES_NORM_INITIAL_ONLY       = 2,
617:   SNES_NORM_FINAL_ONLY         = 3,
618:   SNES_NORM_INITIAL_FINAL_ONLY = 4
619: } SNESNormSchedule;
620: PETSC_EXTERN const char *const *const SNESNormSchedules;

622: /*MC
623:    SNES_NORM_NONE - Don't compute function and its L2 norm when possible

625:    Level: advanced

627:    Note:
628:    This is most useful for stationary solvers with a fixed number of iterations used as smoothers.

630: .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_DEFAULT`
631: M*/

633: /*MC
634:    SNES_NORM_ALWAYS - Compute the function and its L2 norm at each iteration.

636:    Level: advanced

638:    Note:
639:    Most solvers will use this no matter what norm type is passed to them.

641: .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_NONE`
642: M*/

644: /*MC
645:    SNES_NORM_INITIAL_ONLY - Compute the function and its L2 at iteration 0, but do not update it.

647:    Level: advanced

649:    Notes:
650:    This method is useful in composed methods, when a true solution might actually be found before `SNESSolve()` is called.
651:    This option enables the solve to abort on the zeroth iteration if this is the case.

653:    For solvers that require the computation of the L2 norm of the function as part of the method, this merely cancels
654:    the norm computation at the last iteration (if possible).

656: .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_FINAL_ONLY`, `SNES_NORM_INITIAL_FINAL_ONLY`
657: M*/

659: /*MC
660:    SNES_NORM_FINAL_ONLY - Compute the function and its L2 norm on only the final iteration.

662:    Level: advanced

664:    Note:
665:    For solvers that require the computation of the L2 norm of the function as part of the method, behaves
666:    exactly as `SNES_NORM_DEFAULT`.  This method is useful when the function is gotten after `SNESSolve()` and
667:    used in subsequent computation for methods that do not need the norm computed during the rest of the
668:    solution procedure.

670: .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_INITIAL_ONLY`, `SNES_NORM_INITIAL_FINAL_ONLY`
671: M*/

673: /*MC
674:    SNES_NORM_INITIAL_FINAL_ONLY - Compute the function and its L2 norm on only the initial and final iterations.

676:    Level: advanced

678:    Note:
679:    This method combines the benefits of `SNES_NORM_INITIAL_ONLY` and `SNES_NORM_FINAL_ONLY`.

681: .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_SNES_NORM_INITIAL_ONLY`, `SNES_NORM_FINAL_ONLY`
682: M*/

684: PETSC_EXTERN PetscErrorCode SNESSetNormSchedule(SNES, SNESNormSchedule);
685: PETSC_EXTERN PetscErrorCode SNESGetNormSchedule(SNES, SNESNormSchedule *);
686: PETSC_EXTERN PetscErrorCode SNESSetFunctionNorm(SNES, PetscReal);
687: PETSC_EXTERN PetscErrorCode SNESGetFunctionNorm(SNES, PetscReal *);
688: PETSC_EXTERN PetscErrorCode SNESGetUpdateNorm(SNES, PetscReal *);
689: PETSC_EXTERN PetscErrorCode SNESGetSolutionNorm(SNES, PetscReal *);

691: /*E
692:    SNESFunctionType - Type of function computed

694:    Values:
695: +  `SNES_FUNCTION_DEFAULT`          - the default behavior for the current `SNESType`
696: .  `SNES_FUNCTION_UNPRECONDITIONED` - the original function provided
697: -  `SNES_FUNCTION_PRECONDITIONED`   - the modification of the function by the preconditioner

699:    Level: advanced

701:    Note:
702:    Support for these is dependent on the solver.

704: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPSetNormType()`,
705:           `KSPSetConvergenceTest()`, `KSPSetPCSide()`
706: E*/
707: typedef enum {
708:   SNES_FUNCTION_DEFAULT          = -1,
709:   SNES_FUNCTION_UNPRECONDITIONED = 0,
710:   SNES_FUNCTION_PRECONDITIONED   = 1
711: } SNESFunctionType;
712: PETSC_EXTERN const char *const *const SNESFunctionTypes;

714: PETSC_EXTERN PetscErrorCode SNESSetFunctionType(SNES, SNESFunctionType);
715: PETSC_EXTERN PetscErrorCode SNESGetFunctionType(SNES, SNESFunctionType *);

717: PETSC_EXTERN PetscErrorCode SNESSetNGS(SNES, SNESNGSFn *, PetscCtx);
718: PETSC_EXTERN PetscErrorCode SNESGetNGS(SNES, SNESNGSFn **, PetscCtxRt);
719: PETSC_EXTERN PetscErrorCode SNESComputeNGS(SNES, Vec, Vec);

721: PETSC_EXTERN PetscErrorCode SNESNGSSetSweeps(SNES, PetscInt);
722: PETSC_EXTERN PetscErrorCode SNESNGSGetSweeps(SNES, PetscInt *);
723: PETSC_EXTERN PetscErrorCode SNESNGSSetTolerances(SNES, PetscReal, PetscReal, PetscReal, PetscInt);
724: PETSC_EXTERN PetscErrorCode SNESNGSGetTolerances(SNES, PetscReal *, PetscReal *, PetscReal *, PetscInt *);

726: PETSC_EXTERN PetscErrorCode SNESSetAlwaysComputesFinalResidual(SNES, PetscBool);
727: PETSC_EXTERN PetscErrorCode SNESGetAlwaysComputesFinalResidual(SNES, PetscBool *);

729: PETSC_EXTERN PetscErrorCode SNESShellGetContext(SNES, PetscCtxRt);
730: PETSC_EXTERN PetscErrorCode SNESShellSetContext(SNES, PetscCtx);
731: PETSC_EXTERN PetscErrorCode SNESShellSetSolve(SNES, PetscErrorCode (*)(SNES, Vec));

733: /* --------- Routines specifically for line search methods --------------- */

735: /*S
736:    SNESLineSearch - Abstract PETSc object that manages line-search operations for nonlinear solvers

738:    Level: beginner

740: .seealso: [](ch_snes), `SNESLineSearchType`, `SNESLineSearchCreate()`, `SNESLineSearchSetType()`, `SNES`
741: S*/
742: typedef struct _p_LineSearch *SNESLineSearch;

744: /*J
745:    SNESLineSearchType - String with the name of a PETSc line search method `SNESLineSearch`. Provides all the linesearches for the nonlinear solvers, `SNES`,
746:                         in PETSc.

748:    Values:
749: +  `SNESLINESEARCHBASIC`     - (or equivalently `SNESLINESEARCHNONE`) Simple damping line search, defaults to using the full Newton step
750: .  `SNESLINESEARCHBT`        - Backtracking line search over the L2 norm of the function or an objective function
751: .  `SNESLINESEARCHSECANT`    - Secant line search over the L2 norm of the function or an objective function
752: .  `SNESLINESEARCHCP`        - Critical point secant line search assuming $F(x) = \nabla G(x)$ for some unknown $G(x)$
753: .  `SNESLINESEARCHNLEQERR`   - Affine-covariant error-oriented linesearch
754: -  `SNESLINESEARCHBISECTION` - bisection line search for a root in the directional derivative
755: -  `SNESLINESEARCHSHELL`     - User provided `SNESLineSearch` implementation

757:    Level: beginner

759:    Note:
760:    Use `SNESLineSearchSetType()` or the options database key `-snes_linesearch_type` to set
761:    the specific line search algorithm to use with a given `SNES` object. Not all `SNESType` can utilize a line search.

763: .seealso: [](ch_snes), `SNESLineSearch`, `SNESLineSearchSetType()`, `SNES`
764: J*/
765: typedef const char *SNESLineSearchType;
766: #define SNESLINESEARCHBT        "bt"
767: #define SNESLINESEARCHNLEQERR   "nleqerr"
768: #define SNESLINESEARCHBASIC     "basic"
769: #define SNESLINESEARCHNONE      "none"
770: #define SNESLINESEARCHSECANT    "secant"
771: #define SNESLINESEARCHL2        PETSC_DEPRECATED_MACRO(3, 24, 0, "SNESLINESEARCHSECANT", ) "secant"
772: #define SNESLINESEARCHCP        "cp"
773: #define SNESLINESEARCHSHELL     "shell"
774: #define SNESLINESEARCHNCGLINEAR "ncglinear"
775: #define SNESLINESEARCHBISECTION "bisection"

777: PETSC_EXTERN PetscFunctionList SNESList;
778: PETSC_EXTERN PetscClassId      SNESLINESEARCH_CLASSID;
779: PETSC_EXTERN PetscFunctionList SNESLineSearchList;

781: #define SNES_LINESEARCH_ORDER_LINEAR    1
782: #define SNES_LINESEARCH_ORDER_QUADRATIC 2
783: #define SNES_LINESEARCH_ORDER_CUBIC     3

785: /*S
786:   SNESLineSearchVIProjectFn - A prototype of a `SNES` function that projects a vector onto the VI bounds, passed to `SNESLineSearchSetVIFunctions()`

788:   Calling Sequence:
789: + snes  - `SNES` context
790: - u     - the vector to project to the bounds

792:   Level: advanced

794:   Note:
795:   The deprecated `SNESLineSearchVIProjectFunc` still works as a replacement for `SNESLineSearchVIProjectFn` *.

797: .seealso: [](ch_snes), `SNES`, `SNESLineSearch`
798: S*/
799: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode             SNESLineSearchVIProjectFn(SNES snes, Vec u);
800: PETSC_EXTERN_TYPEDEF typedef SNESLineSearchVIProjectFn *SNESLineSearchVIProjectFunc PETSC_DEPRECATED_TYPEDEF(3, 21, 0, "SNESLineSearchVIProjectFn*", );

802: /*S
803:   SNESLineSearchVINormFn - A prototype of a `SNES` function that computes the norm of the active set variables in a vector in a variational inequality (VI) solve,
804:   passed to `SNESLineSearchSetVIFunctions()`

806:   Calling Sequence:
807: + snes  - `SNES` context
808: . f     - the vector to compute the norm of
809: . u     - the current solution, entries that are on the variational inequality (VI) bounds are ignored
810: - fnorm - the resulting norm

812:   Level: advanced

814: .seealso: [](ch_snes), `SNES`, `SNESLineSearch`
815: S*/
816: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode          SNESLineSearchVINormFn(SNES snes, Vec f, Vec u, PetscReal *fnorm);
817: PETSC_EXTERN_TYPEDEF typedef SNESLineSearchVINormFn *SNESLineSearchVINormFunc PETSC_DEPRECATED_TYPEDEF(3, 21, 0, "SNESLineSearchVINormFnn*", );

819: /*S
820:   SNESLineSearchVIDirDerivFn - A prototype of a `SNES` function that computes the directional derivative considering the VI bounds, passed to `SNESLineSearchSetVIFunctions()`

822:   Calling Sequence:
823: + snes  - `SNES` context
824: . f     - the function vector to compute the directional derivative with
825: . u     - the current solution, entries that are on the VI bounds are ignored
826: . y     - the direction to compute the directional derivative
827: - fty   - the resulting directional derivative

829:   Level: advanced

831: .seealso: [](ch_snes), `SNES`, `SNESLineSearch`, `SNESLineSearchVINormFn`, `SNESLineSearchVIProjectFn`, `SNESLineSearchSetVIFunctions()`, `SNESLineSearchGetVIFunctions()`
832: S*/
833: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESLineSearchVIDirDerivFn(SNES snes, Vec f, Vec u, Vec y, PetscScalar *fty);

835: /*S
836:   SNESLineSearchApplyFn - Function type for a `SNESLineSearch` implementation's apply routine

838:   Calling Sequence:
839: . ls - the `SNESLineSearch` object whose internal state holds the current step, search direction and other data

841:   Level: developer

843: .seealso: `SNESLineSearch`, `SNESLineSearchType`, `SNESLineSearchSetType()`, `SNESLineSearchShellApplyFn`
844: S*/
845: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode         SNESLineSearchApplyFn(SNESLineSearch ls);
846: PETSC_EXTERN_TYPEDEF typedef SNESLineSearchApplyFn *SNESLineSearchApplyFunc PETSC_DEPRECATED_TYPEDEF(3, 21, 0, "SNESLineSearchApplyFn*", );
847: /*S
848:   SNESLineSearchShellApplyFn - Function type for the user-supplied apply routine registered with the `SNESLINESEARCHSHELL` line-search

850:   Calling Sequence:
851: + ls  - the `SNESLineSearch` object
852: - ctx - optional user-provided context set with `SNESLineSearchShellSetApply()`

854:   Level: developer

856: .seealso: `SNESLineSearch`, `SNESLINESEARCHSHELL`, `SNESLineSearchShellSetApply()`, `SNESLineSearchApplyFn`
857: S*/
858: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode              SNESLineSearchShellApplyFn(SNESLineSearch ls, PetscCtx ctx);
859: PETSC_EXTERN_TYPEDEF typedef SNESLineSearchShellApplyFn *SNESLineSearchUserFunc PETSC_DEPRECATED_TYPEDEF(3, 21, 0, "SNESLineSearchApplyFn*", );

861: PETSC_EXTERN PetscErrorCode SNESLineSearchCreate(MPI_Comm, SNESLineSearch *);
862: PETSC_EXTERN PetscErrorCode SNESLineSearchReset(SNESLineSearch);
863: PETSC_EXTERN PetscErrorCode SNESLineSearchView(SNESLineSearch, PetscViewer);
864: PETSC_EXTERN PetscErrorCode SNESLineSearchDestroy(SNESLineSearch *);
865: PETSC_EXTERN PetscErrorCode SNESLineSearchGetType(SNESLineSearch, SNESLineSearchType *);
866: PETSC_EXTERN PetscErrorCode SNESLineSearchSetType(SNESLineSearch, SNESLineSearchType);
867: PETSC_EXTERN PetscErrorCode SNESLineSearchSetFromOptions(SNESLineSearch);
868: PETSC_EXTERN PetscErrorCode SNESLineSearchSetFunction(SNESLineSearch, PetscErrorCode (*)(SNES, Vec, Vec));
869: PETSC_EXTERN PetscErrorCode SNESLineSearchSetUp(SNESLineSearch);
870: PETSC_EXTERN PetscErrorCode SNESLineSearchApply(SNESLineSearch, Vec, Vec, PetscReal *, Vec);
871: PETSC_EXTERN PetscErrorCode SNESLineSearchPreCheck(SNESLineSearch, Vec, Vec, PetscBool *);
872: PETSC_EXTERN PetscErrorCode SNESLineSearchPostCheck(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *);
873: PETSC_EXTERN PetscErrorCode SNESLineSearchSetWorkVecs(SNESLineSearch, PetscInt);

875: /* set the functions for precheck and postcheck */

877: PETSC_EXTERN PetscErrorCode SNESLineSearchSetPreCheck(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, Vec, Vec, PetscBool *, PetscCtx), PetscCtx);
878: PETSC_EXTERN PetscErrorCode SNESLineSearchSetPostCheck(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *, PetscCtx), PetscCtx);

880: PETSC_EXTERN PetscErrorCode SNESLineSearchGetPreCheck(SNESLineSearch, PetscErrorCode (**)(SNESLineSearch, Vec, Vec, PetscBool *, PetscCtx), PetscCtxRt);
881: PETSC_EXTERN PetscErrorCode SNESLineSearchGetPostCheck(SNESLineSearch, PetscErrorCode (**)(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *, PetscCtx), PetscCtxRt);

883: /* set the functions for VI-specific line search operations */

885: PETSC_EXTERN PetscErrorCode SNESLineSearchSetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFn *, SNESLineSearchVINormFn *, SNESLineSearchVIDirDerivFn *);
886: PETSC_EXTERN PetscErrorCode SNESLineSearchGetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFn **, SNESLineSearchVINormFn **, SNESLineSearchVIDirDerivFn **);

888: /* pointers to the associated SNES in order to be able to get the function evaluation out */
889: PETSC_EXTERN PetscErrorCode SNESLineSearchSetSNES(SNESLineSearch, SNES);
890: PETSC_EXTERN PetscErrorCode SNESLineSearchGetSNES(SNESLineSearch, SNES *);

892: /* set and get the parameters and vectors */
893: PETSC_EXTERN PetscErrorCode SNESLineSearchGetTolerances(SNESLineSearch, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscInt *);
894: PETSC_EXTERN PetscErrorCode SNESLineSearchSetTolerances(SNESLineSearch, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscInt);

896: PETSC_EXTERN PetscErrorCode SNESLineSearchPreCheckPicard(SNESLineSearch, Vec, Vec, PetscBool *, PetscCtx);

898: PETSC_EXTERN PetscErrorCode SNESLineSearchGetLambda(SNESLineSearch, PetscReal *);
899: PETSC_EXTERN PetscErrorCode SNESLineSearchSetLambda(SNESLineSearch, PetscReal);

901: PETSC_EXTERN PetscErrorCode SNESLineSearchGetDamping(SNESLineSearch, PetscReal *);
902: PETSC_EXTERN PetscErrorCode SNESLineSearchSetDamping(SNESLineSearch, PetscReal);

904: PETSC_EXTERN PetscErrorCode SNESLineSearchGetOrder(SNESLineSearch, PetscInt *);
905: PETSC_EXTERN PetscErrorCode SNESLineSearchSetOrder(SNESLineSearch, PetscInt);

907: /*E
908:     SNESLineSearchReason - indication if the line search has succeeded or failed and why

910:   Values:
911: +  `SNES_LINESEARCH_SUCCEEDED`              - the line search succeeded
912: .  `SNES_LINESEARCH_FAILED_NANORINF`        - a not a number of infinity appeared in the computions
913: .  `SNES_LINESEARCH_FAILED_FUNCTION_DOMAIN` - the function was evaluated outside of its domain, see `SNESSetFunctionDomainError()`
914: .  `SNES_LINESEARCH_FAILED_OBJECTIVE_DOMAIN`- the objective function was evaluated outside of its domain, see `SNESSetObjectiveDomainError()`
915: .  `SNES_LINESEARCH_FAILED_JACOBIAN_DOMAIN` - the Jacobian was evaluated outside of its domain, see `SNESSetJacobianDomainError()`
916: .  `SNES_LINESEARCH_FAILED_REDUCT`          - the linear search failed to get the requested decrease in its norm or objective
917: .  `SNES_LINESEARCH_FAILED_USER`            - used by `SNESLINESEARCHNLEQERR` to indicate the user changed the search direction inappropriately
918: -  `SNES_LINESEARCH_FAILED_FUNCTION`        - indicates the maximum number of function evaluations allowed has been surpassed, `SNESConvergedReason` is also
919:                                               set to `SNES_DIVERGED_FUNCTION_COUNT`

921:    Level: intermediate

923:    Developer Note:
924:    Some of these reasons overlap with values of `SNESConvergedReason`. It is possibly a better design to have `SNESConvergedReaon` alone used also for indicating line
925:    search failures.

927: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPConvergedReason`, `SNESSetConvergenceTest()`,
928:           `SNESSetFunctionDomainError()`, `SNESSetJacobianDomainError()`
929: E*/
930: typedef enum {
931:   SNES_LINESEARCH_SUCCEEDED,
932:   SNES_LINESEARCH_FAILED_NANORINF,
933:   SNES_LINESEARCH_FAILED_FUNCTION_DOMAIN,
934:   SNES_LINESEARCH_FAILED_OBJECTIVE_DOMAIN,
935:   SNES_LINESEARCH_FAILED_JACOBIAN_DOMAIN,
936:   SNES_LINESEARCH_FAILED_REDUCT, /* INSUFFICIENT REDUCTION */
937:   SNES_LINESEARCH_FAILED_USER,
938:   SNES_LINESEARCH_FAILED_FUNCTION
939: } SNESLineSearchReason;

941: PETSC_EXTERN PetscErrorCode SNESLineSearchGetReason(SNESLineSearch, SNESLineSearchReason *);
942: PETSC_EXTERN PetscErrorCode SNESLineSearchSetReason(SNESLineSearch, SNESLineSearchReason);

944: PETSC_EXTERN PetscErrorCode SNESLineSearchGetVecs(SNESLineSearch, Vec *, Vec *, Vec *, Vec *, Vec *);
945: PETSC_EXTERN PetscErrorCode SNESLineSearchSetVecs(SNESLineSearch, Vec, Vec, Vec, Vec, Vec);

947: PETSC_EXTERN PetscErrorCode SNESLineSearchGetNorms(SNESLineSearch, PetscReal *, PetscReal *, PetscReal *);
948: PETSC_EXTERN PetscErrorCode SNESLineSearchSetNorms(SNESLineSearch, PetscReal, PetscReal, PetscReal);
949: PETSC_EXTERN PetscErrorCode SNESLineSearchComputeNorms(SNESLineSearch);
950: PETSC_EXTERN PetscErrorCode SNESLineSearchSetComputeNorms(SNESLineSearch, PetscBool);

952: PETSC_EXTERN PetscErrorCode SNESLineSearchMonitor(SNESLineSearch);
953: PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSet(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, PetscCtx), PetscCtx, PetscCtxDestroyFn *);
954: PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSetFromOptions(SNESLineSearch, const char[], const char[], const char[], PetscErrorCode (*)(SNESLineSearch, PetscViewerAndFormat *), PetscErrorCode (*)(SNESLineSearch, PetscViewerAndFormat *));
955: PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorCancel(SNESLineSearch);
956: PETSC_EXTERN PetscErrorCode SNESLineSearchSetDefaultMonitor(SNESLineSearch, PetscViewer);
957: PETSC_EXTERN PetscErrorCode SNESLineSearchGetDefaultMonitor(SNESLineSearch, PetscViewer *);
958: PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSolutionUpdate(SNESLineSearch, PetscViewerAndFormat *);

960: PETSC_EXTERN PetscErrorCode SNESLineSearchAppendOptionsPrefix(SNESLineSearch, const char[]);
961: PETSC_EXTERN PetscErrorCode SNESLineSearchGetOptionsPrefix(SNESLineSearch, const char *[]);

963: /* Shell interface functions */
964: PETSC_EXTERN PetscErrorCode SNESLineSearchShellSetApply(SNESLineSearch, SNESLineSearchShellApplyFn *, PetscCtx);
965: PETSC_EXTERN PetscErrorCode SNESLineSearchShellGetApply(SNESLineSearch, SNESLineSearchShellApplyFn **, PetscCtxRt);

967: PETSC_DEPRECATED_FUNCTION(3, 21, 0, "SNESLinesearchShellSetApply()", ) static inline PetscErrorCode SNESLineSearchShellSetUserFunc(SNESLineSearch ls, SNESLineSearchShellApplyFn *f, PetscCtx ctx)
968: {
969:   return SNESLineSearchShellSetApply(ls, f, ctx);
970: }

972: PETSC_DEPRECATED_FUNCTION(3, 21, 0, "SNESLinesearchShellGetApply()", ) static inline PetscErrorCode SNESLineSearchShellGetUserFunc(SNESLineSearch ls, SNESLineSearchShellApplyFn **f, PetscCtxRt ctx)
973: {
974:   return SNESLineSearchShellGetApply(ls, f, ctx);
975: }

977: /* BT interface functions */
978: PETSC_EXTERN PetscErrorCode SNESLineSearchBTSetAlpha(SNESLineSearch, PetscReal);
979: PETSC_EXTERN PetscErrorCode SNESLineSearchBTGetAlpha(SNESLineSearch, PetscReal *);

981: /*register line search types */
982: PETSC_EXTERN PetscErrorCode SNESLineSearchRegister(const char[], PetscErrorCode (*)(SNESLineSearch));

984: /* Routines for VI solver */
985: PETSC_EXTERN PetscErrorCode SNESVISetVariableBounds(SNES, Vec, Vec);
986: PETSC_EXTERN PetscErrorCode SNESVIGetVariableBounds(SNES, Vec *, Vec *);
987: PETSC_EXTERN PetscErrorCode SNESVISetComputeVariableBounds(SNES, PetscErrorCode (*)(SNES, Vec, Vec));
988: PETSC_EXTERN PetscErrorCode SNESVIGetInactiveSet(SNES, IS *);
989: PETSC_EXTERN PetscErrorCode SNESVIGetActiveSetIS(SNES, Vec, Vec, IS *);
990: PETSC_EXTERN PetscErrorCode SNESVIComputeInactiveSetFnorm(SNES, Vec, Vec, PetscReal *);
991: PETSC_EXTERN PetscErrorCode SNESVIComputeInactiveSetFtY(SNES, Vec, Vec, Vec, PetscScalar *);
992: PETSC_EXTERN PetscErrorCode SNESVISetRedundancyCheck(SNES, PetscErrorCode (*)(SNES, IS, IS *, PetscCtx), PetscCtx);
993: PETSC_EXTERN PetscErrorCode SNESVIComputeMeritFunction(Vec, PetscReal *, PetscReal *);
994: PETSC_EXTERN PetscErrorCode SNESVIComputeFunction(SNES, Vec, Vec, PetscCtx);
995: PETSC_EXTERN PetscErrorCode DMSetVI(DM, IS);
996: PETSC_EXTERN PetscErrorCode DMDestroyVI(DM);

998: PETSC_EXTERN PetscErrorCode SNESTestLocalMin(SNES);

1000: /* Should this routine be private? */
1001: PETSC_EXTERN PetscErrorCode SNESComputeJacobian(SNES, Vec, Mat, Mat);
1002: PETSC_EXTERN PetscErrorCode SNESTestJacobian(SNES, PetscReal *, PetscReal *);
1003: PETSC_EXTERN PetscErrorCode SNESTestFunction(SNES);

1005: PETSC_EXTERN PetscErrorCode SNESSetDM(SNES, DM);
1006: PETSC_EXTERN PetscErrorCode SNESGetDM(SNES, DM *);
1007: PETSC_EXTERN PetscErrorCode SNESSetNPC(SNES, SNES);
1008: PETSC_EXTERN PetscErrorCode SNESGetNPC(SNES, SNES *);
1009: PETSC_EXTERN PetscErrorCode SNESHasNPC(SNES, PetscBool *);
1010: PETSC_EXTERN PetscErrorCode SNESApplyNPC(SNES, Vec, Vec, Vec);
1011: PETSC_EXTERN PetscErrorCode SNESGetNPCFunction(SNES, Vec, PetscReal *);
1012: PETSC_EXTERN PetscErrorCode SNESComputeFunctionDefaultNPC(SNES, Vec, Vec);
1013: PETSC_EXTERN PetscErrorCode SNESSetNPCSide(SNES, PCSide);
1014: PETSC_EXTERN PetscErrorCode SNESGetNPCSide(SNES, PCSide *);
1015: PETSC_EXTERN PetscErrorCode SNESSetLineSearch(SNES, SNESLineSearch);
1016: PETSC_EXTERN PetscErrorCode SNESGetLineSearch(SNES, SNESLineSearch *);

1018: PETSC_DEPRECATED_FUNCTION(3, 4, 0, "SNESGetLineSearch()", ) static inline PetscErrorCode SNESGetSNESLineSearch(SNES snes, SNESLineSearch *ls)
1019: {
1020:   return SNESGetLineSearch(snes, ls);
1021: }
1022: PETSC_DEPRECATED_FUNCTION(3, 4, 0, "SNESSetLineSearch()", ) static inline PetscErrorCode SNESSetSNESLineSearch(SNES snes, SNESLineSearch ls)
1023: {
1024:   return SNESSetLineSearch(snes, ls);
1025: }

1027: PETSC_EXTERN PetscErrorCode SNESSetUpMatrices(SNES);
1028: PETSC_EXTERN PetscErrorCode DMSNESSetFunction(DM, SNESFunctionFn *, PetscCtx);
1029: PETSC_EXTERN PetscErrorCode DMSNESGetFunction(DM, SNESFunctionFn **, PetscCtxRt);
1030: PETSC_EXTERN PetscErrorCode DMSNESSetFunctionContextDestroy(DM, PetscCtxDestroyFn *);
1031: PETSC_EXTERN PetscErrorCode DMSNESSetMFFunction(DM, SNESFunctionFn *, PetscCtx);
1032: PETSC_EXTERN PetscErrorCode DMSNESSetNGS(DM, SNESNGSFn *, PetscCtx);
1033: PETSC_EXTERN PetscErrorCode DMSNESGetNGS(DM, SNESNGSFn **, PetscCtxRt);
1034: PETSC_EXTERN PetscErrorCode DMSNESSetJacobian(DM, SNESJacobianFn *, PetscCtx);
1035: PETSC_EXTERN PetscErrorCode DMSNESGetJacobian(DM, SNESJacobianFn **, PetscCtxRt);
1036: PETSC_EXTERN PetscErrorCode DMSNESSetJacobianContextDestroy(DM, PetscCtxDestroyFn *);
1037: PETSC_EXTERN PetscErrorCode DMSNESSetPicard(DM, SNESFunctionFn *, SNESJacobianFn *, PetscCtx);
1038: PETSC_EXTERN PetscErrorCode DMSNESGetPicard(DM, SNESFunctionFn **, SNESJacobianFn **, PetscCtxRt);
1039: PETSC_EXTERN PetscErrorCode DMSNESSetObjective(DM, SNESObjectiveFn *, PetscCtx);
1040: PETSC_EXTERN PetscErrorCode DMSNESGetObjective(DM, SNESObjectiveFn **, PetscCtxRt);
1041: PETSC_EXTERN PetscErrorCode DMCopyDMSNES(DM, DM);

1043: /*S
1044:   DMDASNESFunctionFn - Function type for the local residual callback set with `DMDASNESSetFunctionLocal()` on a `DMDA`-based `SNES`

1046:   Calling Sequence:
1047: + info - the local grid information from the `DMDA`
1048: . u    - pointer to the local input solution array
1049: . f    - pointer to the local output residual array to be filled
1050: - ctx  - optional user-provided context

1052:   Level: intermediate

1054: .seealso: `DMDA`, `SNES`, `DMDASNESSetFunctionLocal()`, `DMDASNESJacobianFn`, `DMDASNESObjectiveFn`, `DMDASNESFunctionVecFn`
1055: S*/
1056: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode DMDASNESFunctionFn(DMDALocalInfo *info, void *u, void *f, PetscCtx ctx);

1058: /*S
1059:   DMDASNESJacobianFn - Function type for the local Jacobian callback set with `DMDASNESSetJacobianLocal()` on a `DMDA`-based `SNES`

1061:   Calling Sequence:
1062: + info - the local grid information from the `DMDA`
1063: . u    - pointer to the local input solution array
1064: . J    - the Jacobian matrix to assemble
1065: . Jp   - the matrix from which the preconditioner for the Jacobian is to be constructed
1066: - ctx  - optional user-provided context

1068:   Level: intermediate

1070: .seealso: `DMDA`, `SNES`, `DMDASNESSetJacobianLocal()`, `DMDASNESFunctionFn`, `DMDASNESObjectiveFn`, `DMDASNESJacobianVecFn`
1071: S*/
1072: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode DMDASNESJacobianFn(DMDALocalInfo *info, void *u, Mat J, Mat Jp, PetscCtx ctx);

1074: /*S
1075:   DMDASNESObjectiveFn - Function type for the local objective callback set with `DMDASNESSetObjectiveLocal()` on a `DMDA`-based `SNES`

1077:   Calling Sequence:
1078: + info - the local grid information from the `DMDA`
1079: . u    - pointer to the local input solution array
1080: . obj  - on output, the local contribution to the objective function value
1081: - ctx  - optional user-provided context

1083:   Level: intermediate

1085: .seealso: `DMDA`, `SNES`, `DMDASNESSetObjectiveLocal()`, `DMDASNESFunctionFn`, `DMDASNESJacobianFn`, `DMDASNESObjectiveVecFn`
1086: S*/
1087: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode DMDASNESObjectiveFn(DMDALocalInfo *info, void *u, PetscReal *obj, PetscCtx ctx);

1089: /*S
1090:   DMDASNESFunctionVecFn - `Vec`-based variant of `DMDASNESFunctionFn`, set with `DMDASNESSetFunctionLocalVec()`

1092:   Calling Sequence:
1093: + info - the local grid information from the `DMDA`
1094: . u    - the local input solution `Vec`
1095: . f    - the local output residual `Vec`
1096: - ctx  - optional user-provided context

1098:   Level: intermediate

1100: .seealso: `DMDA`, `SNES`, `DMDASNESSetFunctionLocalVec()`, `DMDASNESFunctionFn`, `DMDASNESJacobianVecFn`, `DMDASNESObjectiveVecFn`
1101: S*/
1102: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode DMDASNESFunctionVecFn(DMDALocalInfo *info, Vec u, Vec f, PetscCtx ctx);

1104: /*S
1105:   DMDASNESJacobianVecFn - `Vec`-based variant of `DMDASNESJacobianFn`, set with `DMDASNESSetJacobianLocalVec()`

1107:   Calling Sequence:
1108: + info - the local grid information from the `DMDA`
1109: . u    - the local input solution `Vec`
1110: . J    - the Jacobian matrix to assemble
1111: . Jp   - the preconditioner matrix to assemble
1112: - ctx  - optional user-provided context

1114:   Level: intermediate

1116: .seealso: `DMDA`, `SNES`, `DMDASNESSetJacobianLocalVec()`, `DMDASNESJacobianFn`, `DMDASNESFunctionVecFn`, `DMDASNESObjectiveVecFn`
1117: S*/
1118: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode DMDASNESJacobianVecFn(DMDALocalInfo *info, Vec u, Mat J, Mat Jp, PetscCtx ctx);

1120: /*S
1121:   DMDASNESObjectiveVecFn - `Vec`-based variant of `DMDASNESObjectiveFn`, set with `DMDASNESSetObjectiveLocalVec()`

1123:   Calling Sequence:
1124: + info - the local grid information from the `DMDA`
1125: . u    - the local input solution `Vec`
1126: . obj  - on output, the local contribution to the objective function value
1127: - ctx  - optional user-provided context

1129:   Level: intermediate

1131: .seealso: `DMDA`, `SNES`, `DMDASNESSetObjectiveLocalVec()`, `DMDASNESObjectiveFn`, `DMDASNESFunctionVecFn`, `DMDASNESJacobianVecFn`
1132: S*/
1133: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode DMDASNESObjectiveVecFn(DMDALocalInfo *info, Vec u, PetscReal *obj, PetscCtx ctx);

1135: PETSC_EXTERN PetscErrorCode DMDASNESSetFunctionLocal(DM, InsertMode, DMDASNESFunctionFn *, PetscCtx);
1136: PETSC_EXTERN PetscErrorCode DMDASNESSetJacobianLocal(DM, DMDASNESJacobianFn *, PetscCtx);
1137: PETSC_EXTERN PetscErrorCode DMDASNESSetObjectiveLocal(DM, DMDASNESObjectiveFn *, PetscCtx);
1138: PETSC_EXTERN PetscErrorCode DMDASNESSetPicardLocal(DM, InsertMode, DMDASNESFunctionFn *, DMDASNESJacobianFn *, PetscCtx);

1140: PETSC_EXTERN PetscErrorCode DMDASNESSetFunctionLocalVec(DM, InsertMode, DMDASNESFunctionVecFn *, PetscCtx);
1141: PETSC_EXTERN PetscErrorCode DMDASNESSetJacobianLocalVec(DM, DMDASNESJacobianVecFn *, PetscCtx);
1142: PETSC_EXTERN PetscErrorCode DMDASNESSetObjectiveLocalVec(DM, DMDASNESObjectiveVecFn *, PetscCtx);

1144: PETSC_EXTERN PetscErrorCode DMSNESSetBoundaryLocal(DM, PetscErrorCode (*)(DM, Vec, PetscCtx), PetscCtx);
1145: PETSC_EXTERN PetscErrorCode DMSNESSetObjectiveLocal(DM, PetscErrorCode (*)(DM, Vec, PetscReal *, PetscCtx), PetscCtx);
1146: PETSC_EXTERN PetscErrorCode DMSNESSetFunctionLocal(DM, PetscErrorCode (*)(DM, Vec, Vec, PetscCtx), PetscCtx);
1147: PETSC_EXTERN PetscErrorCode DMSNESSetJacobianLocal(DM, PetscErrorCode (*)(DM, Vec, Mat, Mat, PetscCtx), PetscCtx);
1148: PETSC_EXTERN PetscErrorCode DMSNESGetBoundaryLocal(DM, PetscErrorCode (**)(DM, Vec, PetscCtx), PetscCtxRt);
1149: PETSC_EXTERN PetscErrorCode DMSNESGetObjectiveLocal(DM, PetscErrorCode (**)(DM, Vec, PetscReal *, PetscCtx), PetscCtxRt);
1150: PETSC_EXTERN PetscErrorCode DMSNESGetFunctionLocal(DM, PetscErrorCode (**)(DM, Vec, Vec, PetscCtx), PetscCtxRt);
1151: PETSC_EXTERN PetscErrorCode DMSNESGetJacobianLocal(DM, PetscErrorCode (**)(DM, Vec, Mat, Mat, PetscCtx), PetscCtxRt);

1153: /* Routines for Multiblock solver */
1154: PETSC_EXTERN PetscErrorCode SNESMultiblockSetFields(SNES, const char[], PetscInt, const PetscInt *);
1155: PETSC_EXTERN PetscErrorCode SNESMultiblockSetIS(SNES, const char[], IS);
1156: PETSC_EXTERN PetscErrorCode SNESMultiblockSetBlockSize(SNES, PetscInt);
1157: PETSC_EXTERN PetscErrorCode SNESMultiblockSetType(SNES, PCCompositeType);
1158: PETSC_EXTERN PetscErrorCode SNESMultiblockGetSubSNES(SNES, PetscInt *, SNES *[]);

1160: /*J
1161:    SNESMSType - String with the name of a PETSc `SNESMS` method.

1163:    Level: intermediate

1165: .seealso: [](ch_snes), `SNESMS`, `SNESMSGetType()`, `SNESMSSetType()`, `SNES`
1166: J*/
1167: typedef const char *SNESMSType;
1168: #define SNESMSM62       "m62"
1169: #define SNESMSEULER     "euler"
1170: #define SNESMSJAMESON83 "jameson83"
1171: #define SNESMSVLTP11    "vltp11"
1172: #define SNESMSVLTP21    "vltp21"
1173: #define SNESMSVLTP31    "vltp31"
1174: #define SNESMSVLTP41    "vltp41"
1175: #define SNESMSVLTP51    "vltp51"
1176: #define SNESMSVLTP61    "vltp61"

1178: PETSC_EXTERN PetscErrorCode SNESMSRegister(SNESMSType, PetscInt, PetscInt, PetscReal, const PetscReal[], const PetscReal[], const PetscReal[]);
1179: PETSC_EXTERN PetscErrorCode SNESMSRegisterAll(void);
1180: PETSC_EXTERN PetscErrorCode SNESMSGetType(SNES, SNESMSType *);
1181: PETSC_EXTERN PetscErrorCode SNESMSSetType(SNES, SNESMSType);
1182: PETSC_EXTERN PetscErrorCode SNESMSGetDamping(SNES, PetscReal *);
1183: PETSC_EXTERN PetscErrorCode SNESMSSetDamping(SNES, PetscReal);
1184: PETSC_EXTERN PetscErrorCode SNESMSFinalizePackage(void);
1185: PETSC_EXTERN PetscErrorCode SNESMSInitializePackage(void);
1186: PETSC_EXTERN PetscErrorCode SNESMSRegisterDestroy(void);

1188: /*MC
1189:    SNESNGMRESRestartType - the restart approach used by `SNESNGMRES`

1191:   Values:
1192: +   `SNES_NGMRES_RESTART_NONE`       - never restart
1193: .   `SNES_NGMRES_RESTART_DIFFERENCE` - restart based upon difference criteria
1194: -   `SNES_NGMRES_RESTART_PERIODIC`   - restart after a fixed number of iterations

1196:   Options Database Keys:
1197: + -snes_ngmres_restart_type (difference|periodic|none) - set the restart type
1198: - -snes_ngmres_restart 30                              - sets the number of iterations before restart for periodic

1200:    Level: intermediate

1202: .seealso: `SNES`, `SNESNGMRES`, `SNESNGMRESSetSelectType()`, `SNESNGMRESGetSelectType()`, `SNESNGMRESSetRestartType()`,
1203:           `SNESNGMRESGetRestartType()`, `SNESNGMRESSelectType`
1204: M*/
1205: typedef enum {
1206:   SNES_NGMRES_RESTART_NONE       = 0,
1207:   SNES_NGMRES_RESTART_PERIODIC   = 1,
1208:   SNES_NGMRES_RESTART_DIFFERENCE = 2
1209: } SNESNGMRESRestartType;
1210: PETSC_EXTERN const char *const SNESNGMRESRestartTypes[];

1212: /*MC
1213:    SNESNGMRESSelectType - the approach used by `SNESNGMRES` to determine how the candidate solution and
1214:   combined solution are used to create the next iterate.

1216:    Values:
1217: +   `SNES_NGMRES_SELECT_NONE`       - choose the combined solution all the time
1218: .   `SNES_NGMRES_SELECT_DIFFERENCE` - choose based upon the selection criteria
1219: -   `SNES_NGMRES_SELECT_LINESEARCH` - choose based upon line search combination

1221:   Options Database Key:
1222: . -snes_ngmres_select_type (difference|none|linesearch) - select how the next iterate is created

1224:    Level: intermediate

1226: .seealso: `SNES`, `SNESNGMRES`, `SNESNGMRESSetSelectType()`, `SNESNGMRESGetSelectType()`, `SNESNGMRESSetRestartType()`,
1227:           `SNESNGMRESGetRestartType()`, `SNESNGMRESRestartType`
1228: M*/
1229: typedef enum {
1230:   SNES_NGMRES_SELECT_NONE       = 0,
1231:   SNES_NGMRES_SELECT_DIFFERENCE = 1,
1232:   SNES_NGMRES_SELECT_LINESEARCH = 2
1233: } SNESNGMRESSelectType;
1234: PETSC_EXTERN const char *const SNESNGMRESSelectTypes[];

1236: PETSC_EXTERN PetscErrorCode SNESNGMRESSetRestartType(SNES, SNESNGMRESRestartType);
1237: PETSC_EXTERN PetscErrorCode SNESNGMRESSetSelectType(SNES, SNESNGMRESSelectType);
1238: PETSC_EXTERN PetscErrorCode SNESNGMRESSetRestartFmRise(SNES, PetscBool);
1239: PETSC_EXTERN PetscErrorCode SNESNGMRESGetRestartFmRise(SNES, PetscBool *);

1241: /*MC
1242:    SNESNCGType - the conjugate update approach for `SNESNCG`

1244:    Values:
1245: +   `SNES_NCG_FR`  - Fletcher-Reeves update
1246: .   `SNES_NCG_PRP` - Polak-Ribiere-Polyak update, the default and the only one that tolerates generalized search directions
1247: .   `SNES_NCG_HS`  - Hestenes-Steifel update
1248: .   `SNES_NCG_DY`  - Dai-Yuan update
1249: -   `SNES_NCG_CD`  - Conjugate Descent update

1251:   Options Database Key:
1252: . -snes_ncg_type (fr|prp|hs|dy|cd) - select the type

1254:    Level: intermediate

1256: .seealso: `SNES`, `SNESNCG`, `SNESNCGSetType()`
1257: M*/
1258: typedef enum {
1259:   SNES_NCG_FR  = 0,
1260:   SNES_NCG_PRP = 1,
1261:   SNES_NCG_HS  = 2,
1262:   SNES_NCG_DY  = 3,
1263:   SNES_NCG_CD  = 4
1264: } SNESNCGType;
1265: PETSC_EXTERN const char *const SNESNCGTypes[];

1267: PETSC_EXTERN PetscErrorCode SNESNCGSetType(SNES, SNESNCGType);

1269: /*MC
1270:    SNESQNScaleType - the scaling type used by `SNESQN`

1272:    Values:
1273: +   `SNES_QN_SCALE_NONE`     - don't scale the problem
1274: .   `SNES_QN_SCALE_SCALAR`   - use Shanno scaling
1275: .   `SNES_QN_SCALE_DIAGONAL` - scale with a diagonalized BFGS formula (see Gilbert and Lemarechal 1989), available
1276: -   `SNES_QN_SCALE_JACOBIAN` - scale by solving a linear system coming from the Jacobian you provided with `SNESSetJacobian()`
1277:                                computed at the first iteration of `SNESQN` and at ever restart.

1279:     Options Database Key:
1280: . -snes_qn_scale_type (diagonal|none|scalar|jacobian) - Select the scaling type

1282:    Level: intermediate

1284: .seealso: `SNES`, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNType`, `SNESQNSetType()`, `SNESQNSetRestartType()`, `SNESQNRestartType`
1285: M*/
1286: typedef enum {
1287:   SNES_QN_SCALE_DEFAULT  = 0,
1288:   SNES_QN_SCALE_NONE     = 1,
1289:   SNES_QN_SCALE_SCALAR   = 2,
1290:   SNES_QN_SCALE_DIAGONAL = 3,
1291:   SNES_QN_SCALE_JACOBIAN = 4
1292: } SNESQNScaleType;
1293: PETSC_EXTERN const char *const SNESQNScaleTypes[];

1295: /*MC
1296:    SNESQNRestartType - the restart approached used by `SNESQN`

1298:    Values:
1299: +   `SNES_QN_RESTART_NONE`     - never restart
1300: .   `SNES_QN_RESTART_POWELL`   - restart based upon descent criteria
1301: -   `SNES_QN_RESTART_PERIODIC` - restart after a fixed number of iterations

1303:   Options Database Keys:
1304: + -snes_qn_restart_type (powell|periodic|none) - set the restart type
1305: - -snes_qn_m m                                 - sets the number of stored updates and the restart period for periodic

1307:    Level: intermediate

1309: .seealso: `SNES`, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNType`, `SNESQNSetType()`, `SNESQNSetRestartType()`, `SNESQNScaleType`
1310: M*/
1311: typedef enum {
1312:   SNES_QN_RESTART_DEFAULT  = 0,
1313:   SNES_QN_RESTART_NONE     = 1,
1314:   SNES_QN_RESTART_POWELL   = 2,
1315:   SNES_QN_RESTART_PERIODIC = 3
1316: } SNESQNRestartType;
1317: PETSC_EXTERN const char *const SNESQNRestartTypes[];

1319: /*MC
1320:    SNESQNType - the type used by `SNESQN`

1322:   Values:
1323: +   `SNES_QN_LBFGS`      - LBFGS variant
1324: .   `SNES_QN_BROYDEN`    - Broyden variant
1325: -   `SNES_QN_BADBROYDEN` - Bad Broyden variant

1327:   Options Database Key:
1328: . -snes_qn_type (lbfgs|broyden|badbroyden) - quasi-Newton type

1330:    Level: intermediate

1332: .seealso: `SNES`, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNSetType()`, `SNESQNScaleType`, `SNESQNRestartType`, `SNESQNSetRestartType()`
1333: M*/
1334: typedef enum {
1335:   SNES_QN_LBFGS      = 0,
1336:   SNES_QN_BROYDEN    = 1,
1337:   SNES_QN_BADBROYDEN = 2
1338: } SNESQNType;
1339: PETSC_EXTERN const char *const SNESQNTypes[];

1341: PETSC_EXTERN PetscErrorCode SNESQNSetType(SNES, SNESQNType);
1342: PETSC_EXTERN PetscErrorCode SNESQNSetScaleType(SNES, SNESQNScaleType);
1343: PETSC_EXTERN PetscErrorCode SNESQNSetRestartType(SNES, SNESQNRestartType);

1345: PETSC_EXTERN PetscErrorCode SNESNASMGetType(SNES, PCASMType *);
1346: PETSC_EXTERN PetscErrorCode SNESNASMSetType(SNES, PCASMType);
1347: PETSC_EXTERN PetscErrorCode SNESNASMGetSubdomains(SNES, PetscInt *, SNES *[], VecScatter *[], VecScatter *[], VecScatter *[]);
1348: PETSC_EXTERN PetscErrorCode SNESNASMSetSubdomains(SNES, PetscInt, SNES[], VecScatter[], VecScatter[], VecScatter[]);
1349: PETSC_EXTERN PetscErrorCode SNESNASMSetDamping(SNES, PetscReal);
1350: PETSC_EXTERN PetscErrorCode SNESNASMGetDamping(SNES, PetscReal *);
1351: PETSC_EXTERN PetscErrorCode SNESNASMGetSubdomainVecs(SNES, PetscInt *, Vec *[], Vec *[], Vec *[], Vec *[]);
1352: PETSC_EXTERN PetscErrorCode SNESNASMSetComputeFinalJacobian(SNES, PetscBool);
1353: PETSC_EXTERN PetscErrorCode SNESNASMGetSNES(SNES, PetscInt, SNES *);
1354: PETSC_EXTERN PetscErrorCode SNESNASMGetNumber(SNES, PetscInt *);
1355: PETSC_EXTERN PetscErrorCode SNESNASMSetWeight(SNES, Vec);

1357: /*E
1358:   SNESCompositeType - Determines how two or more preconditioners are composed with the `SNESType` of `SNESCOMPOSITE`

1360:   Values:
1361: + `SNES_COMPOSITE_ADDITIVE`        - results from application of all preconditioners are added together
1362: . `SNES_COMPOSITE_MULTIPLICATIVE`  - preconditioners are applied sequentially to the residual freshly
1363:                                      computed after the previous preconditioner application
1364: - `SNES_COMPOSITE_ADDITIVEOPTIMAL` - uses a linear combination of the solutions obtained with each preconditioner that approximately minimize the function
1365:                                      value at the new iteration.

1367:    Level: beginner

1369: .seealso: [](sec_pc), `PCCOMPOSITE`, `PCFIELDSPLIT`, `PC`, `PCCompositeSetType()`, `PCCompositeType`
1370: E*/
1371: typedef enum {
1372:   SNES_COMPOSITE_ADDITIVE,
1373:   SNES_COMPOSITE_MULTIPLICATIVE,
1374:   SNES_COMPOSITE_ADDITIVEOPTIMAL
1375: } SNESCompositeType;
1376: PETSC_EXTERN const char *const SNESCompositeTypes[];

1378: PETSC_EXTERN PetscErrorCode SNESCompositeSetType(SNES, SNESCompositeType);
1379: PETSC_EXTERN PetscErrorCode SNESCompositeAddSNES(SNES, SNESType);
1380: PETSC_EXTERN PetscErrorCode SNESCompositeGetSNES(SNES, PetscInt, SNES *);
1381: PETSC_EXTERN PetscErrorCode SNESCompositeGetNumber(SNES, PetscInt *);
1382: PETSC_EXTERN PetscErrorCode SNESCompositeSetDamping(SNES, PetscInt, PetscReal);

1384: PETSC_EXTERN PetscErrorCode SNESPatchSetDiscretisationInfo(SNES, PetscInt, DM *, PetscInt *, PetscInt *, const PetscInt **, const PetscInt *, PetscInt, const PetscInt *, PetscInt, const PetscInt *);
1385: PETSC_EXTERN PetscErrorCode SNESPatchSetComputeOperator(SNES, PetscErrorCode (*func)(PC, PetscInt, Vec, Mat, IS, PetscInt, const PetscInt *, const PetscInt *, PetscCtx), PetscCtx);
1386: PETSC_EXTERN PetscErrorCode SNESPatchSetComputeFunction(SNES, PetscErrorCode (*func)(PC, PetscInt, Vec, Vec, IS, PetscInt, const PetscInt *, const PetscInt *, PetscCtx), PetscCtx);
1387: PETSC_EXTERN PetscErrorCode SNESPatchSetConstructType(SNES, PCPatchConstructType, PetscErrorCode (*func)(PC, PetscInt *, IS **, IS *, PetscCtx), PetscCtx);
1388: PETSC_EXTERN PetscErrorCode SNESPatchSetCellNumbering(SNES, PetscSection);

1390: /*E
1391:     SNESFASType - Determines the type of nonlinear multigrid method that is run.

1393:    Values:
1394: +  `SNES_FAS_MULTIPLICATIVE` (default) - traditional V or W cycle as determined by `SNESFASSetCycles()`
1395: .  `SNES_FAS_ADDITIVE`                 - additive FAS cycle
1396: .  `SNES_FAS_FULL`                     - full FAS cycle
1397: -  `SNES_FAS_KASKADE`                  - Kaskade FAS cycle

1399:    Level: beginner

1401: .seealso: [](ch_snes), `SNESFAS`, `PCMGSetType()`, `PCMGType`
1402: E*/
1403: typedef enum {
1404:   SNES_FAS_MULTIPLICATIVE,
1405:   SNES_FAS_ADDITIVE,
1406:   SNES_FAS_FULL,
1407:   SNES_FAS_KASKADE
1408: } SNESFASType;
1409: PETSC_EXTERN const char *const SNESFASTypes[];

1411: /* called on the finest level FAS instance*/
1412: PETSC_EXTERN PetscErrorCode SNESFASSetType(SNES, SNESFASType);
1413: PETSC_EXTERN PetscErrorCode SNESFASGetType(SNES, SNESFASType *);
1414: PETSC_EXTERN PetscErrorCode SNESFASSetLevels(SNES, PetscInt, MPI_Comm *);
1415: PETSC_EXTERN PetscErrorCode SNESFASGetLevels(SNES, PetscInt *);
1416: PETSC_EXTERN PetscErrorCode SNESFASGetCycleSNES(SNES, PetscInt, SNES *);
1417: PETSC_EXTERN PetscErrorCode SNESFASSetNumberSmoothUp(SNES, PetscInt);
1418: PETSC_EXTERN PetscErrorCode SNESFASSetNumberSmoothDown(SNES, PetscInt);
1419: PETSC_EXTERN PetscErrorCode SNESFASSetCycles(SNES, PetscInt);
1420: PETSC_EXTERN PetscErrorCode SNESFASSetMonitor(SNES, PetscViewerAndFormat *, PetscBool);
1421: PETSC_EXTERN PetscErrorCode SNESFASSetLog(SNES, PetscBool);

1423: PETSC_EXTERN PetscErrorCode SNESFASSetGalerkin(SNES, PetscBool);
1424: PETSC_EXTERN PetscErrorCode SNESFASGetGalerkin(SNES, PetscBool *);
1425: PETSC_EXTERN PetscErrorCode SNESFASGalerkinFunctionDefault(SNES, Vec, Vec, PetscCtx);

1427: /* called on any level -- "Cycle" FAS instance */
1428: PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmoother(SNES, SNES *);
1429: PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmootherUp(SNES, SNES *);
1430: PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmootherDown(SNES, SNES *);
1431: PETSC_EXTERN PetscErrorCode SNESFASCycleGetCorrection(SNES, SNES *);
1432: PETSC_EXTERN PetscErrorCode SNESFASCycleGetInterpolation(SNES, Mat *);
1433: PETSC_EXTERN PetscErrorCode SNESFASCycleGetRestriction(SNES, Mat *);
1434: PETSC_EXTERN PetscErrorCode SNESFASCycleGetInjection(SNES, Mat *);
1435: PETSC_EXTERN PetscErrorCode SNESFASCycleGetRScale(SNES, Vec *);
1436: PETSC_EXTERN PetscErrorCode SNESFASCycleSetCycles(SNES, PetscInt);
1437: PETSC_EXTERN PetscErrorCode SNESFASCycleIsFine(SNES, PetscBool *);

1439: /* called on the (outer) finest level FAS to set/get parameters on any level instance */
1440: PETSC_EXTERN PetscErrorCode SNESFASSetInterpolation(SNES, PetscInt, Mat);
1441: PETSC_EXTERN PetscErrorCode SNESFASGetInterpolation(SNES, PetscInt, Mat *);
1442: PETSC_EXTERN PetscErrorCode SNESFASSetRestriction(SNES, PetscInt, Mat);
1443: PETSC_EXTERN PetscErrorCode SNESFASGetRestriction(SNES, PetscInt, Mat *);
1444: PETSC_EXTERN PetscErrorCode SNESFASSetInjection(SNES, PetscInt, Mat);
1445: PETSC_EXTERN PetscErrorCode SNESFASGetInjection(SNES, PetscInt, Mat *);
1446: PETSC_EXTERN PetscErrorCode SNESFASSetRScale(SNES, PetscInt, Vec);
1447: PETSC_EXTERN PetscErrorCode SNESFASGetRScale(SNES, PetscInt, Vec *);
1448: PETSC_EXTERN PetscErrorCode SNESFASSetContinuation(SNES, PetscBool);

1450: PETSC_EXTERN PetscErrorCode SNESFASGetSmoother(SNES, PetscInt, SNES *);
1451: PETSC_EXTERN PetscErrorCode SNESFASGetSmootherUp(SNES, PetscInt, SNES *);
1452: PETSC_EXTERN PetscErrorCode SNESFASGetSmootherDown(SNES, PetscInt, SNES *);
1453: PETSC_EXTERN PetscErrorCode SNESFASGetCoarseSolve(SNES, SNES *);

1455: /* parameters for full FAS */
1456: PETSC_EXTERN PetscErrorCode SNESFASFullSetDownSweep(SNES, PetscBool);
1457: PETSC_EXTERN PetscErrorCode SNESFASCreateCoarseVec(SNES, Vec *);
1458: PETSC_EXTERN PetscErrorCode SNESFASRestrict(SNES, Vec, Vec);
1459: PETSC_EXTERN PetscErrorCode SNESFASFullSetTotal(SNES, PetscBool);
1460: PETSC_EXTERN PetscErrorCode SNESFASFullGetTotal(SNES, PetscBool *);

1462: PETSC_EXTERN PetscErrorCode DMPlexSetSNESVariableBounds(DM, SNES);
1463: PETSC_EXTERN PetscErrorCode DMSNESCheckDiscretization(SNES, DM, PetscReal, Vec, PetscReal, PetscReal[]);
1464: PETSC_EXTERN PetscErrorCode DMSNESCheckResidual(SNES, DM, Vec, PetscReal, PetscReal *);
1465: PETSC_EXTERN PetscErrorCode DMSNESCheckJacobian(SNES, DM, Vec, PetscReal, PetscBool *, PetscReal *);
1466: PETSC_EXTERN PetscErrorCode DMSNESCheckFromOptions(SNES, Vec);
1467: PETSC_EXTERN PetscErrorCode DMSNESComputeJacobianAction(DM, Vec, Vec, Vec, PetscCtx);
1468: PETSC_EXTERN PetscErrorCode DMSNESCreateJacobianMF(DM, Vec, PetscCtx, Mat *);

1470: PETSC_EXTERN PetscErrorCode SNESNewtonALSetFunction(SNES, SNESFunctionFn *, PetscCtx);
1471: PETSC_EXTERN PetscErrorCode SNESNewtonALGetFunction(SNES, SNESFunctionFn **, PetscCtxRt);
1472: PETSC_EXTERN PetscErrorCode SNESNewtonALComputeFunction(SNES, Vec, Vec);
1473: PETSC_EXTERN PetscErrorCode SNESNewtonALGetLoadParameter(SNES, PetscReal *);
1474: PETSC_EXTERN PetscErrorCode SNESNewtonALSetDiagonalScaling(SNES snes, Vec v);

1476: /*MC
1477:    SNESNewtonALCorrectionType - the approach used by `SNESNEWTONAL` to determine
1478:    the correction to the current increment. While the exact correction satisfies
1479:    the constraint surface at every iteration, it also requires solving a quadratic
1480:    equation which may not have real roots. Conversely, the normal correction is more
1481:    efficient and always yields a real correction and is the default.

1483:    Values:
1484: +   `SNES_NEWTONAL_CORRECTION_EXACT`  - choose the correction which exactly satisfies the constraint
1485: -   `SNES_NEWTONAL_CORRECTION_NORMAL` - choose the correction in the updated normal hyper-surface to the constraint surface

1487:    Options Database Key:
1488: . -snes_newtonal_correction_type (exact|normal) - exactly satisfy the constraint or satisfy it on the normal hyper-surface

1490:    Level: intermediate

1492: .seealso: `SNES`, `SNESNEWTONAL`, `SNESNewtonALSetCorrectionType()`
1493: M*/
1494: typedef enum {
1495:   SNES_NEWTONAL_CORRECTION_EXACT  = 0,
1496:   SNES_NEWTONAL_CORRECTION_NORMAL = 1,
1497: } SNESNewtonALCorrectionType;
1498: PETSC_EXTERN const char *const SNESNewtonALCorrectionTypes[];

1500: PETSC_EXTERN PetscErrorCode SNESNewtonALSetCorrectionType(SNES, SNESNewtonALCorrectionType);