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 |p_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)


 27: .keywords: SNES, nonlinear, set, line search params

 29: .seealso: SNESLineSearchGetParams(), SNESLineSearchSet()
 30: @*/
 31: PetscErrorCode  SNESLineSearchSetParams(SNES snes,PetscReal alpha,PetscReal maxstep)
 32: {
 33:   SNES_LS *ls;


 38:   ls = (SNES_LS*)snes->data;
 39:   if (alpha   >= 0.0) ls->alpha   = alpha;
 40:   if (maxstep >= 0.0) ls->maxstep = maxstep;
 41:   return(0);
 42: }

 46: /*@C
 47:    SNESLineSearchGetParams - Gets the parameters associated with the line search
 48:      routine in the Newton-based method SNESLS.

 50:    Not collective, but any processor will return the same values

 52:    Input Parameter:
 53: .  snes    - The nonlinear context obtained from SNESCreate()

 55:    Output Parameters:
 56: +  alpha   - The scalar such that .5*f_{n+1} . f_{n+1} <= .5*f_n . f_n - alpha |p_n . J . f_n|
 57: -  maxstep - The maximum norm of the update vector


 60:    Level: intermediate

 62:    Note:
 63:     To not get a certain parameter, pass in PETSC_NULL

 65:    We are finding the zero of f() so the one dimensional minimization problem we are
 66:    solving in the line search is minimize .5*f(x_n + lambda*step_direction) . f(x_n + lambda*step_direction)

 68: .keywords: SNES, nonlinear, set, line search parameters

 70: .seealso: SNESLineSearchSetParams(), SNESLineSearchSet()
 71: @*/
 72: PetscErrorCode  SNESLineSearchGetParams(SNES snes,PetscReal *alpha,PetscReal *maxstep)
 73: {
 74:   SNES_LS *ls;


 79:   ls = (SNES_LS*)snes->data;
 80:   if (alpha) {
 82:     *alpha   = ls->alpha;
 83:   }
 84:   if (maxstep) {
 86:     *maxstep = ls->maxstep;
 87:   }
 88:   return(0);
 89: }