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: int nfuncs; /* number of function evaluations */
41: int max_funcs; /* max number of function evals */
43: /* ------------------------- Gradient Evaluation ------------------------*/
44: TaoVec* vec_grad; /* pointer to gradient */
45: int ngrads; /* number of gradient evaluations */
46: int nfgrads; /* number of function/gradient evaluations */
47: TaoTruth viewgradient;
49: /* ------------------------- Hessian Evaluation --------------------------*/
50: TaoMat * hessian; /* Hessian matrix */
51: int 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: int njac;
66: TaoTruth viewjacobian;
68: TaoVec* vfunc;
69: TaoVec *RXL, *RXU;
70: TaoMat *CA;
71: int nvfunc;
72: TaoTruth viewvfunc;
75: /* ------------------------ Line Search Context -------------------------*/
76: /* Line Search termination code and function pointers */
77: void *linectx;
79: int 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*,int*,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 step; /* last step length or trust region radius */
99: /* -------------------------- Monitoring ------------------------------------*/
101: int numbermonitors; /* number of monitors */
102: int (*defaultmonitor)(TAO_SOLVER,void*); /* default monitor routine */
103: int (*monitor[MAX_TAO_MONITORS])(TAO_SOLVER,void*); /* monitor routine */
104: void *monitorcontext[MAX_TAO_MONITORS]; /* monitor context */
105: int (*converged)(TAO_SOLVER,void*); /* convergence routine */
107: /* -------------------------- Parameters -------------------------------------- */
109: double fatol; /* Absolute tolerance for objective value */
110: double frtol; /* Relative tolerance for objective value */
111: double catol; /* Absolute tolerance for constraints */
112: double crtol; /* Relative tolerance for constraints */
113: double gatol; /* Absolute tolerance for gradient */
114: double grtol; /* Relative tolerance for gradient */
115: double gttol; /* Relative tolerance for gradient */
116: double xtol; /* relative tolerance in solution */
117: double fmin; /* minimum tolerance for function value */
119: /* -------------------------- Statistics -------------------------------------- */
120: int max_its; /* max number of iterations */
121: int iter; /* global iteration number */
122: TaoTerminateReason reason;
124: double norm; /* KKT residual norm of current iterate */
125: double norm0; /* KKT residual norm of residual iterate */
126: int linear_its; /* total number of linear solver iterations */
128: /* ------------------------- Convergence History ------------------------ */
130: void *cnvP; /* convergence context */
131: double *conv_hist; /* If !0, stores function norm (or
132: gradient norm) at each iteration */
133: int *conv_hist_its; /* linear iterations for each Newton step */
134: int conv_hist_len; /* size of convergence history array */
135: int conv_hist_max; /* actual amount of data in conv_history */
136: TaoTruth conv_hist_reset; /* reset counter for each new TAO_SOLVER solve */
138: TaoTruth viewtao;
139: TaoTruth viewksptao;
141: /* Routines called when destroying this structure */
142: int numberdestroyers;
143: int (*userdestroy[MAX_TAO_DESTROY])(void*);
144: void *userctxdestroy[MAX_TAO_DESTROY];
147: /* ------------------------ Default Work-area Management ---------------------- */
149: TaoVec* WorkX1;
150: };
152: #define TaoLogConvHistory(tao_um,res,its) \
153: { if (tao_um->conv_hist && tao_um->conv_hist_max > tao_um->conv_hist_len) \
154: { tao_um->conv_hist[tao_um->conv_hist_len] = res; \
155: tao_um->conv_hist_its[tao_um->conv_hist_len++] = its; \
156: }}
159: #endif