Actual source code: unit.c


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

  4: static PetscErrorCode TaoLineSearchDestroy_Unit(TaoLineSearch ls)
  5: {
  6:   return 0;
  7: }

  9: static PetscErrorCode TaoLineSearchSetFromOptions_Unit(TaoLineSearch ls, PetscOptionItems *PetscOptionsObject)
 10: {
 11:   return 0;
 12: }

 14: static PetscErrorCode TaoLineSearchView_Unit(TaoLineSearch ls, PetscViewer viewer)
 15: {
 16:   PetscBool isascii;

 18:   PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii);
 19:   if (isascii) PetscViewerASCIIPrintf(viewer, "  Line Search: Unit Step %g.\n", (double)ls->initstep);
 20:   return 0;
 21: }

 23: /* Take unit step (newx = startx + initstep*step_direction) */
 24: static PetscErrorCode TaoLineSearchApply_Unit(TaoLineSearch ls, Vec x, PetscReal *f, Vec g, Vec step_direction)
 25: {
 26:   TaoLineSearchMonitor(ls, 0, *f, 0.0);
 27:   ls->step = ls->initstep;
 28:   VecAXPY(x, ls->step, step_direction);
 29:   TaoLineSearchComputeObjectiveAndGradient(ls, x, f, g);
 30:   TaoLineSearchMonitor(ls, 1, *f, ls->step);
 31:   ls->reason = TAOLINESEARCH_SUCCESS;
 32:   return 0;
 33: }

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

 38:   Options Database Keys:
 39: . -tao_ls_stepinit <step> - steplength

 41:    Level: developer

 43: .seealso: `TaoLineSearchCreate()`, `TaoLineSearchSetType()`, `TaoLineSearchApply()`

 45: .keywords: Tao, linesearch
 46: M*/
 47: PETSC_EXTERN PetscErrorCode TaoLineSearchCreate_Unit(TaoLineSearch ls)
 48: {
 49:   ls->ops->setup          = NULL;
 50:   ls->ops->reset          = NULL;
 51:   ls->ops->monitor        = NULL;
 52:   ls->ops->apply          = TaoLineSearchApply_Unit;
 53:   ls->ops->view           = TaoLineSearchView_Unit;
 54:   ls->ops->destroy        = TaoLineSearchDestroy_Unit;
 55:   ls->ops->setfromoptions = TaoLineSearchSetFromOptions_Unit;
 56:   return 0;
 57: }