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 (*MeritFunctionGTSApply)(TAO_SOLVER,TaoVec *, TaoVec *, double *, double *,void*);
92: int (*MeritFunctionDestroy)(TAO_SOLVER,void*);
93: void *meritctx;
94:
95: /* Trust Region information */
96: double trtol; /* Miminum Trust region radius */
97: double trust0; /* Initial Trust Region Radius */
98: double current_step; /* Current step length for line search */
99: TaoTruth new_search; /* True on first evaluation of new line search */
100: double step; /* last step length or trust region radius */
102: /* -------------------------- Monitoring ------------------------------------*/
104: TaoInt numbermonitors; /* number of monitors */
105: int (*defaultmonitor)(TAO_SOLVER,void*); /* default monitor routine */
106: int (*monitor[MAX_TAO_MONITORS])(TAO_SOLVER,void*); /* monitor routine */
107: void *monitorcontext[MAX_TAO_MONITORS]; /* monitor context */
108: int (*converged)(TAO_SOLVER,void*); /* convergence routine */
110: /* -------------------------- Parameters -------------------------------------- */
112: double fatol; /* Absolute tolerance for objective value */
113: double frtol; /* Relative tolerance for objective value */
114: double catol; /* Absolute tolerance for constraints */
115: double crtol; /* Relative tolerance for constraints */
116: double gatol; /* Absolute tolerance for gradient */
117: double grtol; /* Relative tolerance for gradient */
118: double gttol; /* Relative tolerance for gradient */
119: double xtol; /* relative tolerance in solution */
120: double fmin; /* minimum tolerance for function value */
122: /* -------------------------- Statistics -------------------------------------- */
123: TaoInt max_its; /* max number of iterations */
124: TaoInt iter; /* global iteration number */
125: TaoTerminateReason reason;
127: double norm; /* KKT residual norm of current iterate */
128: double norm0; /* KKT residual norm of residual iterate */
129: int linear_its; /* total number of linear solver iterations */
131: /* ------------------------- Convergence History ------------------------ */
133: void *cnvP; /* convergence context */
134: double *conv_hist; /* If !0, stores function norm (or
135: gradient norm) at each iteration */
136: TaoInt *conv_hist_its; /* linear iterations for each Newton step */
137: TaoInt conv_hist_len; /* size of convergence history array */
138: TaoInt conv_hist_max; /* actual amount of data in conv_history */
139: TaoTruth conv_hist_reset; /* reset counter for each new TAO_SOLVER solve */
141: TaoTruth viewtao;
142: TaoTruth viewksptao;
144: /* Routines called when destroying this structure */
145: TaoInt numberdestroyers;
146: int (*userdestroy[MAX_TAO_DESTROY])(void*);
147: void *userctxdestroy[MAX_TAO_DESTROY];
150: /* ------------------------ Default Work-area Management ---------------------- */
152: TaoVec* WorkX1;
153: };
155: #define TaoLogConvHistory(tao_um,res,its) \
156: { if (tao_um->conv_hist && tao_um->conv_hist_max > tao_um->conv_hist_len) \
157: { tao_um->conv_hist[tao_um->conv_hist_len] = res; \
158: tao_um->conv_hist_its[tao_um->conv_hist_len++] = its; \
159: }}
162: #endif