Actual source code: lsparams.c
1: #define PETSCSNES_DLL
3: #include ../src/snes/impls/ls/ls.h
7: /*@
8: SNESLineSearchSetParams - Sets the parameters associated with the line search
9: routine in the Newton-based method SNESLS.
11: Collective on SNES
13: Input Parameters:
14: + snes - The nonlinear context obtained from SNESCreate()
15: . alpha - The scalar such that .5*f_{n+1} . f_{n+1} <= .5*f_n . f_n - alpha |f_n . J . f_n|
16: - maxstep - The maximum norm of the update vector
18: Level: intermediate
20: Note:
21: Pass in PETSC_DEFAULT for any parameter you do not wish to change.
23: We are finding the zero of f() so the one dimensional minimization problem we are
24: solving in the line search is minimize .5*f(x_n + lambda*step_direction) . f(x_n + lambda*step_direction)
26: Contributed by: Mathew Knepley
28: .keywords: SNES, nonlinear, set, line search params
30: .seealso: SNESLineSearchGetParams(), SNESLineSearchSet()
31: @*/
32: PetscErrorCode SNESLineSearchSetParams(SNES snes,PetscReal alpha,PetscReal maxstep)
33: {
34: SNES_LS *ls;
39: ls = (SNES_LS*)snes->data;
40: if (alpha >= 0.0) ls->alpha = alpha;
41: if (maxstep >= 0.0) ls->maxstep = maxstep;
42: return(0);
43: }
47: /*@C
48: SNESLineSearchGetParams - Gets the parameters associated with the line search
49: routine in the Newton-based method SNESLS.
51: Not collective, but any processor will return the same values
53: Input Parameter:
54: . snes - The nonlinear context obtained from SNESCreate()
56: Output Parameters:
57: + alpha - The scalar such that .5*f_{n+1} . f_{n+1} <= .5*f_n . f_n - alpha |f_n . J . f_n|
58: - maxstep - The maximum norm of the update vector
61: Level: intermediate
63: Note:
64: To not get a certain parameter, pass in PETSC_NULL
66: We are finding the zero of f() so the one dimensional minimization problem we are
67: solving in the line search is minimize .5*f(x_n + lambda*step_direction) . f(x_n + lambda*step_direction)
69: Contributed by: Mathew Knepley
71: .keywords: SNES, nonlinear, set, line search parameters
73: .seealso: SNESLineSearchSetParams(), SNESLineSearchSet()
74: @*/
75: PetscErrorCode SNESLineSearchGetParams(SNES snes,PetscReal *alpha,PetscReal *maxstep)
76: {
77: SNES_LS *ls;
82: ls = (SNES_LS*)snes->data;
83: if (alpha) {
85: *alpha = ls->alpha;
86: }
87: if (maxstep) {
89: *maxstep = ls->maxstep;
90: }
91: return(0);
92: }