1*9a6cb015SBarry Smith /* $Id: snes.h,v 1.75 1998/10/31 23:57:32 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 11b1f5cb9dSBarry Smith 1282bf6240SBarry Smith #define SNES_EQ_LS "ls" 1382bf6240SBarry Smith #define SNES_EQ_TR "tr" 1482bf6240SBarry Smith #define SNES_EQ_TR_DOG_LEG 1582bf6240SBarry Smith #define SNES_EQ_TR2_LIN 1682bf6240SBarry Smith #define SNES_EQ_TEST "test" 1782bf6240SBarry Smith #define SNES_UM_LS "umls" 1882bf6240SBarry Smith #define SNES_UM_TR "umtr" 1982bf6240SBarry Smith 2082bf6240SBarry Smith typedef char *SNESType; 21b1f5cb9dSBarry Smith 222a03e22aSLois Curfman McInnes typedef enum {SNES_NONLINEAR_EQUATIONS, SNES_UNCONSTRAINED_MINIMIZATION, SNES_LEAST_SQUARES} SNESProblemType; 232a03e22aSLois Curfman McInnes 244b0e389bSBarry Smith extern int SNESCreate(MPI_Comm,SNESProblemType,SNES*); 254b0e389bSBarry Smith extern int SNESDestroy(SNES); 264b0e389bSBarry Smith extern int SNESSetType(SNES,SNESType); 27eafb4bcbSBarry Smith extern int SNESSetMonitor(SNES,int(*)(SNES,int,double,void*),void *); 285cd90555SBarry Smith extern int SNESClearMonitor(SNES); 2951979daaSLois Curfman McInnes extern int SNESSetConvergenceHistory(SNES,double*,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 37b2002411SLois Curfman McInnes extern int SNESRegister_Private(char*,char*,char*,int(*)(SNES)); 38b2002411SLois Curfman McInnes #if defined(USE_DYNAMIC_LIBRARIES) 39b2002411SLois Curfman McInnes #define SNESRegister(a,b,c,d) SNESRegister_Private(a,b,c,0) 40b2002411SLois Curfman McInnes #else 41b2002411SLois Curfman McInnes #define SNESRegister(a,b,c,d) SNESRegister_Private(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*); 47eafb4bcbSBarry Smith extern int SNESGetFunction(SNES,Vec*); 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); 55639f9d9dSBarry Smith extern int SNESAddOptionsChecker(int (*)(SNES)); 5640191667SLois Curfman McInnes 57*9a6cb015SBarry Smith extern int MatCreateSNESFDMF(SNES,Vec x,Mat*); 58*9a6cb015SBarry Smith extern int MatSNESFDMFAddNullSpace(Mat,int,int,Vec *); 59*9a6cb015SBarry Smith extern int MatSNESFDMFSetHHistory(Mat,Scalar *,int); 60*9a6cb015SBarry Smith extern int MatSNESFDMFResetHHistory(Mat); 61*9a6cb015SBarry Smith extern int MatSNESFDMFSetFunctionError(Mat,double); 62*9a6cb015SBarry Smith extern int MatSNESFDMFGetH(Mat,Scalar *); 63*9a6cb015SBarry Smith extern int MatSNESFDMFKSPMonitor(KSP,int,double,void *); 64*9a6cb015SBarry Smith extern int MatSNESFDMFSetFromOptions(Mat); 65*9a6cb015SBarry Smith typedef struct _p_MatSNESFDMFCtx *MatSNESFDMFCtx; 66*9a6cb015SBarry Smith extern int MatSNESFDMFSetType(Mat,char*); 67*9a6cb015SBarry Smith extern int MatSNESFDMFRegister_Private(char *,char *,char *,int (*)(MatSNESFDMFCtx)); 68*9a6cb015SBarry Smith #if defined(USE_DYNAMIC_LIBRARIES) 69*9a6cb015SBarry Smith #define MatSNESFDMFRegister(a,b,c,d) MatSNESFDMFRegister_Private(a,b,c,0) 70*9a6cb015SBarry Smith #else 71*9a6cb015SBarry Smith #define MatSNESFDMFRegister(a,b,c,d) MatSNESFDMFRegister_Private(a,b,c,d) 72*9a6cb015SBarry Smith #endif 73*9a6cb015SBarry Smith extern int MatSNESFDMFRegisterAll(char *); 74*9a6cb015SBarry Smith extern int MatSNESFDMFRegisterDestroy(void); 75*9a6cb015SBarry Smith extern int MatSNESFDMFDefaultSetUmin(Mat,double); 768f6e3e37SBarry Smith 7782bf6240SBarry Smith extern int SNESGetType(SNES,SNESType*); 78eafb4bcbSBarry Smith extern int SNESDefaultMonitor(SNES,int,double,void *); 79c512e24aSBarry Smith extern int SNESDefaultSMonitor(SNES,int,double,void *); 80d7a720efSLois Curfman McInnes extern int SNESSetTolerances(SNES,double,double,double,int,int); 8133174efeSLois Curfman McInnes extern int SNESGetTolerances(SNES,double*,double*,double*,int*,int*); 8252392280SLois Curfman McInnes extern int SNESSetTrustRegionTolerance(SNES,double); 837e984346SBarry Smith extern int SNESGetIterationNumber(SNES,int*); 844f6d0874SLois Curfman McInnes extern int SNESGetFunctionNorm(SNES,Scalar*); 85a96f0e77SLois Curfman McInnes extern int SNESGetNumberUnsuccessfulSteps(SNES,int*); 86d2bb1046SLois Curfman McInnes extern int SNESGetNumberLinearIterations(SNES,int*); 8755b5a45fSLois Curfman McInnes extern int SNES_KSP_SetParametersEW(SNES,int,double,double,double,double,double,double); 8855b5a45fSLois Curfman McInnes extern int SNES_KSP_SetConvergenceTestEW(SNES); 89eafb4bcbSBarry Smith 903369ce9aSBarry Smith /* 913369ce9aSBarry Smith Reuse the default KSP monitor routines for SNES 923369ce9aSBarry Smith */ 93eafb4bcbSBarry Smith #define SNESLGMonitorCreate KSPLGMonitorCreate 94eafb4bcbSBarry Smith #define SNESLGMonitorDestroy KSPLGMonitorDestroy 95eafb4bcbSBarry Smith #define SNESLGMonitor ((int (*)(SNES,int,double,void*))KSPLGMonitor) 96eafb4bcbSBarry Smith 97c01c455dSBarry Smith extern int SNESSetApplicationContext(SNES,void *); 98c01c455dSBarry Smith extern int SNESGetApplicationContext(SNES,void **); 99f26ada1bSBarry Smith extern int SNESSetConvergenceTest(SNES,int (*)(SNES,double,double,double,void*),void*); 100ddbbdb52SLois Curfman McInnes 101b67197daSBarry Smith /* --------- Solving systems of nonlinear equations --------------- */ 10240191667SLois Curfman McInnes extern int SNESSetFunction(SNES,Vec,int(*)(SNES,Vec,Vec,void*),void *); 10340191667SLois Curfman McInnes extern int SNESComputeFunction(SNES,Vec,Vec); 10440191667SLois Curfman McInnes extern int SNESSetJacobian(SNES,Mat,Mat,int(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *); 10540191667SLois Curfman McInnes extern int SNESGetJacobian(SNES,Mat*,Mat*,void **); 10640191667SLois Curfman McInnes extern int SNESDefaultComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*); 107639f9d9dSBarry Smith extern int SNESDefaultComputeJacobianWithColoring(SNES,Vec,Mat*,Mat*,MatStructure*,void*); 10840191667SLois Curfman McInnes extern int SNESConverged_EQ_LS(SNES,double,double,double,void*); 10940191667SLois Curfman McInnes extern int SNESConverged_EQ_TR(SNES,double,double,double,void*); 11084cb2905SBarry Smith extern int SNESSetLineSearch(SNES,int(*)(SNES,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*)); 11140191667SLois Curfman McInnes extern int SNESNoLineSearch(SNES,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*); 11293c39befSBarry Smith extern int SNESNoLineSearchNoNorms(SNES,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*); 11340191667SLois Curfman McInnes extern int SNESCubicLineSearch(SNES,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*); 11440191667SLois Curfman McInnes extern int SNESQuadraticLineSearch(SNES,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*); 11540191667SLois Curfman McInnes 11684cb2905SBarry Smith /* --------- Unconstrained minimization routines --------------------------------*/ 117ddbbdb52SLois Curfman McInnes extern int SNESSetHessian(SNES,Mat,Mat,int(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *); 11882590567SLois Curfman McInnes extern int SNESGetHessian(SNES,Mat*,Mat*,void **); 11940191667SLois Curfman McInnes extern int SNESDefaultComputeHessian(SNES,Vec,Mat*,Mat*,MatStructure*,void*); 120ddbbdb52SLois Curfman McInnes extern int SNESSetGradient(SNES,Vec,int(*)(SNES,Vec,Vec,void*),void*); 121ddbbdb52SLois Curfman McInnes extern int SNESGetGradient(SNES,Vec*); 12225c7317fSLois Curfman McInnes extern int SNESGetGradientNorm(SNES,Scalar*); 123ddbbdb52SLois Curfman McInnes extern int SNESComputeGradient(SNES,Vec,Vec); 12425c7317fSLois Curfman McInnes extern int SNESSetMinimizationFunction(SNES,int(*)(SNES,Vec,double*,void*),void*); 12525c7317fSLois Curfman McInnes extern int SNESComputeMinimizationFunction(SNES,Vec,double*); 12625c7317fSLois Curfman McInnes extern int SNESGetMinimizationFunction(SNES,double*); 12777c4ece6SBarry Smith extern int SNESSetMinimizationFunctionTolerance(SNES,double); 12882bf6240SBarry Smith extern int SNESLineSearchSetDampingParameter(SNES,Scalar*); 12940191667SLois Curfman McInnes extern int SNESConverged_UM_LS(SNES,double,double,double,void*); 13040191667SLois Curfman McInnes extern int SNESConverged_UM_TR(SNES,double,double,double,void*); 13152392280SLois Curfman McInnes 1324b0e389bSBarry Smith 13352392280SLois Curfman McInnes /* Should these 2 routines be private? */ 13452392280SLois Curfman McInnes extern int SNESComputeHessian(SNES,Vec,Mat*,Mat*,MatStructure*); 13552392280SLois Curfman McInnes extern int SNESComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*); 136ddbbdb52SLois Curfman McInnes 137ce3d82beSBarry Smith #endif 138b1f5cb9dSBarry Smith 139