Actual source code: unit.c

  1: #include <petsc/private/taolinesearchimpl.h>

  3: static PetscErrorCode TaoLineSearchView_Unit(TaoLineSearch ls, PetscViewer viewer)
  4: {
  5:   PetscBool isascii;

  7:   PetscFunctionBegin;
  8:   PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii));
  9:   if (isascii) PetscCall(PetscViewerASCIIPrintf(viewer, "  Line Search: Unit Step %g.\n", (double)ls->initstep));
 10:   PetscFunctionReturn(PETSC_SUCCESS);
 11: }

 13: /* Take unit step (newx = startx + initstep*step_direction) */
 14: static PetscErrorCode TaoLineSearchApply_Unit(TaoLineSearch ls, Vec x, PetscReal *f, Vec g, Vec step_direction)
 15: {
 16:   PetscFunctionBegin;
 17:   PetscCall(TaoLineSearchMonitor(ls, 0, *f, 0.0));
 18:   ls->step = ls->initstep;
 19:   PetscCall(VecAXPY(x, ls->step, step_direction));
 20:   PetscCall(TaoLineSearchComputeObjectiveAndGradient(ls, x, f, g));
 21:   PetscCall(TaoLineSearchMonitor(ls, 1, *f, ls->step));
 22:   ls->reason = TAOLINESEARCH_SUCCESS;
 23:   PetscFunctionReturn(PETSC_SUCCESS);
 24: }

 26: /*MC
 27:    TAOLINESEARCHUNIT - Line-search type that disables line search and accepts the unit step length every time

 29:   Options Database Keys:
 30: . -tao_ls_stepinit <step> - steplength

 32:    Level: developer

 34: .seealso: `Tao`, `TaoLineSearch`, `TaoLineSearchCreate()`, `TaoLineSearchSetType()`, `TaoLineSearchApply()`
 35: M*/
 36: PETSC_EXTERN PetscErrorCode TaoLineSearchCreate_Unit(TaoLineSearch ls)
 37: {
 38:   PetscFunctionBegin;
 39:   ls->ops->setup   = NULL;
 40:   ls->ops->reset   = NULL;
 41:   ls->ops->monitor = NULL;
 42:   ls->ops->apply   = TaoLineSearchApply_Unit;
 43:   ls->ops->view    = TaoLineSearchView_Unit;
 44:   PetscFunctionReturn(PETSC_SUCCESS);
 45: }