diff --git a/tracy/tools/soltracy.cc b/tracy/tools/soltracy.cc index 13928a956c0f8454ab64991cea1a9da66bcc516d..86b8a7680efca451f6c3fb9d26a1620f07124684 100644 --- a/tracy/tools/soltracy.cc +++ b/tracy/tools/soltracy.cc @@ -721,8 +721,9 @@ Based on parts of functions get_param( ) & ID_corr(), etc in nsls-ii_lib.cc int k = 0; - printf("Begin ID matching:................ \n"); - + cout << endl; + cout << "************ Begin ID matching: **********" <<endl; + // read the family index of quadrupoles used for ID correction if (N_calls > 0) { if (N_Fam > N_Fam_max) { @@ -735,11 +736,20 @@ Based on parts of functions get_param( ) & ID_corr(), etc in nsls-ii_lib.cc Q_Fam[k] = ElemIndex(IDCq_name[k]); } - // ID correction - for (int k = 0; k < N_Fam; k++) - printf("%d\n",Q_Fam[k]); - - + //For debug + if(!trace){ + cout << "scl_dbetax = " << scl_dbetax << " scl_dbetay = " << scl_dbetay <<endl; + cout << "scl_dnux = " << scl_dnux << " scl_dnuy = " << scl_dnuy << endl; + cout << "scl_nux = " << scl_nux << " scl_nuy = " << scl_nuy << endl; + cout << "ID_step = " << ID_step <<endl; + cout << "N_calls = " << N_calls << " N_steps = " << N_steps <<endl; + cout << "Number of quadrupole families used for ID correction: " << N_Fam << endl; + cout << "Quadrupoles used for ID correction: " << endl; + for (int k = 0; k < N_Fam; k++) + printf("%d\n",Q_Fam[k]); + } + + //initialization ini_ID_corr(); printlatt("linlat00.out"); diff --git a/tracy/tracy/inc/nsls-ii_lib.h b/tracy/tracy/inc/nsls-ii_lib.h index da3d2ff2bdd22f6b6b80f66025526864492c8588..d853b2ed45c7bfdc03d5e2ce0013c9f8199e9a37 100644 --- a/tracy/tracy/inc/nsls-ii_lib.h +++ b/tracy/tracy/inc/nsls-ii_lib.h @@ -18,9 +18,14 @@ extern double x_max_FMA, y_max_FMA, delta_FMA; extern double delta_DA_; -extern const int N_Fam_max; //number of quadrupoles for ID correction extern char ae_file[max_str], fe_file[max_str], ap_file[max_str]; -extern int N_calls, N_steps, N_Fam, Q_Fam[]; //For ID correction + +//For ID correction +extern const int N_Fam_max; //number of quadrupoles for ID correction +extern int N_calls, N_steps, N_Fam, Q_Fam[]; +extern double scl_nux,scl_nuy, scl_dbetax,scl_dbetay, scl_dnux,scl_dnuy, ID_step; + + extern double disp_wave_y; extern Vector2 beta_ref; diff --git a/tracy/tracy/src/nsls-ii_lib.cc b/tracy/tracy/src/nsls-ii_lib.cc index 4ccb8db6228e242b76501a8c54e80db2a945610d..128ab05f01468a1aa6a40aae98a099e3a93b54de 100644 --- a/tracy/tracy/src/nsls-ii_lib.cc +++ b/tracy/tracy/src/nsls-ii_lib.cc @@ -5,9 +5,9 @@ T. Shaftan, I. Pinayev, Y. Luo, C. Montag, B. Nash */ -/* Current revision $Revision: 1.17 $ +/* Current revision $Revision: 1.18 $ On branch $Name: not supported by cvs2svn $ - Latest change by $Author: nadolski $ + Latest change by $Author: zhang $ */ // global params @@ -67,14 +67,20 @@ const char deta_y_FileName[] = "deta_y.out"; const int max_elem = Cell_nLocMax; -const int N_Fam_max = 15; -// Weights for ID correction -const double scl_nu = 1e2, scl_dbeta = 1e0, scl_dnu = 0.1, ID_step = 0.7; char ae_file[max_str], fe_file[max_str], ap_file[max_str]; int N_BPM, N_HCOR, N_VCOR, N_SKEW, N_COUPLE; -int N_calls, N_steps, N_Fam, Q_Fam[N_Fam_max]; // ID correction params + +/* ID correction**********/ +// maximum number of quadrupole families used for ID correction +const int N_Fam_max = 15; +// ID correction params +int N_calls = 1, N_steps = 1, N_Fam, Q_Fam[N_Fam_max]; +// Weights for ID correction +double scl_nux = 1e2, scl_nuy = 1e2, scl_dbetax = 1e0, scl_dbetay = 1e0; +double scl_dnux = 0.1, scl_dnuy = 0.1, ID_step = 0.7; + int n_sext, sexts[max_elem]; double beta0_[max_elem][2], nu0s[max_elem][2], nu0_[2], b2[N_Fam_max]; double **SkewRespMat, *VertCouple, *SkewStrengthCorr, *eta_y; @@ -3396,6 +3402,22 @@ void corr_eps_y(void) } +/******************************************************************* +void get_IDs(void) + + Purpose: + Get the ID. + + Input: + none + + Output: + none + + Comments: + Print out the scaling 2 of Insertion. + +********************************************************************/ // Control of IDs void get_IDs(void) @@ -3412,8 +3434,8 @@ void get_IDs(void) n_ID_Fams++; ID_Fams[n_ID_Fams-1] = k + 1; break; case Insertion: - printf("found ID family: %s %12.5e\n", - ElemFam[k].ElemF.PName, ElemFam[k].ElemF.ID->scaling1); + printf("found ID family: %s scaling1 = %12.5e, scaling2 = %12.5e\n", + ElemFam[k].ElemF.PName, ElemFam[k].ElemF.ID->scaling1, ElemFam[k].ElemF.ID->scaling2); n_ID_Fams++; ID_Fams[n_ID_Fams-1] = k + 1; break; case FieldMap: @@ -3715,7 +3737,22 @@ double Nus(double bq, double nus, double nuq, double NuQ) return Nu; } +/***************************************************************** +void A_matrix(void) + +Purpose: + solove A in the matrix b = A.x + using SVD. + Used for ID correction. + Comments: + change scl_dbeta to scl_dbetax and scl_dbetay + change scl_dnu to scl_dnux and scl_dnuy + change scl_nu to scl_nux and scl_nuy + + + See also X_vector () +******************************************************************/ void A_matrix(void) { int k, j; @@ -3742,16 +3779,16 @@ void A_matrix(void) NuX = -Nus(qb0[X_][j-1], sNu0[X_][k-1], qNu0[X_][j-1], Nu_X0); BtY = -Bet(qb0[Y_][j-1], sNu0[Y_][k-1], qNu0[Y_][j-1], Nu_Y0); NuY = Nus(qb0[Y_][j-1], sNu0[Y_][k-1], qNu0[Y_][j-1], Nu_Y0); - A1[k][j] = scl_dbeta*BtX; - A1[k+Nsext][j] = scl_dbeta*BtY; - A1[k+2*Nsext][j] = scl_dnu*NuX; - A1[k+3*Nsext][j] = scl_dnu*NuY; + A1[k][j] = scl_dbetax*BtX; + A1[k+Nsext][j] = scl_dbetay*BtY; + A1[k+2*Nsext][j] = scl_dnux*NuX; + A1[k+3*Nsext][j] = scl_dnuy*NuY; } } // Now adding 2 more constraints for global tunes for (j = 1; j <= Nquad; j++) { - A1[4*Nsext+1][j] = -scl_nu*qb0[X_][j-1]/(4.0*M_PI); - A1[4*Nsext+2][j] = scl_nu*qb0[Y_][j-1]/(4.0*M_PI); + A1[4*Nsext+1][j] = -scl_nux*qb0[X_][j-1]/(4.0*M_PI); + A1[4*Nsext+2][j] = scl_nuy*qb0[Y_][j-1]/(4.0*M_PI); } if (prt) { @@ -3766,7 +3803,22 @@ void A_matrix(void) } } +/**************************************************** +void X_vector(const bool first) + + Purpose: + solove x in the matrix b = A.x + using SVD. + Used for ID correction. + Comments: + change scl_dbeta to scl_dbetax and scl_dbetay + change scl_dnu to scl_dnux and scl_dnuy + change scl_nu to scl_nux and scl_nuy + + See also: + void A_matrix(void) +*****************************************************/ void X_vector(const bool first) { int k; @@ -3786,13 +3838,13 @@ void X_vector(const bool first) } else { // Now substracting from X in X=A*B2L for (k = 1; k <= Nsext; k++) { - Xsext[k] = scl_dbeta*(Xsext0[k]-sb[X_][k-1])/sb[X_][k-1]; - Xsext[k+Nsext] = scl_dbeta*(Xsext0[k+Nsext]-sb[Y_][k-1])/sb[Y_][k-1]; - Xsext[k+2*Nsext] = scl_dnu*(Xsext0[k+2*Nsext]-sNu[X_][k-1]+dnu0[X_]/2.0); - Xsext[k+3*Nsext] = scl_dnu*(Xsext0[k+3*Nsext]-sNu[Y_][k-1]+dnu0[Y_]/2.0); + Xsext[k] = scl_dbetax*(Xsext0[k]-sb[X_][k-1])/sb[X_][k-1]; + Xsext[k+Nsext] = scl_dbetay*(Xsext0[k+Nsext]-sb[Y_][k-1])/sb[Y_][k-1]; + Xsext[k+2*Nsext] = scl_dnux*(Xsext0[k+2*Nsext]-sNu[X_][k-1]+dnu0[X_]/2.0); + Xsext[k+3*Nsext] = scl_dnuy*(Xsext0[k+3*Nsext]-sNu[Y_][k-1]+dnu0[Y_]/2.0); } - Xsext[4*Nsext+1] = scl_nu*(Nu_X0-globval.TotalTune[X_]); - Xsext[4*Nsext+2] = scl_nu*(Nu_Y0-globval.TotalTune[Y_]); + Xsext[4*Nsext+1] = scl_nux*(Nu_X0-globval.TotalTune[X_]); + Xsext[4*Nsext+2] = scl_nuy*(Nu_Y0-globval.TotalTune[Y_]); } if (prt) { diff --git a/tracy/tracy/src/read_script.cc b/tracy/tracy/src/read_script.cc index 4893c4464e32900828b1bf2a3c4fb6aa25ff0967..9c3d3c252aa3b0e90fd0cd5f3e6cf80f442b6f4f 100644 --- a/tracy/tracy/src/read_script.cc +++ b/tracy/tracy/src/read_script.cc @@ -498,6 +498,20 @@ void read_script(const char *param_file_name, bool rd_lat, long& CommNo, UserCom //ID correction else if (strcmp("IDCorrFlag", name) == 0) strcpy(UserCommandFlag[CommNo].CommandStr,name); + else if (strcmp("scl_dbetax", name) == 0)//scaling of dbetax, for ID correction + sscanf(line, "%*s %lf", &scl_dbetax); + else if (strcmp("scl_dbetay", name) == 0)//scaling of dbetay, for ID correction + sscanf(line, "%*s %lf", &scl_dbetay); + else if (strcmp("scl_dnux", name) == 0)//scaling of dnux, for ID correction + sscanf(line, "%*s %lf", &scl_dnux); + else if (strcmp("scl_dnuy", name) == 0)//scaling of dnuy, for ID correction + sscanf(line, "%*s %lf", &scl_dnuy); + else if (strcmp("scl_nux", name) == 0) //scaling of nux, for ID correction + sscanf(line, "%*s %lf", &scl_nux); + else if (strcmp("scl_nuy", name) == 0) //scaling of nuy, for ID correction + sscanf(line, "%*s %lf", &scl_nuy); + else if (strcmp("ID_step", name) == 0)//ID steps, for ID correction + sscanf(line, "%*s %lf", &ID_step); else if (strcmp("N_calls", name) == 0) // ID correction parameters sscanf(line, "%*s %d", &N_calls); else if (strcmp("N_steps", name) == 0) @@ -510,7 +524,6 @@ void read_script(const char *param_file_name, bool rd_lat, long& CommNo, UserCom IDCq_name[4], IDCq_name[5], IDCq_name[6], IDCq_name[7], IDCq_name[8], IDCq_name[9], IDCq_name[10]); } -// } else if (strcmp("scl_nu", name) == 0) else{ printf("bad line in file %s, line %ld \n", full_param_file_name, LineNum); exit_(1);