1f26ada1bSBarry Smith /* 2eef9c623SLois Curfman McInnes User interface for the nonlinear solvers package. 3f26ada1bSBarry Smith */ 4a4963045SJacob Faibussowitsch #pragma once 5ac09b921SBarry Smith 62c8e378dSBarry Smith #include <petscksp.h> 71e25c274SJed Brown #include <petscdmtypes.h> 87ed8fce4SMatthew G. Knepley #include <petscfvtypes.h> 91e25c274SJed Brown #include <petscdmdatypes.h> 10b1f5cb9dSBarry Smith 11ac09b921SBarry Smith /* SUBMANSEC = SNES */ 12ac09b921SBarry Smith 13435da068SBarry Smith /*S 1416a05f60SBarry Smith SNES - Abstract PETSc object that manages nonlinear solves 15435da068SBarry Smith 16435da068SBarry Smith Level: beginner 17435da068SBarry Smith 181cc06b55SBarry Smith .seealso: [](doc_nonlinsolve), [](ch_snes), `SNESCreate()`, `SNESSetType()`, `SNESType`, `TS`, `SNES`, `KSP`, `PC`, `SNESDestroy()` 19435da068SBarry Smith S*/ 20f09e8eb9SSatish Balay typedef struct _p_SNES *SNES; 21435da068SBarry Smith 2276bdecfbSBarry Smith /*J 2316a05f60SBarry Smith SNESType - String with the name of a PETSc `SNES` method. 24435da068SBarry Smith 25435da068SBarry Smith Level: beginner 26435da068SBarry Smith 271cc06b55SBarry Smith .seealso: [](doc_nonlinsolve), [](ch_snes), `SNESSetType()`, `SNES`, `SNESCreate()`, `SNESDestroy()`, `SNESSetFromOptions()` 2876bdecfbSBarry Smith J*/ 2919fd82e9SBarry Smith typedef const char *SNESType; 3004d7464bSBarry Smith #define SNESNEWTONLS "newtonls" 3104d7464bSBarry Smith #define SNESNEWTONTR "newtontr" 3241ba4c6cSHeeho Park #define SNESNEWTONTRDC "newtontrdc" 331d6018f0SLisandro Dalcin #define SNESPYTHON "python" 34d5c3842bSBarry Smith #define SNESNRICHARDSON "nrichardson" 35b79b07cfSJed Brown #define SNESKSPONLY "ksponly" 361ef27442SStefano Zampini #define SNESKSPTRANSPOSEONLY "ksptransposeonly" 37f450aa47SBarry Smith #define SNESVINEWTONRSLS "vinewtonrsls" 38f450aa47SBarry Smith #define SNESVINEWTONSSLS "vinewtonssls" 394a0c5b0cSMatthew G Knepley #define SNESNGMRES "ngmres" 404b11644fSPeter Brune #define SNESQN "qn" 41c5ae4b9aSBarry Smith #define SNESSHELL "shell" 42be95d8f1SBarry Smith #define SNESNGS "ngs" 43fef7b6d8SPeter Brune #define SNESNCG "ncg" 44421d9b32SPeter Brune #define SNESFAS "fas" 4537e1895aSJed Brown #define SNESMS "ms" 46eaedb033SPeter Brune #define SNESNASM "nasm" 47f31c9d25SPeter Brune #define SNESANDERSON "anderson" 48d728fb7dSPeter Brune #define SNESASPIN "aspin" 49eed5f15bSPeter Brune #define SNESCOMPOSITE "composite" 50561742edSMatthew G. Knepley #define SNESPATCH "patch" 51d5c3842bSBarry Smith 52deeb6e72SMatthew Knepley /* Logging support */ 53014dd563SJed Brown PETSC_EXTERN PetscClassId SNES_CLASSID; 5422c6f798SBarry Smith PETSC_EXTERN PetscClassId DMSNES_CLASSID; 55deeb6e72SMatthew Knepley 56607a6623SBarry Smith PETSC_EXTERN PetscErrorCode SNESInitializePackage(void); 574bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode SNESFinalizePackage(void); 58deeb6e72SMatthew Knepley 59014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESCreate(MPI_Comm, SNES *); 60014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESReset(SNES); 61014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESDestroy(SNES *); 6219fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetType(SNES, SNESType); 63014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitor(SNES, PetscInt, PetscReal); 64014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorSet(SNES, PetscErrorCode (*)(SNES, PetscInt, PetscReal, void *), void *, PetscErrorCode (*)(void **)); 65d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorSetFromOptions(SNES, const char[], const char[], const char[], PetscErrorCode (*)(SNES, PetscInt, PetscReal, PetscViewerAndFormat *), PetscErrorCode (*)(SNES, PetscViewerAndFormat *)); 66014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorCancel(SNES); 678a70d858SHong Zhang PETSC_EXTERN PetscErrorCode SNESMonitorSAWs(SNES, PetscInt, PetscReal, void *); 688a70d858SHong Zhang PETSC_EXTERN PetscErrorCode SNESMonitorSAWsCreate(SNES, void **); 698a70d858SHong Zhang PETSC_EXTERN PetscErrorCode SNESMonitorSAWsDestroy(void **); 70014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetConvergenceHistory(SNES, PetscReal[], PetscInt[], PetscInt, PetscBool); 71014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetConvergenceHistory(SNES, PetscReal *[], PetscInt *[], PetscInt *); 72014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetUp(SNES); 73014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSolve(SNES, Vec, Vec); 74014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetErrorIfNotConverged(SNES, PetscBool); 75014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetErrorIfNotConverged(SNES, PetscBool *); 762d157150SStefano Zampini PETSC_EXTERN PetscErrorCode SNESConverged(SNES, PetscInt, PetscReal, PetscReal, PetscReal); 77e113a28aSBarry Smith 78fa0ddf94SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetWorkVecs(SNES, PetscInt); 7984cb2905SBarry Smith 80014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESAddOptionsChecker(PetscErrorCode (*)(SNES)); 814d8f6ca9SMatthew Knepley 82014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetUpdate(SNES, PetscErrorCode (*)(SNES, PetscInt)); 834d8f6ca9SMatthew Knepley 84bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode SNESRegister(const char[], PetscErrorCode (*)(SNES)); 8530de9b25SBarry Smith 86014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetKSP(SNES, KSP *); 87014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetKSP(SNES, KSP); 883cd8a7caSMatthew G. Knepley PETSC_EXTERN PetscErrorCode SNESSetSolution(SNES, Vec); 89014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetSolution(SNES, Vec *); 90014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetSolutionUpdate(SNES, Vec *); 91014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetRhs(SNES, Vec *); 92014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESView(SNES, PetscViewer); 9355849f57SBarry Smith PETSC_EXTERN PetscErrorCode SNESLoad(SNES, PetscViewer); 94c4421ceaSFande Kong PETSC_EXTERN PetscErrorCode SNESConvergedReasonViewSet(SNES, PetscErrorCode (*)(SNES, void *), void *, PetscErrorCode (*)(void **)); 95fe2efc57SMark PETSC_EXTERN PetscErrorCode SNESViewFromOptions(SNES, PetscObject, const char[]); 9619a666eeSBarry Smith PETSC_EXTERN PetscErrorCode SNESConvergedReasonView(SNES, PetscViewer); 9719a666eeSBarry Smith PETSC_EXTERN PetscErrorCode SNESConvergedReasonViewFromOptions(SNES); 98c4421ceaSFande Kong PETSC_EXTERN PetscErrorCode SNESConvergedReasonViewCancel(SNES); 9919a666eeSBarry Smith 100edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 14, 0, "SNESConvergedReasonView()", ) static inline PetscErrorCode SNESReasonView(SNES snes, PetscViewer v) 101d71ae5a4SJacob Faibussowitsch { 1029371c9d4SSatish Balay return SNESConvergedReasonView(snes, v); 1039371c9d4SSatish Balay } 104edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 14, 0, "SNESConvergedReasonViewFromOptions()", ) static inline PetscErrorCode SNESReasonViewFromOptions(SNES snes) 105d71ae5a4SJacob Faibussowitsch { 1069371c9d4SSatish Balay return SNESConvergedReasonViewFromOptions(snes); 1079371c9d4SSatish Balay } 10855849f57SBarry Smith 10955849f57SBarry Smith #define SNES_FILE_CLASSID 1211224 1107bc3d0afSSatish Balay 111014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetOptionsPrefix(SNES, const char[]); 112014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESAppendOptionsPrefix(SNES, const char[]); 113014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetOptionsPrefix(SNES, const char *[]); 114014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetFromOptions(SNES); 11587d6299eSMatthew G. Knepley PETSC_EXTERN PetscErrorCode SNESResetFromOptions(SNES); 11640191667SLois Curfman McInnes 1173565c898SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetUseMatrixFree(SNES, PetscBool, PetscBool); 1183565c898SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetUseMatrixFree(SNES, PetscBool *, PetscBool *); 119014dd563SJed Brown PETSC_EXTERN PetscErrorCode MatCreateSNESMF(SNES, Mat *); 120bc13fc8dSBarry Smith PETSC_EXTERN PetscErrorCode MatSNESMFGetSNES(Mat, SNES *); 121208be567SBarry Smith PETSC_EXTERN PetscErrorCode MatSNESMFSetReuseBase(Mat, PetscBool); 122208be567SBarry Smith PETSC_EXTERN PetscErrorCode MatSNESMFGetReuseBase(Mat, PetscBool *); 123d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode MatMFFDComputeJacobian(SNES, Vec, Mat, Mat, void *); 124f6dfbefdSBarry Smith PETSC_EXTERN PetscErrorCode MatCreateSNESMFMore(SNES, Vec, Mat *); 125f6dfbefdSBarry Smith PETSC_EXTERN PetscErrorCode MatSNESMFMoreSetParameters(Mat, PetscReal, PetscReal, PetscReal); 1268f6e3e37SBarry Smith 12719fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetType(SNES, SNESType *); 128fbcc4530SMatthew G. Knepley PETSC_EXTERN PetscErrorCode SNESMonitorDefaultSetUp(SNES, PetscViewerAndFormat *); 129d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorDefault(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 1301f60017eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorScaling(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 131d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorRange(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 132d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorRatio(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 133d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorRatioSetUp(SNES, PetscViewerAndFormat *); 134d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorSolution(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 135d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorResidual(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 136d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorSolutionUpdate(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 137d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorDefaultShort(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 138d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorDefaultField(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 139d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorJacUpdateSpectrum(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 140d43b4f6eSBarry Smith PETSC_EXTERN PetscErrorCode SNESMonitorFields(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 141798534f6SMatthew G. Knepley PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidual(KSP, PetscInt, PetscReal, PetscViewerAndFormat *); 142798534f6SMatthew G. Knepley PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidualDrawLG(KSP, PetscInt, PetscReal, PetscViewerAndFormat *); 143798534f6SMatthew G. Knepley PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidualDrawLGCreate(PetscViewer, PetscViewerFormat, void *, PetscViewerAndFormat **); 144e5f7ee39SBarry Smith 145014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetTolerances(SNES, PetscReal, PetscReal, PetscReal, PetscInt, PetscInt); 146e4d06f11SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESSetDivergenceTolerance(SNES, PetscReal); 147014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetTolerances(SNES, PetscReal *, PetscReal *, PetscReal *, PetscInt *, PetscInt *); 148e4d06f11SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESGetDivergenceTolerance(SNES, PetscReal *); 149014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetTrustRegionTolerance(SNES, PetscReal); 15085216dc7SFande Kong PETSC_EXTERN PetscErrorCode SNESGetForceIteration(SNES, PetscBool *); 151be5caee7SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetForceIteration(SNES, PetscBool); 152014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetIterationNumber(SNES, PetscInt *); 153014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetIterationNumber(SNES, PetscInt); 1543d4c4710SBarry Smith 1554a221d59SStefano Zampini /*E 1564a221d59SStefano Zampini SNESNewtonTRFallbackType - type of fallback in case the solution of the trust-region subproblem is outside of the radius 1574a221d59SStefano Zampini 1584a221d59SStefano Zampini Values: 1594a221d59SStefano Zampini + `SNES_TR_FALLBACK_NEWTON` - use scaled Newton step 1604a221d59SStefano Zampini . `SNES_TR_FALLBACK_CAUCHY` - use Cauchy direction 1614a221d59SStefano Zampini - `SNES_TR_FALLBACK_DOGLEG` - use dogleg method 16216a05f60SBarry Smith 16316a05f60SBarry Smith Level: intermediate 16416a05f60SBarry Smith 1651cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESNEWTONTR`, `SNESNEWTONTRDC` 1664a221d59SStefano Zampini E*/ 1674a221d59SStefano Zampini typedef enum { 1684a221d59SStefano Zampini SNES_TR_FALLBACK_NEWTON, 1694a221d59SStefano Zampini SNES_TR_FALLBACK_CAUCHY, 1704a221d59SStefano Zampini SNES_TR_FALLBACK_DOGLEG, 1714a221d59SStefano Zampini } SNESNewtonTRFallbackType; 1724a221d59SStefano Zampini 1734a221d59SStefano Zampini PETSC_EXTERN const char *const SNESNewtonTRFallbackTypes[]; 1744a221d59SStefano Zampini 175c9368356SGlenn Hammond PETSC_EXTERN PetscErrorCode SNESNewtonTRSetPreCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, PetscBool *, void *), void *ctx); 176c9368356SGlenn Hammond PETSC_EXTERN PetscErrorCode SNESNewtonTRGetPreCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, PetscBool *, void *), void **ctx); 177c9368356SGlenn Hammond PETSC_EXTERN PetscErrorCode SNESNewtonTRSetPostCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void *ctx); 178c9368356SGlenn Hammond PETSC_EXTERN PetscErrorCode SNESNewtonTRGetPostCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void **ctx); 1794a221d59SStefano Zampini PETSC_EXTERN PetscErrorCode SNESNewtonTRSetFallbackType(SNES, SNESNewtonTRFallbackType); 1804a221d59SStefano Zampini PETSC_EXTERN PetscErrorCode SNESNewtonTRPreCheck(SNES, Vec, Vec, PetscBool *); 1814a221d59SStefano Zampini PETSC_EXTERN PetscErrorCode SNESNewtonTRPostCheck(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *); 182*24fb275aSStefano Zampini PETSC_EXTERN PetscErrorCode SNESNewtonTRSetNormType(SNES, NormType); 183*24fb275aSStefano Zampini 184*24fb275aSStefano Zampini /*E 185*24fb275aSStefano Zampini SNESNewtonTRQNType - type of quasi-Newton model to use 186*24fb275aSStefano Zampini 187*24fb275aSStefano Zampini Values: 188*24fb275aSStefano Zampini + `SNES_TR_QN_NONE` - do not use a quasi-Newton model 189*24fb275aSStefano Zampini . `SNES_TR_QN_SAME` - use the same quasi-Newton model for matrix and preconditioner 190*24fb275aSStefano Zampini - `SNES_TR_QN_DIFFERENT` - use different quasi-Newton models for matrix and preconditioner 191*24fb275aSStefano Zampini 192*24fb275aSStefano Zampini Level: intermediate 193*24fb275aSStefano Zampini 194*24fb275aSStefano Zampini .seealso: [](ch_snes), `SNES`, `SNESNEWTONTR` 195*24fb275aSStefano Zampini E*/ 196*24fb275aSStefano Zampini typedef enum { 197*24fb275aSStefano Zampini SNES_TR_QN_NONE, 198*24fb275aSStefano Zampini SNES_TR_QN_SAME, 199*24fb275aSStefano Zampini SNES_TR_QN_DIFFERENT, 200*24fb275aSStefano Zampini } SNESNewtonTRQNType; 201*24fb275aSStefano Zampini 202*24fb275aSStefano Zampini PETSC_EXTERN const char *const SNESNewtonTRQNTypes[]; 203*24fb275aSStefano Zampini 204*24fb275aSStefano Zampini PETSC_EXTERN PetscErrorCode SNESNewtonTRSetQNType(SNES, SNESNewtonTRQNType); 2057cb011f5SBarry Smith 2064a221d59SStefano Zampini /* TRDC API, to be removed after 3.19 */ 20741ba4c6cSHeeho Park PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetRhoFlag(SNES, PetscBool *); 20841ba4c6cSHeeho Park PETSC_EXTERN PetscErrorCode SNESNewtonTRDCSetPreCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, PetscBool *, void *), void *ctx); 20941ba4c6cSHeeho Park PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetPreCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, PetscBool *, void *), void **ctx); 21041ba4c6cSHeeho Park PETSC_EXTERN PetscErrorCode SNESNewtonTRDCSetPostCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void *ctx); 21141ba4c6cSHeeho Park PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetPostCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void **ctx); 21241ba4c6cSHeeho Park 213014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetNonlinearStepFailures(SNES, PetscInt *); 214014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetMaxNonlinearStepFailures(SNES, PetscInt); 215014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetMaxNonlinearStepFailures(SNES, PetscInt *); 216014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetNumberFunctionEvals(SNES, PetscInt *); 217b850b91aSLisandro Dalcin 218014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetLagPreconditioner(SNES, PetscInt); 219014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLagPreconditioner(SNES, PetscInt *); 220014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetLagJacobian(SNES, PetscInt); 221014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLagJacobian(SNES, PetscInt *); 22237ec4e1aSPeter Brune PETSC_EXTERN PetscErrorCode SNESSetLagPreconditionerPersists(SNES, PetscBool); 22337ec4e1aSPeter Brune PETSC_EXTERN PetscErrorCode SNESSetLagJacobianPersists(SNES, PetscBool); 224014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetGridSequence(SNES, PetscInt); 225fa19ca70SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetGridSequence(SNES, PetscInt *); 226a8054027SBarry Smith 227014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLinearSolveIterations(SNES, PetscInt *); 228014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLinearSolveFailures(SNES, PetscInt *); 229014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetMaxLinearSolveFailures(SNES, PetscInt); 230014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetMaxLinearSolveFailures(SNES, PetscInt *); 231971e163fSPeter Brune PETSC_EXTERN PetscErrorCode SNESSetCountersReset(SNES, PetscBool); 2323d4c4710SBarry Smith 233014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESKSPSetUseEW(SNES, PetscBool); 234014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESKSPGetUseEW(SNES, PetscBool *); 235014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESKSPSetParametersEW(SNES, PetscInt, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal); 236014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESKSPGetParametersEW(SNES, PetscInt *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *); 237eafb4bcbSBarry Smith 2389804daf3SBarry Smith #include <petscdrawtypes.h> 239014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMonitorLGRange(SNES, PetscInt, PetscReal, void *); 240eafb4bcbSBarry Smith 241014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetApplicationContext(SNES, void *); 242014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetApplicationContext(SNES, void *); 243014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetComputeApplicationContext(SNES, PetscErrorCode (*)(SNES, void **), PetscErrorCode (*)(void **)); 244184914b5SBarry Smith 245014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESPythonSetType(SNES, const char[]); 246ebead697SStefano Zampini PETSC_EXTERN PetscErrorCode SNESPythonGetType(SNES, const char *[]); 2471d6018f0SLisandro Dalcin 248014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetFunctionDomainError(SNES); 249014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetFunctionDomainError(SNES, PetscBool *); 250cc6b0f04SFande Kong PETSC_EXTERN PetscErrorCode SNESGetJacobianDomainError(SNES, PetscBool *); 251cc6b0f04SFande Kong PETSC_EXTERN PetscErrorCode SNESSetJacobianDomainError(SNES); 252b351a90bSFande Kong PETSC_EXTERN PetscErrorCode SNESSetCheckJacobianDomainError(SNES, PetscBool); 2538383d7d7SFande Kong PETSC_EXTERN PetscErrorCode SNESGetCheckJacobianDomainError(SNES, PetscBool *); 2546a388c36SPeter Brune 255edd03b47SJacob Faibussowitsch #define SNES_CONVERGED_TR_DELTA_DEPRECATED SNES_CONVERGED_TR_DELTA PETSC_DEPRECATED_ENUM(3, 12, 0, "SNES_DIVERGED_TR_DELTA", ) 256435da068SBarry Smith /*E 257dc4c0fb0SBarry Smith SNESConvergedReason - reason a `SNESSolve()` was determined to have converged or diverged 258435da068SBarry Smith 259dc4c0fb0SBarry Smith Values: 260dc4c0fb0SBarry Smith + `SNES_CONVERGED_FNORM_ABS` - 2-norm(F) <= abstol 261dc4c0fb0SBarry Smith . `SNES_CONVERGED_FNORM_RELATIVE` - 2-norm(F) <= rtol*2-norm(F(x_0)) where x_0 is the initial guess 262dc4c0fb0SBarry Smith . `SNES_CONVERGED_SNORM_RELATIVE` - The 2-norm of the last step <= stol * 2-norm(x) where x is the current 263dc4c0fb0SBarry Smith . `SNES_DIVERGED_FUNCTION_COUNT` - The user provided function has been called more times than the maximum set in `SNESSetTolerances()` 264dc4c0fb0SBarry Smith . `SNES_DIVERGED_DTOL` - The norm of the function has increased by a factor of divtol set with `SNESSetDivergenceTolerance()` 265dc4c0fb0SBarry Smith . `SNES_DIVERGED_FNORM_NAN` - the 2-norm of the current function evaluation is not-a-number (NaN), this 266dc4c0fb0SBarry Smith is usually caused by a division of 0 by 0. 267dc4c0fb0SBarry Smith . `SNES_DIVERGED_MAX_IT` - `SNESSolve()` has reached the maximum number of iterations requested 268dc4c0fb0SBarry Smith . `SNES_DIVERGED_LINE_SEARCH` - The line search has failed. This only occurs for `SNES` solvers that use a line search 269dc4c0fb0SBarry Smith . `SNES_DIVERGED_LOCAL_MIN` - the algorithm seems to have stagnated at a local minimum that is not zero. 270dc4c0fb0SBarry Smith - `SNES_CONERGED_ITERATING` - this only occurs if `SNESGetConvergedReason()` is called during the `SNESSolve()` 271f203c74bSBarry Smith 27216a05f60SBarry Smith Level: beginner 27316a05f60SBarry Smith 274dc4c0fb0SBarry Smith Notes: 275dc4c0fb0SBarry Smith The two most common reasons for divergence are an incorrectly coded or computed Jacobian or failure or lack of convergence in the linear system (in this case we recommend 276dc4c0fb0SBarry Smith testing with `-pc_type lu` to eliminate the linear solver as the cause of the problem). 277dc4c0fb0SBarry Smith 278dc4c0fb0SBarry Smith `SNES_DIVERGED_LOCAL_MIN` can only occur when using the line-search variant of `SNES`. 279f203c74bSBarry Smith The line search wants to minimize Q(alpha) = 1/2 || F(x + alpha s) ||^2_2 this occurs 280f203c74bSBarry Smith at Q'(alpha) = s^T F'(x+alpha s)^T F(x+alpha s) = 0. If s is the Newton direction - F'(x)^(-1)F(x) then 281f203c74bSBarry Smith you get Q'(alpha) = -F(x)^T F'(x)^(-1)^T F'(x+alpha s)F(x+alpha s); when alpha = 0 282f203c74bSBarry Smith Q'(0) = - ||F(x)||^2_2 which is always NEGATIVE if F'(x) is invertible. This means the Newton 283f203c74bSBarry Smith direction is a descent direction and the line search should succeed if alpha is small enough. 284f203c74bSBarry Smith 285f203c74bSBarry Smith If F'(x) is NOT invertible AND F'(x)^T F(x) = 0 then Q'(0) = 0 and the Newton direction 286f203c74bSBarry Smith is NOT a descent direction so the line search will fail. All one can do at this point 287f203c74bSBarry Smith is change the initial guess and try again. 288f203c74bSBarry Smith 289f203c74bSBarry Smith An alternative explanation: Newton's method can be regarded as replacing the function with 290f203c74bSBarry Smith its linear approximation and minimizing the 2-norm of that. That is F(x+s) approx F(x) + F'(x)s 291f203c74bSBarry Smith so we minimize || F(x) + F'(x) s ||^2_2; do this using Least Squares. If F'(x) is invertible then 292f203c74bSBarry Smith s = - F'(x)^(-1)F(x) otherwise F'(x)^T F'(x) s = -F'(x)^T F(x). If F'(x)^T F(x) is NOT zero then there 2936aad120cSJose E. Roman exists a nontrivial (that is F'(x)s != 0) solution to the equation and this direction is 294f203c74bSBarry Smith s = - [F'(x)^T F'(x)]^(-1) F'(x)^T F(x) so Q'(0) = - F(x)^T F'(x) [F'(x)^T F'(x)]^(-T) F'(x)^T F(x) 295f203c74bSBarry Smith = - (F'(x)^T F(x)) [F'(x)^T F'(x)]^(-T) (F'(x)^T F(x)). Since we are assuming (F'(x)^T F(x)) != 0 296f203c74bSBarry Smith and F'(x)^T F'(x) has no negative eigenvalues Q'(0) < 0 so s is a descent direction and the line 297f203c74bSBarry Smith search should succeed for small enough alpha. 298f203c74bSBarry Smith 299f203c74bSBarry Smith Note that this RARELY happens in practice. Far more likely the linear system is not being solved 300f203c74bSBarry Smith (well enough?) or the Jacobian is wrong. 301f203c74bSBarry Smith 30287497f52SBarry Smith `SNES_DIVERGED_MAX_IT` means that the solver reached the maximum number of iterations without satisfying any 30387497f52SBarry Smith convergence criteria. `SNES_CONVERGED_ITS` means that `SNESConvergedSkip()` was chosen as the convergence test; 3044d0a8057SBarry Smith thus the usual convergence criteria have not been checked and may or may not be satisfied. 305f203c74bSBarry Smith 3061cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPConvergedReason`, `SNESSetConvergenceTest()`, `SNESSetTolerances()` 307435da068SBarry Smith E*/ 308184914b5SBarry Smith typedef enum { /* converged */ 30901b82886SBarry Smith SNES_CONVERGED_FNORM_ABS = 2, /* ||F|| < atol */ 31001b82886SBarry Smith SNES_CONVERGED_FNORM_RELATIVE = 3, /* ||F|| < rtol*||F_initial|| */ 3115358d0d4SBarry Smith SNES_CONVERGED_SNORM_RELATIVE = 4, /* Newton computed step size small; || delta x || < stol || x ||*/ 3123f149594SLisandro Dalcin SNES_CONVERGED_ITS = 5, /* maximum iterations reached */ 31341ba4c6cSHeeho Park SNES_BREAKOUT_INNER_ITER = 6, /* Flag to break out of inner loop after checking custom convergence. */ 31441ba4c6cSHeeho Park /* it is used in multi-phase flow when state changes */ 315184914b5SBarry Smith /* diverged */ 31646a9e3ceSBarry Smith SNES_DIVERGED_FUNCTION_DOMAIN = -1, /* the new x location passed the function is not in the domain of F */ 317184914b5SBarry Smith SNES_DIVERGED_FUNCTION_COUNT = -2, 31846a9e3ceSBarry Smith SNES_DIVERGED_LINEAR_SOLVE = -3, /* the linear solve failed */ 319184914b5SBarry Smith SNES_DIVERGED_FNORM_NAN = -4, 320184914b5SBarry Smith SNES_DIVERGED_MAX_IT = -5, 321647a2e1fSBarry Smith SNES_DIVERGED_LINE_SEARCH = -6, /* the line search failed */ 3221e633543SBarry Smith SNES_DIVERGED_INNER = -7, /* inner solve failed */ 32358c775ebSBarry Smith SNES_DIVERGED_LOCAL_MIN = -8, /* || J^T b || is small, implies converged to local minimum of F() */ 324e37c518bSBarry Smith SNES_DIVERGED_DTOL = -9, /* || F || > divtol*||F_initial|| */ 32507b62357SFande Kong SNES_DIVERGED_JACOBIAN_DOMAIN = -10, /* Jacobian calculation does not make sense */ 3261c6b2ff8SBarry Smith SNES_DIVERGED_TR_DELTA = -11, 327c78072a7SPatrick Sanan SNES_CONVERGED_TR_DELTA_DEPRECATED = -11, 328e37c518bSBarry Smith 3299371c9d4SSatish Balay SNES_CONVERGED_ITERATING = 0 3309371c9d4SSatish Balay } SNESConvergedReason; 331014dd563SJed Brown PETSC_EXTERN const char *const *SNESConvergedReasons; 332184914b5SBarry Smith 333c838673bSBarry Smith /*MC 334c838673bSBarry Smith SNES_CONVERGED_FNORM_ABS - 2-norm(F) <= abstol 335c838673bSBarry Smith 336c838673bSBarry Smith Level: beginner 337c838673bSBarry Smith 3381cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 339c838673bSBarry Smith M*/ 340c838673bSBarry Smith 341c838673bSBarry Smith /*MC 342c838673bSBarry Smith SNES_CONVERGED_FNORM_RELATIVE - 2-norm(F) <= rtol*2-norm(F(x_0)) where x_0 is the initial guess 343c838673bSBarry Smith 344c838673bSBarry Smith Level: beginner 345c838673bSBarry Smith 3461cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 347c838673bSBarry Smith M*/ 348c838673bSBarry Smith 349c838673bSBarry Smith /*MC 350c60f73f4SPeter Brune SNES_CONVERGED_SNORM_RELATIVE - The 2-norm of the last step <= stol * 2-norm(x) where x is the current 35187497f52SBarry Smith solution and stol is the 4th argument to `SNESSetTolerances()` 352c838673bSBarry Smith 353ae9be289SBarry Smith Options Database Keys: 354ae9be289SBarry Smith -snes_stol <stol> - the step tolerance 355ae9be289SBarry Smith 356c838673bSBarry Smith Level: beginner 357c838673bSBarry Smith 3581cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 359c838673bSBarry Smith M*/ 360c838673bSBarry Smith 361c838673bSBarry Smith /*MC 362c838673bSBarry Smith SNES_DIVERGED_FUNCTION_COUNT - The user provided function has been called more times then the final 36387497f52SBarry Smith argument to `SNESSetTolerances()` 364c838673bSBarry Smith 365c838673bSBarry Smith Level: beginner 366c838673bSBarry Smith 3671cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 368c838673bSBarry Smith M*/ 369c838673bSBarry Smith 370c838673bSBarry Smith /*MC 37187497f52SBarry Smith SNES_DIVERGED_DTOL - The norm of the function has increased by a factor of divtol set with `SNESSetDivergenceTolerance()` 372e37c518bSBarry Smith 373e37c518bSBarry Smith Level: beginner 374e37c518bSBarry Smith 3751cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`, `SNESSetDivergenceTolerance()` 376e37c518bSBarry Smith M*/ 377e37c518bSBarry Smith 378e37c518bSBarry Smith /*MC 379c838673bSBarry Smith SNES_DIVERGED_FNORM_NAN - the 2-norm of the current function evaluation is not-a-number (NaN), this 380c838673bSBarry Smith is usually caused by a division of 0 by 0. 381c838673bSBarry Smith 382c838673bSBarry Smith Level: beginner 383c838673bSBarry Smith 3841cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 385c838673bSBarry Smith M*/ 386c838673bSBarry Smith 387c838673bSBarry Smith /*MC 388c838673bSBarry Smith SNES_DIVERGED_MAX_IT - SNESSolve() has reached the maximum number of iterations requested 389c838673bSBarry Smith 390c838673bSBarry Smith Level: beginner 391c838673bSBarry Smith 3921cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 393c838673bSBarry Smith M*/ 394c838673bSBarry Smith 395c838673bSBarry Smith /*MC 39687497f52SBarry Smith SNES_DIVERGED_LINE_SEARCH - The line search has failed. This only occurs for a `SNES` solvers that use a line search 397c838673bSBarry Smith 398c838673bSBarry Smith Level: beginner 399c838673bSBarry Smith 4001cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`, `SNESLineSearch` 401c838673bSBarry Smith M*/ 402c838673bSBarry Smith 403c838673bSBarry Smith /*MC 40446a9e3ceSBarry Smith SNES_DIVERGED_LOCAL_MIN - the algorithm seems to have stagnated at a local minimum that is not zero. 40587497f52SBarry Smith See the manual page for `SNESConvergedReason` for more details 406c838673bSBarry Smith 407c838673bSBarry Smith Level: beginner 408c838673bSBarry Smith 4091cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 410c838673bSBarry Smith M*/ 411c838673bSBarry Smith 412c838673bSBarry Smith /*MC 41387497f52SBarry Smith SNES_CONERGED_ITERATING - this only occurs if `SNESGetConvergedReason()` is called during the `SNESSolve()` 414c838673bSBarry Smith 415c838673bSBarry Smith Level: beginner 416c838673bSBarry Smith 4171cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 418c838673bSBarry Smith M*/ 419c838673bSBarry Smith 420014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetConvergenceTest(SNES, PetscErrorCode (*)(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, void *), void *, PetscErrorCode (*)(void *)); 4218d359177SBarry Smith PETSC_EXTERN PetscErrorCode SNESConvergedDefault(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, void *); 422e2a6519dSDmitry Karpeev PETSC_EXTERN PetscErrorCode SNESConvergedSkip(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, void *); 423649ef022SMatthew Knepley PETSC_EXTERN PetscErrorCode SNESConvergedCorrectPressure(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, void *); 424014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetConvergedReason(SNES, SNESConvergedReason *); 425c4421ceaSFande Kong PETSC_EXTERN PetscErrorCode SNESGetConvergedReasonString(SNES, const char **); 42633866048SMatthew G. Knepley PETSC_EXTERN PetscErrorCode SNESSetConvergedReason(SNES, SNESConvergedReason); 427ddbbdb52SLois Curfman McInnes 428edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 5, 0, "SNESConvergedSkip()", ) static inline void SNESSkipConverged(void) 429d71ae5a4SJacob Faibussowitsch { /* never called */ 4309371c9d4SSatish Balay } 4318ea1b3e6SJed Brown #define SNESSkipConverged (SNESSkipConverged, SNESConvergedSkip) 43211f088b5SMatthew G Knepley 433b67197daSBarry Smith /* --------- Solving systems of nonlinear equations --------------- */ 434f8b49ee9SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetFunction(SNES, Vec, PetscErrorCode (*)(SNES, Vec, Vec, void *), void *); 435f8b49ee9SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetFunction(SNES, Vec *, PetscErrorCode (**)(SNES, Vec, Vec, void *), void **); 436014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESComputeFunction(SNES, Vec, Vec); 437bbc1464cSBarry Smith PETSC_EXTERN PetscErrorCode SNESComputeMFFunction(SNES, Vec, Vec); 43825acbd8eSLisandro Dalcin PETSC_EXTERN PetscErrorCode SNESSetInitialFunction(SNES, Vec); 43932f3f7c2SPeter Brune 440d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode SNESSetJacobian(SNES, Mat, Mat, PetscErrorCode (*)(SNES, Vec, Mat, Mat, void *), void *); 441d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode SNESGetJacobian(SNES, Mat *, Mat *, PetscErrorCode (**)(SNES, Vec, Mat, Mat, void *), void **); 4428d359177SBarry Smith PETSC_EXTERN PetscErrorCode SNESObjectiveComputeFunctionDefaultFD(SNES, Vec, Vec, void *); 443d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode SNESComputeJacobianDefault(SNES, Vec, Mat, Mat, void *); 444d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode SNESComputeJacobianDefaultColor(SNES, Vec, Mat, Mat, void *); 44578e7fe0eSHong Zhang PETSC_EXTERN PetscErrorCode SNESPruneJacobianColor(SNES, Mat, Mat); 446014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetComputeInitialGuess(SNES, PetscErrorCode (*)(SNES, Vec, void *), void *); 447d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode SNESSetPicard(SNES, Vec, PetscErrorCode (*)(SNES, Vec, Vec, void *), Mat, Mat, PetscErrorCode (*)(SNES, Vec, Mat, Mat, void *), void *); 448d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode SNESGetPicard(SNES, Vec *, PetscErrorCode (**)(SNES, Vec, Vec, void *), Mat *, Mat *, PetscErrorCode (**)(SNES, Vec, Mat, Mat, void *), void **); 44925acbd8eSLisandro Dalcin PETSC_EXTERN PetscErrorCode SNESPicardComputeFunction(SNES, Vec, Vec, void *); 450bbc1464cSBarry Smith PETSC_EXTERN PetscErrorCode SNESPicardComputeMFFunction(SNES, Vec, Vec, void *); 45125acbd8eSLisandro Dalcin PETSC_EXTERN PetscErrorCode SNESPicardComputeJacobian(SNES, Vec, Mat, Mat, void *); 45217bae607SBarry Smith 453f8b49ee9SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetObjective(SNES, PetscErrorCode (*)(SNES, Vec, PetscReal *, void *), void *); 454f8b49ee9SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetObjective(SNES, PetscErrorCode (**)(SNES, Vec, PetscReal *, void *), void **); 4552a4ee8f2SPeter Brune PETSC_EXTERN PetscErrorCode SNESComputeObjective(SNES, Vec, PetscReal *); 4562a4ee8f2SPeter Brune 457534ebe21SPeter Brune /*E 45816a05f60SBarry Smith SNESNormSchedule - Frequency with which the norm is computed during a nonliner solve 459534ebe21SPeter Brune 460dc4c0fb0SBarry Smith Values: 461dc4c0fb0SBarry Smith + `SNES_NORM_DEFAULT` - use the default behavior for the current `SNESType` 462dc4c0fb0SBarry Smith . `SNES_NORM_NONE` - avoid all norm computations 463dc4c0fb0SBarry Smith . `SNES_NORM_ALWAYS` - compute the norms whenever possible 464dc4c0fb0SBarry Smith . `SNES_NORM_INITIAL_ONLY` - compute the norm only when the algorithm starts 465dc4c0fb0SBarry Smith . `SNES_NORM_FINAL_ONLY` - compute the norm only when the algorithm finishes 466dc4c0fb0SBarry Smith - `SNES_NORM_INITIAL_FINAL_ONLY` - compute the norm at the start and end of the algorithm 467534ebe21SPeter Brune 46816a05f60SBarry Smith Level: advanced 46916a05f60SBarry Smith 470534ebe21SPeter Brune Notes: 471dc4c0fb0SBarry Smith Support for these is highly dependent on the solver. 472dc4c0fb0SBarry Smith 473dc4c0fb0SBarry Smith Some options limit the convergence tests that can be used. 474dc4c0fb0SBarry Smith 475dc4c0fb0SBarry Smith The `SNES_NORM_NONE` option is most commonly used when the nonlinear solver is being used as a smoother, for example for `SNESFAS` 476dc4c0fb0SBarry Smith 477534ebe21SPeter Brune This is primarily used to turn off extra norm and function computation 478534ebe21SPeter Brune when the solvers are composed. 479534ebe21SPeter Brune 4801cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPSetNormType()`, 481db781477SPatrick Sanan `KSPSetConvergenceTest()`, `KSPSetPCSide()` 482534ebe21SPeter Brune E*/ 4839371c9d4SSatish Balay typedef enum { 4849371c9d4SSatish Balay SNES_NORM_DEFAULT = -1, 485fdacfa88SPeter Brune SNES_NORM_NONE = 0, 486365a6726SPeter Brune SNES_NORM_ALWAYS = 1, 487fdacfa88SPeter Brune SNES_NORM_INITIAL_ONLY = 2, 488fdacfa88SPeter Brune SNES_NORM_FINAL_ONLY = 3, 4899371c9d4SSatish Balay SNES_NORM_INITIAL_FINAL_ONLY = 4 4909371c9d4SSatish Balay } SNESNormSchedule; 491365a6726SPeter Brune PETSC_EXTERN const char *const *const SNESNormSchedules; 4921957e957SBarry Smith 493534ebe21SPeter Brune /*MC 49416a05f60SBarry Smith SNES_NORM_NONE - Don't compute function and its L2 norm when possible 495534ebe21SPeter Brune 496534ebe21SPeter Brune Level: advanced 497534ebe21SPeter Brune 498dc4c0fb0SBarry Smith Note: 499534ebe21SPeter Brune This is most useful for stationary solvers with a fixed number of iterations used as smoothers. 500534ebe21SPeter Brune 5011cc06b55SBarry Smith .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_DEFAULT` 502534ebe21SPeter Brune M*/ 503534ebe21SPeter Brune 504fdacfa88SPeter Brune /*MC 505365a6726SPeter Brune SNES_NORM_ALWAYS - Compute the function and its L2 norm at each iteration. 506534ebe21SPeter Brune 507fdacfa88SPeter Brune Level: advanced 508fdacfa88SPeter Brune 509dc4c0fb0SBarry Smith Note: 510fdacfa88SPeter Brune Most solvers will use this no matter what norm type is passed to them. 511fdacfa88SPeter Brune 5121cc06b55SBarry Smith .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_NONE` 513fdacfa88SPeter Brune M*/ 514534ebe21SPeter Brune 515534ebe21SPeter Brune /*MC 516534ebe21SPeter Brune SNES_NORM_INITIAL_ONLY - Compute the function and its L2 at iteration 0, but do not update it. 517534ebe21SPeter Brune 518534ebe21SPeter Brune Level: advanced 519534ebe21SPeter Brune 520534ebe21SPeter Brune Notes: 521dc4c0fb0SBarry Smith This method is useful in composed methods, when a true solution might actually be found before `SNESSolve()` is called. 522534ebe21SPeter Brune This option enables the solve to abort on the zeroth iteration if this is the case. 523534ebe21SPeter Brune 524534ebe21SPeter Brune For solvers that require the computation of the L2 norm of the function as part of the method, this merely cancels 525534ebe21SPeter Brune the norm computation at the last iteration (if possible). 526534ebe21SPeter Brune 5271cc06b55SBarry Smith .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_FINAL_ONLY`, `SNES_NORM_INITIAL_FINAL_ONLY` 528534ebe21SPeter Brune M*/ 529534ebe21SPeter Brune 530534ebe21SPeter Brune /*MC 531534ebe21SPeter Brune SNES_NORM_FINAL_ONLY - Compute the function and its L2 norm on only the final iteration. 532534ebe21SPeter Brune 533534ebe21SPeter Brune Level: advanced 534534ebe21SPeter Brune 535dc4c0fb0SBarry Smith Note: 536534ebe21SPeter Brune For solvers that require the computation of the L2 norm of the function as part of the method, behaves 53787497f52SBarry Smith exactly as `SNES_NORM_DEFAULT`. This method is useful when the function is gotten after `SNESSolve()` and 538534ebe21SPeter Brune used in subsequent computation for methods that do not need the norm computed during the rest of the 539534ebe21SPeter Brune solution procedure. 540534ebe21SPeter Brune 5411cc06b55SBarry Smith .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_INITIAL_ONLY`, `SNES_NORM_INITIAL_FINAL_ONLY` 542534ebe21SPeter Brune M*/ 543534ebe21SPeter Brune 544534ebe21SPeter Brune /*MC 545534ebe21SPeter Brune SNES_NORM_INITIAL_FINAL_ONLY - Compute the function and its L2 norm on only the initial and final iterations. 546534ebe21SPeter Brune 547534ebe21SPeter Brune Level: advanced 548534ebe21SPeter Brune 549dc4c0fb0SBarry Smith Note: 55087497f52SBarry Smith This method combines the benefits of `SNES_NORM_INITIAL_ONLY` and `SNES_NORM_FINAL_ONLY`. 551534ebe21SPeter Brune 5521cc06b55SBarry Smith .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_SNES_NORM_INITIAL_ONLY`, `SNES_NORM_FINAL_ONLY` 553534ebe21SPeter Brune M*/ 554534ebe21SPeter Brune 555365a6726SPeter Brune PETSC_EXTERN PetscErrorCode SNESSetNormSchedule(SNES, SNESNormSchedule); 556365a6726SPeter Brune PETSC_EXTERN PetscErrorCode SNESGetNormSchedule(SNES, SNESNormSchedule *); 557c5ce4427SMatthew G. Knepley PETSC_EXTERN PetscErrorCode SNESSetFunctionNorm(SNES, PetscReal); 558c5ce4427SMatthew G. Knepley PETSC_EXTERN PetscErrorCode SNESGetFunctionNorm(SNES, PetscReal *); 559c1e67a49SFande Kong PETSC_EXTERN PetscErrorCode SNESGetUpdateNorm(SNES, PetscReal *); 560c1e67a49SFande Kong PETSC_EXTERN PetscErrorCode SNESGetSolutionNorm(SNES, PetscReal *); 561534ebe21SPeter Brune 56247073ea2SPeter Brune /*E 56347073ea2SPeter Brune SNESFunctionType - Type of function computed 56447073ea2SPeter Brune 565dc4c0fb0SBarry Smith Values: 566dc4c0fb0SBarry Smith + `SNES_FUNCTION_DEFAULT` - the default behavior for the current `SNESType` 567dc4c0fb0SBarry Smith . `SNES_FUNCTION_UNPRECONDITIONED` - the original function provided 568dc4c0fb0SBarry Smith - `SNES_FUNCTION_PRECONDITIONED` - the modification of the function by the preconditioner 56947073ea2SPeter Brune 57016a05f60SBarry Smith Level: advanced 57116a05f60SBarry Smith 572dc4c0fb0SBarry Smith Note: 573dc4c0fb0SBarry Smith Support for these is dependent on the solver. 574dc4c0fb0SBarry Smith 5751cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPSetNormType()`, 576db781477SPatrick Sanan `KSPSetConvergenceTest()`, `KSPSetPCSide()` 57747073ea2SPeter Brune E*/ 5789371c9d4SSatish Balay typedef enum { 5799371c9d4SSatish Balay SNES_FUNCTION_DEFAULT = -1, 58047073ea2SPeter Brune SNES_FUNCTION_UNPRECONDITIONED = 0, 5819371c9d4SSatish Balay SNES_FUNCTION_PRECONDITIONED = 1 5829371c9d4SSatish Balay } SNESFunctionType; 58347073ea2SPeter Brune PETSC_EXTERN const char *const *const SNESFunctionTypes; 58447073ea2SPeter Brune 58547073ea2SPeter Brune PETSC_EXTERN PetscErrorCode SNESSetFunctionType(SNES, SNESFunctionType); 58647073ea2SPeter Brune PETSC_EXTERN PetscErrorCode SNESGetFunctionType(SNES, SNESFunctionType *); 587f1c6b773SPeter Brune 588be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetNGS(SNES, PetscErrorCode (*)(SNES, Vec, Vec, void *), void *); 589be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetNGS(SNES, PetscErrorCode (**)(SNES, Vec, Vec, void *), void **); 590be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESComputeNGS(SNES, Vec, Vec); 591b6266c6eSPeter Brune 592be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESNGSSetSweeps(SNES, PetscInt); 593be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESNGSGetSweeps(SNES, PetscInt *); 594be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESNGSSetTolerances(SNES, PetscReal, PetscReal, PetscReal, PetscInt); 595be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESNGSGetTolerances(SNES, PetscReal *, PetscReal *, PetscReal *, PetscInt *); 596badc63e7SPeter Brune 5974fc747eaSLawrence Mitchell PETSC_EXTERN PetscErrorCode SNESSetAlwaysComputesFinalResidual(SNES, PetscBool); 5984fc747eaSLawrence Mitchell PETSC_EXTERN PetscErrorCode SNESGetAlwaysComputesFinalResidual(SNES, PetscBool *); 5994fc747eaSLawrence Mitchell 6003ec1f749SStefano Zampini PETSC_EXTERN PetscErrorCode SNESShellGetContext(SNES, void *); 601014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESShellSetContext(SNES, void *); 602014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESShellSetSolve(SNES, PetscErrorCode (*)(SNES, Vec)); 603646217ecSPeter Brune 604c5ae4b9aSBarry Smith /* --------- Routines specifically for line search methods --------------- */ 605c5ae4b9aSBarry Smith 606872b6db9SPeter Brune /*S 60787497f52SBarry Smith SNESLineSearch - Abstract PETSc object that manages line-search operations for nonlinear solvers 6089e764e56SPeter Brune 6099e764e56SPeter Brune Level: beginner 6109e764e56SPeter Brune 6111cc06b55SBarry Smith .seealso: [](ch_snes), `SNESLineSearchType`, `SNESLineSearchCreate()`, `SNESLineSearchSetType()`, `SNES` 6129e764e56SPeter Brune S*/ 613907376e6SBarry Smith typedef struct _p_LineSearch *SNESLineSearch; 6149e764e56SPeter Brune 6159e764e56SPeter Brune /*J 616dc4c0fb0SBarry Smith SNESLineSearchType - String with the name of a PETSc line search method `SNESLineSearch` 6179e764e56SPeter Brune 618ceaaa498SBarry Smith Values: 619ceaaa498SBarry Smith + `SNESLINESEARCHBASIC` - (or equivalently `SNESLINESEARCHNONE`) Simple damping line search, defaults to using the full Newton step 620ceaaa498SBarry Smith . `SNESLINESEARCHBT` - Backtracking line search over the L2 norm of the function 621ceaaa498SBarry Smith . `SNESLINESEARCHL2` - Secant line search over the L2 norm of the function 622ceaaa498SBarry Smith . `SNESLINESEARCHCP` - Critical point secant line search assuming F(x) = grad G(x) for some unknown G(x) 623ceaaa498SBarry Smith . `SNESLINESEARCHNLEQERR` - Affine-covariant error-oriented linesearch 624ceaaa498SBarry Smith - `SNESLINESEARCHSHELL` - User provided `SNESLineSearch` implementation 625ceaaa498SBarry Smith 62695bd0b28SBarry Smith Level: beginner 62795bd0b28SBarry Smith 6281cc06b55SBarry Smith .seealso: [](ch_snes), `SNESLineSearch`, `SNESLineSearchSetType()`, `SNES` 6299e764e56SPeter Brune J*/ 63019fd82e9SBarry Smith typedef const char *SNESLineSearchType; 6319e764e56SPeter Brune #define SNESLINESEARCHBT "bt" 632d4c6564cSPatrick Farrell #define SNESLINESEARCHNLEQERR "nleqerr" 633c87759e9SPeter Brune #define SNESLINESEARCHBASIC "basic" 6340b00b554SBarry Smith #define SNESLINESEARCHNONE "none" 6359e764e56SPeter Brune #define SNESLINESEARCHL2 "l2" 6369e764e56SPeter Brune #define SNESLINESEARCHCP "cp" 6379e764e56SPeter Brune #define SNESLINESEARCHSHELL "shell" 638b5badacbSBarry Smith #define SNESLINESEARCHNCGLINEAR "ncglinear" 6399e764e56SPeter Brune 640140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList SNESList; 641014dd563SJed Brown PETSC_EXTERN PetscClassId SNESLINESEARCH_CLASSID; 642140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList SNESLineSearchList; 6439e764e56SPeter Brune 644b000cd8dSPeter Brune #define SNES_LINESEARCH_ORDER_LINEAR 1 645b000cd8dSPeter Brune #define SNES_LINESEARCH_ORDER_QUADRATIC 2 646b000cd8dSPeter Brune #define SNES_LINESEARCH_ORDER_CUBIC 3 6479e764e56SPeter Brune 648638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*SNESLineSearchVIProjectFunc)(SNES, Vec); 649638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*SNESLineSearchVINormFunc)(SNES, Vec, Vec, PetscReal *); 650638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*SNESLineSearchApplyFunc)(SNESLineSearch); 651638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*SNESLineSearchUserFunc)(SNESLineSearch, void *); 6529e764e56SPeter Brune 653014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchCreate(MPI_Comm, SNESLineSearch *); 654014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchReset(SNESLineSearch); 655014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchView(SNESLineSearch, PetscViewer); 656014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchDestroy(SNESLineSearch *); 657a80ff896SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetType(SNESLineSearch, SNESLineSearchType *); 65819fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetType(SNESLineSearch, SNESLineSearchType); 659014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetFromOptions(SNESLineSearch); 660ed07d7d7SPeter Brune PETSC_EXTERN PetscErrorCode SNESLineSearchSetFunction(SNESLineSearch, PetscErrorCode (*)(SNES, Vec, Vec)); 661014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetUp(SNESLineSearch); 662014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchApply(SNESLineSearch, Vec, Vec, PetscReal *, Vec); 663014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchPreCheck(SNESLineSearch, Vec, Vec, PetscBool *); 664014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchPostCheck(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *); 665fa0ddf94SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetWorkVecs(SNESLineSearch, PetscInt); 6669e764e56SPeter Brune 6679bd66eb0SPeter Brune /* set the functions for precheck and postcheck */ 66886d74e61SPeter Brune 669f190f2fcSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetPreCheck(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, Vec, Vec, PetscBool *, void *), void *ctx); 670f190f2fcSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetPostCheck(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void *ctx); 6719e764e56SPeter Brune 672f190f2fcSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchGetPreCheck(SNESLineSearch, PetscErrorCode (**)(SNESLineSearch, Vec, Vec, PetscBool *, void *), void **ctx); 673f190f2fcSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchGetPostCheck(SNESLineSearch, PetscErrorCode (**)(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void **ctx); 6749e764e56SPeter Brune 6759bd66eb0SPeter Brune /* set the functions for VI-specific line search operations */ 6769bd66eb0SPeter Brune 677014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFunc, SNESLineSearchVINormFunc); 678014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFunc *, SNESLineSearchVINormFunc *); 6799bd66eb0SPeter Brune 6809e764e56SPeter Brune /* pointers to the associated SNES in order to be able to get the function evaluation out */ 681014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetSNES(SNESLineSearch, SNES); 682014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetSNES(SNESLineSearch, SNES *); 6839e764e56SPeter Brune 6849e764e56SPeter Brune /* set and get the parameters and vectors */ 685014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetTolerances(SNESLineSearch, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscInt *); 686014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetTolerances(SNESLineSearch, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscInt); 6879e764e56SPeter Brune 688014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchPreCheckPicard(SNESLineSearch, Vec, Vec, PetscBool *, void *); 68986d74e61SPeter Brune 690014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetLambda(SNESLineSearch, PetscReal *); 691014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetLambda(SNESLineSearch, PetscReal); 6929e764e56SPeter Brune 693014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetDamping(SNESLineSearch, PetscReal *); 694014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetDamping(SNESLineSearch, PetscReal); 6959e764e56SPeter Brune 696014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetOrder(SNESLineSearch, PetscInt *order); 697014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetOrder(SNESLineSearch, PetscInt order); 69859405d5eSPeter Brune 699422a814eSBarry Smith /*E 700dc4c0fb0SBarry Smith SNESLineSearchReason - indication if the line search has succeeded or failed and why 701422a814eSBarry Smith 702dc4c0fb0SBarry Smith Values: 703dc4c0fb0SBarry Smith + `SNES_LINESEARCH_SUCCEEDED` - the line search succeeded 704dc4c0fb0SBarry Smith . `SNES_LINESEARCH_FAILED_NANORINF` - a not a number of infinity appeared in the computions 705dc4c0fb0SBarry Smith . `SNES_LINESEARCH_FAILED_DOMAIN` - the function was evaluated outside of its domain, see `SNESSetFunctionDomainError()` and `SNESSetJacobianDomainError()` 706dc4c0fb0SBarry Smith . `SNES_LINESEARCH_FAILED_REDUCT` - the linear search failed to get the requested decrease in its norm or objective 707dc4c0fb0SBarry Smith . `SNES_LINESEARCH_FAILED_USER` - used by `SNESLINESEARCHNLEQERR` to indicate the user changed the search direction inappropriately 708dc4c0fb0SBarry Smith - `SNES_LINESEARCH_FAILED_FUNCTION` - indicates the maximum number of function evaluations allowed has been surpassed, `SNESConvergedReason` is also 709dc4c0fb0SBarry Smith set to `SNES_DIVERGED_FUNCTION_COUNT` 710422a814eSBarry Smith 71116a05f60SBarry Smith Level: intermediate 71216a05f60SBarry Smith 713dc4c0fb0SBarry Smith Developer Note: 714dc4c0fb0SBarry Smith Some of these reasons overlap with values of `SNESConvergedReason` 715422a814eSBarry Smith 7161cc06b55SBarry Smith .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPConvergedReason`, `SNESSetConvergenceTest()`, 717dc4c0fb0SBarry Smith `SNESSetFunctionDomainError()` and `SNESSetJacobianDomainError()` 718422a814eSBarry Smith E*/ 7199371c9d4SSatish Balay typedef enum { 7209371c9d4SSatish Balay SNES_LINESEARCH_SUCCEEDED, 721422a814eSBarry Smith SNES_LINESEARCH_FAILED_NANORINF, 722e9b602ebSSatish Balay SNES_LINESEARCH_FAILED_DOMAIN, 723d5b43468SJose E. Roman SNES_LINESEARCH_FAILED_REDUCT, /* INSUFFICIENT REDUCTION */ 724e9b602ebSSatish Balay SNES_LINESEARCH_FAILED_USER, 7259371c9d4SSatish Balay SNES_LINESEARCH_FAILED_FUNCTION 7269371c9d4SSatish Balay } SNESLineSearchReason; 727422a814eSBarry Smith 728422a814eSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchGetReason(SNESLineSearch, SNESLineSearchReason *); 729422a814eSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetReason(SNESLineSearch, SNESLineSearchReason); 7309e764e56SPeter Brune 731014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetVecs(SNESLineSearch, Vec *, Vec *, Vec *, Vec *, Vec *); 732014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetVecs(SNESLineSearch, Vec, Vec, Vec, Vec, Vec); 7339e764e56SPeter Brune 734014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetNorms(SNESLineSearch, PetscReal *, PetscReal *, PetscReal *); 735014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetNorms(SNESLineSearch, PetscReal, PetscReal, PetscReal); 736014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchComputeNorms(SNESLineSearch); 737014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchSetComputeNorms(SNESLineSearch, PetscBool); 7389e764e56SPeter Brune 739dcf2fd19SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchMonitor(SNESLineSearch); 740dcf2fd19SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSet(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, void *), void *, PetscErrorCode (*)(void **)); 741d12e167eSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSetFromOptions(SNESLineSearch, const char[], const char[], const char[], PetscErrorCode (*)(SNESLineSearch, PetscViewerAndFormat *), PetscErrorCode (*)(SNESLineSearch, PetscViewerAndFormat *)); 742dcf2fd19SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorCancel(SNESLineSearch); 743dcf2fd19SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchSetDefaultMonitor(SNESLineSearch, PetscViewer); 744dcf2fd19SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchGetDefaultMonitor(SNESLineSearch, PetscViewer *); 745d12e167eSBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSolutionUpdate(SNESLineSearch, PetscViewerAndFormat *); 7469e764e56SPeter Brune 747014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchAppendOptionsPrefix(SNESLineSearch, const char prefix[]); 748014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchGetOptionsPrefix(SNESLineSearch, const char *prefix[]); 7499e764e56SPeter Brune 7509e764e56SPeter Brune /* Shell interface functions */ 751014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchShellSetUserFunc(SNESLineSearch, SNESLineSearchUserFunc, void *); 752014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchShellGetUserFunc(SNESLineSearch, SNESLineSearchUserFunc *, void **); 7539e764e56SPeter Brune 7542f4102e2SPeter Brune /* BT interface functions */ 755014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchBTSetAlpha(SNESLineSearch, PetscReal); 756014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESLineSearchBTGetAlpha(SNESLineSearch, PetscReal *); 7572f4102e2SPeter Brune 7589e764e56SPeter Brune /*register line search types */ 759bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode SNESLineSearchRegister(const char[], PetscErrorCode (*)(SNESLineSearch)); 7609e764e56SPeter Brune 761720c9a41SShri Abhyankar /* Routines for VI solver */ 762014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVISetVariableBounds(SNES, Vec, Vec); 763cf836535SBlaise Bourdin PETSC_EXTERN PetscErrorCode SNESVIGetVariableBounds(SNES, Vec *, Vec *); 764014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVISetComputeVariableBounds(SNES, PetscErrorCode (*)(SNES, Vec, Vec)); 765014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVIGetInactiveSet(SNES, IS *); 766014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVIGetActiveSetIS(SNES, Vec, Vec, IS *); 767014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVIComputeInactiveSetFnorm(SNES, Vec, Vec, PetscReal *); 768014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESVISetRedundancyCheck(SNES, PetscErrorCode (*)(SNES, IS, IS *, void *), void *); 769f6dfbefdSBarry Smith PETSC_EXTERN PetscErrorCode SNESVIComputeMeritFunction(Vec, PetscReal *, PetscReal *); 770f6dfbefdSBarry Smith PETSC_EXTERN PetscErrorCode SNESVIComputeFunction(SNES, Vec, Vec, void *); 771f6dfbefdSBarry Smith PETSC_EXTERN PetscErrorCode DMSetVI(DM, IS); 772f6dfbefdSBarry Smith PETSC_EXTERN PetscErrorCode DMDestroyVI(DM); 773f5ea5bd2SShri Abhyankar 774014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESTestLocalMin(SNES); 775da9b6338SBarry Smith 776eef9c623SLois Curfman McInnes /* Should this routine be private? */ 777d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode SNESComputeJacobian(SNES, Vec, Mat, Mat); 778e885f1abSBarry Smith PETSC_EXTERN PetscErrorCode SNESTestJacobian(SNES); 779ddbbdb52SLois Curfman McInnes 780014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetDM(SNES, DM); 781014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESGetDM(SNES, DM *); 782be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetNPC(SNES, SNES); 783be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetNPC(SNES, SNES *); 7843ad1a0b9SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESHasNPC(SNES, PetscBool *); 785be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESApplyNPC(SNES, Vec, Vec, Vec); 786be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetNPCFunction(SNES, Vec, PetscReal *); 787be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESComputeFunctionDefaultNPC(SNES, Vec, Vec); 788be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESSetNPCSide(SNES, PCSide); 789be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode SNESGetNPCSide(SNES, PCSide *); 7907601faf0SJed Brown PETSC_EXTERN PetscErrorCode SNESSetLineSearch(SNES, SNESLineSearch); 7917601faf0SJed Brown PETSC_EXTERN PetscErrorCode SNESGetLineSearch(SNES, SNESLineSearch *); 7926c699258SBarry Smith 793edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 4, 0, "SNESGetLineSearch()", ) static inline PetscErrorCode SNESGetSNESLineSearch(SNES snes, SNESLineSearch *ls) 794d71ae5a4SJacob Faibussowitsch { 7959371c9d4SSatish Balay return SNESGetLineSearch(snes, ls); 7969371c9d4SSatish Balay } 797edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 4, 0, "SNESSetLineSearch()", ) static inline PetscErrorCode SNESSetSNESLineSearch(SNES snes, SNESLineSearch ls) 798d71ae5a4SJacob Faibussowitsch { 7999371c9d4SSatish Balay return SNESSetLineSearch(snes, ls); 8009371c9d4SSatish Balay } 8018b7b3213SJed Brown 802014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESSetUpMatrices(SNES); 803f8b49ee9SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetFunction(DM, PetscErrorCode (*)(SNES, Vec, Vec, void *), void *); 804f8b49ee9SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetFunction(DM, PetscErrorCode (**)(SNES, Vec, Vec, void *), void **); 805800f99ffSJeremy L Thompson PETSC_EXTERN PetscErrorCode DMSNESSetFunctionContextDestroy(DM, PetscErrorCode (*)(void *)); 806bbc1464cSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetMFFunction(DM, PetscErrorCode (*)(SNES, Vec, Vec, void *), void *); 807be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetNGS(DM, PetscErrorCode (*)(SNES, Vec, Vec, void *), void *); 808be95d8f1SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetNGS(DM, PetscErrorCode (**)(SNES, Vec, Vec, void *), void **); 809d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetJacobian(DM, PetscErrorCode (*)(SNES, Vec, Mat, Mat, void *), void *); 810d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetJacobian(DM, PetscErrorCode (**)(SNES, Vec, Mat, Mat, void *), void **); 811800f99ffSJeremy L Thompson PETSC_EXTERN PetscErrorCode DMSNESSetJacobianContextDestroy(DM, PetscErrorCode (*)(void *)); 812d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetPicard(DM, PetscErrorCode (*)(SNES, Vec, Vec, void *), PetscErrorCode (*)(SNES, Vec, Mat, Mat, void *), void *); 813d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetPicard(DM, PetscErrorCode (**)(SNES, Vec, Vec, void *), PetscErrorCode (**)(SNES, Vec, Mat, Mat, void *), void **); 814f8b49ee9SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetObjective(DM, PetscErrorCode (*)(SNES, Vec, PetscReal *, void *), void *); 815f8b49ee9SBarry Smith PETSC_EXTERN PetscErrorCode DMSNESGetObjective(DM, PetscErrorCode (**)(SNES, Vec, PetscReal *, void *), void **); 8164dd50a75SBarry Smith PETSC_EXTERN PetscErrorCode DMCopyDMSNES(DM, DM); 8176cab3a1bSJed Brown 818c9d099b5SPeter Brune PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*DMDASNESFunction)(DMDALocalInfo *, void *, void *, void *); 819d1e9a80fSBarry Smith PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*DMDASNESJacobian)(DMDALocalInfo *, void *, Mat, Mat, void *); 8202a4ee8f2SPeter Brune PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*DMDASNESObjective)(DMDALocalInfo *, void *, PetscReal *, void *); 821c9d099b5SPeter Brune 8225505f7afSJunchao Zhang PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*DMDASNESFunctionVec)(DMDALocalInfo *, Vec, Vec, void *); 8235505f7afSJunchao Zhang PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*DMDASNESJacobianVec)(DMDALocalInfo *, Vec, Mat, Mat, void *); 8245505f7afSJunchao Zhang PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*DMDASNESObjectiveVec)(DMDALocalInfo *, Vec, PetscReal *, void *); 8255505f7afSJunchao Zhang 826c9d099b5SPeter Brune PETSC_EXTERN PetscErrorCode DMDASNESSetFunctionLocal(DM, InsertMode, DMDASNESFunction, void *); 827c9d099b5SPeter Brune PETSC_EXTERN PetscErrorCode DMDASNESSetJacobianLocal(DM, DMDASNESJacobian, void *); 8282a4ee8f2SPeter Brune PETSC_EXTERN PetscErrorCode DMDASNESSetObjectiveLocal(DM, DMDASNESObjective, void *); 829d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode DMDASNESSetPicardLocal(DM, InsertMode, PetscErrorCode (*)(DMDALocalInfo *, void *, void *, void *), PetscErrorCode (*)(DMDALocalInfo *, void *, Mat, Mat, void *), void *); 8306cab3a1bSJed Brown 8315505f7afSJunchao Zhang PETSC_EXTERN PetscErrorCode DMDASNESSetFunctionLocalVec(DM, InsertMode, DMDASNESFunctionVec, void *); 8325505f7afSJunchao Zhang PETSC_EXTERN PetscErrorCode DMDASNESSetJacobianLocalVec(DM, DMDASNESJacobianVec, void *); 8335505f7afSJunchao Zhang PETSC_EXTERN PetscErrorCode DMDASNESSetObjectiveLocalVec(DM, DMDASNESObjectiveVec, void *); 8345505f7afSJunchao Zhang 835bdd6f66aSToby Isaac PETSC_EXTERN PetscErrorCode DMSNESSetBoundaryLocal(DM, PetscErrorCode (*)(DM, Vec, void *), void *); 836ff35dfedSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetFunctionLocal(DM, PetscErrorCode (*)(DM, Vec, Vec, void *), void *); 837d1e9a80fSBarry Smith PETSC_EXTERN PetscErrorCode DMSNESSetJacobianLocal(DM, PetscErrorCode (*)(DM, Vec, Mat, Mat, void *), void *); 83828d58a37SPierre Jolivet PETSC_EXTERN PetscErrorCode DMSNESGetBoundaryLocal(DM, PetscErrorCode (**)(DM, Vec, void *), void **); 83928d58a37SPierre Jolivet PETSC_EXTERN PetscErrorCode DMSNESGetFunctionLocal(DM, PetscErrorCode (**)(DM, Vec, Vec, void *), void **); 84028d58a37SPierre Jolivet PETSC_EXTERN PetscErrorCode DMSNESGetJacobianLocal(DM, PetscErrorCode (**)(DM, Vec, Mat, Mat, void *), void **); 841ff35dfedSBarry Smith 842b665c654SMatthew G Knepley /* Routines for Multiblock solver */ 843014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMultiblockSetFields(SNES, const char[], PetscInt, const PetscInt *); 844014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMultiblockSetIS(SNES, const char[], IS); 845014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMultiblockSetBlockSize(SNES, PetscInt); 846014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMultiblockSetType(SNES, PCCompositeType); 8474bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode SNESMultiblockGetSubSNES(SNES, PetscInt *, SNES *[]); 848aeed3662SMatthew G Knepley 84937e1895aSJed Brown /*J 85087497f52SBarry Smith SNESMSType - String with the name of a PETSc `SNESMS` method. 85137e1895aSJed Brown 85237e1895aSJed Brown Level: intermediate 85337e1895aSJed Brown 8541cc06b55SBarry Smith .seealso: [](ch_snes), `SNESMS`, `SNESMSGetType()`, `SNESMSSetType()`, `SNES` 85537e1895aSJed Brown J*/ 85619fd82e9SBarry Smith typedef const char *SNESMSType; 85737e1895aSJed Brown #define SNESMSM62 "m62" 85837e1895aSJed Brown #define SNESMSEULER "euler" 859a97cb6bcSJed Brown #define SNESMSJAMESON83 "jameson83" 8603847c725SLisandro Dalcin #define SNESMSVLTP11 "vltp11" 861a97cb6bcSJed Brown #define SNESMSVLTP21 "vltp21" 862a97cb6bcSJed Brown #define SNESMSVLTP31 "vltp31" 863a97cb6bcSJed Brown #define SNESMSVLTP41 "vltp41" 864a97cb6bcSJed Brown #define SNESMSVLTP51 "vltp51" 865a97cb6bcSJed Brown #define SNESMSVLTP61 "vltp61" 86637e1895aSJed Brown 86719fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESMSRegister(SNESMSType, PetscInt, PetscInt, PetscReal, const PetscReal[], const PetscReal[], const PetscReal[]); 8684bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode SNESMSRegisterAll(void); 86957715debSLisandro Dalcin PETSC_EXTERN PetscErrorCode SNESMSGetType(SNES, SNESMSType *); 87019fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode SNESMSSetType(SNES, SNESMSType); 87157715debSLisandro Dalcin PETSC_EXTERN PetscErrorCode SNESMSGetDamping(SNES, PetscReal *); 87257715debSLisandro Dalcin PETSC_EXTERN PetscErrorCode SNESMSSetDamping(SNES, PetscReal); 873014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMSFinalizePackage(void); 874607a6623SBarry Smith PETSC_EXTERN PetscErrorCode SNESMSInitializePackage(void); 875014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESMSRegisterDestroy(void); 87637e1895aSJed Brown 877ceaaa498SBarry Smith /*MC 878ceaaa498SBarry Smith SNESNGMRESRestartType - the restart approach used by `SNESNGMRES` 87913a62661SPeter Brune 880ceaaa498SBarry Smith Values: 881ceaaa498SBarry Smith + `SNES_NGMRES_RESTART_NONE` - never restart 882ceaaa498SBarry Smith . `SNES_NGMRES_RESTART_DIFFERENCE` - restart based upon difference criteria 883ceaaa498SBarry Smith - `SNES_NGMRES_RESTART_PERIODIC` - restart after a fixed number of iterations 884ceaaa498SBarry Smith 885ceaaa498SBarry Smith Options Database Keys: 886ceaaa498SBarry Smith + -snes_ngmres_restart_type<difference,periodic,none> - set the restart type 887ceaaa498SBarry Smith - -snes_ngmres_restart[30] - sets the number of iterations before restart for periodic 888ceaaa498SBarry Smith 88995bd0b28SBarry Smith Level: intermediate 89095bd0b28SBarry Smith 891ceaaa498SBarry Smith .seealso: `SNES, `SNESNGMRES`, `SNESNGMRESSetSelectType()`, `SNESNGMRESGetSelectType()`, `SNESNGMRESSetRestartType()`, 892ceaaa498SBarry Smith `SNESNGMRESGetRestartType()`, `SNESNGMRESSelectType` 893ceaaa498SBarry Smith M*/ 89413a62661SPeter Brune typedef enum { 89513a62661SPeter Brune SNES_NGMRES_RESTART_NONE = 0, 89613a62661SPeter Brune SNES_NGMRES_RESTART_PERIODIC = 1, 8979371c9d4SSatish Balay SNES_NGMRES_RESTART_DIFFERENCE = 2 8989371c9d4SSatish Balay } SNESNGMRESRestartType; 8996a6fc655SJed Brown PETSC_EXTERN const char *const SNESNGMRESRestartTypes[]; 90013a62661SPeter Brune 901ceaaa498SBarry Smith /*MC 902ceaaa498SBarry Smith SNESNGMRESSelectType - the approach used by `SNESNGMRES` to determine how the candidate solution and 903ceaaa498SBarry Smith combined solution are used to create the next iterate. 904ceaaa498SBarry Smith 905ceaaa498SBarry Smith Values: 906ceaaa498SBarry Smith + `SNES_NGMRES_SELECT_NONE` - choose the combined solution all the time 907ceaaa498SBarry Smith . `SNES_NGMRES_SELECT_DIFFERENCE` - choose based upon the selection criteria 908ceaaa498SBarry Smith - `SNES_NGMRES_SELECT_LINESEARCH` - choose based upon line search combination 909ceaaa498SBarry Smith 910ceaaa498SBarry Smith Options Database Key: 911ceaaa498SBarry Smith . -snes_ngmres_select_type<difference,none,linesearch> - select type 912ceaaa498SBarry Smith 91395bd0b28SBarry Smith Level: intermediate 91495bd0b28SBarry Smith 915ceaaa498SBarry Smith .seealso: `SNES, `SNESNGMRES`, `SNESNGMRESSetSelectType()`, `SNESNGMRESGetSelectType()`, `SNESNGMRESSetRestartType()`, 916ceaaa498SBarry Smith `SNESNGMRESGetRestartType()`, `SNESNGMRESRestartType` 917ceaaa498SBarry Smith M*/ 91813a62661SPeter Brune typedef enum { 91913a62661SPeter Brune SNES_NGMRES_SELECT_NONE = 0, 92013a62661SPeter Brune SNES_NGMRES_SELECT_DIFFERENCE = 1, 9219371c9d4SSatish Balay SNES_NGMRES_SELECT_LINESEARCH = 2 9229371c9d4SSatish Balay } SNESNGMRESSelectType; 9236a6fc655SJed Brown PETSC_EXTERN const char *const SNESNGMRESSelectTypes[]; 92413a62661SPeter Brune 925014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESNGMRESSetRestartType(SNES, SNESNGMRESRestartType); 926014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESNGMRESSetSelectType(SNES, SNESNGMRESSelectType); 92723b3e82cSAsbjørn Nilsen Riseth PETSC_EXTERN PetscErrorCode SNESNGMRESSetRestartFmRise(SNES, PetscBool); 92823b3e82cSAsbjørn Nilsen Riseth PETSC_EXTERN PetscErrorCode SNESNGMRESGetRestartFmRise(SNES, PetscBool *); 92913a62661SPeter Brune 930ceaaa498SBarry Smith /*MC 931ceaaa498SBarry Smith SNESNCGType - the conjugate update approach for `SNESNCG` 9320a844d1aSPeter Brune 933ceaaa498SBarry Smith Values: 934ceaaa498SBarry Smith + `SNES_NCG_FR` - Fletcher-Reeves update 935ceaaa498SBarry Smith . `SNES_NCG_PRP` - Polak-Ribiere-Polyak update, the default and the only one that tolerates generalized search directions 936ceaaa498SBarry Smith . `SNES_NCG_HS` - Hestenes-Steifel update 937ceaaa498SBarry Smith . `SNES_NCG_DY` - Dai-Yuan update 938ceaaa498SBarry Smith - `SNES_NCG_CD` - Conjugate Descent update 939ceaaa498SBarry Smith 940ceaaa498SBarry Smith Options Database Key: 941ceaaa498SBarry Smith . -snes_ncg_type<fr,prp,hs,dy,cd> - select type 942ceaaa498SBarry Smith 94395bd0b28SBarry Smith Level: intermediate 94495bd0b28SBarry Smith 945ceaaa498SBarry Smith .seealso: `SNES, `SNESNCG`, `SNESNCGSetType()` 946ceaaa498SBarry Smith M*/ 9470a844d1aSPeter Brune typedef enum { 9480de8b71eSPeter Brune SNES_NCG_FR = 0, 9490de8b71eSPeter Brune SNES_NCG_PRP = 1, 9500de8b71eSPeter Brune SNES_NCG_HS = 2, 9510de8b71eSPeter Brune SNES_NCG_DY = 3, 9529371c9d4SSatish Balay SNES_NCG_CD = 4 9539371c9d4SSatish Balay } SNESNCGType; 9546a6fc655SJed Brown PETSC_EXTERN const char *const SNESNCGTypes[]; 9550a844d1aSPeter Brune 956014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESNCGSetType(SNES, SNESNCGType); 95713a62661SPeter Brune 958ceaaa498SBarry Smith /*MC 959ceaaa498SBarry Smith SNESQNScaleType - the scaling type used by `SNESQN` 960ceaaa498SBarry Smith 961ceaaa498SBarry Smith Values: 962ceaaa498SBarry Smith + `SNES_QN_SCALE_NONE` - don't scale the problem 963ceaaa498SBarry Smith . `SNES_QN_SCALE_SCALAR` - use Shanno scaling 964ceaaa498SBarry Smith . `SNES_QN_SCALE_DIAGONAL` - scale with a diagonalized BFGS formula (see Gilbert and Lemarechal 1989), available 965ceaaa498SBarry Smith - `SNES_QN_SCALE_JACOBIAN` - scale by solving a linear system coming from the Jacobian you provided with `SNESSetJacobian()` 966ceaaa498SBarry Smith computed at the first iteration of `SNESQN` and at ever restart. 967ceaaa498SBarry Smith 968ceaaa498SBarry Smith Options Database Key: 969ceaaa498SBarry Smith . -snes_qn_scale_type <diagonal,none,scalar,jacobian> - Scaling type 970ceaaa498SBarry Smith 97195bd0b28SBarry Smith Level: intermediate 97295bd0b28SBarry Smith 973ceaaa498SBarry Smith .seealso: `SNES, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNType`, `SNESQNSetType()`, `SNESQNSetRestartType()`, `SNESQNRestartType` 974ceaaa498SBarry Smith M*/ 9759371c9d4SSatish Balay typedef enum { 9769371c9d4SSatish Balay SNES_QN_SCALE_DEFAULT = 0, 9771efc8c45SPeter Brune SNES_QN_SCALE_NONE = 1, 97892f76d53SAlp Dener SNES_QN_SCALE_SCALAR = 2, 97992f76d53SAlp Dener SNES_QN_SCALE_DIAGONAL = 3, 9809371c9d4SSatish Balay SNES_QN_SCALE_JACOBIAN = 4 9819371c9d4SSatish Balay } SNESQNScaleType; 9826a6fc655SJed Brown PETSC_EXTERN const char *const SNESQNScaleTypes[]; 983ceaaa498SBarry Smith 984ceaaa498SBarry Smith /*MC 985ceaaa498SBarry Smith SNESQNRestartType - the restart approached used by `SNESQN` 986ceaaa498SBarry Smith 987ceaaa498SBarry Smith Values: 988ceaaa498SBarry Smith + `SNES_QN_RESTART_NONE` - never restart 989ceaaa498SBarry Smith . `SNES_QN_RESTART_POWELL` - restart based upon descent criteria 990ceaaa498SBarry Smith - `SNES_QN_RESTART_PERIODIC` - restart after a fixed number of iterations 991ceaaa498SBarry Smith 992ceaaa498SBarry Smith Options Database Keys: 993ceaaa498SBarry Smith + -snes_qn_restart_type <powell,periodic,none> - set the restart type 994ceaaa498SBarry Smith - -snes_qn_m <m> - sets the number of stored updates and the restart period for periodic 995ceaaa498SBarry Smith 99695bd0b28SBarry Smith Level: intermediate 99795bd0b28SBarry Smith 998ceaaa498SBarry Smith .seealso: `SNES, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNType`, `SNESQNSetType()`, `SNESQNSetRestartType()`, `SNESQNScaleType` 999ceaaa498SBarry Smith M*/ 10009371c9d4SSatish Balay typedef enum { 10019371c9d4SSatish Balay SNES_QN_RESTART_DEFAULT = 0, 10021efc8c45SPeter Brune SNES_QN_RESTART_NONE = 1, 10031efc8c45SPeter Brune SNES_QN_RESTART_POWELL = 2, 10049371c9d4SSatish Balay SNES_QN_RESTART_PERIODIC = 3 10059371c9d4SSatish Balay } SNESQNRestartType; 10066a6fc655SJed Brown PETSC_EXTERN const char *const SNESQNRestartTypes[]; 1007ceaaa498SBarry Smith 1008ceaaa498SBarry Smith /*MC 1009ceaaa498SBarry Smith SNESQNType - the type used by `SNESQN` 1010ceaaa498SBarry Smith 1011ceaaa498SBarry Smith Values: 1012ceaaa498SBarry Smith + `SNES_QN_LBFGS` - LBFGS variant 1013ceaaa498SBarry Smith . `SNES_QN_BROYDEN` - Broyden variant 1014ceaaa498SBarry Smith - `SNES_QN_BADBROYDEN` - Bad Broyden variant 1015ceaaa498SBarry Smith 1016ceaaa498SBarry Smith Options Database Key: 1017ceaaa498SBarry Smith . -snes_qn_type <lbfgs,broyden,badbroyden> - quasi-Newton type 1018ceaaa498SBarry Smith 101995bd0b28SBarry Smith Level: intermediate 102095bd0b28SBarry Smith 1021ceaaa498SBarry Smith .seealso: `SNES, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNSetType()`, `SNESQNScaleType`, `SNESQNRestartType`, `SNESQNSetRestartType()` 1022ceaaa498SBarry Smith M*/ 10239371c9d4SSatish Balay typedef enum { 10249371c9d4SSatish Balay SNES_QN_LBFGS = 0, 10251efc8c45SPeter Brune SNES_QN_BROYDEN = 1, 10261efc8c45SPeter Brune SNES_QN_BADBROYDEN = 2 10271efc8c45SPeter Brune } SNESQNType; 10281efc8c45SPeter Brune PETSC_EXTERN const char *const SNESQNTypes[]; 10290c777b0cSPeter Brune 10301efc8c45SPeter Brune PETSC_EXTERN PetscErrorCode SNESQNSetType(SNES, SNESQNType); 1031014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESQNSetScaleType(SNES, SNESQNScaleType); 1032014dd563SJed Brown PETSC_EXTERN PetscErrorCode SNESQNSetRestartType(SNES, SNESQNRestartType); 10330c777b0cSPeter Brune 1034e0331734SPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMGetType(SNES, PCASMType *); 1035e0331734SPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMSetType(SNES, PCASMType); 103676857b2aSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMGetSubdomains(SNES, PetscInt *, SNES **, VecScatter **, VecScatter **, VecScatter **); 103776857b2aSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMSetSubdomains(SNES, PetscInt, SNES *, VecScatter *, VecScatter *, VecScatter *); 1038610116beSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMSetDamping(SNES, PetscReal); 1039610116beSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMGetDamping(SNES, PetscReal *); 104076857b2aSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMGetSubdomainVecs(SNES, PetscInt *, Vec **, Vec **, Vec **, Vec **); 1041d728fb7dSPeter Brune PETSC_EXTERN PetscErrorCode SNESNASMSetComputeFinalJacobian(SNES, PetscBool); 1042d2dc0b00SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESNASMGetSNES(SNES, PetscInt, SNES *); 1043d2dc0b00SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESNASMGetNumber(SNES, PetscInt *); 1044f10b3e88SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESNASMSetWeight(SNES, Vec); 10450c777b0cSPeter Brune 10469371c9d4SSatish Balay typedef enum { 10479371c9d4SSatish Balay SNES_COMPOSITE_ADDITIVE, 10489371c9d4SSatish Balay SNES_COMPOSITE_MULTIPLICATIVE, 10499371c9d4SSatish Balay SNES_COMPOSITE_ADDITIVEOPTIMAL 10509371c9d4SSatish Balay } SNESCompositeType; 1051eed5f15bSPeter Brune PETSC_EXTERN const char *const SNESCompositeTypes[]; 1052eed5f15bSPeter Brune 1053eed5f15bSPeter Brune PETSC_EXTERN PetscErrorCode SNESCompositeSetType(SNES, SNESCompositeType); 1054eed5f15bSPeter Brune PETSC_EXTERN PetscErrorCode SNESCompositeAddSNES(SNES, SNESType); 1055eed5f15bSPeter Brune PETSC_EXTERN PetscErrorCode SNESCompositeGetSNES(SNES, PetscInt, SNES *); 1056a6b47ab3SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESCompositeGetNumber(SNES, PetscInt *); 10578f626970SPeter Brune PETSC_EXTERN PetscErrorCode SNESCompositeSetDamping(SNES, PetscInt, PetscReal); 1058eed5f15bSPeter Brune 105968e6d53eSPatrick Farrell PETSC_EXTERN PetscErrorCode SNESPatchSetDiscretisationInfo(SNES, PetscInt, DM *, PetscInt *, PetscInt *, const PetscInt **, const PetscInt *, PetscInt, const PetscInt *, PetscInt, const PetscInt *); 10604d04e9f1SPatrick Farrell PETSC_EXTERN PetscErrorCode SNESPatchSetComputeOperator(SNES, PetscErrorCode (*func)(PC, PetscInt, Vec, Mat, IS, PetscInt, const PetscInt *, const PetscInt *, void *), void *); 106139fd2e8aSPatrick Farrell PETSC_EXTERN PetscErrorCode SNESPatchSetComputeFunction(SNES, PetscErrorCode (*func)(PC, PetscInt, Vec, Vec, IS, PetscInt, const PetscInt *, const PetscInt *, void *), void *); 106268e6d53eSPatrick Farrell PETSC_EXTERN PetscErrorCode SNESPatchSetConstructType(SNES, PCPatchConstructType, PetscErrorCode (*func)(PC, PetscInt *, IS **, IS *, void *), void *); 106368e6d53eSPatrick Farrell PETSC_EXTERN PetscErrorCode SNESPatchSetCellNumbering(SNES, PetscSection); 1064561742edSMatthew G. Knepley 1065a055c8caSBarry Smith /*E 1066a055c8caSBarry Smith SNESFASType - Determines the type of nonlinear multigrid method that is run. 1067a055c8caSBarry Smith 1068a055c8caSBarry Smith Values: 106987497f52SBarry Smith + `SNES_FAS_MULTIPLICATIVE` (default) - traditional V or W cycle as determined by `SNESFASSetCycles()` 107087497f52SBarry Smith . `SNES_FAS_ADDITIVE` - additive FAS cycle 107187497f52SBarry Smith . `SNES_FAS_FULL` - full FAS cycle 107287497f52SBarry Smith - `SNES_FAS_KASKADE` - Kaskade FAS cycle 1073a055c8caSBarry Smith 107416a05f60SBarry Smith Level: beginner 107516a05f60SBarry Smith 10761cc06b55SBarry Smith .seealso: [](ch_snes), `SNESFAS`, `PCMGSetType()`, `PCMGType` 1077a055c8caSBarry Smith E*/ 10789371c9d4SSatish Balay typedef enum { 10799371c9d4SSatish Balay SNES_FAS_MULTIPLICATIVE, 10809371c9d4SSatish Balay SNES_FAS_ADDITIVE, 10819371c9d4SSatish Balay SNES_FAS_FULL, 10829371c9d4SSatish Balay SNES_FAS_KASKADE 10839371c9d4SSatish Balay } SNESFASType; 1084a055c8caSBarry Smith PETSC_EXTERN const char *const SNESFASTypes[]; 1085a055c8caSBarry Smith 1086a055c8caSBarry Smith /* called on the finest level FAS instance*/ 1087a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetType(SNES, SNESFASType); 1088a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetType(SNES, SNESFASType *); 1089a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetLevels(SNES, PetscInt, MPI_Comm *); 1090a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetLevels(SNES, PetscInt *); 1091a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetCycleSNES(SNES, PetscInt, SNES *); 1092a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetNumberSmoothUp(SNES, PetscInt); 1093a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetNumberSmoothDown(SNES, PetscInt); 1094a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetCycles(SNES, PetscInt); 1095d142ab34SLawrence Mitchell PETSC_EXTERN PetscErrorCode SNESFASSetMonitor(SNES, PetscViewerAndFormat *, PetscBool); 1096a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetLog(SNES, PetscBool); 1097a055c8caSBarry Smith 1098a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetGalerkin(SNES, PetscBool); 1099a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetGalerkin(SNES, PetscBool *); 110025acbd8eSLisandro Dalcin PETSC_EXTERN PetscErrorCode SNESFASGalerkinFunctionDefault(SNES, Vec, Vec, void *); 1101a055c8caSBarry Smith 1102a055c8caSBarry Smith /* called on any level -- "Cycle" FAS instance */ 1103a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmoother(SNES, SNES *); 1104a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmootherUp(SNES, SNES *); 1105a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmootherDown(SNES, SNES *); 1106a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetCorrection(SNES, SNES *); 1107a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetInterpolation(SNES, Mat *); 1108a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetRestriction(SNES, Mat *); 1109a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetInjection(SNES, Mat *); 1110a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleGetRScale(SNES, Vec *); 1111a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleSetCycles(SNES, PetscInt); 1112a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCycleIsFine(SNES, PetscBool *); 1113a055c8caSBarry Smith 1114a055c8caSBarry Smith /* called on the (outer) finest level FAS to set/get parameters on any level instance */ 1115a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetInterpolation(SNES, PetscInt, Mat); 1116a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetInterpolation(SNES, PetscInt, Mat *); 1117a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetRestriction(SNES, PetscInt, Mat); 1118a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetRestriction(SNES, PetscInt, Mat *); 1119a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetInjection(SNES, PetscInt, Mat); 1120a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetInjection(SNES, PetscInt, Mat *); 1121a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASSetRScale(SNES, PetscInt, Vec); 1122a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetRScale(SNES, PetscInt, Vec *); 1123020631bcSPeter Brune PETSC_EXTERN PetscErrorCode SNESFASSetContinuation(SNES, PetscBool); 1124a055c8caSBarry Smith 1125a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetSmoother(SNES, PetscInt, SNES *); 1126a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetSmootherUp(SNES, PetscInt, SNES *); 1127a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetSmootherDown(SNES, PetscInt, SNES *); 1128a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASGetCoarseSolve(SNES, SNES *); 1129a055c8caSBarry Smith 1130a055c8caSBarry Smith /* parameters for full FAS */ 1131a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASFullSetDownSweep(SNES, PetscBool); 1132a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASCreateCoarseVec(SNES, Vec *); 1133a055c8caSBarry Smith PETSC_EXTERN PetscErrorCode SNESFASRestrict(SNES, Vec, Vec); 11346dfbafefSToby Isaac PETSC_EXTERN PetscErrorCode SNESFASFullSetTotal(SNES, PetscBool); 11356dfbafefSToby Isaac PETSC_EXTERN PetscErrorCode SNESFASFullGetTotal(SNES, PetscBool *); 1136a055c8caSBarry Smith 1137f2cacb80SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMSNESCheckDiscretization(SNES, DM, PetscReal, Vec, PetscReal, PetscReal[]); 1138f3c94560SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMSNESCheckResidual(SNES, DM, Vec, PetscReal, PetscReal *); 1139f3c94560SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMSNESCheckJacobian(SNES, DM, Vec, PetscReal, PetscBool *, PetscReal *); 11407f96f943SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMSNESCheckFromOptions(SNES, Vec); 11418e3a2eefSMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMSNESComputeJacobianAction(DM, Vec, Vec, Vec, void *); 11428e3a2eefSMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMSNESCreateJacobianMF(DM, Vec, void *, Mat *); 1143