1*130052c2SBarry Smith /* $Id: snes.h,v 1.89 1999/05/16 14:48:52 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_TEST "test" 1582bf6240SBarry Smith #define SNES_UM_LS "umls" 1682bf6240SBarry Smith #define SNES_UM_TR "umtr" 1782bf6240SBarry Smith 1882bf6240SBarry Smith typedef char *SNESType; 19b1f5cb9dSBarry Smith 202a03e22aSLois Curfman McInnes typedef enum {SNES_NONLINEAR_EQUATIONS, SNES_UNCONSTRAINED_MINIMIZATION, SNES_LEAST_SQUARES} SNESProblemType; 212a03e22aSLois Curfman McInnes 224b0e389bSBarry Smith extern int SNESCreate(MPI_Comm,SNESProblemType,SNES*); 234b0e389bSBarry Smith extern int SNESDestroy(SNES); 244b0e389bSBarry Smith extern int SNESSetType(SNES,SNESType); 25b8a78c4aSBarry Smith extern int SNESSetMonitor(SNES,int(*)(SNES,int,double,void*),void *,int (*)(void *)); 265cd90555SBarry Smith extern int SNESClearMonitor(SNES); 2784c569c9SBarry Smith extern int SNESSetConvergenceHistory(SNES,double*,int *,int,PetscTruth); 2884c569c9SBarry Smith extern int SNESGetConvergenceHistory(SNES,double**,int **,int *); 298ddd3da0SLois Curfman McInnes extern int SNESSetUp(SNES,Vec); 308ddd3da0SLois Curfman McInnes extern int SNESSolve(SNES,Vec,int*); 3184cb2905SBarry Smith 32488ecbafSBarry Smith extern FList SNESList; 33cf256101SBarry Smith extern int SNESRegisterDestroy(void); 3482bf6240SBarry Smith extern int SNESRegisterAll(char *); 3584cb2905SBarry Smith 36b2002411SLois Curfman McInnes extern int SNESRegister_Private(char*,char*,char*,int(*)(SNES)); 37aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 38b2002411SLois Curfman McInnes #define SNESRegister(a,b,c,d) SNESRegister_Private(a,b,c,0) 39b2002411SLois Curfman McInnes #else 40b2002411SLois Curfman McInnes #define SNESRegister(a,b,c,d) SNESRegister_Private(a,b,c,d) 41b2002411SLois Curfman McInnes #endif 42b2002411SLois Curfman McInnes 43ce3d82beSBarry Smith extern int SNESGetSLES(SNES,SLES*); 44ce3d82beSBarry Smith extern int SNESGetSolution(SNES,Vec*); 45e81d6643SLois Curfman McInnes extern int SNESGetSolutionUpdate(SNES,Vec*); 46eafb4bcbSBarry Smith extern int SNESGetFunction(SNES,Vec*); 47ce3d82beSBarry Smith extern int SNESPrintHelp(SNES); 48e9e17121SLois Curfman McInnes extern int SNESView(SNES,Viewer); 497bc3d0afSSatish Balay 506daaf66cSBarry Smith extern int SNESSetOptionsPrefix(SNES,char*); 517bc3d0afSSatish Balay extern int SNESAppendOptionsPrefix(SNES,char*); 527bc3d0afSSatish Balay extern int SNESGetOptionsPrefix(SNES,char**); 53ce3d82beSBarry Smith extern int SNESSetFromOptions(SNES); 5415091d37SBarry Smith extern int SNESSetTypeFromOptions(SNES); 55639f9d9dSBarry Smith extern int SNESAddOptionsChecker(int (*)(SNES)); 5640191667SLois Curfman McInnes 575a655dc6SBarry Smith extern int MatCreateSNESMF(SNES,Vec,Mat*); 58*130052c2SBarry Smith extern int MatSNESMFSetFunction(Mat,Vec,int(*)(SNES,Vec,Vec,void*),void *); 59*130052c2SBarry Smith extern int MatSNESMFAddNullSpace(Mat,PCNullSpace); 605a655dc6SBarry Smith extern int MatSNESMFSetHHistory(Mat,Scalar *,int); 615a655dc6SBarry Smith extern int MatSNESMFResetHHistory(Mat); 625a655dc6SBarry Smith extern int MatSNESMFSetFunctionError(Mat,double); 635a655dc6SBarry Smith extern int MatSNESMFGetH(Mat,Scalar *); 645a655dc6SBarry Smith extern int MatSNESMFKSPMonitor(KSP,int,double,void *); 655a655dc6SBarry Smith extern int MatSNESMFSetFromOptions(Mat); 665a655dc6SBarry Smith typedef struct _p_MatSNESMFCtx *MatSNESMFCtx; 675a655dc6SBarry Smith extern int MatSNESMFSetType(Mat,char*); 685a655dc6SBarry Smith extern int MatSNESMFRegister_Private(char *,char *,char *,int (*)(MatSNESMFCtx)); 69aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 705a655dc6SBarry Smith #define MatSNESMFRegister(a,b,c,d) MatSNESMFRegister_Private(a,b,c,0) 719a6cb015SBarry Smith #else 725a655dc6SBarry Smith #define MatSNESMFRegister(a,b,c,d) MatSNESMFRegister_Private(a,b,c,d) 739a6cb015SBarry Smith #endif 745a655dc6SBarry Smith extern int MatSNESMFRegisterAll(char *); 755a655dc6SBarry Smith extern int MatSNESMFRegisterDestroy(void); 765a655dc6SBarry Smith extern int MatSNESMFDefaultSetUmin(Mat,double); 775a655dc6SBarry Smith extern int MatSNESMFWPSetComputeNormA(Mat,PetscTruth); 785a655dc6SBarry Smith extern int MatSNESMFWPSetComputeNormU(Mat,PetscTruth); 798f6e3e37SBarry Smith 8082bf6240SBarry Smith extern int SNESGetType(SNES,SNESType*); 81eafb4bcbSBarry Smith extern int SNESDefaultMonitor(SNES,int,double,void *); 823f1db9ecSBarry Smith extern int SNESVecViewMonitor(SNES,int,double,void *); 83d132466eSBarry Smith extern int SNESVecViewMonitorUpdate(SNES,int,double,void *); 84c512e24aSBarry Smith extern int SNESDefaultSMonitor(SNES,int,double,void *); 85d7a720efSLois Curfman McInnes extern int SNESSetTolerances(SNES,double,double,double,int,int); 8633174efeSLois Curfman McInnes extern int SNESGetTolerances(SNES,double*,double*,double*,int*,int*); 8752392280SLois Curfman McInnes extern int SNESSetTrustRegionTolerance(SNES,double); 887e984346SBarry Smith extern int SNESGetIterationNumber(SNES,int*); 894f6d0874SLois Curfman McInnes extern int SNESGetFunctionNorm(SNES,Scalar*); 90a96f0e77SLois Curfman McInnes extern int SNESGetNumberUnsuccessfulSteps(SNES,int*); 91d2bb1046SLois Curfman McInnes extern int SNESGetNumberLinearIterations(SNES,int*); 9255b5a45fSLois Curfman McInnes extern int SNES_KSP_SetParametersEW(SNES,int,double,double,double,double,double,double); 9355b5a45fSLois Curfman McInnes extern int SNES_KSP_SetConvergenceTestEW(SNES); 94eafb4bcbSBarry Smith 953369ce9aSBarry Smith /* 963369ce9aSBarry Smith Reuse the default KSP monitor routines for SNES 973369ce9aSBarry Smith */ 98df9fa365SBarry Smith extern int SNESLGMonitorCreate(char*,char*,int,int,int,int,DrawLG*); 99ce1608b8SBarry Smith extern int SNESLGMonitor(SNES,int,double,void*); 100df9fa365SBarry Smith extern int SNESLGMonitorDestroy(DrawLG); 101eafb4bcbSBarry Smith 102c01c455dSBarry Smith extern int SNESSetApplicationContext(SNES,void *); 103c01c455dSBarry Smith extern int SNESGetApplicationContext(SNES,void **); 104f26ada1bSBarry Smith extern int SNESSetConvergenceTest(SNES,int (*)(SNES,double,double,double,void*),void*); 105ddbbdb52SLois Curfman McInnes 106b67197daSBarry Smith /* --------- Solving systems of nonlinear equations --------------- */ 10740191667SLois Curfman McInnes extern int SNESSetFunction(SNES,Vec,int(*)(SNES,Vec,Vec,void*),void *); 10840191667SLois Curfman McInnes extern int SNESComputeFunction(SNES,Vec,Vec); 10940191667SLois Curfman McInnes extern int SNESSetJacobian(SNES,Mat,Mat,int(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *); 11040191667SLois Curfman McInnes extern int SNESGetJacobian(SNES,Mat*,Mat*,void **); 11140191667SLois Curfman McInnes extern int SNESDefaultComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*,void*); 1122d0c0e3bSBarry Smith extern int SNESDefaultComputeJacobianColor(SNES,Vec,Mat*,Mat*,MatStructure*,void*); 11340191667SLois Curfman McInnes extern int SNESConverged_EQ_LS(SNES,double,double,double,void*); 11440191667SLois Curfman McInnes extern int SNESConverged_EQ_TR(SNES,double,double,double,void*); 11508405cd6SLois Curfman McInnes extern int SNESSetLineSearch(SNES,int(*)(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*),void*); 11608405cd6SLois Curfman McInnes extern int SNESNoLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*); 11708405cd6SLois Curfman McInnes extern int SNESNoLineSearchNoNorms(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*); 11808405cd6SLois Curfman McInnes extern int SNESCubicLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*); 11908405cd6SLois Curfman McInnes extern int SNESQuadraticLineSearch(SNES,void*,Vec,Vec,Vec,Vec,Vec,double,double*,double*,int*); 12008405cd6SLois Curfman McInnes extern int SNESSetLineSearchCheck(SNES,int(*)(SNES,void*,Vec,PetscTruth*),void*); 121*130052c2SBarry Smith extern int SNESSetLineSearchParams(SNES, double, double, double); 122*130052c2SBarry Smith extern int SNESGetLineSearchParams(SNES, double*, double*, double*); 123*130052c2SBarry Smith { 12440191667SLois Curfman McInnes 12584cb2905SBarry Smith /* --------- Unconstrained minimization routines --------------------------------*/ 126ddbbdb52SLois Curfman McInnes extern int SNESSetHessian(SNES,Mat,Mat,int(*)(SNES,Vec,Mat*,Mat*,MatStructure*,void*),void *); 12782590567SLois Curfman McInnes extern int SNESGetHessian(SNES,Mat*,Mat*,void **); 12840191667SLois Curfman McInnes extern int SNESDefaultComputeHessian(SNES,Vec,Mat*,Mat*,MatStructure*,void*); 129ddbbdb52SLois Curfman McInnes extern int SNESSetGradient(SNES,Vec,int(*)(SNES,Vec,Vec,void*),void*); 130ddbbdb52SLois Curfman McInnes extern int SNESGetGradient(SNES,Vec*); 13125c7317fSLois Curfman McInnes extern int SNESGetGradientNorm(SNES,Scalar*); 132ddbbdb52SLois Curfman McInnes extern int SNESComputeGradient(SNES,Vec,Vec); 13325c7317fSLois Curfman McInnes extern int SNESSetMinimizationFunction(SNES,int(*)(SNES,Vec,double*,void*),void*); 13425c7317fSLois Curfman McInnes extern int SNESComputeMinimizationFunction(SNES,Vec,double*); 13525c7317fSLois Curfman McInnes extern int SNESGetMinimizationFunction(SNES,double*); 13677c4ece6SBarry Smith extern int SNESSetMinimizationFunctionTolerance(SNES,double); 13782bf6240SBarry Smith extern int SNESLineSearchSetDampingParameter(SNES,Scalar*); 13840191667SLois Curfman McInnes extern int SNESConverged_UM_LS(SNES,double,double,double,void*); 13940191667SLois Curfman McInnes extern int SNESConverged_UM_TR(SNES,double,double,double,void*); 14052392280SLois Curfman McInnes 1414b0e389bSBarry Smith 14252392280SLois Curfman McInnes /* Should these 2 routines be private? */ 14352392280SLois Curfman McInnes extern int SNESComputeHessian(SNES,Vec,Mat*,Mat*,MatStructure*); 14452392280SLois Curfman McInnes extern int SNESComputeJacobian(SNES,Vec,Mat*,Mat*,MatStructure*); 145ddbbdb52SLois Curfman McInnes 146ce3d82beSBarry Smith #endif 147b1f5cb9dSBarry Smith 148