1 /* 2 User interface for the nonlinear solvers package. 3 */ 4 #pragma once 5 6 #include <petscksp.h> 7 #include <petscdmtypes.h> 8 #include <petscfvtypes.h> 9 #include <petscdmdatypes.h> 10 #include <petscsnestypes.h> 11 12 /* SUBMANSEC = SNES */ 13 14 /*J 15 SNESType - String with the name of a PETSc `SNES` method. 16 17 Level: beginner 18 19 .seealso: [](doc_nonlinsolve), [](ch_snes), `SNESSetType()`, `SNES`, `SNESCreate()`, `SNESDestroy()`, `SNESSetFromOptions()` 20 J*/ 21 typedef const char *SNESType; 22 #define SNESNEWTONLS "newtonls" 23 #define SNESNEWTONTR "newtontr" 24 #define SNESNEWTONTRDC "newtontrdc" 25 #define SNESPYTHON "python" 26 #define SNESNRICHARDSON "nrichardson" 27 #define SNESKSPONLY "ksponly" 28 #define SNESKSPTRANSPOSEONLY "ksptransposeonly" 29 #define SNESVINEWTONRSLS "vinewtonrsls" 30 #define SNESVINEWTONSSLS "vinewtonssls" 31 #define SNESNGMRES "ngmres" 32 #define SNESQN "qn" 33 #define SNESSHELL "shell" 34 #define SNESNGS "ngs" 35 #define SNESNCG "ncg" 36 #define SNESFAS "fas" 37 #define SNESMS "ms" 38 #define SNESNASM "nasm" 39 #define SNESANDERSON "anderson" 40 #define SNESASPIN "aspin" 41 #define SNESCOMPOSITE "composite" 42 #define SNESPATCH "patch" 43 44 /* Logging support */ 45 PETSC_EXTERN PetscClassId SNES_CLASSID; 46 PETSC_EXTERN PetscClassId DMSNES_CLASSID; 47 48 PETSC_EXTERN PetscErrorCode SNESInitializePackage(void); 49 PETSC_EXTERN PetscErrorCode SNESFinalizePackage(void); 50 51 PETSC_EXTERN PetscErrorCode SNESCreate(MPI_Comm, SNES *); 52 PETSC_EXTERN PetscErrorCode SNESParametersInitialize(SNES); 53 PETSC_EXTERN PetscErrorCode SNESReset(SNES); 54 PETSC_EXTERN PetscErrorCode SNESDestroy(SNES *); 55 PETSC_EXTERN PetscErrorCode SNESSetType(SNES, SNESType); 56 PETSC_EXTERN PetscErrorCode SNESMonitor(SNES, PetscInt, PetscReal); 57 PETSC_EXTERN PetscErrorCode SNESMonitorSet(SNES, PetscErrorCode (*)(SNES, PetscInt, PetscReal, void *), void *, PetscErrorCode (*)(void **)); 58 PETSC_EXTERN PetscErrorCode SNESMonitorSetFromOptions(SNES, const char[], const char[], const char[], PetscErrorCode (*)(SNES, PetscInt, PetscReal, PetscViewerAndFormat *), PetscErrorCode (*)(SNES, PetscViewerAndFormat *)); 59 PETSC_EXTERN PetscErrorCode SNESMonitorCancel(SNES); 60 PETSC_EXTERN PetscErrorCode SNESMonitorSAWs(SNES, PetscInt, PetscReal, void *); 61 PETSC_EXTERN PetscErrorCode SNESMonitorSAWsCreate(SNES, void **); 62 PETSC_EXTERN PetscErrorCode SNESMonitorSAWsDestroy(void **); 63 PETSC_EXTERN PetscErrorCode SNESSetConvergenceHistory(SNES, PetscReal[], PetscInt[], PetscInt, PetscBool); 64 PETSC_EXTERN PetscErrorCode SNESGetConvergenceHistory(SNES, PetscReal *[], PetscInt *[], PetscInt *); 65 PETSC_EXTERN PetscErrorCode SNESSetUp(SNES); 66 PETSC_EXTERN PetscErrorCode SNESSolve(SNES, Vec, Vec); 67 PETSC_EXTERN PetscErrorCode SNESSetErrorIfNotConverged(SNES, PetscBool); 68 PETSC_EXTERN PetscErrorCode SNESGetErrorIfNotConverged(SNES, PetscBool *); 69 PETSC_EXTERN PetscErrorCode SNESConverged(SNES, PetscInt, PetscReal, PetscReal, PetscReal); 70 71 PETSC_EXTERN PetscErrorCode SNESSetWorkVecs(SNES, PetscInt); 72 73 PETSC_EXTERN PetscErrorCode SNESAddOptionsChecker(PetscErrorCode (*)(SNES)); 74 75 PETSC_EXTERN PetscErrorCode SNESRegister(const char[], PetscErrorCode (*)(SNES)); 76 77 PETSC_EXTERN PetscErrorCode SNESGetKSP(SNES, KSP *); 78 PETSC_EXTERN PetscErrorCode SNESSetKSP(SNES, KSP); 79 PETSC_EXTERN PetscErrorCode SNESSetSolution(SNES, Vec); 80 PETSC_EXTERN PetscErrorCode SNESGetSolution(SNES, Vec *); 81 PETSC_EXTERN PetscErrorCode SNESGetSolutionUpdate(SNES, Vec *); 82 PETSC_EXTERN PetscErrorCode SNESGetRhs(SNES, Vec *); 83 PETSC_EXTERN PetscErrorCode SNESView(SNES, PetscViewer); 84 PETSC_EXTERN PetscErrorCode SNESLoad(SNES, PetscViewer); 85 PETSC_EXTERN PetscErrorCode SNESConvergedReasonViewSet(SNES, PetscErrorCode (*)(SNES, void *), void *, PetscErrorCode (*)(void **)); 86 PETSC_EXTERN PetscErrorCode SNESViewFromOptions(SNES, PetscObject, const char[]); 87 PETSC_EXTERN PetscErrorCode SNESConvergedReasonView(SNES, PetscViewer); 88 PETSC_EXTERN PetscErrorCode SNESConvergedReasonViewFromOptions(SNES); 89 PETSC_EXTERN PetscErrorCode SNESConvergedReasonViewCancel(SNES); 90 91 PETSC_DEPRECATED_FUNCTION(3, 14, 0, "SNESConvergedReasonView()", ) static inline PetscErrorCode SNESReasonView(SNES snes, PetscViewer v) 92 { 93 return SNESConvergedReasonView(snes, v); 94 } 95 PETSC_DEPRECATED_FUNCTION(3, 14, 0, "SNESConvergedReasonViewFromOptions()", ) static inline PetscErrorCode SNESReasonViewFromOptions(SNES snes) 96 { 97 return SNESConvergedReasonViewFromOptions(snes); 98 } 99 100 #define SNES_FILE_CLASSID 1211224 101 102 PETSC_EXTERN PetscErrorCode SNESSetOptionsPrefix(SNES, const char[]); 103 PETSC_EXTERN PetscErrorCode SNESAppendOptionsPrefix(SNES, const char[]); 104 PETSC_EXTERN PetscErrorCode SNESGetOptionsPrefix(SNES, const char *[]); 105 PETSC_EXTERN PetscErrorCode SNESSetFromOptions(SNES); 106 PETSC_EXTERN PetscErrorCode SNESResetFromOptions(SNES); 107 108 PETSC_EXTERN PetscErrorCode SNESSetUseMatrixFree(SNES, PetscBool, PetscBool); 109 PETSC_EXTERN PetscErrorCode SNESGetUseMatrixFree(SNES, PetscBool *, PetscBool *); 110 PETSC_EXTERN PetscErrorCode MatCreateSNESMF(SNES, Mat *); 111 PETSC_EXTERN PetscErrorCode MatSNESMFGetSNES(Mat, SNES *); 112 PETSC_EXTERN PetscErrorCode MatSNESMFSetReuseBase(Mat, PetscBool); 113 PETSC_EXTERN PetscErrorCode MatSNESMFGetReuseBase(Mat, PetscBool *); 114 PETSC_EXTERN PetscErrorCode MatMFFDComputeJacobian(SNES, Vec, Mat, Mat, void *); 115 PETSC_EXTERN PetscErrorCode MatCreateSNESMFMore(SNES, Vec, Mat *); 116 PETSC_EXTERN PetscErrorCode MatSNESMFMoreSetParameters(Mat, PetscReal, PetscReal, PetscReal); 117 118 PETSC_EXTERN PetscErrorCode SNESGetType(SNES, SNESType *); 119 PETSC_EXTERN PetscErrorCode SNESMonitorDefaultSetUp(SNES, PetscViewerAndFormat *); 120 PETSC_EXTERN PetscErrorCode SNESMonitorDefault(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 121 PETSC_EXTERN PetscErrorCode SNESMonitorScaling(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 122 PETSC_EXTERN PetscErrorCode SNESMonitorRange(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 123 PETSC_EXTERN PetscErrorCode SNESMonitorRatio(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 124 PETSC_EXTERN PetscErrorCode SNESMonitorRatioSetUp(SNES, PetscViewerAndFormat *); 125 PETSC_EXTERN PetscErrorCode SNESMonitorSolution(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 126 PETSC_EXTERN PetscErrorCode SNESMonitorResidual(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 127 PETSC_EXTERN PetscErrorCode SNESMonitorSolutionUpdate(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 128 PETSC_EXTERN PetscErrorCode SNESMonitorDefaultShort(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 129 PETSC_EXTERN PetscErrorCode SNESMonitorDefaultField(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 130 PETSC_EXTERN PetscErrorCode SNESMonitorJacUpdateSpectrum(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 131 PETSC_EXTERN PetscErrorCode SNESMonitorFields(SNES, PetscInt, PetscReal, PetscViewerAndFormat *); 132 PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidual(KSP, PetscInt, PetscReal, PetscViewerAndFormat *); 133 PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidualDrawLG(KSP, PetscInt, PetscReal, PetscViewerAndFormat *); 134 PETSC_EXTERN PetscErrorCode KSPMonitorSNESResidualDrawLGCreate(PetscViewer, PetscViewerFormat, void *, PetscViewerAndFormat **); 135 136 PETSC_EXTERN PetscErrorCode SNESSetTolerances(SNES, PetscReal, PetscReal, PetscReal, PetscInt, PetscInt); 137 PETSC_EXTERN PetscErrorCode SNESSetDivergenceTolerance(SNES, PetscReal); 138 PETSC_EXTERN PetscErrorCode SNESGetTolerances(SNES, PetscReal *, PetscReal *, PetscReal *, PetscInt *, PetscInt *); 139 PETSC_EXTERN PetscErrorCode SNESGetDivergenceTolerance(SNES, PetscReal *); 140 PETSC_EXTERN PetscErrorCode SNESSetTrustRegionTolerance(SNES, PetscReal); 141 PETSC_EXTERN PetscErrorCode SNESGetForceIteration(SNES, PetscBool *); 142 PETSC_EXTERN PetscErrorCode SNESSetForceIteration(SNES, PetscBool); 143 PETSC_EXTERN PetscErrorCode SNESGetIterationNumber(SNES, PetscInt *); 144 PETSC_EXTERN PetscErrorCode SNESSetIterationNumber(SNES, PetscInt); 145 146 /*E 147 SNESNewtonTRFallbackType - type of fallback in case the solution of the trust-region subproblem is outside of the radius 148 149 Values: 150 + `SNES_TR_FALLBACK_NEWTON` - use scaled Newton step 151 . `SNES_TR_FALLBACK_CAUCHY` - use Cauchy direction 152 - `SNES_TR_FALLBACK_DOGLEG` - use dogleg method 153 154 Level: intermediate 155 156 .seealso: [](ch_snes), `SNES`, `SNESNEWTONTR`, `SNESNEWTONTRDC` 157 E*/ 158 typedef enum { 159 SNES_TR_FALLBACK_NEWTON, 160 SNES_TR_FALLBACK_CAUCHY, 161 SNES_TR_FALLBACK_DOGLEG, 162 } SNESNewtonTRFallbackType; 163 164 PETSC_EXTERN const char *const SNESNewtonTRFallbackTypes[]; 165 166 PETSC_EXTERN PetscErrorCode SNESNewtonTRSetPreCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, PetscBool *, void *), void *ctx); 167 PETSC_EXTERN PetscErrorCode SNESNewtonTRGetPreCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, PetscBool *, void *), void **ctx); 168 PETSC_EXTERN PetscErrorCode SNESNewtonTRSetPostCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void *ctx); 169 PETSC_EXTERN PetscErrorCode SNESNewtonTRGetPostCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void **ctx); 170 PETSC_EXTERN PetscErrorCode SNESNewtonTRSetFallbackType(SNES, SNESNewtonTRFallbackType); 171 PETSC_EXTERN PetscErrorCode SNESNewtonTRPreCheck(SNES, Vec, Vec, PetscBool *); 172 PETSC_EXTERN PetscErrorCode SNESNewtonTRPostCheck(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *); 173 PETSC_EXTERN PetscErrorCode SNESNewtonTRSetNormType(SNES, NormType); 174 175 /*E 176 SNESNewtonTRQNType - type of quasi-Newton model to use 177 178 Values: 179 + `SNES_TR_QN_NONE` - do not use a quasi-Newton model 180 . `SNES_TR_QN_SAME` - use the same quasi-Newton model for matrix and preconditioner 181 - `SNES_TR_QN_DIFFERENT` - use different quasi-Newton models for matrix and preconditioner 182 183 Level: intermediate 184 185 .seealso: [](ch_snes), `SNES`, `SNESNEWTONTR` 186 E*/ 187 typedef enum { 188 SNES_TR_QN_NONE, 189 SNES_TR_QN_SAME, 190 SNES_TR_QN_DIFFERENT, 191 } SNESNewtonTRQNType; 192 193 PETSC_EXTERN const char *const SNESNewtonTRQNTypes[]; 194 195 PETSC_EXTERN PetscErrorCode SNESNewtonTRSetQNType(SNES, SNESNewtonTRQNType); 196 197 PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetRhoFlag(SNES, PetscBool *); 198 PETSC_EXTERN PetscErrorCode SNESNewtonTRDCSetPreCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, PetscBool *, void *), void *ctx); 199 PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetPreCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, PetscBool *, void *), void **ctx); 200 PETSC_EXTERN PetscErrorCode SNESNewtonTRDCSetPostCheck(SNES, PetscErrorCode (*)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void *ctx); 201 PETSC_EXTERN PetscErrorCode SNESNewtonTRDCGetPostCheck(SNES, PetscErrorCode (**)(SNES, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void **ctx); 202 203 PETSC_EXTERN PetscErrorCode SNESGetNonlinearStepFailures(SNES, PetscInt *); 204 PETSC_EXTERN PetscErrorCode SNESSetMaxNonlinearStepFailures(SNES, PetscInt); 205 PETSC_EXTERN PetscErrorCode SNESGetMaxNonlinearStepFailures(SNES, PetscInt *); 206 PETSC_EXTERN PetscErrorCode SNESGetNumberFunctionEvals(SNES, PetscInt *); 207 208 PETSC_EXTERN PetscErrorCode SNESSetLagPreconditioner(SNES, PetscInt); 209 PETSC_EXTERN PetscErrorCode SNESGetLagPreconditioner(SNES, PetscInt *); 210 PETSC_EXTERN PetscErrorCode SNESSetLagJacobian(SNES, PetscInt); 211 PETSC_EXTERN PetscErrorCode SNESGetLagJacobian(SNES, PetscInt *); 212 PETSC_EXTERN PetscErrorCode SNESSetLagPreconditionerPersists(SNES, PetscBool); 213 PETSC_EXTERN PetscErrorCode SNESSetLagJacobianPersists(SNES, PetscBool); 214 PETSC_EXTERN PetscErrorCode SNESSetGridSequence(SNES, PetscInt); 215 PETSC_EXTERN PetscErrorCode SNESGetGridSequence(SNES, PetscInt *); 216 217 PETSC_EXTERN PetscErrorCode SNESGetLinearSolveIterations(SNES, PetscInt *); 218 PETSC_EXTERN PetscErrorCode SNESGetLinearSolveFailures(SNES, PetscInt *); 219 PETSC_EXTERN PetscErrorCode SNESSetMaxLinearSolveFailures(SNES, PetscInt); 220 PETSC_EXTERN PetscErrorCode SNESGetMaxLinearSolveFailures(SNES, PetscInt *); 221 PETSC_EXTERN PetscErrorCode SNESSetCountersReset(SNES, PetscBool); 222 223 PETSC_EXTERN PetscErrorCode SNESKSPSetUseEW(SNES, PetscBool); 224 PETSC_EXTERN PetscErrorCode SNESKSPGetUseEW(SNES, PetscBool *); 225 PETSC_EXTERN PetscErrorCode SNESKSPSetParametersEW(SNES, PetscInt, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal); 226 PETSC_EXTERN PetscErrorCode SNESKSPGetParametersEW(SNES, PetscInt *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *); 227 228 #include <petscdrawtypes.h> 229 PETSC_EXTERN PetscErrorCode SNESMonitorLGRange(SNES, PetscInt, PetscReal, void *); 230 231 PETSC_EXTERN PetscErrorCode SNESSetApplicationContext(SNES, void *); 232 PETSC_EXTERN PetscErrorCode SNESGetApplicationContext(SNES, void *); 233 PETSC_EXTERN PetscErrorCode SNESSetComputeApplicationContext(SNES, PetscErrorCode (*)(SNES, void **), PetscErrorCode (*)(void **)); 234 235 PETSC_EXTERN PetscErrorCode SNESPythonSetType(SNES, const char[]); 236 PETSC_EXTERN PetscErrorCode SNESPythonGetType(SNES, const char *[]); 237 238 PETSC_EXTERN PetscErrorCode SNESSetFunctionDomainError(SNES); 239 PETSC_EXTERN PetscErrorCode SNESGetFunctionDomainError(SNES, PetscBool *); 240 PETSC_EXTERN PetscErrorCode SNESGetJacobianDomainError(SNES, PetscBool *); 241 PETSC_EXTERN PetscErrorCode SNESSetJacobianDomainError(SNES); 242 PETSC_EXTERN PetscErrorCode SNESSetCheckJacobianDomainError(SNES, PetscBool); 243 PETSC_EXTERN PetscErrorCode SNESGetCheckJacobianDomainError(SNES, PetscBool *); 244 245 #define SNES_CONVERGED_TR_DELTA_DEPRECATED SNES_CONVERGED_TR_DELTA PETSC_DEPRECATED_ENUM(3, 12, 0, "SNES_DIVERGED_TR_DELTA", ) 246 /*E 247 SNESConvergedReason - reason a `SNESSolve()` was determined to have converged or diverged 248 249 Values: 250 + `SNES_CONVERGED_FNORM_ABS` - 2-norm(F) <= abstol 251 . `SNES_CONVERGED_FNORM_RELATIVE` - 2-norm(F) <= rtol*2-norm(F(x_0)) where x_0 is the initial guess 252 . `SNES_CONVERGED_SNORM_RELATIVE` - The 2-norm of the last step <= stol * 2-norm(x) where x is the current 253 . `SNES_DIVERGED_FUNCTION_COUNT` - The user provided function has been called more times than the maximum set in `SNESSetTolerances()` 254 . `SNES_DIVERGED_DTOL` - The norm of the function has increased by a factor of divtol set with `SNESSetDivergenceTolerance()` 255 . `SNES_DIVERGED_FNORM_NAN` - the 2-norm of the current function evaluation is not-a-number (NaN), this 256 is usually caused by a division of 0 by 0. 257 . `SNES_DIVERGED_MAX_IT` - `SNESSolve()` has reached the maximum number of iterations requested 258 . `SNES_DIVERGED_LINE_SEARCH` - The line search has failed. This only occurs for `SNES` solvers that use a line search 259 . `SNES_DIVERGED_LOCAL_MIN` - the algorithm seems to have stagnated at a local minimum that is not zero. 260 - `SNES_CONERGED_ITERATING` - this only occurs if `SNESGetConvergedReason()` is called during the `SNESSolve()` 261 262 Level: beginner 263 264 Notes: 265 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 266 testing with `-pc_type lu` to eliminate the linear solver as the cause of the problem). 267 268 `SNES_DIVERGED_LOCAL_MIN` can only occur when using the line-search variant of `SNES`. 269 The line search wants to minimize Q(alpha) = 1/2 || F(x + alpha s) ||^2_2 this occurs 270 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 271 you get Q'(alpha) = -F(x)^T F'(x)^(-1)^T F'(x+alpha s)F(x+alpha s); when alpha = 0 272 Q'(0) = - ||F(x)||^2_2 which is always NEGATIVE if F'(x) is invertible. This means the Newton 273 direction is a descent direction and the line search should succeed if alpha is small enough. 274 275 If F'(x) is NOT invertible AND F'(x)^T F(x) = 0 then Q'(0) = 0 and the Newton direction 276 is NOT a descent direction so the line search will fail. All one can do at this point 277 is change the initial guess and try again. 278 279 An alternative explanation: Newton's method can be regarded as replacing the function with 280 its linear approximation and minimizing the 2-norm of that. That is F(x+s) approx F(x) + F'(x)s 281 so we minimize || F(x) + F'(x) s ||^2_2; do this using Least Squares. If F'(x) is invertible then 282 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 283 exists a nontrivial (that is F'(x)s != 0) solution to the equation and this direction is 284 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) 285 = - (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 286 and F'(x)^T F'(x) has no negative eigenvalues Q'(0) < 0 so s is a descent direction and the line 287 search should succeed for small enough alpha. 288 289 Note that this RARELY happens in practice. Far more likely the linear system is not being solved 290 (well enough?) or the Jacobian is wrong. 291 292 `SNES_DIVERGED_MAX_IT` means that the solver reached the maximum number of iterations without satisfying any 293 convergence criteria. `SNES_CONVERGED_ITS` means that `SNESConvergedSkip()` was chosen as the convergence test; 294 thus the usual convergence criteria have not been checked and may or may not be satisfied. 295 296 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPConvergedReason`, `SNESSetConvergenceTest()`, `SNESSetTolerances()` 297 E*/ 298 typedef enum { /* converged */ 299 SNES_CONVERGED_FNORM_ABS = 2, /* ||F|| < atol */ 300 SNES_CONVERGED_FNORM_RELATIVE = 3, /* ||F|| < rtol*||F_initial|| */ 301 SNES_CONVERGED_SNORM_RELATIVE = 4, /* Newton computed step size small; || delta x || < stol || x ||*/ 302 SNES_CONVERGED_ITS = 5, /* maximum iterations reached */ 303 SNES_BREAKOUT_INNER_ITER = 6, /* Flag to break out of inner loop after checking custom convergence. */ 304 /* it is used in multi-phase flow when state changes */ 305 /* diverged */ 306 SNES_DIVERGED_FUNCTION_DOMAIN = -1, /* the new x location passed the function is not in the domain of F */ 307 SNES_DIVERGED_FUNCTION_COUNT = -2, 308 SNES_DIVERGED_LINEAR_SOLVE = -3, /* the linear solve failed */ 309 SNES_DIVERGED_FNORM_NAN = -4, 310 SNES_DIVERGED_MAX_IT = -5, 311 SNES_DIVERGED_LINE_SEARCH = -6, /* the line search failed */ 312 SNES_DIVERGED_INNER = -7, /* inner solve failed */ 313 SNES_DIVERGED_LOCAL_MIN = -8, /* || J^T b || is small, implies converged to local minimum of F() */ 314 SNES_DIVERGED_DTOL = -9, /* || F || > divtol*||F_initial|| */ 315 SNES_DIVERGED_JACOBIAN_DOMAIN = -10, /* Jacobian calculation does not make sense */ 316 SNES_DIVERGED_TR_DELTA = -11, 317 SNES_CONVERGED_TR_DELTA_DEPRECATED = -11, 318 319 SNES_CONVERGED_ITERATING = 0 320 } SNESConvergedReason; 321 PETSC_EXTERN const char *const *SNESConvergedReasons; 322 323 /*MC 324 SNES_CONVERGED_FNORM_ABS - 2-norm(F) <= abstol 325 326 Level: beginner 327 328 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 329 M*/ 330 331 /*MC 332 SNES_CONVERGED_FNORM_RELATIVE - 2-norm(F) <= rtol*2-norm(F(x_0)) where x_0 is the initial guess 333 334 Level: beginner 335 336 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 337 M*/ 338 339 /*MC 340 SNES_CONVERGED_SNORM_RELATIVE - The 2-norm of the last step <= stol * 2-norm(x) where x is the current 341 solution and stol is the 4th argument to `SNESSetTolerances()` 342 343 Options Database Key: 344 -snes_stol <stol> - the step tolerance 345 346 Level: beginner 347 348 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 349 M*/ 350 351 /*MC 352 SNES_DIVERGED_FUNCTION_COUNT - The user provided function has been called more times then the final 353 argument to `SNESSetTolerances()` 354 355 Level: beginner 356 357 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 358 M*/ 359 360 /*MC 361 SNES_DIVERGED_DTOL - The norm of the function has increased by a factor of divtol set with `SNESSetDivergenceTolerance()` 362 363 Level: beginner 364 365 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`, `SNESSetDivergenceTolerance()` 366 M*/ 367 368 /*MC 369 SNES_DIVERGED_FNORM_NAN - the 2-norm of the current function evaluation is not-a-number (NaN), this 370 is usually caused by a division of 0 by 0. 371 372 Level: beginner 373 374 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 375 M*/ 376 377 /*MC 378 SNES_DIVERGED_MAX_IT - SNESSolve() has reached the maximum number of iterations requested 379 380 Level: beginner 381 382 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 383 M*/ 384 385 /*MC 386 SNES_DIVERGED_LINE_SEARCH - The line search has failed. This only occurs for a `SNES` solvers that use a line search 387 388 Level: beginner 389 390 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()`, `SNESLineSearch` 391 M*/ 392 393 /*MC 394 SNES_DIVERGED_LOCAL_MIN - the algorithm seems to have stagnated at a local minimum that is not zero. 395 See the manual page for `SNESConvergedReason` for more details 396 397 Level: beginner 398 399 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 400 M*/ 401 402 /*MC 403 SNES_CONERGED_ITERATING - this only occurs if `SNESGetConvergedReason()` is called during the `SNESSolve()` 404 405 Level: beginner 406 407 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `SNESConvergedReason`, `SNESSetTolerances()` 408 M*/ 409 410 PETSC_EXTERN PetscErrorCode SNESSetConvergenceTest(SNES, PetscErrorCode (*)(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, void *), void *, PetscErrorCode (*)(void *)); 411 PETSC_EXTERN PetscErrorCode SNESConvergedDefault(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, void *); 412 PETSC_EXTERN PetscErrorCode SNESConvergedSkip(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, void *); 413 PETSC_EXTERN PetscErrorCode SNESConvergedCorrectPressure(SNES, PetscInt, PetscReal, PetscReal, PetscReal, SNESConvergedReason *, void *); 414 PETSC_EXTERN PetscErrorCode SNESGetConvergedReason(SNES, SNESConvergedReason *); 415 PETSC_EXTERN PetscErrorCode SNESGetConvergedReasonString(SNES, const char **); 416 PETSC_EXTERN PetscErrorCode SNESSetConvergedReason(SNES, SNESConvergedReason); 417 418 PETSC_DEPRECATED_FUNCTION(3, 5, 0, "SNESConvergedSkip()", ) static inline void SNESSkipConverged(void) 419 { /* never called */ 420 } 421 #define SNESSkipConverged (SNESSkipConverged, SNESConvergedSkip) 422 423 /*S 424 SNESInitialGuessFn - A prototype of a `SNES` compute initial guess function that would be passed to `SNESSetComputeInitialGuess()` 425 426 Calling Sequence: 427 + snes - `SNES` context 428 . u - output vector to contain initial guess 429 - ctx - [optional] user-defined function context 430 431 Level: beginner 432 433 .seealso: [](ch_snes), `SNES`, `SNESSetComputeInitialGuess()`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`, `SNESFunctionFn` 434 S*/ 435 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESInitialGuessFn)(SNES snes, Vec u, void *ctx); 436 437 /*S 438 SNESFunctionFn - A prototype of a `SNES` evaluation function that would be passed to `SNESSetFunction()` 439 440 Calling Sequence: 441 + snes - `SNES` context 442 . u - input vector 443 . F - function vector 444 - ctx - [optional] user-defined function context 445 446 Level: beginner 447 448 .seealso: [](ch_snes), `SNES`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`, `SNESNGSFn` 449 S*/ 450 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESFunctionFn)(SNES snes, Vec u, Vec F, void *ctx); 451 452 /*S 453 SNESObjectiveFn - A prototype of a `SNES` objective evaluation function that would be passed to `SNESSetObjective()` 454 455 Calling Sequence: 456 + snes - `SNES` context 457 . u - input vector 458 . o - output value 459 - ctx - [optional] user-defined function context 460 461 Level: beginner 462 463 .seealso: [](ch_snes), `SNES`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn`, `SNESNGSFn` 464 S*/ 465 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESObjectiveFn)(SNES snes, Vec u, PetscReal *o, void *ctx); 466 467 /*S 468 SNESJacobianFn - A prototype of a `SNES` Jacobian evaluation function that would be passed to `SNESSetJacobian()` 469 470 Calling Sequence: 471 + snes - the `SNES` context obtained from `SNESCreate()` 472 . u - input vector 473 . Amat - (approximate) Jacobian matrix 474 . Pmat - matrix used to construct the preconditioner, often the same as `Amat` 475 - ctx - [optional] user-defined context for matrix evaluation routine 476 477 Level: beginner 478 479 .seealso: [](ch_snes), `SNES`, `SNESSetJacobian()`, `SNESGetJacobian()`, `SNESFunctionFn`, `SNESNGSFn` 480 S*/ 481 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESJacobianFn)(SNES snes, Vec u, Mat Amat, Mat Pmat, void *ctx); 482 483 /*S 484 SNESNGSFn - A prototype of a `SNES` nonlinear Gauss-Seidel function that would be passed to `SNESSetNGS()` 485 486 Calling Sequence: 487 + snes - the `SNES` context obtained from `SNESCreate()` 488 . u - the current solution, updated in place 489 . b - the right-hand side vector (which may be `NULL`) 490 - ctx - [optional] user-defined context for matrix evaluation routine 491 492 Level: beginner 493 494 .seealso: [](ch_snes), `SNES`, `SNESSetJacobian()`, `SNESGetJacobian()`, `SNESFunctionFn`, `SNESSetFunction()`, `SNESGetFunction()`, `SNESJacobianFn` 495 S*/ 496 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESNGSFn)(SNES snes, Vec u, Vec b, void *ctx); 497 498 /*S 499 SNESUpdateFn - A prototype of a `SNES` update function that would be passed to `SNESSetUpdate()` 500 501 Calling Sequence: 502 + snes - `SNES` context 503 - step - the current iteration index 504 505 Level: advanced 506 507 .seealso: [](ch_snes), `SNES`, `SNESSetUpdate()` 508 S*/ 509 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESUpdateFn)(SNES snes, PetscInt step); 510 511 /* --------- Solving systems of nonlinear equations --------------- */ 512 PETSC_EXTERN PetscErrorCode SNESSetFunction(SNES, Vec, SNESFunctionFn *, void *); 513 PETSC_EXTERN PetscErrorCode SNESGetFunction(SNES, Vec *, SNESFunctionFn **, void **); 514 PETSC_EXTERN PetscErrorCode SNESComputeFunction(SNES, Vec, Vec); 515 PETSC_EXTERN PetscErrorCode SNESComputeMFFunction(SNES, Vec, Vec); 516 PETSC_EXTERN PetscErrorCode SNESSetInitialFunction(SNES, Vec); 517 518 PETSC_EXTERN PetscErrorCode SNESSetJacobian(SNES, Mat, Mat, SNESJacobianFn *, void *); 519 PETSC_EXTERN PetscErrorCode SNESGetJacobian(SNES, Mat *, Mat *, SNESJacobianFn **, void **); 520 PETSC_EXTERN SNESFunctionFn SNESObjectiveComputeFunctionDefaultFD; 521 PETSC_EXTERN SNESJacobianFn SNESComputeJacobianDefault; 522 PETSC_EXTERN SNESJacobianFn SNESComputeJacobianDefaultColor; 523 PETSC_EXTERN PetscErrorCode SNESPruneJacobianColor(SNES, Mat, Mat); 524 PETSC_EXTERN PetscErrorCode SNESSetComputeInitialGuess(SNES, SNESInitialGuessFn *, void *); 525 PETSC_EXTERN PetscErrorCode SNESSetPicard(SNES, Vec, SNESFunctionFn *, Mat, Mat, SNESJacobianFn *, void *); 526 PETSC_EXTERN PetscErrorCode SNESGetPicard(SNES, Vec *, SNESFunctionFn **, Mat *, Mat *, SNESJacobianFn **, void **); 527 PETSC_EXTERN SNESFunctionFn SNESPicardComputeFunction; 528 PETSC_EXTERN SNESFunctionFn SNESPicardComputeMFFunction; 529 PETSC_EXTERN SNESJacobianFn SNESPicardComputeJacobian; 530 531 PETSC_EXTERN PetscErrorCode SNESSetObjective(SNES, SNESObjectiveFn *, void *); 532 PETSC_EXTERN PetscErrorCode SNESGetObjective(SNES, SNESObjectiveFn **, void **); 533 PETSC_EXTERN PetscErrorCode SNESComputeObjective(SNES, Vec, PetscReal *); 534 535 PETSC_EXTERN PetscErrorCode SNESSetUpdate(SNES, SNESUpdateFn *); 536 537 /*E 538 SNESNormSchedule - Frequency with which the norm is computed during a nonliner solve 539 540 Values: 541 + `SNES_NORM_DEFAULT` - use the default behavior for the current `SNESType` 542 . `SNES_NORM_NONE` - avoid all norm computations 543 . `SNES_NORM_ALWAYS` - compute the norms whenever possible 544 . `SNES_NORM_INITIAL_ONLY` - compute the norm only when the algorithm starts 545 . `SNES_NORM_FINAL_ONLY` - compute the norm only when the algorithm finishes 546 - `SNES_NORM_INITIAL_FINAL_ONLY` - compute the norm at the start and end of the algorithm 547 548 Level: advanced 549 550 Notes: 551 Support for these is highly dependent on the solver. 552 553 Some options limit the convergence tests that can be used. 554 555 The `SNES_NORM_NONE` option is most commonly used when the nonlinear solver is being used as a smoother, for example for `SNESFAS` 556 557 This is primarily used to turn off extra norm and function computation 558 when the solvers are composed. 559 560 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPSetNormType()`, 561 `KSPSetConvergenceTest()`, `KSPSetPCSide()` 562 E*/ 563 typedef enum { 564 SNES_NORM_DEFAULT = -1, 565 SNES_NORM_NONE = 0, 566 SNES_NORM_ALWAYS = 1, 567 SNES_NORM_INITIAL_ONLY = 2, 568 SNES_NORM_FINAL_ONLY = 3, 569 SNES_NORM_INITIAL_FINAL_ONLY = 4 570 } SNESNormSchedule; 571 PETSC_EXTERN const char *const *const SNESNormSchedules; 572 573 /*MC 574 SNES_NORM_NONE - Don't compute function and its L2 norm when possible 575 576 Level: advanced 577 578 Note: 579 This is most useful for stationary solvers with a fixed number of iterations used as smoothers. 580 581 .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_DEFAULT` 582 M*/ 583 584 /*MC 585 SNES_NORM_ALWAYS - Compute the function and its L2 norm at each iteration. 586 587 Level: advanced 588 589 Note: 590 Most solvers will use this no matter what norm type is passed to them. 591 592 .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_NONE` 593 M*/ 594 595 /*MC 596 SNES_NORM_INITIAL_ONLY - Compute the function and its L2 at iteration 0, but do not update it. 597 598 Level: advanced 599 600 Notes: 601 This method is useful in composed methods, when a true solution might actually be found before `SNESSolve()` is called. 602 This option enables the solve to abort on the zeroth iteration if this is the case. 603 604 For solvers that require the computation of the L2 norm of the function as part of the method, this merely cancels 605 the norm computation at the last iteration (if possible). 606 607 .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_FINAL_ONLY`, `SNES_NORM_INITIAL_FINAL_ONLY` 608 M*/ 609 610 /*MC 611 SNES_NORM_FINAL_ONLY - Compute the function and its L2 norm on only the final iteration. 612 613 Level: advanced 614 615 Note: 616 For solvers that require the computation of the L2 norm of the function as part of the method, behaves 617 exactly as `SNES_NORM_DEFAULT`. This method is useful when the function is gotten after `SNESSolve()` and 618 used in subsequent computation for methods that do not need the norm computed during the rest of the 619 solution procedure. 620 621 .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_INITIAL_ONLY`, `SNES_NORM_INITIAL_FINAL_ONLY` 622 M*/ 623 624 /*MC 625 SNES_NORM_INITIAL_FINAL_ONLY - Compute the function and its L2 norm on only the initial and final iterations. 626 627 Level: advanced 628 629 Note: 630 This method combines the benefits of `SNES_NORM_INITIAL_ONLY` and `SNES_NORM_FINAL_ONLY`. 631 632 .seealso: [](ch_snes), `SNESNormSchedule`, `SNES`, `SNESSetNormSchedule()`, `SNES_NORM_SNES_NORM_INITIAL_ONLY`, `SNES_NORM_FINAL_ONLY` 633 M*/ 634 635 PETSC_EXTERN PetscErrorCode SNESSetNormSchedule(SNES, SNESNormSchedule); 636 PETSC_EXTERN PetscErrorCode SNESGetNormSchedule(SNES, SNESNormSchedule *); 637 PETSC_EXTERN PetscErrorCode SNESSetFunctionNorm(SNES, PetscReal); 638 PETSC_EXTERN PetscErrorCode SNESGetFunctionNorm(SNES, PetscReal *); 639 PETSC_EXTERN PetscErrorCode SNESGetUpdateNorm(SNES, PetscReal *); 640 PETSC_EXTERN PetscErrorCode SNESGetSolutionNorm(SNES, PetscReal *); 641 642 /*E 643 SNESFunctionType - Type of function computed 644 645 Values: 646 + `SNES_FUNCTION_DEFAULT` - the default behavior for the current `SNESType` 647 . `SNES_FUNCTION_UNPRECONDITIONED` - the original function provided 648 - `SNES_FUNCTION_PRECONDITIONED` - the modification of the function by the preconditioner 649 650 Level: advanced 651 652 Note: 653 Support for these is dependent on the solver. 654 655 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPSetNormType()`, 656 `KSPSetConvergenceTest()`, `KSPSetPCSide()` 657 E*/ 658 typedef enum { 659 SNES_FUNCTION_DEFAULT = -1, 660 SNES_FUNCTION_UNPRECONDITIONED = 0, 661 SNES_FUNCTION_PRECONDITIONED = 1 662 } SNESFunctionType; 663 PETSC_EXTERN const char *const *const SNESFunctionTypes; 664 665 PETSC_EXTERN PetscErrorCode SNESSetFunctionType(SNES, SNESFunctionType); 666 PETSC_EXTERN PetscErrorCode SNESGetFunctionType(SNES, SNESFunctionType *); 667 668 PETSC_EXTERN PetscErrorCode SNESSetNGS(SNES, SNESNGSFn *, void *); 669 PETSC_EXTERN PetscErrorCode SNESGetNGS(SNES, SNESNGSFn **, void **); 670 PETSC_EXTERN PetscErrorCode SNESComputeNGS(SNES, Vec, Vec); 671 672 PETSC_EXTERN PetscErrorCode SNESNGSSetSweeps(SNES, PetscInt); 673 PETSC_EXTERN PetscErrorCode SNESNGSGetSweeps(SNES, PetscInt *); 674 PETSC_EXTERN PetscErrorCode SNESNGSSetTolerances(SNES, PetscReal, PetscReal, PetscReal, PetscInt); 675 PETSC_EXTERN PetscErrorCode SNESNGSGetTolerances(SNES, PetscReal *, PetscReal *, PetscReal *, PetscInt *); 676 677 PETSC_EXTERN PetscErrorCode SNESSetAlwaysComputesFinalResidual(SNES, PetscBool); 678 PETSC_EXTERN PetscErrorCode SNESGetAlwaysComputesFinalResidual(SNES, PetscBool *); 679 680 PETSC_EXTERN PetscErrorCode SNESShellGetContext(SNES, void *); 681 PETSC_EXTERN PetscErrorCode SNESShellSetContext(SNES, void *); 682 PETSC_EXTERN PetscErrorCode SNESShellSetSolve(SNES, PetscErrorCode (*)(SNES, Vec)); 683 684 /* --------- Routines specifically for line search methods --------------- */ 685 686 /*S 687 SNESLineSearch - Abstract PETSc object that manages line-search operations for nonlinear solvers 688 689 Level: beginner 690 691 .seealso: [](ch_snes), `SNESLineSearchType`, `SNESLineSearchCreate()`, `SNESLineSearchSetType()`, `SNES` 692 S*/ 693 typedef struct _p_LineSearch *SNESLineSearch; 694 695 /*J 696 SNESLineSearchType - String with the name of a PETSc line search method `SNESLineSearch` 697 698 Values: 699 + `SNESLINESEARCHBASIC` - (or equivalently `SNESLINESEARCHNONE`) Simple damping line search, defaults to using the full Newton step 700 . `SNESLINESEARCHBT` - Backtracking line search over the L2 norm of the function 701 . `SNESLINESEARCHL2` - Secant line search over the L2 norm of the function 702 . `SNESLINESEARCHCP` - Critical point secant line search assuming F(x) = grad G(x) for some unknown G(x) 703 . `SNESLINESEARCHNLEQERR` - Affine-covariant error-oriented linesearch 704 - `SNESLINESEARCHSHELL` - User provided `SNESLineSearch` implementation 705 706 Level: beginner 707 708 .seealso: [](ch_snes), `SNESLineSearch`, `SNESLineSearchSetType()`, `SNES` 709 J*/ 710 typedef const char *SNESLineSearchType; 711 #define SNESLINESEARCHBT "bt" 712 #define SNESLINESEARCHNLEQERR "nleqerr" 713 #define SNESLINESEARCHBASIC "basic" 714 #define SNESLINESEARCHNONE "none" 715 #define SNESLINESEARCHL2 "l2" 716 #define SNESLINESEARCHCP "cp" 717 #define SNESLINESEARCHSHELL "shell" 718 #define SNESLINESEARCHNCGLINEAR "ncglinear" 719 720 PETSC_EXTERN PetscFunctionList SNESList; 721 PETSC_EXTERN PetscClassId SNESLINESEARCH_CLASSID; 722 PETSC_EXTERN PetscFunctionList SNESLineSearchList; 723 724 #define SNES_LINESEARCH_ORDER_LINEAR 1 725 #define SNES_LINESEARCH_ORDER_QUADRATIC 2 726 #define SNES_LINESEARCH_ORDER_CUBIC 3 727 728 /*S 729 SNESLineSearchVIProjectFn - A prototype of a `SNES` function that projects a vector onto the VI bounds, passed to `SNESLineSearchSetVIFunctions()` 730 731 Calling Sequence: 732 + snes - `SNES` context 733 - u - the vector to project to the bounds 734 735 Level: advanced 736 737 Note: 738 The deprecated `SNESLineSearchVIProjectFunc` still works as a replacement for `SNESLineSearchVIProjectFn` *. 739 740 .seealso: [](ch_snes), `SNES`, `SNESLineSearch` 741 S*/ 742 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESLineSearchVIProjectFn)(SNES snes, Vec u); 743 PETSC_EXTERN_TYPEDEF typedef SNESLineSearchVIProjectFn *SNESLineSearchVIProjectFunc; // deprecated 744 745 /*S 746 SNESLineSearchVIProjectFn - A prototype of a `SNES` function that computes the norm of the active set variables in a vector in a VI solve, 747 passed to `SNESLineSearchSetVIFunctions()` 748 749 Calling Sequence: 750 + snes - `SNES` context 751 . f - the vector to compute the norm of 752 . u - the current solution, entries that are on the VI bounds are ignored 753 - fnorm - the resulting norm 754 755 Level: advanced 756 757 Note: 758 The deprecated `SNESLineSearchVINormFunc` still works as a replacement for `SNESLineSearchVINormFn` *. 759 760 .seealso: [](ch_snes), `SNES`, `SNESLineSearch` 761 S*/ 762 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESLineSearchVINormFn)(SNES snes, Vec f, Vec u, PetscReal *fnorm); 763 PETSC_EXTERN_TYPEDEF typedef SNESLineSearchVINormFn *SNESLineSearchVINormFunc; // deprecated 764 765 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESLineSearchApplyFn)(SNESLineSearch); 766 PETSC_EXTERN_TYPEDEF typedef SNESLineSearchApplyFn *SNESLineSearchApplyFunc; // deprecated 767 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(SNESLineSearchShellApplyFn)(SNESLineSearch, void *); 768 PETSC_EXTERN_TYPEDEF typedef SNESLineSearchShellApplyFn *SNESLineSearchUserFunc; // deprecated 769 770 PETSC_EXTERN PetscErrorCode SNESLineSearchCreate(MPI_Comm, SNESLineSearch *); 771 PETSC_EXTERN PetscErrorCode SNESLineSearchReset(SNESLineSearch); 772 PETSC_EXTERN PetscErrorCode SNESLineSearchView(SNESLineSearch, PetscViewer); 773 PETSC_EXTERN PetscErrorCode SNESLineSearchDestroy(SNESLineSearch *); 774 PETSC_EXTERN PetscErrorCode SNESLineSearchGetType(SNESLineSearch, SNESLineSearchType *); 775 PETSC_EXTERN PetscErrorCode SNESLineSearchSetType(SNESLineSearch, SNESLineSearchType); 776 PETSC_EXTERN PetscErrorCode SNESLineSearchSetFromOptions(SNESLineSearch); 777 PETSC_EXTERN PetscErrorCode SNESLineSearchSetFunction(SNESLineSearch, PetscErrorCode (*)(SNES, Vec, Vec)); 778 PETSC_EXTERN PetscErrorCode SNESLineSearchSetUp(SNESLineSearch); 779 PETSC_EXTERN PetscErrorCode SNESLineSearchApply(SNESLineSearch, Vec, Vec, PetscReal *, Vec); 780 PETSC_EXTERN PetscErrorCode SNESLineSearchPreCheck(SNESLineSearch, Vec, Vec, PetscBool *); 781 PETSC_EXTERN PetscErrorCode SNESLineSearchPostCheck(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *); 782 PETSC_EXTERN PetscErrorCode SNESLineSearchSetWorkVecs(SNESLineSearch, PetscInt); 783 784 /* set the functions for precheck and postcheck */ 785 786 PETSC_EXTERN PetscErrorCode SNESLineSearchSetPreCheck(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, Vec, Vec, PetscBool *, void *), void *ctx); 787 PETSC_EXTERN PetscErrorCode SNESLineSearchSetPostCheck(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void *ctx); 788 789 PETSC_EXTERN PetscErrorCode SNESLineSearchGetPreCheck(SNESLineSearch, PetscErrorCode (**)(SNESLineSearch, Vec, Vec, PetscBool *, void *), void **ctx); 790 PETSC_EXTERN PetscErrorCode SNESLineSearchGetPostCheck(SNESLineSearch, PetscErrorCode (**)(SNESLineSearch, Vec, Vec, Vec, PetscBool *, PetscBool *, void *), void **ctx); 791 792 /* set the functions for VI-specific line search operations */ 793 794 PETSC_EXTERN PetscErrorCode SNESLineSearchSetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFn *, SNESLineSearchVINormFn *); 795 PETSC_EXTERN PetscErrorCode SNESLineSearchGetVIFunctions(SNESLineSearch, SNESLineSearchVIProjectFn **, SNESLineSearchVINormFn **); 796 797 /* pointers to the associated SNES in order to be able to get the function evaluation out */ 798 PETSC_EXTERN PetscErrorCode SNESLineSearchSetSNES(SNESLineSearch, SNES); 799 PETSC_EXTERN PetscErrorCode SNESLineSearchGetSNES(SNESLineSearch, SNES *); 800 801 /* set and get the parameters and vectors */ 802 PETSC_EXTERN PetscErrorCode SNESLineSearchGetTolerances(SNESLineSearch, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscReal *, PetscInt *); 803 PETSC_EXTERN PetscErrorCode SNESLineSearchSetTolerances(SNESLineSearch, PetscReal, PetscReal, PetscReal, PetscReal, PetscReal, PetscInt); 804 805 PETSC_EXTERN PetscErrorCode SNESLineSearchPreCheckPicard(SNESLineSearch, Vec, Vec, PetscBool *, void *); 806 807 PETSC_EXTERN PetscErrorCode SNESLineSearchGetLambda(SNESLineSearch, PetscReal *); 808 PETSC_EXTERN PetscErrorCode SNESLineSearchSetLambda(SNESLineSearch, PetscReal); 809 810 PETSC_EXTERN PetscErrorCode SNESLineSearchGetDamping(SNESLineSearch, PetscReal *); 811 PETSC_EXTERN PetscErrorCode SNESLineSearchSetDamping(SNESLineSearch, PetscReal); 812 813 PETSC_EXTERN PetscErrorCode SNESLineSearchGetOrder(SNESLineSearch, PetscInt *order); 814 PETSC_EXTERN PetscErrorCode SNESLineSearchSetOrder(SNESLineSearch, PetscInt order); 815 816 /*E 817 SNESLineSearchReason - indication if the line search has succeeded or failed and why 818 819 Values: 820 + `SNES_LINESEARCH_SUCCEEDED` - the line search succeeded 821 . `SNES_LINESEARCH_FAILED_NANORINF` - a not a number of infinity appeared in the computions 822 . `SNES_LINESEARCH_FAILED_DOMAIN` - the function was evaluated outside of its domain, see `SNESSetFunctionDomainError()` and `SNESSetJacobianDomainError()` 823 . `SNES_LINESEARCH_FAILED_REDUCT` - the linear search failed to get the requested decrease in its norm or objective 824 . `SNES_LINESEARCH_FAILED_USER` - used by `SNESLINESEARCHNLEQERR` to indicate the user changed the search direction inappropriately 825 - `SNES_LINESEARCH_FAILED_FUNCTION` - indicates the maximum number of function evaluations allowed has been surpassed, `SNESConvergedReason` is also 826 set to `SNES_DIVERGED_FUNCTION_COUNT` 827 828 Level: intermediate 829 830 Developer Note: 831 Some of these reasons overlap with values of `SNESConvergedReason` 832 833 .seealso: [](ch_snes), `SNES`, `SNESSolve()`, `SNESGetConvergedReason()`, `KSPConvergedReason`, `SNESSetConvergenceTest()`, 834 `SNESSetFunctionDomainError()` and `SNESSetJacobianDomainError()` 835 E*/ 836 typedef enum { 837 SNES_LINESEARCH_SUCCEEDED, 838 SNES_LINESEARCH_FAILED_NANORINF, 839 SNES_LINESEARCH_FAILED_DOMAIN, 840 SNES_LINESEARCH_FAILED_REDUCT, /* INSUFFICIENT REDUCTION */ 841 SNES_LINESEARCH_FAILED_USER, 842 SNES_LINESEARCH_FAILED_FUNCTION 843 } SNESLineSearchReason; 844 845 PETSC_EXTERN PetscErrorCode SNESLineSearchGetReason(SNESLineSearch, SNESLineSearchReason *); 846 PETSC_EXTERN PetscErrorCode SNESLineSearchSetReason(SNESLineSearch, SNESLineSearchReason); 847 848 PETSC_EXTERN PetscErrorCode SNESLineSearchGetVecs(SNESLineSearch, Vec *, Vec *, Vec *, Vec *, Vec *); 849 PETSC_EXTERN PetscErrorCode SNESLineSearchSetVecs(SNESLineSearch, Vec, Vec, Vec, Vec, Vec); 850 851 PETSC_EXTERN PetscErrorCode SNESLineSearchGetNorms(SNESLineSearch, PetscReal *, PetscReal *, PetscReal *); 852 PETSC_EXTERN PetscErrorCode SNESLineSearchSetNorms(SNESLineSearch, PetscReal, PetscReal, PetscReal); 853 PETSC_EXTERN PetscErrorCode SNESLineSearchComputeNorms(SNESLineSearch); 854 PETSC_EXTERN PetscErrorCode SNESLineSearchSetComputeNorms(SNESLineSearch, PetscBool); 855 856 PETSC_EXTERN PetscErrorCode SNESLineSearchMonitor(SNESLineSearch); 857 PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSet(SNESLineSearch, PetscErrorCode (*)(SNESLineSearch, void *), void *, PetscErrorCode (*)(void **)); 858 PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSetFromOptions(SNESLineSearch, const char[], const char[], const char[], PetscErrorCode (*)(SNESLineSearch, PetscViewerAndFormat *), PetscErrorCode (*)(SNESLineSearch, PetscViewerAndFormat *)); 859 PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorCancel(SNESLineSearch); 860 PETSC_EXTERN PetscErrorCode SNESLineSearchSetDefaultMonitor(SNESLineSearch, PetscViewer); 861 PETSC_EXTERN PetscErrorCode SNESLineSearchGetDefaultMonitor(SNESLineSearch, PetscViewer *); 862 PETSC_EXTERN PetscErrorCode SNESLineSearchMonitorSolutionUpdate(SNESLineSearch, PetscViewerAndFormat *); 863 864 PETSC_EXTERN PetscErrorCode SNESLineSearchAppendOptionsPrefix(SNESLineSearch, const char prefix[]); 865 PETSC_EXTERN PetscErrorCode SNESLineSearchGetOptionsPrefix(SNESLineSearch, const char *prefix[]); 866 867 /* Shell interface functions */ 868 PETSC_EXTERN PetscErrorCode SNESLineSearchShellSetApply(SNESLineSearch, SNESLineSearchShellApplyFn, void *); 869 PETSC_EXTERN PetscErrorCode SNESLineSearchShellGetApply(SNESLineSearch, SNESLineSearchShellApplyFn **, void **); 870 871 PETSC_DEPRECATED_FUNCTION(3, 21, 0, "SNESLinesearchShellSetApply()", ) static inline PetscErrorCode SNESLineSearchShellSetUserFunc(SNESLineSearch ls, SNESLineSearchUserFunc f, void *ctx) 872 { 873 return SNESLineSearchShellSetApply(ls, f, ctx); 874 } 875 876 PETSC_DEPRECATED_FUNCTION(3, 21, 0, "SNESLinesearchShellGetApply()", ) static inline PetscErrorCode SNESLineSearchShellGetUserFunc(SNESLineSearch ls, SNESLineSearchUserFunc *f, void **ctx) 877 { 878 return SNESLineSearchShellGetApply(ls, f, ctx); 879 } 880 881 /* BT interface functions */ 882 PETSC_EXTERN PetscErrorCode SNESLineSearchBTSetAlpha(SNESLineSearch, PetscReal); 883 PETSC_EXTERN PetscErrorCode SNESLineSearchBTGetAlpha(SNESLineSearch, PetscReal *); 884 885 /*register line search types */ 886 PETSC_EXTERN PetscErrorCode SNESLineSearchRegister(const char[], PetscErrorCode (*)(SNESLineSearch)); 887 888 /* Routines for VI solver */ 889 PETSC_EXTERN PetscErrorCode SNESVISetVariableBounds(SNES, Vec, Vec); 890 PETSC_EXTERN PetscErrorCode SNESVIGetVariableBounds(SNES, Vec *, Vec *); 891 PETSC_EXTERN PetscErrorCode SNESVISetComputeVariableBounds(SNES, PetscErrorCode (*)(SNES, Vec, Vec)); 892 PETSC_EXTERN PetscErrorCode SNESVIGetInactiveSet(SNES, IS *); 893 PETSC_EXTERN PetscErrorCode SNESVIGetActiveSetIS(SNES, Vec, Vec, IS *); 894 PETSC_EXTERN PetscErrorCode SNESVIComputeInactiveSetFnorm(SNES, Vec, Vec, PetscReal *); 895 PETSC_EXTERN PetscErrorCode SNESVISetRedundancyCheck(SNES, PetscErrorCode (*)(SNES, IS, IS *, void *), void *); 896 PETSC_EXTERN PetscErrorCode SNESVIComputeMeritFunction(Vec, PetscReal *, PetscReal *); 897 PETSC_EXTERN PetscErrorCode SNESVIComputeFunction(SNES, Vec, Vec, void *); 898 PETSC_EXTERN PetscErrorCode DMSetVI(DM, IS); 899 PETSC_EXTERN PetscErrorCode DMDestroyVI(DM); 900 901 PETSC_EXTERN PetscErrorCode SNESTestLocalMin(SNES); 902 903 /* Should this routine be private? */ 904 PETSC_EXTERN PetscErrorCode SNESComputeJacobian(SNES, Vec, Mat, Mat); 905 PETSC_EXTERN PetscErrorCode SNESTestJacobian(SNES); 906 PETSC_EXTERN PetscErrorCode SNESTestFunction(SNES); 907 908 PETSC_EXTERN PetscErrorCode SNESSetDM(SNES, DM); 909 PETSC_EXTERN PetscErrorCode SNESGetDM(SNES, DM *); 910 PETSC_EXTERN PetscErrorCode SNESSetNPC(SNES, SNES); 911 PETSC_EXTERN PetscErrorCode SNESGetNPC(SNES, SNES *); 912 PETSC_EXTERN PetscErrorCode SNESHasNPC(SNES, PetscBool *); 913 PETSC_EXTERN PetscErrorCode SNESApplyNPC(SNES, Vec, Vec, Vec); 914 PETSC_EXTERN PetscErrorCode SNESGetNPCFunction(SNES, Vec, PetscReal *); 915 PETSC_EXTERN PetscErrorCode SNESComputeFunctionDefaultNPC(SNES, Vec, Vec); 916 PETSC_EXTERN PetscErrorCode SNESSetNPCSide(SNES, PCSide); 917 PETSC_EXTERN PetscErrorCode SNESGetNPCSide(SNES, PCSide *); 918 PETSC_EXTERN PetscErrorCode SNESSetLineSearch(SNES, SNESLineSearch); 919 PETSC_EXTERN PetscErrorCode SNESGetLineSearch(SNES, SNESLineSearch *); 920 921 PETSC_DEPRECATED_FUNCTION(3, 4, 0, "SNESGetLineSearch()", ) static inline PetscErrorCode SNESGetSNESLineSearch(SNES snes, SNESLineSearch *ls) 922 { 923 return SNESGetLineSearch(snes, ls); 924 } 925 PETSC_DEPRECATED_FUNCTION(3, 4, 0, "SNESSetLineSearch()", ) static inline PetscErrorCode SNESSetSNESLineSearch(SNES snes, SNESLineSearch ls) 926 { 927 return SNESSetLineSearch(snes, ls); 928 } 929 930 PETSC_EXTERN PetscErrorCode SNESSetUpMatrices(SNES); 931 PETSC_EXTERN PetscErrorCode DMSNESSetFunction(DM, SNESFunctionFn *, void *); 932 PETSC_EXTERN PetscErrorCode DMSNESGetFunction(DM, SNESFunctionFn **, void **); 933 PETSC_EXTERN PetscErrorCode DMSNESSetFunctionContextDestroy(DM, PetscErrorCode (*)(void *)); 934 PETSC_EXTERN PetscErrorCode DMSNESSetMFFunction(DM, SNESFunctionFn *, void *); 935 PETSC_EXTERN PetscErrorCode DMSNESSetNGS(DM, SNESNGSFn *, void *); 936 PETSC_EXTERN PetscErrorCode DMSNESGetNGS(DM, SNESNGSFn **, void **); 937 PETSC_EXTERN PetscErrorCode DMSNESSetJacobian(DM, SNESJacobianFn *, void *); 938 PETSC_EXTERN PetscErrorCode DMSNESGetJacobian(DM, SNESJacobianFn **, void **); 939 PETSC_EXTERN PetscErrorCode DMSNESSetJacobianContextDestroy(DM, PetscErrorCode (*)(void *)); 940 PETSC_EXTERN PetscErrorCode DMSNESSetPicard(DM, SNESFunctionFn *, SNESJacobianFn *, void *); 941 PETSC_EXTERN PetscErrorCode DMSNESGetPicard(DM, SNESFunctionFn **, SNESJacobianFn **, void **); 942 PETSC_EXTERN PetscErrorCode DMSNESSetObjective(DM, SNESObjectiveFn *, void *); 943 PETSC_EXTERN PetscErrorCode DMSNESGetObjective(DM, SNESObjectiveFn **, void **); 944 PETSC_EXTERN PetscErrorCode DMCopyDMSNES(DM, DM); 945 946 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(DMDASNESFunctionFn)(DMDALocalInfo *, void *, void *, void *); 947 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(DMDASNESJacobianFn)(DMDALocalInfo *, void *, Mat, Mat, void *); 948 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(DMDASNESObjectiveFn)(DMDALocalInfo *, void *, PetscReal *, void *); 949 950 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(DMDASNESFunctionVecFn)(DMDALocalInfo *, Vec, Vec, void *); 951 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(DMDASNESJacobianVecFn)(DMDALocalInfo *, Vec, Mat, Mat, void *); 952 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode(DMDASNESObjectiveVecFn)(DMDALocalInfo *, Vec, PetscReal *, void *); 953 954 PETSC_EXTERN PetscErrorCode DMDASNESSetFunctionLocal(DM, InsertMode, DMDASNESFunctionFn *, void *); 955 PETSC_EXTERN PetscErrorCode DMDASNESSetJacobianLocal(DM, DMDASNESJacobianFn *, void *); 956 PETSC_EXTERN PetscErrorCode DMDASNESSetObjectiveLocal(DM, DMDASNESObjectiveFn *, void *); 957 PETSC_EXTERN PetscErrorCode DMDASNESSetPicardLocal(DM, InsertMode, DMDASNESFunctionFn *, DMDASNESJacobianFn, void *); 958 959 PETSC_EXTERN PetscErrorCode DMDASNESSetFunctionLocalVec(DM, InsertMode, DMDASNESFunctionVecFn *, void *); 960 PETSC_EXTERN PetscErrorCode DMDASNESSetJacobianLocalVec(DM, DMDASNESJacobianVecFn *, void *); 961 PETSC_EXTERN PetscErrorCode DMDASNESSetObjectiveLocalVec(DM, DMDASNESObjectiveVecFn *, void *); 962 963 PETSC_EXTERN PetscErrorCode DMSNESSetBoundaryLocal(DM, PetscErrorCode (*)(DM, Vec, void *), void *); 964 PETSC_EXTERN PetscErrorCode DMSNESSetObjectiveLocal(DM, PetscErrorCode (*)(DM, Vec, PetscReal *, void *), void *); 965 PETSC_EXTERN PetscErrorCode DMSNESSetFunctionLocal(DM, PetscErrorCode (*)(DM, Vec, Vec, void *), void *); 966 PETSC_EXTERN PetscErrorCode DMSNESSetJacobianLocal(DM, PetscErrorCode (*)(DM, Vec, Mat, Mat, void *), void *); 967 PETSC_EXTERN PetscErrorCode DMSNESGetBoundaryLocal(DM, PetscErrorCode (**)(DM, Vec, void *), void **); 968 PETSC_EXTERN PetscErrorCode DMSNESGetObjectiveLocal(DM, PetscErrorCode (**)(DM, Vec, PetscReal *, void *), void **); 969 PETSC_EXTERN PetscErrorCode DMSNESGetFunctionLocal(DM, PetscErrorCode (**)(DM, Vec, Vec, void *), void **); 970 PETSC_EXTERN PetscErrorCode DMSNESGetJacobianLocal(DM, PetscErrorCode (**)(DM, Vec, Mat, Mat, void *), void **); 971 972 /* Routines for Multiblock solver */ 973 PETSC_EXTERN PetscErrorCode SNESMultiblockSetFields(SNES, const char[], PetscInt, const PetscInt *); 974 PETSC_EXTERN PetscErrorCode SNESMultiblockSetIS(SNES, const char[], IS); 975 PETSC_EXTERN PetscErrorCode SNESMultiblockSetBlockSize(SNES, PetscInt); 976 PETSC_EXTERN PetscErrorCode SNESMultiblockSetType(SNES, PCCompositeType); 977 PETSC_EXTERN PetscErrorCode SNESMultiblockGetSubSNES(SNES, PetscInt *, SNES *[]); 978 979 /*J 980 SNESMSType - String with the name of a PETSc `SNESMS` method. 981 982 Level: intermediate 983 984 .seealso: [](ch_snes), `SNESMS`, `SNESMSGetType()`, `SNESMSSetType()`, `SNES` 985 J*/ 986 typedef const char *SNESMSType; 987 #define SNESMSM62 "m62" 988 #define SNESMSEULER "euler" 989 #define SNESMSJAMESON83 "jameson83" 990 #define SNESMSVLTP11 "vltp11" 991 #define SNESMSVLTP21 "vltp21" 992 #define SNESMSVLTP31 "vltp31" 993 #define SNESMSVLTP41 "vltp41" 994 #define SNESMSVLTP51 "vltp51" 995 #define SNESMSVLTP61 "vltp61" 996 997 PETSC_EXTERN PetscErrorCode SNESMSRegister(SNESMSType, PetscInt, PetscInt, PetscReal, const PetscReal[], const PetscReal[], const PetscReal[]); 998 PETSC_EXTERN PetscErrorCode SNESMSRegisterAll(void); 999 PETSC_EXTERN PetscErrorCode SNESMSGetType(SNES, SNESMSType *); 1000 PETSC_EXTERN PetscErrorCode SNESMSSetType(SNES, SNESMSType); 1001 PETSC_EXTERN PetscErrorCode SNESMSGetDamping(SNES, PetscReal *); 1002 PETSC_EXTERN PetscErrorCode SNESMSSetDamping(SNES, PetscReal); 1003 PETSC_EXTERN PetscErrorCode SNESMSFinalizePackage(void); 1004 PETSC_EXTERN PetscErrorCode SNESMSInitializePackage(void); 1005 PETSC_EXTERN PetscErrorCode SNESMSRegisterDestroy(void); 1006 1007 /*MC 1008 SNESNGMRESRestartType - the restart approach used by `SNESNGMRES` 1009 1010 Values: 1011 + `SNES_NGMRES_RESTART_NONE` - never restart 1012 . `SNES_NGMRES_RESTART_DIFFERENCE` - restart based upon difference criteria 1013 - `SNES_NGMRES_RESTART_PERIODIC` - restart after a fixed number of iterations 1014 1015 Options Database Keys: 1016 + -snes_ngmres_restart_type <difference,periodic,none> - set the restart type 1017 - -snes_ngmres_restart <30> - sets the number of iterations before restart for periodic 1018 1019 Level: intermediate 1020 1021 .seealso: `SNES, `SNESNGMRES`, `SNESNGMRESSetSelectType()`, `SNESNGMRESGetSelectType()`, `SNESNGMRESSetRestartType()`, 1022 `SNESNGMRESGetRestartType()`, `SNESNGMRESSelectType` 1023 M*/ 1024 typedef enum { 1025 SNES_NGMRES_RESTART_NONE = 0, 1026 SNES_NGMRES_RESTART_PERIODIC = 1, 1027 SNES_NGMRES_RESTART_DIFFERENCE = 2 1028 } SNESNGMRESRestartType; 1029 PETSC_EXTERN const char *const SNESNGMRESRestartTypes[]; 1030 1031 /*MC 1032 SNESNGMRESSelectType - the approach used by `SNESNGMRES` to determine how the candidate solution and 1033 combined solution are used to create the next iterate. 1034 1035 Values: 1036 + `SNES_NGMRES_SELECT_NONE` - choose the combined solution all the time 1037 . `SNES_NGMRES_SELECT_DIFFERENCE` - choose based upon the selection criteria 1038 - `SNES_NGMRES_SELECT_LINESEARCH` - choose based upon line search combination 1039 1040 Options Database Key: 1041 . -snes_ngmres_select_type<difference,none,linesearch> - select type 1042 1043 Level: intermediate 1044 1045 .seealso: `SNES, `SNESNGMRES`, `SNESNGMRESSetSelectType()`, `SNESNGMRESGetSelectType()`, `SNESNGMRESSetRestartType()`, 1046 `SNESNGMRESGetRestartType()`, `SNESNGMRESRestartType` 1047 M*/ 1048 typedef enum { 1049 SNES_NGMRES_SELECT_NONE = 0, 1050 SNES_NGMRES_SELECT_DIFFERENCE = 1, 1051 SNES_NGMRES_SELECT_LINESEARCH = 2 1052 } SNESNGMRESSelectType; 1053 PETSC_EXTERN const char *const SNESNGMRESSelectTypes[]; 1054 1055 PETSC_EXTERN PetscErrorCode SNESNGMRESSetRestartType(SNES, SNESNGMRESRestartType); 1056 PETSC_EXTERN PetscErrorCode SNESNGMRESSetSelectType(SNES, SNESNGMRESSelectType); 1057 PETSC_EXTERN PetscErrorCode SNESNGMRESSetRestartFmRise(SNES, PetscBool); 1058 PETSC_EXTERN PetscErrorCode SNESNGMRESGetRestartFmRise(SNES, PetscBool *); 1059 1060 /*MC 1061 SNESNCGType - the conjugate update approach for `SNESNCG` 1062 1063 Values: 1064 + `SNES_NCG_FR` - Fletcher-Reeves update 1065 . `SNES_NCG_PRP` - Polak-Ribiere-Polyak update, the default and the only one that tolerates generalized search directions 1066 . `SNES_NCG_HS` - Hestenes-Steifel update 1067 . `SNES_NCG_DY` - Dai-Yuan update 1068 - `SNES_NCG_CD` - Conjugate Descent update 1069 1070 Options Database Key: 1071 . -snes_ncg_type<fr,prp,hs,dy,cd> - select type 1072 1073 Level: intermediate 1074 1075 .seealso: `SNES, `SNESNCG`, `SNESNCGSetType()` 1076 M*/ 1077 typedef enum { 1078 SNES_NCG_FR = 0, 1079 SNES_NCG_PRP = 1, 1080 SNES_NCG_HS = 2, 1081 SNES_NCG_DY = 3, 1082 SNES_NCG_CD = 4 1083 } SNESNCGType; 1084 PETSC_EXTERN const char *const SNESNCGTypes[]; 1085 1086 PETSC_EXTERN PetscErrorCode SNESNCGSetType(SNES, SNESNCGType); 1087 1088 /*MC 1089 SNESQNScaleType - the scaling type used by `SNESQN` 1090 1091 Values: 1092 + `SNES_QN_SCALE_NONE` - don't scale the problem 1093 . `SNES_QN_SCALE_SCALAR` - use Shanno scaling 1094 . `SNES_QN_SCALE_DIAGONAL` - scale with a diagonalized BFGS formula (see Gilbert and Lemarechal 1989), available 1095 - `SNES_QN_SCALE_JACOBIAN` - scale by solving a linear system coming from the Jacobian you provided with `SNESSetJacobian()` 1096 computed at the first iteration of `SNESQN` and at ever restart. 1097 1098 Options Database Key: 1099 . -snes_qn_scale_type <diagonal,none,scalar,jacobian> - Scaling type 1100 1101 Level: intermediate 1102 1103 .seealso: `SNES, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNType`, `SNESQNSetType()`, `SNESQNSetRestartType()`, `SNESQNRestartType` 1104 M*/ 1105 typedef enum { 1106 SNES_QN_SCALE_DEFAULT = 0, 1107 SNES_QN_SCALE_NONE = 1, 1108 SNES_QN_SCALE_SCALAR = 2, 1109 SNES_QN_SCALE_DIAGONAL = 3, 1110 SNES_QN_SCALE_JACOBIAN = 4 1111 } SNESQNScaleType; 1112 PETSC_EXTERN const char *const SNESQNScaleTypes[]; 1113 1114 /*MC 1115 SNESQNRestartType - the restart approached used by `SNESQN` 1116 1117 Values: 1118 + `SNES_QN_RESTART_NONE` - never restart 1119 . `SNES_QN_RESTART_POWELL` - restart based upon descent criteria 1120 - `SNES_QN_RESTART_PERIODIC` - restart after a fixed number of iterations 1121 1122 Options Database Keys: 1123 + -snes_qn_restart_type <powell,periodic,none> - set the restart type 1124 - -snes_qn_m <m> - sets the number of stored updates and the restart period for periodic 1125 1126 Level: intermediate 1127 1128 .seealso: `SNES, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNType`, `SNESQNSetType()`, `SNESQNSetRestartType()`, `SNESQNScaleType` 1129 M*/ 1130 typedef enum { 1131 SNES_QN_RESTART_DEFAULT = 0, 1132 SNES_QN_RESTART_NONE = 1, 1133 SNES_QN_RESTART_POWELL = 2, 1134 SNES_QN_RESTART_PERIODIC = 3 1135 } SNESQNRestartType; 1136 PETSC_EXTERN const char *const SNESQNRestartTypes[]; 1137 1138 /*MC 1139 SNESQNType - the type used by `SNESQN` 1140 1141 Values: 1142 + `SNES_QN_LBFGS` - LBFGS variant 1143 . `SNES_QN_BROYDEN` - Broyden variant 1144 - `SNES_QN_BADBROYDEN` - Bad Broyden variant 1145 1146 Options Database Key: 1147 . -snes_qn_type <lbfgs,broyden,badbroyden> - quasi-Newton type 1148 1149 Level: intermediate 1150 1151 .seealso: `SNES, `SNESQN`, `SNESQNSetScaleType()`, `SNESQNSetType()`, `SNESQNScaleType`, `SNESQNRestartType`, `SNESQNSetRestartType()` 1152 M*/ 1153 typedef enum { 1154 SNES_QN_LBFGS = 0, 1155 SNES_QN_BROYDEN = 1, 1156 SNES_QN_BADBROYDEN = 2 1157 } SNESQNType; 1158 PETSC_EXTERN const char *const SNESQNTypes[]; 1159 1160 PETSC_EXTERN PetscErrorCode SNESQNSetType(SNES, SNESQNType); 1161 PETSC_EXTERN PetscErrorCode SNESQNSetScaleType(SNES, SNESQNScaleType); 1162 PETSC_EXTERN PetscErrorCode SNESQNSetRestartType(SNES, SNESQNRestartType); 1163 1164 PETSC_EXTERN PetscErrorCode SNESNASMGetType(SNES, PCASMType *); 1165 PETSC_EXTERN PetscErrorCode SNESNASMSetType(SNES, PCASMType); 1166 PETSC_EXTERN PetscErrorCode SNESNASMGetSubdomains(SNES, PetscInt *, SNES **, VecScatter **, VecScatter **, VecScatter **); 1167 PETSC_EXTERN PetscErrorCode SNESNASMSetSubdomains(SNES, PetscInt, SNES *, VecScatter *, VecScatter *, VecScatter *); 1168 PETSC_EXTERN PetscErrorCode SNESNASMSetDamping(SNES, PetscReal); 1169 PETSC_EXTERN PetscErrorCode SNESNASMGetDamping(SNES, PetscReal *); 1170 PETSC_EXTERN PetscErrorCode SNESNASMGetSubdomainVecs(SNES, PetscInt *, Vec **, Vec **, Vec **, Vec **); 1171 PETSC_EXTERN PetscErrorCode SNESNASMSetComputeFinalJacobian(SNES, PetscBool); 1172 PETSC_EXTERN PetscErrorCode SNESNASMGetSNES(SNES, PetscInt, SNES *); 1173 PETSC_EXTERN PetscErrorCode SNESNASMGetNumber(SNES, PetscInt *); 1174 PETSC_EXTERN PetscErrorCode SNESNASMSetWeight(SNES, Vec); 1175 1176 /*E 1177 SNESCompositeType - Determines how two or more preconditioners are composed with the `SNESType` of `SNESCOMPOSITE` 1178 1179 Values: 1180 + `SNES_COMPOSITE_ADDITIVE` - results from application of all preconditioners are added together 1181 . `SNES_COMPOSITE_MULTIPLICATIVE` - preconditioners are applied sequentially to the residual freshly 1182 computed after the previous preconditioner application 1183 - `SNES_COMPOSITE_ADDITIVEOPTIMAL` - uses a linear combination of the solutions obtained with each preconditioner that approximately minimize the function 1184 value at the new iteration. 1185 1186 Level: beginner 1187 1188 .seealso: [](sec_pc), `PCCOMPOSITE`, `PCFIELDSPLIT`, `PC`, `PCCompositeSetType()`, `PCCompositeType` 1189 E*/ 1190 typedef enum { 1191 SNES_COMPOSITE_ADDITIVE, 1192 SNES_COMPOSITE_MULTIPLICATIVE, 1193 SNES_COMPOSITE_ADDITIVEOPTIMAL 1194 } SNESCompositeType; 1195 PETSC_EXTERN const char *const SNESCompositeTypes[]; 1196 1197 PETSC_EXTERN PetscErrorCode SNESCompositeSetType(SNES, SNESCompositeType); 1198 PETSC_EXTERN PetscErrorCode SNESCompositeAddSNES(SNES, SNESType); 1199 PETSC_EXTERN PetscErrorCode SNESCompositeGetSNES(SNES, PetscInt, SNES *); 1200 PETSC_EXTERN PetscErrorCode SNESCompositeGetNumber(SNES, PetscInt *); 1201 PETSC_EXTERN PetscErrorCode SNESCompositeSetDamping(SNES, PetscInt, PetscReal); 1202 1203 PETSC_EXTERN PetscErrorCode SNESPatchSetDiscretisationInfo(SNES, PetscInt, DM *, PetscInt *, PetscInt *, const PetscInt **, const PetscInt *, PetscInt, const PetscInt *, PetscInt, const PetscInt *); 1204 PETSC_EXTERN PetscErrorCode SNESPatchSetComputeOperator(SNES, PetscErrorCode (*func)(PC, PetscInt, Vec, Mat, IS, PetscInt, const PetscInt *, const PetscInt *, void *), void *); 1205 PETSC_EXTERN PetscErrorCode SNESPatchSetComputeFunction(SNES, PetscErrorCode (*func)(PC, PetscInt, Vec, Vec, IS, PetscInt, const PetscInt *, const PetscInt *, void *), void *); 1206 PETSC_EXTERN PetscErrorCode SNESPatchSetConstructType(SNES, PCPatchConstructType, PetscErrorCode (*func)(PC, PetscInt *, IS **, IS *, void *), void *); 1207 PETSC_EXTERN PetscErrorCode SNESPatchSetCellNumbering(SNES, PetscSection); 1208 1209 /*E 1210 SNESFASType - Determines the type of nonlinear multigrid method that is run. 1211 1212 Values: 1213 + `SNES_FAS_MULTIPLICATIVE` (default) - traditional V or W cycle as determined by `SNESFASSetCycles()` 1214 . `SNES_FAS_ADDITIVE` - additive FAS cycle 1215 . `SNES_FAS_FULL` - full FAS cycle 1216 - `SNES_FAS_KASKADE` - Kaskade FAS cycle 1217 1218 Level: beginner 1219 1220 .seealso: [](ch_snes), `SNESFAS`, `PCMGSetType()`, `PCMGType` 1221 E*/ 1222 typedef enum { 1223 SNES_FAS_MULTIPLICATIVE, 1224 SNES_FAS_ADDITIVE, 1225 SNES_FAS_FULL, 1226 SNES_FAS_KASKADE 1227 } SNESFASType; 1228 PETSC_EXTERN const char *const SNESFASTypes[]; 1229 1230 /* called on the finest level FAS instance*/ 1231 PETSC_EXTERN PetscErrorCode SNESFASSetType(SNES, SNESFASType); 1232 PETSC_EXTERN PetscErrorCode SNESFASGetType(SNES, SNESFASType *); 1233 PETSC_EXTERN PetscErrorCode SNESFASSetLevels(SNES, PetscInt, MPI_Comm *); 1234 PETSC_EXTERN PetscErrorCode SNESFASGetLevels(SNES, PetscInt *); 1235 PETSC_EXTERN PetscErrorCode SNESFASGetCycleSNES(SNES, PetscInt, SNES *); 1236 PETSC_EXTERN PetscErrorCode SNESFASSetNumberSmoothUp(SNES, PetscInt); 1237 PETSC_EXTERN PetscErrorCode SNESFASSetNumberSmoothDown(SNES, PetscInt); 1238 PETSC_EXTERN PetscErrorCode SNESFASSetCycles(SNES, PetscInt); 1239 PETSC_EXTERN PetscErrorCode SNESFASSetMonitor(SNES, PetscViewerAndFormat *, PetscBool); 1240 PETSC_EXTERN PetscErrorCode SNESFASSetLog(SNES, PetscBool); 1241 1242 PETSC_EXTERN PetscErrorCode SNESFASSetGalerkin(SNES, PetscBool); 1243 PETSC_EXTERN PetscErrorCode SNESFASGetGalerkin(SNES, PetscBool *); 1244 PETSC_EXTERN PetscErrorCode SNESFASGalerkinFunctionDefault(SNES, Vec, Vec, void *); 1245 1246 /* called on any level -- "Cycle" FAS instance */ 1247 PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmoother(SNES, SNES *); 1248 PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmootherUp(SNES, SNES *); 1249 PETSC_EXTERN PetscErrorCode SNESFASCycleGetSmootherDown(SNES, SNES *); 1250 PETSC_EXTERN PetscErrorCode SNESFASCycleGetCorrection(SNES, SNES *); 1251 PETSC_EXTERN PetscErrorCode SNESFASCycleGetInterpolation(SNES, Mat *); 1252 PETSC_EXTERN PetscErrorCode SNESFASCycleGetRestriction(SNES, Mat *); 1253 PETSC_EXTERN PetscErrorCode SNESFASCycleGetInjection(SNES, Mat *); 1254 PETSC_EXTERN PetscErrorCode SNESFASCycleGetRScale(SNES, Vec *); 1255 PETSC_EXTERN PetscErrorCode SNESFASCycleSetCycles(SNES, PetscInt); 1256 PETSC_EXTERN PetscErrorCode SNESFASCycleIsFine(SNES, PetscBool *); 1257 1258 /* called on the (outer) finest level FAS to set/get parameters on any level instance */ 1259 PETSC_EXTERN PetscErrorCode SNESFASSetInterpolation(SNES, PetscInt, Mat); 1260 PETSC_EXTERN PetscErrorCode SNESFASGetInterpolation(SNES, PetscInt, Mat *); 1261 PETSC_EXTERN PetscErrorCode SNESFASSetRestriction(SNES, PetscInt, Mat); 1262 PETSC_EXTERN PetscErrorCode SNESFASGetRestriction(SNES, PetscInt, Mat *); 1263 PETSC_EXTERN PetscErrorCode SNESFASSetInjection(SNES, PetscInt, Mat); 1264 PETSC_EXTERN PetscErrorCode SNESFASGetInjection(SNES, PetscInt, Mat *); 1265 PETSC_EXTERN PetscErrorCode SNESFASSetRScale(SNES, PetscInt, Vec); 1266 PETSC_EXTERN PetscErrorCode SNESFASGetRScale(SNES, PetscInt, Vec *); 1267 PETSC_EXTERN PetscErrorCode SNESFASSetContinuation(SNES, PetscBool); 1268 1269 PETSC_EXTERN PetscErrorCode SNESFASGetSmoother(SNES, PetscInt, SNES *); 1270 PETSC_EXTERN PetscErrorCode SNESFASGetSmootherUp(SNES, PetscInt, SNES *); 1271 PETSC_EXTERN PetscErrorCode SNESFASGetSmootherDown(SNES, PetscInt, SNES *); 1272 PETSC_EXTERN PetscErrorCode SNESFASGetCoarseSolve(SNES, SNES *); 1273 1274 /* parameters for full FAS */ 1275 PETSC_EXTERN PetscErrorCode SNESFASFullSetDownSweep(SNES, PetscBool); 1276 PETSC_EXTERN PetscErrorCode SNESFASCreateCoarseVec(SNES, Vec *); 1277 PETSC_EXTERN PetscErrorCode SNESFASRestrict(SNES, Vec, Vec); 1278 PETSC_EXTERN PetscErrorCode SNESFASFullSetTotal(SNES, PetscBool); 1279 PETSC_EXTERN PetscErrorCode SNESFASFullGetTotal(SNES, PetscBool *); 1280 1281 PETSC_EXTERN PetscErrorCode DMSNESCheckDiscretization(SNES, DM, PetscReal, Vec, PetscReal, PetscReal[]); 1282 PETSC_EXTERN PetscErrorCode DMSNESCheckResidual(SNES, DM, Vec, PetscReal, PetscReal *); 1283 PETSC_EXTERN PetscErrorCode DMSNESCheckJacobian(SNES, DM, Vec, PetscReal, PetscBool *, PetscReal *); 1284 PETSC_EXTERN PetscErrorCode DMSNESCheckFromOptions(SNES, Vec); 1285 PETSC_EXTERN PetscErrorCode DMSNESComputeJacobianAction(DM, Vec, Vec, Vec, void *); 1286 PETSC_EXTERN PetscErrorCode DMSNESCreateJacobianMF(DM, Vec, void *, Mat *); 1287