Changeset 11267
- Timestamp:
- 01/31/12 10:34:43 (13 years ago)
- Location:
- issm/trunk-jpl/src/c/solutions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/solutions/controltao_core.cpp
r10052 r11267 13 13 #include "../solvers/solvers.h" 14 14 15 16 #if defined (_HAVE_TAO_) && (_PETSC_MAJOR_ < 3 || (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 2)) 17 #include "tao.h" 15 #if defined (_HAVE_TAO_) && (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ == 2) 16 #include <tao.h> 18 17 19 18 /*Local prototype*/ 20 int FormFunctionGradient(T AO_APPLICATION,Vec,double *,Vec,void*);19 int FormFunctionGradient(TaoSolver tao,Vec,double *,Vec,void*); 21 20 typedef struct { 22 21 FemModel* femmodel; … … 26 25 27 26 /*TAO*/ 28 int i,n,info; 29 //TaoMethod method = "tao_blmvm"; 30 //TaoMethod method = "tao_lmvm"; 31 TaoMethod method = "tao_cg"; 32 TaoTerminateReason reason; 33 TAO_SOLVER tao; 34 TAO_APPLICATION controlapp; 35 Vec initial_solution = NULL; 36 AppCtx user; 37 PetscInt iter; 38 double ff,gnorm; 27 int i,n,info; 28 TaoSolverTerminationReason reason; 29 TaoSolver tao; 30 Vec initial_solution = NULL; 31 AppCtx user; 32 PetscInt iter; 33 double ff ,gnorm; 39 34 40 35 /*Initialize TAO*/ … … 62 57 /*Set up and solve TAO*/ 63 58 GetVectorFromInputsx(&initial_solution,femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,MaterialsRheologyBbarEnum,VertexEnum); 64 info = TaoCreate(PETSC_COMM_WORLD, method,&tao); if(info) _error_("STOP");65 info = Tao ApplicationCreate(PETSC_COMM_WORLD,&controlapp); if(info) _error_("STOP");66 info = Tao AppSetInitialSolutionVec(controlapp,initial_solution); if(info) _error_("STOP");67 info = Tao AppSetObjectiveAndGradientRoutine(controlapp,FormFunctionGradient,(void*)&user); if(info) _error_("STOP");68 info = TaoSet Options(controlapp,tao); if(info) _error_("STOP");69 info = TaoSolve Application(controlapp,tao); //if(info) _error_("STOP");59 info = TaoCreate(PETSC_COMM_WORLD,&tao); if(info) _error_("STOP"); 60 info = TaoSetType(tao,"tao_cg"); if(info) _error_("STOP"); 61 info = TaoSetInitialVector(tao,initial_solution); if(info) _error_("STOP"); 62 info = TaoSetObjectiveAndGradientRoutine(tao,FormFunctionGradient,(void*)&user); if(info) _error_("STOP"); 63 info = TaoSetFromOptions(tao); if(info) _error_("STOP"); 64 info = TaoSolve(tao); //if(info) _error_("STOP"); 70 65 71 66 /*Get solution status*/ 72 67 info = TaoGetSolutionStatus(tao,&iter,&ff,&gnorm,0,0,&reason); //CHKERRQ(info); 73 switch(reason){ /*http://www.mcs.anl.gov/research/projects/tao/docs/manualpages/solver/TaoGetTerminationReason.html*/ 74 case TAO_CONVERGED_ATOL: _printf_(true,"TAO_CONVERGED_ATOL (res <= atol)\n"); break; 75 case TAO_CONVERGED_RTOL: _printf_(true,"TAO_CONVERGED_RTOL (res/res0 <= rtol)\n"); break; 76 case TAO_CONVERGED_TRTOL: _printf_(true,"TAO_CONVERGED_TRTOL (xdiff <= trtol) \n"); break; 77 case TAO_CONVERGED_MINF: _printf_(true,"TAO_CONVERGED_MINF (f <= fmin)\n"); break; 78 case TAO_CONVERGED_USER: _printf_(true,"TAO_CONVERGED_USER (user defined)\n"); break; 68 switch(reason){ 69 /*http://www.mcs.anl.gov/research/projects/tao/docs/manpages/taosolver/TaoGetTerminationReason.html*/ 79 70 case TAO_DIVERGED_MAXITS: _printf_(true,"TAO_DIVERGED_MAXITS (its>maxits)\n"); break; 80 71 case TAO_DIVERGED_NAN: _printf_(true,"TAO_DIVERGED_NAN (Numerical problems)\n"); break; … … 92 83 _printf_(true,"TAO found a solution"); 93 84 } 94 info = TaoView(tao ); if(info) _error_("STOP");85 info = TaoView(tao,PETSC_VIEWER_STDOUT_SELF); if(info) _error_("STOP"); 95 86 96 87 /*Clean up*/ 97 info = TaoDestroy(tao); if(info) _error_("STOP"); 98 info = TaoAppDestroy(controlapp); if(info) _error_("STOP"); 88 info = TaoDestroy(&tao); if(info) _error_("STOP"); 99 89 VecFree(&initial_solution); 100 90 … … 103 93 } 104 94 105 int FormFunctionGradient(T AO_APPLICATION taoapp, Vec X, double *fcn,Vec G,void *userCtx){95 int FormFunctionGradient(TaoSolver tao, Vec X, double *fcn,Vec G,void *userCtx){ 106 96 107 97 /*Retreive arguments*/ -
issm/trunk-jpl/src/c/solutions/issm.cpp
r10569 r11267 96 96 else if(control_analysis){ 97 97 #ifdef _HAVE_CONTROL_ 98 #ifdef _HAVE_TAO_ 99 controltao_core(femmodel); 100 #else 98 101 control_core(femmodel); 102 #endif 99 103 #else 100 104 _error_("ISSM was not compiled with control support, cannot carry out dakota analysis!");
Note:
See TracChangeset
for help on using the changeset viewer.