00001
00002
00003
00004 #ifndef OPTIMIZE_H_
00005 #define OPTIMIZE_H_
00006
00007 #include "energy.h"
00008 #include "flux.h"
00009
00012 bool lgOptimize_do(void);
00013
00017 void vary_input(bool *lgLimOK, int grid_index);
00018
00033 void optimize_subplex(long int n,
00034 double tol,
00035 long int maxnfe,
00036 long int mode,
00037 realnum scale[],
00038 realnum x[],
00039 realnum *fx,
00040 long int *nfe,
00041 realnum work[],
00042 long int iwork[],
00043 long int *iflag);
00044
00045
00047 const realnum VRSNEW = realnum(4.00);
00048
00049 typedef double chi2_type;
00050
00051 const chi2_type BIG_CHI2 = chi2_type(FLT_MAX);
00052
00053 void optimize_phymir(realnum[],const realnum[],long,chi2_type*,realnum);
00054
00056 chi2_type optimize_func(const realnum param[], int grid_index = -1);
00057
00058
00060 const long LIMEXT = 5L;
00061 const long LIMPAR = 20L;
00062
00063 EXTERN char chOptimFileName[INPUT_LINE_LENGTH];
00065 typedef enum { PHYMIR_ILL, PHYMIR_SEQ, PHYMIR_FORK, PHYMIR_MPI } phymir_mode;
00066
00067
00068
00069
00070 template<class X, class Y = X, int NP = 32, int NSTR = 32>
00071 class phymir_state
00072 {
00073 X p_xmax;
00074 Y p_ymax;
00075 X p_xp[2*NP+1][NP];
00076 Y p_yp[2*NP+1];
00077 X p_absmin[NP];
00078 X p_absmax[NP];
00079 X p_varmin[NP];
00080 X p_varmax[NP];
00081 X p_a2[NP][NP];
00082 X p_c1[NP];
00083 X p_c2[NP];
00084 X p_xc[NP];
00085 X p_xcold[NP];
00086 X p_vers;
00087 X p_toler;
00088 X p_dmax;
00089 X p_dold;
00090 Y p_ymin;
00091 int32 p_dim;
00092 int32 p_sdim;
00093 int32 p_nvar;
00094 int32 p_noptim;
00095 int32 p_maxiter;
00096 int32 p_jmin;
00097 int32 p_maxcpu;
00098 int32 p_curcpu;
00099 phymir_mode p_mode;
00100 char p_chState[NSTR];
00101 char p_chStr1[NSTR];
00102 char p_chStr2[NSTR];
00103 char p_chStr3[NSTR];
00104
00105
00106 uint32 p_size;
00107 Y (*p_func)(const X[],int);
00108
00109
00110 void p_clear1();
00111 void p_wr_state(const char*) const;
00112 void p_rd_state(const char*);
00113 Y p_execute_job( const X[], int, int );
00114
00115 void p_execute_job_parallel( const X[], int, int ) const;
00116 void p_barrier( int, int );
00117 void p_process_output(int, int );
00118 void p_evaluate_hyperblock();
00119 void p_setup_next_hyperblock();
00120 void p_reset_hyperblock();
00121 void p_phygrm( X[][NP], int );
00122 bool p_lgLimitExceeded(const X[]) const;
00123 X p_delta( int i, int j ) const { return ( i == j ) ? X(1.) : X(0.); }
00124 void p_reset_transformation_matrix();
00125
00126 public:
00127
00128 phymir_state() { p_clear1(); }
00129 void clear() { p_clear1(); }
00130 void init_minmax( const X[], const X[], int );
00131 void init_state_file_name( const char* );
00132 void init_strings( const char*, const char*, const char* );
00133 void initial_run( Y (*)(const X[],int), int, const X[], const X[], X, int, phymir_mode, int );
00134 void continue_from_state( Y (*)(const X[],int), int, const char*, X, int, phymir_mode, int );
00135 void optimize();
00136 void optimize_with_restart();
00137 bool lgMaxIterExceeded() const { return ( p_noptim >= p_maxiter ); }
00138 bool lgInitialized() const { return ( p_nvar > 0 ); }
00139 bool lgConverged() const { return ( p_dmax <= p_toler ); }
00140 bool lgConvergedRestart() const;
00141 X xval( int i ) const { return p_xc[i]; }
00142 X xmin( int i ) const { return max(p_varmin[i],p_absmin[i]); }
00143 X xmax( int i ) const { return min(p_varmax[i],p_absmax[i]); }
00144 Y yval() const { return p_ymin; }
00145 int32 noptim() const { return p_noptim; }
00146 };
00147
00148
00170 EXTERN struct t_optimize {
00171
00173 bool lgVaryOn;
00175 bool lgNoVary;
00176
00178 bool lgOptimr;
00179
00180 bool lgOptimizeAsLinear[LIMPAR];
00181
00183 realnum varmax[LIMPAR];
00184 realnum varmin[LIMPAR];
00185
00188 realnum vparm[LIMEXT][LIMPAR];
00189
00191 realnum vincr[LIMPAR];
00192
00194 long int nvarxt[LIMPAR],
00195 nvfpnt[LIMPAR];
00196
00197 realnum OptIncrm[LIMPAR],
00198 varang[LIMPAR][2];
00199
00200 long int nvary,
00201 nparm,
00202 nRangeSet;
00203 bool lgVarOn;
00204
00205 long int nIterOptim;
00206
00208 vector<string> chColDen_label;
00209 vector<long> ion_ColDen;
00210 vector<realnum> ColDen_Obs;
00211 vector<realnum> ColDen_error;
00212
00214 vector<int> nEmergent;
00215 vector<string> chLineLabel;
00217 vector<realnum> wavelength;
00219 vector<realnum> errorwave;
00220 vector<long> ipobs;
00221 vector<realnum> xLineInt_Obs;
00222 vector<realnum> xLineInt_error;
00223
00225 vector<string> chTempLab;
00226 vector<long> ionTemp;
00227 vector<realnum> temp_obs;
00228 vector<realnum> temp_error;
00229 vector<string> chTempWeight;
00230
00232 bool lgOptDiam;
00233 bool lgDiamInCM;
00234 chi2_type optDiam;
00235 chi2_type optDiamErr;
00236
00238 vector<long> ContIndex;
00239 vector<Energy> ContEner;
00240 vector<Flux> ContNFnu;
00241 vector<chi2_type> ContNFnuErr;
00242
00243 realnum OptGlobalErr;
00244
00246 long int nOptimiz;
00247
00248 bool lgOptimFlow;
00249 realnum optint;
00250 realnum optier;
00251 long int nTrOpt;
00252 bool lgTrOpt;
00253 bool lgOptimize;
00255 bool lgOptLum;
00256 int nOptLum;
00257
00259 bool lgParallel;
00260 bool lgOptCont;
00261 long useCPU;
00262
00263 char chVarFmt[LIMPAR][FILENAME_PATH_LENGTH_2];
00264 char chOptRtn[5];
00265
00266 double SavGenericData[10];
00267
00268 } optimize;
00269
00270 #endif