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_DEPRECATED_FUNCTION(3, 26, 0, "SNESMonitorDefault()", ) static inline PetscErrorCode SNESMonitorDefaultShort(SNES snes, PetscInt n, PetscReal fgnorm, PetscViewerAndFormat *vf)
133: {
134: return SNESMonitorDefault(snes, n, fgnorm, vf);
135: }
136: PETSC_EXTERN PetscErrorCode SNESMonitorDefaultField(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
137: PETSC_EXTERN PetscErrorCode SNESMonitorJacUpdateSpectrum(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
138: PETSC_EXTERN PetscErrorCode SNESMonitorFields(SNES, PetscInt, PetscReal, PetscViewerAndFormat *);
139: PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidual(KSP, PetscInt, PetscReal, PetscViewerAndFormat *);
140: PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidualDrawLG(KSP, PetscInt, PetscReal, PetscViewerAndFormat *);
141: PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidualDrawLGCreate(PetscViewer, PetscViewerFormat, PetscCtx, PetscViewerAndFormat **);
143: PETSC_EXTERN PetscErrorCode SNESSetTolerances(SNES, PetscReal, PetscReal, PetscReal, PetscInt, PetscInt);
144: PETSC_EXTERN PetscErrorCode SNESSetDivergenceTolerance(SNES, PetscReal);
145: PETSC_EXTERN PetscErrorCode SNESGetTolerances(SNES, PetscReal *, PetscReal *, PetscReal *, PetscInt *, PetscInt *);
146: PETSC_EXTERN PetscErrorCode SNESGetDivergenceTolerance(SNES, PetscReal *);
147: PETSC_EXTERN PetscErrorCode SNESGetForceIteration(SNES, PetscBool *);
148: PETSC_EXTERN PetscErrorCode SNESSetForceIteration(SNES, PetscBool);
149: PETSC_EXTERN PetscErrorCode SNESGetIterationNumber(SNES, PetscInt *);
150: PETSC_EXTERN PetscErrorCode SNESSetIterationNumber(SNES, PetscInt);
152: /*E
153: SNESNewtonTRFallbackType - type of fallback in case the solution of the trust-region subproblem is outside of the radius
155: Values:
156: + `SNES_TR_FALLBACK_NEWTON` - use scaled Newton step
157: . `SNES_TR_FALLBACK_CAUCHY` - use Cauchy direction
158: - `SNES_TR_FALLBACK_DOGLEG` - use dogleg method
160: Level: intermediate
162: .seealso: [](ch_snes), `SNES`, `SNESNEWTONTR`, `SNESNEWTONTRDC`
163: E*/
164: typedef enum {
165: SNES_TR_FALLBACK_NEWTON,
166: SNES_TR_FALLBACK_CAUCHY,
167: SNES_TR_FALLBACK_DOGLEG,
168: } SNESNewtonTRFallbackType;
170: PETSC_EXTERN const char *const SNESNewtonTRFallbackTypes[];
172: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetPreCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, PetscBool *, PetscCtx), PetscCtx);
173: PETSC_EXTERN PetscErrorCode SNESNewtonTRGetPreCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, PetscBool *, PetscCtx), PetscCtxRt);
174: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetPostCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, PetscCtx), PetscCtx);
175: PETSC_EXTERN PetscErrorCode SNESNewtonTRGetPostCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, PetscCtx), PetscCtxRt);
176: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetFallbackType(SNES, SNESNewtonTRFallbackType);
177: PETSC_EXTERN PetscErrorCode SNESNewtonTRPreCheck(SNES, Vec, Vec, PetscBool *);
178: PETSC_EXTERN PetscErrorCode SNESNewtonTRPostCheck(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *);
179: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetNormType(SNES, NormType);
181: /*E
182: SNESNewtonTRQNType - type of quasi-Newton model to use
184: Values:
185: + `SNES_TR_QN_NONE` - do not use a quasi-Newton model
186: . `SNES_TR_QN_SAME` - use the same quasi-Newton model for matrix and the generation of the preconditioner
187: - `SNES_TR_QN_DIFFERENT` - use different quasi-Newton models for matrix and the generation of the preconditioner
189: Level: intermediate
191: .seealso: [](ch_snes), `SNES`, `SNESNEWTONTR`
192: E*/
193: typedef enum {
194: SNES_TR_QN_NONE,
195: SNES_TR_QN_SAME,
196: SNES_TR_QN_DIFFERENT,
197: } SNESNewtonTRQNType;
199: PETSC_EXTERN const char *const SNESNewtonTRQNTypes[];
201: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetQNType(SNES, SNESNewtonTRQNType);
203: PETSC_EXTERN PETSC_DEPRECATED_FUNCTION(3, 22, 0, "SNESNewtonTRSetTolerances()", ) PetscErrorCode SNESSetTrustRegionTolerance(SNES, PetscReal);
204: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetTolerances(SNES, PetscReal, PetscReal, PetscReal);
205: PETSC_EXTERN PetscErrorCode SNESNewtonTRGetTolerances(SNES, PetscReal *, PetscReal *, PetscReal *);
206: PETSC_EXTERN PetscErrorCode SNESNewtonTRSetUpdateParameters(SNES, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal);
207: PETSC_EXTERN PetscErrorCode SNESNewtonTRGetUpdateParameters(SNES, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *);
209: PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetRhoFlag(SNES, PetscBool *);
210: PETSC_EXTERN PetscErrorCode SNESNewtonTRDCSetPreCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, PetscBool *, PetscCtx), PetscCtx);
211: PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetPreCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, PetscBool *, PetscCtx), PetscCtxRt);
212: PETSC_EXTERN PetscErrorCode SNESNewtonTRDCSetPostCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, PetscCtx), PetscCtx);
213: PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetPostCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, PetscCtx), PetscCtxRt);
215: PETSC_EXTERN PetscErrorCode SNESGetNonlinearStepFailures(SNES, PetscInt *);
216: PETSC_EXTERN PetscErrorCode SNESSetMaxNonlinearStepFailures(SNES, PetscInt);
217: PETSC_EXTERN PetscErrorCode SNESGetMaxNonlinearStepFailures(SNES, PetscInt *);
218: PETSC_EXTERN PetscErrorCode SNESGetNumberFunctionEvals(SNES, PetscInt *);
220: PETSC_EXTERN PetscErrorCode SNESSetLagPreconditioner(SNES, PetscInt);
221: PETSC_EXTERN PetscErrorCode SNESGetLagPreconditioner(SNES, PetscInt *);
222: PETSC_EXTERN PetscErrorCode SNESSetLagJacobian(SNES, PetscInt);
223: PETSC_EXTERN PetscErrorCode SNESGetLagJacobian(SNES, PetscInt *);
224: PETSC_EXTERN PetscErrorCode SNESSetLagPreconditionerPersists(SNES, PetscBool);
225: PETSC_EXTERN PetscErrorCode SNESSetLagJacobianPersists(SNES, PetscBool);
226: PETSC_EXTERN PetscErrorCode SNESSetGridSequence(SNES, PetscInt);
227: PETSC_EXTERN PetscErrorCode SNESGetGridSequence(SNES, PetscInt *);
229: PETSC_EXTERN PetscErrorCode SNESGetLinearSolveIterations(SNES, PetscInt *);
230: PETSC_EXTERN PetscErrorCode SNESGetLinearSolveFailures(SNES, PetscInt *);
231: PETSC_EXTERN PetscErrorCode SNESSetMaxLinearSolveFailures(SNES, PetscInt);
232: PETSC_EXTERN PetscErrorCode SNESGetMaxLinearSolveFailures(SNES, PetscInt *);
233: PETSC_EXTERN PetscErrorCode SNESSetCountersReset(SNES, PetscBool);
234: PETSC_EXTERN PetscErrorCode SNESResetCounters(SNES);
236: PETSC_EXTERN PetscErrorCode SNESKSPSetUseEW(SNES, PetscBool);
237: PETSC_EXTERN PetscErrorCode SNESKSPGetUseEW(SNES, PetscBool *);
238: PETSC_EXTERN PetscErrorCode SNESKSPSetParametersEW(SNES, PetscInt, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal);
239: PETSC_EXTERN PetscErrorCode SNESKSPGetParametersEW(SNES, PetscInt *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *);
241: PETSC_EXTERN PetscErrorCode SNESMonitorLGRange(SNES, PetscInt, PetscReal, PetscCtx);
243: PETSC_EXTERN PetscErrorCode SNESSetApplicationContext(SNES, PetscCtx);
244: PETSC_EXTERN PetscErrorCode SNESGetApplicationContext(SNES, PetscCtxRt);
245: PETSC_EXTERN PetscErrorCode SNESSetComputeApplicationContext(SNES, PetscErrorCode (*)(SNES, PetscCtxRt), PetscCtxDestroyFn *);
247: PETSC_EXTERN PetscErrorCode SNESPythonSetType(SNES, const char[]);
248: PETSC_EXTERN PetscErrorCode SNESPythonGetType(SNES, const char *[]);
250: PETSC_EXTERN PetscErrorCode SNESSetFunctionDomainError(SNES);
251: PETSC_EXTERN PetscErrorCode SNESSetObjectiveDomainError(SNES);
252: PETSC_EXTERN PetscErrorCode SNESSetJacobianDomainError(SNES);
253: PETSC_EXTERN PetscErrorCode SNESSetCheckJacobianDomainError(SNES, PetscBool);
254: PETSC_EXTERN PetscErrorCode SNESGetCheckJacobianDomainError(SNES, PetscBool *);
256: #define SNES_CONVERGED_TR_DELTA_DEPRECATED SNES_CONVERGED_TR_DELTA PETSC_DEPRECATED_ENUM(3, 12, 0, "SNES_DIVERGED_TR_DELTA", )
257: #define SNES_DIVERGED_FNORM_NAN_DEPRECATED SNES_DIVERGED_FNORM_NAN PETSC_DEPRECATED_ENUM(3, 25, 0, "SNES_DIVERGED_FUNCTION_NANORINF", )
258: /*E
259: SNESConvergedReason - reason a `SNESSolve()` was determined to have converged or diverged
261: Values:
262: + `SNES_CONVERGED_FNORM_ABS` - $ ||F|| \le abstol $
263: . `SNES_CONVERGED_FNORM_RELATIVE` - $ ||F|| <= rtol*||F(x_0))|| $ where $x_0 $ is the initial guess
264: . `SNES_CONVERGED_SNORM_RELATIVE` - The 2-norm of the last step $ \le stol * ||x|| $ where $ x $ is the current solution
265: . `SNES_CONVERGED_USER` - The user has indicated convergence for an arbitrary reason
266: . `SNES_DIVERGED_FUNCTION_COUNT` - The user provided function has been called more times than the maximum set in `SNESSetTolerances()`
267: . `SNES_DIVERGED_DTOL` - The norm of the function has increased by a factor of divtol set with `SNESSetDivergenceTolerance()`
268: . `SNES_DIVERGED_FUNCTION_NANORINF` - the 2-norm of the current function evaluation is not-a-number (NaN) or infinity, (this
269: 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)
270: . `SNES_DIVERGED_OBJECTIVE_NANORINF` - the object function evaluation is not-a-number (NaN) or infinity, (this
271: 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)
272: . `SNES_DIVERGED_FUNCTION_DOMAIN` - the function evaluation occurred outside the function's domain (function callback provided by
273: `SNESSetFunction()` called `SNESSetObjectiveDomainError()`) and the solver could not recover from this (by, for example, cutting the step size)
274: . `SNES_DIVERGED_OBJECTIVE_DOMAIN` - the object function evaluation occurred outside the function's domain (function callback provided by
275: `SNESSetObjective()` called `SNESSetObjectiveDomainError()`) and the solver could not recover from this (by, for example, cutting the step size)
276: . `SNES_DIVERGED_JACOBIAN_DOMAIN` - the Jacobian evaluation occurred outside the function's domain (function callback provided by
277: `SNESSetJacobian()` called `SNESSetJacobianDomainError()`)
278: . `SNES_DIVERGED_MAX_IT` - `SNESSolve()` has reached the maximum number of iterations requested
279: . `SNES_DIVERGED_LINE_SEARCH` - The line search has failed. This only occurs for `SNES` solvers that use a line search
280: . `SNES_DIVERGED_LOCAL_MIN` - the algorithm seems to have stagnated at a local minimum that is not zero.
281: - `SNES_CONVERGED_ITERATING - this only occurs if `SNESGetConvergedReason()` is called during the `SNESSolve()`
283: Level: beginner
285: Notes:
286: The two most common reasons for divergence are an incorrectly coded or computed Jacobian or failure or lack of convergence in the linear system
287: (in this case we recommend
288: testing with `-pc_type lu` to eliminate the linear solver as the cause of the problem).
290: `SNES_DIVERGED_LOCAL_MIN` can only occur when using a `SNES` solver that uses a line search (`SNESLineSearch`).
291: The line search wants to $ \min Q(\alpha) = 1/2 || F(x + \alpha s) ||^2_2 $ this occurs
292: 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
293: $ Q'(\alpha) = -F(x)^T F'(x)^(-1)^T F'(x+\alpha s)F(x+\alpha s)$; when $\alpha = 0$
294: $Q'(0) = - ||F(x)||^2_2 $ which is always NEGATIVE if $F'(x)$ is invertible. This means the Newton
295: direction is a descent direction and the line search should succeed if $\alpha $ is small enough.
297: If $F'(x)$ is NOT invertible AND $F'(x)^T F(x) = 0 $ then $Q'(0) = 0 $ and the Newton direction
298: is NOT a descent direction so the line search will fail. All one can do at this point
299: is change the initial guess and try again.
301: An alternative explanation: Newton's method can be regarded as replacing the function with
302: its linear approximation and minimizing the 2-norm of that. That is $F(x+s) \approx F(x) + F'(x)s$
303: so we minimize $ || F(x) + F'(x) s ||^2_2$ using Least Squares. If $F'(x)$ is invertible then
304: $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
305: exists a nontrivial (that is $F'(x)s \ne 0$) solution to the equation and this direction is
306: $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)
307: = - (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$
308: and $F'(x)^T F'(x)$ has no negative eigenvalues $Q'(0) < 0$ so $s$ is a descent direction and the line
309: search should succeed for small enough $\alpha$.
311: Note that this RARELY happens in practice. Far more likely the linear system is not being solved
312: (well enough?) or the Jacobian is wrong.
314: `SNES_DIVERGED_MAX_IT` means that the solver reached the maximum number of iterations without satisfying any
315: convergence criteria. `SNES_CONVERGED_ITS` means that `SNESConvergedSkip()` was chosen as the convergence test;
316: thus the usual convergence criteria have not been checked and may or may not be satisfied.
318: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPConvergedReason`, `SNESSetConvergenceTest()`, `SNESSetTolerances()`
319: E*/
320: typedef enum { /* converged */
321: SNES_CONVERGED_FNORM_ABS = 2, /* ||F|| < atol */
322: SNES_CONVERGED_FNORM_RELATIVE = 3, /* ||F|| < rtol*||F_initial|| */
323: SNES_CONVERGED_SNORM_RELATIVE = 4, /* Newton computed step size small; || delta x || < stol || x || */
324: SNES_CONVERGED_ITS = 5, /* maximum iterations reached */
325: SNES_BREAKOUT_INNER_ITER = 6, /* Flag to break out of inner loop after checking custom convergence, used in multi-phase flow when state changes */
326: SNES_CONVERGED_USER = 7, /* The user has indicated convergence for an arbitrary reason */
327: /* diverged */
328: SNES_DIVERGED_FUNCTION_DOMAIN = -1, /* the new x location passed the function is not in the domain of F */
329: SNES_DIVERGED_FUNCTION_COUNT = -2,
330: SNES_DIVERGED_LINEAR_SOLVE = -3, /* the linear solve failed */
331: SNES_DIVERGED_FUNCTION_NANORINF = -4,
332: SNES_DIVERGED_FNORM_NAN_DEPRECATED = -4,
333: SNES_DIVERGED_MAX_IT = -5,
334: SNES_DIVERGED_LINE_SEARCH = -6, /* the line search failed */
335: SNES_DIVERGED_INNER = -7, /* inner solve failed */
336: SNES_DIVERGED_LOCAL_MIN = -8, /* || J^T b || is small, implies converged to local minimum of F() */
337: SNES_DIVERGED_DTOL = -9, /* || F || > divtol*||F_initial|| */
338: SNES_DIVERGED_JACOBIAN_DOMAIN = -10, /* Jacobian calculation does not make sense */
339: SNES_DIVERGED_TR_DELTA = -11,
340: SNES_CONVERGED_TR_DELTA_DEPRECATED = -11,
341: SNES_DIVERGED_USER = -12, /* The user has indicated divergence for an arbitrary reason */
342: SNES_DIVERGED_OBJECTIVE_DOMAIN = -13,
343: SNES_DIVERGED_OBJECTIVE_NANORINF = -14,
345: SNES_CONVERGED_ITERATING = 0
346: } SNESConvergedReason;
347: PETSC_EXTERN const char *const *SNESConvergedReasons;
349: /*MC
350: SNES_CONVERGED_FNORM_ABS - $||F|| \le abstol$
352: Level: beginner
354: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
355: M*/
357: /*MC
358: SNES_CONVERGED_FNORM_RELATIVE - $||F|| \le rtol*||F(x_0)||$ where $x_0$ is the initial guess
360: Level: beginner
362: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
363: M*/
365: /*MC
366: SNES_CONVERGED_SNORM_RELATIVE - The 2-norm of the last step $\le stol * ||x||$ where `x` is the current
367: solution and `stol` is the 4th argument to `SNESSetTolerances()`
369: Options Database Key:
370: -snes_stol stol - the step tolerance
372: Level: beginner
374: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
375: M*/
377: /*MC
378: SNES_DIVERGED_FUNCTION_COUNT - The user provided function has been called more times then the final
379: argument to `SNESSetTolerances()`
381: Level: beginner
383: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
384: M*/
386: /*MC
387: SNES_DIVERGED_DTOL - The norm of the function has increased by a factor of divtol set with `SNESSetDivergenceTolerance()`
389: Level: beginner
391: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`, `SNESSetDivergenceTolerance()`
392: M*/
394: /*MC
395: SNES_DIVERGED_FUNCTION_NANORINF - the 2-norm of the current function evaluation is not-a-number (NaN) or infinity, this
396: is usually caused by a division of 0 by 0, or infinity. See `SNESSetFunctionDomainError()`
398: Level: beginner
400: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
401: M*/
403: /*MC
404: SNES_DIVERGED_FUNCTION_DOMAIN - the function provided with `SNESSetFunction()` called `SNESSetFunctionDomainError()` and
405: the solver could not recoverer.
407: Level: beginner
409: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
410: M*/
412: /*MC
413: SNES_DIVERGED_OBJECTIVE_DOMAIN - the function provided with `SNESSetObjective()` called `SNESSetObjectiveDomainError()` and
414: the solver could not recoverer.
416: Level: beginner
418: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
419: M*/
421: /*MC
422: SNES_DIVERGED_JACOBIAN_DOMAIN - the function provided with `SNESSetJacobian()` called `SNESSetJacobianDomainError()`
424: Level: beginner
426: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
427: M*/
429: /*MC
430: SNES_DIVERGED_MAX_IT - SNESSolve() has reached the maximum number of iterations requested
432: Level: beginner
434: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
435: M*/
437: /*MC
438: SNES_DIVERGED_LINE_SEARCH - The line search has failed. This only occurs for a `SNES` solvers that use a line search
440: Level: beginner
442: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`, `SNESLineSearch`
443: M*/
445: /*MC
446: SNES_DIVERGED_LOCAL_MIN - the algorithm seems to have stagnated at a local minimum that is not zero.
447: See the manual page for `SNESConvergedReason` for more details
449: Level: beginner
451: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
452: M*/
454: /*MC
455: SNES_CONERGED_ITERATING - this only occurs if `SNESGetConvergedReason()` is called during the `SNESSolve()`
457: Level: beginner
459: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`
460: M*/
462: PETSC_EXTERN PetscErrorCode SNESSetConvergenceTest(SNES, PetscErrorCode (*)(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, PetscCtx), PetscCtx, PetscCtxDestroyFn *);
463: PETSC_EXTERN PetscErrorCode SNESConvergedDefault(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, PetscCtx);
464: PETSC_EXTERN PetscErrorCode SNESConvergedSkip(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, PetscCtx);
465: PETSC_EXTERN PetscErrorCode SNESConvergedCorrectPressure(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, PetscCtx);
466: PETSC_EXTERN PetscErrorCode SNESGetConvergedReason(SNES, SNESConvergedReason *);
467: PETSC_EXTERN PetscErrorCode SNESGetConvergedReasonString(SNES, const char *[]);
468: PETSC_EXTERN PetscErrorCode SNESSetConvergedReason(SNES, SNESConvergedReason);
470: PETSC_DEPRECATED_FUNCTION(3, 5, 0, "SNESConvergedSkip()", ) static inline void SNESSkipConverged(void)
471: { /* never called */
472: }
473: #define SNESSkipConverged (SNESSkipConverged, SNESConvergedSkip)
475: /*S
476: SNESInitialGuessFn - A prototype of a `SNES` compute initial guess function that would be passed to `SNESSetComputeInitialGuess()`
478: Calling Sequence:
479: + snes - `SNES` context
480: . u - output vector to contain initial guess
481: - ctx - [optional] user-defined function context
483: Level: beginner
485: .seealso: [](ch_snes), `SNES`, `SNESSetComputeInitialGuess()`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`, `SNESFunctionFn`
486: S*/
487: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESInitialGuessFn(SNES snes, Vec u, PetscCtx ctx);
489: /*S
490: SNESFunctionFn - A prototype of a `SNES` evaluation function that would be passed to `SNESSetFunction()`
492: Calling Sequence:
493: + snes - `SNES` context
494: . u - input vector
495: . F - function vector
496: - ctx - [optional] user-defined function context
498: Level: beginner
500: .seealso: [](ch_snes), `SNES`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`, `SNESNGSFn`
501: S*/
502: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESFunctionFn(SNES snes, Vec u, Vec F, PetscCtx ctx);
504: /*S
505: SNESObjectiveFn - A prototype of a `SNES` objective evaluation function that would be passed to `SNESSetObjective()`
507: Calling Sequence:
508: + snes - `SNES` context
509: . u - input vector
510: . o - output value
511: - ctx - [optional] user-defined function context
513: Level: beginner
515: .seealso: [](ch_snes), `SNES`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`, `SNESNGSFn`
516: S*/
517: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESObjectiveFn(SNES snes, Vec u, PetscReal *o, PetscCtx ctx);
519: /*S
520: SNESJacobianFn - A prototype of a `SNES` Jacobian evaluation function that would be passed to `SNESSetJacobian()`
522: Calling Sequence:
523: + snes - the `SNES` context obtained from `SNESCreate()`
524: . u - input vector
525: . Amat - (approximate) Jacobian matrix
526: . Pmat - matrix used to construct the preconditioner, often the same as `Amat`
527: - ctx - [optional] user-defined context for matrix evaluation routine
529: Level: beginner
531: .seealso: [](ch_snes), `SNES`, `SNESSetJacobian()`, `SNESGetJacobian()`, `SNESFunctionFn`, `SNESNGSFn`
532: S*/
533: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESJacobianFn(SNES snes, Vec u, Mat Amat, Mat Pmat, PetscCtx ctx);
535: /*S
536: SNESNGSFn - A prototype of a `SNES` nonlinear Gauss-Seidel function that would be passed to `SNESSetNGS()`
538: Calling Sequence:
539: + snes - the `SNES` context obtained from `SNESCreate()`
540: . u - the current solution, updated in place
541: . b - the right-hand side vector (which may be `NULL`)
542: - ctx - [optional] user-defined context for matrix evaluation routine
544: Level: beginner
546: .seealso: [](ch_snes), `SNES`, `SNESSetJacobian()`, `SNESGetJacobian()`, `SNESFunctionFn`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`
547: S*/
548: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESNGSFn(SNES snes, Vec u, Vec b, PetscCtx ctx);
550: /*S
551: SNESUpdateFn - A prototype of a `SNES` update function that would be passed to `SNESSetUpdate()`
553: Calling Sequence:
554: + snes - `SNES` context
555: - step - the current iteration index
557: Level: advanced
559: .seealso: [](ch_snes), `SNES`, `SNESSetUpdate()`
560: S*/
561: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESUpdateFn(SNES snes, PetscInt step);
563: /* --------- Solving systems of nonlinear equations --------------- */
564: PETSC_EXTERN PetscErrorCode SNESSetFunction(SNES, Vec, SNESFunctionFn *, PetscCtx);
565: PETSC_EXTERN PetscErrorCode SNESGetFunction(SNES, Vec *, SNESFunctionFn **, PetscCtxRt);
566: PETSC_EXTERN PetscErrorCode SNESComputeFunction(SNES, Vec, Vec);
567: PETSC_EXTERN PetscErrorCode SNESComputeMFFunction(SNES, Vec, Vec);
568: PETSC_EXTERN PetscErrorCode SNESSetInitialFunction(SNES, Vec);
570: PETSC_EXTERN PetscErrorCode SNESSetJacobian(SNES, Mat, Mat, SNESJacobianFn *, PetscCtx);
571: PETSC_EXTERN PetscErrorCode SNESGetJacobian(SNES, Mat *, Mat *, SNESJacobianFn **, PetscCtxRt);
572: PETSC_EXTERN SNESFunctionFn SNESObjectiveComputeFunctionDefaultFD;
573: PETSC_EXTERN SNESJacobianFn SNESComputeJacobianDefault;
574: PETSC_EXTERN SNESJacobianFn SNESComputeJacobianDefaultColor;
575: PETSC_EXTERN PetscErrorCode SNESPruneJacobianColor(SNES, Mat, Mat);
576: PETSC_EXTERN PetscErrorCode SNESSetComputeInitialGuess(SNES, SNESInitialGuessFn *, PetscCtx);
577: PETSC_EXTERN PetscErrorCode SNESSetPicard(SNES, Vec, SNESFunctionFn *, Mat, Mat, SNESJacobianFn *, PetscCtx);
578: PETSC_EXTERN PetscErrorCode SNESGetPicard(SNES, Vec *, SNESFunctionFn **, Mat *, Mat *, SNESJacobianFn **, PetscCtxRt);
579: PETSC_EXTERN SNESFunctionFn SNESPicardComputeFunction;
580: PETSC_EXTERN SNESFunctionFn SNESPicardComputeMFFunction;
581: PETSC_EXTERN SNESJacobianFn SNESPicardComputeJacobian;
583: PETSC_EXTERN PetscErrorCode SNESSetObjective(SNES, SNESObjectiveFn *, PetscCtx);
584: PETSC_EXTERN PetscErrorCode SNESGetObjective(SNES, SNESObjectiveFn **, PetscCtxRt);
585: PETSC_EXTERN PetscErrorCode SNESComputeObjective(SNES, Vec, PetscReal *);
587: PETSC_EXTERN PetscErrorCode SNESSetUpdate(SNES, SNESUpdateFn *);
589: /*E
590: SNESNormSchedule - Frequency with which the norm is computed during a nonliner solve
592: Values:
593: + `SNES_NORM_DEFAULT` - use the default behavior for the current `SNESType`
594: . `SNES_NORM_NONE` - avoid all norm computations
595: . `SNES_NORM_ALWAYS` - compute the norms whenever possible
596: . `SNES_NORM_INITIAL_ONLY` - compute the norm only when the algorithm starts
597: . `SNES_NORM_FINAL_ONLY` - compute the norm only when the algorithm finishes
598: - `SNES_NORM_INITIAL_FINAL_ONLY` - compute the norm at the start and end of the algorithm
600: Level: advanced
602: Notes:
603: Support for these is highly dependent on the solver.
605: Some options limit the convergence tests that can be used.
607: The `SNES_NORM_NONE` option is most commonly used when the nonlinear solver is being used as a smoother, for example for `SNESFAS`
609: This is primarily used to turn off extra norm and function computation
610: when the solvers are composed.
612: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPSetNormType()`,
613: `KSPSetConvergenceTest()`, `KSPSetPCSide()`
614: E*/
615: typedef enum {
616: SNES_NORM_DEFAULT = -1,
617: SNES_NORM_NONE = 0,
618: SNES_NORM_ALWAYS = 1,
619: SNES_NORM_INITIAL_ONLY = 2,
620: SNES_NORM_FINAL_ONLY = 3,
621: SNES_NORM_INITIAL_FINAL_ONLY = 4
622: } SNESNormSchedule;
623: PETSC_EXTERN const char *const *const SNESNormSchedules;
625: /*MC
626: SNES_NORM_NONE - Don't compute function and its L2 norm when possible
628: Level: advanced
630: Note:
631: This is most useful for stationary solvers with a fixed number of iterations used as smoothers.
633: .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_DEFAULT`
634: M*/
636: /*MC
637: SNES_NORM_ALWAYS - Compute the function and its L2 norm at each iteration.
639: Level: advanced
641: Note:
642: Most solvers will use this no matter what norm type is passed to them.
644: .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_NONE`
645: M*/
647: /*MC
648: SNES_NORM_INITIAL_ONLY - Compute the function and its L2 at iteration 0, but do not update it.
650: Level: advanced
652: Notes:
653: This method is useful in composed methods, when a true solution might actually be found before `SNESSolve()` is called.
654: This option enables the solve to abort on the zeroth iteration if this is the case.
656: For solvers that require the computation of the L2 norm of the function as part of the method, this merely cancels
657: the norm computation at the last iteration (if possible).
659: .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_FINAL_ONLY`, `SNES_NORM_INITIAL_FINAL_ONLY`
660: M*/
662: /*MC
663: SNES_NORM_FINAL_ONLY - Compute the function and its L2 norm on only the final iteration.
665: Level: advanced
667: Note:
668: For solvers that require the computation of the L2 norm of the function as part of the method, behaves
669: exactly as `SNES_NORM_DEFAULT`. This method is useful when the function is gotten after `SNESSolve()` and
670: used in subsequent computation for methods that do not need the norm computed during the rest of the
671: solution procedure.
673: .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_INITIAL_ONLY`, `SNES_NORM_INITIAL_FINAL_ONLY`
674: M*/
676: /*MC
677: SNES_NORM_INITIAL_FINAL_ONLY - Compute the function and its L2 norm on only the initial and final iterations.
679: Level: advanced
681: Note:
682: This method combines the benefits of `SNES_NORM_INITIAL_ONLY` and `SNES_NORM_FINAL_ONLY`.
684: .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_SNES_NORM_INITIAL_ONLY`, `SNES_NORM_FINAL_ONLY`
685: M*/
687: PETSC_EXTERN PetscErrorCode SNESSetNormSchedule(SNES, SNESNormSchedule);
688: PETSC_EXTERN PetscErrorCode SNESGetNormSchedule(SNES, SNESNormSchedule *);
689: PETSC_EXTERN PetscErrorCode SNESSetFunctionNorm(SNES, PetscReal);
690: PETSC_EXTERN PetscErrorCode SNESGetFunctionNorm(SNES, PetscReal *);
691: PETSC_EXTERN PetscErrorCode SNESGetUpdateNorm(SNES, PetscReal *);
692: PETSC_EXTERN PetscErrorCode SNESGetSolutionNorm(SNES, PetscReal *);
694: /*E
695: SNESFunctionType - Type of function computed
697: Values:
698: + `SNES_FUNCTION_DEFAULT` - the default behavior for the current `SNESType`
699: . `SNES_FUNCTION_UNPRECONDITIONED` - the original function provided
700: - `SNES_FUNCTION_PRECONDITIONED` - the modification of the function by the preconditioner
702: Level: advanced
704: Note:
705: Support for these is dependent on the solver.
707: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPSetNormType()`,
708: `KSPSetConvergenceTest()`, `KSPSetPCSide()`
709: E*/
710: typedef enum {
711: SNES_FUNCTION_DEFAULT = -1,
712: SNES_FUNCTION_UNPRECONDITIONED = 0,
713: SNES_FUNCTION_PRECONDITIONED = 1
714: } SNESFunctionType;
715: PETSC_EXTERN const char *const *const SNESFunctionTypes;
717: PETSC_EXTERN PetscErrorCode SNESSetFunctionType(SNES, SNESFunctionType);
718: PETSC_EXTERN PetscErrorCode SNESGetFunctionType(SNES, SNESFunctionType *);
720: PETSC_EXTERN PetscErrorCode SNESSetNGS(SNES, SNESNGSFn *, PetscCtx);
721: PETSC_EXTERN PetscErrorCode SNESGetNGS(SNES, SNESNGSFn **, PetscCtxRt);
722: PETSC_EXTERN PetscErrorCode SNESComputeNGS(SNES, Vec, Vec);
724: PETSC_EXTERN PetscErrorCode SNESNGSSetSweeps(SNES, PetscInt);
725: PETSC_EXTERN PetscErrorCode SNESNGSGetSweeps(SNES, PetscInt *);
726: PETSC_EXTERN PetscErrorCode SNESNGSSetTolerances(SNES, PetscReal, PetscReal, PetscReal, PetscInt);
727: PETSC_EXTERN PetscErrorCode SNESNGSGetTolerances(SNES, PetscReal *, PetscReal *, PetscReal *, PetscInt *);
729: PETSC_EXTERN PetscErrorCode SNESSetAlwaysComputesFinalResidual(SNES, PetscBool);
730: PETSC_EXTERN PetscErrorCode SNESGetAlwaysComputesFinalResidual(SNES, PetscBool *);
732: PETSC_EXTERN PetscErrorCode SNESShellGetContext(SNES, PetscCtxRt);
733: PETSC_EXTERN PetscErrorCode SNESShellSetContext(SNES, PetscCtx);
734: PETSC_EXTERN PetscErrorCode SNESShellSetSolve(SNES, PetscErrorCode (*)(SNES, Vec));
736: /* --------- Routines specifically for line search methods --------------- */
738: /*S
739: SNESLineSearch - Abstract PETSc object that manages line-search operations for nonlinear solvers
741: Level: beginner
743: Note:
744: See `SNESLineSearchSetFromOptions()` for all the line search options.
746: .seealso: [](ch_snes), `SNESLineSearchType`, `SNESLineSearchCreate()`, `SNESLineSearchSetType()`, `SNES`, `SNESLineSearchSetFromOptions()`
747: S*/
748: typedef struct _p_SNESLineSearch *SNESLineSearch;
750: /*J
751: SNESLineSearchType - String with the name of a PETSc line search method `SNESLineSearch`. Provides all the linesearches for the nonlinear solvers, `SNES`,
752: in PETSc.
754: Values:
755: + `SNESLINESEARCHNONE` - Simple damping line search, defaults to using the full Newton step
756: . `SNESLINESEARCHBT` - Backtracking line search over the L2 norm of the function or an objective function
757: . `SNESLINESEARCHSECANT` - Secant line search over the L2 norm of the function or an objective function
758: . `SNESLINESEARCHCP` - Critical point secant line search assuming $F(x) = \nabla G(x)$ for some unknown $G(x)$
759: . `SNESLINESEARCHNLEQERR` - Affine-covariant error-oriented linesearch
760: - `SNESLINESEARCHBISECTION` - bisection line search for a root in the directional derivative
761: - `SNESLINESEARCHSHELL` - User provided `SNESLineSearch` implementation
763: Level: beginner
765: Note:
766: Use `SNESLineSearchSetType()` or the options database key `-snes_linesearch_type` to set
767: the specific line search algorithm to use with a given `SNES` object. Not all `SNESType` can utilize a line search.
769: .seealso: [](ch_snes), `SNESLineSearch`, `SNESLineSearchSetType()`, `SNES`
770: J*/
771: typedef const char *SNESLineSearchType;
772: #define SNESLINESEARCHBT "bt"
773: #define SNESLINESEARCHNLEQERR "nleqerr"
774: #define SNESLINESEARCHNONE "none"
775: #define SNESLINESEARCHBASIC PETSC_DEPRECATED_MACRO(3, 26, 0, "SNESLINESEARCHNONE", ) SNESLINESEARCHNONE
776: #define SNESLINESEARCHSECANT "secant"
777: #define SNESLINESEARCHL2 PETSC_DEPRECATED_MACRO(3, 24, 0, "SNESLINESEARCHSECANT", ) SNESLINESEARCHSECANT
778: #define SNESLINESEARCHCP "cp"
779: #define SNESLINESEARCHSHELL "shell"
780: #define SNESLINESEARCHNCGLINEAR "ncglinear"
781: #define SNESLINESEARCHBISECTION "bisection"
783: PETSC_EXTERN PetscFunctionList SNESList;
784: PETSC_EXTERN PetscClassId SNESLINESEARCH_CLASSID;
785: PETSC_EXTERN PetscFunctionList SNESLineSearchList;
787: #define SNES_LINESEARCH_ORDER_LINEAR 1
788: #define SNES_LINESEARCH_ORDER_QUADRATIC 2
789: #define SNES_LINESEARCH_ORDER_CUBIC 3
791: /*S
792: SNESLineSearchVIProjectFn - A prototype of a `SNES` function that projects a vector onto the VI bounds, passed to `SNESLineSearchSetVIFunctions()`
794: Calling Sequence:
795: + snes - `SNES` context
796: - u - the vector to project to the bounds
798: Level: advanced
800: Note:
801: The deprecated `SNESLineSearchVIProjectFunc` still works as a replacement for `SNESLineSearchVIProjectFn` *.
803: .seealso: [](ch_snes), `SNES`, `SNESLineSearch`
804: S*/
805: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESLineSearchVIProjectFn(SNES snes, Vec u);
806: PETSC_EXTERN_TYPEDEF typedef SNESLineSearchVIProjectFn *SNESLineSearchVIProjectFunc PETSC_DEPRECATED_TYPEDEF(3, 21, 0, "SNESLineSearchVIProjectFn*", );
808: /*S
809: 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,
810: passed to `SNESLineSearchSetVIFunctions()`
812: Calling Sequence:
813: + snes - `SNES` context
814: . f - the vector to compute the norm of
815: . u - the current solution, entries that are on the variational inequality (VI) bounds are ignored
816: - fnorm - the resulting norm
818: Level: advanced
820: .seealso: [](ch_snes), `SNES`, `SNESLineSearch`
821: S*/
822: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESLineSearchVINormFn(SNES snes, Vec f, Vec u, PetscReal *fnorm);
823: PETSC_EXTERN_TYPEDEF typedef SNESLineSearchVINormFn *SNESLineSearchVINormFunc PETSC_DEPRECATED_TYPEDEF(3, 21, 0, "SNESLineSearchVINormFnn*", );
825: /*S
826: SNESLineSearchVIDirDerivFn - A prototype of a `SNES` function that computes the directional derivative considering the VI bounds, passed to `SNESLineSearchSetVIFunctions()`
828: Calling Sequence:
829: + snes - `SNES` context
830: . f - the function vector to compute the directional derivative with
831: . u - the current solution, entries that are on the VI bounds are ignored
832: . y - the direction to compute the directional derivative
833: - fty - the resulting directional derivative
835: Level: advanced
837: .seealso: [](ch_snes), `SNES`, `SNESLineSearch`, `SNESLineSearchVINormFn`, `SNESLineSearchVIProjectFn`, `SNESLineSearchSetVIFunctions()`, `SNESLineSearchGetVIFunctions()`
838: S*/
839: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESLineSearchVIDirDerivFn(SNES snes, Vec f, Vec u, Vec y, PetscScalar *fty);
841: /*S
842: SNESLineSearchApplyFn - Function type for a `SNESLineSearch` implementation's apply routine
844: Calling Sequence:
845: . ls - the `SNESLineSearch` object whose internal state holds the current step, search direction and other data
847: Level: developer
849: .seealso: `SNESLineSearch`, `SNESLineSearchType`, `SNESLineSearchSetType()`, `SNESLineSearchShellApplyFn`
850: S*/
851: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESLineSearchApplyFn(SNESLineSearch ls);
852: PETSC_EXTERN_TYPEDEF typedef SNESLineSearchApplyFn *SNESLineSearchApplyFunc PETSC_DEPRECATED_TYPEDEF(3, 21, 0, "SNESLineSearchApplyFn*", );
853: /*S
854: SNESLineSearchShellApplyFn - Function type for the user-supplied apply routine registered with the `SNESLINESEARCHSHELL` line-search
856: Calling Sequence:
857: + ls - the `SNESLineSearch` object
858: - ctx - optional user-provided context set with `SNESLineSearchShellSetApply()`
860: Level: developer
862: .seealso: `SNESLineSearch`, `SNESLINESEARCHSHELL`, `SNESLineSearchShellSetApply()`, `SNESLineSearchApplyFn`
863: S*/
864: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode SNESLineSearchShellApplyFn(SNESLineSearch ls, PetscCtx ctx);
865: PETSC_EXTERN_TYPEDEF typedef SNESLineSearchShellApplyFn *SNESLineSearchUserFunc PETSC_DEPRECATED_TYPEDEF(3, 21, 0, "SNESLineSearchApplyFn*", );
867: PETSC_EXTERN PetscErrorCode SNESLineSearchCreate(MPI_Comm, SNESLineSearch *);
868: PETSC_EXTERN PetscErrorCode SNESLineSearchReset(SNESLineSearch);
869: PETSC_EXTERN PetscErrorCode SNESLineSearchView(SNESLineSearch, PetscViewer);
870: PETSC_EXTERN PetscErrorCode SNESLineSearchDestroy(SNESLineSearch *);
871: PETSC_EXTERN PetscErrorCode SNESLineSearchGetType(SNESLineSearch, SNESLineSearchType *);
872: PETSC_EXTERN PetscErrorCode SNESLineSearchSetType(SNESLineSearch, SNESLineSearchType);
873: PETSC_EXTERN PetscErrorCode SNESLineSearchSetFromOptions(SNESLineSearch);
874: PETSC_EXTERN PetscErrorCode SNESLineSearchSetFunction(SNESLineSearch, PetscErrorCode (*)(SNES, Vec, Vec));
875: PETSC_EXTERN PetscErrorCode SNESLineSearchSetUp(SNESLineSearch);
876: PETSC_EXTERN PetscErrorCode SNESLineSearchApply(SNESLineSearch, Vec, Vec, PetscReal *, Vec);
877: PETSC_EXTERN PetscErrorCode SNESLineSearchPreCheck(SNESLineSearch, Vec, Vec, PetscBool *);
878: PETSC_EXTERN PetscErrorCode SNESLineSearchPostCheck(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *);
879: PETSC_EXTERN PetscErrorCode SNESLineSearchSetWorkVecs(SNESLineSearch, PetscInt);
881: /* set the functions for precheck and postcheck */
883: PETSC_EXTERN PetscErrorCode SNESLineSearchSetPreCheck(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, Vec, Vec, PetscBool *, PetscCtx), PetscCtx);
884: PETSC_EXTERN PetscErrorCode SNESLineSearchSetPostCheck(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *, PetscCtx), PetscCtx);
886: PETSC_EXTERN PetscErrorCode SNESLineSearchGetPreCheck(SNESLineSearch, PetscErrorCode (**)(SNESLineSearch, Vec, Vec, PetscBool *, PetscCtx), PetscCtxRt);
887: PETSC_EXTERN PetscErrorCode SNESLineSearchGetPostCheck(SNESLineSearch, PetscErrorCode (**)(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *, PetscCtx), PetscCtxRt);
889: /* set the functions for VI-specific line search operations */
891: PETSC_EXTERN PetscErrorCode SNESLineSearchSetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFn *, SNESLineSearchVINormFn *, SNESLineSearchVIDirDerivFn *);
892: PETSC_EXTERN PetscErrorCode SNESLineSearchGetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFn **, SNESLineSearchVINormFn **, SNESLineSearchVIDirDerivFn **);
894: /* pointers to the associated SNES in order to be able to get the function evaluation out */
895: PETSC_EXTERN PetscErrorCode SNESLineSearchSetSNES(SNESLineSearch, SNES);
896: PETSC_EXTERN PetscErrorCode SNESLineSearchGetSNES(SNESLineSearch, SNES *);
898: /* set and get the parameters and vectors */
899: PETSC_EXTERN PetscErrorCode SNESLineSearchGetTolerances(SNESLineSearch, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscInt *);
900: PETSC_EXTERN PetscErrorCode SNESLineSearchSetTolerances(SNESLineSearch, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscInt);
902: PETSC_EXTERN PetscErrorCode SNESLineSearchPreCheckPicard(SNESLineSearch, Vec, Vec, PetscBool *, PetscCtx);
904: PETSC_EXTERN PetscErrorCode SNESLineSearchGetLambda(SNESLineSearch, PetscReal *);
905: PETSC_EXTERN PetscErrorCode SNESLineSearchSetLambda(SNESLineSearch, PetscReal);
907: PETSC_EXTERN PetscErrorCode SNESLineSearchGetDamping(SNESLineSearch, PetscReal *);
908: PETSC_EXTERN PetscErrorCode SNESLineSearchSetDamping(SNESLineSearch, PetscReal);
910: PETSC_EXTERN PetscErrorCode SNESLineSearchGetOrder(SNESLineSearch, PetscInt *);
911: PETSC_EXTERN PetscErrorCode SNESLineSearchSetOrder(SNESLineSearch, PetscInt);
913: /*E
914: SNESLineSearchReason - indication if the line search has succeeded or failed and why
916: Values:
917: + `SNES_LINESEARCH_SUCCEEDED` - the line search succeeded
918: . `SNES_LINESEARCH_FAILED_NANORINF` - a not a number of infinity appeared in the computions
919: . `SNES_LINESEARCH_FAILED_FUNCTION_DOMAIN` - the function was evaluated outside of its domain, see `SNESSetFunctionDomainError()`
920: . `SNES_LINESEARCH_FAILED_OBJECTIVE_DOMAIN`- the objective function was evaluated outside of its domain, see `SNESSetObjectiveDomainError()`
921: . `SNES_LINESEARCH_FAILED_JACOBIAN_DOMAIN` - the Jacobian was evaluated outside of its domain, see `SNESSetJacobianDomainError()`
922: . `SNES_LINESEARCH_FAILED_REDUCT` - the linear search failed to get the requested decrease in its norm or objective
923: . `SNES_LINESEARCH_FAILED_USER` - used by `SNESLINESEARCHNLEQERR` to indicate the user changed the search direction inappropriately
924: - `SNES_LINESEARCH_FAILED_FUNCTION` - indicates the maximum number of function evaluations allowed has been surpassed, `SNESConvergedReason` is also
925: set to `SNES_DIVERGED_FUNCTION_COUNT`
927: Level: intermediate
929: Developer Note:
930: Some of these reasons overlap with values of `SNESConvergedReason`. It is possibly a better design to have `SNESConvergedReaon` alone used also for indicating line
931: search failures.
933: .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPConvergedReason`, `SNESSetConvergenceTest()`,
934: `SNESSetFunctionDomainError()`, `SNESSetJacobianDomainError()`
935: E*/
936: typedef enum {
937: SNES_LINESEARCH_SUCCEEDED,
938: SNES_LINESEARCH_FAILED_NANORINF,
939: SNES_LINESEARCH_FAILED_FUNCTION_DOMAIN,
940: SNES_LINESEARCH_FAILED_OBJECTIVE_DOMAIN,
941: SNES_LINESEARCH_FAILED_JACOBIAN_DOMAIN,
942: SNES_LINESEARCH_FAILED_REDUCT, /* INSUFFICIENT REDUCTION */
943: SNES_LINESEARCH_FAILED_USER,
944: SNES_LINESEARCH_FAILED_FUNCTION
945: } SNESLineSearchReason;
947: PETSC_EXTERN PetscErrorCode SNESLineSearchGetReason(SNESLineSearch, SNESLineSearchReason *);
948: PETSC_EXTERN PetscErrorCode SNESLineSearchSetReason(SNESLineSearch, SNESLineSearchReason);
950: PETSC_EXTERN PetscErrorCode SNESLineSearchGetVecs(SNESLineSearch, Vec *, Vec *, Vec *, Vec *, Vec *);
951: PETSC_EXTERN PetscErrorCode SNESLineSearchSetVecs(SNESLineSearch, Vec, Vec, Vec, Vec, Vec);
953: PETSC_EXTERN PetscErrorCode SNESLineSearchGetNorms(SNESLineSearch, PetscReal *, PetscReal *, PetscReal *);
954: PETSC_EXTERN PetscErrorCode SNESLineSearchSetNorms(SNESLineSearch, PetscReal, PetscReal, PetscReal);
955: PETSC_EXTERN PetscErrorCode SNESLineSearchComputeNorms(SNESLineSearch);
956: PETSC_EXTERN PetscErrorCode SNESLineSearchSetComputeNorms(SNESLineSearch, PetscBool);
958: PETSC_EXTERN PetscErrorCode SNESLineSearchMonitor(SNESLineSearch);
959: PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSet(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, PetscCtx), PetscCtx, PetscCtxDestroyFn *);
960: PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSetFromOptions(SNESLineSearch, const char[], const char[], const char[], PetscErrorCode (*)(SNESLineSearch, PetscViewerAndFormat *), PetscErrorCode (*)(SNESLineSearch, PetscViewerAndFormat *));
961: PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorCancel(SNESLineSearch);
962: PETSC_EXTERN PetscErrorCode SNESLineSearchSetDefaultMonitor(SNESLineSearch, PetscViewer);
963: PETSC_EXTERN PetscErrorCode SNESLineSearchGetDefaultMonitor(SNESLineSearch, PetscViewer *);
964: PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSolutionUpdate(SNESLineSearch, PetscViewerAndFormat *);
966: PETSC_EXTERN PetscErrorCode SNESLineSearchAppendOptionsPrefix(SNESLineSearch, const char[]);
967: PETSC_EXTERN PetscErrorCode SNESLineSearchGetOptionsPrefix(SNESLineSearch, const char *[]);
969: /* Shell interface functions */
970: PETSC_EXTERN PetscErrorCode SNESLineSearchShellSetApply(SNESLineSearch, SNESLineSearchShellApplyFn *, PetscCtx);
971: PETSC_EXTERN PetscErrorCode SNESLineSearchShellGetApply(SNESLineSearch, SNESLineSearchShellApplyFn **, PetscCtxRt);
973: PETSC_DEPRECATED_FUNCTION(3, 21, 0, "SNESLinesearchShellSetApply()", ) static inline PetscErrorCode SNESLineSearchShellSetUserFunc(SNESLineSearch ls, SNESLineSearchShellApplyFn *f, PetscCtx ctx)
974: {
975: return SNESLineSearchShellSetApply(ls, f, ctx);
976: }
978: PETSC_DEPRECATED_FUNCTION(3, 21, 0, "SNESLinesearchShellGetApply()", ) static inline PetscErrorCode SNESLineSearchShellGetUserFunc(SNESLineSearch ls, SNESLineSearchShellApplyFn **f, PetscCtxRt ctx)
979: {
980: return SNESLineSearchShellGetApply(ls, f, ctx);
981: }
983: /* BT interface functions */
984: PETSC_EXTERN PetscErrorCode SNESLineSearchBTSetAlpha(SNESLineSearch, PetscReal);
985: PETSC_EXTERN PetscErrorCode SNESLineSearchBTGetAlpha(SNESLineSearch, PetscReal *);
987: /*register line search types */
988: PETSC_EXTERN PetscErrorCode SNESLineSearchRegister(const char[], PetscErrorCode (*)(SNESLineSearch));
990: /* Routines for VI solver */
991: PETSC_EXTERN PetscErrorCode SNESVISetVariableBounds(SNES, Vec, Vec);
992: PETSC_EXTERN PetscErrorCode SNESVIGetVariableBounds(SNES, Vec *, Vec *);
993: PETSC_EXTERN PetscErrorCode SNESVISetComputeVariableBounds(SNES, PetscErrorCode (*)(SNES, Vec, Vec));
994: PETSC_EXTERN PetscErrorCode SNESVIGetInactiveSet(SNES, IS *);
995: PETSC_EXTERN PetscErrorCode SNESVIGetActiveSetIS(SNES, Vec, Vec, IS *);
996: PETSC_EXTERN PetscErrorCode SNESVIComputeInactiveSetFnorm(SNES, Vec, Vec, PetscReal *);
997: PETSC_EXTERN PetscErrorCode SNESVIComputeInactiveSetFtY(SNES, Vec, Vec, Vec, PetscScalar *);
998: PETSC_EXTERN PetscErrorCode SNESVISetRedundancyCheck(SNES, PetscErrorCode (*)(SNES, IS, IS *, PetscCtx), PetscCtx);
999: PETSC_EXTERN PetscErrorCode SNESVIComputeMeritFunction(Vec, PetscReal *, PetscReal *);
1000: PETSC_EXTERN PetscErrorCode SNESVIComputeFunction(SNES, Vec, Vec, PetscCtx);
1001: PETSC_EXTERN PetscErrorCode DMSetVI(DM, IS);
1002: PETSC_EXTERN PetscErrorCode DMDestroyVI(DM);
1004: PETSC_EXTERN PetscErrorCode SNESTestLocalMin(SNES);
1006: /* Should this routine be private? */
1007: PETSC_EXTERN PetscErrorCode SNESComputeJacobian(SNES, Vec, Mat, Mat);
1008: PETSC_EXTERN PetscErrorCode SNESTestJacobian(SNES, PetscReal *, PetscReal *);
1009: PETSC_EXTERN PetscErrorCode SNESTestFunction(SNES);
1011: PETSC_EXTERN PetscErrorCode SNESSetDM(SNES, DM);
1012: PETSC_EXTERN PetscErrorCode SNESGetDM(SNES, DM *);
1013: PETSC_EXTERN PetscErrorCode SNESSetNPC(SNES, SNES);
1014: PETSC_EXTERN PetscErrorCode SNESGetNPC(SNES, SNES *);
1015: PETSC_EXTERN PetscErrorCode SNESHasNPC(SNES, PetscBool *);
1016: PETSC_EXTERN PetscErrorCode SNESApplyNPC(SNES, Vec, Vec, Vec);
1017: PETSC_EXTERN PetscErrorCode SNESGetNPCFunction(SNES, Vec, PetscReal *);
1018: PETSC_EXTERN PetscErrorCode SNESComputeFunctionDefaultNPC(SNES, Vec, Vec);
1019: PETSC_EXTERN PetscErrorCode SNESSetNPCSide(SNES, PCSide);
1020: PETSC_EXTERN PetscErrorCode SNESGetNPCSide(SNES, PCSide *);
1021: PETSC_EXTERN PetscErrorCode SNESSetLineSearch(SNES, SNESLineSearch);
1022: PETSC_EXTERN PetscErrorCode SNESGetLineSearch(SNES, SNESLineSearch *);
1024: PETSC_DEPRECATED_FUNCTION(3, 4, 0, "SNESGetLineSearch()", ) static inline PetscErrorCode SNESGetSNESLineSearch(SNES snes, SNESLineSearch *ls)
1025: {
1026: return SNESGetLineSearch(snes, ls);
1027: }
1028: PETSC_DEPRECATED_FUNCTION(3, 4, 0, "SNESSetLineSearch()", ) static inline PetscErrorCode SNESSetSNESLineSearch(SNES snes, SNESLineSearch ls)
1029: {
1030: return SNESSetLineSearch(snes, ls);
1031: }
1033: PETSC_EXTERN PetscErrorCode SNESSetUpMatrices(SNES);
1034: PETSC_EXTERN PetscErrorCode DMSNESSetFunction(DM, SNESFunctionFn *, PetscCtx);
1035: PETSC_EXTERN PetscErrorCode DMSNESGetFunction(DM, SNESFunctionFn **, PetscCtxRt);
1036: PETSC_EXTERN PetscErrorCode DMSNESSetFunctionContextDestroy(DM, PetscCtxDestroyFn *);
1037: PETSC_EXTERN PetscErrorCode DMSNESSetMFFunction(DM, SNESFunctionFn *, PetscCtx);
1038: PETSC_EXTERN PetscErrorCode DMSNESSetNGS(DM, SNESNGSFn *, PetscCtx);
1039: PETSC_EXTERN PetscErrorCode DMSNESGetNGS(DM, SNESNGSFn **, PetscCtxRt);
1040: PETSC_EXTERN PetscErrorCode DMSNESSetJacobian(DM, SNESJacobianFn *, PetscCtx);
1041: PETSC_EXTERN PetscErrorCode DMSNESGetJacobian(DM, SNESJacobianFn **, PetscCtxRt);
1042: PETSC_EXTERN PetscErrorCode DMSNESSetJacobianContextDestroy(DM, PetscCtxDestroyFn *);
1043: PETSC_EXTERN PetscErrorCode DMSNESSetPicard(DM, SNESFunctionFn *, SNESJacobianFn *, PetscCtx);
1044: PETSC_EXTERN PetscErrorCode DMSNESGetPicard(DM, SNESFunctionFn **, SNESJacobianFn **, PetscCtxRt);
1045: PETSC_EXTERN PetscErrorCode DMSNESSetObjective(DM, SNESObjectiveFn *, PetscCtx);
1046: PETSC_EXTERN PetscErrorCode DMSNESGetObjective(DM, SNESObjectiveFn **, PetscCtxRt);
1047: PETSC_EXTERN PetscErrorCode DMCopyDMSNES(DM, DM);
1049: /*S
1050: DMDASNESFunctionFn - Function type for the local residual callback set with `DMDASNESSetFunctionLocal()` on a `DMDA`-based `SNES`
1052: Calling Sequence:
1053: + info - the local grid information from the `DMDA`
1054: . u - pointer to the local input solution array
1055: . f - pointer to the local output residual array to be filled
1056: - ctx - optional user-provided context
1058: Level: intermediate
1060: .seealso: `DMDA`, `SNES`, `DMDASNESSetFunctionLocal()`, `DMDASNESJacobianFn`, `DMDASNESObjectiveFn`, `DMDASNESFunctionVecFn`
1061: S*/
1062: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode DMDASNESFunctionFn(DMDALocalInfo *info, void *u, void *f, PetscCtx ctx);
1064: /*S
1065: DMDASNESJacobianFn - Function type for the local Jacobian callback set with `DMDASNESSetJacobianLocal()` on a `DMDA`-based `SNES`
1067: Calling Sequence:
1068: + info - the local grid information from the `DMDA`
1069: . u - pointer to the local input solution array
1070: . J - the Jacobian matrix to assemble
1071: . Jp - the matrix from which the preconditioner for the Jacobian is to be constructed
1072: - ctx - optional user-provided context
1074: Level: intermediate
1076: .seealso: `DMDA`, `SNES`, `DMDASNESSetJacobianLocal()`, `DMDASNESFunctionFn`, `DMDASNESObjectiveFn`, `DMDASNESJacobianVecFn`
1077: S*/
1078: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode DMDASNESJacobianFn(DMDALocalInfo *info, void *u, Mat J, Mat Jp, PetscCtx ctx);
1080: /*S
1081: DMDASNESObjectiveFn - Function type for the local objective callback set with `DMDASNESSetObjectiveLocal()` on a `DMDA`-based `SNES`
1083: Calling Sequence:
1084: + info - the local grid information from the `DMDA`
1085: . u - pointer to the local input solution array
1086: . obj - on output, the local contribution to the objective function value
1087: - ctx - optional user-provided context
1089: Level: intermediate
1091: .seealso: `DMDA`, `SNES`, `DMDASNESSetObjectiveLocal()`, `DMDASNESFunctionFn`, `DMDASNESJacobianFn`, `DMDASNESObjectiveVecFn`
1092: S*/
1093: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode DMDASNESObjectiveFn(DMDALocalInfo *info, void *u, PetscReal *obj, PetscCtx ctx);
1095: /*S
1096: DMDASNESFunctionVecFn - `Vec`-based variant of `DMDASNESFunctionFn`, set with `DMDASNESSetFunctionLocalVec()`
1098: Calling Sequence:
1099: + info - the local grid information from the `DMDA`
1100: . u - the local input solution `Vec`
1101: . f - the local output residual `Vec`
1102: - ctx - optional user-provided context
1104: Level: intermediate
1106: .seealso: `DMDA`, `SNES`, `DMDASNESSetFunctionLocalVec()`, `DMDASNESFunctionFn`, `DMDASNESJacobianVecFn`, `DMDASNESObjectiveVecFn`
1107: S*/
1108: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode DMDASNESFunctionVecFn(DMDALocalInfo *info, Vec u, Vec f, PetscCtx ctx);
1110: /*S
1111: DMDASNESJacobianVecFn - `Vec`-based variant of `DMDASNESJacobianFn`, set with `DMDASNESSetJacobianLocalVec()`
1113: Calling Sequence:
1114: + info - the local grid information from the `DMDA`
1115: . u - the local input solution `Vec`
1116: . J - the Jacobian matrix to assemble
1117: . Jp - the preconditioner matrix to assemble
1118: - ctx - optional user-provided context
1120: Level: intermediate
1122: .seealso: `DMDA`, `SNES`, `DMDASNESSetJacobianLocalVec()`, `DMDASNESJacobianFn`, `DMDASNESFunctionVecFn`, `DMDASNESObjectiveVecFn`
1123: S*/
1124: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode DMDASNESJacobianVecFn(DMDALocalInfo *info, Vec u, Mat J, Mat Jp, PetscCtx ctx);
1126: /*S
1127: DMDASNESObjectiveVecFn - `Vec`-based variant of `DMDASNESObjectiveFn`, set with `DMDASNESSetObjectiveLocalVec()`
1129: Calling Sequence:
1130: + info - the local grid information from the `DMDA`
1131: . u - the local input solution `Vec`
1132: . obj - on output, the local contribution to the objective function value
1133: - ctx - optional user-provided context
1135: Level: intermediate
1137: .seealso: `DMDA`, `SNES`, `DMDASNESSetObjectiveLocalVec()`, `DMDASNESObjectiveFn`, `DMDASNESFunctionVecFn`, `DMDASNESJacobianVecFn`
1138: S*/
1139: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode DMDASNESObjectiveVecFn(DMDALocalInfo *info, Vec u, PetscReal *obj, PetscCtx ctx);
1141: PETSC_EXTERN PetscErrorCode DMDASNESSetFunctionLocal(DM, InsertMode, DMDASNESFunctionFn *, PetscCtx);
1142: PETSC_EXTERN PetscErrorCode DMDASNESSetJacobianLocal(DM, DMDASNESJacobianFn *, PetscCtx);
1143: PETSC_EXTERN PetscErrorCode DMDASNESSetObjectiveLocal(DM, DMDASNESObjectiveFn *, PetscCtx);
1144: PETSC_EXTERN PetscErrorCode DMDASNESSetPicardLocal(DM, InsertMode, DMDASNESFunctionFn *, DMDASNESJacobianFn *, PetscCtx);
1146: PETSC_EXTERN PetscErrorCode DMDASNESSetFunctionLocalVec(DM, InsertMode, DMDASNESFunctionVecFn *, PetscCtx);
1147: PETSC_EXTERN PetscErrorCode DMDASNESSetJacobianLocalVec(DM, DMDASNESJacobianVecFn *, PetscCtx);
1148: PETSC_EXTERN PetscErrorCode DMDASNESSetObjectiveLocalVec(DM, DMDASNESObjectiveVecFn *, PetscCtx);
1150: PETSC_EXTERN PetscErrorCode DMSNESSetBoundaryLocal(DM, PetscErrorCode (*)(DM, Vec, PetscCtx), PetscCtx);
1151: PETSC_EXTERN PetscErrorCode DMSNESSetObjectiveLocal(DM, PetscErrorCode (*)(DM, Vec, PetscReal *, PetscCtx), PetscCtx);
1152: PETSC_EXTERN PetscErrorCode DMSNESSetFunctionLocal(DM, PetscErrorCode (*)(DM, Vec, Vec, PetscCtx), PetscCtx);
1153: PETSC_EXTERN PetscErrorCode DMSNESSetJacobianLocal(DM, PetscErrorCode (*)(DM, Vec, Mat, Mat, PetscCtx), PetscCtx);
1154: PETSC_EXTERN PetscErrorCode DMSNESGetBoundaryLocal(DM, PetscErrorCode (**)(DM, Vec, PetscCtx), PetscCtxRt);
1155: PETSC_EXTERN PetscErrorCode DMSNESGetObjectiveLocal(DM, PetscErrorCode (**)(DM, Vec, PetscReal *, PetscCtx), PetscCtxRt);
1156: PETSC_EXTERN PetscErrorCode DMSNESGetFunctionLocal(DM, PetscErrorCode (**)(DM, Vec, Vec, PetscCtx), PetscCtxRt);
1157: PETSC_EXTERN PetscErrorCode DMSNESGetJacobianLocal(DM, PetscErrorCode (**)(DM, Vec, Mat, Mat, PetscCtx), PetscCtxRt);
1159: /* Routines for Multiblock solver */
1160: PETSC_EXTERN PetscErrorCode SNESMultiblockSetFields(SNES, const char[], PetscInt, const PetscInt *);
1161: PETSC_EXTERN PetscErrorCode SNESMultiblockSetIS(SNES, const char[], IS);
1162: PETSC_EXTERN PetscErrorCode SNESMultiblockSetBlockSize(SNES, PetscInt);
1163: PETSC_EXTERN PetscErrorCode SNESMultiblockSetType(SNES, PCCompositeType);
1164: PETSC_EXTERN PetscErrorCode SNESMultiblockGetSubSNES(SNES, PetscInt *, SNES *[]);
1166: /*J
1167: SNESMSType - String with the name of a PETSc `SNESMS` method.
1169: Level: intermediate
1171: .seealso: [](ch_snes), `SNESMS`, `SNESMSGetType()`, `SNESMSSetType()`, `SNES`
1172: J*/
1173: typedef const char *SNESMSType;
1174: #define SNESMSM62 "m62"
1175: #define SNESMSEULER "euler"
1176: #define SNESMSJAMESON83 "jameson83"
1177: #define SNESMSVLTP11 "vltp11"
1178: #define SNESMSVLTP21 "vltp21"
1179: #define SNESMSVLTP31 "vltp31"
1180: #define SNESMSVLTP41 "vltp41"
1181: #define SNESMSVLTP51 "vltp51"
1182: #define SNESMSVLTP61 "vltp61"
1184: PETSC_EXTERN PetscErrorCode SNESMSRegister(SNESMSType, PetscInt, PetscInt, PetscReal, const PetscReal[], const PetscReal[], const PetscReal[]);
1185: PETSC_EXTERN PetscErrorCode SNESMSRegisterAll(void);
1186: PETSC_EXTERN PetscErrorCode SNESMSGetType(SNES, SNESMSType *);
1187: PETSC_EXTERN PetscErrorCode SNESMSSetType(SNES, SNESMSType);
1188: PETSC_EXTERN PetscErrorCode SNESMSGetDamping(SNES, PetscReal *);
1189: PETSC_EXTERN PetscErrorCode SNESMSSetDamping(SNES, PetscReal);
1190: PETSC_EXTERN PetscErrorCode SNESMSFinalizePackage(void);
1191: PETSC_EXTERN PetscErrorCode SNESMSInitializePackage(void);
1192: PETSC_EXTERN PetscErrorCode SNESMSRegisterDestroy(void);
1194: /*MC
1195: SNESNGMRESRestartType - the restart approach used by `SNESNGMRES`
1197: Values:
1198: + `SNES_NGMRES_RESTART_NONE` - never restart
1199: . `SNES_NGMRES_RESTART_DIFFERENCE` - restart based upon difference criteria
1200: - `SNES_NGMRES_RESTART_PERIODIC` - restart after a fixed number of iterations
1202: Options Database Keys:
1203: + -snes_ngmres_restart_type (difference|periodic|none) - set the restart type
1204: - -snes_ngmres_restart 30 - sets the number of iterations before restart for periodic
1206: Level: intermediate
1208: .seealso: `SNES`, `SNESNGMRES`, `SNESNGMRESSetSelectType()`, `SNESNGMRESGetSelectType()`, `SNESNGMRESSetRestartType()`,
1209: `SNESNGMRESGetRestartType()`, `SNESNGMRESSelectType`
1210: M*/
1211: typedef enum {
1212: SNES_NGMRES_RESTART_NONE = 0,
1213: SNES_NGMRES_RESTART_PERIODIC = 1,
1214: SNES_NGMRES_RESTART_DIFFERENCE = 2
1215: } SNESNGMRESRestartType;
1216: PETSC_EXTERN const char *const SNESNGMRESRestartTypes[];
1218: /*MC
1219: SNESNGMRESSelectType - the approach used by `SNESNGMRES` to determine how the candidate solution and
1220: combined solution are used to create the next iterate.
1222: Values:
1223: + `SNES_NGMRES_SELECT_NONE` - choose the combined solution all the time
1224: . `SNES_NGMRES_SELECT_DIFFERENCE` - choose based upon the selection criteria
1225: - `SNES_NGMRES_SELECT_LINESEARCH` - choose based upon line search combination
1227: Options Database Key:
1228: . -snes_ngmres_select_type (difference|none|linesearch) - select how the next iterate is created
1230: Level: intermediate
1232: .seealso: `SNES`, `SNESNGMRES`, `SNESNGMRESSetSelectType()`, `SNESNGMRESGetSelectType()`, `SNESNGMRESSetRestartType()`,
1233: `SNESNGMRESGetRestartType()`, `SNESNGMRESRestartType`
1234: M*/
1235: typedef enum {
1236: SNES_NGMRES_SELECT_NONE = 0,
1237: SNES_NGMRES_SELECT_DIFFERENCE = 1,
1238: SNES_NGMRES_SELECT_LINESEARCH = 2
1239: } SNESNGMRESSelectType;
1240: PETSC_EXTERN const char *const SNESNGMRESSelectTypes[];
1242: PETSC_EXTERN PetscErrorCode SNESNGMRESSetRestartType(SNES, SNESNGMRESRestartType);
1243: PETSC_EXTERN PetscErrorCode SNESNGMRESSetSelectType(SNES, SNESNGMRESSelectType);
1244: PETSC_EXTERN PetscErrorCode SNESNGMRESSetRestartFmRise(SNES, PetscBool);
1245: PETSC_EXTERN PetscErrorCode SNESNGMRESGetRestartFmRise(SNES, PetscBool *);
1247: /*MC
1248: SNESNCGType - the conjugate update approach for `SNESNCG`
1250: Values:
1251: + `SNES_NCG_FR` - Fletcher-Reeves update
1252: . `SNES_NCG_PRP` - Polak-Ribiere-Polyak update, the default and the only one that tolerates generalized search directions
1253: . `SNES_NCG_HS` - Hestenes-Steifel update
1254: . `SNES_NCG_DY` - Dai-Yuan update
1255: - `SNES_NCG_CD` - Conjugate Descent update
1257: Options Database Key:
1258: . -snes_ncg_type (fr|prp|hs|dy|cd) - select the type
1260: Level: intermediate
1262: .seealso: `SNES`, `SNESNCG`, `SNESNCGSetType()`
1263: M*/
1264: typedef enum {
1265: SNES_NCG_FR = 0,
1266: SNES_NCG_PRP = 1,
1267: SNES_NCG_HS = 2,
1268: SNES_NCG_DY = 3,
1269: SNES_NCG_CD = 4
1270: } SNESNCGType;
1271: PETSC_EXTERN const char *const SNESNCGTypes[];
1273: PETSC_EXTERN PetscErrorCode SNESNCGSetType(SNES, SNESNCGType);
1275: /*MC
1276: SNESQNScaleType - the scaling type used by `SNESQN`
1278: Values:
1279: + `SNES_QN_SCALE_NONE` - don't scale the problem
1280: . `SNES_QN_SCALE_SCALAR` - use Shanno scaling
1281: . `SNES_QN_SCALE_DIAGONAL` - scale with a diagonalized BFGS formula (see Gilbert and Lemarechal 1989), available
1282: - `SNES_QN_SCALE_JACOBIAN` - scale by solving a linear system coming from the Jacobian you provided with `SNESSetJacobian()`
1283: computed at the first iteration of `SNESQN` and at ever restart.
1285: Options Database Key:
1286: . -snes_qn_scale_type (diagonal|none|scalar|jacobian) - Select the scaling type
1288: Level: intermediate
1290: .seealso: `SNES`, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNType`, `SNESQNSetType()`, `SNESQNSetRestartType()`, `SNESQNRestartType`
1291: M*/
1292: typedef enum {
1293: SNES_QN_SCALE_DEFAULT = 0,
1294: SNES_QN_SCALE_NONE = 1,
1295: SNES_QN_SCALE_SCALAR = 2,
1296: SNES_QN_SCALE_DIAGONAL = 3,
1297: SNES_QN_SCALE_JACOBIAN = 4
1298: } SNESQNScaleType;
1299: PETSC_EXTERN const char *const SNESQNScaleTypes[];
1301: /*MC
1302: SNESQNRestartType - the restart approached used by `SNESQN`
1304: Values:
1305: + `SNES_QN_RESTART_NONE` - never restart
1306: . `SNES_QN_RESTART_POWELL` - restart based upon descent criteria
1307: - `SNES_QN_RESTART_PERIODIC` - restart after a fixed number of iterations
1309: Options Database Keys:
1310: + -snes_qn_restart_type (powell|periodic|none) - set the restart type
1311: - -snes_qn_m m - sets the number of stored updates and the restart period for periodic
1313: Level: intermediate
1315: .seealso: `SNES`, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNType`, `SNESQNSetType()`, `SNESQNSetRestartType()`, `SNESQNScaleType`
1316: M*/
1317: typedef enum {
1318: SNES_QN_RESTART_DEFAULT = 0,
1319: SNES_QN_RESTART_NONE = 1,
1320: SNES_QN_RESTART_POWELL = 2,
1321: SNES_QN_RESTART_PERIODIC = 3
1322: } SNESQNRestartType;
1323: PETSC_EXTERN const char *const SNESQNRestartTypes[];
1325: /*MC
1326: SNESQNType - the type used by `SNESQN`
1328: Values:
1329: + `SNES_QN_LBFGS` - LBFGS variant
1330: . `SNES_QN_BROYDEN` - Broyden variant
1331: - `SNES_QN_BADBROYDEN` - Bad Broyden variant
1333: Options Database Key:
1334: . -snes_qn_type (lbfgs|broyden|badbroyden) - quasi-Newton type
1336: Level: intermediate
1338: .seealso: `SNES`, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNSetType()`, `SNESQNScaleType`, `SNESQNRestartType`, `SNESQNSetRestartType()`
1339: M*/
1340: typedef enum {
1341: SNES_QN_LBFGS = 0,
1342: SNES_QN_BROYDEN = 1,
1343: SNES_QN_BADBROYDEN = 2
1344: } SNESQNType;
1345: PETSC_EXTERN const char *const SNESQNTypes[];
1347: PETSC_EXTERN PetscErrorCode SNESQNSetType(SNES, SNESQNType);
1348: PETSC_EXTERN PetscErrorCode SNESQNSetScaleType(SNES, SNESQNScaleType);
1349: PETSC_EXTERN PetscErrorCode SNESQNSetRestartType(SNES, SNESQNRestartType);
1351: PETSC_EXTERN PetscErrorCode SNESNASMGetType(SNES, PCASMType *);
1352: PETSC_EXTERN PetscErrorCode SNESNASMSetType(SNES, PCASMType);
1353: PETSC_EXTERN PetscErrorCode SNESNASMGetSubdomains(SNES, PetscInt *, SNES *[], VecScatter *[], VecScatter *[], VecScatter *[]);
1354: PETSC_EXTERN PetscErrorCode SNESNASMSetSubdomains(SNES, PetscInt, SNES[], VecScatter[], VecScatter[], VecScatter[]);
1355: PETSC_EXTERN PetscErrorCode SNESNASMSetDamping(SNES, PetscReal);
1356: PETSC_EXTERN PetscErrorCode SNESNASMGetDamping(SNES, PetscReal *);
1357: PETSC_EXTERN PetscErrorCode SNESNASMGetSubdomainVecs(SNES, PetscInt *, Vec *[], Vec *[], Vec *[], Vec *[]);
1358: PETSC_EXTERN PetscErrorCode SNESNASMSetComputeFinalJacobian(SNES, PetscBool);
1359: PETSC_EXTERN PetscErrorCode SNESNASMGetSNES(SNES, PetscInt, SNES *);
1360: PETSC_EXTERN PetscErrorCode SNESNASMGetNumber(SNES, PetscInt *);
1361: PETSC_EXTERN PetscErrorCode SNESNASMSetWeight(SNES, Vec);
1363: /*E
1364: SNESCompositeType - Determines how two or more preconditioners are composed with the `SNESType` of `SNESCOMPOSITE`
1366: Values:
1367: + `SNES_COMPOSITE_ADDITIVE` - results from application of all preconditioners are added together
1368: . `SNES_COMPOSITE_MULTIPLICATIVE` - preconditioners are applied sequentially to the residual freshly
1369: computed after the previous preconditioner application
1370: - `SNES_COMPOSITE_ADDITIVEOPTIMAL` - uses a linear combination of the solutions obtained with each preconditioner that approximately minimize the function
1371: value at the new iteration.
1373: Level: beginner
1375: .seealso: [](sec_pc), `PCCOMPOSITE`, `PCFIELDSPLIT`, `PC`, `PCCompositeSetType()`, `PCCompositeType`
1376: E*/
1377: typedef enum {
1378: SNES_COMPOSITE_ADDITIVE,
1379: SNES_COMPOSITE_MULTIPLICATIVE,
1380: SNES_COMPOSITE_ADDITIVEOPTIMAL
1381: } SNESCompositeType;
1382: PETSC_EXTERN const char *const SNESCompositeTypes[];
1384: PETSC_EXTERN PetscErrorCode SNESCompositeSetType(SNES, SNESCompositeType);
1385: PETSC_EXTERN PetscErrorCode SNESCompositeAddSNES(SNES, SNESType);
1386: PETSC_EXTERN PetscErrorCode SNESCompositeGetSNES(SNES, PetscInt, SNES *);
1387: PETSC_EXTERN PetscErrorCode SNESCompositeGetNumber(SNES, PetscInt *);
1388: PETSC_EXTERN PetscErrorCode SNESCompositeSetDamping(SNES, PetscInt, PetscReal);
1390: PETSC_EXTERN PetscErrorCode SNESPatchSetDiscretisationInfo(SNES, PetscInt, DM[], PetscInt[], PetscInt[], const PetscInt **, const PetscInt[], PetscInt, const PetscInt[], PetscInt, const PetscInt[]);
1391: PETSC_EXTERN PetscErrorCode SNESPatchSetComputeOperator(SNES, PetscErrorCode (*func)(PC, PetscInt, Vec, Mat, IS, PetscInt, const PetscInt *, const PetscInt *, PetscCtx), PetscCtx);
1392: PETSC_EXTERN PetscErrorCode SNESPatchSetComputeFunction(SNES, PetscErrorCode (*func)(PC, PetscInt, Vec, Vec, IS, PetscInt, const PetscInt *, const PetscInt *, PetscCtx), PetscCtx);
1393: PETSC_EXTERN PetscErrorCode SNESPatchSetConstructType(SNES, PCPatchConstructType, PetscErrorCode (*func)(PC, PetscInt *, IS **, IS *, PetscCtx), PetscCtx);
1394: PETSC_EXTERN PetscErrorCode SNESPatchSetCellNumbering(SNES, PetscSection);
1396: /*E
1397: SNESFASType - Determines the type of nonlinear multigrid method that is run.
1399: Values:
1400: + `SNES_FAS_MULTIPLICATIVE` (default) - traditional V or W cycle as determined by `SNESFASSetCycles()`
1401: . `SNES_FAS_ADDITIVE` - additive FAS cycle
1402: . `SNES_FAS_FULL` - full FAS cycle
1403: - `SNES_FAS_KASKADE` - Kaskade FAS cycle
1405: Level: beginner
1407: .seealso: [](ch_snes), `SNESFAS`, `PCMGSetType()`, `PCMGType`
1408: E*/
1409: typedef enum {
1410: SNES_FAS_MULTIPLICATIVE,
1411: SNES_FAS_ADDITIVE,
1412: SNES_FAS_FULL,
1413: SNES_FAS_KASKADE
1414: } SNESFASType;
1415: PETSC_EXTERN const char *const SNESFASTypes[];
1417: /* called on the finest level FAS instance*/
1418: PETSC_EXTERN PetscErrorCode SNESFASSetType(SNES, SNESFASType);
1419: PETSC_EXTERN PetscErrorCode SNESFASGetType(SNES, SNESFASType *);
1420: PETSC_EXTERN PetscErrorCode SNESFASSetLevels(SNES, PetscInt, MPI_Comm *);
1421: PETSC_EXTERN PetscErrorCode SNESFASGetLevels(SNES, PetscInt *);
1422: PETSC_EXTERN PetscErrorCode SNESFASGetCycleSNES(SNES, PetscInt, SNES *);
1423: PETSC_EXTERN PetscErrorCode SNESFASSetNumberSmoothUp(SNES, PetscInt);
1424: PETSC_EXTERN PetscErrorCode SNESFASSetNumberSmoothDown(SNES, PetscInt);
1425: PETSC_EXTERN PetscErrorCode SNESFASSetCycles(SNES, PetscInt);
1426: PETSC_EXTERN PetscErrorCode SNESFASSetMonitor(SNES, PetscViewerAndFormat *, PetscBool);
1427: PETSC_EXTERN PetscErrorCode SNESFASSetLog(SNES, PetscBool);
1429: PETSC_EXTERN PetscErrorCode SNESFASSetGalerkin(SNES, PetscBool);
1430: PETSC_EXTERN PetscErrorCode SNESFASGetGalerkin(SNES, PetscBool *);
1431: PETSC_EXTERN PetscErrorCode SNESFASGalerkinFunctionDefault(SNES, Vec, Vec, PetscCtx);
1433: /* called on any level -- "Cycle" FAS instance */
1434: PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmoother(SNES, SNES *);
1435: PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmootherUp(SNES, SNES *);
1436: PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmootherDown(SNES, SNES *);
1437: PETSC_EXTERN PetscErrorCode SNESFASCycleGetCorrection(SNES, SNES *);
1438: PETSC_EXTERN PetscErrorCode SNESFASCycleGetInterpolation(SNES, Mat *);
1439: PETSC_EXTERN PetscErrorCode SNESFASCycleGetRestriction(SNES, Mat *);
1440: PETSC_EXTERN PetscErrorCode SNESFASCycleGetInjection(SNES, Mat *);
1441: PETSC_EXTERN PetscErrorCode SNESFASCycleGetRScale(SNES, Vec *);
1442: PETSC_EXTERN PetscErrorCode SNESFASCycleSetCycles(SNES, PetscInt);
1443: PETSC_EXTERN PetscErrorCode SNESFASCycleIsFine(SNES, PetscBool *);
1445: /* called on the (outer) finest level FAS to set/get parameters on any level instance */
1446: PETSC_EXTERN PetscErrorCode SNESFASSetInterpolation(SNES, PetscInt, Mat);
1447: PETSC_EXTERN PetscErrorCode SNESFASGetInterpolation(SNES, PetscInt, Mat *);
1448: PETSC_EXTERN PetscErrorCode SNESFASSetRestriction(SNES, PetscInt, Mat);
1449: PETSC_EXTERN PetscErrorCode SNESFASGetRestriction(SNES, PetscInt, Mat *);
1450: PETSC_EXTERN PetscErrorCode SNESFASSetInjection(SNES, PetscInt, Mat);
1451: PETSC_EXTERN PetscErrorCode SNESFASGetInjection(SNES, PetscInt, Mat *);
1452: PETSC_EXTERN PetscErrorCode SNESFASSetRScale(SNES, PetscInt, Vec);
1453: PETSC_EXTERN PetscErrorCode SNESFASGetRScale(SNES, PetscInt, Vec *);
1454: PETSC_EXTERN PetscErrorCode SNESFASSetContinuation(SNES, PetscBool);
1456: PETSC_EXTERN PetscErrorCode SNESFASGetSmoother(SNES, PetscInt, SNES *);
1457: PETSC_EXTERN PetscErrorCode SNESFASGetSmootherUp(SNES, PetscInt, SNES *);
1458: PETSC_EXTERN PetscErrorCode SNESFASGetSmootherDown(SNES, PetscInt, SNES *);
1459: PETSC_EXTERN PetscErrorCode SNESFASGetCoarseSolve(SNES, SNES *);
1460: PETSC_EXTERN PetscErrorCode SNESFASSetUseCoarseCorrectionLineSearch(SNES, PetscBool);
1461: PETSC_EXTERN PetscErrorCode SNESFASGetCoarseCorrectionLineSearch(SNES, PetscInt, SNESLineSearch *);
1463: /* parameters for full FAS */
1464: PETSC_EXTERN PetscErrorCode SNESFASFullSetDownSweep(SNES, PetscBool);
1465: PETSC_EXTERN PetscErrorCode SNESFASCreateCoarseVec(SNES, Vec *);
1466: PETSC_EXTERN PetscErrorCode SNESFASRestrict(SNES, Vec, Vec);
1467: PETSC_EXTERN PetscErrorCode SNESFASFullSetTotal(SNES, PetscBool);
1468: PETSC_EXTERN PetscErrorCode SNESFASFullGetTotal(SNES, PetscBool *);
1470: PETSC_EXTERN PetscErrorCode DMPlexSetSNESVariableBounds(DM, SNES);
1471: PETSC_EXTERN PetscErrorCode DMSNESCheckDiscretization(SNES, DM, PetscReal, Vec, PetscReal, PetscReal[]);
1472: PETSC_EXTERN PetscErrorCode DMSNESCheckResidual(SNES, DM, Vec, PetscReal, PetscReal *);
1473: PETSC_EXTERN PetscErrorCode DMSNESCheckJacobian(SNES, DM, Vec, PetscReal, PetscBool *, PetscReal *);
1474: PETSC_EXTERN PetscErrorCode DMSNESCheckFromOptions(SNES, Vec);
1475: PETSC_EXTERN PetscErrorCode DMSNESComputeJacobianAction(DM, Vec, Vec, Vec, PetscCtx);
1476: PETSC_EXTERN PetscErrorCode DMSNESCreateJacobianMF(DM, Vec, PetscCtx, Mat *);
1478: PETSC_EXTERN PetscErrorCode SNESNewtonALSetFunction(SNES, SNESFunctionFn *, PetscCtx);
1479: PETSC_EXTERN PetscErrorCode SNESNewtonALGetFunction(SNES, SNESFunctionFn **, PetscCtxRt);
1480: PETSC_EXTERN PetscErrorCode SNESNewtonALComputeFunction(SNES, Vec, Vec);
1481: PETSC_EXTERN PetscErrorCode SNESNewtonALGetLoadParameter(SNES, PetscReal *);
1482: PETSC_EXTERN PetscErrorCode SNESNewtonALSetDiagonalScaling(SNES snes, Vec v);
1484: /*MC
1485: SNESNewtonALCorrectionType - the approach used by `SNESNEWTONAL` to determine
1486: the correction to the current increment. While the exact correction satisfies
1487: the constraint surface at every iteration, it also requires solving a quadratic
1488: equation which may not have real roots. Conversely, the normal correction is more
1489: efficient and always yields a real correction and is the default.
1491: Values:
1492: + `SNES_NEWTONAL_CORRECTION_EXACT` - choose the correction which exactly satisfies the constraint
1493: - `SNES_NEWTONAL_CORRECTION_NORMAL` - choose the correction in the updated normal hyper-surface to the constraint surface
1495: Options Database Key:
1496: . -snes_newtonal_correction_type (exact|normal) - exactly satisfy the constraint or satisfy it on the normal hyper-surface
1498: Level: intermediate
1500: .seealso: `SNES`, `SNESNEWTONAL`, `SNESNewtonALSetCorrectionType()`
1501: M*/
1502: typedef enum {
1503: SNES_NEWTONAL_CORRECTION_EXACT = 0,
1504: SNES_NEWTONAL_CORRECTION_NORMAL = 1,
1505: } SNESNewtonALCorrectionType;
1506: PETSC_EXTERN const char *const SNESNewtonALCorrectionTypes[];
1508: PETSC_EXTERN PetscErrorCode SNESNewtonALSetCorrectionType(SNES, SNESNewtonALCorrectionType);