xref: /petsc/include/petscsnes.h (revision 6831982abb6453c2f3e25efecb5d0951d333371e)
1 /* $Id: snes.h,v 1.93 1999/09/27 21:33:07 bsmith Exp bsmith $ */
2 /*
3     User interface for the nonlinear solvers and unconstrained minimization package.
4 */
5 #if !defined(__SNES_H)
6 #define __SNES_H
7 #include "sles.h"
8 
9 typedef struct _p_SNES* SNES;
10 #define SNES_COOKIE         PETSC_COOKIE+13
11 #define MATSNESMFCTX_COOKIE PETSC_COOKIE+29
12 
13 #define SNESEQLS          "ls"
14 #define SNESEQTR          "tr"
15 #define SNESEQTEST        "test"
16 #define SNESUMLS          "umls"
17 #define SNESUMTR          "umtr"
18 
19 typedef char *SNESType;
20 
21 typedef enum {SNES_NONLINEAR_EQUATIONS, SNES_UNCONSTRAINED_MINIMIZATION, SNES_LEAST_SQUARES} SNESProblemType;
22 
23 extern int SNESCreate(MPI_Comm,SNESProblemType,SNES*);
24 extern int SNESDestroy(SNES);
25 extern int SNESSetType(SNES,SNESType);
26 extern int SNESSetMonitor(SNES,int(*)(SNES,int,double,void*),void *,int (*)(void *));
27 extern int SNESClearMonitor(SNES);
28 extern int SNESSetConvergenceHistory(SNES,double*,int *,int,PetscTruth);
29 extern int SNESGetConvergenceHistory(SNES,double**,int **,int *);
30 extern int SNESSetUp(SNES,Vec);
31 extern int SNESSolve(SNES,Vec,int*);
32 
33 extern FList SNESList;
34 extern int SNESRegisterDestroy(void);
35 extern int SNESRegisterAll(char *);
36 
37 extern int SNESRegister_Private(char*,char*,char*,int(*)(SNES));
38 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
39 #define SNESRegister(a,b,c,d) SNESRegister_Private(a,b,c,0)
40 #else
41 #define SNESRegister(a,b,c,d) SNESRegister_Private(a,b,c,d)
42 #endif
43 
44 extern int SNESGetSLES(SNES,SLES*);
45 extern int SNESGetSolution(SNES,Vec*);
46 extern int SNESGetSolutionUpdate(SNES,Vec*);
47 extern int SNESGetFunction(SNES,Vec*,void**);
48 extern int SNESPrintHelp(SNES);
49 extern int SNESView(SNES,Viewer);
50 
51 extern int SNESSetOptionsPrefix(SNES,char*);
52 extern int SNESAppendOptionsPrefix(SNES,char*);
53 extern int SNESGetOptionsPrefix(SNES,char**);
54 extern int SNESSetFromOptions(SNES);
55 extern int SNESSetTypeFromOptions(SNES);
56 extern int SNESAddOptionsChecker(int (*)(SNES));
57 
58 extern int MatCreateSNESMF(SNES,Vec,Mat*);
59 extern int MatSNESMFSetFunction(Mat,Vec,int(*)(SNES,Vec,Vec,void*),void *);
60 extern int MatSNESMFAddNullSpace(Mat,PCNullSpace);
61 extern int MatSNESMFSetHHistory(Mat,Scalar *,int);
62 extern int MatSNESMFResetHHistory(Mat);
63 extern int MatSNESMFSetFunctionError(Mat,double);
64 extern int MatSNESMFGetH(Mat,Scalar *);
65 extern int MatSNESMFKSPMonitor(KSP,int,double,void *);
66 extern int MatSNESMFSetFromOptions(Mat);
67 typedef struct _p_MatSNESMFCtx   *MatSNESMFCtx;
68 extern int MatSNESMFSetType(Mat,char*);
69 extern int MatSNESMFRegister_Private(char *,char *,char *,int (*)(MatSNESMFCtx));
70 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
71 #define MatSNESMFRegister(a,b,c,d) MatSNESMFRegister_Private(a,b,c,0)
72 #else
73 #define MatSNESMFRegister(a,b,c,d) MatSNESMFRegister_Private(a,b,c,d)
74 #endif
75 extern int MatSNESMFRegisterAll(char *);
76 extern int MatSNESMFRegisterDestroy(void);
77 extern int MatSNESMFDefaultSetUmin(Mat,double);
78 extern int MatSNESMFWPSetComputeNormA(Mat,PetscTruth);
79 extern int MatSNESMFWPSetComputeNormU(Mat,PetscTruth);
80 
81 extern int SNESGetType(SNES,SNESType*);
82 extern int SNESDefaultMonitor(SNES,int,double,void *);
83 extern int SNESVecViewMonitor(SNES,int,double,void *);
84 extern int SNESVecViewMonitorUpdate(SNES,int,double,void *);
85 extern int SNESDefaultSMonitor(SNES,int,double,void *);
86 extern int SNESSetTolerances(SNES,double,double,double,int,int);
87 extern int SNESGetTolerances(SNES,double*,double*,double*,int*,int*);
88 extern int SNESSetTrustRegionTolerance(SNES,double);
89 extern int SNESGetIterationNumber(SNES,int*);
90 extern int SNESGetFunctionNorm(SNES,Scalar*);
91 extern int SNESGetNumberUnsuccessfulSteps(SNES,int*);
92 extern int SNESGetNumberLinearIterations(SNES,int*);
93 extern int SNES_KSP_SetParametersEW(SNES,int,double,double,double,double,double,double);
94 extern int SNES_KSP_SetConvergenceTestEW(SNES);
95 
96 /*
97      Reuse the default KSP monitor routines for SNES
98 */
99 extern int SNESLGMonitorCreate(char*,char*,int,int,int,int,DrawLG*);
100 extern int SNESLGMonitor(SNES,int,double,void*);
101 extern int SNESLGMonitorDestroy(DrawLG);
102 
103 extern int SNESSetApplicationContext(SNES,void *);
104 extern int SNESGetApplicationContext(SNES,void **);
105 
106 typedef enum {/* converged */
107               SNES_CONVERGED_FNORM_ABS         =  2, /* F < F_minabs */
108               SNES_CONVERGED_FNORM_RELATIVE    =  3, /* F < F_mintol*F_initial */
109               SNES_CONVERGED_PNORM_RELATIVE    =  4, /* step size small */
110               SNES_CONVERGED_GNORM_ABS         =  5, /* grad F < grad F_min */
111               SNES_CONVERGED_TR_REDUCTION      =  6,
112               SNES_CONVERGED_TR_DELTA          =  7,
113               /* diverged */
114               SNES_DIVERGED_FUNCTION_COUNT     = -2,
115               SNES_DIVERGED_FNORM_NAN          = -4,
116               SNES_DIVERGED_MAX_IT             = -5,
117               SNES_DIVERGED_LS_FAILURE         = -6,
118               SNES_DIVERGED_TR_REDUCTION       = -7,
119               SNES_CONVERGED_ITERATING         =  0} SNESConvergedReason;
120 
121 extern int SNESSetConvergenceTest(SNES,int (*)(SNES,double,double,double,SNESConvergedReason*,void*),void*);
122 extern int SNESConverged_UM_LS(SNES,double,double,double,SNESConvergedReason*,void*);
123 extern int SNESConverged_UM_TR(SNES,double,double,double,SNESConvergedReason*,void*);
124 extern int SNESConverged_EQ_LS(SNES,double,double,double,SNESConvergedReason*,void*);
125 extern int SNESConverged_EQ_TR(SNES,double,double,double,SNESConvergedReason*,void*);
126 extern int SNESGetConvergedReason(SNES,SNESConvergedReason*);
127 
128 /* --------- Solving systems of nonlinear equations --------------- */
129 extern int SNESSetFunction(SNES,Vec,int(*)(SNES,Vec,Vec,void*),void *);
130 extern int SNESComputeFunction(SNES,Vec,Vec);
131 extern int SNESSetJacobian(SNES,Mat,Mat,int(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *);
132 extern int SNESGetJacobian(SNES,Mat*,Mat*,void **);
133 extern int SNESDefaultComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
134 extern int SNESDefaultComputeJacobianColor(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
135 extern int SNESSetLineSearch(SNES,int(*)(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*),void*);
136 extern int SNESNoLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
137 extern int SNESNoLineSearchNoNorms(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
138 extern int SNESCubicLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
139 extern int SNESQuadraticLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
140 extern int SNESSetLineSearchCheck(SNES,int(*)(SNES,void*,Vec,PetscTruth*),void*);
141 extern int SNESSetLineSearchParams(SNES, double, double, double);
142 extern int SNESGetLineSearchParams(SNES, double*, double*, double*);
143 
144 /* --------- Unconstrained minimization routines --------------------------------*/
145 extern int SNESSetHessian(SNES,Mat,Mat,int(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *);
146 extern int SNESGetHessian(SNES,Mat*,Mat*,void **);
147 extern int SNESDefaultComputeHessian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
148 extern int SNESDefaultComputeHessianColor(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
149 extern int SNESSetGradient(SNES,Vec,int(*)(SNES,Vec,Vec,void*),void*);
150 extern int SNESGetGradient(SNES,Vec*,void**);
151 extern int SNESGetGradientNorm(SNES,Scalar*);
152 extern int SNESComputeGradient(SNES,Vec,Vec);
153 extern int SNESSetMinimizationFunction(SNES,int(*)(SNES,Vec,double*,void*),void*);
154 extern int SNESComputeMinimizationFunction(SNES,Vec,double*);
155 extern int SNESGetMinimizationFunction(SNES,double*,void**);
156 extern int SNESSetMinimizationFunctionTolerance(SNES,double);
157 extern int SNESLineSearchSetDampingParameter(SNES,Scalar*);
158 
159 
160 /* Should these 2 routines be private? */
161 extern int SNESComputeHessian(SNES,Vec,Mat*,Mat*,MatStructure*);
162 extern int SNESComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*);
163 
164 #endif
165 
166