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