xref: /petsc/include/petscsnes.h (revision fdacfa885c588be27742c19354cf22cc1da6ef0f)
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
694b7f48cSBarry Smith #include "petscksp.h"
76cab3a1bSJed Brown #include "petscdmda.h"
8e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN
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*/
30a313700dSBarry Smith #define SNESType char*
31eef9c623SLois Curfman McInnes #define SNESLS           "ls"
32eef9c623SLois Curfman McInnes #define SNESTR           "tr"
331d6018f0SLisandro Dalcin #define SNESPYTHON       "python"
34eef9c623SLois Curfman McInnes #define SNESTEST         "test"
35d5c3842bSBarry Smith #define SNESNRICHARDSON  "nrichardson"
36b79b07cfSJed Brown #define SNESKSPONLY      "ksponly"
37c2fc9fa9SBarry Smith #define SNESVIRS         "virs"
38c2fc9fa9SBarry Smith #define SNESVISS         "viss"
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"
44d5c3842bSBarry Smith #define SNESSORQN        "sorqn"
45421d9b32SPeter Brune #define SNESFAS          "fas"
4637e1895aSJed Brown #define SNESMS           "ms"
47d5c3842bSBarry Smith 
48deeb6e72SMatthew Knepley /* Logging support */
497087cfbeSBarry Smith extern PetscClassId  SNES_CLASSID;
50deeb6e72SMatthew Knepley 
517087cfbeSBarry Smith extern PetscErrorCode  SNESInitializePackage(const char[]);
52deeb6e72SMatthew Knepley 
537087cfbeSBarry Smith extern PetscErrorCode  SNESCreate(MPI_Comm,SNES*);
5437596af1SLisandro Dalcin extern PetscErrorCode  SNESReset(SNES);
55fcfd50ebSBarry Smith extern PetscErrorCode  SNESDestroy(SNES*);
567087cfbeSBarry Smith extern PetscErrorCode  SNESSetType(SNES,const SNESType);
57228d79bcSJed Brown extern PetscErrorCode  SNESMonitor(SNES,PetscInt,PetscReal);
58c2efdce3SBarry Smith extern PetscErrorCode  SNESMonitorSet(SNES,PetscErrorCode(*)(SNES,PetscInt,PetscReal,void*),void *,PetscErrorCode (*)(void**));
597087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorCancel(SNES);
607087cfbeSBarry Smith extern PetscErrorCode  SNESSetConvergenceHistory(SNES,PetscReal[],PetscInt[],PetscInt,PetscBool );
617087cfbeSBarry Smith extern PetscErrorCode  SNESGetConvergenceHistory(SNES,PetscReal*[],PetscInt *[],PetscInt *);
627087cfbeSBarry Smith extern PetscErrorCode  SNESSetUp(SNES);
637087cfbeSBarry Smith extern PetscErrorCode  SNESSolve(SNES,Vec,Vec);
647087cfbeSBarry Smith extern PetscErrorCode  SNESSetErrorIfNotConverged(SNES,PetscBool );
657087cfbeSBarry Smith extern PetscErrorCode  SNESGetErrorIfNotConverged(SNES,PetscBool  *);
66e113a28aSBarry Smith 
6784cb2905SBarry Smith 
687087cfbeSBarry Smith extern PetscErrorCode  SNESAddOptionsChecker(PetscErrorCode (*)(SNES));
694d8f6ca9SMatthew Knepley 
707087cfbeSBarry Smith extern PetscErrorCode  SNESSetUpdate(SNES, PetscErrorCode (*)(SNES, PetscInt));
717087cfbeSBarry Smith extern PetscErrorCode  SNESDefaultUpdate(SNES, PetscInt);
724d8f6ca9SMatthew Knepley 
73b0a32e0cSBarry Smith extern PetscFList SNESList;
747087cfbeSBarry Smith extern PetscErrorCode  SNESRegisterDestroy(void);
757087cfbeSBarry Smith extern PetscErrorCode  SNESRegisterAll(const char[]);
7684cb2905SBarry Smith 
777087cfbeSBarry Smith extern PetscErrorCode  SNESRegister(const char[],const char[],const char[],PetscErrorCode (*)(SNES));
7830de9b25SBarry Smith 
7930de9b25SBarry Smith /*MC
8030de9b25SBarry Smith    SNESRegisterDynamic - Adds a method to the nonlinear solver package.
8130de9b25SBarry Smith 
8230de9b25SBarry Smith    Synopsis:
831890ba74SBarry Smith    PetscErrorCode SNESRegisterDynamic(const char *name_solver,const char *path,const char *name_create,PetscErrorCode (*routine_create)(SNES))
8430de9b25SBarry Smith 
8530de9b25SBarry Smith    Not collective
8630de9b25SBarry Smith 
8730de9b25SBarry Smith    Input Parameters:
8830de9b25SBarry Smith +  name_solver - name of a new user-defined solver
8930de9b25SBarry Smith .  path - path (either absolute or relative) the library containing this solver
9030de9b25SBarry Smith .  name_create - name of routine to create method context
9130de9b25SBarry Smith -  routine_create - routine to create method context
9230de9b25SBarry Smith 
9330de9b25SBarry Smith    Notes:
9430de9b25SBarry Smith    SNESRegisterDynamic() may be called multiple times to add several user-defined solvers.
9530de9b25SBarry Smith 
9630de9b25SBarry Smith    If dynamic libraries are used, then the fourth input argument (routine_create)
9730de9b25SBarry Smith    is ignored.
9830de9b25SBarry Smith 
99ab901514SBarry Smith    Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR},
10030de9b25SBarry Smith    and others of the form ${any_environmental_variable} occuring in pathname will be
10130de9b25SBarry Smith    replaced with appropriate values.
10230de9b25SBarry Smith 
10330de9b25SBarry Smith    Sample usage:
10430de9b25SBarry Smith .vb
10530de9b25SBarry Smith    SNESRegisterDynamic("my_solver",/home/username/my_lib/lib/libg/solaris/mylib.a,
10630de9b25SBarry Smith                 "MySolverCreate",MySolverCreate);
10730de9b25SBarry Smith .ve
10830de9b25SBarry Smith 
10930de9b25SBarry Smith    Then, your solver can be chosen with the procedural interface via
11030de9b25SBarry Smith $     SNESSetType(snes,"my_solver")
11130de9b25SBarry Smith    or at runtime via the option
11230de9b25SBarry Smith $     -snes_type my_solver
11330de9b25SBarry Smith 
11430de9b25SBarry Smith    Level: advanced
11530de9b25SBarry Smith 
11630de9b25SBarry Smith     Note: If your function is not being put into a shared library then use SNESRegister() instead
11730de9b25SBarry Smith 
11830de9b25SBarry Smith .keywords: SNES, nonlinear, register
11930de9b25SBarry Smith 
12030de9b25SBarry Smith .seealso: SNESRegisterAll(), SNESRegisterDestroy()
12130de9b25SBarry Smith M*/
122aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
123f1af5d2fSBarry Smith #define SNESRegisterDynamic(a,b,c,d) SNESRegister(a,b,c,0)
124b2002411SLois Curfman McInnes #else
125f1af5d2fSBarry Smith #define SNESRegisterDynamic(a,b,c,d) SNESRegister(a,b,c,d)
126b2002411SLois Curfman McInnes #endif
127b2002411SLois Curfman McInnes 
1287087cfbeSBarry Smith extern PetscErrorCode  SNESGetKSP(SNES,KSP*);
1297087cfbeSBarry Smith extern PetscErrorCode  SNESSetKSP(SNES,KSP);
1307087cfbeSBarry Smith extern PetscErrorCode  SNESGetSolution(SNES,Vec*);
1317087cfbeSBarry Smith extern PetscErrorCode  SNESGetSolutionUpdate(SNES,Vec*);
1322d4b5aceSLisandro Dalcin extern PetscErrorCode  SNESGetRhs(SNES,Vec*);
1337087cfbeSBarry Smith extern PetscErrorCode  SNESView(SNES,PetscViewer);
1347bc3d0afSSatish Balay 
1357087cfbeSBarry Smith extern PetscErrorCode  SNESSetOptionsPrefix(SNES,const char[]);
1367087cfbeSBarry Smith extern PetscErrorCode  SNESAppendOptionsPrefix(SNES,const char[]);
1377087cfbeSBarry Smith extern PetscErrorCode  SNESGetOptionsPrefix(SNES,const char*[]);
1387087cfbeSBarry Smith extern PetscErrorCode  SNESSetFromOptions(SNES);
139c699ede6SMatthew G Knepley extern PetscErrorCode  SNESDefaultGetWork(SNES,PetscInt);
14040191667SLois Curfman McInnes 
1417087cfbeSBarry Smith extern PetscErrorCode  MatCreateSNESMF(SNES,Mat*);
1427087cfbeSBarry Smith extern PetscErrorCode  MatMFFDComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
1438f6e3e37SBarry Smith 
1447087cfbeSBarry Smith extern PetscErrorCode  MatDAADSetSNES(Mat,SNES);
1453a7fca6bSBarry Smith 
1467087cfbeSBarry Smith extern PetscErrorCode  SNESGetType(SNES,const SNESType*);
1477087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorDefault(SNES,PetscInt,PetscReal,void *);
1487087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorRange(SNES,PetscInt,PetscReal,void *);
1497087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorRatio(SNES,PetscInt,PetscReal,void *);
150649052a6SBarry Smith extern PetscErrorCode  SNESMonitorSetRatio(SNES,PetscViewer);
1517087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorSolution(SNES,PetscInt,PetscReal,void *);
1527087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorResidual(SNES,PetscInt,PetscReal,void *);
1537087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorSolutionUpdate(SNES,PetscInt,PetscReal,void *);
1547087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorDefaultShort(SNES,PetscInt,PetscReal,void *);
1557087cfbeSBarry Smith extern PetscErrorCode  SNESSetTolerances(SNES,PetscReal,PetscReal,PetscReal,PetscInt,PetscInt);
1567087cfbeSBarry Smith extern PetscErrorCode  SNESGetTolerances(SNES,PetscReal*,PetscReal*,PetscReal*,PetscInt*,PetscInt*);
1577087cfbeSBarry Smith extern PetscErrorCode  SNESSetTrustRegionTolerance(SNES,PetscReal);
1587087cfbeSBarry Smith extern PetscErrorCode  SNESGetFunctionNorm(SNES,PetscReal*);
159360c497dSPeter Brune extern PetscErrorCode  SNESSetFunctionNorm(SNES,PetscReal);
1607087cfbeSBarry Smith extern PetscErrorCode  SNESGetIterationNumber(SNES,PetscInt*);
161360c497dSPeter Brune extern PetscErrorCode  SNESSetIterationNumber(SNES,PetscInt);
1623d4c4710SBarry Smith 
1637087cfbeSBarry Smith extern PetscErrorCode  SNESGetNonlinearStepFailures(SNES,PetscInt*);
1647087cfbeSBarry Smith extern PetscErrorCode  SNESSetMaxNonlinearStepFailures(SNES,PetscInt);
1657087cfbeSBarry Smith extern PetscErrorCode  SNESGetMaxNonlinearStepFailures(SNES,PetscInt*);
1667087cfbeSBarry Smith extern PetscErrorCode  SNESGetNumberFunctionEvals(SNES,PetscInt*);
167b850b91aSLisandro Dalcin 
1687087cfbeSBarry Smith extern PetscErrorCode  SNESSetLagPreconditioner(SNES,PetscInt);
1697087cfbeSBarry Smith extern PetscErrorCode  SNESGetLagPreconditioner(SNES,PetscInt*);
1707087cfbeSBarry Smith extern PetscErrorCode  SNESSetLagJacobian(SNES,PetscInt);
1717087cfbeSBarry Smith extern PetscErrorCode  SNESGetLagJacobian(SNES,PetscInt*);
172efd51863SBarry Smith extern PetscErrorCode  SNESSetGridSequence(SNES,PetscInt);
173a8054027SBarry Smith 
1747087cfbeSBarry Smith extern PetscErrorCode  SNESGetLinearSolveIterations(SNES,PetscInt*);
1757087cfbeSBarry Smith extern PetscErrorCode  SNESGetLinearSolveFailures(SNES,PetscInt*);
1767087cfbeSBarry Smith extern PetscErrorCode  SNESSetMaxLinearSolveFailures(SNES,PetscInt);
1777087cfbeSBarry Smith extern PetscErrorCode  SNESGetMaxLinearSolveFailures(SNES,PetscInt*);
1783d4c4710SBarry Smith 
1797087cfbeSBarry Smith extern PetscErrorCode  SNESKSPSetUseEW(SNES,PetscBool );
1807087cfbeSBarry Smith extern PetscErrorCode  SNESKSPGetUseEW(SNES,PetscBool *);
1817087cfbeSBarry Smith extern PetscErrorCode  SNESKSPSetParametersEW(SNES,PetscInt,PetscReal,PetscReal,PetscReal,PetscReal,PetscReal,PetscReal);
1827087cfbeSBarry Smith extern PetscErrorCode  SNESKSPGetParametersEW(SNES,PetscInt*,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscReal*);
183eafb4bcbSBarry Smith 
1847087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorLGCreate(const char[],const char[],int,int,int,int,PetscDrawLG*);
1857087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorLG(SNES,PetscInt,PetscReal,void*);
186fcfd50ebSBarry Smith extern PetscErrorCode  SNESMonitorLGDestroy(PetscDrawLG*);
1877087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorLGRangeCreate(const char[],const char[],int,int,int,int,PetscDrawLG*);
1887087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorLGRange(SNES,PetscInt,PetscReal,void*);
189fcfd50ebSBarry Smith extern PetscErrorCode  SNESMonitorLGRangeDestroy(PetscDrawLG*);
190eafb4bcbSBarry Smith 
1917087cfbeSBarry Smith extern PetscErrorCode  SNESSetApplicationContext(SNES,void *);
192e71120c6SJed Brown extern PetscErrorCode  SNESGetApplicationContext(SNES,void *);
193d25893d9SBarry Smith extern PetscErrorCode  SNESSetComputeApplicationContext(SNES,PetscErrorCode (*)(SNES,void**),PetscErrorCode (*)(void**));
194184914b5SBarry Smith 
1957087cfbeSBarry Smith extern PetscErrorCode  SNESPythonSetType(SNES,const char[]);
1961d6018f0SLisandro Dalcin 
1977087cfbeSBarry Smith extern PetscErrorCode  SNESSetFunctionDomainError(SNES);
1986a388c36SPeter Brune extern PetscErrorCode  SNESGetFunctionDomainError(SNES, PetscBool *);
1996a388c36SPeter Brune 
200435da068SBarry Smith /*E
201435da068SBarry Smith     SNESConvergedReason - reason a SNES method was said to
202435da068SBarry Smith          have converged or diverged
203435da068SBarry Smith 
204435da068SBarry Smith    Level: beginner
205435da068SBarry Smith 
206f203c74bSBarry Smith    The two most common reasons for divergence are
207f203c74bSBarry Smith $   1) an incorrectly coded or computed Jacobian or
208f203c74bSBarry Smith $   2) failure or lack of convergence in the linear system (in this case we recommend
209f203c74bSBarry Smith $      testing with -pc_type lu to eliminate the linear solver as the cause of the problem).
210f203c74bSBarry Smith 
211f203c74bSBarry Smith    Diverged Reasons:
212f203c74bSBarry Smith .    SNES_DIVERGED_LOCAL_MIN - this can only occur when using the line-search variant of SNES.
213f203c74bSBarry Smith        The line search wants to minimize Q(alpha) = 1/2 || F(x + alpha s) ||^2_2  this occurs
214f203c74bSBarry 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
215f203c74bSBarry Smith        you get Q'(alpha) = -F(x)^T F'(x)^(-1)^T F'(x+alpha s)F(x+alpha s); when alpha = 0
216f203c74bSBarry Smith        Q'(0) = - ||F(x)||^2_2 which is always NEGATIVE if F'(x) is invertible. This means the Newton
217f203c74bSBarry Smith        direction is a descent direction and the line search should succeed if alpha is small enough.
218f203c74bSBarry Smith 
219f203c74bSBarry Smith        If F'(x) is NOT invertible AND F'(x)^T F(x) = 0 then Q'(0) = 0 and the Newton direction
220f203c74bSBarry Smith        is NOT a descent direction so the line search will fail. All one can do at this point
221f203c74bSBarry Smith        is change the initial guess and try again.
222f203c74bSBarry Smith 
223f203c74bSBarry Smith        An alternative explanation: Newton's method can be regarded as replacing the function with
224f203c74bSBarry Smith        its linear approximation and minimizing the 2-norm of that. That is F(x+s) approx F(x) + F'(x)s
225f203c74bSBarry Smith        so we minimize || F(x) + F'(x) s ||^2_2; do this using Least Squares. If F'(x) is invertible then
226f203c74bSBarry 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
227f203c74bSBarry Smith        exists a nontrival (that is F'(x)s != 0) solution to the equation and this direction is
228f203c74bSBarry 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)
229f203c74bSBarry 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
230f203c74bSBarry Smith        and F'(x)^T F'(x) has no negative eigenvalues Q'(0) < 0 so s is a descent direction and the line
231f203c74bSBarry Smith        search should succeed for small enough alpha.
232f203c74bSBarry Smith 
233f203c74bSBarry Smith        Note that this RARELY happens in practice. Far more likely the linear system is not being solved
234f203c74bSBarry Smith        (well enough?) or the Jacobian is wrong.
235f203c74bSBarry Smith 
2364d0a8057SBarry Smith    SNES_DIVERGED_MAX_IT means that the solver reached the maximum number of iterations without satisfying any
2374d0a8057SBarry Smith    convergence criteria. SNES_CONVERGED_ITS means that SNESSkipConverged() was chosen as the convergence test;
2384d0a8057SBarry Smith    thus the usual convergence criteria have not been checked and may or may not be satisfied.
239f203c74bSBarry Smith 
2404d0a8057SBarry Smith    Developer Notes: this must match finclude/petscsnes.h
2414d0a8057SBarry Smith 
2424d0a8057SBarry Smith        The string versions of these are in SNESConvergedReason, if you change any value here you must
2434d0a8057SBarry Smith      also adjust that array.
2445968eb51SBarry Smith 
24546a9e3ceSBarry Smith    Each reason has its own manual page.
24646a9e3ceSBarry Smith 
247435da068SBarry Smith .seealso: SNESSolve(), SNESGetConvergedReason(), KSPConvergedReason, SNESSetConvergenceTest()
248435da068SBarry Smith E*/
249184914b5SBarry Smith typedef enum {/* converged */
25001b82886SBarry Smith               SNES_CONVERGED_FNORM_ABS         =  2, /* ||F|| < atol */
25101b82886SBarry Smith               SNES_CONVERGED_FNORM_RELATIVE    =  3, /* ||F|| < rtol*||F_initial|| */
252c60f73f4SPeter Brune               SNES_CONVERGED_SNORM_RELATIVE    =  4, /* Newton computed step size small; || delta x || < stol */
2533f149594SLisandro Dalcin               SNES_CONVERGED_ITS               =  5, /* maximum iterations reached */
254184914b5SBarry Smith               SNES_CONVERGED_TR_DELTA          =  7,
255184914b5SBarry Smith               /* diverged */
25646a9e3ceSBarry Smith               SNES_DIVERGED_FUNCTION_DOMAIN     = -1, /* the new x location passed the function is not in the domain of F */
257184914b5SBarry Smith               SNES_DIVERGED_FUNCTION_COUNT      = -2,
25846a9e3ceSBarry Smith               SNES_DIVERGED_LINEAR_SOLVE        = -3, /* the linear solve failed */
259184914b5SBarry Smith               SNES_DIVERGED_FNORM_NAN           = -4,
260184914b5SBarry Smith               SNES_DIVERGED_MAX_IT              = -5,
261647a2e1fSBarry Smith               SNES_DIVERGED_LINE_SEARCH         = -6, /* the line search failed */
2621e633543SBarry Smith               SNES_DIVERGED_INNER               = -7, /* inner solve failed */
26358c775ebSBarry Smith               SNES_DIVERGED_LOCAL_MIN           = -8, /* || J^T b || is small, implies converged to local minimum of F() */
264184914b5SBarry Smith               SNES_CONVERGED_ITERATING          =  0} SNESConvergedReason;
2657935a769SJed Brown extern const char *const*SNESConvergedReasons;
266184914b5SBarry Smith 
267c838673bSBarry Smith /*MC
268c838673bSBarry Smith      SNES_CONVERGED_FNORM_ABS - 2-norm(F) <= abstol
269c838673bSBarry Smith 
270c838673bSBarry Smith    Level: beginner
271c838673bSBarry Smith 
272c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
273c838673bSBarry Smith 
274c838673bSBarry Smith M*/
275c838673bSBarry Smith 
276c838673bSBarry Smith /*MC
277c838673bSBarry Smith      SNES_CONVERGED_FNORM_RELATIVE - 2-norm(F) <= rtol*2-norm(F(x_0)) where x_0 is the initial guess
278c838673bSBarry Smith 
279c838673bSBarry Smith    Level: beginner
280c838673bSBarry Smith 
281c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
282c838673bSBarry Smith 
283c838673bSBarry Smith M*/
284c838673bSBarry Smith 
285c838673bSBarry Smith /*MC
286c60f73f4SPeter Brune      SNES_CONVERGED_SNORM_RELATIVE - The 2-norm of the last step <= stol * 2-norm(x) where x is the current
28746a9e3ceSBarry Smith           solution and stol is the 4th argument to SNESSetTolerances()
288c838673bSBarry Smith 
289ae9be289SBarry Smith      Options Database Keys:
290ae9be289SBarry Smith       -snes_stol <stol> - the step tolerance
291ae9be289SBarry Smith 
292c838673bSBarry Smith    Level: beginner
293c838673bSBarry Smith 
294c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
295c838673bSBarry Smith 
296c838673bSBarry Smith M*/
297c838673bSBarry Smith 
298c838673bSBarry Smith /*MC
299c838673bSBarry Smith      SNES_DIVERGED_FUNCTION_COUNT - The user provided function has been called more times then the final
300c838673bSBarry Smith          argument to SNESSetTolerances()
301c838673bSBarry Smith 
302c838673bSBarry Smith    Level: beginner
303c838673bSBarry Smith 
304c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
305c838673bSBarry Smith 
306c838673bSBarry Smith M*/
307c838673bSBarry Smith 
308c838673bSBarry Smith /*MC
309c838673bSBarry Smith      SNES_DIVERGED_FNORM_NAN - the 2-norm of the current function evaluation is not-a-number (NaN), this
310c838673bSBarry Smith       is usually caused by a division of 0 by 0.
311c838673bSBarry Smith 
312c838673bSBarry Smith    Level: beginner
313c838673bSBarry Smith 
314c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
315c838673bSBarry Smith 
316c838673bSBarry Smith M*/
317c838673bSBarry Smith 
318c838673bSBarry Smith /*MC
319c838673bSBarry Smith      SNES_DIVERGED_MAX_IT - SNESSolve() has reached the maximum number of iterations requested
320c838673bSBarry Smith 
321c838673bSBarry Smith    Level: beginner
322c838673bSBarry Smith 
323c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
324c838673bSBarry Smith 
325c838673bSBarry Smith M*/
326c838673bSBarry Smith 
327c838673bSBarry Smith /*MC
328647a2e1fSBarry Smith      SNES_DIVERGED_LINE_SEARCH - The line search has failed. This only occurs for a SNESType of SNESLS
329c838673bSBarry Smith 
330c838673bSBarry Smith    Level: beginner
331c838673bSBarry Smith 
332c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
333c838673bSBarry Smith 
334c838673bSBarry Smith M*/
335c838673bSBarry Smith 
336c838673bSBarry Smith /*MC
33746a9e3ceSBarry Smith      SNES_DIVERGED_LOCAL_MIN - the algorithm seems to have stagnated at a local minimum that is not zero.
33846a9e3ceSBarry Smith         See the manual page for SNESConvergedReason for more details
339c838673bSBarry Smith 
340c838673bSBarry Smith    Level: beginner
341c838673bSBarry Smith 
342c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
343c838673bSBarry Smith 
344c838673bSBarry Smith M*/
345c838673bSBarry Smith 
346c838673bSBarry Smith /*MC
347c838673bSBarry Smith      SNES_CONERGED_ITERATING - this only occurs if SNESGetConvergedReason() is called during the SNESSolve()
348c838673bSBarry Smith 
349c838673bSBarry Smith    Level: beginner
350c838673bSBarry Smith 
351c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
352c838673bSBarry Smith 
353c838673bSBarry Smith M*/
354c838673bSBarry Smith 
3557087cfbeSBarry Smith extern PetscErrorCode  SNESSetConvergenceTest(SNES,PetscErrorCode (*)(SNES,PetscInt,PetscReal,PetscReal,PetscReal,SNESConvergedReason*,void*),void*,PetscErrorCode (*)(void*));
3567087cfbeSBarry Smith extern PetscErrorCode  SNESDefaultConverged(SNES,PetscInt,PetscReal,PetscReal,PetscReal,SNESConvergedReason*,void*);
3577087cfbeSBarry Smith extern PetscErrorCode  SNESSkipConverged(SNES,PetscInt,PetscReal,PetscReal,PetscReal,SNESConvergedReason*,void*);
3587087cfbeSBarry Smith extern PetscErrorCode  SNESGetConvergedReason(SNES,SNESConvergedReason*);
359ddbbdb52SLois Curfman McInnes 
360837ad101SBarry Smith extern PetscErrorCode  SNESDMDAComputeFunction(SNES,Vec,Vec,void*);
361837ad101SBarry Smith extern PetscErrorCode  SNESDMDAComputeJacobianWithAdic(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
362837ad101SBarry Smith extern PetscErrorCode  SNESDMDAComputeJacobianWithAdifor(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
363837ad101SBarry Smith extern PetscErrorCode  SNESDMDAComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
3643a7fca6bSBarry Smith 
365837ad101SBarry Smith extern PetscErrorCode SNESDMMeshComputeFunction(SNES,Vec,Vec,void*);
366837ad101SBarry Smith extern PetscErrorCode SNESDMMeshComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
3677da65231SMatthew G Knepley extern PetscErrorCode SNESDMComplexComputeFunction(SNES,Vec,Vec,void *);
3687da65231SMatthew G Knepley extern PetscErrorCode SNESDMComplexComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
36911f088b5SMatthew G Knepley 
370b67197daSBarry Smith /* --------- Solving systems of nonlinear equations --------------- */
3712d4b5aceSLisandro Dalcin typedef PetscErrorCode (*SNESFunction)(SNES,Vec,Vec,void*);
3722d4b5aceSLisandro Dalcin typedef PetscErrorCode (*SNESJacobian)(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
3733542a6bcSPeter Brune typedef PetscErrorCode (*SNESGSFunction)(SNES,Vec,Vec,void*);
3742d4b5aceSLisandro Dalcin extern PetscErrorCode  SNESSetFunction(SNES,Vec,SNESFunction,void*);
3752d4b5aceSLisandro Dalcin extern PetscErrorCode  SNESGetFunction(SNES,Vec*,SNESFunction*,void**);
3767087cfbeSBarry Smith extern PetscErrorCode  SNESComputeFunction(SNES,Vec,Vec);
3772d4b5aceSLisandro Dalcin extern PetscErrorCode  SNESSetJacobian(SNES,Mat,Mat,SNESJacobian,void*);
3782d4b5aceSLisandro Dalcin extern PetscErrorCode  SNESGetJacobian(SNES,Mat*,Mat*,SNESJacobian*,void**);
3797087cfbeSBarry Smith extern PetscErrorCode  SNESDefaultComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
3807087cfbeSBarry Smith extern PetscErrorCode  SNESDefaultComputeJacobianColor(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
381d25893d9SBarry Smith extern PetscErrorCode  SNESSetComputeInitialGuess(SNES,PetscErrorCode (*)(SNES,Vec,void*),void*);
3828b0a5094SBarry Smith extern PetscErrorCode  SNESSetPicard(SNES,Vec,SNESFunction,Mat,Mat,SNESJacobian,void*);
3838b0a5094SBarry Smith extern PetscErrorCode  SNESGetPicard(SNES,Vec*,SNESFunction*,Mat*,SNESJacobian*,void**);
384e4ed7901SPeter Brune extern PetscErrorCode  SNESSetInitialFunction(SNES,Vec);
385e4ed7901SPeter Brune extern PetscErrorCode  SNESSetInitialFunctionNorm(SNES,PetscReal);
38617bae607SBarry Smith 
387*534ebe21SPeter Brune /*E
388*534ebe21SPeter Brune     SNESNormType - Norm that is passed in the Krylov convergence
389*534ebe21SPeter Brune        test routines.
390*534ebe21SPeter Brune 
391*534ebe21SPeter Brune    Level: advanced
392*534ebe21SPeter Brune 
393*534ebe21SPeter Brune    Support for these is highly dependent on the solver.
394*534ebe21SPeter Brune 
395*534ebe21SPeter Brune    Notes:
396*534ebe21SPeter Brune    This is primarily used to turn off extra norm and function computation
397*534ebe21SPeter Brune    when the solvers are composed.
398*534ebe21SPeter Brune 
399*534ebe21SPeter Brune .seealso: SNESSolve(), SNESGetConvergedReason(), KSPSetNormType(),
400*534ebe21SPeter Brune           KSPSetConvergenceTest(), KSPSetPCSide()
401*534ebe21SPeter Brune E*/
402*534ebe21SPeter Brune 
403*534ebe21SPeter Brune typedef enum {SNES_NORM_DEFAULT            = -1,
404fdacfa88SPeter Brune               SNES_NORM_NONE               = 0,
405fdacfa88SPeter Brune               SNES_NORM_FUNCTION           = 1,
406fdacfa88SPeter Brune               SNES_NORM_INITIAL_ONLY       = 2,
407fdacfa88SPeter Brune               SNES_NORM_FINAL_ONLY         = 3,
408fdacfa88SPeter Brune               SNES_NORM_INITIAL_FINAL_ONLY = 4} SNESNormType;
409fdacfa88SPeter Brune extern const char *const*const SNESNormTypes;
410*534ebe21SPeter Brune /*MC
411fdacfa88SPeter Brune     SNES_NORM_NONE - Don't compute function and its L2 norm.
412*534ebe21SPeter Brune 
413*534ebe21SPeter Brune    Level: advanced
414*534ebe21SPeter Brune 
415*534ebe21SPeter Brune     Notes:
416*534ebe21SPeter Brune     This is most useful for stationary solvers with a fixed number of iterations used as smoothers.
417*534ebe21SPeter Brune 
418*534ebe21SPeter Brune .seealso: SNESNormType, SNESSetNormType(), SNES_NORM_DEFAULT
419*534ebe21SPeter Brune M*/
420*534ebe21SPeter Brune 
421fdacfa88SPeter Brune /*MC
422fdacfa88SPeter Brune     SNES_NORM_FUNCTION - Compute the function and its L2 norm at each iteration.
423*534ebe21SPeter Brune 
424fdacfa88SPeter Brune    Level: advanced
425fdacfa88SPeter Brune 
426fdacfa88SPeter Brune     Notes:
427fdacfa88SPeter Brune     Most solvers will use this no matter what norm type is passed to them.
428fdacfa88SPeter Brune 
429fdacfa88SPeter Brune .seealso: SNESNormType, SNESSetNormType(), SNES_NORM_NONE
430fdacfa88SPeter Brune M*/
431*534ebe21SPeter Brune 
432*534ebe21SPeter Brune /*MC
433*534ebe21SPeter Brune     SNES_NORM_INITIAL_ONLY - Compute the function and its L2 at iteration 0, but do not update it.
434*534ebe21SPeter Brune 
435*534ebe21SPeter Brune    Level: advanced
436*534ebe21SPeter Brune 
437*534ebe21SPeter Brune    Notes:
438*534ebe21SPeter Brune    This method is useful in composed methods, when a true solution might actually be found before SNESSolve() is called.
439*534ebe21SPeter Brune    This option enables the solve to abort on the zeroth iteration if this is the case.
440*534ebe21SPeter Brune 
441*534ebe21SPeter Brune    For solvers that require the computation of the L2 norm of the function as part of the method, this merely cancels
442*534ebe21SPeter Brune    the norm computation at the last iteration (if possible).
443*534ebe21SPeter Brune 
444*534ebe21SPeter Brune .seealso: SNESNormType, SNESSetNormType(), SNES_NORM_FINAL_ONLY, SNES_NORM_INITIAL_FINAL_ONLY
445*534ebe21SPeter Brune M*/
446*534ebe21SPeter Brune 
447*534ebe21SPeter Brune /*MC
448*534ebe21SPeter Brune     SNES_NORM_FINAL_ONLY - Compute the function and its L2 norm on only the final iteration.
449*534ebe21SPeter Brune 
450*534ebe21SPeter Brune    Level: advanced
451*534ebe21SPeter Brune 
452*534ebe21SPeter Brune    Notes:
453*534ebe21SPeter Brune    For solvers that require the computation of the L2 norm of the function as part of the method, behaves
454*534ebe21SPeter Brune    exactly as SNES_NORM_DEFAULT.  This method is useful when the function is gotten after SNESSolve and
455*534ebe21SPeter Brune    used in subsequent computation for methods that do not need the norm computed during the rest of the
456*534ebe21SPeter Brune    solution procedure.
457*534ebe21SPeter Brune 
458*534ebe21SPeter Brune .seealso: SNESNormType, SNESSetNormType(), SNES_NORM_INITIAL_ONLY, SNES_NORM_INITIAL_FINAL_ONLY
459*534ebe21SPeter Brune M*/
460*534ebe21SPeter Brune 
461*534ebe21SPeter Brune /*MC
462*534ebe21SPeter Brune     SNES_NORM_INITIAL_FINAL_ONLY - Compute the function and its L2 norm on only the initial and final iterations.
463*534ebe21SPeter Brune 
464*534ebe21SPeter Brune    Level: advanced
465*534ebe21SPeter Brune 
466*534ebe21SPeter Brune    Notes:
467*534ebe21SPeter Brune    This method combines the benefits of SNES_NORM_INITIAL_ONLY and SNES_NORM_FINAL_ONLY.
468*534ebe21SPeter Brune 
469*534ebe21SPeter Brune .seealso: SNESNormType, SNESSetNormType(), SNES_NORM_SNES_NORM_INITIAL_ONLY, SNES_NORM_FINAL_ONLY
470*534ebe21SPeter Brune M*/
471*534ebe21SPeter Brune 
472*534ebe21SPeter Brune 
473*534ebe21SPeter Brune extern PetscErrorCode  SNESSetNormType(SNES,SNESNormType);
474*534ebe21SPeter Brune extern PetscErrorCode  SNESGetNormType(SNES,SNESNormType*);
475*534ebe21SPeter Brune 
4763542a6bcSPeter Brune extern PetscErrorCode  SNESSetGS(SNES,SNESGSFunction,void*);
4773542a6bcSPeter Brune extern PetscErrorCode  SNESGetGS(SNES,SNESGSFunction*,void**);
478badc63e7SPeter Brune extern PetscErrorCode  SNESSetUseGS(SNES,PetscBool);
479badc63e7SPeter Brune extern PetscErrorCode  SNESGetUseGS(SNES,PetscBool *);
48089b92e6fSPeter Brune extern PetscErrorCode  SNESSetGSSweeps(SNES,PetscInt);
48189b92e6fSPeter Brune extern PetscErrorCode  SNESGetGSSweeps(SNES,PetscInt *);
482646217ecSPeter Brune extern PetscErrorCode  SNESComputeGS(SNES,Vec,Vec);
483646217ecSPeter Brune 
484c5ae4b9aSBarry Smith extern PetscErrorCode  SNESShellGetContext(SNES,void**);
485c5ae4b9aSBarry Smith extern PetscErrorCode  SNESShellSetContext(SNES,void*);
486c5ae4b9aSBarry Smith extern PetscErrorCode  SNESShellSetSolve(SNES,PetscErrorCode (*)(SNES,Vec));
487c5ae4b9aSBarry Smith 
488872b6db9SPeter Brune /* --------- Routines specifically for line search methods --------------- */
489872b6db9SPeter Brune 
490f1c6b773SPeter Brune typedef struct _p_LineSearch* SNESLineSearch;
4919e764e56SPeter Brune 
492cd7522eaSPeter Brune /*S
493cd7522eaSPeter Brune      SNESLineSearch - Abstract PETSc object that manages line-search operations
494cd7522eaSPeter Brune 
495cd7522eaSPeter Brune    Level: beginner
496cd7522eaSPeter Brune 
497cd7522eaSPeter Brune   Concepts: nonlinear solvers, line search
498cd7522eaSPeter Brune 
499cd7522eaSPeter Brune .seealso:  SNESLineSearchCreate(), SNESLineSearchSetType(), SNES
500cd7522eaSPeter Brune S*/
501cd7522eaSPeter Brune 
502cd7522eaSPeter Brune /*J
503cd7522eaSPeter Brune     SNESLineSearchType - String with the name of a PETSc line search method
504cd7522eaSPeter Brune 
505cd7522eaSPeter Brune    Level: beginner
506cd7522eaSPeter Brune 
507cd7522eaSPeter Brune .seealso: SNESLineSearchSetType(), SNES
508cd7522eaSPeter Brune J*/
5099e764e56SPeter Brune 
510f1c6b773SPeter Brune #define SNESLineSearchType char*
5111a4f838cSPeter Brune #define SNESLINESEARCHBT                 "bt"
5121a4f838cSPeter Brune #define SNESLINESEARCHBASIC              "basic"
5131a4f838cSPeter Brune #define SNESLINESEARCHL2                 "l2"
5141a4f838cSPeter Brune #define SNESLINESEARCHCP                 "cp"
5151a4f838cSPeter Brune #define SNESLINESEARCHSHELL              "shell"
5169e764e56SPeter Brune 
517f1c6b773SPeter Brune extern PetscClassId  SNESLINESEARCH_CLASSID;
518f1c6b773SPeter Brune extern PetscBool     SNESLineSearchRegisterAllCalled;
519f1c6b773SPeter Brune extern PetscFList    SNESLineSearchList;
520f1c6b773SPeter Brune extern PetscLogEvent SNESLineSearch_Apply;
5219e764e56SPeter Brune 
52259405d5eSPeter Brune typedef enum {SNES_LINESEARCH_LINEAR,
52359405d5eSPeter Brune               SNES_LINESEARCH_CUBIC,
52459405d5eSPeter Brune               SNES_LINESEARCH_QUADRATIC} SNESLineSearchOrder;
52559405d5eSPeter Brune 
526f1c6b773SPeter Brune typedef PetscErrorCode (*SNESLineSearchPreCheckFunc)(SNESLineSearch,Vec,Vec,PetscBool*,void*);
527f1c6b773SPeter Brune typedef PetscErrorCode (*SNESLineSearchVIProjectFunc)(SNES,Vec);
528f1c6b773SPeter Brune typedef PetscErrorCode (*SNESLineSearchVINormFunc)(SNES,Vec,Vec,PetscReal *);
529f1c6b773SPeter Brune typedef PetscErrorCode (*SNESLineSearchPostCheckFunc)(SNESLineSearch,Vec,Vec,Vec,PetscBool *,PetscBool *,void*);
530f1c6b773SPeter Brune typedef PetscErrorCode (*SNESLineSearchApplyFunc)(SNESLineSearch);
531f1c6b773SPeter Brune typedef PetscErrorCode (*SNESLineSearchUserFunc)(SNESLineSearch, void *);
5329e764e56SPeter Brune 
533f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchCreate(MPI_Comm, SNESLineSearch*);
534f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchReset(SNESLineSearch);
5357f1410a3SPeter Brune extern PetscErrorCode SNESLineSearchView(SNESLineSearch,PetscViewer);
536f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchDestroy(SNESLineSearch *);
537f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchSetType(SNESLineSearch, const SNESLineSearchType);
538f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchSetFromOptions(SNESLineSearch);
539f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchSetUp(SNESLineSearch);
540f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchApply(SNESLineSearch, Vec, Vec, PetscReal *, Vec);
541f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchPreCheck(SNESLineSearch, PetscBool *);
542f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchPostCheck(SNESLineSearch, PetscBool *, PetscBool *);
543f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchGetWork(SNESLineSearch, PetscInt);
5449e764e56SPeter Brune 
5459bd66eb0SPeter Brune /* set the functions for precheck and postcheck */
54686d74e61SPeter Brune 
547f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchSetPreCheck(SNESLineSearch, SNESLineSearchPreCheckFunc, void *ctx);
548f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchSetPostCheck(SNESLineSearch, SNESLineSearchPostCheckFunc, void *ctx);
5499e764e56SPeter Brune 
550f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchGetPreCheck(SNESLineSearch, SNESLineSearchPreCheckFunc*, void **ctx);
551f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchGetPostCheck(SNESLineSearch, SNESLineSearchPostCheckFunc*, void **ctx);
5529e764e56SPeter Brune 
5539bd66eb0SPeter Brune /* set the functions for VI-specific line search operations */
5549bd66eb0SPeter Brune 
555f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchSetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFunc, SNESLineSearchVINormFunc);
556f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchGetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFunc*, SNESLineSearchVINormFunc*);
5579bd66eb0SPeter Brune 
5589e764e56SPeter Brune /* pointers to the associated SNES in order to be able to get the function evaluation out */
559f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchSetSNES(SNESLineSearch,SNES);
560f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchGetSNES(SNESLineSearch,SNES*);
5619e764e56SPeter Brune 
5629e764e56SPeter Brune /* set and get the parameters and vectors */
563f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchGetTolerances(SNESLineSearch,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscInt*);
564f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchSetTolerances(SNESLineSearch,PetscReal,PetscReal,PetscReal,PetscReal,PetscReal,PetscInt);
5659e764e56SPeter Brune 
566f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchPreCheckPicard(SNESLineSearch,Vec,Vec,PetscBool*,void*);
56786d74e61SPeter Brune 
568f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchGetLambda(SNESLineSearch,PetscReal*);
569f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchSetLambda(SNESLineSearch,PetscReal);
5709e764e56SPeter Brune 
571f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchGetDamping(SNESLineSearch,PetscReal*);
572f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchSetDamping(SNESLineSearch,PetscReal);
5739e764e56SPeter Brune 
57459405d5eSPeter Brune extern PetscErrorCode  SNESLineSearchGetOrder(SNESLineSearch,SNESLineSearchOrder *order);
57559405d5eSPeter Brune extern PetscErrorCode  SNESLineSearchSetOrder(SNESLineSearch,SNESLineSearchOrder order);
57659405d5eSPeter Brune 
577f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchGetSuccess(SNESLineSearch, PetscBool*);
578f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchSetSuccess(SNESLineSearch, PetscBool);
5799e764e56SPeter Brune 
580f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchGetVecs(SNESLineSearch,Vec*,Vec*,Vec*,Vec*,Vec*);
581f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchSetVecs(SNESLineSearch,Vec,Vec,Vec,Vec,Vec);
5829e764e56SPeter Brune 
583f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchGetNorms(SNESLineSearch, PetscReal *, PetscReal *, PetscReal *);
584f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchSetNorms(SNESLineSearch, PetscReal, PetscReal, PetscReal);
585f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchComputeNorms(SNESLineSearch);
5866f263ca3SPeter Brune extern PetscErrorCode SNESLineSearchSetComputeNorms(SNESLineSearch, PetscBool);
5879e764e56SPeter Brune 
588f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchSetMonitor(SNESLineSearch, PetscBool);
589f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchGetMonitor(SNESLineSearch, PetscViewer*);
5909e764e56SPeter Brune 
591f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchAppendOptionsPrefix(SNESLineSearch, const char prefix[]);
592f1c6b773SPeter Brune extern PetscErrorCode  SNESLineSearchGetOptionsPrefix(SNESLineSearch, const char *prefix[]);
5939e764e56SPeter Brune 
5949e764e56SPeter Brune 
5959e764e56SPeter Brune /* Shell interface functions */
596f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchShellSetUserFunc(SNESLineSearch,SNESLineSearchUserFunc,void*);
597f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchShellGetUserFunc(SNESLineSearch,SNESLineSearchUserFunc*,void**);
5989e764e56SPeter Brune 
5992f4102e2SPeter Brune /* BT interface functions */
6002f4102e2SPeter Brune extern PetscErrorCode SNESLineSearchBTSetAlpha(SNESLineSearch, PetscReal);
601754fc1b0SHong Zhang extern PetscErrorCode SNESLineSearchBTGetAlpha(SNESLineSearch, PetscReal*);
6022f4102e2SPeter Brune 
6039e764e56SPeter Brune /*register line search types */
604f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchRegister(const char[],const char[],const char[],PetscErrorCode(*)(SNESLineSearch));
605f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchRegisterAll(const char path[]);
606f1c6b773SPeter Brune extern PetscErrorCode SNESLineSearchRegisterDestroy(void);
6079e764e56SPeter Brune 
6089e764e56SPeter Brune #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
609f1c6b773SPeter Brune #define SNESLineSearchRegisterDynamic(a,b,c,d) SNESLineSearchRegister(a,b,c,0)
6109e764e56SPeter Brune #else
611f1c6b773SPeter Brune #define SNESLineSearchRegisterDynamic(a,b,c,d) SNESLineSearchRegister(a,b,c,d)
6129e764e56SPeter Brune #endif
6139e764e56SPeter Brune 
614720c9a41SShri Abhyankar /* Routines for VI solver */
6157087cfbeSBarry Smith extern PetscErrorCode  SNESVISetVariableBounds(SNES,Vec,Vec);
61677cdaf69SJed Brown extern PetscErrorCode  SNESVISetComputeVariableBounds(SNES, PetscErrorCode (*)(SNES,Vec,Vec));
617ed70e96aSJungho Lee extern PetscErrorCode  SNESVIGetInactiveSet(SNES,IS*);
618c2fc9fa9SBarry Smith extern PetscErrorCode  SNESVIGetActiveSetIS(SNES,Vec,Vec,IS*);
619c2fc9fa9SBarry Smith extern PetscErrorCode  SNESVIComputeInactiveSetFnorm(SNES,Vec,Vec,PetscReal*);
620cb5fe31bSShri Abhyankar extern PetscErrorCode  SNESVISetRedundancyCheck(SNES,PetscErrorCode(*)(SNES,IS,IS*,void*),void*);
62101f0b76bSBarry Smith #define SNES_VI_INF   1.0e20
62201f0b76bSBarry Smith #define SNES_VI_NINF -1.0e20
623f5ea5bd2SShri Abhyankar 
6247087cfbeSBarry Smith extern PetscErrorCode  SNESTestLocalMin(SNES);
625da9b6338SBarry Smith 
626eef9c623SLois Curfman McInnes /* Should this routine be private? */
6277087cfbeSBarry Smith extern PetscErrorCode  SNESComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*);
628ddbbdb52SLois Curfman McInnes 
6297087cfbeSBarry Smith extern PetscErrorCode SNESSetDM(SNES,DM);
6307087cfbeSBarry Smith extern PetscErrorCode SNESGetDM(SNES,DM*);
63131823bd8SMatthew G Knepley extern PetscErrorCode SNESSetPC(SNES,SNES);
63231823bd8SMatthew G Knepley extern PetscErrorCode SNESGetPC(SNES,SNES*);
633f1c6b773SPeter Brune extern PetscErrorCode SNESSetSNESLineSearch(SNES,SNESLineSearch);
634f1c6b773SPeter Brune extern PetscErrorCode SNESGetSNESLineSearch(SNES,SNESLineSearch*);
63545fc2758SJed Brown extern PetscErrorCode SNESRestrictHookAdd(SNES,PetscErrorCode (*)(SNES,SNES,void*),void*);
63645fc2758SJed Brown extern PetscErrorCode SNESRestrictHooksRun(SNES,SNES);
6376c699258SBarry Smith 
6386cab3a1bSJed Brown extern PetscErrorCode SNESSetUpMatrices(SNES);
6396cab3a1bSJed Brown extern PetscErrorCode DMSNESSetFunction(DM,PetscErrorCode(*)(SNES,Vec,Vec,void*),void*);
6406cab3a1bSJed Brown extern PetscErrorCode DMSNESGetFunction(DM,PetscErrorCode(**)(SNES,Vec,Vec,void*),void**);
6416cab3a1bSJed Brown extern PetscErrorCode DMSNESSetGS(DM,PetscErrorCode(*)(SNES,Vec,Vec,void*),void*);
6426cab3a1bSJed Brown extern PetscErrorCode DMSNESGetGS(DM,PetscErrorCode(**)(SNES,Vec,Vec,void*),void**);
6436cab3a1bSJed Brown extern PetscErrorCode DMSNESSetJacobian(DM,PetscErrorCode(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void*);
6446cab3a1bSJed Brown extern PetscErrorCode DMSNESGetJacobian(DM,PetscErrorCode(**)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void**);
6456cab3a1bSJed Brown 
6466cab3a1bSJed Brown extern PetscErrorCode DMDASNESSetFunctionLocal(DM,PetscErrorCode(*)(DMDALocalInfo*,void*,void*,void*),void*);
6476cab3a1bSJed Brown extern PetscErrorCode DMDASNESSetJacobianLocal(DM,PetscErrorCode(*)(DMDALocalInfo*,void*,Mat,Mat,MatStructure*,void*),void*);
6486cab3a1bSJed Brown 
649b665c654SMatthew G Knepley /* Routines for Multiblock solver */
650aeed3662SMatthew G Knepley extern PetscErrorCode SNESMultiblockSetFields(SNES, const char [], PetscInt, const PetscInt *);
651aeed3662SMatthew G Knepley extern PetscErrorCode SNESMultiblockSetIS(SNES, const char [], IS);
652aeed3662SMatthew G Knepley extern PetscErrorCode SNESMultiblockSetBlockSize(SNES, PetscInt);
653aeed3662SMatthew G Knepley extern PetscErrorCode SNESMultiblockSetType(SNES, PCCompositeType);
654aeed3662SMatthew G Knepley 
65537e1895aSJed Brown /*J
65637e1895aSJed Brown     SNESMSType - String with the name of a PETSc SNESMS method.
65737e1895aSJed Brown 
65837e1895aSJed Brown    Level: intermediate
65937e1895aSJed Brown 
66037e1895aSJed Brown .seealso: SNESMSSetType(), SNES
66137e1895aSJed Brown J*/
66237e1895aSJed Brown #define SNESMSType char*
66337e1895aSJed Brown #define SNESMSM62       "m62"
66437e1895aSJed Brown #define SNESMSEULER     "euler"
665a97cb6bcSJed Brown #define SNESMSJAMESON83 "jameson83"
666a97cb6bcSJed Brown #define SNESMSVLTP21    "vltp21"
667a97cb6bcSJed Brown #define SNESMSVLTP31    "vltp31"
668a97cb6bcSJed Brown #define SNESMSVLTP41    "vltp41"
669a97cb6bcSJed Brown #define SNESMSVLTP51    "vltp51"
670a97cb6bcSJed Brown #define SNESMSVLTP61    "vltp61"
67137e1895aSJed Brown 
67237e1895aSJed Brown extern PetscErrorCode SNESMSRegister(const SNESMSType,PetscInt,PetscInt,PetscReal,const PetscReal[],const PetscReal[],const PetscReal[]);
67337e1895aSJed Brown extern PetscErrorCode SNESMSSetType(SNES,const SNESMSType);
67437e1895aSJed Brown extern PetscErrorCode SNESMSFinalizePackage(void);
67537e1895aSJed Brown extern PetscErrorCode SNESMSInitializePackage(const char path[]);
67637e1895aSJed Brown extern PetscErrorCode SNESMSRegisterDestroy(void);
67737e1895aSJed Brown extern PetscErrorCode SNESMSRegisterAll(void);
67837e1895aSJed Brown 
679e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
680ce3d82beSBarry Smith #endif
681