Commits

sarich  committed fbe0838

fix viewer issues in tao and taolinesearch

  • Participants
  • Parent commits 7a12173

Comments (0)

Files changed (6)

File include/petsc-private/taoimpl.h

     PetscReal fmin;
 
     PetscBool printreason;
-    PetscBool viewtao;
     PetscBool viewsolution;
     PetscBool viewgradient;
     PetscBool viewconstraints;
     PetscBool viewhessian;
     PetscBool viewjacobian;
-    PetscViewer viewer;
 
     TaoSubsetType subset_type;
     PetscInt      hist_max;/* Number of iteration histories to keep */

File include/petsc-private/taolinesearchimpl.h

     PetscReal gtol;      /* tol for curvature condition (gtol>0)*/
     PetscReal stepmin;   /* lower bound for step */
     PetscReal stepmax;   /* upper bound for step */
-    PetscBool viewls;    /* print out information if true */
 
     Tao tao;
 };

File include/petsctao.h

 
 PETSC_EXTERN PetscErrorCode TaoSetOptionsPrefix(Tao,const char []);
 PETSC_EXTERN PetscErrorCode TaoView(Tao, PetscViewer);
+PETSC_STATIC_INLINE PetscErrorCode TaoViewFromOptions(Tao A,const char prefix[],const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,prefix,name);}
 
 PETSC_EXTERN PetscErrorCode TaoSolve(Tao);
 

File include/petsctaolinesearch.h

 PETSC_EXTERN PetscErrorCode TaoLineSearchSetUp(TaoLineSearch);
 PETSC_EXTERN PetscErrorCode TaoLineSearchDestroy(TaoLineSearch*);
 PETSC_EXTERN PetscErrorCode TaoLineSearchView(TaoLineSearch,PetscViewer);
+PETSC_STATIC_INLINE PetscErrorCode TaoLineSearchViewFromOptions(TaoLineSearch A,const char prefix[],const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,prefix,name);}
+
 PETSC_EXTERN PetscErrorCode TaoLineSearchSetOptionsPrefix(TaoLineSearch,const char prefix[]);
 PETSC_EXTERN PetscErrorCode TaoLineSearchReset(TaoLineSearch);
 PETSC_EXTERN PetscErrorCode TaoLineSearchAppendOptionsPrefix(TaoLineSearch,const char prefix[]);

File src/tao/interface/taosolver.c

   tao->viewgradient=PETSC_FALSE;
   tao->viewjacobian=PETSC_FALSE;
   tao->viewconstraints = PETSC_FALSE;
-  tao->viewtao = PETSC_FALSE;
 
   ierr = TaoResetStatistics(tao);CHKERRQ(ierr);
   *newtao = tao;
 PetscErrorCode TaoSolve(Tao tao)
 {
   PetscErrorCode   ierr;
-  char             filename[PETSC_MAX_PATH_LEN];
-  PetscBool        flg;
-  PetscViewer      viewer;
   static PetscBool set = PETSC_FALSE;
 
   PetscFunctionBegin;
   if (tao->ops->solve){ ierr = (*tao->ops->solve)(tao);CHKERRQ(ierr); }
   ierr = PetscLogEventEnd(Tao_Solve,tao,0,0,0);CHKERRQ(ierr);
 
-  ierr = PetscOptionsGetString(((PetscObject)tao)->prefix,"-tao_view",filename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
-  if (flg && !PetscPreLoadingOn) {
-    ierr = PetscViewerASCIIOpen(((PetscObject)tao)->comm,filename,&viewer);CHKERRQ(ierr);
-    ierr = TaoView(tao,viewer);CHKERRQ(ierr);
-    ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
-  }
+  ierr = TaoViewFromOptions(tao,NULL,"-tao_view");CHKERRQ(ierr);
 
   if (tao->printreason) {
     if (tao->reason > 0) {
       ierr = TaoSetType(tao,default_type);
     }
 
-    ierr = PetscOptionsBool("-tao_view","view Tao info after each minimization has completed","TaoView",PETSC_FALSE,&tao->viewtao,&flg);CHKERRQ(ierr);
     ierr = PetscOptionsReal("-tao_fatol","Stop if solution within","TaoSetTolerances",tao->fatol,&tao->fatol,&flg);CHKERRQ(ierr);
     ierr = PetscOptionsReal("-tao_frtol","Stop if relative solution within","TaoSetTolerances",tao->frtol,&tao->frtol,&flg);CHKERRQ(ierr);
     ierr = PetscOptionsReal("-tao_catol","Stop if constraints violations within","TaoSetConstraintTolerances",tao->catol,&tao->catol,&flg);CHKERRQ(ierr);

File src/tao/linesearch/interface/taolinesearch.c

 PetscErrorCode TaoLineSearchApply(TaoLineSearch ls, Vec x, PetscReal *f, Vec g, Vec s, PetscReal *steplength, TaoLineSearchConvergedReason *reason)
 {
   PetscErrorCode ierr;
-  PetscViewer    viewer;
   PetscInt       low1,low2,low3,high1,high2,high3;
-  PetscBool      flg;
-  char           filename[PETSC_MAX_PATH_LEN];
 
   PetscFunctionBegin;
   *reason = TAOLINESEARCH_CONTINUE_ITERATING;
     *steplength=ls->step;
   }
 
-  ierr = PetscOptionsGetString(((PetscObject)ls)->prefix,"-tao_ls_view",filename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
-  if (ls->viewls && !PetscPreLoadingOn) {
-    ierr = PetscViewerASCIIOpen(((PetscObject)ls)->comm,filename,&viewer);CHKERRQ(ierr);
-    ierr = TaoLineSearchView(ls,viewer);CHKERRQ(ierr);
-    ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
-  }
+  ierr = TaoLineSearchViewFromOptions(ls,NULL,"-tao_ls_view");CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 
   ierr = PetscOptionsReal("-tao_ls_rtol","relative tol for acceptable step","",ls->rtol,&ls->rtol,0);CHKERRQ(ierr);
   ierr = PetscOptionsReal("-tao_ls_stepmin","lower bound for step","",ls->stepmin,&ls->stepmin,0);CHKERRQ(ierr);
   ierr = PetscOptionsReal("-tao_ls_stepmax","upper bound for step","",ls->stepmax,&ls->stepmax,0);CHKERRQ(ierr);
-  ierr = PetscOptionsBool("-tao_ls_view","view TaoLineSearch info after each line search has completed","TaoLineSearchView",PETSC_FALSE,&ls->viewls,NULL);CHKERRQ(ierr);
   if (ls->ops->setfromoptions) {
     ierr = (*ls->ops->setfromoptions)(ls);CHKERRQ(ierr);
   }
     PetscStackPop;
     ierr = PetscLogEventEnd(TaoLineSearch_EvalEvent,ls,0,0,0);CHKERRQ(ierr);
     ierr = PetscInfo1(ls,"TaoLineSearch Function evaluation: %14.12e\n",(double)(*f));CHKERRQ(ierr);
-    ls->nfgeval++;
   }
+  ls->nfgeval++;
   PetscFunctionReturn(0);
 }