xref: /petsc/src/tao/linesearch/impls/unit/unit.c (revision fe998a80077c9ee0917a39496df43fc256e1b478) !
1 
2 #include <petsc-private/taolinesearchimpl.h>
3 
4 #undef __FUNCT__
5 #define __FUNCT__ "TaoLineSearchDestroy_Unit"
6 static PetscErrorCode TaoLineSearchDestroy_Unit(TaoLineSearch ls)
7 {
8   PetscErrorCode ierr;
9   PetscFunctionBegin;
10   ierr = PetscFree(ls->data);CHKERRQ(ierr);
11   PetscFunctionReturn(0);
12 }
13 
14 #undef __FUNCT__
15 #define __FUNCT__ "TaoLineSearchSetFromOptions_Unit"
16 static PetscErrorCode TaoLineSearchSetFromOptions_Unit(TaoLineSearch ls)
17 {
18   PetscErrorCode ierr;
19   PetscFunctionBegin;
20   ierr = PetscOptionsHead("No Unit line search options");CHKERRQ(ierr);
21   ierr = PetscOptionsTail();CHKERRQ(ierr);
22   PetscFunctionReturn(0);
23 }
24 
25 #undef __FUNCT__
26 #define __FUNCT__ "TaoLineSearchView_Unit"
27 static PetscErrorCode TaoLineSearchView_Unit(TaoLineSearch ls,PetscViewer viewer)
28 {
29   PetscErrorCode ierr;
30   PetscBool      isascii;
31 
32   PetscFunctionBegin;
33   ierr = PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii);CHKERRQ(ierr);
34   if (isascii) {
35     ierr=PetscViewerASCIIPrintf(viewer,"  Line Search: Unit Step.\n");CHKERRQ(ierr);
36   }
37   PetscFunctionReturn(0);
38 }
39 
40 #undef __FUNCT__
41 #define __FUNCT__ "TaoLineSearchApply_Unit"
42 static PetscErrorCode TaoLineSearchApply_Unit(TaoLineSearch ls,Vec x,PetscReal *f,Vec g,Vec step_direction)
43 {
44   PetscErrorCode ierr;
45   PetscReal      ftry;
46   PetscReal      startf = *f;
47 
48   PetscFunctionBegin;
49   /* Take unit step (newx = startx + 1.0*step_direction) */
50   ierr = VecAXPY(x,1.0,step_direction);CHKERRQ(ierr);
51   ierr = TaoLineSearchComputeObjectiveAndGradient(ls,x,&ftry,g);CHKERRQ(ierr);
52   ierr = PetscInfo1(ls,"Tao Apply Unit Step: %4.4e\n",1.0);CHKERRQ(ierr);
53   if (startf < ftry){
54     ierr = PetscInfo2(ls,"Tao Apply Unit Step, FINCREASE: F old:= %12.10e, F new: %12.10e\n",(double)startf,(double)ftry);CHKERRQ(ierr);
55   }
56   *f = ftry;
57   ls->step = 1.0;
58   ls->reason=TAOLINESEARCH_SUCCESS;
59   PetscFunctionReturn(0);
60 }
61 
62 #undef __FUNCT__
63 #define __FUNCT__ "TaoLineSearchCreate_Unit"
64 /*@C
65    TaoCreateUnitLineSearch - Always use step length of 1.0
66 
67    Input Parameters:
68 .  tao - Tao context
69 
70    Level: advanced
71 
72 .keywords: Tao, linesearch
73 @*/
74 PETSC_EXTERN PetscErrorCode TaoLineSearchCreate_Unit(TaoLineSearch ls)
75 {
76   PetscFunctionBegin;
77   ls->ops->setup = 0;
78   ls->ops->reset = 0;
79   ls->ops->apply = TaoLineSearchApply_Unit;
80   ls->ops->view = TaoLineSearchView_Unit;
81   ls->ops->destroy = TaoLineSearchDestroy_Unit;
82   ls->ops->setfromoptions = TaoLineSearchSetFromOptions_Unit;
83   PetscFunctionReturn(0);
84 }
85 
86 
87