xref: /petsc/include/petscsnes.h (revision 5a655dc69978bfa5d89a399bdbc880d673ee91a3)
1 /* $Id: snes.h,v 1.83 1999/03/17 23:25:44 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 
12 #define SNES_EQ_LS          "ls"
13 #define SNES_EQ_TR          "tr"
14 #define SNES_EQ_TR_DOG_LEG
15 #define SNES_EQ_TR2_LIN
16 #define SNES_EQ_TEST        "test"
17 #define SNES_UM_LS          "umls"
18 #define SNES_UM_TR          "umtr"
19 
20 typedef char *SNESType;
21 
22 typedef enum {SNES_NONLINEAR_EQUATIONS, SNES_UNCONSTRAINED_MINIMIZATION, SNES_LEAST_SQUARES} SNESProblemType;
23 
24 extern int SNESCreate(MPI_Comm,SNESProblemType,SNES*);
25 extern int SNESDestroy(SNES);
26 extern int SNESSetType(SNES,SNESType);
27 extern int SNESSetMonitor(SNES,int(*)(SNES,int,double,void*),void *);
28 extern int SNESClearMonitor(SNES);
29 extern int SNESSetConvergenceHistory(SNES,double*,int *,int,PetscTruth);
30 extern int SNESGetConvergenceHistory(SNES,double**,int **,int *);
31 extern int SNESSetUp(SNES,Vec);
32 extern int SNESSolve(SNES,Vec,int*);
33 
34 extern FList SNESList;
35 extern int SNESRegisterDestroy(void);
36 extern int SNESRegisterAll(char *);
37 
38 extern int SNESRegister_Private(char*,char*,char*,int(*)(SNES));
39 #if defined(USE_DYNAMIC_LIBRARIES)
40 #define SNESRegister(a,b,c,d) SNESRegister_Private(a,b,c,0)
41 #else
42 #define SNESRegister(a,b,c,d) SNESRegister_Private(a,b,c,d)
43 #endif
44 
45 extern int SNESGetSLES(SNES,SLES*);
46 extern int SNESGetSolution(SNES,Vec*);
47 extern int SNESGetSolutionUpdate(SNES,Vec*);
48 extern int SNESGetFunction(SNES,Vec*);
49 extern int SNESPrintHelp(SNES);
50 extern int SNESView(SNES,Viewer);
51 
52 extern int SNESSetOptionsPrefix(SNES,char*);
53 extern int SNESAppendOptionsPrefix(SNES,char*);
54 extern int SNESGetOptionsPrefix(SNES,char**);
55 extern int SNESSetFromOptions(SNES);
56 extern int SNESSetTypeFromOptions(SNES);
57 extern int SNESAddOptionsChecker(int (*)(SNES));
58 
59 extern int MatCreateSNESMF(SNES,Vec,Mat*);
60 extern int MatSNESMFAddNullSpace(Mat,int,int,Vec *);
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(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 SNESDefaultSMonitor(SNES,int,double,void *);
85 extern int SNESSetTolerances(SNES,double,double,double,int,int);
86 extern int SNESGetTolerances(SNES,double*,double*,double*,int*,int*);
87 extern int SNESSetTrustRegionTolerance(SNES,double);
88 extern int SNESGetIterationNumber(SNES,int*);
89 extern int SNESGetFunctionNorm(SNES,Scalar*);
90 extern int SNESGetNumberUnsuccessfulSteps(SNES,int*);
91 extern int SNESGetNumberLinearIterations(SNES,int*);
92 extern int SNES_KSP_SetParametersEW(SNES,int,double,double,double,double,double,double);
93 extern int SNES_KSP_SetConvergenceTestEW(SNES);
94 
95 /*
96      Reuse the default KSP monitor routines for SNES
97 */
98 #define SNESLGMonitorCreate  KSPLGMonitorCreate
99 #define SNESLGMonitorDestroy KSPLGMonitorDestroy
100 extern int SNESLGMonitor(SNES,int,double,void*);
101 
102 extern int SNESSetApplicationContext(SNES,void *);
103 extern int SNESGetApplicationContext(SNES,void **);
104 extern int SNESSetConvergenceTest(SNES,int (*)(SNES,double,double,double,void*),void*);
105 
106 /* --------- Solving systems of nonlinear equations --------------- */
107 extern int SNESSetFunction(SNES,Vec,int(*)(SNES,Vec,Vec,void*),void *);
108 extern int SNESComputeFunction(SNES,Vec,Vec);
109 extern int SNESSetJacobian(SNES,Mat,Mat,int(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *);
110 extern int SNESGetJacobian(SNES,Mat*,Mat*,void **);
111 extern int SNESDefaultComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
112 extern int SNESDefaultComputeJacobianColor(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
113 extern int SNESConverged_EQ_LS(SNES,double,double,double,void*);
114 extern int SNESConverged_EQ_TR(SNES,double,double,double,void*);
115 extern int SNESSetLineSearch(SNES,int(*)(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*),void*);
116 extern int SNESNoLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
117 extern int SNESNoLineSearchNoNorms(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
118 extern int SNESCubicLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
119 extern int SNESQuadraticLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
120 extern int SNESSetLineSearchCheck(SNES,int(*)(SNES,void*,Vec,PetscTruth*),void*);
121 
122 /* --------- Unconstrained minimization routines --------------------------------*/
123 extern int SNESSetHessian(SNES,Mat,Mat,int(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *);
124 extern int SNESGetHessian(SNES,Mat*,Mat*,void **);
125 extern int SNESDefaultComputeHessian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
126 extern int SNESSetGradient(SNES,Vec,int(*)(SNES,Vec,Vec,void*),void*);
127 extern int SNESGetGradient(SNES,Vec*);
128 extern int SNESGetGradientNorm(SNES,Scalar*);
129 extern int SNESComputeGradient(SNES,Vec,Vec);
130 extern int SNESSetMinimizationFunction(SNES,int(*)(SNES,Vec,double*,void*),void*);
131 extern int SNESComputeMinimizationFunction(SNES,Vec,double*);
132 extern int SNESGetMinimizationFunction(SNES,double*);
133 extern int SNESSetMinimizationFunctionTolerance(SNES,double);
134 extern int SNESLineSearchSetDampingParameter(SNES,Scalar*);
135 extern int SNESConverged_UM_LS(SNES,double,double,double,void*);
136 extern int SNESConverged_UM_TR(SNES,double,double,double,void*);
137 
138 
139 /* Should these 2 routines be private? */
140 extern int SNESComputeHessian(SNES,Vec,Mat*,Mat*,MatStructure*);
141 extern int SNESComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*);
142 
143 #endif
144 
145