Actual source code: unit.c


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

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

 12: static PetscErrorCode TaoLineSearchSetFromOptions_Unit(PetscOptionItems *PetscOptionsObject,TaoLineSearch ls)
 13: {
 16:   PetscOptionsHead(PetscOptionsObject,"No Unit line search options");
 17:   PetscOptionsTail();
 18:   return(0);
 19: }

 21: static PetscErrorCode TaoLineSearchView_Unit(TaoLineSearch ls,PetscViewer viewer)
 22: {
 24:   PetscBool      isascii;

 27:   PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii);
 28:   if (isascii) {
 29:     ierr=PetscViewerASCIIPrintf(viewer,"  Line Search: Unit Step.\n");
 30:   }
 31:   return(0);
 32: }

 34: static PetscErrorCode TaoLineSearchApply_Unit(TaoLineSearch ls,Vec x,PetscReal *f,Vec g,Vec step_direction)
 35: {
 37:   PetscReal      ftry;
 38:   PetscReal      startf = *f;

 41:   /* Take unit step (newx = startx + 1.0*step_direction) */
 42:   TaoLineSearchMonitor(ls, 0, *f, 0.0);
 43:   VecAXPY(x,1.0,step_direction);
 44:   TaoLineSearchComputeObjectiveAndGradient(ls,x,&ftry,g);
 45:   TaoLineSearchMonitor(ls, 1, *f, 1.0);
 46:   PetscInfo1(ls,"Tao Apply Unit Step: %4.4e\n",1.0);
 47:   if (startf < ftry){
 48:     PetscInfo2(ls,"Tao Apply Unit Step, FINCREASE: F old:= %12.10e, F new: %12.10e\n",(double)startf,(double)ftry);
 49:   }
 50:   *f = ftry;
 51:   ls->step = 1.0;
 52:   ls->reason=TAOLINESEARCH_SUCCESS;
 53:   return(0);
 54: }

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

 59:    Level: developer

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

 63: .keywords: Tao, linesearch
 64: M*/
 65: PETSC_EXTERN PetscErrorCode TaoLineSearchCreate_Unit(TaoLineSearch ls)
 66: {
 68:   ls->ops->setup = NULL;
 69:   ls->ops->reset = NULL;
 70:   ls->ops->apply = TaoLineSearchApply_Unit;
 71:   ls->ops->view = TaoLineSearchView_Unit;
 72:   ls->ops->destroy = TaoLineSearchDestroy_Unit;
 73:   ls->ops->setfromoptions = TaoLineSearchSetFromOptions_Unit;
 74:   return(0);
 75: }