Actual source code: tao_impl.h
1: #ifndef __TAO_IMPL_H
4: #include "tao_solver.h"
6: /*
7: TAO solver context
8: */
9: #define MAX_TAO_MONITORS 5
11: #ifndef MAX_TAO_USER_DESTROY
12: #define MAX_TAO_DESTROY 50
13: #endif
15: struct _p_TAO_SOLVER {
17: TAOHEADER(int);
19: /* ------------------------ User-provided Info -------------------------------*/
21: /* --- Routines and data that are unique to each particular solver ----------- */
22: void *data; /* algorithm implementation-specific data */
24: int (*setup)(TAO_SOLVER,void*); /* routine to set up the nonlinear solver */
25: int (*solve)(TAO_SOLVER,void*); /* a nonlinear optimization solver */
26: int (*setdown)(TAO_SOLVER,void*); /* destroys solver */
28: int (*setfromoptions)(TAO_SOLVER,void*); /* sets options from database */
29: int (*view)(TAO_SOLVER,void*); /* views solver info */
31: TaoTruth setupcalled; /* true if setup has been called */
32: TaoTruth set_method_called; /* flag indicating set_method has been called */
34: /* ------------------------- Function Evaluation ------------------------*/
35: TaoApplication* taoappl;
37: TaoVec* vec_sol; /* pointer to solution */
38: TaoVec* vec_sol_update; /* pointer to solution update */
39: double fc; /* function value */
40: TaoInt nfuncs; /* number of function evaluations */
41: TaoInt max_funcs; /* max number of function evals */
43: /* ------------------------- Gradient Evaluation ------------------------*/
44: TaoVec* vec_grad; /* pointer to gradient */
45: TaoInt ngrads; /* number of gradient evaluations */
46: TaoInt nfgrads; /* number of function/gradient evaluations */
47: TaoTruth viewgradient;
49: /* ------------------------- Hessian Evaluation --------------------------*/
50: TaoMat * hessian; /* Hessian matrix */
51: TaoInt nhesss; /* number of Hessian evaluations */
52: TaoTruth viewhessian;
53: TaoLinearSolver* ksp; /* linear solver context */
54:
55: /* Bound Information */
56: TaoVec* XL; /* lower bound */
57: TaoVec* XU; /* upper bound */
58: double cnorm;
59: double cnorm0;
60: int (*CopyDuals)(TAO_SOLVER,TaoVec*,TaoVec*,void*);
63: /* Constraint information */
64: TaoMat *jacobian;
65: TaoInt njac;
66: TaoTruth viewjacobian;
68: TaoVec* vfunc;
69: TaoVec *RXL, *RXU;
70: TaoMat *CA;
71: TaoInt nvfunc;
72: TaoTruth viewvfunc;
75: /* ------------------------ Line Search Context -------------------------*/
76: /* Line Search termination code and function pointers */
77: void *linectx;
79: TaoInt lsflag; /* Line search termination code (set line=1 on success) */
81: int (*LineSearchSetUp)(TAO_SOLVER,void*);
82: int (*LineSearchSetFromOptions)(TAO_SOLVER,void*);
83: int (*LineSearchApply)(TAO_SOLVER,TaoVec*,TaoVec*,TaoVec*,TaoVec*,double*,double*,double*,TaoInt*,void*);
84: int (*LineSearchView)(TAO_SOLVER,void*);
85: int (*LineSearchDestroy)(TAO_SOLVER,void*);
87: /* Support for a merit function */
88: int (*MeritFunctionApply)(TAO_SOLVER,TaoVec *, double *, void*);
89: int (*MeritFunctionGradientApply)(TAO_SOLVER,TaoVec *, double *, TaoVec *, void*);
90: int (*MeritGradientApply)(TAO_SOLVER,TaoVec *, TaoVec *, void*);
91: int (*MeritFunctionDestroy)(TAO_SOLVER,void*);
92: void *meritctx;
93:
94: /* Trust Region information */
95: double trtol; /* Miminum Trust region radius */
96: double trust0; /* Initial Trust Region Radius */
97: double current_step; /* Current step length for line search */
98: TaoTruth new_search; /* True on first evaluation of new line search */
99: double step; /* last step length or trust region radius */
101: /* -------------------------- Monitoring ------------------------------------*/
103: TaoInt numbermonitors; /* number of monitors */
104: int (*defaultmonitor)(TAO_SOLVER,void*); /* default monitor routine */
105: int (*monitor[MAX_TAO_MONITORS])(TAO_SOLVER,void*); /* monitor routine */
106: void *monitorcontext[MAX_TAO_MONITORS]; /* monitor context */
107: int (*converged)(TAO_SOLVER,void*); /* convergence routine */
109: /* -------------------------- Parameters -------------------------------------- */
111: double fatol; /* Absolute tolerance for objective value */
112: double frtol; /* Relative tolerance for objective value */
113: double catol; /* Absolute tolerance for constraints */
114: double crtol; /* Relative tolerance for constraints */
115: double gatol; /* Absolute tolerance for gradient */
116: double grtol; /* Relative tolerance for gradient */
117: double gttol; /* Relative tolerance for gradient */
118: double xtol; /* relative tolerance in solution */
119: double fmin; /* minimum tolerance for function value */
121: /* -------------------------- Statistics -------------------------------------- */
122: TaoInt max_its; /* max number of iterations */
123: TaoInt iter; /* global iteration number */
124: TaoTerminateReason reason;
126: double norm; /* KKT residual norm of current iterate */
127: double norm0; /* KKT residual norm of residual iterate */
128: int linear_its; /* total number of linear solver iterations */
130: /* ------------------------- Convergence History ------------------------ */
132: void *cnvP; /* convergence context */
133: double *conv_hist; /* If !0, stores function norm (or
134: gradient norm) at each iteration */
135: TaoInt *conv_hist_its; /* linear iterations for each Newton step */
136: TaoInt conv_hist_len; /* size of convergence history array */
137: TaoInt conv_hist_max; /* actual amount of data in conv_history */
138: TaoTruth conv_hist_reset; /* reset counter for each new TAO_SOLVER solve */
140: TaoTruth viewtao;
141: TaoTruth viewksptao;
143: /* Routines called when destroying this structure */
144: TaoInt numberdestroyers;
145: int (*userdestroy[MAX_TAO_DESTROY])(void*);
146: void *userctxdestroy[MAX_TAO_DESTROY];
149: /* ------------------------ Default Work-area Management ---------------------- */
151: TaoVec* WorkX1;
152: };
154: #define TaoLogConvHistory(tao_um,res,its) \
155: { if (tao_um->conv_hist && tao_um->conv_hist_max > tao_um->conv_hist_len) \
156: { tao_um->conv_hist[tao_um->conv_hist_len] = res; \
157: tao_um->conv_hist_its[tao_um->conv_hist_len++] = its; \
158: }}
161: #endif