Actual source code: newsolver.c

  1: #include "src/tao_impl.h"      /*I "tao_solver.h"  I*/

  5: /*@
  6:   TaoSetMethodFromOptions - Sets the TAO_SOLVER solver type from the options database, 
  7:   or sets a default if no method has been specified.

  9:    Collective on TAO_SOLVER

 11:    Input Parameter:
 12: .  solver - the TAO_SOLVER solver context

 14:    Options Database Keys:
 15: .  -tao_method <type> - tao_nls, tao_ntr, tao_ntl, tao_lmvm, tao_cg, tao_tron, etc.

 17:    Level: intermediate

 19: .keywords: method, options, database

 21: .seealso: TaoSetOptions()
 22: @*/
 23: int TaoSetMethodFromOptions(TAO_SOLVER solver)
 24: {
 25:   char       type[256];
 26:   int        info;
 27:   TaoTruth flg;

 29:   TaoFunctionBegin;
 30:   TaoValidHeaderSpecific(solver,TAO_COOKIE,1);
 31:   if (solver->setupcalled) SETERRQ(1,"Must call prior to TaoSetUp()");

 33:   info = TaoOptionString("-tao_method","TaoMethod","TaoSetMethod","",type,256, &flg);CHKERRQ(info);
 34:   if (flg) {
 35:     info = TaoSetMethod(solver,(TaoMethod) type);CHKERRQ(info);
 36:   }
 37:   if (!((PetscObject)solver)->type_name) {
 38:     info = TaoSetMethod(solver,"tao_lmvm");CHKERRQ(info);
 39:   }
 40:   TaoFunctionReturn(0);
 41: }


 46: /*@
 47:    TaoSetFromOptions - Sets many TAO_SOLVER parameters from the command line arguments.  
 48:    This command does not set the solver type.

 50:    Collective on TAO_SOLVER

 52:    Input Parameter:
 53: .  solver - the TAO_SOLVER solver context

 55:    Options Database Keys:
 56: +  -tao_stol - convergence tolerance in terms of the norm
 57:                 of the change in the solution between steps
 58: .  -tao_fatol <fatol> - absolute tolerance of residual norm
 59: .  -tao_frtol <frtol> - relative decrease in tolerance norm from initial
 60: .  -tao_max_its <max_its> - maximum number of iterations
 61: .  -tao_max_funcs <max_funcs> - maximum number of function evaluations
 62: .  -tao_trtol <trtol> - trust region tolerance
 63: .  -tao_trust0 <radius> - initial trust region radius
 64: .  -tao_no_convergence_test - skip convergence test in minimization solver;
 65:                                hence iterations will continue until max_it
 66:                                or some other criterion is reached. Saves expense
 67:                                of convergence test
 68: .  -tao_monitor - prints residual norm at each iteration 
 69: .  -tao_vecmonitor - plots solution at each iteration
 70: .  -tao_vecmonitor_update - plots update to solution at each iteration 
 71: .  -tao_xmonitor - plots residual norm at each iteration 
 72: .  -tao_fd - use finite differences to compute Hessian; very slow, only for testing
 73: -  -tao_mf_ksp_monitor - if using matrix-free multiply then print h at each KSP iteration

 75:    Notes:
 76:    To see all options, run your program with the -help option or consult
 77:    the users manual.

 79:    Level: developer

 81: .keywords: options, converence, monitor, view, database

 83: .seealso: TaoSetMethodFromOptions()
 84: @*/
 85: int TaoSetFromOptions(TAO_SOLVER solver)
 86: {
 87:   TaoTruth flg;
 88:   int      info;
 89:   char      type[256];

 91:   TaoFunctionBegin;
 92:   TaoValidHeaderSpecific(solver,TAO_COOKIE,1);

 94:   info = TaoMethodsList("-tao_method","Select TAO method","TaoSetMethod",0,type,256,0);CHKERRQ(info);

 96:   if (solver->setfromoptions) {
 97:     info = (*solver->setfromoptions)(solver,solver->data); CHKERRQ(info);
 98:   }


101:   info = TaoOptionName("-tao_view","view TAO_SOLVER info after each minimization has completed","TaoView",&flg);CHKERRQ(info);
102:   if (flg) solver->viewtao = TAO_TRUE;
103:   info = TaoOptionName("-tao_kspview","view the Linear Solver used by the solver after minimization has completed","TaoViewLinearSolver",&flg);CHKERRQ(info);
104:   if (flg) solver->viewksptao = TAO_TRUE;
105:   
106:   info = TaoOptionDouble("-tao_fatol","Stop if solution within","TaoSetTolerances",solver->fatol,&solver->fatol,&flg);CHKERRQ(info);
107:   info = TaoOptionDouble("-tao_frtol","Stop if relative solution within","TaoSetTolerances",solver->frtol,&solver->frtol,&flg);CHKERRQ(info);
108:   info = TaoOptionDouble("-tao_catol","Stop if constraints violations within","TaoSetTolerances",solver->catol,&solver->catol,&flg);CHKERRQ(info);
109:   info = TaoOptionDouble("-tao_crtol","Stop if relative contraint violations within","TaoSetTolerances",solver->crtol,&solver->crtol,&flg);CHKERRQ(info);
110:   info = TaoOptionDouble("-tao_gatol","Stop if norm of gradient less than","TaoSetGradientTolerances",solver->gatol,&solver->gatol,&flg);CHKERRQ(info);
111:   info = TaoOptionDouble("-tao_grtol","Stop if norm of gradient divided by the function value is less than","TaoSetGradientTolerances",solver->grtol,&solver->grtol,&flg);CHKERRQ(info); 
112:   info = TaoOptionDouble("-tao_gttol","Stop if the norm of the gradient is less than the norm of the initial gradient times","TaoSetGradientTolerances",solver->gttol,&solver->gttol,&flg);CHKERRQ(info); 
113:   info = TaoOptionInt("-tao_max_its","Stop if iteration number exceeds",
114:                        "TaoSetMaximumIterates",solver->max_its,&solver->max_its,
115:                        &flg);CHKERRQ(info);
116:   info = TaoOptionInt("-tao_max_funcs","Stop if number of function evaluations exceeds","TaoSetMaximumFunctionEvaluations",solver->max_funcs,&solver->max_funcs,&flg);
117:   info = TaoOptionDouble("-tao_fmin","Stop if function less than","TaoSetFunctionLowerBound",solver->fmin,&solver->fmin,&flg);
118:   info = TaoOptionDouble("-tao_steptol","Stop if step size or trust region radius less than","TaoSetTrustRegionRadius",solver->trtol,&solver->trtol,&flg);CHKERRQ(info);
119:   info = TaoOptionDouble("-tao_trust0","Initial trust region radius","TaoSetTrustRegionRadius",solver->trust0,&solver->trust0,&flg);CHKERRQ(info);

121:   /*
122:   info = (*PetscHelpPrintf)(solver->comm," TAO_SOLVER Monitoring Options: Choose any of the following\n");CHKERRQ(info);
123:   */

125:   info = TaoOptionName("-tao_unitstep","Always use unit step length","TaoCreateUnitLineSearch",&flg);
126:   if (flg){info=TaoCreateUnitLineSearch(solver);CHKERRQ(info);}
127:   info = TaoOptionName("-tao_lmvmh","User supplies approximate hessian for LMVM solvers","TaoLMVMSetH0",&flg);
128:   if (flg){info=TaoBLMVMSetH0(solver,TAO_TRUE);CHKERRQ(info);info=TaoLMVMSetH0(solver,TAO_TRUE);CHKERRQ(info);}
129:   
130:   info = TaoOptionName("-tao_view_hessian","view Hessian after each evaluation","None",&flg);CHKERRQ(info);
131:   if (flg) solver->viewhessian = TAO_TRUE;
132:   info = TaoOptionName("-tao_view_gradient","view gradient after each evaluation","None",&flg);CHKERRQ(info);
133:   if (flg) solver->viewgradient = TAO_TRUE;
134:   info = TaoOptionName("-tao_view_jacobian","view jacobian after each evaluation","None",&flg);CHKERRQ(info);  
135:   if (flg) solver->viewjacobian = TAO_TRUE;
136:   info = TaoOptionName("-tao_view_constraints","view constraint function after each evaluation","None",&flg);CHKERRQ(info);  
137:   if (flg) solver->viewvfunc = TAO_TRUE;

139:   info = TaoOptionName("-tao_cancelmonitors","cancel all monitors hardwired in code","TaoClearMonitor",&flg);CHKERRQ(info);
140:   if (flg) {info = TaoClearMonitor(solver);CHKERRQ(info);}
141:   info = TaoOptionName("-tao_monitor","Use the default convergence monitor","TaoSetMonitor",&flg);CHKERRQ(info);
142:   if (flg && solver->defaultmonitor) {
143:     info = TaoSetMonitor(solver,solver->defaultmonitor,TAO_NULL);CHKERRQ(info);
144:   }
145:   info = TaoOptionName("-tao_smonitor","Use short monitor","None",&flg);CHKERRQ(info);
146:   if (flg) {info = TaoSetMonitor(solver,TaoDefaultSMonitor,TAO_NULL);CHKERRQ(info);}
147:   info = TaoOptionName("-tao_vecmonitor","Plot solution vector at each iteration","TaoVecViewMonitor",&flg);CHKERRQ(info);
148:   if (flg) {info = TaoSetMonitor(solver,TaoVecViewMonitor,TAO_NULL);CHKERRQ(info);}
149:   info = TaoOptionName("-tao_vecmonitor_update","plots step direction at each iteration","TaoVecViewMonitorUpdate",&flg);CHKERRQ(info);
150:   if (flg) {info = TaoSetMonitor(solver,TaoVecViewMonitorUpdate,TAO_NULL);CHKERRQ(info);}


153:   //  info = PetscOptionsEnd();CHKERRQ(info);

155:   //  info = TaoSetLinearSolverOptions(solver);CHKERRQ(info);

157:   TaoFunctionReturn(0); 
158: }


161: /* -----------------------------------------------------------*/
164: /*
165:    TaoCreateFull - Creates a TAO_SOLVER context.

167:    Collective on MPI_Comm

169:    Input Parameters:
170: +  method - A TAO method.  
171: .  prefix - a prefix to prepend to all option names (usually TAO_NULL)
172: -  comm - MPI communicator

174:    Output Parameter:
175: .  newsolver - the new TAO_SOLVER context

177:    Options Database Keys:
178: .   -tao_method - select which method TAO should use

180:    Level: developer

182: .keywords: Create, solver, method, context

184: .seealso: TaoCreate(), TaoSolve(), TaoSetMethod(), TaoDestroy()
185: */
186: int TaoCreateFull(TaoMethod method, const char* prefix, MPI_Comm comm, TAO_SOLVER *newsolver)
187: {
188:   TAO_SOLVER solver;
189:   int info;

191:   TaoFunctionBegin;

193:   *newsolver = 0;

195:   info = TaoInitialize(0,0,0,0);CHKERRQ(info);CHKERRQ(info);

197:   info = TaoObjectCreate(newsolver,comm);CHKERRQ(info);
198:   solver=*newsolver;

200:   //  info = TaoSetOptionsPrefix(solver,prefix);CHKERRQ(info);

202:   solver->vec_sol=0;
203:   solver->hessian=0;
204:   solver->vfunc=0;
205:   solver->jacobian=0;
206:   solver->RXL=0;
207:   solver->RXU=0;
208:   solver->CA=0;

210:   info = TaoResetSolver(solver); CHKERRQ(info);  /* Set some pointers to NULL */
211:   info = TaoSetDefaultParameters(solver);CHKERRQ(info);
212:   info = TaoSetDefaultStatistics(solver);CHKERRQ(info);
213:   info = TaoSetDefaultMonitors(solver);CHKERRQ(info);

215:   *newsolver = solver;
216:   if (method) {
217:     info=TaoSetMethod(solver,method);CHKERRQ(info);
218:   }

220:   TaoFunctionReturn(0);
221: }


224: /* -----------------------------------------------------------*/
227: /*@C
228:    TaoCreate - Creates a TAO_SOLVER context.

230:    Collective on MPI_Comm

232:    Input Parameters:
233: +  comm - MPI communicator
234: -  method - A TAO method.  

236:    Output Parameter:
237: .  newsolver - the new TAO_SOLVER context

239:    Options Database Keys:
240: .   -tao_method - select which method TAO should use

242:    Available methods include:
243: +    tao_nls - Newton's method with line search for unconstrained minimization
244: .    tao_ntr - Newton's method with trust region for unconstrained minimization
245: .    tao_ntl - Newton's method with trust region, line search for unconstrained minimization
246: .    tao_lmvm - Limited memory variable metric method for unconstrained minimization
247: .    tao_cg - Nonlinear conjugate gradient method for unconstrained minimization
248: .    tao_nm - Nelder-Mead algorithm for derivate-free unconstrained minimization
249: .    tao_tron - Newton Trust Region method for bound constrained minimization
250: .    tao_gpcg - Newton Trust Region method for quadratic bound constrained minimization
251: .    tao_blmvm - Limited memory variable metric method for bound constrained minimization
252: .    tao_kt - Formulate a bound constrained problem as a complementarity problem
253: .    tao_bqpip - Interior point method for quadratic bound constrained minimization
254: .    tao_ssils - Infeasible semismooth method with a linesearch for complementarity problems
255: -    tao_ssfls - Feasible semismooth method with a linesearch for complementarity problems

257:    Level: beginner

259:    Note: 
260:    If the second argument specifies a TaoMethod, quotation marks should 
261:    surround the method.

263:    Note:
264:    The TaoMethod can be TAO_NULL (C/C++) or 
265:    TAO_NULL_CHARACTER (Fortran), in which case the
266:    method will be specified by the runtime option -tao_method

268:    If a particular optimization method is specified at runtime by
269:    the option '-tao_method', this choice will be used instead of
270:    any default that may have been specified as the input parameter
271:    "method" to this routine.

273: .keywords: Create, solver, method, context

275: .seealso: TaoSolve(), TaoSetMethod(), TaoSetApplication(), TaoDestroy()
276: @*/
277: int TaoCreate(MPI_Comm comm, TaoMethod method, TAO_SOLVER *newsolver)
278: {
279:   int info;

281:   TaoFunctionBegin;

283:   *newsolver = 0;

285:   info = TaoCreateFull(method,0,comm,newsolver);CHKERRQ(info);
286:   info = TaoSetMethodFromOptions(*newsolver);CHKERRQ(info);

288:   TaoFunctionReturn(0);
289: }



293: /* ----- Routines to initialize and destroy a minimization solver ---- */

297: /*@
298:    TaoSetDefaultParameters - Set the parameters used by all TAO solvers to a default value.  These
299:    parameter include convergence tolerances.  This routine is called before setting the
300:    method used by TAO

302:    Collective on TAO_SOLVER

304:    Input Parameters:
305: .  solver - the TAO_SOLVER solver context

307:    Level: developer

309: .keywords: options, defaults

311: .seealso: TaoCreate(), TaoSetDefaultStatistics(), TaoSetDefaultMonitors()
312: @*/
313: int TaoSetDefaultParameters(TAO_SOLVER solver){

315:   TaoFunctionBegin;
316:   solver->max_its            = 0;
317:   solver->max_funcs             = 100000000;
318:   solver->fatol              = 0.0;
319:   solver->frtol              = 0.0;
320:   solver->catol              = 0.0;
321:   solver->crtol              = 0.0;
322:   solver->gatol              = 0.0;
323:   solver->grtol              = 0.0;
324:   solver->xtol                     = 0.0;
325:   solver->trtol              = 0.0;
326:   solver->fmin               = -1.e30;
327:   TaoFunctionReturn(0);
328: }

332: /*@
333:    TaoSetDefaultStatistics - Initialize the statistics used by TAO for all of the solvers.
334:    These statistics include the iteration number, residual norms, and convergence status.
335:    This routine gets called before solving each optimization problem.

337:    Collective on TAO_SOLVER

339:    Input Parameters:
340: .  solver - the TAO_SOLVER solver context

342:    Level: developer

344: .keywords: options, defaults

346: .seealso: TaoCreate(), TaoSetDefaultParameters(), TaoSetDefaultMonitors(), TaoSolve()
347: @*/
348: int TaoSetDefaultStatistics(TAO_SOLVER solver){

350:   TaoFunctionBegin;
351:   solver->iter               = 0;
352:   solver->fc                 = 0;
353:   solver->norm                     = 0.0;
354:   solver->norm0                     = 0.0;
355:   solver->cnorm                     = 0.0;
356:   solver->cnorm0             = 0.0;
357:   solver->nfuncs             = 0;
358:   solver->ngrads             = 0;
359:   solver->nfgrads            = 0;
360:   solver->nhesss             = 0;
361:   solver->nvfunc             = 0;
362:   solver->njac               = 0;
363:   solver->linear_its         = 0;
364:   solver->lsflag             = 0;
365:   solver->reason             = TAO_CONTINUE_ITERATING;
366:   solver->step               = 1.0e+30;
367:   if (solver->conv_hist_reset == TAO_TRUE) solver->conv_hist_len = 0;
368:   TaoFunctionReturn(0);

370: }
373: /*@
374:    TaoSetDefaultMonitors - Set the default monitors and viewing options available in TAO.
375:    This routine is generally called only in TaoCreate().

377:    Collective on TAO_SOLVER

379:    Input Parameters:
380: .  solver - the TAO_SOLVER solver context

382:    Level: developer

384: .keywords: options, defaults

386: .seealso: TaoCreate(), TaoSetDefaultStatistics(), TaoSetDefaultParameters(), TaoSetMonitor(), TaoView()
387: @*/
388: int TaoSetDefaultMonitors(TAO_SOLVER solver){

390:   TaoFunctionBegin;
391:   solver->numbermonitors     = 0;
392:   solver->viewhessian        = TAO_FALSE;
393:   solver->viewgradient       = TAO_FALSE;
394:   solver->viewjacobian       = TAO_FALSE;
395:   solver->viewvfunc          = TAO_FALSE;
396:   solver->viewtao            = TAO_FALSE;
397:   solver->viewksptao        = TAO_FALSE;

399:   solver->converged          = TaoConverged_Default;
400:   solver->defaultmonitor     = TaoDefaultMonitor;

402:   solver->conv_hist_len      = 0;
403:   solver->conv_hist_max      = 0;
404:   solver->conv_hist          = TAO_NULL;
405:   solver->conv_hist_its      = TAO_NULL;
406:   solver->conv_hist_reset    = TAO_TRUE;

408:   solver->numberdestroyers   =0;

410:   TaoFunctionReturn(0);

412: }

414: /* ----- Routines to initialize and destroy a minimization solver ---- */

418: /*@
419:    TaoSetUp - Sets up the internal data structures for the later use
420:    of a minimization solver.

422:    Collective on TAO_SOLVER

424:    Input Parameters:
425: .  solver - the TAO_SOLVER solver context

427:    Notes:
428:    For basic use of the TAO_SOLVER solvers the user need not explicitly call
429:    TaoSetUp(), since these actions will automatically occur during
430:    the call to TaoSolve().  However, if one wishes to control this
431:    phase separately, TaoSetUp() should be called after TaoCreate()
432:    and optional routines of the form TaoSetXXX(), but before TaoSolve().  

434:    Level: developer

436: .keywords: Solve, setup

438: .seealso: TaoCreate(), TaoSolve(), TaoSetDown(), TaoDestroy()
439: @*/
440: int TaoSetUp(TAO_SOLVER solver)
441: {
442:   int      info;
443:   TaoTruth flag;
444:   TaoVec   *xx,*dx;
445:   TaoFunctionBegin;
446:   TaoValidHeaderSpecific(solver,TAO_COOKIE,1);

448:   //  info = TaoSetOptions(solver);CHKERRQ(info);
449:   if (!solver->set_method_called) {
450:     SETERRQ(1,"Must explicitly call TaoSetMethod() or TaoSetMethodFromOptions() before TaoSolve()");
451:   }

453:   /* Determine if the solver has already been set up with structures of the right dimension */
454:   if ( solver->setupcalled==TAO_TRUE) {
455:     info = TaoGetSolution(solver,&xx);CHKERRQ(info);
456:     if (!xx){SETERRQ(1,"Must explicitly call TaoSetApplication() and Set Variable Vector");}
457:     info = TaoGetStepDirectionVector(solver,&dx);CHKERRQ(info);
458:     if (dx){
459:       info = xx->Compatible(dx,&flag); CHKERRQ(info);
460:     } else {
461:       flag=TAO_FALSE;
462:     }
463:     if (flag==TAO_TRUE){
464:       info = TaoGetGradient(solver,&dx);CHKERRQ(info);
465:       if (dx){
466:         info = xx->Compatible(dx,&flag); CHKERRQ(info);
467:       } 
468:     }
469:     if (flag==TAO_FALSE){  /* Setup done, but data structures of wrong size */
470:       info = TaoSetDown(solver); CHKERRQ(info);
471:     }
472:   }

474:   if ( solver->setupcalled==TAO_FALSE) {
475:     if (solver->setup) {
476:       info = (*solver->setup)(solver,solver->data);CHKERRQ(info);    
477:     }
478:   } 
479:   solver->setupcalled=TAO_TRUE;
480:   info = TaoLineSearchSetUp(solver);CHKERRQ(info);
481:   TaoFunctionReturn(0);
482: }

486: /*@
487:    TaoDestroy - Destroys the TAO solver that was created with TaoCreate().

489:    Collective on TAO_SOLVER

491:    Input Parameter:
492: .  solver - the TAO_SOLVER solver context

494:    Level: beginner

496: .keywords: Destroy

498: .seealso: TaoCreate(), TaoSolve()
499: @*/
500: int TaoDestroy(TAO_SOLVER solver)
501: {
502:   int i,info;

504:   TaoFunctionBegin;
505:   TaoValidHeaderSpecific(solver,TAO_COOKIE,1);
506:   if (--((PetscObject)solver)->refct > 0) TaoFunctionReturn(0);

508:   for (i=0; i< solver->numberdestroyers; i++){
509:     info = (*solver->userdestroy[i])(solver->userctxdestroy[i]); CHKERRQ(info);
510:   }

512:   info = TaoResetSolver(solver);CHKERRQ(info);

514:   info = TaoObjectDestroy(solver); CHKERRQ(info);
515:   
516:   TaoFunctionReturn(0);
517: }

521: /*@
522:    TaoSetDown - Take down the data structures created in TaoSetUp().
523:    These structures typically include the work vectors, and linear solver.

525:    Collective on TAO_SOLVER

527:    Input Parameter:
528: .  solver - the TAO_SOLVER solver context

530:    Level: advanced

532: .keywords: Destroy

534: .seealso: TaoSetUp(), TaoDestroy()
535: @*/
536: int TaoSetDown(TAO_SOLVER solver)
537: {
538:   int info;

540:   TaoFunctionBegin;
541:   TaoValidHeaderSpecific(solver,TAO_COOKIE,1);

543:   if (solver->setupcalled){
544:     if (solver->setdown) {info = (*(solver)->setdown)(solver,solver->data);CHKERRQ(info);}
545:   }
546:   info = TaoSetLagrangianGradientVector(solver,0);CHKERRQ(info);
547:   info = TaoSetStepDirectionVector(solver,0);CHKERRQ(info);
548:   info = TaoSetVariableBounds(solver,0,0);CHKERRQ(info);
549:   solver->ksp = TAO_NULL;
550:   solver->setupcalled=TAO_FALSE;

552:   TaoFunctionReturn(0);
553: }

557: /*@
558:    TaoResetSolver - Take down the data structures created in TaoCreate__XXX().
559:    This routine destroys the line search, and the solver context.  It
560:    also set many of the solver routines for solving, options, duals, viewing,
561:    setup, and destroy to TAO_NULL.

563:    Collective on TAO_SOLVER

565:    Input Parameter:
566: .  solver - the TAO_SOLVER solver context

568:    Level: advanced

570: .keywords: Destroy

572: .seealso: TaoCreate(), TaoSetMethod(), TaoSetDown(), TaoDestroy()
573: @*/
574: int TaoResetSolver(TAO_SOLVER solver)
575: {
576:   int info;

578:   TaoFunctionBegin;
579:   TaoValidHeaderSpecific(solver,TAO_COOKIE,1);

581:   info = TaoSetDown(solver); CHKERRQ(info);
582:   if (solver->data){
583:     info = TaoFree(solver->data);CHKERRQ(info);
584:   }
585:   solver->data = 0;
586:   solver->CopyDuals=0;
587:   solver->solve=0;
588:   solver->data=0;
589:   solver->view=0;
590:   solver->setup=0;
591:   solver->setdown=0;
592:   solver->setfromoptions=0;

594:   info = TaoLineSearchDestroy(solver);CHKERRQ(info);
595:   info = TaoMeritFunctionDestroy(solver);CHKERRQ(info);

597:   /* Set Default Parameters */
598:   info = TaoSetDefaultParameters(solver); CHKERRQ(info);
599:   info = TaoSetDefaultMeritFunction(solver); CHKERRQ(info);

601:   solver->set_method_called  = TAO_FALSE;

603:   TaoFunctionReturn(0);
604: }



608: /* --------- Internal routines for TAO_SOLVER Package --------- */

612: /*@C
613:    TaoSetMethod - Sets the method for the unconstrained minimization solver.  

615:    Collective on TAO_SOLVER

617:    Input Parameters:
618: +  solver - the TAO_SOLVER solver context
619: -  type - a known method

621:    Options Database Key:
622: .  -tao_method <type> - Sets the method; use -help for a list
623:    of available methods (for instance, "-tao_method tao_lmvm" or 
624:    "-tao_method tao_tron")

626:    Available methods include:
627: +    tao_nls - Newton's method with line search for unconstrained minimization
628: .    tao_ntr - Newton's method with trust region for unconstrained minimization
629: .    tao_ntl - Newton's method with trust region, line search for unconstrained minimization
630: .    tao_lmvm - Limited memory variable metric method for unconstrained minimization
631: .    tao_cg - Nonlinear conjugate gradient method for unconstrained minimization
632: .    tao_nm - Nelder-Mead algorithm for derivate-free unconstrained minimization
633: .    tao_tron - Newton Trust Region method for bound constrained minimization
634: .    tao_gpcg - Newton Trust Region method for quadratic bound constrained minimization
635: .    tao_blmvm - Limited memory variable metric method for bound constrained minimization
636: .    tao_kt - Formulate a bound constrained problem as a complementarity problem
637: .    tao_bqpip - Interior point method for quadratic bound constrained minimization
638: .    tao_ssils - Infeasible semismooth method with a linesearch for complementarity problems
639: -    tao_ssfls - Feasible semismooth method with a linesearch for complementarity problems

641:   Level: intermediate

643: .keywords: method, Create, solve

645: .seealso: TaoCreate(), TaoGetMethod()

647: @*/
648: int TaoSetMethod(TAO_SOLVER solver,TaoMethod type)
649: {
650:   int info;
651:   int (*r)(TAO_SOLVER);
652:   TaoTruth issame;

654:   TaoFunctionBegin;
655:   TaoValidHeaderSpecific(solver,TAO_COOKIE,1);

657:   info = TaoCompareMethod(solver,type,&issame);CHKERRQ(info);
658:   if (issame) TaoFunctionReturn(0);
659:   info = TaoResetSolver(solver); CHKERRQ(info);
660:   info = TaoFindSolver(solver,type,&r);CHKERRQ(info);  

662:   if (!r) SETERRQ1(1,"Unable to find requested TAO_SOLVER type %s",type);
663:   info = (*r)(solver);CHKERRQ(info);

665:   solver->set_method_called = TAO_TRUE;

667:   TaoFunctionReturn(0); 
668: }


671: /* --------------------------------------------------------------------- */
674: /*@C
675:   TaoSetTaoDualVariablesRoutine - Set a routine that can be called
676:   to compute the dual variables on the lower and upper bounds of the
677:   variables.

679:    Collective on TAO_SOLVER

681:    Input Parameters:
682: +  tao - the TAO_SOLVER context
683: -  dual - Dual variables routine

685:    Note: The calling sequence of the dual routine passes
686:    the TAO_SOLVER object in the first argument, an (optional)
687:    pointer to a TaoVec to put the duals of the lower bounds,
688:    an (optional) pointer to a TaoVec to put the duals of 
689:    the upper bounds, and the solver context passed to TAO
690:    in TaoSetSolver().

692:    Level: developer

694: .keywords: TAO_SOLVER, duals

696: .seealso: TaoSetTaoSolveRoutine()
697: @*/
698: int TaoSetTaoDualVariablesRoutine(TAO_SOLVER tao, 
699:                                   int (*duals)(TAO_SOLVER,TaoVec*,TaoVec*,void*))
700: {
701:   TaoFunctionBegin;
702:   tao->CopyDuals  = duals;
703:   TaoFunctionReturn(0);
704: }

708: /*@C
709:    TaoSetTaoSolveRoutine - Sets the routine that will solve an optimization application

711:    Collective on TAO_SOLVER

713:    Input Parameters:
714: +  solver - the TAO_SOLVER context
715: .  solve - routine that applies the algorithm
716: -  data - solver data structure (optional)

718:    Level: developer

720:    Note:
721:    This routine is generally used within a "TaoCreate_XXX" routine.
722:    TAO will call this routine as part of the TaoSolve() routine.

724:    Note:
725:    The first and third arguments of this routine will be used as
726:    the arguments of the solver routine provided here.

728: .keywords: TAO_SOLVER, solve

730: .seealso: TaoCreate(), TaoSolve(), TaoGetSolverContext()
731: @*/
732: int TaoSetTaoSolveRoutine(TAO_SOLVER tao, 
733:                           int (*solve)(TAO_SOLVER,void*), void*ctx)
734: {  
735:   TaoFunctionBegin;
736:   tao->solve                  = solve;
737:   tao->data                  = ctx;
738:   TaoFunctionReturn(0);
739: }

743: /*@C
744:    TaoSetTaoSetUpDownRoutines - Sets the routines that setup and destroy solver data structures

746:    Collective on TAO_SOLVER

748:    Input Parameters:
749: +  tao - the TAO_SOLVER context
750: .  setup - routine that creates the work vectors in a solver.
751: -  setdown - the routine that will destroy the work vectors of a solver

753:    Note:
754:    This routine is generally called within a "TaoCreate_XXX" routine.
755:    The routines set here will be called in the TaoSetApplication() and
756:    TaoDestroy() routines, respectively.  Vectors and other data structures
757:    needed by the solver can be created and destroyed within the TaoSolve_XXX()
758:    routine, or before and after this routine.  The advantage to doing it
759:    before and after is that the solver can be called multiple times
760:    without reallocated these structures -- improving efficiency.

762:    Note:
763:    When the 'setup' routine is called, the solution vector, and other
764:    data will be available to clone.
765:    
766:    Note:
767:    When TAO calls these routines, the second arguement will be the
768:    context specified in TaoSetTaoSolveRoutine().

770:    Level: developer

772: .keywords: TAO_SOLVER, setup, destroy

774: .seealso: TaoCreate(), TaoSetUp(), TaoSetDown(), TaoDestroy(), TaoSetTaoSolveRoutine()
775: @*/
776: int TaoSetTaoSetUpDownRoutines(TAO_SOLVER tao, 
777:                                  int (*setup)(TAO_SOLVER,void*),
778:                                  int (*setdown)(TAO_SOLVER,void*))
779: {
780:   TaoFunctionBegin;
781:   tao->setup                  = setup;
782:   tao->setdown                  = setdown;
783:   TaoFunctionReturn(0);
784: }

788: /*@C
789:    TaoSetTaoViewRoutine - Sets the routine that will display information
790:    about the optimization solver

792:    Collective on TAO_SOLVER

794:    Input Parameters:
795: +  tao - the TAO_SOLVER context
796: -  view - routine that views the solver

798:    Note:
799:    This routine is generally used within a "TaoCreate_XXX" routine.
800:    TAO will call this routine as part of the TaoView() routine.

802:    Note:
803:    When TAO calls these routines, the second arguement will be the
804:    context specified in TaoSetTaoSolveRoutine().

806:    Level: developer

808: .keywords: TAO_SOLVER, view

810: .seealso: TaoCreate(), TaoView(), TaoSetTaoSolveRoutine()
811: @*/
812: int TaoSetTaoViewRoutine(TAO_SOLVER tao, 
813:                          int (*view)(TAO_SOLVER,void*))
814: {  
815:   TaoFunctionBegin;
816:   tao->view               = view;
817:   TaoFunctionReturn(0);
818: }

822: /*@C
823:    TaoSetTaoSolveRoutine - Sets the routine that will set the options for
824:    the optimization solver.

826:    Collective on TAO_SOLVER

828:    Input Parameters:
829: +  solver - the TAO_SOLVER context
830: -  options - routine that views the solver

832:    Note:
833:    This routine is generally used within a "TaoCreate_XXX" routine.
834:    TAO will call this routine as part of the TaoSetOptions() routine.

836:    Note:
837:    When TAO calls these routines, the second argument will be the
838:    context specified in TaoSetTaoSolveRoutine().

840:    Level: developer

842: .keywords: TAO_SOLVER, solve

844: .seealso: TaoCreate(), TaoSetOptions(), TaoSetTaoSolveRoutine().
845: @*/
846: int TaoSetTaoOptionsRoutine(TAO_SOLVER tao, 
847:                             int (*options)(TAO_SOLVER,void*))
848: {  
849:   TaoFunctionBegin;
850:   tao->setfromoptions     = options;
851:   TaoFunctionReturn(0);
852: }


857: /*@C
858:    TaoGetApplication - Gets the user defined context for 
859:    the minimization solvers.  

861:    Collective on TAO_SOLVER

863:    Input Parameters:
864: +  tao - the TAO_SOLVER solver context
865: -  taoapp - user application context

867:    Level: advanced

869: .keywords: application, context

871: @*/
872: int TaoGetApplication(TAO_SOLVER tao, TaoApplication **taoapp){
873:   TaoFunctionBegin;
874:   *taoapp=tao->taoappl;
875:   TaoFunctionReturn(0);
876: }



882: /*@C
883:    TaoGetSolverContext - Gets the solver context for 
884:    the minimization solvers.  

886:    Collective on TAO_SOLVER

888:    Input Parameter:
889: +  tao - the TAO_SOLVER solver context
890: -  type - the name of the method

892:    Output Parameter:
893: .  solverctx - solver context IF the type matches.

895:    Level: developer

897: .keywords: application, context

899: .seealso: TaoSetTaoSolveRoutine()

901: @*/
902: int TaoGetSolverContext(TAO_SOLVER tao, TaoMethod type, void **solverctx){
903:   int info;
904:   TaoTruth issame;
905:   TaoFunctionBegin;
906:   if (solverctx){
907:     info = TaoCompareMethod(tao,type,&issame);CHKERRQ(info);
908:     if (issame) *solverctx=tao->data;
909:     else        *solverctx=0;
910:   }
911:   TaoFunctionReturn(0);
912: }