1 2 #include <petsc/private/taolinesearchimpl.h> 3 4 static PetscErrorCode TaoLineSearchDestroy_Unit(TaoLineSearch ls) { 5 PetscFunctionBegin; 6 PetscFunctionReturn(0); 7 } 8 9 static PetscErrorCode TaoLineSearchSetFromOptions_Unit(TaoLineSearch ls, PetscOptionItems *PetscOptionsObject) { 10 PetscFunctionBegin; 11 PetscFunctionReturn(0); 12 } 13 14 static PetscErrorCode TaoLineSearchView_Unit(TaoLineSearch ls, PetscViewer viewer) { 15 PetscBool isascii; 16 17 PetscFunctionBegin; 18 PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 19 if (isascii) PetscCall(PetscViewerASCIIPrintf(viewer, " Line Search: Unit Step %g.\n", (double)ls->initstep)); 20 PetscFunctionReturn(0); 21 } 22 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 PetscFunctionBegin; 26 PetscCall(TaoLineSearchMonitor(ls, 0, *f, 0.0)); 27 ls->step = ls->initstep; 28 PetscCall(VecAXPY(x, ls->step, step_direction)); 29 PetscCall(TaoLineSearchComputeObjectiveAndGradient(ls, x, f, g)); 30 PetscCall(TaoLineSearchMonitor(ls, 1, *f, ls->step)); 31 ls->reason = TAOLINESEARCH_SUCCESS; 32 PetscFunctionReturn(0); 33 } 34 35 /*MC 36 TAOLINESEARCHUNIT - Line-search type that disables line search and accepts the unit step length every time 37 38 Options Database Keys: 39 . -tao_ls_stepinit <step> - steplength 40 41 Level: developer 42 43 .seealso: `TaoLineSearchCreate()`, `TaoLineSearchSetType()`, `TaoLineSearchApply()` 44 45 .keywords: Tao, linesearch 46 M*/ 47 PETSC_EXTERN PetscErrorCode TaoLineSearchCreate_Unit(TaoLineSearch ls) { 48 PetscFunctionBegin; 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 PetscFunctionReturn(0); 57 } 58