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