[11991] | 1 | Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/solutions/controltao_core.cpp
|
---|
| 2 | ===================================================================
|
---|
| 3 | --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/solutions/controltao_core.cpp (revision 11702)
|
---|
| 4 | +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/solutions/controltao_core.cpp (revision 11703)
|
---|
| 5 | @@ -12,7 +12,7 @@
|
---|
| 6 | #include "../include/include.h"
|
---|
| 7 | #include "../solvers/solvers.h"
|
---|
| 8 |
|
---|
| 9 | -#if defined (_HAVE_TAO_) && (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ == 2)
|
---|
| 10 | +#if defined (_HAVE_TAO_) && defined (_HAVE_PETSC_) && (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ == 2)
|
---|
| 11 | #include <tao.h>
|
---|
| 12 |
|
---|
| 13 | /*Local prototype*/
|
---|
| 14 | @@ -32,9 +32,9 @@
|
---|
| 15 | TaoSolver tao;
|
---|
| 16 | double *dummy = NULL;
|
---|
| 17 | int *control_list = NULL;
|
---|
| 18 | - Vec X = NULL;
|
---|
| 19 | - Vec XL = NULL;
|
---|
| 20 | - Vec XU = NULL;
|
---|
| 21 | + Vector *X = NULL;
|
---|
| 22 | + Vector *XL = NULL;
|
---|
| 23 | + Vector *XU = NULL;
|
---|
| 24 |
|
---|
| 25 | /*Initialize TAO*/
|
---|
| 26 | int argc; char **args=NULL;
|
---|
| 27 | @@ -67,10 +67,10 @@
|
---|
| 28 | GetVectorFromControlInputsx(&X, femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,"value");
|
---|
| 29 | GetVectorFromControlInputsx(&XL,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,"lowerbound");
|
---|
| 30 | GetVectorFromControlInputsx(&XU,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,"upperbound");
|
---|
| 31 | - TaoSetInitialVector(tao,X);
|
---|
| 32 | - TaoSetVariableBounds(tao,XL,XU);
|
---|
| 33 | - VecFree(&XL);
|
---|
| 34 | - VecFree(&XU);
|
---|
| 35 | + TaoSetInitialVector(tao,X->vector);
|
---|
| 36 | + TaoSetVariableBounds(tao,XL->vector,XU->vector);
|
---|
| 37 | + xdelete(&XL);
|
---|
| 38 | + xdelete(&XU);
|
---|
| 39 |
|
---|
| 40 | user.femmodel=femmodel;
|
---|
| 41 | TaoSetObjectiveAndGradientRoutine(tao,FormFunctionGradient,(void*)&user);
|
---|
| 42 | @@ -79,7 +79,7 @@
|
---|
| 43 | _printf_(VerboseControl(),"%s\n"," Starting optimization");
|
---|
| 44 | TaoSolve(tao);
|
---|
| 45 | TaoView(tao,PETSC_VIEWER_STDOUT_WORLD);
|
---|
| 46 | - TaoGetSolutionVector(tao,&X);
|
---|
| 47 | + TaoGetSolutionVector(tao,&X->vector);
|
---|
| 48 | SetControlInputsFromVectorx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,X);
|
---|
| 49 | for(int i=0;i<num_controls;i++){
|
---|
| 50 | InputToResultx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,control_list[i]);
|
---|
| 51 | @@ -94,11 +94,11 @@
|
---|
| 52 |
|
---|
| 53 | /*Clean up and return*/
|
---|
| 54 | xfree((void**)&control_list);
|
---|
| 55 | - VecFree(&X);
|
---|
| 56 | + xdelete(&X);
|
---|
| 57 | TaoDestroy(&tao);
|
---|
| 58 | TaoFinalize();
|
---|
| 59 | }
|
---|
| 60 | -int FormFunctionGradient(TaoSolver tao, Vec X, double *fcn,Vec G,void *userCtx){
|
---|
| 61 | +int FormFunctionGradient(TaoSolver tao, Vec Xpetsc, double *fcn,Vec G,void *userCtx){
|
---|
| 62 |
|
---|
| 63 | /*Retreive arguments*/
|
---|
| 64 | int solution_type,num_cost_functions;
|
---|
| 65 | @@ -106,8 +106,12 @@
|
---|
| 66 | FemModel *femmodel = user->femmodel;
|
---|
| 67 | int *cost_functions = NULL;
|
---|
| 68 | double *cost_functionsd= NULL;
|
---|
| 69 | - Vec gradient = NULL;
|
---|
| 70 | + Vector *gradient = NULL;
|
---|
| 71 | + Vector *X = NULL;
|
---|
| 72 |
|
---|
| 73 | + /*Convert input to Vec*/
|
---|
| 74 | + X=new Vector(Xpetsc);
|
---|
| 75 | +
|
---|
| 76 | /*Set new variable*/
|
---|
| 77 | //VecView(X,PETSC_VIEWER_STDOUT_WORLD);
|
---|
| 78 | SetControlInputsFromVectorx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,X);
|
---|
| 79 | @@ -135,7 +139,7 @@
|
---|
| 80 |
|
---|
| 81 | /*Compute gradient*/
|
---|
| 82 | Gradjx(&gradient,NULL,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
|
---|
| 83 | - VecCopy(gradient,G); VecFree(&gradient);
|
---|
| 84 | + VecCopy(gradient->vector,G); xdelete(&gradient);
|
---|
| 85 | VecScale(G,-1.);
|
---|
| 86 |
|
---|
| 87 | /*Clean-up and return*/
|
---|