xref: /petsc/include/petscsnes.h (revision d728fb7dff1ad61d29df6dcab893bdd59c1da584)
1f26ada1bSBarry Smith /*
2eef9c623SLois Curfman McInnes     User interface for the nonlinear solvers package.
3f26ada1bSBarry Smith */
40a835dfdSSatish Balay #if !defined(__PETSCSNES_H)
50a835dfdSSatish Balay #define __PETSCSNES_H
62c8e378dSBarry Smith #include <petscksp.h>
71e25c274SJed Brown #include <petscdmtypes.h>
81e25c274SJed Brown #include <petscdmdatypes.h>
9b1f5cb9dSBarry Smith 
10435da068SBarry Smith /*S
11435da068SBarry Smith      SNES - Abstract PETSc object that manages all nonlinear solves
12435da068SBarry Smith 
13435da068SBarry Smith    Level: beginner
14435da068SBarry Smith 
15435da068SBarry Smith   Concepts: nonlinear solvers
16435da068SBarry Smith 
1794b7f48cSBarry Smith .seealso:  SNESCreate(), SNESSetType(), SNESType, TS, KSP, KSP, PC
18435da068SBarry Smith S*/
19f09e8eb9SSatish Balay typedef struct _p_SNES* SNES;
20435da068SBarry Smith 
2176bdecfbSBarry Smith /*J
22435da068SBarry Smith     SNESType - String with the name of a PETSc SNES method or the creation function
23435da068SBarry Smith        with an optional dynamic library name, for example
24435da068SBarry Smith        http://www.mcs.anl.gov/petsc/lib.a:mysnescreate()
25435da068SBarry Smith 
26435da068SBarry Smith    Level: beginner
27435da068SBarry Smith 
28435da068SBarry Smith .seealso: SNESSetType(), SNES
2976bdecfbSBarry Smith J*/
3019fd82e9SBarry Smith typedef const char* SNESType;
3104d7464bSBarry Smith #define SNESNEWTONLS     "newtonls"
3204d7464bSBarry Smith #define SNESNEWTONTR     "newtontr"
331d6018f0SLisandro Dalcin #define SNESPYTHON       "python"
34eef9c623SLois Curfman McInnes #define SNESTEST         "test"
35d5c3842bSBarry Smith #define SNESNRICHARDSON  "nrichardson"
36b79b07cfSJed Brown #define SNESKSPONLY      "ksponly"
37f450aa47SBarry Smith #define SNESVINEWTONRSLS "vinewtonrsls"
38f450aa47SBarry Smith #define SNESVINEWTONSSLS "vinewtonssls"
394a0c5b0cSMatthew G Knepley #define SNESNGMRES       "ngmres"
404b11644fSPeter Brune #define SNESQN           "qn"
41c5ae4b9aSBarry Smith #define SNESSHELL        "shell"
423542a6bcSPeter Brune #define SNESGS           "gs"
43fef7b6d8SPeter Brune #define SNESNCG          "ncg"
44421d9b32SPeter Brune #define SNESFAS          "fas"
4537e1895aSJed Brown #define SNESMS           "ms"
46eaedb033SPeter Brune #define SNESNASM         "nasm"
47f31c9d25SPeter Brune #define SNESANDERSON     "anderson"
48*d728fb7dSPeter Brune #define SNESASPIN        "aspin"
49d5c3842bSBarry Smith 
50deeb6e72SMatthew Knepley /* Logging support */
51014dd563SJed Brown PETSC_EXTERN PetscClassId SNES_CLASSID;
5222c6f798SBarry Smith PETSC_EXTERN PetscClassId DMSNES_CLASSID;
53deeb6e72SMatthew Knepley 
54014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESInitializePackage(const char[]);
55deeb6e72SMatthew Knepley 
56014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESCreate(MPI_Comm,SNES*);
57014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESReset(SNES);
58014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESDestroy(SNES*);
5919fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetType(SNES,SNESType);
60014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitor(SNES,PetscInt,PetscReal);
61014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorSet(SNES,PetscErrorCode(*)(SNES,PetscInt,PetscReal,void*),void *,PetscErrorCode (*)(void**));
62014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorCancel(SNES);
63014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetConvergenceHistory(SNES,PetscReal[],PetscInt[],PetscInt,PetscBool );
64014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetConvergenceHistory(SNES,PetscReal*[],PetscInt *[],PetscInt *);
65014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetUp(SNES);
66014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSolve(SNES,Vec,Vec);
67014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetErrorIfNotConverged(SNES,PetscBool );
68014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetErrorIfNotConverged(SNES,PetscBool  *);
69e113a28aSBarry Smith 
7084cb2905SBarry Smith 
71014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESAddOptionsChecker(PetscErrorCode (*)(SNES));
724d8f6ca9SMatthew Knepley 
73014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetUpdate(SNES, PetscErrorCode (*)(SNES, PetscInt));
74014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESDefaultUpdate(SNES, PetscInt);
754d8f6ca9SMatthew Knepley 
76014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESRegisterDestroy(void);
77014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESRegisterAll(const char[]);
7884cb2905SBarry Smith 
79014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESRegister(const char[],const char[],const char[],PetscErrorCode (*)(SNES));
8030de9b25SBarry Smith 
8130de9b25SBarry Smith /*MC
8230de9b25SBarry Smith    SNESRegisterDynamic - Adds a method to the nonlinear solver package.
8330de9b25SBarry Smith 
8430de9b25SBarry Smith    Synopsis:
85f2ba6396SBarry Smith     #include "petscsnes.h"
861890ba74SBarry Smith    PetscErrorCode SNESRegisterDynamic(const char *name_solver,const char *path,const char *name_create,PetscErrorCode (*routine_create)(SNES))
8730de9b25SBarry Smith 
8830de9b25SBarry Smith    Not collective
8930de9b25SBarry Smith 
9030de9b25SBarry Smith    Input Parameters:
9130de9b25SBarry Smith +  name_solver - name of a new user-defined solver
9230de9b25SBarry Smith .  path - path (either absolute or relative) the library containing this solver
9330de9b25SBarry Smith .  name_create - name of routine to create method context
9430de9b25SBarry Smith -  routine_create - routine to create method context
9530de9b25SBarry Smith 
9630de9b25SBarry Smith    Notes:
9730de9b25SBarry Smith    SNESRegisterDynamic() may be called multiple times to add several user-defined solvers.
9830de9b25SBarry Smith 
9930de9b25SBarry Smith    If dynamic libraries are used, then the fourth input argument (routine_create)
10030de9b25SBarry Smith    is ignored.
10130de9b25SBarry Smith 
102ab901514SBarry Smith    Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR},
10330de9b25SBarry Smith    and others of the form ${any_environmental_variable} occuring in pathname will be
10430de9b25SBarry Smith    replaced with appropriate values.
10530de9b25SBarry Smith 
10630de9b25SBarry Smith    Sample usage:
10730de9b25SBarry Smith .vb
10830de9b25SBarry Smith    SNESRegisterDynamic("my_solver",/home/username/my_lib/lib/libg/solaris/mylib.a,
10930de9b25SBarry Smith                 "MySolverCreate",MySolverCreate);
11030de9b25SBarry Smith .ve
11130de9b25SBarry Smith 
11230de9b25SBarry Smith    Then, your solver can be chosen with the procedural interface via
11330de9b25SBarry Smith $     SNESSetType(snes,"my_solver")
11430de9b25SBarry Smith    or at runtime via the option
11530de9b25SBarry Smith $     -snes_type my_solver
11630de9b25SBarry Smith 
11730de9b25SBarry Smith    Level: advanced
11830de9b25SBarry Smith 
11930de9b25SBarry Smith     Note: If your function is not being put into a shared library then use SNESRegister() instead
12030de9b25SBarry Smith 
12130de9b25SBarry Smith .keywords: SNES, nonlinear, register
12230de9b25SBarry Smith 
12330de9b25SBarry Smith .seealso: SNESRegisterAll(), SNESRegisterDestroy()
12430de9b25SBarry Smith M*/
125aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
126f1af5d2fSBarry Smith #define SNESRegisterDynamic(a,b,c,d) SNESRegister(a,b,c,0)
127b2002411SLois Curfman McInnes #else
128f1af5d2fSBarry Smith #define SNESRegisterDynamic(a,b,c,d) SNESRegister(a,b,c,d)
129b2002411SLois Curfman McInnes #endif
130b2002411SLois Curfman McInnes 
131014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetKSP(SNES,KSP*);
132014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetKSP(SNES,KSP);
133014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetSolution(SNES,Vec*);
134014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetSolutionUpdate(SNES,Vec*);
135014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetRhs(SNES,Vec*);
136014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESView(SNES,PetscViewer);
13755849f57SBarry Smith PETSC_EXTERN PetscErrorCode SNESLoad(SNES,PetscViewer);
13855849f57SBarry Smith 
13955849f57SBarry Smith #define SNES_FILE_CLASSID 1211224
1407bc3d0afSSatish Balay 
141014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetOptionsPrefix(SNES,const char[]);
142014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESAppendOptionsPrefix(SNES,const char[]);
143014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetOptionsPrefix(SNES,const char*[]);
144014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetFromOptions(SNES);
145014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESDefaultGetWork(SNES,PetscInt);
14640191667SLois Curfman McInnes 
147014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSNESMF(SNES,Mat*);
148014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatMFFDComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
1498f6e3e37SBarry Smith 
150014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatDAADSetSNES(Mat,SNES);
1513a7fca6bSBarry Smith 
15219fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetType(SNES,SNESType*);
153014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorDefault(SNES,PetscInt,PetscReal,void *);
154014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorRange(SNES,PetscInt,PetscReal,void *);
155014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorRatio(SNES,PetscInt,PetscReal,void *);
156014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorSetRatio(SNES,PetscViewer);
157014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorSolution(SNES,PetscInt,PetscReal,void *);
158014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorResidual(SNES,PetscInt,PetscReal,void *);
159014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorSolutionUpdate(SNES,PetscInt,PetscReal,void *);
160014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorDefaultShort(SNES,PetscInt,PetscReal,void *);
1612e7541e6SPeter Brune PETSC_EXTERN PetscErrorCode SNESMonitorJacUpdateSpectrum(SNES,PetscInt,PetscReal,void *);
162014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetTolerances(SNES,PetscReal,PetscReal,PetscReal,PetscInt,PetscInt);
163014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetTolerances(SNES,PetscReal*,PetscReal*,PetscReal*,PetscInt*,PetscInt*);
164014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetTrustRegionTolerance(SNES,PetscReal);
165014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetFunctionNorm(SNES,PetscReal*);
166014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetFunctionNorm(SNES,PetscReal);
167014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetIterationNumber(SNES,PetscInt*);
168014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetIterationNumber(SNES,PetscInt);
1693d4c4710SBarry Smith 
170014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetNonlinearStepFailures(SNES,PetscInt*);
171014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetMaxNonlinearStepFailures(SNES,PetscInt);
172014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetMaxNonlinearStepFailures(SNES,PetscInt*);
173014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetNumberFunctionEvals(SNES,PetscInt*);
174b850b91aSLisandro Dalcin 
175014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetLagPreconditioner(SNES,PetscInt);
176014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLagPreconditioner(SNES,PetscInt*);
177014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetLagJacobian(SNES,PetscInt);
178014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLagJacobian(SNES,PetscInt*);
179014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetGridSequence(SNES,PetscInt);
180a8054027SBarry Smith 
181014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLinearSolveIterations(SNES,PetscInt*);
182014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLinearSolveFailures(SNES,PetscInt*);
183014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetMaxLinearSolveFailures(SNES,PetscInt);
184014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetMaxLinearSolveFailures(SNES,PetscInt*);
1853d4c4710SBarry Smith 
186014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESKSPSetUseEW(SNES,PetscBool );
187014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESKSPGetUseEW(SNES,PetscBool *);
188014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESKSPSetParametersEW(SNES,PetscInt,PetscReal,PetscReal,PetscReal,PetscReal,PetscReal,PetscReal);
189014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESKSPGetParametersEW(SNES,PetscInt*,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscReal*);
190eafb4bcbSBarry Smith 
1919804daf3SBarry Smith #include <petscdrawtypes.h>
192014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorLGCreate(const char[],const char[],int,int,int,int,PetscDrawLG*);
1934619e776SBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorLGResidualNorm(SNES,PetscInt,PetscReal,void*);
194014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorLGDestroy(PetscDrawLG*);
195014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorLGRange(SNES,PetscInt,PetscReal,void*);
196eafb4bcbSBarry Smith 
197014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetApplicationContext(SNES,void *);
198014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetApplicationContext(SNES,void *);
199014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetComputeApplicationContext(SNES,PetscErrorCode (*)(SNES,void**),PetscErrorCode (*)(void**));
200184914b5SBarry Smith 
201014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESPythonSetType(SNES,const char[]);
2021d6018f0SLisandro Dalcin 
203014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetFunctionDomainError(SNES);
204014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetFunctionDomainError(SNES, PetscBool *);
2056a388c36SPeter Brune 
206435da068SBarry Smith /*E
207435da068SBarry Smith     SNESConvergedReason - reason a SNES method was said to
208435da068SBarry Smith          have converged or diverged
209435da068SBarry Smith 
210435da068SBarry Smith    Level: beginner
211435da068SBarry Smith 
212f203c74bSBarry Smith    The two most common reasons for divergence are
213f203c74bSBarry Smith $   1) an incorrectly coded or computed Jacobian or
214f203c74bSBarry Smith $   2) failure or lack of convergence in the linear system (in this case we recommend
215f203c74bSBarry Smith $      testing with -pc_type lu to eliminate the linear solver as the cause of the problem).
216f203c74bSBarry Smith 
217f203c74bSBarry Smith    Diverged Reasons:
218f203c74bSBarry Smith .    SNES_DIVERGED_LOCAL_MIN - this can only occur when using the line-search variant of SNES.
219f203c74bSBarry Smith        The line search wants to minimize Q(alpha) = 1/2 || F(x + alpha s) ||^2_2  this occurs
220f203c74bSBarry Smith        at Q'(alpha) = s^T F'(x+alpha s)^T F(x+alpha s) = 0. If s is the Newton direction - F'(x)^(-1)F(x) then
221f203c74bSBarry Smith        you get Q'(alpha) = -F(x)^T F'(x)^(-1)^T F'(x+alpha s)F(x+alpha s); when alpha = 0
222f203c74bSBarry Smith        Q'(0) = - ||F(x)||^2_2 which is always NEGATIVE if F'(x) is invertible. This means the Newton
223f203c74bSBarry Smith        direction is a descent direction and the line search should succeed if alpha is small enough.
224f203c74bSBarry Smith 
225f203c74bSBarry Smith        If F'(x) is NOT invertible AND F'(x)^T F(x) = 0 then Q'(0) = 0 and the Newton direction
226f203c74bSBarry Smith        is NOT a descent direction so the line search will fail. All one can do at this point
227f203c74bSBarry Smith        is change the initial guess and try again.
228f203c74bSBarry Smith 
229f203c74bSBarry Smith        An alternative explanation: Newton's method can be regarded as replacing the function with
230f203c74bSBarry Smith        its linear approximation and minimizing the 2-norm of that. That is F(x+s) approx F(x) + F'(x)s
231f203c74bSBarry Smith        so we minimize || F(x) + F'(x) s ||^2_2; do this using Least Squares. If F'(x) is invertible then
232f203c74bSBarry Smith        s = - F'(x)^(-1)F(x) otherwise F'(x)^T F'(x) s = -F'(x)^T F(x). If F'(x)^T F(x) is NOT zero then there
233f203c74bSBarry Smith        exists a nontrival (that is F'(x)s != 0) solution to the equation and this direction is
234f203c74bSBarry Smith        s = - [F'(x)^T F'(x)]^(-1) F'(x)^T F(x) so Q'(0) = - F(x)^T F'(x) [F'(x)^T F'(x)]^(-T) F'(x)^T F(x)
235f203c74bSBarry Smith        = - (F'(x)^T F(x)) [F'(x)^T F'(x)]^(-T) (F'(x)^T F(x)). Since we are assuming (F'(x)^T F(x)) != 0
236f203c74bSBarry Smith        and F'(x)^T F'(x) has no negative eigenvalues Q'(0) < 0 so s is a descent direction and the line
237f203c74bSBarry Smith        search should succeed for small enough alpha.
238f203c74bSBarry Smith 
239f203c74bSBarry Smith        Note that this RARELY happens in practice. Far more likely the linear system is not being solved
240f203c74bSBarry Smith        (well enough?) or the Jacobian is wrong.
241f203c74bSBarry Smith 
2424d0a8057SBarry Smith    SNES_DIVERGED_MAX_IT means that the solver reached the maximum number of iterations without satisfying any
2434d0a8057SBarry Smith    convergence criteria. SNES_CONVERGED_ITS means that SNESSkipConverged() was chosen as the convergence test;
2444d0a8057SBarry Smith    thus the usual convergence criteria have not been checked and may or may not be satisfied.
245f203c74bSBarry Smith 
2464d0a8057SBarry Smith    Developer Notes: this must match finclude/petscsnes.h
2474d0a8057SBarry Smith 
2484d0a8057SBarry Smith        The string versions of these are in SNESConvergedReason, if you change any value here you must
2494d0a8057SBarry Smith      also adjust that array.
2505968eb51SBarry Smith 
25146a9e3ceSBarry Smith    Each reason has its own manual page.
25246a9e3ceSBarry Smith 
253435da068SBarry Smith .seealso: SNESSolve(), SNESGetConvergedReason(), KSPConvergedReason, SNESSetConvergenceTest()
254435da068SBarry Smith E*/
255184914b5SBarry Smith typedef enum {/* converged */
25601b82886SBarry Smith               SNES_CONVERGED_FNORM_ABS         =  2, /* ||F|| < atol */
25701b82886SBarry Smith               SNES_CONVERGED_FNORM_RELATIVE    =  3, /* ||F|| < rtol*||F_initial|| */
2585358d0d4SBarry Smith               SNES_CONVERGED_SNORM_RELATIVE    =  4, /* Newton computed step size small; || delta x || < stol || x ||*/
2593f149594SLisandro Dalcin               SNES_CONVERGED_ITS               =  5, /* maximum iterations reached */
260184914b5SBarry Smith               SNES_CONVERGED_TR_DELTA          =  7,
261184914b5SBarry Smith               /* diverged */
26246a9e3ceSBarry Smith               SNES_DIVERGED_FUNCTION_DOMAIN     = -1, /* the new x location passed the function is not in the domain of F */
263184914b5SBarry Smith               SNES_DIVERGED_FUNCTION_COUNT      = -2,
26446a9e3ceSBarry Smith               SNES_DIVERGED_LINEAR_SOLVE        = -3, /* the linear solve failed */
265184914b5SBarry Smith               SNES_DIVERGED_FNORM_NAN           = -4,
266184914b5SBarry Smith               SNES_DIVERGED_MAX_IT              = -5,
267647a2e1fSBarry Smith               SNES_DIVERGED_LINE_SEARCH         = -6, /* the line search failed */
2681e633543SBarry Smith               SNES_DIVERGED_INNER               = -7, /* inner solve failed */
26958c775ebSBarry Smith               SNES_DIVERGED_LOCAL_MIN           = -8, /* || J^T b || is small, implies converged to local minimum of F() */
270184914b5SBarry Smith               SNES_CONVERGED_ITERATING          =  0} SNESConvergedReason;
271014dd563SJed Brown PETSC_EXTERN const char *const*SNESConvergedReasons;
272184914b5SBarry Smith 
273c838673bSBarry Smith /*MC
274c838673bSBarry Smith      SNES_CONVERGED_FNORM_ABS - 2-norm(F) <= abstol
275c838673bSBarry Smith 
276c838673bSBarry Smith    Level: beginner
277c838673bSBarry Smith 
278c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
279c838673bSBarry Smith 
280c838673bSBarry Smith M*/
281c838673bSBarry Smith 
282c838673bSBarry Smith /*MC
283c838673bSBarry Smith      SNES_CONVERGED_FNORM_RELATIVE - 2-norm(F) <= rtol*2-norm(F(x_0)) where x_0 is the initial guess
284c838673bSBarry Smith 
285c838673bSBarry Smith    Level: beginner
286c838673bSBarry Smith 
287c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
288c838673bSBarry Smith 
289c838673bSBarry Smith M*/
290c838673bSBarry Smith 
291c838673bSBarry Smith /*MC
292c60f73f4SPeter Brune      SNES_CONVERGED_SNORM_RELATIVE - The 2-norm of the last step <= stol * 2-norm(x) where x is the current
29346a9e3ceSBarry Smith           solution and stol is the 4th argument to SNESSetTolerances()
294c838673bSBarry Smith 
295ae9be289SBarry Smith      Options Database Keys:
296ae9be289SBarry Smith       -snes_stol <stol> - the step tolerance
297ae9be289SBarry Smith 
298c838673bSBarry Smith    Level: beginner
299c838673bSBarry Smith 
300c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
301c838673bSBarry Smith 
302c838673bSBarry Smith M*/
303c838673bSBarry Smith 
304c838673bSBarry Smith /*MC
305c838673bSBarry Smith      SNES_DIVERGED_FUNCTION_COUNT - The user provided function has been called more times then the final
306c838673bSBarry Smith          argument to SNESSetTolerances()
307c838673bSBarry Smith 
308c838673bSBarry Smith    Level: beginner
309c838673bSBarry Smith 
310c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
311c838673bSBarry Smith 
312c838673bSBarry Smith M*/
313c838673bSBarry Smith 
314c838673bSBarry Smith /*MC
315c838673bSBarry Smith      SNES_DIVERGED_FNORM_NAN - the 2-norm of the current function evaluation is not-a-number (NaN), this
316c838673bSBarry Smith       is usually caused by a division of 0 by 0.
317c838673bSBarry Smith 
318c838673bSBarry Smith    Level: beginner
319c838673bSBarry Smith 
320c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
321c838673bSBarry Smith 
322c838673bSBarry Smith M*/
323c838673bSBarry Smith 
324c838673bSBarry Smith /*MC
325c838673bSBarry Smith      SNES_DIVERGED_MAX_IT - SNESSolve() has reached the maximum number of iterations requested
326c838673bSBarry Smith 
327c838673bSBarry Smith    Level: beginner
328c838673bSBarry Smith 
329c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
330c838673bSBarry Smith 
331c838673bSBarry Smith M*/
332c838673bSBarry Smith 
333c838673bSBarry Smith /*MC
33404d7464bSBarry Smith      SNES_DIVERGED_LINE_SEARCH - The line search has failed. This only occurs for a SNES solvers that use a line search
335c838673bSBarry Smith 
336c838673bSBarry Smith    Level: beginner
337c838673bSBarry Smith 
33804d7464bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances(), SNESLineSearch
339c838673bSBarry Smith 
340c838673bSBarry Smith M*/
341c838673bSBarry Smith 
342c838673bSBarry Smith /*MC
34346a9e3ceSBarry Smith      SNES_DIVERGED_LOCAL_MIN - the algorithm seems to have stagnated at a local minimum that is not zero.
34446a9e3ceSBarry Smith         See the manual page for SNESConvergedReason for more details
345c838673bSBarry Smith 
346c838673bSBarry Smith    Level: beginner
347c838673bSBarry Smith 
348c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
349c838673bSBarry Smith 
350c838673bSBarry Smith M*/
351c838673bSBarry Smith 
352c838673bSBarry Smith /*MC
353c838673bSBarry Smith      SNES_CONERGED_ITERATING - this only occurs if SNESGetConvergedReason() is called during the SNESSolve()
354c838673bSBarry Smith 
355c838673bSBarry Smith    Level: beginner
356c838673bSBarry Smith 
357c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
358c838673bSBarry Smith 
359c838673bSBarry Smith M*/
360c838673bSBarry Smith 
361014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetConvergenceTest(SNES,PetscErrorCode (*)(SNES,PetscInt,PetscReal,PetscReal,PetscReal,SNESConvergedReason*,void*),void*,PetscErrorCode (*)(void*));
362014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESDefaultConverged(SNES,PetscInt,PetscReal,PetscReal,PetscReal,SNESConvergedReason*,void*);
363014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSkipConverged(SNES,PetscInt,PetscReal,PetscReal,PetscReal,SNESConvergedReason*,void*);
364014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetConvergedReason(SNES,SNESConvergedReason*);
365ddbbdb52SLois Curfman McInnes 
366014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESDMMeshComputeFunction(SNES,Vec,Vec,void*);
367014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESDMMeshComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
36811f088b5SMatthew G Knepley 
369b67197daSBarry Smith /* --------- Solving systems of nonlinear equations --------------- */
370bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode SNESSetFunction(SNES,Vec,PetscErrorCode (*SNESFunction)(SNES,Vec,Vec,void*),void*);
371bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode SNESGetFunction(SNES,Vec*,PetscErrorCode (**SNESFunction)(SNES,Vec,Vec,void*),void**);
372014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESComputeFunction(SNES,Vec,Vec);
373bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode SNESSetJacobian(SNES,Mat,Mat,PetscErrorCode (*SNESJacobianFunction)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void*);
374bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode SNESGetJacobian(SNES,Mat*,Mat*,PetscErrorCode (**SNESJacobianFunction)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void**);
37597584545SPeter Brune PETSC_EXTERN PetscErrorCode SNESDefaultObjectiveComputeFunctionFD(SNES,Vec,Vec,void*);
376014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESDefaultComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
377014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESDefaultComputeJacobianColor(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
378014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetComputeInitialGuess(SNES,PetscErrorCode (*)(SNES,Vec,void*),void*);
379bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode SNESSetPicard(SNES,Vec,PetscErrorCode (*SNESFunction)(SNES,Vec,Vec,void*),Mat,Mat,PetscErrorCode (*SNESJacobianFunction)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void*);
380bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode SNESGetPicard(SNES,Vec*,PetscErrorCode (**SNESFunction)(SNES,Vec,Vec,void*),Mat*,Mat*,PetscErrorCode (**SNESJacobianFunction)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void**);
381014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetInitialFunction(SNES,Vec);
382014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetInitialFunctionNorm(SNES,PetscReal);
38317bae607SBarry Smith 
384075cc632SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetObjective(SNES,PetscErrorCode (*SNESObjectiveFunction)(SNES,Vec,PetscReal *,void*),void*);
385075cc632SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetObjective(SNES,PetscErrorCode (**SNESObjectiveFunction)(SNES,Vec,PetscReal *,void*),void**);
3862a4ee8f2SPeter Brune PETSC_EXTERN PetscErrorCode SNESComputeObjective(SNES,Vec,PetscReal *);
3872a4ee8f2SPeter Brune 
388534ebe21SPeter Brune /*E
389534ebe21SPeter Brune     SNESNormType - Norm that is passed in the Krylov convergence
390534ebe21SPeter Brune        test routines.
391534ebe21SPeter Brune 
392534ebe21SPeter Brune    Level: advanced
393534ebe21SPeter Brune 
394534ebe21SPeter Brune    Support for these is highly dependent on the solver.
395534ebe21SPeter Brune 
396534ebe21SPeter Brune    Notes:
397534ebe21SPeter Brune    This is primarily used to turn off extra norm and function computation
398534ebe21SPeter Brune    when the solvers are composed.
399534ebe21SPeter Brune 
400534ebe21SPeter Brune .seealso: SNESSolve(), SNESGetConvergedReason(), KSPSetNormType(),
401534ebe21SPeter Brune           KSPSetConvergenceTest(), KSPSetPCSide()
402534ebe21SPeter Brune E*/
403534ebe21SPeter Brune 
404534ebe21SPeter Brune typedef enum {SNES_NORM_DEFAULT            = -1,
405fdacfa88SPeter Brune               SNES_NORM_NONE               =  0,
406fdacfa88SPeter Brune               SNES_NORM_FUNCTION           =  1,
407fdacfa88SPeter Brune               SNES_NORM_INITIAL_ONLY       =  2,
408fdacfa88SPeter Brune               SNES_NORM_FINAL_ONLY         =  3,
409fdacfa88SPeter Brune               SNES_NORM_INITIAL_FINAL_ONLY =  4} SNESNormType;
410014dd563SJed Brown PETSC_EXTERN const char *const*const SNESNormTypes;
411534ebe21SPeter Brune /*MC
412fdacfa88SPeter Brune     SNES_NORM_NONE - Don't compute function and its L2 norm.
413534ebe21SPeter Brune 
414534ebe21SPeter Brune    Level: advanced
415534ebe21SPeter Brune 
416534ebe21SPeter Brune     Notes:
417534ebe21SPeter Brune     This is most useful for stationary solvers with a fixed number of iterations used as smoothers.
418534ebe21SPeter Brune 
419534ebe21SPeter Brune .seealso: SNESNormType, SNESSetNormType(), SNES_NORM_DEFAULT
420534ebe21SPeter Brune M*/
421534ebe21SPeter Brune 
422fdacfa88SPeter Brune /*MC
423fdacfa88SPeter Brune     SNES_NORM_FUNCTION - Compute the function and its L2 norm at each iteration.
424534ebe21SPeter Brune 
425fdacfa88SPeter Brune    Level: advanced
426fdacfa88SPeter Brune 
427fdacfa88SPeter Brune     Notes:
428fdacfa88SPeter Brune     Most solvers will use this no matter what norm type is passed to them.
429fdacfa88SPeter Brune 
430fdacfa88SPeter Brune .seealso: SNESNormType, SNESSetNormType(), SNES_NORM_NONE
431fdacfa88SPeter Brune M*/
432534ebe21SPeter Brune 
433534ebe21SPeter Brune /*MC
434534ebe21SPeter Brune     SNES_NORM_INITIAL_ONLY - Compute the function and its L2 at iteration 0, but do not update it.
435534ebe21SPeter Brune 
436534ebe21SPeter Brune    Level: advanced
437534ebe21SPeter Brune 
438534ebe21SPeter Brune    Notes:
439534ebe21SPeter Brune    This method is useful in composed methods, when a true solution might actually be found before SNESSolve() is called.
440534ebe21SPeter Brune    This option enables the solve to abort on the zeroth iteration if this is the case.
441534ebe21SPeter Brune 
442534ebe21SPeter Brune    For solvers that require the computation of the L2 norm of the function as part of the method, this merely cancels
443534ebe21SPeter Brune    the norm computation at the last iteration (if possible).
444534ebe21SPeter Brune 
445534ebe21SPeter Brune .seealso: SNESNormType, SNESSetNormType(), SNES_NORM_FINAL_ONLY, SNES_NORM_INITIAL_FINAL_ONLY
446534ebe21SPeter Brune M*/
447534ebe21SPeter Brune 
448534ebe21SPeter Brune /*MC
449534ebe21SPeter Brune     SNES_NORM_FINAL_ONLY - Compute the function and its L2 norm on only the final iteration.
450534ebe21SPeter Brune 
451534ebe21SPeter Brune    Level: advanced
452534ebe21SPeter Brune 
453534ebe21SPeter Brune    Notes:
454534ebe21SPeter Brune    For solvers that require the computation of the L2 norm of the function as part of the method, behaves
455534ebe21SPeter Brune    exactly as SNES_NORM_DEFAULT.  This method is useful when the function is gotten after SNESSolve and
456534ebe21SPeter Brune    used in subsequent computation for methods that do not need the norm computed during the rest of the
457534ebe21SPeter Brune    solution procedure.
458534ebe21SPeter Brune 
459534ebe21SPeter Brune .seealso: SNESNormType, SNESSetNormType(), SNES_NORM_INITIAL_ONLY, SNES_NORM_INITIAL_FINAL_ONLY
460534ebe21SPeter Brune M*/
461534ebe21SPeter Brune 
462534ebe21SPeter Brune /*MC
463534ebe21SPeter Brune     SNES_NORM_INITIAL_FINAL_ONLY - Compute the function and its L2 norm on only the initial and final iterations.
464534ebe21SPeter Brune 
465534ebe21SPeter Brune    Level: advanced
466534ebe21SPeter Brune 
467534ebe21SPeter Brune    Notes:
468534ebe21SPeter Brune    This method combines the benefits of SNES_NORM_INITIAL_ONLY and SNES_NORM_FINAL_ONLY.
469534ebe21SPeter Brune 
470534ebe21SPeter Brune .seealso: SNESNormType, SNESSetNormType(), SNES_NORM_SNES_NORM_INITIAL_ONLY, SNES_NORM_FINAL_ONLY
471534ebe21SPeter Brune M*/
472534ebe21SPeter Brune 
473534ebe21SPeter Brune 
474014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetNormType(SNES,SNESNormType);
475014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetNormType(SNES,SNESNormType*);
476534ebe21SPeter Brune 
477bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode SNESSetGS(SNES,PetscErrorCode (*SNESGSFunction)(SNES,Vec,Vec,void*),void*);
478bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode SNESGetGS(SNES,PetscErrorCode (**SNESGSFunction)(SNES,Vec,Vec,void*),void**);
479014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetUseGS(SNES,PetscBool);
480014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetUseGS(SNES,PetscBool *);
481b6266c6eSPeter Brune PETSC_EXTERN PetscErrorCode SNESComputeGS(SNES,Vec,Vec);
482b6266c6eSPeter Brune 
4836cd56b8bSPeter Brune PETSC_EXTERN PetscErrorCode SNESGSSetSweeps(SNES,PetscInt);
4846cd56b8bSPeter Brune PETSC_EXTERN PetscErrorCode SNESGSGetSweeps(SNES,PetscInt *);
485b6266c6eSPeter Brune PETSC_EXTERN PetscErrorCode SNESGSSetTolerances(SNES,PetscReal,PetscReal,PetscReal,PetscInt);
486b6266c6eSPeter Brune PETSC_EXTERN PetscErrorCode SNESGSGetTolerances(SNES,PetscReal*,PetscReal*,PetscReal*,PetscInt*);
487646217ecSPeter Brune 
4885341784dSBarry Smith PETSC_EXTERN PetscErrorCode SNESUpdateCheckJacobian(SNES,PetscInt);
4895341784dSBarry Smith 
490014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESShellGetContext(SNES,void**);
491014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESShellSetContext(SNES,void*);
492014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESShellSetSolve(SNES,PetscErrorCode (*)(SNES,Vec));
493c5ae4b9aSBarry Smith 
494872b6db9SPeter Brune /* --------- Routines specifically for line search methods --------------- */
495872b6db9SPeter Brune 
496f1c6b773SPeter Brune typedef struct _p_LineSearch* SNESLineSearch;
4979e764e56SPeter Brune 
498cd7522eaSPeter Brune /*S
499cd7522eaSPeter Brune      SNESLineSearch - Abstract PETSc object that manages line-search operations
500cd7522eaSPeter Brune 
501cd7522eaSPeter Brune    Level: beginner
502cd7522eaSPeter Brune 
503cd7522eaSPeter Brune   Concepts: nonlinear solvers, line search
504cd7522eaSPeter Brune 
505cd7522eaSPeter Brune .seealso:  SNESLineSearchCreate(), SNESLineSearchSetType(), SNES
506cd7522eaSPeter Brune S*/
507cd7522eaSPeter Brune 
508cd7522eaSPeter Brune /*J
509cd7522eaSPeter Brune     SNESLineSearchType - String with the name of a PETSc line search method
510cd7522eaSPeter Brune 
511cd7522eaSPeter Brune    Level: beginner
512cd7522eaSPeter Brune 
513cd7522eaSPeter Brune .seealso: SNESLineSearchSetType(), SNES
514cd7522eaSPeter Brune J*/
5159e764e56SPeter Brune 
51619fd82e9SBarry Smith typedef const char* SNESLineSearchType;
5171a4f838cSPeter Brune #define SNESLINESEARCHBT                 "bt"
5181a4f838cSPeter Brune #define SNESLINESEARCHBASIC              "basic"
5191a4f838cSPeter Brune #define SNESLINESEARCHL2                 "l2"
5201a4f838cSPeter Brune #define SNESLINESEARCHCP                 "cp"
5211a4f838cSPeter Brune #define SNESLINESEARCHSHELL              "shell"
5229e764e56SPeter Brune 
523140e18c1SBarry Smith PETSC_EXTERN PetscBool         SNESRegisterAllCalled;
524140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList SNESList;
525014dd563SJed Brown PETSC_EXTERN PetscClassId      SNESLINESEARCH_CLASSID;
526014dd563SJed Brown PETSC_EXTERN PetscBool         SNESLineSearchRegisterAllCalled;
527140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList SNESLineSearchList;
528014dd563SJed Brown PETSC_EXTERN PetscLogEvent     SNESLineSearch_Apply;
5299e764e56SPeter Brune 
530b000cd8dSPeter Brune #define SNES_LINESEARCH_ORDER_LINEAR    1
531b000cd8dSPeter Brune #define SNES_LINESEARCH_ORDER_QUADRATIC 2
532b000cd8dSPeter Brune #define SNES_LINESEARCH_ORDER_CUBIC     3
53359405d5eSPeter Brune 
534638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*SNESLineSearchVIProjectFunc)(SNES,Vec);
535638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*SNESLineSearchVINormFunc)(SNES,Vec,Vec,PetscReal *);
536638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*SNESLineSearchApplyFunc)(SNESLineSearch);
537638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*SNESLineSearchUserFunc)(SNESLineSearch, void *);
5389e764e56SPeter Brune 
539014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchCreate(MPI_Comm, SNESLineSearch*);
540014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchReset(SNESLineSearch);
541014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchView(SNESLineSearch,PetscViewer);
542014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchDestroy(SNESLineSearch *);
54319fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetType(SNESLineSearch, SNESLineSearchType);
544014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetFromOptions(SNESLineSearch);
545014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetUp(SNESLineSearch);
546014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchApply(SNESLineSearch, Vec, Vec, PetscReal *, Vec);
547014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchPreCheck(SNESLineSearch,Vec,Vec,PetscBool *);
548014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchPostCheck(SNESLineSearch,Vec,Vec,Vec,PetscBool *,PetscBool *);
549014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetWork(SNESLineSearch, PetscInt);
5509e764e56SPeter Brune 
5519bd66eb0SPeter Brune /* set the functions for precheck and postcheck */
55286d74e61SPeter Brune 
5536b2b7091SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetPreCheck(SNESLineSearch, PetscErrorCode (*SNESLineSearchPreCheckFunction)(SNESLineSearch,Vec,Vec,PetscBool*,void*), void *ctx);
5546b2b7091SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetPostCheck(SNESLineSearch, PetscErrorCode (*SNESLineSearchPostCheckFunction)(SNESLineSearch,Vec,Vec,Vec,PetscBool *,PetscBool *,void*), void *ctx);
5559e764e56SPeter Brune 
5566b2b7091SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchGetPreCheck(SNESLineSearch, PetscErrorCode (**SNESLineSearchPreCheckFunction)(SNESLineSearch,Vec,Vec,PetscBool*,void*), void **ctx);
5576b2b7091SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchGetPostCheck(SNESLineSearch, PetscErrorCode (**SNESLineSearchPostCheckFunction)(SNESLineSearch,Vec,Vec,Vec,PetscBool *,PetscBool *,void*), void **ctx);
5589e764e56SPeter Brune 
5599bd66eb0SPeter Brune /* set the functions for VI-specific line search operations */
5609bd66eb0SPeter Brune 
561014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFunc, SNESLineSearchVINormFunc);
562014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFunc*, SNESLineSearchVINormFunc*);
5639bd66eb0SPeter Brune 
5649e764e56SPeter Brune /* pointers to the associated SNES in order to be able to get the function evaluation out */
565014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetSNES(SNESLineSearch,SNES);
566014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetSNES(SNESLineSearch,SNES*);
5679e764e56SPeter Brune 
5689e764e56SPeter Brune /* set and get the parameters and vectors */
569014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetTolerances(SNESLineSearch,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscInt*);
570014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetTolerances(SNESLineSearch,PetscReal,PetscReal,PetscReal,PetscReal,PetscReal,PetscInt);
5719e764e56SPeter Brune 
572014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchPreCheckPicard(SNESLineSearch,Vec,Vec,PetscBool*,void*);
57386d74e61SPeter Brune 
574014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetLambda(SNESLineSearch,PetscReal*);
575014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetLambda(SNESLineSearch,PetscReal);
5769e764e56SPeter Brune 
577014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetDamping(SNESLineSearch,PetscReal*);
578014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetDamping(SNESLineSearch,PetscReal);
5799e764e56SPeter Brune 
580014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetOrder(SNESLineSearch,PetscInt *order);
581014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetOrder(SNESLineSearch,PetscInt order);
58259405d5eSPeter Brune 
583014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetSuccess(SNESLineSearch, PetscBool*);
584014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetSuccess(SNESLineSearch, PetscBool);
5859e764e56SPeter Brune 
586014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetVecs(SNESLineSearch,Vec*,Vec*,Vec*,Vec*,Vec*);
587014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetVecs(SNESLineSearch,Vec,Vec,Vec,Vec,Vec);
5889e764e56SPeter Brune 
589014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetNorms(SNESLineSearch, PetscReal *, PetscReal *, PetscReal *);
590014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetNorms(SNESLineSearch, PetscReal, PetscReal, PetscReal);
591014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchComputeNorms(SNESLineSearch);
592014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetComputeNorms(SNESLineSearch, PetscBool);
5939e764e56SPeter Brune 
594014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetMonitor(SNESLineSearch, PetscBool);
595014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetMonitor(SNESLineSearch, PetscViewer*);
5969e764e56SPeter Brune 
597014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchAppendOptionsPrefix(SNESLineSearch, const char prefix[]);
598014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetOptionsPrefix(SNESLineSearch, const char *prefix[]);
5999e764e56SPeter Brune 
6009e764e56SPeter Brune 
6019e764e56SPeter Brune /* Shell interface functions */
602014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchShellSetUserFunc(SNESLineSearch,SNESLineSearchUserFunc,void*);
603014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchShellGetUserFunc(SNESLineSearch,SNESLineSearchUserFunc*,void**);
6049e764e56SPeter Brune 
6052f4102e2SPeter Brune /* BT interface functions */
606014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchBTSetAlpha(SNESLineSearch, PetscReal);
607014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchBTGetAlpha(SNESLineSearch, PetscReal*);
6082f4102e2SPeter Brune 
6099e764e56SPeter Brune /*register line search types */
610014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchRegister(const char[],const char[],const char[],PetscErrorCode(*)(SNESLineSearch));
611014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchRegisterAll(const char path[]);
612014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchRegisterDestroy(void);
6139e764e56SPeter Brune 
6149e764e56SPeter Brune #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
615f1c6b773SPeter Brune #define SNESLineSearchRegisterDynamic(a,b,c,d) SNESLineSearchRegister(a,b,c,0)
6169e764e56SPeter Brune #else
617f1c6b773SPeter Brune #define SNESLineSearchRegisterDynamic(a,b,c,d) SNESLineSearchRegister(a,b,c,d)
6189e764e56SPeter Brune #endif
6199e764e56SPeter Brune 
620720c9a41SShri Abhyankar /* Routines for VI solver */
621014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVISetVariableBounds(SNES,Vec,Vec);
622014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVISetComputeVariableBounds(SNES, PetscErrorCode (*)(SNES,Vec,Vec));
623014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVIGetInactiveSet(SNES,IS*);
624014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVIGetActiveSetIS(SNES,Vec,Vec,IS*);
625014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVIComputeInactiveSetFnorm(SNES,Vec,Vec,PetscReal*);
626014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVISetRedundancyCheck(SNES,PetscErrorCode(*)(SNES,IS,IS*,void*),void*);
62701f0b76bSBarry Smith #define SNES_VI_INF   1.0e20
62801f0b76bSBarry Smith #define SNES_VI_NINF -1.0e20
629f5ea5bd2SShri Abhyankar 
630014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESTestLocalMin(SNES);
631da9b6338SBarry Smith 
632eef9c623SLois Curfman McInnes /* Should this routine be private? */
633014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*);
634ddbbdb52SLois Curfman McInnes 
635014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetDM(SNES,DM);
636014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetDM(SNES,DM*);
637014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetPC(SNES,SNES);
638014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetPC(SNES,SNES*);
639c40d0f55SPeter Brune PETSC_EXTERN PetscErrorCode SNESSetPCSide(SNES,PCSide);
640c40d0f55SPeter Brune PETSC_EXTERN PetscErrorCode SNESGetPCSide(SNES,PCSide*);
641014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetSNESLineSearch(SNES,SNESLineSearch);
642014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetSNESLineSearch(SNES,SNESLineSearch*);
643014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESRestrictHookAdd(SNES,PetscErrorCode (*)(SNES,SNES,void*),void*);
644014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESRestrictHooksRun(SNES,SNES);
6456c699258SBarry Smith 
646014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetUpMatrices(SNES);
647bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetFunction(DM,PetscErrorCode(*SNESFunction)(SNES,Vec,Vec,void*),void*);
648bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetFunction(DM,PetscErrorCode(**SNESSetFunction)(SNES,Vec,Vec,void*),void**);
649bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetGS(DM,PetscErrorCode(*SNESGSFunction)(SNES,Vec,Vec,void*),void*);
650bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetGS(DM,PetscErrorCode(**SNESGSFunction)(SNES,Vec,Vec,void*),void**);
651bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetJacobian(DM,PetscErrorCode(*SNESJacobianFunction)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void*);
652bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetJacobian(DM,PetscErrorCode(**SNESJacobianFunction)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void**);
653bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetPicard(DM,PetscErrorCode(*SNESFunction)(SNES,Vec,Vec,void*),PetscErrorCode(*SNESJacobianFunction)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void*);
654bf388a1fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetPicard(DM,PetscErrorCode(**SNESFunction)(SNES,Vec,Vec,void*),PetscErrorCode(**SNESJacobianFunction)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void**);
655075cc632SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetObjective(DM,PetscErrorCode (*SNESObjectiveFunction)(SNES,Vec,PetscReal *,void*),void*);
656075cc632SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetObjective(DM,PetscErrorCode (**SNESObjectiveFunction)(SNES,Vec,PetscReal *,void*),void**);
6576cab3a1bSJed Brown 
658c9d099b5SPeter Brune PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*DMDASNESFunction)(DMDALocalInfo*,void*,void*,void*);
659c9d099b5SPeter Brune PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*DMDASNESJacobian)(DMDALocalInfo*,void*,Mat,Mat,MatStructure*,void*);
6602a4ee8f2SPeter Brune PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*DMDASNESObjective)(DMDALocalInfo*,void*,PetscReal*,void*);
661c9d099b5SPeter Brune 
662c9d099b5SPeter Brune PETSC_EXTERN PetscErrorCode DMDASNESSetFunctionLocal(DM,InsertMode,DMDASNESFunction,void*);
663c9d099b5SPeter Brune PETSC_EXTERN PetscErrorCode DMDASNESSetJacobianLocal(DM,DMDASNESJacobian,void*);
6642a4ee8f2SPeter Brune PETSC_EXTERN PetscErrorCode DMDASNESSetObjectiveLocal(DM,DMDASNESObjective,void*);
665dcad5f1cSBarry Smith PETSC_EXTERN PetscErrorCode DMDASNESSetPicardLocal(DM,InsertMode,PetscErrorCode (*)(DMDALocalInfo*,void*,void*,void*),PetscErrorCode (*)(DMDALocalInfo*,void*,Mat,Mat,MatStructure*,void*),void*);
6666cab3a1bSJed Brown 
667ff35dfedSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetFunctionLocal(DM,PetscErrorCode (*)(DM,Vec,Vec,void*),void*);
668ff35dfedSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetJacobianLocal(DM,PetscErrorCode (*)(DM,Vec,Mat,Mat,MatStructure*,void*),void*);
669ff35dfedSBarry Smith 
670b665c654SMatthew G Knepley /* Routines for Multiblock solver */
671014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMultiblockSetFields(SNES, const char [], PetscInt, const PetscInt *);
672014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMultiblockSetIS(SNES, const char [], IS);
673014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMultiblockSetBlockSize(SNES, PetscInt);
674014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMultiblockSetType(SNES, PCCompositeType);
675aeed3662SMatthew G Knepley 
67637e1895aSJed Brown /*J
67737e1895aSJed Brown     SNESMSType - String with the name of a PETSc SNESMS method.
67837e1895aSJed Brown 
67937e1895aSJed Brown    Level: intermediate
68037e1895aSJed Brown 
68137e1895aSJed Brown .seealso: SNESMSSetType(), SNES
68237e1895aSJed Brown J*/
68319fd82e9SBarry Smith typedef const char* SNESMSType;
68437e1895aSJed Brown #define SNESMSM62       "m62"
68537e1895aSJed Brown #define SNESMSEULER     "euler"
686a97cb6bcSJed Brown #define SNESMSJAMESON83 "jameson83"
687a97cb6bcSJed Brown #define SNESMSVLTP21    "vltp21"
688a97cb6bcSJed Brown #define SNESMSVLTP31    "vltp31"
689a97cb6bcSJed Brown #define SNESMSVLTP41    "vltp41"
690a97cb6bcSJed Brown #define SNESMSVLTP51    "vltp51"
691a97cb6bcSJed Brown #define SNESMSVLTP61    "vltp61"
69237e1895aSJed Brown 
69319fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESMSRegister(SNESMSType,PetscInt,PetscInt,PetscReal,const PetscReal[],const PetscReal[],const PetscReal[]);
69419fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESMSSetType(SNES,SNESMSType);
695014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMSFinalizePackage(void);
696014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMSInitializePackage(const char path[]);
697014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMSRegisterDestroy(void);
698014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMSRegisterAll(void);
69937e1895aSJed Brown 
70013a62661SPeter Brune /* routines for NGMRES solver */
70113a62661SPeter Brune 
70213a62661SPeter Brune typedef enum {
70313a62661SPeter Brune   SNES_NGMRES_RESTART_NONE       = 0,
70413a62661SPeter Brune   SNES_NGMRES_RESTART_PERIODIC   = 1,
70513a62661SPeter Brune   SNES_NGMRES_RESTART_DIFFERENCE = 2} SNESNGMRESRestartType;
7066a6fc655SJed Brown PETSC_EXTERN const char *const SNESNGMRESRestartTypes[];
70713a62661SPeter Brune 
70813a62661SPeter Brune typedef enum {
70913a62661SPeter Brune   SNES_NGMRES_SELECT_NONE       = 0,
71013a62661SPeter Brune   SNES_NGMRES_SELECT_DIFFERENCE = 1,
71113a62661SPeter Brune   SNES_NGMRES_SELECT_LINESEARCH = 2} SNESNGMRESSelectType;
7126a6fc655SJed Brown PETSC_EXTERN const char *const SNESNGMRESSelectTypes[];
71313a62661SPeter Brune 
714014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESNGMRESSetRestartType(SNES, SNESNGMRESRestartType);
715014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESNGMRESSetSelectType(SNES, SNESNGMRESSelectType);
71613a62661SPeter Brune 
7170a844d1aSPeter Brune /* routines for NCG solver */
7180a844d1aSPeter Brune 
7190a844d1aSPeter Brune typedef enum {
7200de8b71eSPeter Brune   SNES_NCG_FR    = 0,
7210de8b71eSPeter Brune   SNES_NCG_PRP   = 1,
7220de8b71eSPeter Brune   SNES_NCG_HS    = 2,
7230de8b71eSPeter Brune   SNES_NCG_DY    = 3,
7240de8b71eSPeter Brune   SNES_NCG_CD    = 4} SNESNCGType;
7256a6fc655SJed Brown PETSC_EXTERN const char *const SNESNCGTypes[];
7260a844d1aSPeter Brune 
727014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESNCGSetType(SNES, SNESNCGType);
72813a62661SPeter Brune 
7290de8b71eSPeter Brune typedef enum {SNES_QN_SCALE_NONE       = 0,
7300de8b71eSPeter Brune               SNES_QN_SCALE_SHANNO     = 1,
7310de8b71eSPeter Brune               SNES_QN_SCALE_LINESEARCH = 2,
7320de8b71eSPeter Brune               SNES_QN_SCALE_JACOBIAN   = 3} SNESQNScaleType;
7336a6fc655SJed Brown PETSC_EXTERN const char *const SNESQNScaleTypes[];
7340de8b71eSPeter Brune typedef enum {SNES_QN_RESTART_NONE     = 0,
7350de8b71eSPeter Brune               SNES_QN_RESTART_POWELL   = 1,
7360de8b71eSPeter Brune               SNES_QN_RESTART_PERIODIC = 2} SNESQNRestartType;
7376a6fc655SJed Brown PETSC_EXTERN const char *const SNESQNRestartTypes[];
7380c777b0cSPeter Brune 
739014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESQNSetScaleType(SNES, SNESQNScaleType);
740014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESQNSetRestartType(SNES, SNESQNRestartType);
7410c777b0cSPeter Brune 
74276857b2aSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMGetSubdomains(SNES,PetscInt*,SNES**,VecScatter**,VecScatter**,VecScatter**);
74376857b2aSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMSetSubdomains(SNES,PetscInt,SNES*,VecScatter*,VecScatter*,VecScatter*);
74476857b2aSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMGetSubdomainVecs(SNES,PetscInt*,Vec**,Vec**,Vec**,Vec**);
745*d728fb7dSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMSetComputeFinalJacobian(SNES,PetscBool);
7460c777b0cSPeter Brune 
747ce3d82beSBarry Smith #endif
748