Actual source code: unit.c
1: #include "petscvec.h"
2: #include "taosolver.h"
3: #include "private/taolinesearch_impl.h"
7: static PetscErrorCode TaoLineSearchDestroy_Unit(TaoLineSearch ls)
8: {
11: PetscFree(ls->data);
12: ls->data = PETSC_NULL;
13: return(0);
14: }
18: static PetscErrorCode TaoLineSearchSetFromOptions_Unit(TaoLineSearch ls)
19: {
22: PetscOptionsHead("No Unit line search options");
23: PetscOptionsTail();
24: return(0);
25: }
29: static PetscErrorCode TaoLineSearchView_Unit(TaoLineSearch ls,PetscViewer viewer)
30: {
31:
33: PetscBool isascii;
35:
36: PetscTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii);
37: if (isascii) {
38: ierr=PetscViewerASCIIPrintf(viewer," Line Search: Unit Step.\n");
39: } else {
40: SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Viewer type %s not supported for Unit TaoLineSearch.",((PetscObject)viewer)->type_name);
41: }
42: return(0);
43: }
47: static PetscErrorCode TaoLineSearchApply_Unit(TaoLineSearch ls,Vec x,PetscReal *f,Vec g,Vec step_direction)
48: {
49: PetscErrorCode ierr;
50: PetscReal ftry;
51: PetscReal startf = *f;
54:
55: /* Take unit step (newx = startx + 1.0*step_direction) */
56: VecAXPY(x,1.0,step_direction);
58: TaoLineSearchComputeObjectiveAndGradient(ls,x,&ftry,g);
59: PetscInfo1(ls,"Tao Apply Unit Step: %4.4e\n",1.0);
60:
61: if (startf < ftry){
62: PetscInfo2(ls,"Tao Apply Unit Step, FINCREASE: F old:= %12.10e, F new: %12.10e\n",startf,ftry);
63: }
64: *f = ftry;
65: ls->step = 1.0;
66: ls->reason=TAOLINESEARCH_SUCCESS;
67: return(0);
68: }
73: /*@C
74: TaoCreateUnitLineSearch - Always use step length of 1.0
76: Input Parameters:
77: . tao - TaoSolver context
80: Level: advanced
82: .keywords: TaoSolver, linesearch
83: @*/
84: PetscErrorCode TaoLineSearchCreate_Unit(TaoLineSearch ls)
85: {
88: ls->ops->setup = 0;
89: ls->ops->apply = TaoLineSearchApply_Unit;
90: ls->ops->view = TaoLineSearchView_Unit;
91: ls->ops->destroy = TaoLineSearchDestroy_Unit;
92: ls->ops->setfromoptions = TaoLineSearchSetFromOptions_Unit;
94: return(0);
95: }