xref: /petsc/include/petscsnes.h (revision 0a835dfde17e989aa2dfc49c3e55e39ea1705529)
1 /* $Id: petscsnes.h,v 1.98 2000/04/01 04:24:29 bsmith Exp balay $ */
2 /*
3     User interface for the nonlinear solvers and unconstrained minimization package.
4 */
5 #if !defined(__PETSCSNES_H)
6 #define __PETSCSNES_H
7 #include "petscsles.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(char*,char*,char*,int(*)(SNES));
38 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
39 #define SNESRegisterDynamic(a,b,c,d) SNESRegister(a,b,c,0)
40 #else
41 #define SNESRegisterDynamic(a,b,c,d) SNESRegister(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 #define MATSNESMF_DEFAULT "default"
59 #define MATSNESMF_WP      "wp"
60 extern int MatCreateSNESMF(SNES,Vec,Mat*);
61 extern int MatSNESMFSetFunction(Mat,Vec,int(*)(SNES,Vec,Vec,void*),void *);
62 extern int MatSNESMFAddNullSpace(Mat,PCNullSpace);
63 extern int MatSNESMFSetHHistory(Mat,Scalar *,int);
64 extern int MatSNESMFResetHHistory(Mat);
65 extern int MatSNESMFSetFunctionError(Mat,double);
66 extern int MatSNESMFSetPeriod(Mat,int);
67 extern int MatSNESMFGetH(Mat,Scalar *);
68 extern int MatSNESMFKSPMonitor(KSP,int,double,void *);
69 extern int MatSNESMFSetFromOptions(Mat);
70 typedef struct _p_MatSNESMFCtx   *MatSNESMFCtx;
71 typedef char* MatSNESMFType;
72 extern int MatSNESMFSetType(Mat,MatSNESMFType);
73 extern int MatSNESMFRegister(char *,char *,char *,int (*)(MatSNESMFCtx));
74 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
75 #define MatSNESMFRegisterDynamic(a,b,c,d) MatSNESMFRegister(a,b,c,0)
76 #else
77 #define MatSNESMFRegisterDynamic(a,b,c,d) MatSNESMFRegister(a,b,c,d)
78 #endif
79 extern int MatSNESMFRegisterAll(char *);
80 extern int MatSNESMFRegisterDestroy(void);
81 extern int MatSNESMFDefaultSetUmin(Mat,double);
82 extern int MatSNESMFWPSetComputeNormA(Mat,PetscTruth);
83 extern int MatSNESMFWPSetComputeNormU(Mat,PetscTruth);
84 
85 extern int SNESGetType(SNES,SNESType*);
86 extern int SNESDefaultMonitor(SNES,int,double,void *);
87 extern int SNESVecViewMonitor(SNES,int,double,void *);
88 extern int SNESVecViewUpdateMonitor(SNES,int,double,void *);
89 extern int SNESDefaultSMonitor(SNES,int,double,void *);
90 extern int SNESSetTolerances(SNES,double,double,double,int,int);
91 extern int SNESGetTolerances(SNES,double*,double*,double*,int*,int*);
92 extern int SNESSetTrustRegionTolerance(SNES,double);
93 extern int SNESGetIterationNumber(SNES,int*);
94 extern int SNESGetFunctionNorm(SNES,Scalar*);
95 extern int SNESGetNumberUnsuccessfulSteps(SNES,int*);
96 extern int SNESGetNumberLinearIterations(SNES,int*);
97 extern int SNES_KSP_SetParametersEW(SNES,int,double,double,double,double,double,double);
98 extern int SNES_KSP_SetConvergenceTestEW(SNES);
99 
100 /*
101      Reuse the default KSP monitor routines for SNES
102 */
103 extern int SNESLGMonitorCreate(char*,char*,int,int,int,int,DrawLG*);
104 extern int SNESLGMonitor(SNES,int,double,void*);
105 extern int SNESLGMonitorDestroy(DrawLG);
106 
107 extern int SNESSetApplicationContext(SNES,void *);
108 extern int SNESGetApplicationContext(SNES,void **);
109 
110 typedef enum {/* converged */
111               SNES_CONVERGED_FNORM_ABS         =  2, /* F < F_minabs */
112               SNES_CONVERGED_FNORM_RELATIVE    =  3, /* F < F_mintol*F_initial */
113               SNES_CONVERGED_PNORM_RELATIVE    =  4, /* step size small */
114               SNES_CONVERGED_GNORM_ABS         =  5, /* grad F < grad F_min */
115               SNES_CONVERGED_TR_REDUCTION      =  6,
116               SNES_CONVERGED_TR_DELTA          =  7,
117               /* diverged */
118               SNES_DIVERGED_FUNCTION_COUNT     = -2,
119               SNES_DIVERGED_FNORM_NAN          = -4,
120               SNES_DIVERGED_MAX_IT             = -5,
121               SNES_DIVERGED_LS_FAILURE         = -6,
122               SNES_DIVERGED_TR_REDUCTION       = -7,
123               SNES_CONVERGED_ITERATING         =  0} SNESConvergedReason;
124 
125 extern int SNESSetConvergenceTest(SNES,int (*)(SNES,double,double,double,SNESConvergedReason*,void*),void*);
126 extern int SNESConverged_UM_LS(SNES,double,double,double,SNESConvergedReason*,void*);
127 extern int SNESConverged_UM_TR(SNES,double,double,double,SNESConvergedReason*,void*);
128 extern int SNESConverged_EQ_LS(SNES,double,double,double,SNESConvergedReason*,void*);
129 extern int SNESConverged_EQ_TR(SNES,double,double,double,SNESConvergedReason*,void*);
130 extern int SNESGetConvergedReason(SNES,SNESConvergedReason*);
131 
132 /* --------- Solving systems of nonlinear equations --------------- */
133 extern int SNESSetFunction(SNES,Vec,int(*)(SNES,Vec,Vec,void*),void *);
134 extern int SNESComputeFunction(SNES,Vec,Vec);
135 extern int SNESSetJacobian(SNES,Mat,Mat,int(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *);
136 extern int SNESGetJacobian(SNES,Mat*,Mat*,void **);
137 extern int SNESDefaultComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
138 extern int SNESDefaultComputeJacobianColor(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
139 extern int SNESSetLineSearch(SNES,int(*)(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*),void*);
140 extern int SNESNoLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
141 extern int SNESNoLineSearchNoNorms(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
142 extern int SNESCubicLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
143 extern int SNESQuadraticLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
144 extern int SNESSetLineSearchCheck(SNES,int(*)(SNES,void*,Vec,PetscTruth*),void*);
145 extern int SNESSetLineSearchParams(SNES,double,double,double);
146 extern int SNESGetLineSearchParams(SNES,double*,double*,double*);
147 
148 /* --------- Unconstrained minimization routines --------------------------------*/
149 extern int SNESSetHessian(SNES,Mat,Mat,int(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *);
150 extern int SNESGetHessian(SNES,Mat*,Mat*,void **);
151 extern int SNESDefaultComputeHessian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
152 extern int SNESDefaultComputeHessianColor(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
153 extern int SNESSetGradient(SNES,Vec,int(*)(SNES,Vec,Vec,void*),void*);
154 extern int SNESGetGradient(SNES,Vec*,void**);
155 extern int SNESGetGradientNorm(SNES,Scalar*);
156 extern int SNESComputeGradient(SNES,Vec,Vec);
157 extern int SNESSetMinimizationFunction(SNES,int(*)(SNES,Vec,double*,void*),void*);
158 extern int SNESComputeMinimizationFunction(SNES,Vec,double*);
159 extern int SNESGetMinimizationFunction(SNES,double*,void**);
160 extern int SNESSetMinimizationFunctionTolerance(SNES,double);
161 extern int SNESLineSearchSetDampingParameter(SNES,Scalar*);
162 
163 
164 /* Should these 2 routines be private? */
165 extern int SNESComputeHessian(SNES,Vec,Mat*,Mat*,MatStructure*);
166 extern int SNESComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*);
167 
168 #endif
169 
170