xref: /petsc/include/petscsnes.h (revision b7fd4e6495d18b4621d8034d33525ddf6d2b3232)
1*b7fd4e64SBarry Smith /* $Id: snes.h,v 1.97 2000/01/11 21:04:04 bsmith Exp bsmith $ */
2f26ada1bSBarry Smith /*
384cb2905SBarry Smith     User interface for the nonlinear solvers and unconstrained minimization package.
4f26ada1bSBarry Smith */
588d459dfSBarry Smith #if !defined(__SNES_H)
688d459dfSBarry Smith #define __SNES_H
7ce3d82beSBarry Smith #include "sles.h"
8b1f5cb9dSBarry Smith 
9f09e8eb9SSatish Balay typedef struct _p_SNES* SNES;
10ce3d82beSBarry Smith #define SNES_COOKIE         PETSC_COOKIE+13
116831982aSBarry Smith #define MATSNESMFCTX_COOKIE PETSC_COOKIE+29
12b1f5cb9dSBarry Smith 
136831982aSBarry Smith #define SNESEQLS          "ls"
146831982aSBarry Smith #define SNESEQTR          "tr"
156831982aSBarry Smith #define SNESEQTEST        "test"
166831982aSBarry Smith #define SNESUMLS          "umls"
176831982aSBarry Smith #define SNESUMTR          "umtr"
1882bf6240SBarry Smith 
1982bf6240SBarry Smith typedef char *SNESType;
20b1f5cb9dSBarry Smith 
212a03e22aSLois Curfman McInnes typedef enum {SNES_NONLINEAR_EQUATIONS,SNES_UNCONSTRAINED_MINIMIZATION,SNES_LEAST_SQUARES} SNESProblemType;
222a03e22aSLois Curfman McInnes 
234b0e389bSBarry Smith extern int SNESCreate(MPI_Comm,SNESProblemType,SNES*);
244b0e389bSBarry Smith extern int SNESDestroy(SNES);
254b0e389bSBarry Smith extern int SNESSetType(SNES,SNESType);
26b8a78c4aSBarry Smith extern int SNESSetMonitor(SNES,int(*)(SNES,int,double,void*),void *,int (*)(void *));
275cd90555SBarry Smith extern int SNESClearMonitor(SNES);
2884c569c9SBarry Smith extern int SNESSetConvergenceHistory(SNES,double*,int *,int,PetscTruth);
2984c569c9SBarry Smith extern int SNESGetConvergenceHistory(SNES,double**,int **,int *);
308ddd3da0SLois Curfman McInnes extern int SNESSetUp(SNES,Vec);
318ddd3da0SLois Curfman McInnes extern int SNESSolve(SNES,Vec,int*);
3284cb2905SBarry Smith 
33488ecbafSBarry Smith extern FList SNESList;
34cf256101SBarry Smith extern int SNESRegisterDestroy(void);
3582bf6240SBarry Smith extern int SNESRegisterAll(char *);
3684cb2905SBarry Smith 
37f1af5d2fSBarry Smith extern int SNESRegister(char*,char*,char*,int(*)(SNES));
38aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
39f1af5d2fSBarry Smith #define SNESRegisterDynamic(a,b,c,d) SNESRegister(a,b,c,0)
40b2002411SLois Curfman McInnes #else
41f1af5d2fSBarry Smith #define SNESRegisterDynamic(a,b,c,d) SNESRegister(a,b,c,d)
42b2002411SLois Curfman McInnes #endif
43b2002411SLois Curfman McInnes 
44ce3d82beSBarry Smith extern int SNESGetSLES(SNES,SLES*);
45ce3d82beSBarry Smith extern int SNESGetSolution(SNES,Vec*);
46e81d6643SLois Curfman McInnes extern int SNESGetSolutionUpdate(SNES,Vec*);
47184914b5SBarry Smith extern int SNESGetFunction(SNES,Vec*,void**);
48ce3d82beSBarry Smith extern int SNESPrintHelp(SNES);
49e9e17121SLois Curfman McInnes extern int SNESView(SNES,Viewer);
507bc3d0afSSatish Balay 
516daaf66cSBarry Smith extern int SNESSetOptionsPrefix(SNES,char*);
527bc3d0afSSatish Balay extern int SNESAppendOptionsPrefix(SNES,char*);
537bc3d0afSSatish Balay extern int SNESGetOptionsPrefix(SNES,char**);
54ce3d82beSBarry Smith extern int SNESSetFromOptions(SNES);
5515091d37SBarry Smith extern int SNESSetTypeFromOptions(SNES);
56639f9d9dSBarry Smith extern int SNESAddOptionsChecker(int (*)(SNES));
5740191667SLois Curfman McInnes 
58*b7fd4e64SBarry Smith #define MATSNESMF_DEFAULT "default"
59*b7fd4e64SBarry Smith #define MATSNESMF_WP      "wp"
605a655dc6SBarry Smith extern int MatCreateSNESMF(SNES,Vec,Mat*);
61130052c2SBarry Smith extern int MatSNESMFSetFunction(Mat,Vec,int(*)(SNES,Vec,Vec,void*),void *);
62130052c2SBarry Smith extern int MatSNESMFAddNullSpace(Mat,PCNullSpace);
635a655dc6SBarry Smith extern int MatSNESMFSetHHistory(Mat,Scalar *,int);
645a655dc6SBarry Smith extern int MatSNESMFResetHHistory(Mat);
655a655dc6SBarry Smith extern int MatSNESMFSetFunctionError(Mat,double);
66329f5518SBarry Smith extern int MatSNESMFSetPeriod(Mat,int);
675a655dc6SBarry Smith extern int MatSNESMFGetH(Mat,Scalar *);
685a655dc6SBarry Smith extern int MatSNESMFKSPMonitor(KSP,int,double,void *);
695a655dc6SBarry Smith extern int MatSNESMFSetFromOptions(Mat);
705a655dc6SBarry Smith typedef struct _p_MatSNESMFCtx   *MatSNESMFCtx;
71*b7fd4e64SBarry Smith typedef char* MatSNESMFType;
72*b7fd4e64SBarry Smith extern int MatSNESMFSetType(Mat,MatSNESMFType);
73f1af5d2fSBarry Smith extern int MatSNESMFRegister(char *,char *,char *,int (*)(MatSNESMFCtx));
74aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
75f1af5d2fSBarry Smith #define MatSNESMFRegisterDynamic(a,b,c,d) MatSNESMFRegister(a,b,c,0)
769a6cb015SBarry Smith #else
77f1af5d2fSBarry Smith #define MatSNESMFRegisterDynamic(a,b,c,d) MatSNESMFRegister(a,b,c,d)
789a6cb015SBarry Smith #endif
795a655dc6SBarry Smith extern int MatSNESMFRegisterAll(char *);
805a655dc6SBarry Smith extern int MatSNESMFRegisterDestroy(void);
815a655dc6SBarry Smith extern int MatSNESMFDefaultSetUmin(Mat,double);
825a655dc6SBarry Smith extern int MatSNESMFWPSetComputeNormA(Mat,PetscTruth);
835a655dc6SBarry Smith extern int MatSNESMFWPSetComputeNormU(Mat,PetscTruth);
848f6e3e37SBarry Smith 
8582bf6240SBarry Smith extern int SNESGetType(SNES,SNESType*);
86eafb4bcbSBarry Smith extern int SNESDefaultMonitor(SNES,int,double,void *);
873f1db9ecSBarry Smith extern int SNESVecViewMonitor(SNES,int,double,void *);
887c922b88SBarry Smith extern int SNESVecViewUpdateMonitor(SNES,int,double,void *);
89c512e24aSBarry Smith extern int SNESDefaultSMonitor(SNES,int,double,void *);
90d7a720efSLois Curfman McInnes extern int SNESSetTolerances(SNES,double,double,double,int,int);
9133174efeSLois Curfman McInnes extern int SNESGetTolerances(SNES,double*,double*,double*,int*,int*);
9252392280SLois Curfman McInnes extern int SNESSetTrustRegionTolerance(SNES,double);
937e984346SBarry Smith extern int SNESGetIterationNumber(SNES,int*);
944f6d0874SLois Curfman McInnes extern int SNESGetFunctionNorm(SNES,Scalar*);
95a96f0e77SLois Curfman McInnes extern int SNESGetNumberUnsuccessfulSteps(SNES,int*);
96d2bb1046SLois Curfman McInnes extern int SNESGetNumberLinearIterations(SNES,int*);
9755b5a45fSLois Curfman McInnes extern int SNES_KSP_SetParametersEW(SNES,int,double,double,double,double,double,double);
9855b5a45fSLois Curfman McInnes extern int SNES_KSP_SetConvergenceTestEW(SNES);
99eafb4bcbSBarry Smith 
1003369ce9aSBarry Smith /*
1013369ce9aSBarry Smith      Reuse the default KSP monitor routines for SNES
1023369ce9aSBarry Smith */
103df9fa365SBarry Smith extern int SNESLGMonitorCreate(char*,char*,int,int,int,int,DrawLG*);
104ce1608b8SBarry Smith extern int SNESLGMonitor(SNES,int,double,void*);
105df9fa365SBarry Smith extern int SNESLGMonitorDestroy(DrawLG);
106eafb4bcbSBarry Smith 
107c01c455dSBarry Smith extern int SNESSetApplicationContext(SNES,void *);
108c01c455dSBarry Smith extern int SNESGetApplicationContext(SNES,void **);
109184914b5SBarry Smith 
110184914b5SBarry Smith typedef enum {/* converged */
111184914b5SBarry Smith               SNES_CONVERGED_FNORM_ABS         =  2, /* F < F_minabs */
112184914b5SBarry Smith               SNES_CONVERGED_FNORM_RELATIVE    =  3, /* F < F_mintol*F_initial */
113184914b5SBarry Smith               SNES_CONVERGED_PNORM_RELATIVE    =  4, /* step size small */
114184914b5SBarry Smith               SNES_CONVERGED_GNORM_ABS         =  5, /* grad F < grad F_min */
115184914b5SBarry Smith               SNES_CONVERGED_TR_REDUCTION      =  6,
116184914b5SBarry Smith               SNES_CONVERGED_TR_DELTA          =  7,
117184914b5SBarry Smith               /* diverged */
118184914b5SBarry Smith               SNES_DIVERGED_FUNCTION_COUNT     = -2,
119184914b5SBarry Smith               SNES_DIVERGED_FNORM_NAN          = -4,
120184914b5SBarry Smith               SNES_DIVERGED_MAX_IT             = -5,
121184914b5SBarry Smith               SNES_DIVERGED_LS_FAILURE         = -6,
122184914b5SBarry Smith               SNES_DIVERGED_TR_REDUCTION       = -7,
123184914b5SBarry Smith               SNES_CONVERGED_ITERATING         =  0} SNESConvergedReason;
124184914b5SBarry Smith 
125184914b5SBarry Smith extern int SNESSetConvergenceTest(SNES,int (*)(SNES,double,double,double,SNESConvergedReason*,void*),void*);
126184914b5SBarry Smith extern int SNESConverged_UM_LS(SNES,double,double,double,SNESConvergedReason*,void*);
127184914b5SBarry Smith extern int SNESConverged_UM_TR(SNES,double,double,double,SNESConvergedReason*,void*);
128184914b5SBarry Smith extern int SNESConverged_EQ_LS(SNES,double,double,double,SNESConvergedReason*,void*);
129184914b5SBarry Smith extern int SNESConverged_EQ_TR(SNES,double,double,double,SNESConvergedReason*,void*);
130184914b5SBarry Smith extern int SNESGetConvergedReason(SNES,SNESConvergedReason*);
131ddbbdb52SLois Curfman McInnes 
132b67197daSBarry Smith /* --------- Solving systems of nonlinear equations --------------- */
13340191667SLois Curfman McInnes extern int SNESSetFunction(SNES,Vec,int(*)(SNES,Vec,Vec,void*),void *);
13440191667SLois Curfman McInnes extern int SNESComputeFunction(SNES,Vec,Vec);
13540191667SLois Curfman McInnes extern int SNESSetJacobian(SNES,Mat,Mat,int(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *);
13640191667SLois Curfman McInnes extern int SNESGetJacobian(SNES,Mat*,Mat*,void **);
13740191667SLois Curfman McInnes extern int SNESDefaultComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
1382d0c0e3bSBarry Smith extern int SNESDefaultComputeJacobianColor(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
13908405cd6SLois Curfman McInnes extern int SNESSetLineSearch(SNES,int(*)(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*),void*);
14008405cd6SLois Curfman McInnes extern int SNESNoLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
14108405cd6SLois Curfman McInnes extern int SNESNoLineSearchNoNorms(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
14208405cd6SLois Curfman McInnes extern int SNESCubicLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
14308405cd6SLois Curfman McInnes extern int SNESQuadraticLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*);
14408405cd6SLois Curfman McInnes extern int SNESSetLineSearchCheck(SNES,int(*)(SNES,void*,Vec,PetscTruth*),void*);
145130052c2SBarry Smith extern int SNESSetLineSearchParams(SNES,double,double,double);
146130052c2SBarry Smith extern int SNESGetLineSearchParams(SNES,double*,double*,double*);
14740191667SLois Curfman McInnes 
14884cb2905SBarry Smith /* --------- Unconstrained minimization routines --------------------------------*/
149ddbbdb52SLois Curfman McInnes extern int SNESSetHessian(SNES,Mat,Mat,int(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *);
15082590567SLois Curfman McInnes extern int SNESGetHessian(SNES,Mat*,Mat*,void **);
15140191667SLois Curfman McInnes extern int SNESDefaultComputeHessian(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
1524896f4f1SBarry Smith extern int SNESDefaultComputeHessianColor(SNES,Vec,Mat*,Mat*,MatStructure*,void*);
153ddbbdb52SLois Curfman McInnes extern int SNESSetGradient(SNES,Vec,int(*)(SNES,Vec,Vec,void*),void*);
154184914b5SBarry Smith extern int SNESGetGradient(SNES,Vec*,void**);
15525c7317fSLois Curfman McInnes extern int SNESGetGradientNorm(SNES,Scalar*);
156ddbbdb52SLois Curfman McInnes extern int SNESComputeGradient(SNES,Vec,Vec);
15725c7317fSLois Curfman McInnes extern int SNESSetMinimizationFunction(SNES,int(*)(SNES,Vec,double*,void*),void*);
15825c7317fSLois Curfman McInnes extern int SNESComputeMinimizationFunction(SNES,Vec,double*);
159184914b5SBarry Smith extern int SNESGetMinimizationFunction(SNES,double*,void**);
16077c4ece6SBarry Smith extern int SNESSetMinimizationFunctionTolerance(SNES,double);
16182bf6240SBarry Smith extern int SNESLineSearchSetDampingParameter(SNES,Scalar*);
16252392280SLois Curfman McInnes 
1634b0e389bSBarry Smith 
16452392280SLois Curfman McInnes /* Should these 2 routines be private? */
16552392280SLois Curfman McInnes extern int SNESComputeHessian(SNES,Vec,Mat*,Mat*,MatStructure*);
16652392280SLois Curfman McInnes extern int SNESComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*);
167ddbbdb52SLois Curfman McInnes 
168ce3d82beSBarry Smith #endif
169b1f5cb9dSBarry Smith 
170