xref: /petsc/include/petscsnes.h (revision f3aaf7366bbc7a33966ee24f401bc15bc56f5905)
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"
7e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN
8b1f5cb9dSBarry Smith 
9435da068SBarry Smith /*S
10435da068SBarry Smith      SNES - Abstract PETSc object that manages all nonlinear solves
11435da068SBarry Smith 
12435da068SBarry Smith    Level: beginner
13435da068SBarry Smith 
14435da068SBarry Smith   Concepts: nonlinear solvers
15435da068SBarry Smith 
1694b7f48cSBarry Smith .seealso:  SNESCreate(), SNESSetType(), SNESType, TS, KSP, KSP, PC
17435da068SBarry Smith S*/
18f09e8eb9SSatish Balay typedef struct _p_SNES* SNES;
19435da068SBarry Smith 
2076bdecfbSBarry Smith /*J
21435da068SBarry Smith     SNESType - String with the name of a PETSc SNES method or the creation function
22435da068SBarry Smith        with an optional dynamic library name, for example
23435da068SBarry Smith        http://www.mcs.anl.gov/petsc/lib.a:mysnescreate()
24435da068SBarry Smith 
25435da068SBarry Smith    Level: beginner
26435da068SBarry Smith 
27435da068SBarry Smith .seealso: SNESSetType(), SNES
2876bdecfbSBarry Smith J*/
29a313700dSBarry Smith #define SNESType char*
30eef9c623SLois Curfman McInnes #define SNESLS           "ls"
31eef9c623SLois Curfman McInnes #define SNESTR           "tr"
321d6018f0SLisandro Dalcin #define SNESPYTHON       "python"
33eef9c623SLois Curfman McInnes #define SNESTEST         "test"
34d5c3842bSBarry Smith #define SNESNRICHARDSON  "nrichardson"
35b79b07cfSJed Brown #define SNESKSPONLY      "ksponly"
36c2fc9fa9SBarry Smith #define SNESVIRS         "virs"
37c2fc9fa9SBarry Smith #define SNESVISS         "viss"
384a0c5b0cSMatthew G Knepley #define SNESNGMRES       "ngmres"
394b11644fSPeter Brune #define SNESQN           "qn"
40c5ae4b9aSBarry Smith #define SNESSHELL        "shell"
413542a6bcSPeter Brune #define SNESGS           "gs"
42fef7b6d8SPeter Brune #define SNESNCG          "ncg"
43d5c3842bSBarry Smith #define SNESSORQN        "sorqn"
44421d9b32SPeter Brune #define SNESFAS          "fas"
4537e1895aSJed Brown #define SNESMS           "ms"
46d5c3842bSBarry Smith 
47deeb6e72SMatthew Knepley /* Logging support */
487087cfbeSBarry Smith extern PetscClassId  SNES_CLASSID;
49deeb6e72SMatthew Knepley 
507087cfbeSBarry Smith extern PetscErrorCode  SNESInitializePackage(const char[]);
51deeb6e72SMatthew Knepley 
527087cfbeSBarry Smith extern PetscErrorCode  SNESCreate(MPI_Comm,SNES*);
5337596af1SLisandro Dalcin extern PetscErrorCode  SNESReset(SNES);
54fcfd50ebSBarry Smith extern PetscErrorCode  SNESDestroy(SNES*);
557087cfbeSBarry Smith extern PetscErrorCode  SNESSetType(SNES,const SNESType);
56228d79bcSJed Brown extern PetscErrorCode  SNESMonitor(SNES,PetscInt,PetscReal);
57c2efdce3SBarry Smith extern PetscErrorCode  SNESMonitorSet(SNES,PetscErrorCode(*)(SNES,PetscInt,PetscReal,void*),void *,PetscErrorCode (*)(void**));
587087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorCancel(SNES);
597087cfbeSBarry Smith extern PetscErrorCode  SNESSetConvergenceHistory(SNES,PetscReal[],PetscInt[],PetscInt,PetscBool );
607087cfbeSBarry Smith extern PetscErrorCode  SNESGetConvergenceHistory(SNES,PetscReal*[],PetscInt *[],PetscInt *);
617087cfbeSBarry Smith extern PetscErrorCode  SNESSetUp(SNES);
627087cfbeSBarry Smith extern PetscErrorCode  SNESSolve(SNES,Vec,Vec);
637087cfbeSBarry Smith extern PetscErrorCode  SNESSetErrorIfNotConverged(SNES,PetscBool );
647087cfbeSBarry Smith extern PetscErrorCode  SNESGetErrorIfNotConverged(SNES,PetscBool  *);
65e113a28aSBarry Smith 
6684cb2905SBarry Smith 
677087cfbeSBarry Smith extern PetscErrorCode  SNESAddOptionsChecker(PetscErrorCode (*)(SNES));
684d8f6ca9SMatthew Knepley 
697087cfbeSBarry Smith extern PetscErrorCode  SNESSetUpdate(SNES, PetscErrorCode (*)(SNES, PetscInt));
707087cfbeSBarry Smith extern PetscErrorCode  SNESDefaultUpdate(SNES, PetscInt);
714d8f6ca9SMatthew Knepley 
72b0a32e0cSBarry Smith extern PetscFList SNESList;
737087cfbeSBarry Smith extern PetscErrorCode  SNESRegisterDestroy(void);
747087cfbeSBarry Smith extern PetscErrorCode  SNESRegisterAll(const char[]);
7584cb2905SBarry Smith 
767087cfbeSBarry Smith extern PetscErrorCode  SNESRegister(const char[],const char[],const char[],PetscErrorCode (*)(SNES));
7730de9b25SBarry Smith 
7830de9b25SBarry Smith /*MC
7930de9b25SBarry Smith    SNESRegisterDynamic - Adds a method to the nonlinear solver package.
8030de9b25SBarry Smith 
8130de9b25SBarry Smith    Synopsis:
821890ba74SBarry Smith    PetscErrorCode SNESRegisterDynamic(const char *name_solver,const char *path,const char *name_create,PetscErrorCode (*routine_create)(SNES))
8330de9b25SBarry Smith 
8430de9b25SBarry Smith    Not collective
8530de9b25SBarry Smith 
8630de9b25SBarry Smith    Input Parameters:
8730de9b25SBarry Smith +  name_solver - name of a new user-defined solver
8830de9b25SBarry Smith .  path - path (either absolute or relative) the library containing this solver
8930de9b25SBarry Smith .  name_create - name of routine to create method context
9030de9b25SBarry Smith -  routine_create - routine to create method context
9130de9b25SBarry Smith 
9230de9b25SBarry Smith    Notes:
9330de9b25SBarry Smith    SNESRegisterDynamic() may be called multiple times to add several user-defined solvers.
9430de9b25SBarry Smith 
9530de9b25SBarry Smith    If dynamic libraries are used, then the fourth input argument (routine_create)
9630de9b25SBarry Smith    is ignored.
9730de9b25SBarry Smith 
98ab901514SBarry Smith    Environmental variables such as ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR},
9930de9b25SBarry Smith    and others of the form ${any_environmental_variable} occuring in pathname will be
10030de9b25SBarry Smith    replaced with appropriate values.
10130de9b25SBarry Smith 
10230de9b25SBarry Smith    Sample usage:
10330de9b25SBarry Smith .vb
10430de9b25SBarry Smith    SNESRegisterDynamic("my_solver",/home/username/my_lib/lib/libg/solaris/mylib.a,
10530de9b25SBarry Smith                 "MySolverCreate",MySolverCreate);
10630de9b25SBarry Smith .ve
10730de9b25SBarry Smith 
10830de9b25SBarry Smith    Then, your solver can be chosen with the procedural interface via
10930de9b25SBarry Smith $     SNESSetType(snes,"my_solver")
11030de9b25SBarry Smith    or at runtime via the option
11130de9b25SBarry Smith $     -snes_type my_solver
11230de9b25SBarry Smith 
11330de9b25SBarry Smith    Level: advanced
11430de9b25SBarry Smith 
11530de9b25SBarry Smith     Note: If your function is not being put into a shared library then use SNESRegister() instead
11630de9b25SBarry Smith 
11730de9b25SBarry Smith .keywords: SNES, nonlinear, register
11830de9b25SBarry Smith 
11930de9b25SBarry Smith .seealso: SNESRegisterAll(), SNESRegisterDestroy()
12030de9b25SBarry Smith M*/
121aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
122f1af5d2fSBarry Smith #define SNESRegisterDynamic(a,b,c,d) SNESRegister(a,b,c,0)
123b2002411SLois Curfman McInnes #else
124f1af5d2fSBarry Smith #define SNESRegisterDynamic(a,b,c,d) SNESRegister(a,b,c,d)
125b2002411SLois Curfman McInnes #endif
126b2002411SLois Curfman McInnes 
1277087cfbeSBarry Smith extern PetscErrorCode  SNESGetKSP(SNES,KSP*);
1287087cfbeSBarry Smith extern PetscErrorCode  SNESSetKSP(SNES,KSP);
1297087cfbeSBarry Smith extern PetscErrorCode  SNESGetSolution(SNES,Vec*);
1307087cfbeSBarry Smith extern PetscErrorCode  SNESGetSolutionUpdate(SNES,Vec*);
1312d4b5aceSLisandro Dalcin extern PetscErrorCode  SNESGetRhs(SNES,Vec*);
1327087cfbeSBarry Smith extern PetscErrorCode  SNESView(SNES,PetscViewer);
1337bc3d0afSSatish Balay 
1347087cfbeSBarry Smith extern PetscErrorCode  SNESSetOptionsPrefix(SNES,const char[]);
1357087cfbeSBarry Smith extern PetscErrorCode  SNESAppendOptionsPrefix(SNES,const char[]);
1367087cfbeSBarry Smith extern PetscErrorCode  SNESGetOptionsPrefix(SNES,const char*[]);
1377087cfbeSBarry Smith extern PetscErrorCode  SNESSetFromOptions(SNES);
138c699ede6SMatthew G Knepley extern PetscErrorCode  SNESDefaultGetWork(SNES,PetscInt);
13940191667SLois Curfman McInnes 
1407087cfbeSBarry Smith extern PetscErrorCode  MatCreateSNESMF(SNES,Mat*);
1417087cfbeSBarry Smith extern PetscErrorCode  MatMFFDComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
1428f6e3e37SBarry Smith 
1437087cfbeSBarry Smith extern PetscErrorCode  MatDAADSetSNES(Mat,SNES);
1443a7fca6bSBarry Smith 
1457087cfbeSBarry Smith extern PetscErrorCode  SNESGetType(SNES,const SNESType*);
1467087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorDefault(SNES,PetscInt,PetscReal,void *);
1477087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorRange(SNES,PetscInt,PetscReal,void *);
1487087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorRatio(SNES,PetscInt,PetscReal,void *);
149649052a6SBarry Smith extern PetscErrorCode  SNESMonitorSetRatio(SNES,PetscViewer);
1507087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorSolution(SNES,PetscInt,PetscReal,void *);
1517087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorResidual(SNES,PetscInt,PetscReal,void *);
1527087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorSolutionUpdate(SNES,PetscInt,PetscReal,void *);
1537087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorDefaultShort(SNES,PetscInt,PetscReal,void *);
1547087cfbeSBarry Smith extern PetscErrorCode  SNESSetTolerances(SNES,PetscReal,PetscReal,PetscReal,PetscInt,PetscInt);
1557087cfbeSBarry Smith extern PetscErrorCode  SNESGetTolerances(SNES,PetscReal*,PetscReal*,PetscReal*,PetscInt*,PetscInt*);
1567087cfbeSBarry Smith extern PetscErrorCode  SNESSetTrustRegionTolerance(SNES,PetscReal);
1577087cfbeSBarry Smith extern PetscErrorCode  SNESGetFunctionNorm(SNES,PetscReal*);
158360c497dSPeter Brune extern PetscErrorCode  SNESSetFunctionNorm(SNES,PetscReal);
1597087cfbeSBarry Smith extern PetscErrorCode  SNESGetIterationNumber(SNES,PetscInt*);
160360c497dSPeter Brune extern PetscErrorCode  SNESSetIterationNumber(SNES,PetscInt);
1613d4c4710SBarry Smith 
1627087cfbeSBarry Smith extern PetscErrorCode  SNESGetNonlinearStepFailures(SNES,PetscInt*);
1637087cfbeSBarry Smith extern PetscErrorCode  SNESSetMaxNonlinearStepFailures(SNES,PetscInt);
1647087cfbeSBarry Smith extern PetscErrorCode  SNESGetMaxNonlinearStepFailures(SNES,PetscInt*);
1657087cfbeSBarry Smith extern PetscErrorCode  SNESGetNumberFunctionEvals(SNES,PetscInt*);
166b850b91aSLisandro Dalcin 
1677087cfbeSBarry Smith extern PetscErrorCode  SNESSetLagPreconditioner(SNES,PetscInt);
1687087cfbeSBarry Smith extern PetscErrorCode  SNESGetLagPreconditioner(SNES,PetscInt*);
1697087cfbeSBarry Smith extern PetscErrorCode  SNESSetLagJacobian(SNES,PetscInt);
1707087cfbeSBarry Smith extern PetscErrorCode  SNESGetLagJacobian(SNES,PetscInt*);
171efd51863SBarry Smith extern PetscErrorCode  SNESSetGridSequence(SNES,PetscInt);
172a8054027SBarry Smith 
1737087cfbeSBarry Smith extern PetscErrorCode  SNESGetLinearSolveIterations(SNES,PetscInt*);
1747087cfbeSBarry Smith extern PetscErrorCode  SNESGetLinearSolveFailures(SNES,PetscInt*);
1757087cfbeSBarry Smith extern PetscErrorCode  SNESSetMaxLinearSolveFailures(SNES,PetscInt);
1767087cfbeSBarry Smith extern PetscErrorCode  SNESGetMaxLinearSolveFailures(SNES,PetscInt*);
1773d4c4710SBarry Smith 
1787087cfbeSBarry Smith extern PetscErrorCode  SNESKSPSetUseEW(SNES,PetscBool );
1797087cfbeSBarry Smith extern PetscErrorCode  SNESKSPGetUseEW(SNES,PetscBool *);
1807087cfbeSBarry Smith extern PetscErrorCode  SNESKSPSetParametersEW(SNES,PetscInt,PetscReal,PetscReal,PetscReal,PetscReal,PetscReal,PetscReal);
1817087cfbeSBarry Smith extern PetscErrorCode  SNESKSPGetParametersEW(SNES,PetscInt*,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscReal*,PetscReal*);
182eafb4bcbSBarry Smith 
1837087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorLGCreate(const char[],const char[],int,int,int,int,PetscDrawLG*);
1847087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorLG(SNES,PetscInt,PetscReal,void*);
185fcfd50ebSBarry Smith extern PetscErrorCode  SNESMonitorLGDestroy(PetscDrawLG*);
1867087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorLGRangeCreate(const char[],const char[],int,int,int,int,PetscDrawLG*);
1877087cfbeSBarry Smith extern PetscErrorCode  SNESMonitorLGRange(SNES,PetscInt,PetscReal,void*);
188fcfd50ebSBarry Smith extern PetscErrorCode  SNESMonitorLGRangeDestroy(PetscDrawLG*);
189eafb4bcbSBarry Smith 
1907087cfbeSBarry Smith extern PetscErrorCode  SNESSetApplicationContext(SNES,void *);
191e71120c6SJed Brown extern PetscErrorCode  SNESGetApplicationContext(SNES,void *);
192d25893d9SBarry Smith extern PetscErrorCode  SNESSetComputeApplicationContext(SNES,PetscErrorCode (*)(SNES,void**),PetscErrorCode (*)(void**));
193184914b5SBarry Smith 
1947087cfbeSBarry Smith extern PetscErrorCode  SNESPythonSetType(SNES,const char[]);
1951d6018f0SLisandro Dalcin 
1967087cfbeSBarry Smith extern PetscErrorCode  SNESSetFunctionDomainError(SNES);
197435da068SBarry Smith /*E
198435da068SBarry Smith     SNESConvergedReason - reason a SNES method was said to
199435da068SBarry Smith          have converged or diverged
200435da068SBarry Smith 
201435da068SBarry Smith    Level: beginner
202435da068SBarry Smith 
203f203c74bSBarry Smith    The two most common reasons for divergence are
204f203c74bSBarry Smith $   1) an incorrectly coded or computed Jacobian or
205f203c74bSBarry Smith $   2) failure or lack of convergence in the linear system (in this case we recommend
206f203c74bSBarry Smith $      testing with -pc_type lu to eliminate the linear solver as the cause of the problem).
207f203c74bSBarry Smith 
208f203c74bSBarry Smith    Diverged Reasons:
209f203c74bSBarry Smith .    SNES_DIVERGED_LOCAL_MIN - this can only occur when using the line-search variant of SNES.
210f203c74bSBarry Smith        The line search wants to minimize Q(alpha) = 1/2 || F(x + alpha s) ||^2_2  this occurs
211f203c74bSBarry 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
212f203c74bSBarry Smith        you get Q'(alpha) = -F(x)^T F'(x)^(-1)^T F'(x+alpha s)F(x+alpha s); when alpha = 0
213f203c74bSBarry Smith        Q'(0) = - ||F(x)||^2_2 which is always NEGATIVE if F'(x) is invertible. This means the Newton
214f203c74bSBarry Smith        direction is a descent direction and the line search should succeed if alpha is small enough.
215f203c74bSBarry Smith 
216f203c74bSBarry Smith        If F'(x) is NOT invertible AND F'(x)^T F(x) = 0 then Q'(0) = 0 and the Newton direction
217f203c74bSBarry Smith        is NOT a descent direction so the line search will fail. All one can do at this point
218f203c74bSBarry Smith        is change the initial guess and try again.
219f203c74bSBarry Smith 
220f203c74bSBarry Smith        An alternative explanation: Newton's method can be regarded as replacing the function with
221f203c74bSBarry Smith        its linear approximation and minimizing the 2-norm of that. That is F(x+s) approx F(x) + F'(x)s
222f203c74bSBarry Smith        so we minimize || F(x) + F'(x) s ||^2_2; do this using Least Squares. If F'(x) is invertible then
223f203c74bSBarry 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
224f203c74bSBarry Smith        exists a nontrival (that is F'(x)s != 0) solution to the equation and this direction is
225f203c74bSBarry 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)
226f203c74bSBarry 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
227f203c74bSBarry Smith        and F'(x)^T F'(x) has no negative eigenvalues Q'(0) < 0 so s is a descent direction and the line
228f203c74bSBarry Smith        search should succeed for small enough alpha.
229f203c74bSBarry Smith 
230f203c74bSBarry Smith        Note that this RARELY happens in practice. Far more likely the linear system is not being solved
231f203c74bSBarry Smith        (well enough?) or the Jacobian is wrong.
232f203c74bSBarry Smith 
2334d0a8057SBarry Smith    SNES_DIVERGED_MAX_IT means that the solver reached the maximum number of iterations without satisfying any
2344d0a8057SBarry Smith    convergence criteria. SNES_CONVERGED_ITS means that SNESSkipConverged() was chosen as the convergence test;
2354d0a8057SBarry Smith    thus the usual convergence criteria have not been checked and may or may not be satisfied.
236f203c74bSBarry Smith 
2374d0a8057SBarry Smith    Developer Notes: this must match finclude/petscsnes.h
2384d0a8057SBarry Smith 
2394d0a8057SBarry Smith        The string versions of these are in SNESConvergedReason, if you change any value here you must
2404d0a8057SBarry Smith      also adjust that array.
2415968eb51SBarry Smith 
24246a9e3ceSBarry Smith    Each reason has its own manual page.
24346a9e3ceSBarry Smith 
244435da068SBarry Smith .seealso: SNESSolve(), SNESGetConvergedReason(), KSPConvergedReason, SNESSetConvergenceTest()
245435da068SBarry Smith E*/
246184914b5SBarry Smith typedef enum {/* converged */
24701b82886SBarry Smith               SNES_CONVERGED_FNORM_ABS         =  2, /* ||F|| < atol */
24801b82886SBarry Smith               SNES_CONVERGED_FNORM_RELATIVE    =  3, /* ||F|| < rtol*||F_initial|| */
24946a9e3ceSBarry Smith               SNES_CONVERGED_PNORM_RELATIVE    =  4, /* Newton computed step size small; || delta x || < stol */
2503f149594SLisandro Dalcin               SNES_CONVERGED_ITS               =  5, /* maximum iterations reached */
251184914b5SBarry Smith               SNES_CONVERGED_TR_DELTA          =  7,
252184914b5SBarry Smith               /* diverged */
25346a9e3ceSBarry Smith               SNES_DIVERGED_FUNCTION_DOMAIN     = -1, /* the new x location passed the function is not in the domain of F */
254184914b5SBarry Smith               SNES_DIVERGED_FUNCTION_COUNT      = -2,
25546a9e3ceSBarry Smith               SNES_DIVERGED_LINEAR_SOLVE        = -3, /* the linear solve failed */
256184914b5SBarry Smith               SNES_DIVERGED_FNORM_NAN           = -4,
257184914b5SBarry Smith               SNES_DIVERGED_MAX_IT              = -5,
258647a2e1fSBarry Smith               SNES_DIVERGED_LINE_SEARCH         = -6, /* the line search failed */
2591e633543SBarry Smith               SNES_DIVERGED_INNER               = -7, /* inner solve failed */
26058c775ebSBarry Smith               SNES_DIVERGED_LOCAL_MIN           = -8, /* || J^T b || is small, implies converged to local minimum of F() */
261184914b5SBarry Smith               SNES_CONVERGED_ITERATING          =  0} SNESConvergedReason;
2627935a769SJed Brown extern const char *const*SNESConvergedReasons;
263184914b5SBarry Smith 
264c838673bSBarry Smith /*MC
265c838673bSBarry Smith      SNES_CONVERGED_FNORM_ABS - 2-norm(F) <= abstol
266c838673bSBarry Smith 
267c838673bSBarry Smith    Level: beginner
268c838673bSBarry Smith 
269c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
270c838673bSBarry Smith 
271c838673bSBarry Smith M*/
272c838673bSBarry Smith 
273c838673bSBarry Smith /*MC
274c838673bSBarry Smith      SNES_CONVERGED_FNORM_RELATIVE - 2-norm(F) <= rtol*2-norm(F(x_0)) where x_0 is the initial guess
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
28346a9e3ceSBarry Smith      SNES_CONVERGED_PNORM_RELATIVE - The 2-norm of the last step <= stol * 2-norm(x) where x is the current
28446a9e3ceSBarry Smith           solution and stol is the 4th argument to SNESSetTolerances()
285c838673bSBarry Smith 
286c838673bSBarry Smith    Level: beginner
287c838673bSBarry Smith 
288c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
289c838673bSBarry Smith 
290c838673bSBarry Smith M*/
291c838673bSBarry Smith 
292c838673bSBarry Smith /*MC
293c838673bSBarry Smith      SNES_DIVERGED_FUNCTION_COUNT - The user provided function has been called more times then the final
294c838673bSBarry Smith          argument to SNESSetTolerances()
295c838673bSBarry Smith 
296c838673bSBarry Smith    Level: beginner
297c838673bSBarry Smith 
298c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
299c838673bSBarry Smith 
300c838673bSBarry Smith M*/
301c838673bSBarry Smith 
302c838673bSBarry Smith /*MC
303c838673bSBarry Smith      SNES_DIVERGED_FNORM_NAN - the 2-norm of the current function evaluation is not-a-number (NaN), this
304c838673bSBarry Smith       is usually caused by a division of 0 by 0.
305c838673bSBarry Smith 
306c838673bSBarry Smith    Level: beginner
307c838673bSBarry Smith 
308c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
309c838673bSBarry Smith 
310c838673bSBarry Smith M*/
311c838673bSBarry Smith 
312c838673bSBarry Smith /*MC
313c838673bSBarry Smith      SNES_DIVERGED_MAX_IT - SNESSolve() has reached the maximum number of iterations requested
314c838673bSBarry Smith 
315c838673bSBarry Smith    Level: beginner
316c838673bSBarry Smith 
317c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
318c838673bSBarry Smith 
319c838673bSBarry Smith M*/
320c838673bSBarry Smith 
321c838673bSBarry Smith /*MC
322647a2e1fSBarry Smith      SNES_DIVERGED_LINE_SEARCH - The line search has failed. This only occurs for a SNESType of SNESLS
323c838673bSBarry Smith 
324c838673bSBarry Smith    Level: beginner
325c838673bSBarry Smith 
326c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
327c838673bSBarry Smith 
328c838673bSBarry Smith M*/
329c838673bSBarry Smith 
330c838673bSBarry Smith /*MC
33146a9e3ceSBarry Smith      SNES_DIVERGED_LOCAL_MIN - the algorithm seems to have stagnated at a local minimum that is not zero.
33246a9e3ceSBarry Smith         See the manual page for SNESConvergedReason for more details
333c838673bSBarry Smith 
334c838673bSBarry Smith    Level: beginner
335c838673bSBarry Smith 
336c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
337c838673bSBarry Smith 
338c838673bSBarry Smith M*/
339c838673bSBarry Smith 
340c838673bSBarry Smith /*MC
341c838673bSBarry Smith      SNES_CONERGED_ITERATING - this only occurs if SNESGetConvergedReason() is called during the SNESSolve()
342c838673bSBarry Smith 
343c838673bSBarry Smith    Level: beginner
344c838673bSBarry Smith 
345c838673bSBarry Smith .seealso:  SNESSolve(), SNESGetConvergedReason(), SNESConvergedReason, SNESSetTolerances()
346c838673bSBarry Smith 
347c838673bSBarry Smith M*/
348c838673bSBarry Smith 
3497087cfbeSBarry Smith extern PetscErrorCode  SNESSetConvergenceTest(SNES,PetscErrorCode (*)(SNES,PetscInt,PetscReal,PetscReal,PetscReal,SNESConvergedReason*,void*),void*,PetscErrorCode (*)(void*));
3507087cfbeSBarry Smith extern PetscErrorCode  SNESDefaultConverged(SNES,PetscInt,PetscReal,PetscReal,PetscReal,SNESConvergedReason*,void*);
3517087cfbeSBarry Smith extern PetscErrorCode  SNESSkipConverged(SNES,PetscInt,PetscReal,PetscReal,PetscReal,SNESConvergedReason*,void*);
3527087cfbeSBarry Smith extern PetscErrorCode  SNESGetConvergedReason(SNES,SNESConvergedReason*);
353ddbbdb52SLois Curfman McInnes 
354837ad101SBarry Smith extern PetscErrorCode  SNESDMDAComputeFunction(SNES,Vec,Vec,void*);
355837ad101SBarry Smith extern PetscErrorCode  SNESDMDAComputeJacobianWithAdic(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
356837ad101SBarry Smith extern PetscErrorCode  SNESDMDAComputeJacobianWithAdifor(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
357837ad101SBarry Smith extern PetscErrorCode  SNESDMDAComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
3583a7fca6bSBarry Smith 
359837ad101SBarry Smith extern PetscErrorCode SNESDMMeshComputeFunction(SNES,Vec,Vec,void*);
360837ad101SBarry Smith extern PetscErrorCode SNESDMMeshComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
3617da65231SMatthew G Knepley extern PetscErrorCode SNESDMComplexComputeFunction(SNES,Vec,Vec,void *);
3627da65231SMatthew G Knepley extern PetscErrorCode SNESDMComplexComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
36311f088b5SMatthew G Knepley 
364b67197daSBarry Smith /* --------- Solving systems of nonlinear equations --------------- */
3652d4b5aceSLisandro Dalcin typedef PetscErrorCode (*SNESFunction)(SNES,Vec,Vec,void*);
3662d4b5aceSLisandro Dalcin typedef PetscErrorCode (*SNESJacobian)(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
3673542a6bcSPeter Brune typedef PetscErrorCode (*SNESGSFunction)(SNES,Vec,Vec,void*);
3682d4b5aceSLisandro Dalcin extern PetscErrorCode  SNESSetFunction(SNES,Vec,SNESFunction,void*);
3692d4b5aceSLisandro Dalcin extern PetscErrorCode  SNESGetFunction(SNES,Vec*,SNESFunction*,void**);
3707087cfbeSBarry Smith extern PetscErrorCode  SNESComputeFunction(SNES,Vec,Vec);
3712d4b5aceSLisandro Dalcin extern PetscErrorCode  SNESSetJacobian(SNES,Mat,Mat,SNESJacobian,void*);
3722d4b5aceSLisandro Dalcin extern PetscErrorCode  SNESGetJacobian(SNES,Mat*,Mat*,SNESJacobian*,void**);
3737087cfbeSBarry Smith extern PetscErrorCode  SNESDefaultComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
3747087cfbeSBarry Smith extern PetscErrorCode  SNESDefaultComputeJacobianColor(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
375d25893d9SBarry Smith extern PetscErrorCode  SNESSetComputeInitialGuess(SNES,PetscErrorCode (*)(SNES,Vec,void*),void*);
3768b0a5094SBarry Smith extern PetscErrorCode  SNESSetPicard(SNES,Vec,SNESFunction,Mat,Mat,SNESJacobian,void*);
3778b0a5094SBarry Smith extern PetscErrorCode  SNESGetPicard(SNES,Vec*,SNESFunction*,Mat*,SNESJacobian*,void**);
37817bae607SBarry Smith 
3793542a6bcSPeter Brune extern PetscErrorCode  SNESSetGS(SNES,SNESGSFunction,void*);
3803542a6bcSPeter Brune extern PetscErrorCode  SNESGetGS(SNES,SNESGSFunction*,void**);
381badc63e7SPeter Brune extern PetscErrorCode  SNESSetUseGS(SNES,PetscBool);
382badc63e7SPeter Brune extern PetscErrorCode  SNESGetUseGS(SNES,PetscBool *);
38389b92e6fSPeter Brune extern PetscErrorCode  SNESSetGSSweeps(SNES,PetscInt);
38489b92e6fSPeter Brune extern PetscErrorCode  SNESGetGSSweeps(SNES,PetscInt *);
385646217ecSPeter Brune extern PetscErrorCode  SNESComputeGS(SNES,Vec,Vec);
386646217ecSPeter Brune 
38717bae607SBarry Smith /* --------- Routines specifically for line search methods --------------- */
388490ca623SBarry Smith /*E
38942f4f86dSBarry Smith     SNESLineSearchType - type of line search used in Newton's method as well as VI solvers and Richardson solvers
390490ca623SBarry Smith 
391490ca623SBarry Smith     Level: beginner
392490ca623SBarry Smith 
393490ca623SBarry Smith .seealso: SNESSetFromOptions(), SNESLineSearchSet()
394490ca623SBarry Smith E*/
395*f3aaf736SPeter Brune typedef enum {SNES_LS_BASIC, SNES_LS_BASIC_NONORMS, SNES_LS_QUADRATIC, SNES_LS_CUBIC, SNES_LS_EXACT, SNES_LS_TEST, SNES_LS_CRITICAL, SNES_LS_USER_DEFINED} SNESLineSearchType;
39621167be9SJed Brown extern const char *const SNESLineSearchTypes[];
39721167be9SJed Brown extern const char *SNESLineSearchTypeName(SNESLineSearchType); /* Does bounds checking, use this for viewing */
398490ca623SBarry Smith 
3991e633543SBarry Smith extern PetscErrorCode  SNESLineSearchSet(SNES,PetscErrorCode(*)(SNES,void*,Vec,Vec,Vec,PetscReal,PetscReal,Vec,Vec,PetscReal*,PetscReal*,PetscBool *),void*);
400ea630c6eSPeter Brune extern PetscErrorCode  SNESLineSearchSetType(SNES,SNESLineSearchType);
4011e633543SBarry Smith extern PetscErrorCode  SNESLineSearchNo(SNES,void*,Vec,Vec,Vec,PetscReal,PetscReal,Vec,Vec,PetscReal*,PetscReal*,PetscBool *);
4021e633543SBarry Smith extern PetscErrorCode  SNESLineSearchNoNorms(SNES,void*,Vec,Vec,Vec,PetscReal,PetscReal,Vec,Vec,PetscReal*,PetscReal*,PetscBool *);
4031e633543SBarry Smith extern PetscErrorCode  SNESLineSearchQuadratic(SNES,void*,Vec,Vec,Vec,PetscReal,PetscReal,Vec,Vec,PetscReal*,PetscReal*,PetscBool *);
40415f5eeeaSPeter Brune extern PetscErrorCode  SNESLineSearchCubic(SNES,void*,Vec,Vec,Vec,PetscReal,PetscReal,Vec,Vec,PetscReal*,PetscReal*,PetscBool *);
405*f3aaf736SPeter Brune extern PetscErrorCode  SNESLineSearchCriticalSecant(SNES,void*,Vec,Vec,Vec,PetscReal,PetscReal,Vec,Vec,PetscReal*,PetscReal*,PetscBool *);
406af60355fSPeter Brune extern PetscErrorCode  SNESLineSearchQuadraticSecant(SNES,void*,Vec,Vec,Vec,PetscReal,PetscReal,Vec,Vec,PetscReal*,PetscReal*,PetscBool *);
407e56c5435SBarry Smith 
40805b53524SPeter Brune extern PetscErrorCode  SNESLineSearchApply(SNES,Vec,Vec,Vec,PetscReal,PetscReal,Vec,Vec,PetscReal*,PetscReal*,PetscBool *);
40905b53524SPeter Brune extern PetscErrorCode  SNESLineSearchPreCheckApply(SNES,Vec,Vec,PetscBool*);
41005b53524SPeter Brune extern PetscErrorCode  SNESLineSearchPostCheckApply(SNES,Vec,Vec,Vec,PetscBool*,PetscBool*);
41105b53524SPeter Brune 
4127087cfbeSBarry Smith extern PetscErrorCode  SNESLineSearchSetPostCheck(SNES,PetscErrorCode(*)(SNES,Vec,Vec,Vec,void*,PetscBool *,PetscBool *),void*);
4137087cfbeSBarry Smith extern PetscErrorCode  SNESLineSearchSetPreCheck(SNES,PetscErrorCode(*)(SNES,Vec,Vec,void*,PetscBool *),void*);
41450f6de3fSJed Brown extern PetscErrorCode  SNESLineSearchPreCheckPicard(SNES,Vec,Vec,void*,PetscBool*);
4157087cfbeSBarry Smith extern PetscErrorCode  SNESLineSearchSetParams(SNES,PetscReal,PetscReal,PetscReal);
4167087cfbeSBarry Smith extern PetscErrorCode  SNESLineSearchGetParams(SNES,PetscReal*,PetscReal*,PetscReal*);
4177087cfbeSBarry Smith extern PetscErrorCode  SNESLineSearchSetMonitor(SNES,PetscBool );
41840191667SLois Curfman McInnes 
419c5ae4b9aSBarry Smith extern PetscErrorCode  SNESShellGetContext(SNES,void**);
420c5ae4b9aSBarry Smith extern PetscErrorCode  SNESShellSetContext(SNES,void*);
421c5ae4b9aSBarry Smith extern PetscErrorCode  SNESShellSetSolve(SNES,PetscErrorCode (*)(SNES,Vec));
422c5ae4b9aSBarry Smith 
423720c9a41SShri Abhyankar /* Routines for VI solver */
4247087cfbeSBarry Smith extern PetscErrorCode  SNESVISetVariableBounds(SNES,Vec,Vec);
42577cdaf69SJed Brown extern PetscErrorCode  SNESVISetComputeVariableBounds(SNES, PetscErrorCode (*)(SNES,Vec,Vec));
426ed70e96aSJungho Lee extern PetscErrorCode  SNESVIGetInactiveSet(SNES,IS*);
427c2fc9fa9SBarry Smith extern PetscErrorCode  SNESVIGetActiveSetIS(SNES,Vec,Vec,IS*);
428c2fc9fa9SBarry Smith extern PetscErrorCode  SNESVIComputeInactiveSetFnorm(SNES,Vec,Vec,PetscReal*);
429cb5fe31bSShri Abhyankar extern PetscErrorCode  SNESVISetRedundancyCheck(SNES,PetscErrorCode(*)(SNES,IS,IS*,void*),void*);
43001f0b76bSBarry Smith #define SNES_VI_INF   1.0e20
43101f0b76bSBarry Smith #define SNES_VI_NINF -1.0e20
432f5ea5bd2SShri Abhyankar 
4337087cfbeSBarry Smith extern PetscErrorCode  SNESTestLocalMin(SNES);
434da9b6338SBarry Smith 
435eef9c623SLois Curfman McInnes /* Should this routine be private? */
4367087cfbeSBarry Smith extern PetscErrorCode  SNESComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*);
437ddbbdb52SLois Curfman McInnes 
4387087cfbeSBarry Smith extern PetscErrorCode SNESSetDM(SNES,DM);
4397087cfbeSBarry Smith extern PetscErrorCode SNESGetDM(SNES,DM*);
44031823bd8SMatthew G Knepley extern PetscErrorCode SNESSetPC(SNES,SNES);
44131823bd8SMatthew G Knepley extern PetscErrorCode SNESGetPC(SNES,SNES*);
44245fc2758SJed Brown extern PetscErrorCode SNESRestrictHookAdd(SNES,PetscErrorCode (*)(SNES,SNES,void*),void*);
44345fc2758SJed Brown extern PetscErrorCode SNESRestrictHooksRun(SNES,SNES);
4446c699258SBarry Smith 
445b665c654SMatthew G Knepley /* Routines for Multiblock solver */
446aeed3662SMatthew G Knepley extern PetscErrorCode SNESMultiblockSetFields(SNES, const char [], PetscInt, const PetscInt *);
447aeed3662SMatthew G Knepley extern PetscErrorCode SNESMultiblockSetIS(SNES, const char [], IS);
448aeed3662SMatthew G Knepley extern PetscErrorCode SNESMultiblockSetBlockSize(SNES, PetscInt);
449aeed3662SMatthew G Knepley extern PetscErrorCode SNESMultiblockSetType(SNES, PCCompositeType);
450aeed3662SMatthew G Knepley 
45137e1895aSJed Brown /*J
45237e1895aSJed Brown     SNESMSType - String with the name of a PETSc SNESMS method.
45337e1895aSJed Brown 
45437e1895aSJed Brown    Level: intermediate
45537e1895aSJed Brown 
45637e1895aSJed Brown .seealso: SNESMSSetType(), SNES
45737e1895aSJed Brown J*/
45837e1895aSJed Brown #define SNESMSType char*
45937e1895aSJed Brown #define SNESMSM62       "m62"
46037e1895aSJed Brown #define SNESMSEULER     "euler"
461a97cb6bcSJed Brown #define SNESMSJAMESON83 "jameson83"
462a97cb6bcSJed Brown #define SNESMSVLTP21    "vltp21"
463a97cb6bcSJed Brown #define SNESMSVLTP31    "vltp31"
464a97cb6bcSJed Brown #define SNESMSVLTP41    "vltp41"
465a97cb6bcSJed Brown #define SNESMSVLTP51    "vltp51"
466a97cb6bcSJed Brown #define SNESMSVLTP61    "vltp61"
46737e1895aSJed Brown 
46837e1895aSJed Brown extern PetscErrorCode SNESMSRegister(const SNESMSType,PetscInt,PetscInt,PetscReal,const PetscReal[],const PetscReal[],const PetscReal[]);
46937e1895aSJed Brown extern PetscErrorCode SNESMSSetType(SNES,const SNESMSType);
47037e1895aSJed Brown extern PetscErrorCode SNESMSFinalizePackage(void);
47137e1895aSJed Brown extern PetscErrorCode SNESMSInitializePackage(const char path[]);
47237e1895aSJed Brown extern PetscErrorCode SNESMSRegisterDestroy(void);
47337e1895aSJed Brown extern PetscErrorCode SNESMSRegisterAll(void);
47437e1895aSJed Brown 
475e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
476ce3d82beSBarry Smith #endif
477