6 #include "../toolkits/toolkits.h"
7 #include "../classes/classes.h"
8 #include "../shared/shared.h"
9 #include "../modules/modules.h"
10 #include "../solutionsequences/solutionsequences.h"
12 #if defined (_HAVE_TAO_)
13 #if defined (_HAVE_PETSC_) && (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 5)
20 #if defined (_HAVE_PETSC_) && (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 5)
22 int IssmMonitor(TaoSolver,
void*);
25 int IssmMonitor(Tao,
void*);
36 int num_controls,solution_type;
40 #if defined (_HAVE_PETSC_) && (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 5)
45 int *control_list = NULL;
46 char *algorithm = NULL;
53 #if defined (_HAVE_PETSC_) && (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 5)
54 int argc;
char **args=NULL;
55 PetscGetArgs(&argc,&args);
56 ierr = TaoInitialize(&argc,&args,(
char*)0,
"");
57 if(ierr)
_error_(
"Could not initialize Tao");
78 TaoSetFromOptions(tao);
79 TaoSetType(tao,algorithm);
82 TaoSetMonitor(tao,IssmMonitor,&user,NULL);
83 TaoSetMaximumFunctionEvaluations(tao,maxiter);
84 TaoSetMaximumIterations(tao,maxsteps);
85 #if (_PETSC_MAJOR_==3) && (_PETSC_MINOR_<7)
86 TaoSetTolerances(tao,0,0,gatol,grtol,gttol);
88 TaoSetTolerances(tao,gatol,grtol,gttol);
94 TaoSetInitialVector(tao,X->pvector->vector);
95 TaoSetVariableBounds(tao,XL->pvector->vector,XU->pvector->vector);
99 user.J=xNewZeroInit<double>(maxiter+5);
106 TaoView(tao,PETSC_VIEWER_STDOUT_WORLD);
109 TaoGetSolutionVector(tao,&X->pvector->vector);
111 TaoGetGradientVector(tao,&G->pvector->vector);
120 void (*solutioncore)(
FemModel*)=NULL;
125 xDelete<int>(control_list);
126 xDelete<char>(algorithm);
127 xDelete<double>(user.J);
130 #if defined (_HAVE_PETSC_) && (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 5)
133 G->pvector->vector = NULL;
137 #if defined (_HAVE_PETSC_) && (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 5)
162 void (*solutioncore)(
FemModel*)=NULL;
163 void (*adjointcore)(
FemModel*)=NULL;
174 VecCopy(gradient->pvector->vector,G);
delete gradient;
180 #if defined (_HAVE_PETSC_) && (_PETSC_MAJOR_ == 3 && _PETSC_MINOR_ < 5)
181 int IssmMonitor(TaoSolver tao,
void *userCtx){
183 int IssmMonitor(Tao tao,
void *userCtx){
186 int its,num_responses;
190 int *responses = NULL;
194 TaoGetSolutionStatus(tao, &its, &f, &gnorm, &cnorm, &xdiff, NULL);
195 if(its==0)
_printf0_(
"Iter Function Residual | List of contributions\n");
196 if(its==0)
_printf0_(
"___________________________________________________________\n");
197 _printf0_(setw(4)<<its<<
" "<<setw(12)<<setprecision(7)<<f<<
" "<<setw(12)<<setprecision(7)<<gnorm<<
" | ");
201 for(
int i=0;i<num_responses;i++){
203 _printf0_(
" "<<setw(12)<<setprecision(7)<<f);
208 xDelete<int>(responses);
214 _error_(
"TAO not installed or PETSc version not supported");