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);
95:
96: info = TaoOptionString("-tao_method","TaoMethod","TaoSetMethod","",type,256, &flg);CHKERRQ(info);
97: if (flg) {
98: info = TaoSetMethod(solver,(TaoMethod) type);CHKERRQ(info);
99: }
100: /* if (!((PetscObject)solver)->type_name) {
101: info = TaoSetMethod(solver,"tao_lmvm");CHKERRQ(info);
102: }*/
104: if (solver->setfromoptions) {
105: info = (*solver->setfromoptions)(solver,solver->data); CHKERRQ(info);
106: }
109: info = TaoOptionName("-tao_view","view TAO_SOLVER info after each minimization has completed","TaoView",&flg);CHKERRQ(info);
110: if (flg) solver->viewtao = TAO_TRUE;
111: info = TaoOptionName("-tao_kspview","view the Linear Solver used by the solver after minimization has completed","TaoViewLinearSolver",&flg);CHKERRQ(info);
112: if (flg) solver->viewksptao = TAO_TRUE;
113:
114: info = TaoOptionDouble("-tao_fatol","Stop if solution within","TaoSetTolerances",solver->fatol,&solver->fatol,&flg);CHKERRQ(info);
115: info = TaoOptionDouble("-tao_frtol","Stop if relative solution within","TaoSetTolerances",solver->frtol,&solver->frtol,&flg);CHKERRQ(info);
116: info = TaoOptionDouble("-tao_catol","Stop if constraints violations within","TaoSetTolerances",solver->catol,&solver->catol,&flg);CHKERRQ(info);
117: info = TaoOptionDouble("-tao_crtol","Stop if relative contraint violations within","TaoSetTolerances",solver->crtol,&solver->crtol,&flg);CHKERRQ(info);
118: info = TaoOptionDouble("-tao_gatol","Stop if norm of gradient less than","TaoSetGradientTolerances",solver->gatol,&solver->gatol,&flg);CHKERRQ(info);
119: 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);
120: 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);
121: info = TaoOptionInt("-tao_max_its","Stop if iteration number exceeds",
122: "TaoSetMaximumIterates",solver->max_its,&solver->max_its,
123: &flg);CHKERRQ(info);
124: info = TaoOptionInt("-tao_max_funcs","Stop if number of function evaluations exceeds","TaoSetMaximumFunctionEvaluations",solver->max_funcs,&solver->max_funcs,&flg);
125: info = TaoOptionDouble("-tao_fmin","Stop if function less than","TaoSetFunctionLowerBound",solver->fmin,&solver->fmin,&flg);
126: info = TaoOptionDouble("-tao_steptol","Stop if step size or trust region radius less than","TaoSetTrustRegionRadius",solver->trtol,&solver->trtol,&flg);CHKERRQ(info);
127: info = TaoOptionDouble("-tao_trust0","Initial trust region radius","TaoSetTrustRegionRadius",solver->trust0,&solver->trust0,&flg);CHKERRQ(info);
129: /*
130: info = (*PetscHelpPrintf)(solver->comm," TAO_SOLVER Monitoring Options: Choose any of the following\n");CHKERRQ(info);
131: */
133: info = TaoOptionName("-tao_unitstep","Always use unit step length","TaoCreateUnitLineSearch",&flg);
134: if (flg){info=TaoCreateUnitLineSearch(solver);CHKERRQ(info);}
135: info = TaoOptionName("-tao_lmvmh","User supplies approximate hessian for LMVM solvers","TaoLMVMSetH0",&flg);
136: if (flg){info=TaoBLMVMSetH0(solver,TAO_TRUE);CHKERRQ(info);info=TaoLMVMSetH0(solver,TAO_TRUE);CHKERRQ(info);}
137:
138: info = TaoOptionName("-tao_view_hessian","view Hessian after each evaluation","None",&flg);CHKERRQ(info);
139: if (flg) solver->viewhessian = TAO_TRUE;
140: info = TaoOptionName("-tao_view_gradient","view gradient after each evaluation","None",&flg);CHKERRQ(info);
141: if (flg) solver->viewgradient = TAO_TRUE;
142: info = TaoOptionName("-tao_view_jacobian","view jacobian after each evaluation","None",&flg);CHKERRQ(info);
143: if (flg) solver->viewjacobian = TAO_TRUE;
144: info = TaoOptionName("-tao_view_constraints","view constraint function after each evaluation","None",&flg);CHKERRQ(info);
145: if (flg) solver->viewvfunc = TAO_TRUE;
147: info = TaoOptionName("-tao_cancelmonitors","cancel all monitors hardwired in code","TaoClearMonitor",&flg);CHKERRQ(info);
148: if (flg) {info = TaoClearMonitor(solver);CHKERRQ(info);}
149: info = TaoOptionName("-tao_monitor","Use the default convergence monitor","TaoSetMonitor",&flg);CHKERRQ(info);
150: if (flg && solver->defaultmonitor) {
151: info = TaoSetMonitor(solver,solver->defaultmonitor,TAO_NULL);CHKERRQ(info);
152: }
153: info = TaoOptionName("-tao_smonitor","Use short monitor","None",&flg);CHKERRQ(info);
154: if (flg) {info = TaoSetMonitor(solver,TaoDefaultSMonitor,TAO_NULL);CHKERRQ(info);}
155: info = TaoOptionName("-tao_vecmonitor","Plot solution vector at each iteration","TaoVecViewMonitor",&flg);CHKERRQ(info);
156: if (flg) {info = TaoSetMonitor(solver,TaoVecViewMonitor,TAO_NULL);CHKERRQ(info);}
157: info = TaoOptionName("-tao_vecmonitor_update","plots step direction at each iteration","TaoVecViewMonitorUpdate",&flg);CHKERRQ(info);
158: if (flg) {info = TaoSetMonitor(solver,TaoVecViewMonitorUpdate,TAO_NULL);CHKERRQ(info);}
161: // info = PetscOptionsEnd();CHKERRQ(info);
163: // info = TaoSetLinearSolverOptions(solver);CHKERRQ(info);
165: TaoFunctionReturn(0);
166: }
169: /* -----------------------------------------------------------*/
172: /*
173: TaoCreateFull - Creates a TAO_SOLVER context.
175: Collective on MPI_Comm
177: Input Parameters:
178: + method - A TAO method.
179: . prefix - a prefix to prepend to all option names (usually TAO_NULL)
180: - comm - MPI communicator
182: Output Parameter:
183: . newsolver - the new TAO_SOLVER context
185: Options Database Keys:
186: . -tao_method - select which method TAO should use
188: Level: developer
190: .keywords: Create, solver, method, context
192: .seealso: TaoCreate(), TaoSolve(), TaoSetMethod(), TaoDestroy()
193: */
194: int TaoCreateFull(TaoMethod method, const char* prefix, MPI_Comm comm, TAO_SOLVER *newsolver)
195: {
196: TAO_SOLVER solver;
197: int info;
199: TaoFunctionBegin;
201: *newsolver = 0;
203: info = TaoInitialize(0,0,0,0);CHKERRQ(info);CHKERRQ(info);
205: info = TaoObjectCreate(newsolver,comm);CHKERRQ(info);
206: solver=*newsolver;
208: // info = TaoSetOptionsPrefix(solver,prefix);CHKERRQ(info);
210: solver->vec_sol=0;
211: solver->hessian=0;
212: solver->vfunc=0;
213: solver->jacobian=0;
214: solver->RXL=0;
215: solver->RXU=0;
216: solver->CA=0;
218: info = TaoResetSolver(solver); CHKERRQ(info); /* Set some pointers to NULL */
219: info = TaoSetDefaultParameters(solver);CHKERRQ(info);
220: info = TaoSetDefaultStatistics(solver);CHKERRQ(info);
221: info = TaoSetDefaultMonitors(solver);CHKERRQ(info);
223: *newsolver = solver;
224: if (method) {
225: info=TaoSetMethod(solver,method);CHKERRQ(info);
226: }
228: TaoFunctionReturn(0);
229: }
232: /* -----------------------------------------------------------*/
235: /*@C
236: TaoCreate - Creates a TAO_SOLVER context.
238: Collective on MPI_Comm
240: Input Parameters:
241: + comm - MPI communicator
242: - method - A TAO method.
244: Output Parameter:
245: . newsolver - the new TAO_SOLVER context
247: Options Database Keys:
248: . -tao_method - select which method TAO should use
250: Available methods include:
251: + tao_nls - Newton's method with line search for unconstrained minimization
252: . tao_ntr - Newton's method with trust region for unconstrained minimization
253: . tao_ntl - Newton's method with trust region, line search for unconstrained minimization
254: . tao_lmvm - Limited memory variable metric method for unconstrained minimization
255: . tao_cg - Nonlinear conjugate gradient method for unconstrained minimization
256: . tao_nm - Nelder-Mead algorithm for derivate-free unconstrained minimization
257: . tao_tron - Newton Trust Region method for bound constrained minimization
258: . tao_gpcg - Newton Trust Region method for quadratic bound constrained minimization
259: . tao_blmvm - Limited memory variable metric method for bound constrained minimization
260: . tao_kt - Formulate a bound constrained problem as a complementarity problem
261: . tao_bqpip - Interior point method for quadratic bound constrained minimization
262: . tao_ssils - Infeasible semismooth method with a linesearch for complementarity problems
263: - tao_ssfls - Feasible semismooth method with a linesearch for complementarity problems
265: Level: beginner
267: Note:
268: If the second argument specifies a TaoMethod, quotation marks should
269: surround the method.
271: Note:
272: The TaoMethod can be TAO_NULL (C/C++) or
273: TAO_NULL_CHARACTER (Fortran), in which case the
274: method will be specified by the runtime option -tao_method
276: If a particular optimization method is specified at runtime by
277: the option '-tao_method', this choice will be used instead of
278: any default that may have been specified as the input parameter
279: "method" to this routine.
281: .keywords: Create, solver, method, context
283: .seealso: TaoSolve(), TaoSetMethod(), TaoSetApplication(), TaoDestroy()
284: @*/
285: int TaoCreate(MPI_Comm comm, TaoMethod method, TAO_SOLVER *newsolver)
286: {
287: int info;
289: TaoFunctionBegin;
291: *newsolver = 0;
293: info = TaoCreateFull(method,0,comm,newsolver);CHKERRQ(info);
294: info = TaoSetMethodFromOptions(*newsolver);CHKERRQ(info);
296: TaoFunctionReturn(0);
297: }
301: /* ----- Routines to initialize and destroy a minimization solver ---- */
305: /*@
306: TaoSetDefaultParameters - Set the parameters used by all TAO solvers to a default value. These
307: parameter include convergence tolerances. This routine is called before setting the
308: method used by TAO
310: Collective on TAO_SOLVER
312: Input Parameters:
313: . solver - the TAO_SOLVER solver context
315: Level: developer
317: .keywords: options, defaults
319: .seealso: TaoCreate(), TaoSetDefaultStatistics(), TaoSetDefaultMonitors()
320: @*/
321: int TaoSetDefaultParameters(TAO_SOLVER solver){
323: TaoFunctionBegin;
324: solver->max_its = 0;
325: solver->max_funcs = 100000000;
326: solver->fatol = 0.0;
327: solver->frtol = 0.0;
328: solver->catol = 0.0;
329: solver->crtol = 0.0;
330: solver->gatol = 0.0;
331: solver->grtol = 0.0;
332: solver->xtol = 0.0;
333: solver->trtol = 0.0;
334: solver->fmin = -1.e30;
335: TaoFunctionReturn(0);
336: }
340: /*@
341: TaoSetDefaultStatistics - Initialize the statistics used by TAO for all of the solvers.
342: These statistics include the iteration number, residual norms, and convergence status.
343: This routine gets called before solving each optimization problem.
345: Collective on TAO_SOLVER
347: Input Parameters:
348: . solver - the TAO_SOLVER solver context
350: Level: developer
352: .keywords: options, defaults
354: .seealso: TaoCreate(), TaoSetDefaultParameters(), TaoSetDefaultMonitors(), TaoSolve()
355: @*/
356: int TaoSetDefaultStatistics(TAO_SOLVER solver){
358: TaoFunctionBegin;
359: solver->iter = 0;
360: solver->fc = 0;
361: solver->norm = 0.0;
362: solver->norm0 = 0.0;
363: solver->cnorm = 0.0;
364: solver->cnorm0 = 0.0;
365: solver->nfuncs = 0;
366: solver->ngrads = 0;
367: solver->nfgrads = 0;
368: solver->nhesss = 0;
369: solver->nvfunc = 0;
370: solver->njac = 0;
371: solver->linear_its = 0;
372: solver->lsflag = 0;
373: solver->reason = TAO_CONTINUE_ITERATING;
374: solver->step = 1.0e+30;
375: if (solver->conv_hist_reset == TAO_TRUE) solver->conv_hist_len = 0;
376: TaoFunctionReturn(0);
378: }
381: /*@
382: TaoSetDefaultMonitors - Set the default monitors and viewing options available in TAO.
383: This routine is generally called only in TaoCreate().
385: Collective on TAO_SOLVER
387: Input Parameters:
388: . solver - the TAO_SOLVER solver context
390: Level: developer
392: .keywords: options, defaults
394: .seealso: TaoCreate(), TaoSetDefaultStatistics(), TaoSetDefaultParameters(), TaoSetMonitor(), TaoView()
395: @*/
396: int TaoSetDefaultMonitors(TAO_SOLVER solver){
398: TaoFunctionBegin;
399: solver->numbermonitors = 0;
400: solver->viewhessian = TAO_FALSE;
401: solver->viewgradient = TAO_FALSE;
402: solver->viewjacobian = TAO_FALSE;
403: solver->viewvfunc = TAO_FALSE;
404: solver->viewtao = TAO_FALSE;
405: solver->viewksptao = TAO_FALSE;
407: solver->converged = TaoConverged_Default;
408: solver->defaultmonitor = TaoDefaultMonitor;
410: solver->conv_hist_len = 0;
411: solver->conv_hist_max = 0;
412: solver->conv_hist = TAO_NULL;
413: solver->conv_hist_its = TAO_NULL;
414: solver->conv_hist_reset = TAO_TRUE;
416: solver->numberdestroyers =0;
418: TaoFunctionReturn(0);
420: }
422: /* ----- Routines to initialize and destroy a minimization solver ---- */
426: /*@
427: TaoSetUp - Sets up the internal data structures for the later use
428: of a minimization solver.
430: Collective on TAO_SOLVER
432: Input Parameters:
433: . solver - the TAO_SOLVER solver context
435: Notes:
436: For basic use of the TAO_SOLVER solvers the user need not explicitly call
437: TaoSetUp(), since these actions will automatically occur during
438: the call to TaoSolve(). However, if one wishes to control this
439: phase separately, TaoSetUp() should be called after TaoCreate()
440: and optional routines of the form TaoSetXXX(), but before TaoSolve().
442: Level: developer
444: .keywords: Solve, setup
446: .seealso: TaoCreate(), TaoSolve(), TaoSetDown(), TaoDestroy()
447: @*/
448: int TaoSetUp(TAO_SOLVER solver)
449: {
450: int info;
451: TaoTruth flag;
452: TaoVec *xx,*dx;
453: TaoFunctionBegin;
454: TaoValidHeaderSpecific(solver,TAO_COOKIE,1);
456: // info = TaoSetOptions(solver);CHKERRQ(info);
457: if (!solver->set_method_called) {
458: SETERRQ(1,"Must explicitly call TaoSetMethod() or TaoSetMethodFromOptions() before TaoSolve()");
459: }
461: /* Determine if the solver has already been set up with structures of the right dimension */
462: if ( solver->setupcalled==TAO_TRUE) {
463: info = TaoGetSolution(solver,&xx);CHKERRQ(info);
464: if (!xx){SETERRQ(1,"Must explicitly call TaoSetApplication() and Set Variable Vector");}
465: info = TaoGetStepDirectionVector(solver,&dx);CHKERRQ(info);
466: if (dx){
467: info = xx->Compatible(dx,&flag); CHKERRQ(info);
468: } else {
469: flag=TAO_FALSE;
470: }
471: if (flag==TAO_TRUE){
472: info = TaoGetGradient(solver,&dx);CHKERRQ(info);
473: if (dx){
474: info = xx->Compatible(dx,&flag); CHKERRQ(info);
475: }
476: }
477: if (flag==TAO_FALSE){ /* Setup done, but data structures of wrong size */
478: info = TaoSetDown(solver); CHKERRQ(info);
479: }
480: }
482: if ( solver->setupcalled==TAO_FALSE) {
483: if (solver->setup) {
484: info = (*solver->setup)(solver,solver->data);CHKERRQ(info);
485: }
486: }
487: solver->setupcalled=TAO_TRUE;
488: info = TaoLineSearchSetUp(solver);CHKERRQ(info);
489: TaoFunctionReturn(0);
490: }
494: /*@
495: TaoDestroy - Destroys the TAO solver that was created with TaoCreate().
497: Collective on TAO_SOLVER
499: Input Parameter:
500: . solver - the TAO_SOLVER solver context
502: Level: beginner
504: .keywords: Destroy
506: .seealso: TaoCreate(), TaoSolve()
507: @*/
508: int TaoDestroy(TAO_SOLVER solver)
509: {
510: int i,info;
512: TaoFunctionBegin;
513: TaoValidHeaderSpecific(solver,TAO_COOKIE,1);
514: if (--((PetscObject)solver)->refct > 0) TaoFunctionReturn(0);
516: for (i=0; i< solver->numberdestroyers; i++){
517: info = (*solver->userdestroy[i])(solver->userctxdestroy[i]); CHKERRQ(info);
518: }
520: info = TaoResetSolver(solver);CHKERRQ(info);
522: info = TaoObjectDestroy(solver); CHKERRQ(info);
523:
524: TaoFunctionReturn(0);
525: }
529: /*@
530: TaoSetDown - Take down the data structures created in TaoSetUp().
531: These structures typically include the work vectors, and linear solver.
533: Collective on TAO_SOLVER
535: Input Parameter:
536: . solver - the TAO_SOLVER solver context
538: Level: advanced
540: .keywords: Destroy
542: .seealso: TaoSetUp(), TaoDestroy()
543: @*/
544: int TaoSetDown(TAO_SOLVER solver)
545: {
546: int info;
548: TaoFunctionBegin;
549: TaoValidHeaderSpecific(solver,TAO_COOKIE,1);
551: if (solver->setupcalled){
552: if (solver->setdown) {info = (*(solver)->setdown)(solver,solver->data);CHKERRQ(info);}
553: }
554: info = TaoSetLagrangianGradientVector(solver,0);CHKERRQ(info);
555: info = TaoSetStepDirectionVector(solver,0);CHKERRQ(info);
556: info = TaoSetVariableBounds(solver,0,0);CHKERRQ(info);
557: solver->ksp = TAO_NULL;
558: solver->setupcalled=TAO_FALSE;
560: TaoFunctionReturn(0);
561: }
565: /*@
566: TaoResetSolver - Take down the data structures created in TaoCreate__XXX().
567: This routine destroys the line search, and the solver context. It
568: also set many of the solver routines for solving, options, duals, viewing,
569: setup, and destroy to TAO_NULL.
571: Collective on TAO_SOLVER
573: Input Parameter:
574: . solver - the TAO_SOLVER solver context
576: Level: advanced
578: .keywords: Destroy
580: .seealso: TaoCreate(), TaoSetMethod(), TaoSetDown(), TaoDestroy()
581: @*/
582: int TaoResetSolver(TAO_SOLVER solver)
583: {
584: int info;
586: TaoFunctionBegin;
587: TaoValidHeaderSpecific(solver,TAO_COOKIE,1);
589: info = TaoSetDown(solver); CHKERRQ(info);
590: if (solver->data){
591: info = TaoFree(solver->data);CHKERRQ(info);
592: }
593: solver->data = 0;
594: solver->CopyDuals=0;
595: solver->solve=0;
596: solver->data=0;
597: solver->view=0;
598: solver->setup=0;
599: solver->setdown=0;
600: solver->setfromoptions=0;
602: info = TaoLineSearchDestroy(solver);CHKERRQ(info);
603: info = TaoMeritFunctionDestroy(solver);CHKERRQ(info);
605: /* Set Default Parameters */
606: info = TaoSetDefaultParameters(solver); CHKERRQ(info);
607: info = TaoSetDefaultMeritFunction(solver); CHKERRQ(info);
609: solver->set_method_called = TAO_FALSE;
611: TaoFunctionReturn(0);
612: }
616: /* --------- Internal routines for TAO_SOLVER Package --------- */
620: /*@C
621: TaoSetMethod - Sets the method for the unconstrained minimization solver.
623: Collective on TAO_SOLVER
625: Input Parameters:
626: + solver - the TAO_SOLVER solver context
627: - type - a known method
629: Options Database Key:
630: . -tao_method <type> - Sets the method; use -help for a list
631: of available methods (for instance, "-tao_method tao_lmvm" or
632: "-tao_method tao_tron")
634: Available methods include:
635: + tao_nls - Newton's method with line search for unconstrained minimization
636: . tao_ntr - Newton's method with trust region for unconstrained minimization
637: . tao_ntl - Newton's method with trust region, line search for unconstrained minimization
638: . tao_lmvm - Limited memory variable metric method for unconstrained minimization
639: . tao_cg - Nonlinear conjugate gradient method for unconstrained minimization
640: . tao_nm - Nelder-Mead algorithm for derivate-free unconstrained minimization
641: . tao_tron - Newton Trust Region method for bound constrained minimization
642: . tao_gpcg - Newton Trust Region method for quadratic bound constrained minimization
643: . tao_blmvm - Limited memory variable metric method for bound constrained minimization
644: . tao_kt - Formulate a bound constrained problem as a complementarity problem
645: . tao_bqpip - Interior point method for quadratic bound constrained minimization
646: . tao_ssils - Infeasible semismooth method with a linesearch for complementarity problems
647: - tao_ssfls - Feasible semismooth method with a linesearch for complementarity problems
649: Level: intermediate
651: .keywords: method, Create, solve
653: .seealso: TaoCreate(), TaoGetMethod()
655: @*/
656: int TaoSetMethod(TAO_SOLVER solver,TaoMethod type)
657: {
658: int info;
659: int (*r)(TAO_SOLVER);
660: TaoTruth issame;
662: TaoFunctionBegin;
663: TaoValidHeaderSpecific(solver,TAO_COOKIE,1);
665: info = TaoCompareMethod(solver,type,&issame);CHKERRQ(info);
666: if (issame) TaoFunctionReturn(0);
667: info = TaoResetSolver(solver); CHKERRQ(info);
668: info = TaoFindSolver(solver,type,&r);CHKERRQ(info);
670: if (!r) SETERRQ1(1,"Unable to find requested TAO_SOLVER type %s",type);
671: info = (*r)(solver);CHKERRQ(info);
673: solver->set_method_called = TAO_TRUE;
675: TaoFunctionReturn(0);
676: }
679: /* --------------------------------------------------------------------- */
682: /*@C
683: TaoSetTaoDualVariablesRoutine - Set a routine that can be called
684: to compute the dual variables on the lower and upper bounds of the
685: variables.
687: Collective on TAO_SOLVER
689: Input Parameters:
690: + tao - the TAO_SOLVER context
691: - dual - Dual variables routine
693: Note: The calling sequence of the dual routine passes
694: the TAO_SOLVER object in the first argument, an (optional)
695: pointer to a TaoVec to put the duals of the lower bounds,
696: an (optional) pointer to a TaoVec to put the duals of
697: the upper bounds, and the solver context passed to TAO
698: in TaoSetSolver().
700: Level: developer
702: .keywords: TAO_SOLVER, duals
704: .seealso: TaoSetTaoSolveRoutine()
705: @*/
706: int TaoSetTaoDualVariablesRoutine(TAO_SOLVER tao,
707: int (*duals)(TAO_SOLVER,TaoVec*,TaoVec*,void*))
708: {
709: TaoFunctionBegin;
710: tao->CopyDuals = duals;
711: TaoFunctionReturn(0);
712: }
716: /*@C
717: TaoSetTaoSolveRoutine - Sets the routine that will solve an optimization application
719: Collective on TAO_SOLVER
721: Input Parameters:
722: + solver - the TAO_SOLVER context
723: . solve - routine that applies the algorithm
724: - data - solver data structure (optional)
726: Level: developer
728: Note:
729: This routine is generally used within a "TaoCreate_XXX" routine.
730: TAO will call this routine as part of the TaoSolve() routine.
732: Note:
733: The first and third arguments of this routine will be used as
734: the arguments of the solver routine provided here.
736: .keywords: TAO_SOLVER, solve
738: .seealso: TaoCreate(), TaoSolve(), TaoGetSolverContext()
739: @*/
740: int TaoSetTaoSolveRoutine(TAO_SOLVER tao,
741: int (*solve)(TAO_SOLVER,void*), void*ctx)
742: {
743: TaoFunctionBegin;
744: tao->solve = solve;
745: tao->data = ctx;
746: TaoFunctionReturn(0);
747: }
751: /*@C
752: TaoSetTaoSetUpDownRoutines - Sets the routines that setup and destroy solver data structures
754: Collective on TAO_SOLVER
756: Input Parameters:
757: + tao - the TAO_SOLVER context
758: . setup - routine that creates the work vectors in a solver.
759: - setdown - the routine that will destroy the work vectors of a solver
761: Note:
762: This routine is generally called within a "TaoCreate_XXX" routine.
763: The routines set here will be called in the TaoSetApplication() and
764: TaoDestroy() routines, respectively. Vectors and other data structures
765: needed by the solver can be created and destroyed within the TaoSolve_XXX()
766: routine, or before and after this routine. The advantage to doing it
767: before and after is that the solver can be called multiple times
768: without reallocated these structures -- improving efficiency.
770: Note:
771: When the 'setup' routine is called, the solution vector, and other
772: data will be available to clone.
773:
774: Note:
775: When TAO calls these routines, the second arguement will be the
776: context specified in TaoSetTaoSolveRoutine().
778: Level: developer
780: .keywords: TAO_SOLVER, setup, destroy
782: .seealso: TaoCreate(), TaoSetUp(), TaoSetDown(), TaoDestroy(), TaoSetTaoSolveRoutine()
783: @*/
784: int TaoSetTaoSetUpDownRoutines(TAO_SOLVER tao,
785: int (*setup)(TAO_SOLVER,void*),
786: int (*setdown)(TAO_SOLVER,void*))
787: {
788: TaoFunctionBegin;
789: tao->setup = setup;
790: tao->setdown = setdown;
791: TaoFunctionReturn(0);
792: }
796: /*@C
797: TaoSetTaoViewRoutine - Sets the routine that will display information
798: about the optimization solver
800: Collective on TAO_SOLVER
802: Input Parameters:
803: + tao - the TAO_SOLVER context
804: - view - routine that views the solver
806: Note:
807: This routine is generally used within a "TaoCreate_XXX" routine.
808: TAO will call this routine as part of the TaoView() routine.
810: Note:
811: When TAO calls these routines, the second arguement will be the
812: context specified in TaoSetTaoSolveRoutine().
814: Level: developer
816: .keywords: TAO_SOLVER, view
818: .seealso: TaoCreate(), TaoView(), TaoSetTaoSolveRoutine()
819: @*/
820: int TaoSetTaoViewRoutine(TAO_SOLVER tao,
821: int (*view)(TAO_SOLVER,void*))
822: {
823: TaoFunctionBegin;
824: tao->view = view;
825: TaoFunctionReturn(0);
826: }
830: /*@C
831: TaoSetTaoSolveRoutine - Sets the routine that will set the options for
832: the optimization solver.
834: Collective on TAO_SOLVER
836: Input Parameters:
837: + solver - the TAO_SOLVER context
838: - options - routine that views the solver
840: Note:
841: This routine is generally used within a "TaoCreate_XXX" routine.
842: TAO will call this routine as part of the TaoSetOptions() routine.
844: Note:
845: When TAO calls these routines, the second argument will be the
846: context specified in TaoSetTaoSolveRoutine().
848: Level: developer
850: .keywords: TAO_SOLVER, solve
852: .seealso: TaoCreate(), TaoSetOptions(), TaoSetTaoSolveRoutine().
853: @*/
854: int TaoSetTaoOptionsRoutine(TAO_SOLVER tao,
855: int (*options)(TAO_SOLVER,void*))
856: {
857: TaoFunctionBegin;
858: tao->setfromoptions = options;
859: TaoFunctionReturn(0);
860: }
865: /*@C
866: TaoGetApplication - Gets the user defined context for
867: the minimization solvers.
869: Collective on TAO_SOLVER
871: Input Parameters:
872: + tao - the TAO_SOLVER solver context
873: - taoapp - user application context
875: Level: advanced
877: .keywords: application, context
879: @*/
880: int TaoGetApplication(TAO_SOLVER tao, TaoApplication **taoapp){
881: TaoFunctionBegin;
882: *taoapp=tao->taoappl;
883: TaoFunctionReturn(0);
884: }
890: /*@C
891: TaoGetSolverContext - Gets the solver context for
892: the minimization solvers.
894: Collective on TAO_SOLVER
896: Input Parameter:
897: + tao - the TAO_SOLVER solver context
898: - type - the name of the method
900: Output Parameter:
901: . solverctx - solver context IF the type matches.
903: Level: developer
905: .keywords: application, context
907: .seealso: TaoSetTaoSolveRoutine()
909: @*/
910: int TaoGetSolverContext(TAO_SOLVER tao, TaoMethod type, void **solverctx){
911: int info;
912: TaoTruth issame;
913: TaoFunctionBegin;
914: if (solverctx){
915: info = TaoCompareMethod(tao,type,&issame);CHKERRQ(info);
916: if (issame) *solverctx=tao->data;
917: else *solverctx=0;
918: }
919: TaoFunctionReturn(0);
920: }