[11514] | 1 | Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/solutions/issm.cpp
|
---|
| 2 | ===================================================================
|
---|
| 3 | --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/solutions/issm.cpp (revision 11266)
|
---|
| 4 | +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/solutions/issm.cpp (revision 11267)
|
---|
| 5 | @@ -95,7 +95,11 @@
|
---|
| 6 | }
|
---|
| 7 | else if(control_analysis){
|
---|
| 8 | #ifdef _HAVE_CONTROL_
|
---|
| 9 | + #ifdef _HAVE_TAO_
|
---|
| 10 | + controltao_core(femmodel);
|
---|
| 11 | + #else
|
---|
| 12 | control_core(femmodel);
|
---|
| 13 | + #endif
|
---|
| 14 | #else
|
---|
| 15 | _error_("ISSM was not compiled with control support, cannot carry out dakota analysis!");
|
---|
| 16 | #endif
|
---|
| 17 | Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/solutions/controltao_core.cpp
|
---|
| 18 | ===================================================================
|
---|
| 19 | --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/solutions/controltao_core.cpp (revision 11266)
|
---|
| 20 | +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/solutions/controltao_core.cpp (revision 11267)
|
---|
| 21 | @@ -12,12 +12,11 @@
|
---|
| 22 | #include "../include/include.h"
|
---|
| 23 | #include "../solvers/solvers.h"
|
---|
| 24 |
|
---|
| 25 | +#if defined (_HAVE_TAO_) && (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ == 2)
|
---|
| 26 | +#include <tao.h>
|
---|
| 27 |
|
---|
| 28 | -#if defined (_HAVE_TAO_) && (_PETSC_MAJOR_ < 3 || (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 2))
|
---|
| 29 | -#include "tao.h"
|
---|
| 30 | -
|
---|
| 31 | /*Local prototype*/
|
---|
| 32 | -int FormFunctionGradient(TAO_APPLICATION,Vec,double *,Vec,void*);
|
---|
| 33 | +int FormFunctionGradient(TaoSolver tao,Vec,double *,Vec,void*);
|
---|
| 34 | typedef struct {
|
---|
| 35 | FemModel* femmodel;
|
---|
| 36 | } AppCtx;
|
---|
| 37 | @@ -25,17 +24,13 @@
|
---|
| 38 | void controltao_core(FemModel* femmodel){
|
---|
| 39 |
|
---|
| 40 | /*TAO*/
|
---|
| 41 | - int i,n,info;
|
---|
| 42 | - //TaoMethod method = "tao_blmvm";
|
---|
| 43 | - //TaoMethod method = "tao_lmvm";
|
---|
| 44 | - TaoMethod method = "tao_cg";
|
---|
| 45 | - TaoTerminateReason reason;
|
---|
| 46 | - TAO_SOLVER tao;
|
---|
| 47 | - TAO_APPLICATION controlapp;
|
---|
| 48 | - Vec initial_solution = NULL;
|
---|
| 49 | - AppCtx user;
|
---|
| 50 | - PetscInt iter;
|
---|
| 51 | - double ff,gnorm;
|
---|
| 52 | + int i,n,info;
|
---|
| 53 | + TaoSolverTerminationReason reason;
|
---|
| 54 | + TaoSolver tao;
|
---|
| 55 | + Vec initial_solution = NULL;
|
---|
| 56 | + AppCtx user;
|
---|
| 57 | + PetscInt iter;
|
---|
| 58 | + double ff ,gnorm;
|
---|
| 59 |
|
---|
| 60 | /*Initialize TAO*/
|
---|
| 61 | int argc; char **args; PetscGetArgs(&argc,&args);
|
---|
| 62 | @@ -61,21 +56,17 @@
|
---|
| 63 |
|
---|
| 64 | /*Set up and solve TAO*/
|
---|
| 65 | GetVectorFromInputsx(&initial_solution,femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,MaterialsRheologyBbarEnum,VertexEnum);
|
---|
| 66 | - info = TaoCreate(PETSC_COMM_WORLD,method,&tao); if(info) _error_("STOP");
|
---|
| 67 | - info = TaoApplicationCreate(PETSC_COMM_WORLD,&controlapp); if(info) _error_("STOP");
|
---|
| 68 | - info = TaoAppSetInitialSolutionVec(controlapp,initial_solution); if(info) _error_("STOP");
|
---|
| 69 | - info = TaoAppSetObjectiveAndGradientRoutine(controlapp,FormFunctionGradient,(void*)&user); if(info) _error_("STOP");
|
---|
| 70 | - info = TaoSetOptions(controlapp,tao); if(info) _error_("STOP");
|
---|
| 71 | - info = TaoSolveApplication(controlapp,tao); //if(info) _error_("STOP");
|
---|
| 72 | + info = TaoCreate(PETSC_COMM_WORLD,&tao); if(info) _error_("STOP");
|
---|
| 73 | + info = TaoSetType(tao,"tao_cg"); if(info) _error_("STOP");
|
---|
| 74 | + info = TaoSetInitialVector(tao,initial_solution); if(info) _error_("STOP");
|
---|
| 75 | + info = TaoSetObjectiveAndGradientRoutine(tao,FormFunctionGradient,(void*)&user); if(info) _error_("STOP");
|
---|
| 76 | + info = TaoSetFromOptions(tao); if(info) _error_("STOP");
|
---|
| 77 | + info = TaoSolve(tao); //if(info) _error_("STOP");
|
---|
| 78 |
|
---|
| 79 | /*Get solution status*/
|
---|
| 80 | info = TaoGetSolutionStatus(tao,&iter,&ff,&gnorm,0,0,&reason); //CHKERRQ(info);
|
---|
| 81 | - switch(reason){ /*http://www.mcs.anl.gov/research/projects/tao/docs/manualpages/solver/TaoGetTerminationReason.html*/
|
---|
| 82 | - case TAO_CONVERGED_ATOL: _printf_(true,"TAO_CONVERGED_ATOL (res <= atol)\n"); break;
|
---|
| 83 | - case TAO_CONVERGED_RTOL: _printf_(true,"TAO_CONVERGED_RTOL (res/res0 <= rtol)\n"); break;
|
---|
| 84 | - case TAO_CONVERGED_TRTOL: _printf_(true,"TAO_CONVERGED_TRTOL (xdiff <= trtol) \n"); break;
|
---|
| 85 | - case TAO_CONVERGED_MINF: _printf_(true,"TAO_CONVERGED_MINF (f <= fmin)\n"); break;
|
---|
| 86 | - case TAO_CONVERGED_USER: _printf_(true,"TAO_CONVERGED_USER (user defined)\n"); break;
|
---|
| 87 | + switch(reason){
|
---|
| 88 | + /*http://www.mcs.anl.gov/research/projects/tao/docs/manpages/taosolver/TaoGetTerminationReason.html*/
|
---|
| 89 | case TAO_DIVERGED_MAXITS: _printf_(true,"TAO_DIVERGED_MAXITS (its>maxits)\n"); break;
|
---|
| 90 | case TAO_DIVERGED_NAN: _printf_(true,"TAO_DIVERGED_NAN (Numerical problems)\n"); break;
|
---|
| 91 | case TAO_DIVERGED_MAXFCN: _printf_(true,"TAO_DIVERGED_MAXFCN (nfunc > maxnfuncts)\n"); break;
|
---|
| 92 | @@ -91,18 +82,17 @@
|
---|
| 93 | else{
|
---|
| 94 | _printf_(true,"TAO found a solution");
|
---|
| 95 | }
|
---|
| 96 | - info = TaoView(tao); if(info) _error_("STOP");
|
---|
| 97 | + info = TaoView(tao,PETSC_VIEWER_STDOUT_SELF); if(info) _error_("STOP");
|
---|
| 98 |
|
---|
| 99 | /*Clean up*/
|
---|
| 100 | - info = TaoDestroy(tao); if(info) _error_("STOP");
|
---|
| 101 | - info = TaoAppDestroy(controlapp); if(info) _error_("STOP");
|
---|
| 102 | + info = TaoDestroy(&tao); if(info) _error_("STOP");
|
---|
| 103 | VecFree(&initial_solution);
|
---|
| 104 |
|
---|
| 105 | /* Finalize TAO */
|
---|
| 106 | TaoFinalize();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | -int FormFunctionGradient(TAO_APPLICATION taoapp, Vec X, double *fcn,Vec G,void *userCtx){
|
---|
| 110 | +int FormFunctionGradient(TaoSolver tao, Vec X, double *fcn,Vec G,void *userCtx){
|
---|
| 111 |
|
---|
| 112 | /*Retreive arguments*/
|
---|
| 113 | AppCtx *user = (AppCtx*)userCtx;
|
---|