Actual source code: lsparams.c

  2: #include <../src/snes/impls/ls/lsimpl.h>  /*I "petscsnes.h" I*/

  6: /*@
  7:    SNESLineSearchSetParams - Sets the parameters associated with the line search
  8:    routine in the Newton-based method SNESLS.

 10:    Logically Collective on SNES

 12:    Input Parameters:
 13: +  snes    - The nonlinear context obtained from SNESCreate()
 14: .  alpha   - The scalar such that .5*f_{n+1} . f_{n+1} <= .5*f_n . f_n - alpha |p_n . J . f_n|
 15: .  maxstep - The maximum norm of the update vector
 16: -  minlambda - lambda is not allowed to be smaller than minlambda/( max_i y[i]/x[i]) 

 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,PetscReal minlambda)
 32: {


 40:   PetscTryMethod(snes,"SNESLineSearchSetParams_C",(SNES,PetscReal,PetscReal,PetscReal),(snes,alpha,maxstep,minlambda));
 41:   return(0);
 42: }

 47: PetscErrorCode  SNESLineSearchSetParams_LS(SNES snes,PetscReal alpha,PetscReal maxstep,PetscReal minlambda)
 48: {
 49:   SNES_LS *ls = (SNES_LS*)snes->data;


 57:   if (alpha   >= 0.0) ls->alpha       = alpha;
 58:   if (maxstep >= 0.0) ls->maxstep     = maxstep;
 59:   if (minlambda >= 0.0) ls->minlambda = minlambda;
 60:   return(0);
 61: }

 66: /*@C
 67:    SNESLineSearchGetParams - Gets the parameters associated with the line search
 68:      routine in the Newton-based method SNESLS.

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

 72:    Input Parameter:
 73: .  snes    - The nonlinear context obtained from SNESCreate()

 75:    Output Parameters:
 76: +  alpha   - The scalar such that .5*f_{n+1} . f_{n+1} <= .5*f_n . f_n - alpha |p_n . J . f_n|
 77: .  maxstep - The maximum norm of the update vector
 78: -  minlambda - lambda is not allowed to be smaller than minlambda/( max_i y[i]/x[i]) 

 80:    Level: intermediate

 82:    Note:
 83:     To not get a certain parameter, pass in PETSC_NULL

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

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

 90: .seealso: SNESLineSearchSetParams(), SNESLineSearchSet()
 91: @*/
 92: PetscErrorCode  SNESLineSearchGetParams(SNES snes,PetscReal *alpha,PetscReal *maxstep,PetscReal *minlambda)
 93: {
 94:   SNES_LS *ls = (SNES_LS*)snes->data;

 98:   if (alpha) {
100:     *alpha   = ls->alpha;
101:   }
102:   if (maxstep) {
104:     *maxstep = ls->maxstep;
105:   }
106:   if (minlambda) {
108:     *minlambda = ls->minlambda;
109:   }
110:   return(0);
111: }