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