Date: 2022-03-31T04:49:04+00:00

Actual source code: unit.c

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

      4: static PetscErrorCode TaoLineSearchDestroy_Unit(TaoLineSearch ls)
      5: {
      6:   PetscFree(ls->data);
      7:   return 0;
      8: }

     10: static PetscErrorCode TaoLineSearchSetFromOptions_Unit(PetscOptionItems *PetscOptionsObject,TaoLineSearch ls)
     11: {
     12:   PetscOptionsHead(PetscOptionsObject,"No Unit line search options");
     13:   PetscOptionsTail();
     14:   return 0;
     15: }

     17: static PetscErrorCode TaoLineSearchView_Unit(TaoLineSearch ls,PetscViewer viewer)
     18: {
     19:   PetscBool      isascii;

     21:   PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii);
     22:   if (isascii) {
     23:     PetscViewerASCIIPrintf(viewer,"  Line Search: Unit Step.\n");
     24:   }
     25:   return 0;
     26: }

     28: static PetscErrorCode TaoLineSearchApply_Unit(TaoLineSearch ls,Vec x,PetscReal *f,Vec g,Vec step_direction)
     29: {
     30:   PetscReal      ftry;
     31:   PetscReal      startf = *f;

     33:   /* Take unit step (newx = startx + 1.0*step_direction) */
     34:   TaoLineSearchMonitor(ls, 0, *f, 0.0);
     35:   VecAXPY(x,1.0,step_direction);
     36:   TaoLineSearchComputeObjectiveAndGradient(ls,x,&ftry,g);
     37:   TaoLineSearchMonitor(ls, 1, *f, 1.0);
     38:   PetscInfo(ls,"Tao Apply Unit Step: %4.4e\n",1.0);
     39:   if (startf < ftry) {
     40:     PetscInfo(ls,"Tao Apply Unit Step, FINCREASE: F old:= %12.10e, F new: %12.10e\n",(double)startf,(double)ftry);
     41:   }
     42:   *f = ftry;
     43:   ls->step = 1.0;
     44:   ls->reason=TAOLINESEARCH_SUCCESS;
     45:   return 0;
     46: }

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

     51:    Level: developer

     53: .seealso: TaoLineSearchCreate(), TaoLineSearchSetType(), TaoLineSearchApply()

     55: .keywords: Tao, linesearch
     56: M*/
     57: PETSC_EXTERN PetscErrorCode TaoLineSearchCreate_Unit(TaoLineSearch ls)
     58: {
     59:   ls->ops->setup = NULL;
     60:   ls->ops->reset = NULL;
     61:   ls->ops->monitor = NULL;
     62:   ls->ops->apply = TaoLineSearchApply_Unit;
     63:   ls->ops->view = TaoLineSearchView_Unit;
     64:   ls->ops->destroy = TaoLineSearchDestroy_Unit;
     65:   ls->ops->setfromoptions = TaoLineSearchSetFromOptions_Unit;
     66:   return 0;
     67: }