Changeset 23 in TRACY3
- Timestamp:
- Dec 6, 2013, 5:12:43 PM (10 years ago)
- Location:
- branches/tracy3-3.10.1b/tracy
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/tracy3-3.10.1b/tracy/tools/soltracy.cc
r11 r23 1 /* ***********************************1 /* 2 2 Current revision $Revision$ 3 3 On branch $Name$ 4 4 Latest change $Date$ by $Author$ 5 *************************************/ 6 #define ORDER 1 7 //#define ORDER 4 5 */ 6 #define ORDER 1 8 7 9 8 int no_tps = ORDER; // arbitrary TPSA order is defined locally 10 9 10 11 11 12 extern bool freq_map; 12 13 13 // #if HAVE_CONFIG_H 14 // #include <config.h> 15 // #endif 16 17 // #if MPI_EXEC 18 // //library of parallel computation,must be before "stdio.h" 19 // #include <mpi.h> 20 // #endif 14 #if HAVE_CONFIG_H 15 #include <config.h> 16 #endif 17 18 /* 19 #if MPI_EXEC 20 //library of parallel computation,must be before "stdio.h" 21 #include <mpi.h> 22 #endif 23 */ 21 24 22 25 #include "tracy_lib.h" … … 41 44 globval.H_exact = false; 42 45 43 44 //output files45 char fic_twiss[S_SIZE + 4] = ""; //twiss file46 char fic_summary[S_SIZE + 4]=""; //summary file47 48 49 46 /* parameters to read the user input script .prm */ 50 47 long i=0L; //initialize the for loop to read command string … … 64 61 UserCommand UserCommandFlag[NCOMMAND]; 65 62 66 // #if MPI_EXEC 67 // //Initialize parallel computation 68 // MPI_Init(&argc, &argv); 69 // #endif 63 /* 64 #if MPI_EXEC 65 //Initialize parallel computation 66 MPI_Init(&argc, &argv); 67 #endif 68 */ 69 70 70 /************************************************************************ 71 71 read in files and flags … … 76 76 read_script(argv[1], true,CommandNo, UserCommandFlag); 77 77 } else { 78 fprintf(stdout, "Not enough parameters\n 78 fprintf(stdout, "Not enough parameters\nSyntax is program parameter file\n"); 79 79 exit_(1); 80 80 } … … 105 105 else 106 106 globval.ge = ElemIndex(ge_name); 107 108 107 109 108 // globval.g = ElemIndex("g"); /* get family index of girder*/ 110 strcpy(fic_twiss,lat_file); 111 strcpy(fic_summary,lat_file); 112 strcat(fic_twiss,".twi"); 113 strcat(fic_summary,".sum"); 114 115 //generate the twiss and summary files with proper appendix 116 /* print the summary of the element in lattice to the screen and an external file*/ 109 110 /* print the summary of the element in lattice */ 117 111 printglob(); 118 printglob2file(fic_summary);119 //print the twiss file120 /* print out lattice functions, with all the optical information for the lattice with design values */121 printlatt(fic_twiss);122 123 112 /************************************************************************ 124 113 print files, very important file for debug … … 263 252 } 264 253 265 else if(strcmp(CommandStr,"PrintTrackElemFlag") == 0) {266 cout << "\n";267 cout << "print the tracked coordinates to file: "268 << UserCommandFlag[i]._PrintTrackElem_track_file << "\n";269 270 PrintTrackElem(UserCommandFlag[i]._PrintTrackElem_track_file,271 UserCommandFlag[i]._PrintTrackElem_x, UserCommandFlag[i]._PrintTrackElem_px,272 UserCommandFlag[i]._PrintTrackElem_y, UserCommandFlag[i]._PrintTrackElem_py,273 UserCommandFlag[i]._PrintTrackElem_delta,UserCommandFlag[i]._PrintTrackElem_ctau,274 UserCommandFlag[i]._PrintTrackElem_nelem1,UserCommandFlag[i]._PrintTrackElem_nelem2);275 }276 254 //print the girder 277 255 // else if(strcmp(CommandStr,"PrintGirderFlag") == 0) { … … 468 446 else if(strcmp(CommandStr,"FmapFlag") == 0) { 469 447 printf("\n begin Fmap calculation for on momentum particles: \n"); 470 471 // #if MPI_EXEC 448 449 // /* 450 // #if MPI_EXEC 472 451 473 452 // //initialization for parallel computing … … 490 469 // UserCommandFlag[i]._FmapFlag_delta, 491 470 // UserCommandFlag[i]._FmapFlag_diffusion, 492 // UserCommandFlag[i]._FmapFlag_printloss,493 471 // numprocs,myid); 494 472 … … 543 521 UserCommandFlag[i]._FmapFlag_ymax, 544 522 UserCommandFlag[i]._FmapFlag_delta, 545 UserCommandFlag[i]._FmapFlag_diffusion, 546 UserCommandFlag[i]._FmapFlag_printloss); 523 UserCommandFlag[i]._FmapFlag_diffusion); 547 524 //#endif 525 548 526 } 549 527 … … 551 529 else if(strcmp(CommandStr,"FmapdpFlag") == 0) { 552 530 printf("\n begin Fmap calculation for off momentum particles: \n"); 553 531 532 // /* 554 533 // #if MPI_EXEC 555 534 … … 572 551 // UserCommandFlag[i]._FmapdpFlag_z, 573 552 // UserCommandFlag[i]._FmapdpFlag_diffusion, 574 // UserCommandFlag[i]._FmapdpFlag_printloss,575 553 // numprocs,myid); 576 554 … … 625 603 UserCommandFlag[i]._FmapdpFlag_emax, 626 604 UserCommandFlag[i]._FmapdpFlag_z, 627 UserCommandFlag[i]._FmapdpFlag_diffusion ,628 UserCommandFlag[i]._FmapdpFlag_printloss); 629 // #endif605 UserCommandFlag[i]._FmapdpFlag_diffusion); 606 // #endif 607 630 608 } 631 609 … … 657 635 printf("\n Calculate momentum acceptance: \n"); 658 636 659 // #if MPI_EXEC 637 638 // #if MPI_EXEC 660 639 661 640 // /* calculate momentum acceptance*/ … … 789 768 790 769 // #else 770 791 771 MomentumAcceptance(UserCommandFlag[i]._MomentumAccFlag_momacc_file, 792 772 UserCommandFlag[i]._MomentumAccFlag_istart, … … 800 780 UserCommandFlag[i]._MomentumAccFlag_nturn, 801 781 UserCommandFlag[i]._MomentumAccFlag_zmax); 802 // #endif 782 /* 783 #endif 784 */ 803 785 804 786 /* restore the initial values*/ … … 863 845 UserCommandFlag[i]._Phase_ctau, 864 846 UserCommandFlag[i]._Phase_nturn); 865 printf(" 6D phase space tracking: \nthe simulation time for phase space in tracy 3 is \n");847 printf("the simulation time for phase space in tracy 3 is \n"); 866 848 stop = stampstop(start); 867 849 … … 1021 1003 1022 1004 1023 // #if MPI_EXEC 1024 // MPI_Finalize(); //finish parallel computation 1025 // #endif 1026 1005 /* 1006 #if MPI_EXEC 1007 MPI_Finalize(); //finish parallel computation 1008 #endif 1009 */ 1010 1027 1011 return 0; 1028 1012 }//end of main() -
branches/tracy3-3.10.1b/tracy/tracy/inc/naffutils.h
r11 r23 27 27 double ctau, long nmax, double Tx[][NTURN], bool *status); 28 28 29 void Trac_Simple4DCOD(double x, double px, double y, double py, double dp,30 double ctau, long nmax, double Tx[][NTURN], long& lastn, long& lastpos,ss_vect<double>& x1,bool *status2);31 32 29 void Trac_Simple6DCOD(double x, double px, double y, double py, double dp, 33 30 double ctau, long nmax, double Tx[][NTURN], bool *status); -
branches/tracy3-3.10.1b/tracy/tracy/inc/physlib.h
r11 r23 55 55 56 56 void printglob(void); 57 58 void printglob2file(const char fic[]);59 57 60 58 void printlatt(const char fic[]); -
branches/tracy3-3.10.1b/tracy/tracy/inc/read_script.h
r11 r23 37 37 long _PrintTrack_nmax; 38 38 39 //start track particle coordinates; PrintTrackFlag40 char _PrintTrackElem_track_file[max_str];41 double _PrintTrackElem_x, _PrintTrackElem_px, _PrintTrackElem_y,42 _PrintTrackElem_py, _PrintTrackElem_delta, _PrintTrackElem_ctau;43 long _PrintTrackElem_nelem1, _PrintTrackElem_nelem2;44 45 46 39 //twiss file 47 40 char _PrintTwiss_twiss_file[max_str]; … … 65 58 long _FmapFlag_nxpoint, _FmapFlag_nypoint, _FmapFlag_nturn; 66 59 double _FmapFlag_xmax, _FmapFlag_ymax, _FmapFlag_delta; 67 bool _FmapFlag_diffusion; 68 bool _FmapFlag_printloss; 69 60 bool _FmapFlag_diffusion; 70 61 71 62 //extern bool FmapdpFlag; … … 73 64 long _FmapdpFlag_nxpoint, _FmapdpFlag_nepoint, _FmapdpFlag_nturn; 74 65 double _FmapdpFlag_xmax, _FmapdpFlag_emax, _FmapdpFlag_z; 75 bool _FmapdpFlag_diffusion; 76 bool _FmapdpFlag_printloss; 66 bool _FmapdpFlag_diffusion; 77 67 78 68 … … 120 110 _FmapFlag_nxpoint=31L, _FmapFlag_nypoint=21L, _FmapFlag_nturn=516L; 121 111 _FmapFlag_xmax=0.025, _FmapFlag_ymax=0.005, _FmapFlag_delta=0.0; 122 _FmapFlag_diffusion = true , _FmapFlag_printloss = false;112 _FmapFlag_diffusion = true; 123 113 124 114 /*fmap for off momentum particle*/ … … 126 116 _FmapdpFlag_nxpoint=31L, _FmapdpFlag_nepoint=21L, _FmapdpFlag_nturn=516L; 127 117 _FmapdpFlag_xmax=0.025, _FmapdpFlag_emax=0.005, _FmapdpFlag_z=0.0; 128 _FmapdpFlag_diffusion = true , _FmapdpFlag_printloss = false;129 118 _FmapdpFlag_diffusion = true; 119 130 120 /* tune shift with amplitude*/ 131 121 strcpy(_AmplitudeTuneShift_nudx_file,"nudx.out"); … … 172 162 173 163 /***** file names************/ 174 extern char lat_file[max_str]; 175 176 //files with multipole errors; for soleil lattice 164 //files with multipole errors; for soleil lattice 177 165 extern char fic_hcorr[max_str],fic_vcorr[max_str], fic_skew[max_str]; 178 166 extern char multipole_file[max_str]; -
branches/tracy3-3.10.1b/tracy/tracy/inc/soleillib.h
r11 r23 58 58 // double z, bool diffusion, bool matlab); 59 59 void fmap(const char *FmapFile, long Nbx, long Nbz, long Nbtour, double xmax, double zmax, 60 double energy, bool diffusion); 61 void fmap(const char *FmapFile, long Nbx, long Nbz, long Nbtour, double xmax, double zmax, 62 double energy, bool diffusion, bool printloss); 60 double energy, bool diffusion); 63 61 void fmap_p(const char *FmapFile, long Nbx, long Nbz, long Nbtour, double xmax, double zmax, 64 double energy, bool diffusion, bool printloss,int numprocs, int myid);62 double energy, bool diffusion, int numprocs, int myid); 65 63 void fmapdp(const char *FmapdpFile, long Nbx, long Nbe, long Nbtour, double xmax, double emax, 66 double z, bool diffusion , bool printloss);64 double z, bool diffusion); 67 65 void fmapdp_p(const char *FmapdpFile, long Nbx, long Nbe, long Nbtour, double xmax, double emax, 68 double z, bool diffusion, bool printloss,int numprocs, int myid);66 double z, bool diffusion, int numprocs, int myid); 69 67 void Nu_Naff(void); 70 68 … … 130 128 /* fit tunes for soleil lattice, in which each quadrupole is cut into two parts*/ 131 129 void FitTune4(long qf1,long qf2, long qd1, long qd2, double nux, double nuy); 132 //print the coordinates at lattice elements tracked for n turns130 //print the coordinates at lattice elements 133 131 void PrintTrack(const char *TrackFile, double x, double px,double y,double py, 134 132 double delta, double ctau, long int nmax); 135 //print the tracked coordinates after a lattice element 136 void PrintTrackElem(const char *TrackFile, double x, double px,double y,double py, 137 double delta, double ctau, long int nelem1,long int nelem2); 133 138 134 139 135 -
branches/tracy3-3.10.1b/tracy/tracy/inc/t2elem.h
r11 r23 38 38 39 39 template<typename T> 40 void Drift(double L,double h_bend, ss_vect<T> &x);41 42 template<typename T>43 40 void Drift(double L, ss_vect<T> &x); 44 41 … … 47 44 48 45 template<typename T> 49 void bend_fringe(double hb, double gap, ss_vect<T> &x); 50 51 template<typename T> 52 static void bendCurvature(double irho, double H, ss_vect<T> &x); 53 54 template<typename T> 55 static void EdgeFocus(double irho, double phi, double gap, ss_vect<T> &x, bool Entrance); 46 static void EdgeFocus(double irho, double phi, double gap, ss_vect<T> &x); 56 47 57 48 template<typename T> … … 61 52 template<typename T> 62 53 void Drift_Pass(CellType &Cell, ss_vect<T> &x); 63 64 template<typename T>65 void dipole_kick(double L, double h_ref, double h_bend, ss_vect<T> &x);66 template<typename T>67 void multipole_kick(int Order, double MB[], double L, double h_bend, ss_vect<T> &x);68 54 69 55 template<typename T> -
branches/tracy3-3.10.1b/tracy/tracy/inc/tpsa_lin.h
r3 r23 75 75 void dacos(const tps_buf &x, tps_buf &z); 76 76 77 void datan(const tps_buf &x, tps_buf &z);78 79 void dactan(const tps_buf &x, tps_buf &z);80 81 77 void dasinh(const tps_buf &x, tps_buf &z); 82 78 83 79 void dacosh(const tps_buf &x, tps_buf &z); 84 80 85 void daarcsin(const tps_buf &x, tps_buf &z); 86 87 void daarccos(const tps_buf &x, tps_buf &z); 81 void datan(const tps_buf &x, tps_buf &z); 88 82 89 83 void daarctan(const tps_buf &x, tps_buf &z); 90 91 void daarcctan(const tps_buf &x, tps_buf &z);92 84 93 85 void dafun_(const char *fun, const tps_buf &x, tps_buf &z); -
branches/tracy3-3.10.1b/tracy/tracy/inc/tracy.h
r11 r23 110 110 bool tuneflag, chromflag, codflag, mapflag, passflag, overflag, chambre; 111 111 int lossplane; /* lost in: horizontal 1 112 vertical 2 113 longitudinal 3 114 not lost in any of the above plane: 0*/ 112 vertical 2 113 longitudinal 3 */ 115 114 } statusrec; 116 115 -
branches/tracy3-3.10.1b/tracy/tracy/inc/tracy_global.h
r11 r23 79 79 int Pmethod; // Integration Method 80 80 int PN; // Number of integration steps 81 long dipEdge_effect1; // dipole edge effect at the entrance82 long dipEdge_effect2; // dipole edge effect at the exit83 81 long quadFF1; /* Entrance quadrupole Fringe field flag */ 84 82 long quadFF2; /* Exit quadrupole Fringe field flag */ … … 100 98 double PdTrnd; // (normal)random scale factor to rotation error PdTrms 101 99 // Multipole strengths 102 mpolArray PBpar; // design field gradient; bn, and an103 mpolArray PBsys; // systematic multipole errors gradient, bn and an104 mpolArray PBrms; // rms multipole field errors gradient, bn and an105 mpolArray PBrnd; // random scale factor of rms error PBrms gradient, bn and an106 mpolArray PB; // total field strength(design,sys,rms) gradient, bn and an100 mpolArray PBpar; // design field strength 101 mpolArray PBsys; // systematic multipole errors 102 mpolArray PBrms; // rms multipole field errors 103 mpolArray PBrnd; // random scale factor of rms error PBrms 104 mpolArray PB; // total field strength(design,sys,rms) 107 105 int Porder; // The highest order in PB 108 106 int n_design; // multipole order (design, All = 0, Dip = 1, Quad = 2, Sext = 3, Oct = 4, Dec = 5, Dodec = 6) … … 111 109 double PTx1; // horizontal entrance angle [deg] 112 110 double PTx2; // horizontal exit angle [deg] 113 double PH1; // bending curvature of the entrance pole face of dipole, see P116 SAC-75.114 double PH2; // bending curvature of the exit pole face of dipole, see P116 SAC-75.115 111 double Pgap; // total magnet gap [m] 116 112 double Pirho; // angle([radian], but in lattice definition, angle is with unit degree)/length of the dipole, 1/rho [1/m] -
branches/tracy3-3.10.1b/tracy/tracy/src/naffutils.cc
r11 r23 18 18 19 19 /****************************************************************************/ 20 /* void Trac_Simple4DCOD(double x, double px, double y, double py, double dp, 21 double ctau, long nmax, double Tx[][NTURN], bool *status2)20 /* void Trac_Simple4DCOD(double x, double px, double y, double py, double dp, long nmax, 21 double Tx[][NTURN], bool *status) 22 22 23 23 Purpose: 24 24 Single particle tracking around the closed orbit for NTURN turns 25 The 6D phase trajectory is saved in a array, but the 26 tracked dp and ctau is not about the COD. 25 The 6D phase trajectory is saved in a array 27 26 28 27 Input: … … 70 69 71 70 72 if ( !trace && status.codflag)71 if (trace && status.codflag) 73 72 printf("dp= % .5e %% xcod= % .5e mm zcod= % .5e mm \n", 74 73 dp*1e2, globval.CODvect[0]*1e3, globval.CODvect[2]*1e3); … … 108 107 } while ((lastn < nmax) && (lastpos == globval.Cell_nLoc) && (lostF == false)); 109 108 110 111 109 if (lastpos != globval.Cell_nLoc) 112 110 { /* Particle lost: Error message section */ … … 118 116 } 119 117 120 121 /****************************************************************************/122 /* void Trac_Simple4DCOD(double x, double px, double y, double py, double dp,123 double ctau, long nmax, double Tx[][NTURN], bool *status2)124 125 Purpose:126 Single particle tracking around the closed orbit for NTURN turns127 The 6D phase trajectory is saved in a array, but the128 tracked dp and ctau is not about the COD.129 130 Input:131 x, px, y, py 4 transverse coordinates132 dp energy offset133 nmax number of turns134 pos starting position for tracking135 aperture global physical aperture136 137 Output:138 lastn last n (should be nmax if not lost)139 lastpos last position in the ring140 Tx 6xNTURN matrix of phase trajectory141 142 Return:143 none144 145 Global variables:146 NTURN number of turn for tracking147 globval148 149 Specific functions:150 Cell_Pass151 152 Comments:153 useful for connection with NAFF154 19/01/03 tracking around the closed orbit155 156 11/06/2013 Modified by Jianfeng Zhang @ LAL157 The same feature as function158 Trac_Simple4DCOD(double x, double px, double y, double py, double dp,159 double ctau, long nmax, double Tx[][NTURN], bool *status2)160 but add the feature to extract the position of the location of161 the lost particle;162 called by function163 fmap(const char *FmapFile, long Nbx, long Nbz, long Nbtour, double xmax, double zmax,164 double energy, bool diffusion, bool loss)165 in soleillib.cc.166 167 ****************************************************************************/168 void Trac_Simple4DCOD(double x, double px, double y, double py, double dp,169 double ctau, long nmax, double Tx[][NTURN], long& lastn, long& lastpos, ss_vect<double>& x1, bool *status2)170 {171 bool lostF = false; /* Lost particle Flag */172 Vector2 aperture = {1.0, 1.0};173 174 lastn = 0;175 lastpos = globval.Cell_nLoc;176 *status2 = true; /* stable */177 x1[0]=0,x1[1]=0,x1[2]=0,x1[3]=0,x1[4]=0,x1[5]=0;178 179 if (globval.MatMeth) Cell_Concat(dp);180 181 /* Get closed orbit */182 183 getcod(dp, lastpos);184 185 186 if (!trace && status.codflag)187 printf("dp= % .5e %% xcod= % .5e mm zcod= % .5e mm \n",188 dp*1e2, globval.CODvect[0]*1e3, globval.CODvect[2]*1e3);189 190 /* Tracking coordinates around the closed orbit */191 x1[0] = x + globval.CODvect[0]; x1[1] = px + globval.CODvect[1];192 x1[2] = y + globval.CODvect[2]; x1[3] = py + globval.CODvect[3];193 x1[4] = dp; x1[5] = ctau;194 195 Tx[0][lastn] = x1[0]; Tx[1][lastn] = x1[1];196 Tx[2][lastn] = x1[2]; Tx[3][lastn] = x1[3];197 Tx[4][lastn] = x1[4]; Tx[5][lastn] = x1[5];198 lastn++;199 200 do201 { /* tracking through the ring */202 if ((lastpos == globval.Cell_nLoc) &&203 (fabs(x1[0]) < aperture[0]) && (fabs(x1[2]) < aperture[1]) && status.codflag)204 {205 if (globval.MatMeth)206 Cell_fPass(x1, lastpos);207 else208 Cell_Pass(0, globval.Cell_nLoc, x1, lastpos);209 Tx[0][lastn] = x1[0]; Tx[1][lastn] = x1[1];210 Tx[2][lastn] = x1[2]; Tx[3][lastn] = x1[3];211 Tx[4][lastn] = x1[4]; Tx[5][lastn] = x1[5];212 }213 else214 {215 printf("Trac_Simple: Particle lost \n");216 fprintf(stdout, "%6ld plane: %1d %+10.5g %+10.5g %+10.5g %+10.5g %+10.5g %+10.5g \n",217 lastn, status.lossplane, x1[0], x1[1], x1[2], x1[3], x1[4], x1[5]);218 lostF = true;219 *status2 = false;220 }221 lastn++;222 } while ((lastn < nmax) && (lastpos == globval.Cell_nLoc) && (lostF == false));223 224 225 if (lastpos != globval.Cell_nLoc)226 { /* Particle lost: Error message section */227 *status2 = false;228 printf("Trac_Simple: Particle lost \n");229 fprintf(stdout, "turn=%5ld plane= %1d %+10.5g %+10.5g %+10.5g %+10.5g %+10.5g %+10.5g \n", lastn-1,230 status.lossplane, x1[0], x1[1], x1[2], x1[3], x1[4], x1[5]);231 }232 }233 234 235 118 /****************************************************************************/ 236 119 /* void Trac_Simple6DCOD(double x, double px, double y, double py, double dp, long nmax, 237 double Tx[][NTURN], bool *status 2)120 double Tx[][NTURN], bool *status) 238 121 239 122 Purpose: -
branches/tracy3-3.10.1b/tracy/tracy/src/physlib.cc
r11 r23 16 16 /**************************/ 17 17 18 /******************************************************************************* 19 * 20 * 21 * 22 * 23 ******************************************************************************/ 18 24 19 /**** same as asctime in C without the \n at the end****/ 25 20 char *asctime2(const struct tm *timeptr) { … … 38 33 return result; 39 34 } 40 /******************************************************************************* 41 * 42 * 43 * 44 * 45 ******************************************************************************/ 35 46 36 /** Get time and date **/ 47 37 struct tm* GetTime() { … … 199 189 200 190 Comments copied from Tracy 2.7(soleil),Written by L.Nadolski. 201 202 03/06/2013 Add feature to print the summary on the sreen and an external file203 191 204 192 ****************************************************************************/ … … 263 251 264 252 /****************************************************************************/ 265 /* void printglob2file(void) 266 267 Purpose: 268 Print global variables on screen 269 Print tunes and chromaticities 270 Print Oneturn matrix 271 272 Input: 273 none 274 275 Output: 276 output on the screen 277 278 Return: 279 none 280 281 Global variables: 282 globval 283 284 Specific functions: 285 none 286 287 Comments: 288 03/06/2013 by Jianfeng Zhang @ LAL 289 The same feature as the file printglob(void), but 290 added feature to print the lattice summary to an external file 291 292 293 ****************************************************************************/ 294 void printglob2file(const char fic[]) { 295 FILE *fout; 296 int i=0,j=0; 297 298 fout = fopen(fic,"w"); 299 300 fprintf(fout, "\n***************************************************************" 301 "***************\n"); 302 fprintf(fout,"\n"); 303 fprintf(fout," dPcommon = %9.3e dPparticle = %9.3e" 304 " Energy [GeV] = %.3f\n", globval.dPcommon, globval.dPparticle, 305 globval.Energy); 306 fprintf(fout," MaxAmplx [m] = %9.3e MaxAmply [m] = %9.3e" 307 " RFAccept [%%] = +/- %4.2f\n", Cell[0].maxampl[X_][1], 308 Cell[0].maxampl[Y_][1], globval.delta_RF * 1e2); 309 fprintf(fout," MatMeth = %s ", globval.MatMeth ? "TRUE " : "FALSE"); 310 fprintf(fout," Cavity_On = %s ", globval.Cavity_on ? "TRUE " : "FALSE"); 311 fprintf(fout," Radiation_On = %s \n", globval.radiation ? "TRUE " : "FALSE"); 312 313 if(globval.bpm == 0) 314 fprintf(fout," bpm = 0"); 315 else 316 fprintf(fout," bpm = %3d", GetnKid(globval.bpm)); 317 if(globval.qt == 0) 318 fprintf(fout," qt = 0 \n"); 319 else 320 fprintf(fout," qt = %3d \n", GetnKid(globval.qt)); 321 if(globval.hcorr == 0) 322 fprintf(fout," hcorr = 0"); 323 else 324 fprintf(fout," hcorr = %3d", GetnKid(globval.hcorr)); 325 if(globval.vcorr == 0) 326 fprintf(fout," vcorr = 0 \n"); 327 else 328 fprintf(fout," vcorr = %3d \n", GetnKid(globval.vcorr)); 329 330 fprintf(fout," Chambre_On = %s \n", globval.Aperture_on ? "TRUE " : "FALSE"); 331 332 fprintf(fout," alphac = %8.4e\n", globval.Alphac); 333 fprintf(fout," nux = %8.6f nuy = %8.6f", 334 globval.TotalTune[X_], globval.TotalTune[Y_]); 335 if (globval.Cavity_on) 336 fprintf(fout," omega = %13.9f\n", globval.Omega); 337 else { 338 fprintf(fout,"\n"); 339 fprintf(fout," ksix = %8.6f ksiy = %8.6f\n", 340 globval.Chrom[X_], globval.Chrom[Y_]); 341 } 342 fprintf(fout,"\n"); 343 344 fprintf(fout," OneTurn matrix:\n"); 345 for(i=0;i<ss_dim;i++){ 346 fprintf(fout,"\n"); 347 for(j=0;j<ss_dim;j++) 348 fprintf(fout,"%14.6e",globval.OneTurnMat[i][j]); 349 } 350 351 fprintf(fout,"\n\nTwiss parameters at entrance:\n"); 352 fprintf(fout, 353 " Betax [m] = % 9.3e Alphax = % 9.3e Etax [m] = % 9.3e Etaxp = % 9.3e\n" 354 " Betay [m] = % 9.3e Alphay = % 9.3e Etay [m] = % 9.3e Etayp = % 9.3e\n\n", 355 Cell[1].Beta[X_], Cell[1].Alpha[X_], Cell[1].Eta[X_], 356 Cell[1].Etap[X_], Cell[1].Beta[Y_], Cell[1].Alpha[Y_], 357 Cell[1].Eta[Y_], Cell[1].Etap[Y_]); 358 359 fclose(fout); 360 } 361 362 /****************************************************************************/ 363 /* void printlatt(const char fic[]) 253 /* void printlatt(void) 364 254 365 255 Purpose: … … 423 313 fclose(outf); 424 314 } 425 /******************************************************************************* 426 * 427 * 428 * 429 * 430 ******************************************************************************/ 315 431 316 double int_curly_H1(long int n) { 432 317 /* Integration with Simpson's Rule */ … … 445 330 return curly_H; 446 331 } 447 /******************************************************************************* 448 * 449 * 450 * 451 * 452 ******************************************************************************/ 332 453 333 void prt_sigma(void) { 454 334 long int i; … … 597 477 } 598 478 } 599 /******************************************************************************* 600 * 601 * 602 * 603 * 604 ******************************************************************************/ 479 605 480 void getabn(Vector2 &alpha, Vector2 &beta, Vector2 &nu) { 606 481 Vector2 gamma; 607 482 Cell_GetABGN(globval.OneTurnMat, alpha, beta, gamma, nu); 608 483 } 609 /******************************************************************************* 610 * 611 * 612 * 613 * 614 ******************************************************************************/ 484 615 485 void TraceABN(long i0, long i1, const Vector2 &alpha, const Vector2 &beta, 616 486 const Vector2 &eta, const Vector2 &etap, const double dP) { … … 743 613 Ring_Fitchrom(ksi, ksieps, ns, sfbuf, sdbuf, ksidkpL, ksiimax); 744 614 } 745 /******************************************************************************* 746 * 747 * 748 * 749 * 750 ******************************************************************************/ 615 751 616 void FitDisp(long q, long pos, double eta) { 752 long i =0L, nq=0L;617 long i, nq; 753 618 fitvect qbuf; 754 619 … … 760 625 Ring_FitDisp(pos, eta, dispeps, nq, qbuf, dispdkL, dispimax); 761 626 } 762 /******************************************************************************* 763 * 764 * 765 * 766 * 767 ******************************************************************************/ 627 768 628 #define nfloq 4 769 629 … … 775 635 #undef nfloq 776 636 777 /*******************************************************************************778 *779 *780 *781 *782 ******************************************************************************/783 637 #define ntrack 4 784 638 … … 797 651 798 652 */ 799 long int i =0L;800 double twoJx =0.0, twoJy=0.0, phix=0.0, phiy=0.0, scl_1 = 1.0, scl_2 = 1.0;653 long int i; 654 double twoJx, twoJy, phix, phiy, scl_1 = 1.0, scl_2 = 1.0; 801 655 Vector x0, x1, x2, xf; 802 656 FILE *outf; … … 956 810 #undef ntrack 957 811 958 /*******************************************************************************959 *960 *961 *962 *963 ******************************************************************************/964 812 #define step 0.1 965 813 #define px 0.0 966 814 #define py 0.0 967 815 void track_(double r, struct LOC_getdynap *LINK) { 968 long i =0L, lastn=0L, lastpos=0L;816 long i, lastn, lastpos; 969 817 Vector x; 970 818 … … 1041 889 void Trac(double x, double px, double y, double py, double dp, double ctau, 1042 890 long nmax, long pos, long &lastn, long &lastpos, FILE *outf1) { 1043 1044 bool lostF = true; /* Lost particle Flag */ 891 bool lostF; /* Lost particle Flag */ 1045 892 Vector x1; /* tracking coordinates */ 1046 893 Vector2 aperture; … … 1060 907 lastn = 0L; 1061 908 (lastpos) = pos; 909 lostF = true; 1062 910 1063 911 if (trace) … … 1128 976 #define nfloq 4 1129 977 bool chk_if_lost(double x0, double y0, double delta, long int nturn, bool floqs) { 1130 1131 long int i=0L, lastn=0L, lastpos=0L; 978 long int i, lastn, lastpos; 1132 979 Vector x; 1133 980 … … 1259 1106 ****************************************************************************/ 1260 1107 void getcsAscr(void) { 1261 long i =0L, j=0L;1262 double phi =0.0;1108 long i, j; 1109 double phi; 1263 1110 Matrix R; 1264 1111 … … 1331 1178 Assumes mid-plane symmetry. */ 1332 1179 1333 long int i =0L, lastpos=0L;1334 double phi =0.0, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0;1180 long int i, lastpos; 1181 double phi, x_min, x_max, y_min, y_max; 1335 1182 1336 1183 getcod(delta, lastpos); … … 1422 1269 ****************************************************************************/ 1423 1270 double get_aper(int n, double x[], double y[]) { 1424 int i =0;1425 double A =0.0;1271 int i; 1272 double A; 1426 1273 1427 1274 A = 0.0; … … 1436 1283 } 1437 1284 1438 /**************************************************************************1439 * void GetTrack(const char *file_name, long *n, double x[], double px[],1440 double y[], double py[])1441 *1442 *1443 *1444 **************************************************************************/1445 1285 void GetTrack(const char *file_name, long *n, double x[], double px[], 1446 1286 double y[], double py[]) { 1447 int k =0;1287 int k; 1448 1288 char line[200]; 1449 1289 FILE *inf; … … 1495 1335 ****************************************************************************/ 1496 1336 void Getj(long n, double *x, double *px, double *y, double *py) { 1497 long int i =0L;1337 long int i; 1498 1338 1499 1339 for (i = 0; i < n; i++) { … … 1529 1369 ****************************************************************************/ 1530 1370 double GetArg(double x, double px, double nu) { 1531 1532 double phi=0.0, val=0.0; 1371 double phi, val; 1533 1372 1534 1373 phi = GetAngle(x, px); … … 1568 1407 void GetPhi(long n, double *x, double *px, double *y, double *py) { 1569 1408 /* Calculates the linear phase */ 1570 long i =0L;1409 long i; 1571 1410 1572 1411 for (i = 1; i <= n; i++) { … … 1582 1421 void Sinfft(int n, double xr[]) { 1583 1422 /* DFT with sine window */ 1584 int i =0;1423 int i; 1585 1424 double xi[n]; 1586 1425 … … 1611 1450 free_dvector(xi, 1, 2 * n); 1612 1451 } 1613 /******************************************************************************* 1614 * 1615 * 1616 * 1617 * 1618 ******************************************************************************/ 1452 1619 1453 void sin_FFT(int n, double xr[], double xi[]) { 1620 1454 /* DFT with sine window */ 1621 int i =0;1455 int i; 1622 1456 double *xri; 1623 1457 … … 1636 1470 free_dvector(xri, 1, 2 * n); 1637 1471 } 1638 /******************************************************************************* 1639 * 1640 * 1641 * 1642 * 1643 ******************************************************************************/ 1472 1644 1473 void GetInd(int n, int k, int *ind1, int *ind3) { 1645 1474 if (k == 1) { … … 1654 1483 } 1655 1484 } 1656 /******************************************************************************* 1657 * 1658 * 1659 * 1660 * 1661 ******************************************************************************/ 1485 1662 1486 void GetInd1(int n, int k, int *ind1, int *ind3) { 1663 1487 if (k == 1) { … … 1672 1496 } 1673 1497 } 1674 /******************************************************************************* 1675 * 1676 * 1677 * 1678 * 1679 ******************************************************************************/ 1498 1680 1499 void GetPeak(int n, double *x, int *k) { 1681 1500 /* Locate peak in DFT spectrum */ 1682 int ind1=0, ind2=0, ind3=0; 1683 double peak=0.0; 1684 1501 int ind1, ind2, ind3; 1502 double peak; 1503 1504 peak = 0.0; 1685 1505 *k = 1; 1686 1506 for (ind2 = 1; ind2 <= n / 2 + 1; ind2++) { … … 1693 1513 } 1694 1514 } 1695 /******************************************************************************* 1696 * 1697 * 1698 * 1699 * 1700 ******************************************************************************/ 1515 1701 1516 void GetPeak1(int n, double *x, int *k) { 1702 1517 /* Locate peak in DFT spectrum */ 1703 int ind1=0, ind2=0, ind3=0; 1704 double peak=0.0; 1705 1518 int ind1, ind2, ind3; 1519 double peak; 1520 1521 peak = 0.0; 1706 1522 *k = 1; 1707 1523 for (ind2 = 1; ind2 <= n; ind2++) { … … 1714 1530 } 1715 1531 } 1716 /******************************************************************************* 1717 * 1718 * 1719 * 1720 * 1721 ******************************************************************************/ 1532 1722 1533 double Int2snu(int n, double *x, int k) { 1723 1534 /* Get frequency by nonlinear interpolation with two samples … … 1728 1539 N A(k-1) + A(k) 2 1729 1540 */ 1730 int ind =0, ind1=0, ind3=0;1731 double ampl1 =0.0, ampl2=0.0;1541 int ind, ind1, ind3; 1542 double ampl1, ampl2; 1732 1543 1733 1544 GetInd(n, k, &ind1, &ind3); … … 1823 1634 2 pi ( k + 1/2 ) pi ( k - 1/2 ) 1824 1635 */ 1825 double corr =0.0;1636 double corr; 1826 1637 1827 1638 corr = (Sinc(M_PI * (k - 1 + 0.5 - nu * n)) + Sinc(M_PI * (k - 1 - 0.5 - nu … … 1858 1669 /* Get phase by linear interpolation for rectangular window 1859 1670 with -pi <= phi <= pi */ 1860 int i =0;1861 double phi =0.0;1671 int i; 1672 double phi; 1862 1673 double xr[n], xi[n]; 1863 1674 … … 1901 1712 ****************************************************************************/ 1902 1713 void FndRes(struct LOC_findres *LINK) { 1903 int i =0, j=0, FORLIM=0, FORLIM1=0;1904 double delta =0.0;1714 int i, j, FORLIM, FORLIM1; 1715 double delta; 1905 1716 1906 1717 FORLIM = LINK->n; … … 1970 1781 } while (!V.found); 1971 1782 } 1972 /******************************************************************************* 1973 * 1974 * 1975 * 1976 * 1977 ******************************************************************************/ 1783 1978 1784 void GetPeaks(int n, double *x, int nf, double *nu, double *A) { 1979 int i =0, k=0, ind1=0, ind3=0;1785 int i, k, ind1, ind3; 1980 1786 1981 1787 for (i = 0; i < nf; i++) { … … 1991 1797 } 1992 1798 } 1993 /******************************************************************************* 1994 * 1995 * 1996 * 1997 * 1998 ******************************************************************************/ 1799 1999 1800 void GetPeaks1(int n, double *x, int nf, double *nu, double *A) { 2000 int i =0, k=0, ind1=0, ind3=0;1801 int i, k, ind1, ind3; 2001 1802 2002 1803 for (i = 0; i < nf; i++) { … … 2018 1819 2019 1820 void SetTol(int Fnum, double dxrms, double dyrms, double drrms) { 2020 int i =0;2021 long k =0L;1821 int i; 1822 long k; 2022 1823 2023 1824 for (i = 1; i <= GetnKid(Fnum); i++) { … … 2033 1834 } 2034 1835 } 2035 /******************************************************************************* 2036 * 2037 * 2038 * 2039 * 2040 ******************************************************************************/ 1836 2041 1837 void Scale_Tol(int Fnum, double dxrms, double dyrms, double drrms) { 2042 int Knum =0;2043 long int loc =0L;1838 int Knum; 1839 long int loc; 2044 1840 2045 1841 for (Knum = 1; Knum <= GetnKid(Fnum); Knum++) { … … 2079 1875 ****************************************************************************/ 2080 1876 void SetaTol(int Fnum, int Knum, double dx, double dy, double dr) { 2081 long int loc =0L;1877 long int loc; 2082 1878 2083 1879 loc = Elem_GetPos(Fnum, Knum); … … 2091 1887 Mpole_SetdT(Fnum, Knum); 2092 1888 } 2093 /******************************************************************************* 2094 * 2095 * 2096 * 2097 * 2098 ******************************************************************************/ 1889 2099 1890 void ini_aper(const double Dxmin, const double Dxmax, const double Dymin, 2100 1891 const double Dymax) { 2101 int k =0;1892 int k; 2102 1893 2103 1894 for (k = 0; k <= globval.Cell_nLoc; k++) { … … 2108 1899 } 2109 1900 } 2110 /******************************************************************************* 2111 * 2112 * 2113 * 2114 * 2115 ******************************************************************************/ 1901 2116 1902 void set_aper(const int Fnum, const double Dxmin, const double Dxmax, 2117 1903 const double Dymin, const double Dymax) { 2118 int i =0;2119 long int loc =0L;1904 int i; 1905 long int loc; 2120 1906 2121 1907 for (i = 1; i <= GetnKid(Fnum); i++) { … … 2127 1913 } 2128 1914 } 2129 /************************************************* 2130 * void LoadApertures(const char *ChamberFileName) 2131 * 2132 * 2133 * 2134 **************************************************/ 1915 2135 1916 void LoadApertures(const char *ChamberFileName) { 2136 1917 char line[128], FamName[32]; 2137 long Fnum =0L;2138 double Xmin =0.0, Xmax=0.0, Ymin=0.0, Ymax=0.0;1918 long Fnum; 1919 double Xmin, Xmax, Ymin, Ymax; 2139 1920 FILE *ChamberFile; 2140 1921 … … 2154 1935 fclose(ChamberFile); 2155 1936 } 2156 /********************************************************************************** 2157 * void LoadTolerances(const char *TolFileName) 2158 * 2159 * 2160 * 2161 **********************************************************************************/ 1937 2162 1938 // Load tolerances from the file 2163 1939 void LoadTolerances(const char *TolFileName) { 2164 1940 char line[128], FamName[32]; 2165 int Fnum =0;2166 double dx =0.0, dy=0.0, dr=0.0;1941 int Fnum; 1942 double dx, dy, dr; 2167 1943 FILE *tolfile; 2168 1944 2169 1945 tolfile = file_read(TolFileName); 2170 if(tolfile == NULL){2171 printf("LoadTolerances(): Error! Failure to read file: %s \n",TolFileName);2172 exit_(1);2173 }2174 1946 2175 1947 do … … 2193 1965 } 2194 1966 2195 /**************************************************************************************2196 * void ScaleTolerances(const char *TolFileName, const double scl)2197 *2198 *2199 *2200 * ************************************************************************************/2201 1967 // Load tolerances from the file 2202 1968 void ScaleTolerances(const char *TolFileName, const double scl) { 2203 1969 char line[128], FamName[32]; 2204 int Fnum =0;2205 double dx =0.0, dy=0.0, dr=0.0;1970 int Fnum; 1971 double dx, dy, dr; 2206 1972 FILE *tolfile; 2207 1973 2208 1974 tolfile = file_read(TolFileName); 2209 if(tolfile == NULL){ 2210 printf("LoadTolerances(): Error! Failure to read file: %s \n",TolFileName); 2211 exit_(1); 2212 } 2213 1975 2214 1976 do 2215 1977 fgets(line, 128, tolfile); … … 2230 1992 fclose(tolfile); 2231 1993 } 2232 /******************************************************************************* 2233 * 2234 * 2235 * 2236 * 2237 ******************************************************************************/ 1994 2238 1995 void SetKpar(int Fnum, int Knum, int Order, double k) { 2239 1996 … … 2241 1998 Mpole_SetPB(Fnum, Knum, Order); 2242 1999 } 2243 /******************************************************************************* 2244 * 2245 * 2246 * 2247 * 2248 ******************************************************************************/ 2000 2249 2001 void SetL(int Fnum, int Knum, double L) { 2250 2002 2251 2003 Cell[Elem_GetPos(Fnum, Knum)].Elem.PL = L; 2252 2004 } 2253 /******************************************************************************* 2254 * 2255 * 2256 * 2257 * 2258 ******************************************************************************/ 2005 2259 2006 void SetL(int Fnum, double L) { 2260 int i =0;2007 int i; 2261 2008 2262 2009 for (i = 1; i <= GetnKid(Fnum); i++) 2263 2010 Cell[Elem_GetPos(Fnum, i)].Elem.PL = L; 2264 2011 } 2265 /******************************************************************************* 2266 * 2267 * 2268 * 2269 * 2270 ******************************************************************************/ 2012 2271 2013 void SetdKpar(int Fnum, int Knum, int Order, double dk) { 2272 2014 … … 2274 2016 Mpole_SetPB(Fnum, Knum, Order); 2275 2017 } 2276 /******************************************************************************* 2277 * 2278 * 2279 * 2280 * 2281 ******************************************************************************/ 2018 2282 2019 void SetKLpar(int Fnum, int Knum, int Order, double kL) { 2283 long int loc =0L;2020 long int loc; 2284 2021 2285 2022 if (abs(Order) > HOMmax) { … … 2296 2033 Mpole_SetPB(Fnum, Knum, Order); 2297 2034 } 2298 /******************************************************************************* 2299 * 2300 * 2301 * 2302 * 2303 ******************************************************************************/ 2035 2304 2036 void SetdKLpar(int Fnum, int Knum, int Order, double dkL) { 2305 long int loc =0L;2037 long int loc; 2306 2038 2307 2039 loc = Elem_GetPos(Fnum, Knum); … … 2332 2064 **************************************************************/ 2333 2065 void SetdKrpar(int Fnum, int Knum, int Order, double dkrel) { 2334 long int loc =0L;2066 long int loc; 2335 2067 2336 2068 loc = Elem_GetPos(Fnum, Knum); … … 2343 2075 Mpole_SetPB(Fnum, Knum, Order); 2344 2076 } 2345 /******************************************************************************* 2346 * 2347 * 2348 * 2349 * 2350 ******************************************************************************/ 2077 2351 2078 void Setbn(int Fnum, int order, double bn) { 2352 int i =0;2079 int i; 2353 2080 2354 2081 for (i = 1; i <= GetnKid(Fnum); i++) 2355 2082 SetKpar(Fnum, i, order, bn); 2356 2083 } 2357 /******************************************************************************* 2358 * 2359 * 2360 * 2361 * 2362 ******************************************************************************/ 2084 2363 2085 void SetbnL(int Fnum, int order, double bnL) { 2364 int i =0;2086 int i; 2365 2087 2366 2088 for (i = 1; i <= GetnKid(Fnum); i++) 2367 2089 SetKLpar(Fnum, i, order, bnL); 2368 2090 } 2369 /******************************************************************************* 2370 * 2371 * 2372 * 2373 * 2374 ******************************************************************************/ 2091 2375 2092 void Setdbn(int Fnum, int order, double dbn) { 2376 int i =0;2093 int i; 2377 2094 2378 2095 for (i = 1; i <= GetnKid(Fnum); i++) 2379 2096 SetdKpar(Fnum, i, order, dbn); 2380 2097 } 2381 /******************************************************************************* 2382 * 2383 * 2384 * 2385 * 2386 ******************************************************************************/ 2098 2387 2099 void SetdbnL(int Fnum, int order, double dbnL) { 2388 int i =0;2100 int i; 2389 2101 2390 2102 for (i = 1; i <= GetnKid(Fnum); i++) { … … 2415 2127 //void Setbnr(int Fnum, long order, double bnr) { 2416 2128 void Setbnr(int Fnum, int order, double bnr) { 2417 int i =0;2129 int i; 2418 2130 2419 2131 for (i = 1; i <= GetnKid(Fnum); i++) 2420 2132 SetdKrpar(Fnum, i, order, bnr); 2421 2133 } 2422 /******************************************************************************* 2423 * 2424 * 2425 * 2426 * 2427 ******************************************************************************/ 2134 2428 2135 void SetbnL_sys(int Fnum, int Order, double bnL_sys) { 2429 int Knum =0;2430 long int loc =0L;2136 int Knum; 2137 long int loc; 2431 2138 2432 2139 for (Knum = 1; Knum <= GetnKid(Fnum); Knum++) { … … 2440 2147 } 2441 2148 } 2442 /******************************************************************************* 2443 * 2444 * 2445 * 2446 * 2447 ******************************************************************************/ 2149 2448 2150 void set_dbn_rel(const int type, const int n, const double dbn_rel) { 2449 long int j =0L;2450 double dbn =0.0;2151 long int j; 2152 double dbn; 2451 2153 2452 2154 printf("\n"); … … 2535 2237 return (Cell[loc].Elem.M->PBpar[Order + HOMmax]); 2536 2238 } 2537 /******************************************************************************* 2538 * 2539 * 2540 * 2541 * 2542 ******************************************************************************/ 2239 2543 2240 void SetdKLrms(int Fnum, int Order, double dkLrms) { 2544 long int Knum =0L, loc=0L;2241 long int Knum, loc; 2545 2242 2546 2243 for (Knum = 1; Knum <= GetnKid(Fnum); Knum++) { … … 2555 2252 } 2556 2253 } 2557 /******************************************************************************* 2558 * 2559 * 2560 * 2561 * 2562 ******************************************************************************/ 2254 2563 2255 void Setdkrrms(int Fnum, int Order, double dkrrms) { 2564 long int Knum =0L, loc=0L;2256 long int Knum, loc; 2565 2257 2566 2258 for (Knum = 1; Knum <= GetnKid(Fnum); Knum++) { … … 2576 2268 } 2577 2269 } 2578 /******************************************************************************* 2579 * 2580 * 2581 * 2582 * 2583 ******************************************************************************/ 2270 2584 2271 void SetKL(int Fnum, int Order) { 2585 long int Knum =0L;2272 long int Knum; 2586 2273 2587 2274 for (Knum = 1; Knum <= GetnKid(Fnum); Knum++) 2588 2275 Mpole_SetPB(Fnum, Knum, Order); 2589 2276 } 2590 /******************************************************************************* 2591 * 2592 * 2593 * 2594 * 2595 ******************************************************************************/ 2277 2596 2278 void set_dx(const int type, const double sigma_x, const double sigma_y) { 2597 long int j =0L;2279 long int j; 2598 2280 2599 2281 printf("\n"); … … 2611 2293 } 2612 2294 } 2613 /******************************************************************************* 2614 * 2615 * 2616 * 2617 * 2618 ******************************************************************************/ 2295 2619 2296 void SetBpmdS(int Fnum, double dxrms, double dyrms) { 2620 long int Knum, loc =0L;2297 long int Knum, loc; 2621 2298 2622 2299 for (Knum = 1; Knum <= GetnKid(Fnum); Knum++) { … … 2644 2321 ****************************************************************************/ 2645 2322 void codstat(double *mean, double *sigma, double *xmax, long lastpos, bool all) { 2646 long i =0L, j=0L, n=0L;2323 long i, j, n; 2647 2324 Vector2 sum, sum2; 2648 double TEMP =0.0;2325 double TEMP; 2649 2326 2650 2327 n = 0; … … 2711 2388 void CodStatBpm(double *mean, double *sigma, double *xmax, long lastpos, 2712 2389 long bpmdis[mnp]) { 2713 long i =0L, j=0L, m=0L, n=0L;2390 long i, j, m, n; 2714 2391 Vector2 sum, sum2; 2715 double TEMP =0.0;2392 double TEMP; 2716 2393 2717 2394 m = n = 0; … … 2871 2548 ****************************************************************************/ 2872 2549 void GetMean(long n, double *x) { 2873 long i =0L;2550 long i; 2874 2551 double mean = 0e0; 2875 2552 … … 3280 2957 const int ntrial = 40; // maximum number of trials for closed orbit 3281 2958 const double tolx = 1e-8; // numerical precision 3282 int k =0;3283 int dim =0; // 4D or 6D tracking3284 long lastpos =0L;2959 int k; 2960 int dim; // 4D or 6D tracking 2961 long lastpos; 3285 2962 3286 2963 vcod = dvector(1, 6); … … 3362 3039 const int ntrial = 40; // maximum number of trials for closed orbit 3363 3040 const double tolx = 1e-10; // numerical precision 3364 int k =0, dim = 0;3365 long lastpos =0L;3041 int k, dim = 0; 3042 long lastpos; 3366 3043 3367 3044 // initializations … … 3429 3106 3430 3107 void computeFandJS(double *x, int n, double **fjac, double *fvect) { 3431 int i =0, k=0;3108 int i, k; 3432 3109 long lastpos = 0L; 3433 3110 Vector x0, fx, fx1, fx2; … … 3501 3178 ****************************************************************************/ 3502 3179 void computeFandJ(int n, Vector &x, Matrix &fjac, Vector &fvect) { 3503 int i =0, k=0;3180 int i, k; 3504 3181 long lastpos = 0; 3505 3182 Vector x0, fx1, fx2; … … 3583 3260 3584 3261 void Newton_RaphsonS(int ntrial, double x[], int n, double tolx) { 3585 int k =0, i=0, *indx;3586 double errx =0.0, d=0.0, *bet, *fvect, **alpha;3262 int k, i, *indx; 3263 double errx, d, *bet, *fvect, **alpha; 3587 3264 3588 3265 errx = 0.0; … … 3681 3358 ****************************************************************************/ 3682 3359 int Newton_Raphson(int n, Vector &x, int ntrial, double tolx) { 3683 int k =0, i=0;3684 double errx =0.0;3360 int k, i; 3361 double errx; 3685 3362 Vector bet, fvect; 3686 3363 Matrix alpha; … … 3724 3401 return 0; 3725 3402 } 3726 /******************************************************************************* 3727 * 3728 * 3729 * 3730 * 3731 ******************************************************************************/ 3403 3732 3404 void rm_mean(long int n, double x[]) { 3733 long int i=0L; 3734 double mean=0.0; 3735 3405 long int i; 3406 double mean; 3407 3408 mean = 0.0; 3736 3409 for (i = 0; i < n; i++) 3737 3410 mean += x[i]; -
branches/tracy3-3.10.1b/tracy/tracy/src/prtmfile.cc
r11 r23 153 153 154 154 Purpose: 155 Print out flatfile; 156 print the lattice parameters in an external file. 155 Print out flatfile 157 156 158 157 Input: … … 182 181 Cell[i].dS[Y_], Cell[i].Elem.M->PdTpar, Cell[i].Elem.M->PdTsys 183 182 + Cell[i].Elem.M->PdTrms * Cell[i].Elem.M->PdTrnd); 184 fprintf(mfile, " %23.16e %23.16e %23.16e %23.16e %23.16e %23.16e %23.16e\n",183 fprintf(mfile, " %23.16e %23.16e %23.16e %23.16e %23.16e\n", 185 184 Cell[i].Elem.PL, Cell[i].Elem.M->Pirho, Cell[i].Elem.M->PTx1, 186 Cell[i].Elem.M->PTx2, Cell[i].Elem.M->P H1,Cell[i].Elem.M->PH2,Cell[i].Elem.M->Pgap);185 Cell[i].Elem.M->PTx2, Cell[i].Elem.M->Pgap); 187 186 prtHOM(mfile, Cell[i].Elem.M->n_design, Cell[i].Elem.M->PB, 188 187 Cell[i].Elem.M->Porder); -
branches/tracy3-3.10.1b/tracy/tracy/src/rdmfile.cc
r11 r23 217 217 if (prt) 218 218 printf("%s\n", line); 219 sscanf(line, "%lf %lf %lf %lf %lf %lf %lf", &Cell[i].Elem.PL,219 sscanf(line, "%lf %lf %lf %lf %lf", &Cell[i].Elem.PL, 220 220 &Cell[i].Elem.M->Pirho, &Cell[i].Elem.M->PTx1, 221 &Cell[i].Elem.M->PTx2, &Cell[i].Elem.M->P H1, &Cell[i].Elem.M->PH2, &Cell[i].Elem.M->Pgap);221 &Cell[i].Elem.M->PTx2, &Cell[i].Elem.M->Pgap); 222 222 if (Cell[i].Elem.M->Pirho != 0.0) 223 223 Cell[i].Elem.M->Porder = 1; -
branches/tracy3-3.10.1b/tracy/tracy/src/read_script.cc
r11 r23 25 25 Comments: 26 26 Written by Jianfeng Zhang 03/2011 soleil 27 28 (1) 15/10/2013 by Jianfeng Zhang @ LAL29 Fix the bugs of fgets():30 to read lines with arbritracy length,31 to read the empty space at the end of the line.32 33 Remove the rontine to move the address of "line" if the34 contents of "line" is empty space; otherwise free() can't35 find the orignial address of "line".36 37 27 38 28 ****************************************************************************/ … … 40 30 /* files */ 41 31 42 char lat_file[max_str]="voidlattice";43 32 // girder file 44 33 char girder_file[max_str]; … … 78 67 79 68 80 char str[max_str]="voidstring", dummy[max_str]="voidstring", dummy2[max_str]="voidstring",nextpara[max_str]="voidpara";69 char str[max_str]="voidstring", dummy[max_str]="voidstring", nextpara[max_str]="voidpara"; 81 70 char in[max_str]; //temporary line with preceding white space 82 char *line = NULL; //line to store the command without preceding white space 83 size_t len = 0; 84 ssize_t read; 71 char *line; //line to store the command without preceding white space 85 72 char name[max_str]="voidname"; 86 //char lat_file[max_str]="voidlattice";73 char lat_file[max_str]="voidlattice"; 87 74 char EndName[]="void"; 88 75 89 76 FILE *inf; 90 77 const bool prt = false; // for debugging printout each line of input file … … 100 87 // Manipulation of the parameter file 101 88 strcpy(dummy, param_file_name); 102 103 sprintf(full_param_file_name,"%s",dummy); 104 if (!prt) printf("\n reading in script file: %s\n",full_param_file_name); 89 pch = strstr (dummy,".prm"); // search for extension .prm 90 /* remove additional .prm if exist */ 91 if (pch != NULL) strncpy(pch,"\0",1); 92 93 sprintf(full_param_file_name,"%s.prm",dummy); 94 if (prt) printf("\n reading in script file: %s\n",full_param_file_name); 105 95 106 96 // 107 97 inf = file_read(full_param_file_name); 108 if(inf == NULL){ 109 printf("read_script(): Error! Read File %s Failure!\n",full_param_file_name); 110 exit_(1); 111 } 98 112 99 113 100 // read parameter file, line by line 114 while ((read = getline(&line, &len, inf)) != -1) { 115 116 LineNum++; 117 if(prt){ 118 printf("Line # %ld \n",LineNum); 119 printf("Retrieved line of length %zu : \n",read); 120 cout << line << endl; 121 } 122 123 101 // while (fgets(line, max_str, inf) != NULL) { 102 while (line = fgets(in, max_str, inf)) { 103 104 /* kill preceding whitespace generated by "table" key 105 or "space" key, but leave \n 106 so we're guaranteed to have something*/ 107 while(*line == ' ' || *line == '\t') { 108 line++; 109 } 110 111 if(prt) 112 printf("cfg: %s",line); 113 114 LineNum++; 124 115 125 116 /* read the end of line symbol '\n','\r' or '\r\n' at different operation system*/ 126 if (strstr(line, "#") == NULL && line[0] != '\n'&&127 line[0] != '\r' && strcmp(line, "\r\n") != 0 ){117 if (strstr(line, "#") == NULL && strcmp(line,"\n") != 0 && 118 strcmp(line,"\r") != 0 && strcmp(line,"\r\n") != 0) { 128 119 // get initial command token 129 120 sscanf(line, "%s", name); … … 260 251 strcpy(UserCommandFlag[CommNo].CommandStr,name); 261 252 } 262 //print the cooridinates using tracking at each element263 else if (strcmp("PrintTrackElemFlag", name) == 0){264 sscanf(line, "%*s %s",nextpara);265 266 if(strcmp(nextpara,"voidpara")!=0)267 sscanf(line, "%*s %s %lf %lf %lf %lf %lf %lf %ld %ld",268 UserCommandFlag[CommNo]._PrintTrackElem_track_file,269 &(UserCommandFlag[CommNo]._PrintTrackElem_x),270 &(UserCommandFlag[CommNo]._PrintTrackElem_px),271 &(UserCommandFlag[CommNo]._PrintTrackElem_y),272 &(UserCommandFlag[CommNo]._PrintTrackElem_py),273 &(UserCommandFlag[CommNo]._PrintTrackElem_delta),274 &(UserCommandFlag[CommNo]._PrintTrackElem_ctau),275 &(UserCommandFlag[CommNo]._PrintTrackElem_nelem1),276 &(UserCommandFlag[CommNo]._PrintTrackElem_nelem2));277 strcpy(UserCommandFlag[CommNo].CommandStr,name);278 }279 253 //print close orbit(COD) flag 280 254 else if (strcmp("PrintGirderFlag", name) == 0){ … … 293 267 else if (strcmp("FmapFlag", name) == 0){ 294 268 strcpy(dummy, ""); 295 strcpy(dummy2,"");269 296 270 sscanf(line, "%*s %s",nextpara); 297 271 298 //if no definition of loss flag in the lattice file, then "dummy2" is empty string.299 272 if(strcmp(nextpara,"voidpara")!=0) 300 sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s %s",273 sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s", 301 274 UserCommandFlag[CommNo]._FmapFlag_fmap_file, 302 275 &(UserCommandFlag[CommNo]._FmapFlag_nxpoint), … … 306 279 &(UserCommandFlag[CommNo]._FmapFlag_ymax), 307 280 &(UserCommandFlag[CommNo]._FmapFlag_delta), 308 dummy ,dummy2);281 dummy); 309 282 310 283 if(strcmp(dummy, "true") == 0) … … 313 286 UserCommandFlag[CommNo]._FmapFlag_diffusion = false; 314 287 315 if(strcmp(dummy2, "true") == 0)316 UserCommandFlag[CommNo]._FmapFlag_printloss = true;317 else if(strcmp(dummy2, "false") == 0)318 UserCommandFlag[CommNo]._FmapFlag_printloss = false;319 else320 UserCommandFlag[CommNo]._FmapFlag_printloss = false;321 322 323 //cout << "debug: " << line << endl;324 //cout << "dummy2 = " << dummy2 << " lossflag = " << UserCommandFlag[CommNo]._FmapFlag_printloss << endl;325 326 288 // FmapFlag = true; 327 289 strcpy(UserCommandFlag[CommNo].CommandStr,name); … … 330 292 else if (strcmp("FmapdpFlag", name) == 0){ 331 293 strcpy(dummy, ""); 332 strcpy(dummy2,"");333 294 sscanf(line, "%*s %s",nextpara); 334 295 335 296 if(strcmp(nextpara,"voidpara")!=0) 336 sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s %s",297 sscanf(line, "%*s %s %ld %ld %ld %lf %lf %lf %s", 337 298 UserCommandFlag[CommNo]._FmapdpFlag_fmapdp_file, 338 299 &(UserCommandFlag[CommNo]._FmapdpFlag_nxpoint), … … 342 303 &(UserCommandFlag[CommNo]._FmapdpFlag_emax), 343 304 &(UserCommandFlag[CommNo]._FmapdpFlag_z), 344 dummy ,dummy2);305 dummy); 345 306 346 307 if(strcmp(dummy, "true") == 0) … … 349 310 UserCommandFlag[CommNo]._FmapdpFlag_diffusion = false; 350 311 351 if(strcmp(dummy2, "true") == 0)352 UserCommandFlag[CommNo]._FmapdpFlag_printloss = true;353 else if(strcmp(dummy2, "false") == 0)354 UserCommandFlag[CommNo]._FmapdpFlag_printloss = false;355 else356 UserCommandFlag[CommNo]._FmapdpFlag_printloss = false;357 358 359 cout << "debug: " << line << endl;360 cout << "dummy2 = " << dummy2 << " lossflag = " << UserCommandFlag[CommNo]._FmapdpFlag_printloss << endl;361 362 312 // FmapdpFlag = true; 363 313 strcpy(UserCommandFlag[CommNo].CommandStr,name); … … 585 535 exit_(1); 586 536 } 587 }537 } 588 538 /* continue read in the line */ 589 539 else 590 continue; 591 }//end of while loop 592 593 free(line); 594 540 continue; 541 } 595 542 fclose(inf); 596 543 } -
branches/tracy3-3.10.1b/tracy/tracy/src/soleillib.cc
r11 r23 25 25 none 26 26 27 28 27 Global variables: 29 28 trace … … 38 37 void Get_Disp_dp(void) 39 38 { 40 long i =0L;39 long i; 41 40 // long lastpos = 0; 42 41 const char nomfic[] = "dispersion.out"; … … 96 95 { 97 96 Vector x1; /* tracking coordinates */ 98 long i = 0L, k = 0L, imax = 50 L;97 long i = 0L, k = 0L, imax = 50; 99 98 FILE * outf; 100 99 double dP = 0.0, dP20 = 0.0, dpmax = 0.06; 101 100 Vector2 amp = {0.0, 0.0}, H = {0.0, 0.0}; 102 101 const char nomfic[] = "amp_ind.out"; 103 long lastpos = 0 L;102 long lastpos = 0; 104 103 CellType Celldebut, Cell; 105 104 Vector codvector[Cell_nLocMax]; … … 201 200 { 202 201 CellType Cell; 203 long i =0L;202 long i; 204 203 Vector2 H; 205 204 … … 252 251 { 253 252 CellType Cell; 254 long i =0L;253 long i; 255 254 long lastpos = 1L; 256 255 Vector2 H; … … 462 461 See also LoadApers in nsrl-ii.cc 463 462 J.Zhang 07/10 soleil 464 465 (1) 15/10/2013 Jianfeng Zhang @ LAL466 Replace fgets() by getline() to fix the bug467 to read arbritrary line length.468 463 ****************************************************************************/ 469 464 void ReadCh(const char *AperFile) 470 465 { 471 char Name1[max_str], Name2[max_str]; 472 char *line = NULL; 473 size_t len = 0; 474 ssize_t read; 466 char in[max_str], Name1[max_str], Name2[max_str]; 467 char *line; 475 468 int Fnum1=0, Fnum2=0, Kidnum1=0, Kidnum2=0, k1=0, k2=0; 476 469 int i=0, j=0,LineNum=0; … … 480 473 481 474 fp = file_read(AperFile); 482 if(fp == NULL){ 483 printf("ReadCh(): Error! Failure to read file %s\n", AperFile); 484 exit_(1); 485 } 486 487 printf("\n Loading and setting vacuum apertures to lattice elements...\n"); 488 489 while ((read=getline(&line, &len, fp)) != -1) { 490 491 /* count the line number that has been read*/ 492 LineNum++; 493 if(!prt){ 494 printf("Line # %ld : \n",LineNum); 495 printf("Retrieved line of length %zu :\n",read); 496 printf("%s\n",line); 497 } 498 475 476 printf("\n"); 477 printf("Loading and setting vacuum apertures to lattice elements...\n"); 478 479 while (line=fgets(in, max_str, fp)) { 480 /* kill preceding whitespace generated by "table" key 481 or "space" key, but leave \n 482 so we're guaranteed to have something*/ 483 while(*line == ' ' || *line == '\t') { 484 line++; 485 } 486 /* count the line number that has been read*/ 487 LineNum++; 499 488 /* NOT read comment line or blank line with the end of line symbol '\n','\r' or '\r\n'*/ 500 if (strstr(line, "#") == NULL && line[0] != '\n'&&501 line[0] != '\r'&&strcmp(line,"\r\n") != 0)489 if (strstr(line, "#") == NULL && strcmp(line,"\n") != 0 && 490 strcmp(line,"\r") != 0 &&strcmp(line,"\r\n") != 0) 502 491 /* read the aperture setting */ 503 492 { … … 570 559 // printf("%s", line); 571 560 } 572 free(line);573 561 fclose(fp); 574 562 // turn on the global flag for CheckAmpl() … … 617 605 bool lostF = true; /* Lost particle Flag */ 618 606 Vector x1; /* tracking coordinates */ 619 long i =0L;607 long i; 620 608 Vector2 aperture; 621 609 aperture[0] = 1e0; aperture[1] = 1e0; … … 811 799 #undef nterm 812 800 813 /******************************************************************************* 814 * 815 * 816 * 817 * 818 ******************************************************************************/ 801 819 802 double get_D(const double df_x, const double df_y) 820 803 { 821 double D =0.0;804 double D; 822 805 823 806 const double D_min = -2.0, D_max = -10.0; … … 851 834 Input: 852 835 FmapFile file to save calculated frequency map analysis 853 Nbx horizontal step number 854 Nby vertical step number 855 xmax horizontal maximum amplitude 856 zmax vertical maximum amplitude 857 Nbtour number of turn for tracking 858 energy particle energy offset 859 diffusion flag to calculate tune diffusion/ tune 860 difference between the first Nbtour and last Nbtour 836 Nbx horizontal step number 837 Nby vertical step number 838 xmax horizontal maximum amplitude 839 zmax vertical maximum amplitude 840 Nbtour number of turn for tracking 841 energy particle energy offset 861 842 matlab set file print format for matlab post-process; specific for nsrl-ii 862 843 863 844 Output: 864 status 2true if stable845 status true if stable 865 846 false otherwise 866 847 … … 895 876 int nb_freq[2] = {0, 0}; 896 877 long nturn = Nbtour; 897 bool status 2= true;878 bool status = true; 898 879 struct tm *newtime; 899 880 … … 946 927 // z = z0 + sgn(j)*sqrt((double)abs(j))*zstep; 947 928 // tracking around closed orbit 948 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status 2);949 if (status 2) { // if trajectory is stable929 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status); 930 if (status) { // if trajectory is stable 950 931 // gets frequency vectors 951 932 Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); … … 993 974 #undef NTERM2 994 975 995 /****************************************************************************/996 /* void fmap(const char *FmapFile, long Nbx, long Nbz, long Nbtour, double xmax, double zmax,997 double energy, bool diffusion, bool loss)998 999 Purpose:1000 1001 1002 Compute a frequency map of Nbx x Nbz points1003 For each set of initial conditions the particle is tracked over1004 Nbtour for an energy offset dp1005 1006 Frequency map is based on fixed beam energy, trace x versus z,1007 or, tracking transverse dynamic aperture for fixed momentum1008 (usually, on-momentum) particle.1009 1010 The stepsize follows a square root law1011 1012 Results in fmap.out1013 1014 Input:1015 FmapFile file to save calculated frequency map analysis1016 Nbx horizontal step number1017 Nby vertical step number1018 xmax horizontal maximum amplitude1019 zmax vertical maximum amplitude1020 Nbtour number of turn for tracking1021 energy particle energy offset1022 diffusion flag to calculate tune diffusion/ tune1023 difference between the first Nbtour and last Nbtour1024 matlab set file print format for matlab post-process; specific for nsrl-ii1025 1026 Output:1027 status2 true if stable1028 false otherwise1029 1030 Return:1031 none1032 1033 Global variables:1034 none1035 1036 Specific functions:1037 Trac_Simple, Get_NAFF1038 1039 Comments:1040 15/10/03 run for the diffusion: nasty patch for retrieving the closed orbit1041 16/02/03 patch removed1042 19/07/11 add interface of file defined by user which is used to save calculated1043 frequency map analysis1044 1045 11/06/2013 Modified by Jianfeng Zhang @ LAL1046 The same as famp(onst char *FmapFile, long Nbx, long Nbz, long Nbtour, double xmax, double zmax,1047 double energy, bool diffusion); but with a flag to print/not print the final information of1048 the particle; if the final turn is not the "Nbtour", then the particle is lost.1049 ****************************************************************************/1050 #define NTERM2 101051 void fmap(const char *FmapFile, long Nbx, long Nbz, long Nbtour, double xmax, double zmax,1052 double energy, bool diffusion, bool printloss)1053 {1054 FILE * outf; //file with the tunes at the grid point1055 FILE *outf_loss; //file with the information of the lost particle1056 long i = 0L, j = 0L;1057 double Tab[DIM][NTURN], Tab0[DIM][NTURN];1058 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx=0.0, dfz=0.0;1059 double x = 0.0, xp = 0.0, z = 0.0, zp = 0.0;1060 double x0 = 1e-6, xp0 = 0.0, z0 = 1e-6, zp0 = 0.0;1061 const double ctau = 0.0;1062 double xstep = 0.0, zstep = 0.0;1063 double nux1 = 0.0, nuz1 = 0.0, nux2 = 0.0, nuz2 = 0.0;1064 int nb_freq[2] = {0, 0};1065 long nturn = Nbtour;1066 bool status2 = true;1067 1068 struct tm *newtime;1069 1070 //variables of the returned the tracked particle1071 long lastn = 0;1072 long lastpos = 1;1073 ss_vect<double> x1;1074 1075 1076 //if(loss){1077 char FmapLossFile[S_SIZE+5]=" ";1078 strcpy(FmapLossFile,FmapFile);1079 strcat(FmapLossFile,".loss");1080 //}1081 1082 /* Get time and date */1083 time_t aclock;1084 time(&aclock); /* Get time in seconds */1085 newtime = localtime(&aclock); /* Convert time to struct */1086 1087 if (trace) printf("Entering fmap ... results in %s\n\n",FmapFile);1088 1089 /* Opening file */1090 if ((outf = fopen(FmapFile, "w")) == NULL) {1091 fprintf(stdout, "fmap: error while opening file %s\n", FmapFile);1092 exit_(1);1093 }1094 1095 1096 fprintf(outf,"# TRACY III -- %s -- %s \n", FmapFile, asctime2(newtime));1097 fprintf(outf,"# nu = f(x) \n");1098 // fprintf(outf,"# x[mm] z[mm] fx fz"1099 // " dfx dfz D=log_10(sqrt(df_x^2+df_y^2))\n");1100 //1101 fprintf(outf,"# x[m] z[m] fx fz"1102 " dfx dfz\n");1103 1104 1105 //file with lost particle information1106 if(printloss){1107 1108 if ((outf_loss = fopen(FmapLossFile, "w")) == NULL) {1109 fprintf(stdout, "fmap: error while opening file %s\n", FmapLossFile);1110 exit_(1);1111 }1112 1113 fprintf(outf_loss,"# TRACY III -- %s -- %s \n", FmapLossFile, asctime2(newtime));1114 fprintf(outf_loss,"# information of the lost particle: "1115 " lostp = 0 (no particle lost /1(horizontal) /2(vertical) /3(longitudinal) plane) \n");1116 1117 fprintf(outf_loss,"# x[m] z[m] Nturn lostp S[m] x[m]"1118 " xp[rad] z[m] zp[rad] delta ctau\n");1119 }1120 1121 if ((Nbx < 1) || (Nbz < 1))1122 fprintf(stdout,"fmap: Error Nbx=%ld Nbz=%ld\n",Nbx,Nbz);1123 1124 // steps in both planes1125 xstep = xmax/sqrt((double)Nbx);1126 zstep = zmax/sqrt((double)Nbz);1127 1128 // double number of turn if diffusion to compute1129 if (diffusion) nturn = 2*Nbtour;1130 1131 // px and pz zeroed1132 xp = xp0;1133 zp = zp0;1134 1135 // Tracking part + NAFF1136 for (i = 0; i <= Nbx; i++) {1137 x = x0 + sqrt((double)i)*xstep;1138 // for (i = -Nbx; i <= Nbx; i++) {1139 // x = x0 + sgn(i)*sqrt((double)abs(i))*xstep;1140 // if (!matlab) fprintf(outf,"\n");1141 fprintf(stdout,"\n");1142 for (j = 0; j<= Nbz; j++) {1143 z = z0 + sqrt((double)j)*zstep;1144 // for (j = -Nbz; j<= Nbz; j++) {1145 // z = z0 + sgn(j)*sqrt((double)abs(j))*zstep;1146 1147 //print out the lost information1148 if(printloss)1149 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,lastn, lastpos, x1, &status2);1150 else1151 // tracking around closed orbit1152 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status2);1153 1154 if (status2) { // if trajectory is stable1155 // gets frequency vectors1156 Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);1157 Get_freq(fx,fz,&nux1,&nuz1); // gets nux and nuz1158 if (diffusion) { // diffusion1159 // shift data for second round NAFF1160 Get_Tabshift(Tab,Tab0,Nbtour,Nbtour);1161 // gets frequency vectors1162 Get_NAFF(NTERM2, Nbtour, Tab0, fx2, fz2, nb_freq);1163 Get_freq(fx2,fz2,&nux2,&nuz2); // gets nux and nuz1164 }1165 } // unstable trajectory1166 else { //zeroing output1167 nux1 = 0.0; nuz1 = 0.0;1168 nux2 = 0.0; nuz2 = 0.0;1169 }1170 1171 // printout value1172 if (!diffusion){1173 // fprintf(outf,"%14.6e %14.6e %14.6e %14.6e\n",1174 // 1e3*x, 1e3*z, nux1, nuz1);1175 // fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e\n",1176 // 1e3*x, 1e3*z, nux1, nuz1);1177 fprintf(outf,"%10.6e %10.6e %10.6e %10.6e\n",1178 x, z, nux1, nuz1);1179 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e\n",1180 x, z, nux1, nuz1);1181 }1182 else {1183 dfx = nux1 - nux2; dfz = nuz1 - nuz2;1184 fprintf(outf,"%10.6e %10.6e %10.6e %10.6e %10.6e %10.6e\n",1185 x, z, nux1, nuz1, dfx, dfz);1186 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %14.6e %14.6e\n",1187 x, z, nux1, nuz1, dfx, dfz);1188 }1189 1190 //print out the information of the lost particle1191 if(printloss)1192 fprintf(outf_loss, "%6.3e %6.3e %8ld %3d %+12.6f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f \n",1193 x, z, lastn,status.lossplane, Cell[lastpos].S, x1[0],x1[1],1194 x1[2], x1[3], x1[4], x1[5]);1195 1196 }1197 }1198 1199 fclose(outf);1200 if(printloss)1201 fclose(outf_loss);1202 }1203 #undef NTERM21204 1205 976 1206 977 /****************************************************************************/ … … 1253 1024 #define NTERM2 10 1254 1025 void fmap_p(const char *FmapFile_p, long Nbx, long Nbz, long Nbtour, double xmax, 1255 double zmax, double energy, bool diffusion, bool printloss,int numprocs, int myid)1026 double zmax, double energy, bool diffusion, int numprocs, int myid) 1256 1027 { 1257 1028 FILE * outf; 1258 FILE *outf_loss; //file with the information of the lost particle1259 1029 long i = 0L, j = 0L; 1260 1030 double Tab[DIM][NTURN], Tab0[DIM][NTURN]; 1261 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx =0.0, dfz=0.0;1031 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx, dfz; 1262 1032 double x = 0.0, xp = 0.0, z = 0.0, zp = 0.0; 1263 1033 double x0 = 1e-6, xp0 = 0.0, z0 = 1e-6, zp0 = 0.0; … … 1267 1037 int nb_freq[2] = {0, 0}; 1268 1038 long nturn = Nbtour; 1269 bool status 2= true;1039 bool status = true; 1270 1040 struct tm *newtime; 1271 1041 … … 1274 1044 strcat(FmapFile,FmapFile_p); 1275 1045 printf("%s\n",FmapFile); 1276 1277 //variables of the returned the tracked particle1278 long lastn = 0;1279 long lastpos = 1;1280 ss_vect<double> x1;1281 1282 char FmapLossFile[S_SIZE+5]=" ";1283 strcpy(FmapLossFile,FmapFile);1284 strcat(FmapLossFile,".loss");1285 1286 1046 1287 1047 /* Get time and date */ … … 1299 1059 } 1300 1060 1301 //file with lost particle information1302 if(printloss){1303 if ((outf_loss = fopen(FmapLossFile, "w")) == NULL) {1304 fprintf(stdout, "fmap: error while opening file %s\n", FmapLossFile);1305 exit_(1);1306 }1307 }1308 1309 1061 if(myid==0) 1310 1062 { … … 1312 1064 fprintf(outf,"# nu = f(x) \n"); 1313 1065 fprintf(outf,"# x[m] z[m] fx fz dfx dfz\n"); 1314 1315 if(printloss){ 1316 fprintf(outf_loss,"# TRACY III -- %s -- %s \n", FmapLossFile, asctime2(newtime)); 1317 fprintf(outf_loss,"# information of the lost particle: " 1318 " lostp = 0 (no particle lost /1(horizontal) /2(vertical) /3(longitudinal) plane) \n"); 1319 1320 fprintf(outf_loss,"# x[m] z[m] Nturn lostp S[m] x[m]" 1321 " xp[rad] z[m] zp[rad] delta ctau\n"); 1322 } 1323 } 1066 } 1324 1067 1325 1068 if ((Nbx < 1) || (Nbz < 1)) … … 1370 1113 1371 1114 // tracking around closed orbit 1372 if(printloss) 1373 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,lastn, lastpos, x1, &status2); 1374 else 1375 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status2); 1376 1377 1378 if (status2) // if trajectory is stable 1115 Trac_Simple4DCOD(x,xp,z,zp,energy,ctau,nturn,Tab,&status); 1116 if (status) // if trajectory is stable 1379 1117 { 1380 1118 // gets frequency vectors … … 1410 1148 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %14.6e %14.6e\n", x, z, nux1, nuz1, dfx, dfz); 1411 1149 } 1412 1413 //print out the information of the lost particle1414 if(printloss)1415 fprintf(outf_loss, "%6.3e %6.3e %8ld %3d %+12.6f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f \n",1416 x, z, lastn,status.lossplane, Cell[lastpos].S, x1[0],x1[1],1417 x1[2], x1[3], x1[4], x1[5]);1418 1150 } 1419 1151 } 1420 1152 1421 1153 fclose(outf); 1422 1423 if(printloss)1424 fclose(outf_loss);1425 1426 1154 } 1427 1155 #undef NTERM2 … … 1453 1181 emax maximum energy 1454 1182 z vertical amplitude 1455 diffusion flag to calculate tune diffusion/ tune 1456 difference between the first Nbtour and last Nbtour 1183 diffusion flag to calculate tune diffusion 1457 1184 matlab set file print format for matlab post-process; specific for nsrl-ii 1458 1185 Output: 1459 status 2true if stable1186 status true if stable 1460 1187 false otherwise 1461 1188 … … 1474 1201 is negative for negative enrgy offset since this is true for the cod 1475 1202 19/07/11 add features to save calculated fmapdp in the user defined file 1476 1477 18/06/2013 by Jianfeng Zhang @ LAL1478 1479 Add bool flag to print out the last information of the tracked particle1480 1203 ****************************************************************************/ 1481 1204 #define NTERM2 10 1482 1205 void fmapdp(const char *FmapdpFile, long Nbx, long Nbe, long Nbtour, double xmax, double emax, 1483 double z, bool diffusion , bool printloss)1206 double z, bool diffusion) 1484 1207 { 1485 1208 FILE * outf; 1486 FILE *outf_loss; //file with the information of the lost particle1487 1209 long i = 0L, j = 0L; 1488 1210 double Tab[DIM][NTURN], Tab0[DIM][NTURN]; 1489 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx =0.0, dfz=0.0;1211 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx, dfz; 1490 1212 double x = 0.0, xp = 0.0, zp = 0.0, dp = 0.0, ctau = 0.0; 1491 1213 double x0 = 1e-6, xp0 = 0.0, zp0 = 0.0; … … 1495 1217 int nb_freq[2] = {0, 0}; 1496 1218 long nturn = Nbtour; 1497 bool status 2=true;1219 bool status=true; 1498 1220 struct tm *newtime; 1499 1500 //variables of the returned the tracked particle1501 long lastn = 0;1502 long lastpos = 1;1503 ss_vect<double> x1;1504 1505 char FmapdpLossFile[S_SIZE+5]=" ";1506 strcpy(FmapdpLossFile,FmapdpFile);1507 strcat(FmapdpLossFile,".loss");1508 1221 1509 1222 /* Get time and date */ … … 1514 1227 if (diffusion && globval.Cavity_on == false) nturn = 2*Nbtour; 1515 1228 1516 if (trace) printf("Entering fmap dp... results in %s\n\n",FmapdpFile);1229 if (trace) printf("Entering fmap ... results in %s\n\n",FmapdpFile); 1517 1230 1518 1231 /* Opening file */ … … 1527 1240 fprintf(outf,"# dp[m] x[m] fx fz dfx dfz\n"); 1528 1241 1529 1530 //file with lost particle information1531 if(printloss){1532 1533 if ((outf_loss = fopen(FmapdpLossFile, "w")) == NULL) {1534 fprintf(stdout, "fmapdp: error while opening file %s\n", FmapdpLossFile);1535 exit_(1);1536 }1537 1538 fprintf(outf_loss,"# TRACY III -- %s -- %s \n", FmapdpLossFile, asctime2(newtime));1539 fprintf(outf_loss,"# information of the lost particle: "1540 " lostp = 0 (no particle lost /1(horizontal) /2(vertical) /3(longitudinal) plane) \n");1541 1542 fprintf(outf_loss,"# dp x[m] Nturn lostp S[m] x[m]"1543 " xp[rad] z[m] zp[rad] delta ctau\n");1544 }1545 1546 1242 if ((Nbx <= 1) || (Nbe <= 1)) 1547 1243 fprintf(stdout,"fmapdp: Error Nbx=%ld Nbe=%ld\n",Nbx,Nbe); … … 1566 1262 diffusion = false; 1567 1263 } 1568 else {1264 else 1569 1265 // x = x0 + sgn(j)*sqrt((double)abs(j))*xstep; 1570 1266 x = x0 + sqrt((double)j)*xstep; 1571 } 1572 1573 if(printloss) 1574 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,nturn,Tab,lastn, lastpos, x1, &status2); 1575 else 1576 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,nturn,Tab,&status2); 1577 1578 if (status2) { 1267 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,nturn,Tab,&status); 1268 if (status) { 1579 1269 Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); 1580 1270 Get_freq(fx,fz,&nux1,&nuz1); // gets nux and nuz … … 1610 1300 dp, x, nux1, nuz2, dfx, dfz); 1611 1301 } 1612 1613 if(printloss)1614 fprintf(outf_loss," %-+8.3f %-+8.3f %-8ld %2d %+12.3f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f \n",1615 dp, x, lastn,status.lossplane, Cell[lastpos].S, x1[0],x1[1], x1[2], x1[3], x1[4], x1[5]);1616 1617 1302 } 1618 1303 } 1619 1304 1620 1305 fclose(outf); 1621 1622 if(printloss)1623 fclose(outf_loss);1624 1306 } 1625 1307 #undef NTERM2 … … 1656 1338 1657 1339 Output: 1658 status 2true if stable1340 status true if stable 1659 1341 false otherwise 1660 1342 … … 1671 1353 14/11/2011 add features to parallel calculate fmapdp. 1672 1354 Merged with the version written by Mao-sen Qiu at Taiwan light source. 1673 1674 18/06/2013 by Jianfeng Zhang @ LAL1675 Add bool flag to print out the last information of the tracked particle1676 1355 ****************************************************************************/ 1677 1356 #define NTERM2 10 1678 1357 void fmapdp_p(const char *FmapdpFile_p, long Nbx, long Nbe, long Nbtour, double xmax, 1679 double emax, double z, bool diffusion, bool printloss,int numprocs, int myid)1358 double emax, double z, bool diffusion, int numprocs, int myid) 1680 1359 { 1681 1360 FILE * outf; 1682 FILE *outf_loss; //file with the information of the lost particle1683 1361 long i = 0L, j = 0L; 1684 1362 double Tab[DIM][NTURN], Tab0[DIM][NTURN]; 1685 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx =0.0, dfz=0.0;1363 double fx[NTERM2], fz[NTERM2], fx2[NTERM2], fz2[NTERM2], dfx, dfz; 1686 1364 double x = 0.0, xp = 0.0, zp = 0.0, dp = 0.0, ctau = 0.0; 1687 1365 double x0 = 1e-6, xp0 = 0.0, zp0 = 0.0; … … 1691 1369 int nb_freq[2] = {0, 0}; 1692 1370 long nturn = Nbtour; 1693 bool status 2=true;1371 bool status=true; 1694 1372 struct tm *newtime; 1695 1373 … … 1699 1377 printf("%s\n",FmapdpFile); 1700 1378 1701 //variables of the returned the tracked particle1702 long lastn = 0;1703 long lastpos = 1;1704 ss_vect<double> x1;1705 1706 char FmapdpLossFile[S_SIZE+5]=" ";1707 strcpy(FmapdpLossFile,FmapdpFile);1708 strcat(FmapdpLossFile,".loss");1709 1710 1379 /* Get time and date */ 1711 1380 time_t aclock; … … 1721 1390 fprintf(stdout, "fmapdp: error while opening file %s\n", FmapdpFile); 1722 1391 exit_(1); 1723 }1724 1725 if(printloss){1726 if ((outf_loss = fopen(FmapdpLossFile, "w")) == NULL) {1727 fprintf(stdout, "fmapdp: error while opening file %s\n", FmapdpLossFile);1728 exit_(1);1729 }1730 1392 } 1731 1393 … … 1736 1398 // fprintf(outf,"# dp[%%] x[mm] fx fz dfx dfz\n"); 1737 1399 fprintf(outf,"# dp[m] x[m] fx fz dfx dfz\n"); 1738 1739 1740 if(printloss){ 1741 fprintf(outf_loss,"# TRACY III -- %s -- %s \n", FmapdpLossFile, asctime2(newtime)); 1742 fprintf(outf_loss,"# information of the lost particle: " 1743 " lostp = 0 (no particle lost /1(horizontal) /2(vertical) /3(longitudinal) plane) \n"); 1744 1745 fprintf(outf_loss,"# dp x[m] Nturn lostp S[m] x[m]" 1746 " xp[rad] z[m] zp[rad] delta ctau\n"); 1747 } 1748 } 1400 } 1749 1401 1750 1402 if ((Nbx <= 1) || (Nbe <= 1)) … … 1796 1448 diffusion = false; 1797 1449 } 1798 else {1450 else 1799 1451 // x = x0 + sgn(j)*sqrt((double)abs(j))*xstep; 1800 1452 x = x0 + sqrt((double)j)*xstep; 1801 } 1802 1803 if(printloss) 1804 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,nturn,Tab,lastn, lastpos, x1, &status2); 1805 else 1806 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,nturn,Tab,&status2); 1807 1808 if (status2) { 1453 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,nturn,Tab,&status); 1454 if (status) { 1809 1455 Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); 1810 1456 Get_freq(fx,fz,&nux1,&nuz1); // gets nux and nuz … … 1840 1486 dp, x, nux1, nuz2, dfx, dfz); 1841 1487 } 1842 1843 if(printloss)1844 fprintf(outf_loss," %-+8.3f %-+8.3f %-8ld %2d %+12.3f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f %+10.6f \n",1845 dp, x, lastn,status.lossplane, Cell[lastpos].S, x1[0],x1[1], x1[2], x1[3], x1[4], x1[5]);1846 1847 1488 } 1848 1489 } 1849 1490 1850 1491 fclose(outf); 1851 1852 if(printloss)1853 fclose(outf_loss);1854 1492 } 1855 1493 #undef NTERM2 … … 1897 1535 double nux1 = 0.0, nuz1 = 0.0; 1898 1536 int nb_freq[2] = {0, 0}; 1899 bool status 2= true;1537 bool status = true; 1900 1538 struct tm *newtime; 1901 1539 … … 1929 1567 ctau = ctau0; 1930 1568 1931 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,Nbtour,Tab,&status 2); // tracking around closed orbit1932 if (status 2) {1569 Trac_Simple4DCOD(x,xp,z,zp,dp,ctau,Nbtour,Tab,&status); // tracking around closed orbit 1570 if (status) { 1933 1571 Get_NAFF(NTERM, Nbtour, Tab, fx, fz, nb_freq); // get frequency vectors 1934 1572 Get_freq(fx,fz,&nux1,&nuz1); // gets nux and nuz … … 1936 1574 else { 1937 1575 nux1 = 0.0; nuz1 = 0.0; 1938 status 2= true;1576 status = true; 1939 1577 } 1940 1578 … … 1991 1629 FILE *outf; 1992 1630 const char *fic = phasefile; 1993 int i =0;1994 bool status 2=false;1631 int i; 1632 bool status; 1995 1633 struct tm *newtime; 1996 1634 … … 2025 1663 } 2026 1664 2027 Trac_Simple6DCOD(x,xp,y,yp,energy,ctau,Nbtour,Tab,&status2); 2028 1665 Trac_Simple6DCOD(x,xp,y,yp,energy,ctau,Nbtour,Tab,&status); 2029 1666 for (i = 0; i < Nbtour; i++) { 2030 1667 fprintf(outf,"% .5e % .5e % .5e % .5e % .5e % .5e\n", 2031 1668 Tab[0][i],Tab[1][i],Tab[2][i],Tab[3][i],Tab[4][i],Tab[5][i]); 2032 1669 } 2033 // cout << "status is: " << status2 << endl;2034 1670 fclose(outf); 2035 1671 } … … 2069 1705 FILE *outf; 2070 1706 const char *fic="phasepoly.out"; 2071 long lastpos = 0 L,lastn = 0L;2072 int i =0,j=0;2073 double x =0.0, z=0.0, px=0.0, pz=0.0, delta=0.0, ctau=0.0;1707 long lastpos = 0,lastn = 0; 1708 int i,j; 1709 double x, z, px, pz, delta, ctau; 2074 1710 double ex = 1368E-9, el = 1.78E-4; 2075 1711 double betax = 9.0, /*betaz = 8.2, */betal = 45.5; … … 2163 1799 double start = 0.0, step = 0.0; 2164 1800 double x = 0.0, px = 0.0, z = 0.0, pz = 0.0, delta = 0.0, ctau = 0.0; 2165 bool status 2= true;1801 bool status = true; 2166 1802 struct tm *newtime; 2167 1803 … … 2222 1858 fprintf(stdout,"% .5e % .5e % .5e % .5e % .5e % .5e\n", 2223 1859 x,px,z,pz,delta,ctau); 2224 Trac_Simple4DCOD(x,px,z,pz,delta,ctau,Nbtour,Tab,&status 2);1860 Trac_Simple4DCOD(x,px,z,pz,delta,ctau,Nbtour,Tab,&status); 2225 1861 for (i = 0; i < Nbtour; i++) { 2226 1862 fprintf(outf,"% .5e % .5e % .5e % .5e % .5e % .5e\n", … … 2265 1901 FILE *outf; 2266 1902 const char fic[] = "check_ampl.out"; 2267 int i =0;1903 int i; 2268 1904 2269 1905 if ((outf = fopen(fic, "w")) == NULL) … … 2320 1956 FILE *outf; 2321 1957 const char fic[] = "enveloppe.out"; 2322 int i =0,j=0;1958 int i,j ; 2323 1959 CellType Cell; 2324 1960 … … 3562 3198 FILE *fi; 3563 3199 const char fic_skew[] = "QT-solamor_2_3.dat"; 3564 int i =0;3200 int i; 3565 3201 double theta[500]; /* array for skew quad tilt*/ 3566 double b2 =0.0, mKL=0.0;3202 double b2, mKL; 3567 3203 CellType Cell; 3568 long mOrder =0L;3204 long mOrder; 3569 3205 3570 3206 int nquad = 0; /* Number of skew quadrupoles */ … … 3767 3403 struct tm *newtime; // for time 3768 3404 Vector codvector[Cell_nLocMax]; 3769 bool cavityflag =false, radiationflag=false;3405 bool cavityflag, radiationflag; 3770 3406 bool trace=true; 3771 3407 … … 4165 3801 struct tm *newtime; // for time 4166 3802 Vector codvector[Cell_nLocMax]; 4167 bool cavityflag =false, radiationflag=false;3803 bool cavityflag, radiationflag; 4168 3804 bool trace=true; 4169 3805 … … 4650 4286 const char xfic[] = "xspectrum.out"; 4651 4287 const char zfic[] = "zspectrum.out"; 4652 long i =0L, j=0L, k=0L;4288 long i, j, k; 4653 4289 #define nterm2 20 4654 4290 double Tab[6][NTURN], fx[nterm2], fz[nterm2], fx2[nterm2], fz2[nterm2]; … … 4658 4294 int nb_freq[2] = {0, 0}; 4659 4295 long nturn = Nbtour; 4660 bool status 2=true;4296 bool status=true; 4661 4297 struct tm *newtime; 4662 4298 … … 4699 4335 for (j = 0; j<= Nbz; j++) { 4700 4336 z = z0 + sqrt((double)j)*zstep; 4701 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status 2);4702 if (status 2) {4337 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status); 4338 if (status) { 4703 4339 Get_NAFF(nterm2, Nbtour, Tab, fx, fz, nb_freq); 4704 4340 } … … 4779 4415 long nmax, long pos, long &lastn, long &lastpos, FILE *outf1) 4780 4416 { 4781 bool lostF =false; /* Lost particle Flag */4417 bool lostF; /* Lost particle Flag */ 4782 4418 Vector x1; /* tracking coordinates */ 4783 4419 Vector2 aperture; … … 4792 4428 getelem(pos-1,&Cell); 4793 4429 4794 if ( trace) printf("dp= % .5e %% xcod= % .5e mm zcod= % .5e mm \n",4430 if (!trace) printf("dp= % .5e %% xcod= % .5e mm zcod= % .5e mm \n", 4795 4431 dp*1e2, Cell.BeamPos[0]*1e3, Cell.BeamPos[2]*1e3); 4796 4432 … … 4863 4499 CellType Cell; 4864 4500 int qlist[320]; 4865 int nquad=0, i =0;4501 int nquad=0, i; 4866 4502 double A = 0.0; 4867 4503 … … 4897 4533 /****************************************************************************/ 4898 4534 /* void fmapfull(long Nbx, long Nbz, long Nbtour, double xmax, double zmax, 4899 double energy, bool *status 2)4535 double energy, bool *status) 4900 4536 4901 4537 Purpose: … … 4917 4553 4918 4554 Output: 4919 status 2true if stable4555 status true if stable 4920 4556 false otherwise 4921 4557 … … 4939 4575 FILE * outf; 4940 4576 const char fic[] = "fmapfull.out"; 4941 int i =0, j=0, k=0;4577 int i, j, k; 4942 4578 double Tab[DIM][NTURN], Tab0[DIM][NTURN]; 4943 4579 double fx[NTERM], fz[NTERM], fx2[NTERM], fz2[NTERM]; … … 4948 4584 double nux1[NTERM], nuz1[NTERM],nux2[NTERM], nuz2[NTERM]; 4949 4585 long nturn = Nbtour; 4950 bool status 2=true;4586 bool status=true; 4951 4587 struct tm *newtime; 4952 4588 char name[14]; … … 5008 4644 for (j = 0; j<= Nbz; j++) { 5009 4645 z = z0 + sqrt((double)j)*zstep; 5010 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status 2);5011 5012 if (status 2) {4646 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status); 4647 4648 if (status) { 5013 4649 Get_NAFF(NTERM, Nbtour, Tab, fx, fz, nb_freq); 5014 4650 … … 5091 4727 /****************************************************************************/ 5092 4728 /* void Dyna(long Nbx, long Nbz, long Nbtour, double xmax, double zmax, 5093 double energy, bool *status 2)4729 double energy, bool *status) 5094 4730 5095 4731 Purpose: … … 5111 4747 5112 4748 Output: 5113 status 2true if stable4749 status true if stable 5114 4750 false otherwise 5115 4751 … … 5133 4769 FILE * outf; 5134 4770 const char fic[] = "dyna.out"; 5135 long i =0, j=0;4771 long i, j; 5136 4772 double Tab[6][NTURN], fx[NTERM2], fz[NTERM2]; 5137 4773 double x = 0.0, xp = 0.0, z = 0.0, zp = 0.0; … … 5140 4776 int nb_freq[2] = {0, 0}; 5141 4777 long nturn = Nbtour; 5142 bool status 2=true;4778 bool status=true; 5143 4779 struct tm *newtime; 5144 4780 … … 5174 4810 for (j = 0; j<= Nbz; j++) { 5175 4811 z = z0 + sqrt((double)j)*zstep; 5176 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status 2);5177 if (status 2) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);4812 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status); 4813 if (status) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); 5178 4814 else { 5179 4815 fx[0] = 0.0; fz[0] = 0.0; 5180 4816 } 5181 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status 2);5182 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status 2);4817 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status); 4818 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status); 5183 4819 if (diffusion) { 5184 if (status 2) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);5185 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status 2);5186 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status 2);4820 if (status) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); 4821 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status); 4822 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status); 5187 4823 } 5188 4824 } … … 5196 4832 for (j = 0; j<= Nbz; j++) { 5197 4833 z = z0 + sqrt((double)j)*zstep; 5198 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status 2);5199 if (status 2) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);4834 Trac_Simple4DCOD(x,xp,z,zp,energy,0.0,nturn,Tab,&status); 4835 if (status) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); 5200 4836 else { 5201 4837 fx[0] = 0.0; fz[0] =0.0; 5202 4838 } 5203 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status 2);5204 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status 2);4839 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status); 4840 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e %d\n", x, z, fx[0], fz[0], status); 5205 4841 if (diffusion) { 5206 if (status 2) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq);4842 if (status) Get_NAFF(NTERM2, Nbtour, Tab, fx, fz, nb_freq); 5207 4843 fprintf(outf,"%14.6e %14.6e %14.6e %14.6e\n", x, z, fx[0], fz[0]); 5208 4844 fprintf(stdout,"%14.6e %14.6e %14.6e %14.6e\n", x, z, fx[0], fz[0]); … … 5247 4883 FILE *outf; 5248 4884 const char fic[] = "phase2.out"; 5249 long lastpos = 0 L,lastn = 0L;4885 long lastpos = 0,lastn = 0; 5250 4886 struct tm *newtime; 5251 4887 … … 5373 5009 int i,j; 5374 5010 bool chroma=true, trace=false; 5375 bool radiationflag =false, cavityflag=false;5011 bool radiationflag, cavityflag; 5376 5012 double dP = 0.0; 5377 5013 double diffcmu = 0.0, /* cos(mu1) - cos(mu2)*/ … … 5795 5431 void PhaseLongitudinalHamiltonien(void) 5796 5432 { 5797 long i =0L,j=0L;5433 long i,j; 5798 5434 const double t = T; // To get a one turn map 5799 double phi =0.0, delta=0.0, H0=0.0;5435 double phi, delta, H0; 5800 5436 long imax = 1000L, // turn number 5801 5437 jmax = 25L; // starting condition number … … 5993 5629 } 5994 5630 5995 /******************************************************************************* 5996 * 5997 * 5998 * 5999 * 6000 ******************************************************************************/ 5631 6001 5632 double EnergySmall(double *X, double irho) 6002 5633 { 6003 double A =0.0, B=0.0;5634 double A, B; 6004 5635 double h = irho; 6005 5636 … … 6008 5639 return (A+B); 6009 5640 } 6010 /******************************************************************************* 6011 * 6012 * 6013 * 6014 * 6015 ******************************************************************************/ 5641 6016 5642 double EnergyDrift(double *X) 6017 5643 { 6018 double A =0.0;5644 double A; 6019 5645 6020 5646 A = (X[1]*X[1]+X[3]*X[3])/2.0/(1.0+X[4]); … … 6055 5681 FILE *outf; 6056 5682 const char fic[] = "enveloppe2.out"; 6057 int i =0,j=0;5683 int i,j ; 6058 5684 CellType Cell; 6059 5685 /* Array for Enveloppes */ … … 6185 5811 void set_RFVoltage(const int Fnum, const double V_RF){ 6186 5812 6187 int k =0, n = 0;5813 int k, n = 0; 6188 5814 6189 5815 … … 6232 5858 01/2011 Fix the bug for reading the end of line symbol "\n" , "\r",'\r\n' 6233 5859 at different operation system 6234 04/2011 Change the set of 'seed' for rms error in file, now it's mandatory. 6235 10/2013 Jianfeng Zhang @ LAL 6236 Fix the bug of fgets() to read lines of arbritrary length. 5860 04/2011 Change the set of 'seed' for rms error in file, now it's mandatory. 6237 5861 *****************************************************************************************************/ 6238 5862 void ReadFieldErr(const char *FieldErrorFile) 6239 5863 { 6240 bool rms=false, set_rnd = false; 6241 char name[max_str],keywrd[max_str], *prm; 6242 char *line = NULL; 6243 size_t len = 0; 6244 ssize_t read; 5864 bool rms, set_rnd = false; 5865 char in[max_str], name[max_str],keywrd[max_str], *prm; 5866 char *line; 6245 5867 int n = 0; /* field error order*/ 6246 5868 int LineNum = 0; 6247 int seed_val = 0; // random seed number for the rms error5869 int seed_val; // random seed number for the rms error 6248 5870 double Bn = 0.0, An = 0.0, r0 = 0.0; /* field error components and radius when the field error is measured */ 6249 5871 /* conversion number from A to T.m for soleil*/ … … 6254 5876 6255 5877 inf = file_read(FieldErrorFile); 6256 if(inf == NULL){ 6257 printf("ReadFieldErr(): Error! Failure to read file %s !\n",FieldErrorFile); 6258 exit_(1); 6259 } 6260 5878 6261 5879 printf("\n"); 6262 5880 /* read lines*/ 6263 while ((read=getline(&line, &len, inf)) != -1) { 5881 while (line=fgets(in, max_str, inf)) { 5882 5883 /* kill preceding whitespace generated by "table" key 5884 or "space" key, but leave \n 5885 so we're guaranteed to have something*/ 5886 while(*line == ' ' || *line == '\t') { 5887 line++; 5888 } 6264 5889 6265 5890 /* count line number for debug*/ 6266 5891 LineNum++; 6267 if(prt){6268 printf("Line # %ld \n",LineNum);6269 printf("Retrieved line of length %zu : \n",read);6270 printf("%s\n",line);6271 }6272 5892 6273 5893 /* check the line is whether comment line or null line*/ … … 6287 5907 /*read and assign the key words and measure radius*/ 6288 5908 sscanf(line, " %*s %s %lf",keywrd, &r0); 6289 if ( !prt) printf("\nsetting <%s> multipole error to: %-5s r0 = %7.1le\n",keywrd,name,r0);5909 if (prt) printf("\nsetting <%s> multipole error to: %-5s r0 = %7.1le\n",keywrd,name,r0); 6290 5910 6291 5911 rms = (strcmp("rms", keywrd) == 0)? true : false; … … 6311 5931 sscanf(prm, "%lf", &An); 6312 5932 6313 if ( !prt)5933 if (prt) 6314 5934 printf(" n = %2d, Bn = %9.1e, An = %9.1e\n", n, Bn, An); 6315 5935 … … 6335 5955 // printf("%s", line); 6336 5956 } 6337 free(line); 5957 6338 5958 fclose(inf); 6339 5959 } … … 6393 6013 AddFieldValues_fam(Fnum,keywrd, r0, n, Bn, An); 6394 6014 else 6395 printf(" AddFieldErrors(): Error! undefined lattice element %s !\n", name);6015 printf("SetFieldErrors: undefined element %s\n", name); 6396 6016 } 6397 6017 } … … 6674 6294 which also functions as these correctors. 6675 6295 6676 10/2010 Written by Jianfeng Zhang @ SOLEIL6296 10/2010 Written by Jianfeng Zhang 6677 6297 **********************************************************************/ 6678 6298 void AddCorrQtErr_fam(char const *fic, const int Fnum, const double conv, const char *keywrd, const double r0, … … 6682 6302 double bnL = 0.0, anL = 0.0; 6683 6303 double brho = 0.0, conv_strength = 0.0; 6684 double corr = 0.0; /* skew quadrupole horizontal or vertical corrector error, read from a file*/6304 double corr; /* skew quadrupole horizontal or vertical corrector error, read from a file*/ 6685 6305 int corrlistThick[120]; /* index of associated sextupole*/ 6686 6306 … … 6798 6418 void FitTune4(long qf1,long qf2, long qd1, long qd2, double nux, double nuy) 6799 6419 { 6800 long i =0L;6420 long i; 6801 6421 iVector2 nq1 = {0,0},nq2 = {0,0}, nq={0,0}; 6802 6422 Vector2 nu = {0.0, 0.0}; … … 6847 6467 delta initial delta relative to closed orbit 6848 6468 ctau initial c*tau relative to closed orbit 6849 nmax maximum number of t racking turns6469 nmax maximum number of turns 6850 6470 6851 6471 … … 6859 6479 { 6860 6480 6861 long int i =0L, pos = 1L;6862 long int lastn = 0 L, lastpos = 0L;6481 long int i,pos = 1; 6482 long int lastn = 0, lastpos = 0; 6863 6483 Vector x0, x1, x2, xf,codvector[Cell_nLocMax]; 6864 6484 FILE *outf; … … 6905 6525 do { 6906 6526 pos = 1;//track from first element 6907 (lastn)++; //number of turns6527 (lastn)++; 6908 6528 for (i = 0; i < nv_; i++) //nv_ = 6 6909 6529 x1[i] = x2[i]; 6910 6530 6911 //tracking for one turn6912 6531 while( pos <= globval.Cell_nLoc){ 6913 6532 … … 6933 6552 pos, lastpos,Cell[pos].Elem.PName,Cell[pos].S, 1e3*xf[x_], 1e3*xf[px_], 6934 6553 1e3*xf[y_], 1e3*xf[py_],1e2*xf[delta_], 1e3*xf[ct_],lastn); 6935 } 6936 fprintf(outf,"i name S x(mm) px(mrad) y(mm) py(mrad) delta(%) z(mm) Nturn\n"); 6937 fprintf(outf,"%6d %s %8.4e %12.4e %12.4e %12.4e %12.4e %12.4e %12.4e %4ld \n", 6554 } 6555 fprintf(outf,"%6d %s %8.4e %12.4e %12.4e %12.4e %12.4e %12.4e %12.4e %4ld \n", 6938 6556 pos,Cell[pos].Elem.PName,Cell[pos].S, 1e3*xf[x_], 1e3*xf[px_], 6939 6557 1e3*xf[y_], 1e3*xf[py_],1e2*xf[delta_], 1e3*xf[ct_],lastn); … … 6942 6560 }//finish of tracking and printing to file 6943 6561 6944 } while ((lastn != nmax) && (lastpos == globval.Cell_nLoc)); //track for nmax turns 6945 6946 // if (globval.MatMeth) 6947 // Cell_Pass(0, globval.Cell_nLoc, x1, lastpos); 6948 6949 fclose(outf); 6950 } 6951 /********************************************************************** 6952 void PrintTrackElem(const char *TrackFile, double x, double px, double y,double py, 6953 double delta, double ctau, long int nelem1, long int nelem2) 6954 6955 Purpose: 6956 Print the coordinates tracked around a lattice element by tracking around COD 6957 6958 Input: 6959 TrackFile file to be print 6960 x initial x relative to closed orbit 6961 px initial px relative to closed orbit 6962 y initial y relative to closed orbit 6963 py initial py relative to closed orbit 6964 delta initial delta relative to closed orbit 6965 ctau initial c*tau relative to closed orbit 6966 nelem1 start lattice index of the tracked element 6967 nelem2 end lattice index of the tracked element 6968 6969 6970 Output: 6971 6972 Comments: 6973 Written by Jianfeng Zhang @ LAL 04/2013 6974 **********************************************************************/ 6975 void PrintTrackElem(const char *TrackFile, double x, double px, double y,double py, 6976 double delta, double ctau, long int nelem1, long int nelem2) 6977 { 6978 6979 long int i=0L, pos = 1L; 6980 Vector x0, x1; 6981 FILE *outf; 6982 struct tm *newtime; 6983 6984 bool prt = true; 6985 6986 outf = file_write(TrackFile); 6987 /* Get time and date */ 6988 newtime = GetTime(); 6989 6990 fprintf(outf, "# Element tracking using TRACY III-- %s -- %s\n",TrackFile, asctime2(newtime)); 6991 fprintf(outf, "#\n"); 6992 // fprintf(outf, "# work tunes: %7.5f %7.5f\n",globval.TotalTune[0], globval.TotalTune[1]); 6993 // fprintf(outf, "# i ElemName S x p_x y p_y"); 6994 // fprintf(outf, " delta cdt NElem \n"); 6995 // fprintf(outf, "# [m] [mm] [mrad] [mm] [mrad]"); 6996 // fprintf(outf, " [%%] [mm]\n"); 6997 6998 fprintf(outf,"i ElemName S[m] x(m) px(rad) y(m) py(rad) delta(-) z(m) \n"); 6999 //initial coordinates 7000 x0[x_] = x; 7001 x0[px_] = px; 7002 x0[y_] = y; 7003 x0[py_] = py; 7004 x0[delta_] = delta; 7005 x0[ct_] = ctau; 7006 7007 for (i = 0; i < nv_; i++) //nv_ = 6 7008 x1[i] = x0[i]; 7009 7010 //print the coordinates at the element 7011 pos = nelem1+1;//first element "1" of Tracy is a default "debut", it's diffirent from the real lattice index 7012 7013 //tracking from the start element to the end element 7014 while( pos <= nelem2+1){ 7015 7016 Elem_Pass(pos,x1); 7017 7018 7019 if (prt) { 7020 printf("%4ld %s %6.4f %16.8f %16.8f %16.8f %16.8f %16.8f %16.8f \n", 7021 pos-1,Cell[pos].Elem.PName,Cell[pos].S, x1[x_], x1[px_], 7022 x1[y_], x1[py_],x1[delta_], x1[ct_]); 7023 } 7024 7025 fprintf(outf,"%6d %s %8.4e %16.8e %16.8e %16.8e %16.8e %16.8e %16.8e \n", 7026 pos-1,Cell[pos].Elem.PName,Cell[pos].S, x1[x_], x1[px_], 7027 x1[y_], x1[py_],x1[delta_], x1[ct_]); 7028 7029 pos++; 7030 }//finish of tracking and printing to file 7031 7032 6562 } while ((lastn != nmax) && (lastpos == globval.Cell_nLoc)); 7033 6563 7034 6564 // if (globval.MatMeth) -
branches/tracy3-3.10.1b/tracy/tracy/src/t2elem.cc
r19 r23 1 /* Tracy-31 /* Tracy-3 2 2 3 3 J. Bengtsson, CBP, LBL 1990 - 1994 Pascal version … … 9 9 Element propagators. */ 10 10 11 12 11 double c_1, d_1, c_2, d_2, cl_rad, q_fluct; 13 12 double I2, I4, I5, dcurly_H, dI4; … … 20 19 21 20 // Dynamic model 22 23 24 21 25 22 /****************************************************************************/ … … 84 81 85 82 Purpose: 86 Get the longitudinal momentum ps ; for the exact/approximation Hamiltonian83 Get the longitudinal momentum ps 87 84 88 85 for approximation Hamitonian: 89 86 ps = 1+delta 90 87 91 92 88 For exact hamitonian: 93 89 94 (1) ps = sqrt((1+delta)^2 - px_^2 - py_^2) 95 96 (2) using the check of TEAPOT to check ps < 0 90 ps 97 91 **********************************************************/ 98 92 template<typename T> … … 101 95 T p_s, p_s2; 102 96 103 if (!globval.H_exact)97 if (!globval.H_exact) 104 98 p_s = 1.0+x[delta_]; 105 99 else { … … 109 103 else { 110 104 // avoid compile warning 111 //p_s = 0.0; 112 p_s = 1.0e-20; 113 cout << " " << 1+x[delta_] << " " << x[px_] << " " << x[py_] << endl; 105 p_s = 0.0; 114 106 printf("get_p_s: *** Speed of light exceeded!\n"); 115 // exit_(1); 116 107 exit_(1); 117 108 } 118 109 } … … 124 115 125 116 Purpose: 126 Exact Drift pass in the curvilinear coordinate for the dipole 127 128 See Eqn. (10.26) on page 307 in E. Forest's beam dynamics, a new attitude 129 130 H(x,y,cT,px,py,delta) =(1 + h_ref*x) * sqrt((1+delta)^ - px^2 - py^2) + delta 117 Drift pass 118 119 If H_exact = false, using approximation Hamiltonian: 120 121 px^2+py^2 122 H(x,y,l,px,py,delta) = ------------- 123 2(1+delta) 124 125 126 Otherwise, using exact Hamiltonian 127 131 128 132 129 Input: … … 144 141 145 142 Specific functions: 146 147 148 149 Comments:150 151 Test version....rewritten by Jianfeng zhang @ LAL, 31/07/2013152 153 ****************************************************************************/154 155 156 template<typename T>157 void Drift(double L,double h_bend, ss_vect<T> &x) {158 T u;159 ss_vect<T> x0;160 161 x0=x;162 163 if (globval.H_exact) {164 if(get_p_s(x) == 0)165 return;166 167 x[x_] = x0[x_]/cos(L*h_bend)/(1-x0[px_]/get_p_s(x)*tan(L*h_bend));168 x[px_]= x0[px_]*cos(L*h_bend) + get_p_s(x)*sin(L*h_bend);169 x[y_] = x0[y_]+x0[px_]*x0[x_]*tan(L*h_bend)/get_p_s(x)/(1-x0[px_]/get_p_s(x)*tan(L*h_bend));170 x[py_]= x0[py_];171 x[ct_]= x0[ct_]+((1+x0[delta_])*x0[x_]*tan(L*h_bend))/get_p_s(x)/(1-x0[px_]/get_p_s(x)*tan(L*h_bend));172 173 174 }175 }176 177 /****************************************************************************/178 /* Drift(double L, ss_vect<T> &x)179 180 Purpose:181 Drift pass in the Cartesian coordinate182 183 If H_exact = false, using approximation Hamiltonian (only valid for big ring):184 185 px^2+py^2186 H(x,y,cT,px,py,delta) = -------------187 2(1+delta)188 189 190 Otherwise, using the exact Hamiltonian (valid for small ring)191 (J. Bengtsson: Tracy-2 user's mannual):192 193 H(x,y,cT,px,py,delta) =(1 + h_ref*x) * sqrt((1+delta)^ - px^2 - py^2) + delta194 195 Input:196 L: drift length197 &x: pointer to initial vector: x198 199 Output:200 none201 202 Return:203 none204 205 Global variables:206 207 208 Specific functions:209 143 210 144 ****************************************************************************/ … … 215 149 T u; 216 150 217 if ( globval.H_exact) {218 if(get_p_s(x) == 0)219 return;220 221 u = L/get_p_s(x);151 if (!globval.H_exact) { 152 u = L/(1.0+x[delta_]); 153 x[ct_] += u*(sqr(x[px_])+sqr(x[py_]))/(2.0*(1.0+x[delta_])); 154 } else { 155 u = L/get_p_s(x); 222 156 x[ct_] += u*(1.0+x[delta_]) - L; 223 } else { 224 u = L/(1.0+x[delta_]); 225 x[ct_] += u*(sqr(x[px_])+sqr(x[py_]))/(2.0*(1.0+x[delta_])); 226 } 227 157 } 228 158 x[x_] += x[px_] * u; 229 159 x[y_] += x[py_] * u; … … 671 601 Correction for magnet gap (longitudinal fringe field) 672 602 673 Input: 674 irho: h = 1/rho [1/m] 675 phi: dipole edge (entrance or exit) angle 676 gap: full gap between poles 603 irho h = 1/rho [1/m] 604 phi dipole edge angle 605 gap full gap between poles 677 606 678 607 2 … … 683 612 K1 is usually 1/2 684 613 K2 is zero here 685 For the type of Tanh-like fringe field 686 687 688 18/06/2012 Jianfeng Zhang@LAL 689 690 Fix the bug to calculate psi for the sector magnets which has phi=0 614 615 691 616 692 617 *********************************************************************/ … … 697 622 const double k1 = 0.5, k2 = 0.0; 698 623 699 // if (phi == 0.0) //NOT hard edge, but sector magnets!!! 700 //psi = 0.0;701 //else624 if (phi == 0.0) //hard edge 625 psi = 0.0; 626 else 702 627 psi = k1 * gap * irho * (1.0 + sqr(sin(dtor(phi)))) / cos(dtor(phi)) 703 628 * (1.0 - k2 * gap * irho * tan(dtor(phi))); 704 629 705 630 return psi; 706 }707 708 /*****************************************************************709 * Exact map of the sector dipole710 *711 * Forest's beam dynamics P.360 Eqn. (12.18)712 * Also see Laurent's thesis: P219-220.713 *714 * Written by Jianfeng Zhang @ LAL, 01/08/2013715 *716 * Test version........................................717 *718 * ****************************************************************/719 template<typename T>720 void dipole_kick(double L, double h_ref, double h_bend, ss_vect<T> &x){721 722 ss_vect<T> x0;723 T ps, u, dpxf;724 725 x0 = x;726 ps = get_p_s(x0);727 728 u = sqrt(sqr(1+x0[delta_])-sqr(x0[py_]));729 730 x[py_] = x0[py_];731 732 x[delta_] =x0[delta_];733 734 x[px_]= x0[px_]*cos(L*h_ref) + (ps -h_bend*(1/h_ref+x0[x_]))*sin(L*h_ref);735 736 dpxf = h_ref*sqrt((1+x[delta_])*(1+x[delta_]) - x[px_]*x[px_] - x[py_]*x[py_])-h_bend*(1+h_ref*x[x_]);737 738 739 x[y_] += h_ref/h_bend*x0[py_]*L + x0[py_]/h_bend*(asin(x0[px_]/u)-asin(x[px_]/u));740 741 x[x_] = 1/(h_bend*h_ref)*(h_ref*sqrt(sqr(1+x[delta_])-sqr(x[px_])-sqr(x[py_]))-dpxf - h_bend);742 743 x[ct_] += (1+x0[delta_])*h_ref/h_bend*L + (1+x0[delta_])/h_bend*(asin(x0[px_]/u)-asin(x[px_]/u));744 745 }746 747 /*****************************************************************748 * pure multipole kick749 *750 * Forest's beam dynamics P.360 Eqn. (12.18)751 * Also see Laurent's thesis: P219-220.752 *753 * Written by Jianfeng Zhang @ LAL, 01/08/2013754 *755 * Test version........................................756 *757 * ****************************************************************/758 template<typename T>759 void multipole_kick(int Order, double MB[], double L, double h_bend, ss_vect<T> &x){760 761 int j=0;762 ss_vect<T> x0;763 764 T ByoBrho = 0, BxoBrho = 0, ByoBrho1=0 ;765 766 if ((h_bend != 0.0) || ((1 <= Order) && (Order <= HOMmax))) {767 x0 = x;768 /* compute the total magnetic field Bx and By with Horner's rule */769 ByoBrho = MB[HOMmax + Order]; // normalized By, By/(p0/e)770 BxoBrho = MB[HOMmax - Order]; // normalized Bx, Bx/(p0/e)771 for (j = Order - 1; j >= 1; j--) {772 ByoBrho1 = x0[x_] * ByoBrho - x0[y_] * BxoBrho + MB[j + HOMmax];773 BxoBrho = x0[y_] * ByoBrho + x0[x_] * BxoBrho + MB[HOMmax - j];774 ByoBrho = ByoBrho1;775 }776 }777 778 x[px_] -= L * (ByoBrho + h_bend*1);779 //vertical kick due to the magnets780 x[py_] += L * BxoBrho;781 631 } 782 632 … … 786 636 787 637 Purpose: 788 Refer to Tracy 2 manual. 789 Calculate multipole kick. 790 , 791 (1) The exact Hamiltonian is 638 Calculate multipole kick. The Hamiltonian is 792 639 793 640 H = A + B where A and B are the kick part defined by 794 795 (exact form of the H of the drift) 796 A(x,y,-l,px,py,dP) = -sqrt( (1 + delta)^2 - px^2 - py^2 ) + delta 797 798 (exact form of the H of the kick from the magnet) 799 B(x,y,-l,px,py,dP) = -h*x*sqrt( (1 + delta)^2 - px^2 - py^2 ) + h x + h^2*x^2/2 + int(Re(By+iBx)/Brho) 800 801 so this is the exact Hamitonian for small ring. 802 803 804 The kick is given by 805 e 806 Dp_x = L* (h_ref*sqrt( (1 + delta)^2 - (px^2 + py^2) ) - h_bend - x*h_bend*h_ref - ---- B_y ) 807 p_0 808 Dp_y = L* e/p_0 * B_x 809 810 x = L* h*x_ref / sqrt( (1 + delta)^2 - px^2 - py^2) * p_x 811 812 y = L* h*x_ref / sqrt( (1 + delta)^2 - px^2 - py^2) * p_y 813 814 CT = L* h*x_ref / sqrt( (1 + delta)^2 - px^2 - py^2) * (1+delta) 815 641 2 2 642 px + py 643 A(x,y,-l,px,py,dP) = --------- 644 2(1+dP) 645 2 2 646 B(x,y,-l,px,py,dP) = -h*x*dP + 0.5 h x + int(Re(By+iBx)/Brho) 647 648 so this is the appproximation for large ring 649 the chromatic term is missing hx*A 650 651 652 The kick is given by 653 654 e L L delta L x e L 655 Dp_x = - --- B_y + ------- - ----- , Dp_y = --- B_x 656 p_0 rho rho^2 p_0 657 816 658 where 817 659 e 1 … … 823 665 / 824 666 ==== 825 826 (2) The approximate Hamiltonian is 827 828 H = A + B where A and B are defined by 829 2 2 830 px + py 831 A(x,y,-l,px,py,dP) = --------- (approximate form of the H of the drift) 832 2(1+delta) 833 2 2 834 B(x,y,-l,px,py,dP) = -h*x*delta + 0.5 h x + int(Re(By+iBx)/Brho) (approximate form of the H of the kick from the magnet) 835 836 so this is the appproximation for large ring 837 the chromatic term is missing hx*A 838 839 840 The kick is given by 841 842 e L L delta L x e L 843 Dp_x = --- B_y + ------- - ----- , Dp_y = --- B_x 844 p_0 rho rho^2 p_0 845 846 //second order of the Hamiltonian motion 847 x = h_ref * x_0 / (1+delta) * p_x 848 849 y = h_ref * x_0 / (1+delta) * p_y 850 851 CT = h_ref * x_0 / (1+delta) * (p_x^2 + p_y^2)/2/(1+delta) 852 853 where 854 e 1 855 --- = ----- 856 p_0 B rho 857 ==== 858 \ 859 (B_y + iB_x) = B rho > (ia_n + b_n ) (x + iy)^n-1 860 / 861 ==== 862 863 = B rho [(b_n*x - a_n*y) + i*(bn*y + an*x) + b_(n-1) + i*a_(n-1)] * (x+iy)^n-2 864 =...... 865 667 866 668 Input: 867 669 Order maximum non zero multipole component 868 670 MB array of an and bn, magnetic field components 869 671 L multipole length 870 h_bend B_dipole/Brho is the dipole field normalized by the reference momentum; one of the example is the combined dipole 871 h_ref 1/rho [m^-1] is the curvature of the reference orbit in the dipoles which is used in curvilinear coordinate, 672 h_bend 1/rho in curvilinear coordinate, 673 0 in cartisian cooridinate. 674 h_ref 1/rho [m^-1] 872 675 x initial coordinates vector 873 676 … … 885 688 886 689 Comments: 887 06/11/2012 Jianfeng Nadolski @ LAL 888 Fix the bug in the kick map of the exact Hamiltonian. 889 Add the second order of the approximate Hamiltonian. 690 none 890 691 891 692 **************************************************************************/ … … 895 696 int j; 896 697 T BxoBrho, ByoBrho, ByoBrho1, B[3]; 897 T sqrtpx, dpx, ps2new, psnew;898 T n1, n2;899 698 ss_vect<T> x0, cod; 900 T u=0.0; 901 699 902 700 if ((h_bend != 0.0) || ((1 <= Order) && (Order <= HOMmax))) { 903 701 x0 = x; 904 /* compute the total magnetic field Bx and Bywith Horner's rule */702 /* compute field with Horner's rule */ 905 703 ByoBrho = MB[HOMmax + Order]; // normalized By, By/(p0/e) 906 704 BxoBrho = MB[HOMmax - Order]; // normalized Bx, Bx/(p0/e) 705 907 706 for (j = Order - 1; j >= 1; j--) { 908 707 ByoBrho1 = x0[x_] * ByoBrho - x0[y_] * BxoBrho + MB[j + HOMmax]; … … 911 710 } 912 711 913 914 712 if (globval.radiation || globval.emittance) { 915 713 B[X_] = BxoBrho; … … 919 717 } 920 718 921 //curvilinear cocodinates, from the dipole components922 719 if (h_ref != 0.0) { 923 924 //exact Hamiltonian925 if (globval.H_exact) {926 927 if(get_p_s(x0)==0)928 return;929 930 //dipole kick map from the exact Hamiltonian; not symplectic931 // u = L * h_ref * x0[x_] /get_p_s(x0);932 // x[x_] += u * x0[px_];933 // x[y_] += u * x0[py_];934 // x[px_]-= L * (-h_ref * get_p_s(x0) + h_bend + h_ref * h_bend935 // * x0[x_] + ByoBrho);936 // x[ct_] += u * (1.0+x0[delta_]);937 938 //kick map due to the dipole vector potential939 // x[px_] -= L*(h_bend + h_ref*h_bend*x0[x_]+ByoBrho);940 941 // sqrtpx = sqrt(sqr(1+x0[delta_])-sqr(x0[py_]));942 // //943 // x[px_] = x0[px_]*cos(L*h_ref) + (get_p_s(x0)-h_bend*(h_ref+x0[x_]))*sin(L*h_ref)-L*ByoBrho;944 //945 // dpx = -x0[px_]*h_ref*sin(L*h_ref)+(get_p_s(x0)-h_bend*(h_ref+x0[x_]))*h_ref*cos(L*h_ref);946 //947 // x[x_] = 1/(h_bend*h_ref)*(h_ref*sqrt(sqr(1+x0[delta_])-sqr(x[px_])-sqr(x0[py_]))-dpx - h_bend);948 //949 // x[y_] += h_ref/h_bend*x0[py_]*L + x0[py_]/h_bend*(asin(sqrtpx*x0[px_])-asin(sqrtpx*x[px_]));950 //951 // x[ct_]+= (1+x0[delta_])*h_ref/h_bend*L + (1+x0[delta_])/h_bend*(asin(sqrtpx*x0[px_])-asin(sqrtpx*x[px_]));952 953 //map of a wedge954 // x[px_] = x0[px_]*cos(L*h_bend) + (get_p_s(x0) - h_ref*x0[x_])*sin(L*h_bend) -L*ByoBrho;955 //956 // sqrtpx = sqrt(sqr(1+x0[delta_])-sqr(x0[py_]));957 // n1 = x0[px_]*sqrtpx;958 // n2 = x[px_]*sqrtpx;959 //960 // x[x_] = x0[x_]*cos(L*h_bend) + (x0[x_]*x0[px_]*sin(2*L*h_bend)+sqr(sin(L*h_bend))*(2*x0[x_]*get_p_s(x0)-h_ref*sqr(x0[x_])))961 // /(sqrt(sqr(1+x0[delta_])-sqr(x[px_])-sqr(x0[y_]))+get_p_s(x0)*cos(L*h_bend)-x0[px_]*sin(L*h_bend));962 //963 // x[y_] += x0[py_]*L*h_bend*h_ref + x0[py_]*h_ref*(asin(n1) - asin(n2));964 // x[ct_]+= (1+x0[delta_])*L*h_bend*h_ref + (1+x0[delta_])*h_ref*(asin(n1) - asin(n2));965 //966 }//approximate Hamiltonian967 else {//first order map968 720 x[px_] -= L * (ByoBrho + (h_bend - h_ref) / 2.0 + h_ref * h_bend 969 721 * x0[x_] - h_ref * x0[delta_]); 970 722 x[ct_] += L * h_ref * x0[x_]; 971 972 // second order, cubic term of H, H3; has problem when do tracking...works for THOMX!!!!! 973 // not symplectic???? 974 if(0){ 975 u = L * h_ref * x0[x_] /(1.0+x0[delta_]); 976 x[x_] += u * x0[px_]; 977 x[y_] += u * x0[py_]; 978 // x[px_]+= 0.5*u/x0[x_]*(x0[px_]*x0[px_]+x0[py_]*x0[py_]); 979 x[ct_] += u*(sqr(x0[px_])+sqr(x0[py_]))/(2.0*(1.0+x0[delta_])); 980 981 // cout << "test......2..... u = " << u<< endl; 982 } 983 } 984 985 }//from other straight magnets 986 else 987 x[px_] -= L * (ByoBrho + h_bend*1); //h_bend should be trigger on for combined dipoles 988 989 //vertical kick due to the magnets 723 } else 724 x[px_] -= L * (ByoBrho + h_bend); 725 990 726 x[py_] += L * BxoBrho; 991 992 /*993 if(h_ref == 0 && h_bend !=0){994 sqrtpx = sqrt(sqr(1+x0[delta_])-sqr(x0[py_]));995 ps2new = sqr(1+x0[delta_]) - sqr(x[px_]) -sqr(x0[py_]);996 psnew = sqrt(ps2new);997 998 x[x_] += 1/h_bend*(psnew - get_p_s(x0));999 x[y_] += x0[py_]/h_bend*(asin(x0[px_]*sqrtpx)-asin(x[px_]*sqrtpx));1000 x[ct_]+= (1+x0[delta_])/h_bend*(asin(x0[px_]*sqrtpx)-asin(x[px_]*sqrtpx));1001 }*/1002 1003 1004 727 } 1005 728 } … … 1012 735 Compute edge focusing for a dipole 1013 736 There is no radiation coming from the edge 1014 The standard formula used is : (SLAC-75, K. Brown's first order of fringe field but with the correction of 1/(1+delta) in R43)737 The standard formula used is : 1015 738 1016 739 px = px0 + irho tan(phi) *x0 … … 1029 752 gap = gap of the dipole for longitudinal fringing field (see psi) 1030 753 x = input particle coordinates 1031 Entrance: bool flag, true, then calculate edge focus and fringe field at the entrance of the dipole 1032 false,...........................................at the exit fo the dipole 1033 754 1034 755 Output: 1035 756 x output particle coordinates … … 1053 774 1054 775 April 2011, No energy dependence for H-plane according to SSC-141 note (E. Forest) 1055 Agreement better with MAD8 (LNLS), SOLEIL small effect (.1). Modified by Laurent Nadolski @ soleil 1056 Comments: Jianfeng Zhang @ LAL, 05/06/2013 1057 This model only works for Soleil lattice, but not works for ThomX and SuperB DR lattice. 1058 1059 18/06/2012 Jianfeng Zhang @ LAL 1060 Add the contribution of x' to the x[py_] for small ring like Thom-X, using Alexandre Loulergue's correction. 1061 This models works for ThomX, Soleil, and SuperB DR lattices; and 1062 close to the Forest's model and K. Brown's models. 1063 776 Agreement better with MAD8 (LNLS), SOLEIL small effect (.1) 1064 777 ****************************************************************************/ 1065 778 template<typename T> 1066 static void EdgeFocus(double irho, double phi, double gap, ss_vect<T> &x, bool Entrance) { 1067 1068 779 static void EdgeFocus(double irho, double phi, double gap, ss_vect<T> &x) { 1069 780 if (true) { 1070 1071 // cout << "Dipole edge effect WITH Alex's correction: " << endl; 1072 1073 //with the contribution from the entrance angle of the particle at the edge 1074 // Original model, written by L. Nadolski, this is a reasonal model!!!! 1075 // warning: => diverging Taylor map (see SSC-141) 1076 // x[px_] += irho * tan(dtor(phi)) * x[x_]; 1077 // x[py_] -= irho * tan(dtor(phi) - get_psi(irho, phi, gap)) * x[y_] 1078 // / (1.0 + x[delta_]); 1079 1080 1081 // K.Brown 2rd order transfer matrix of the dipole fringe field for sector dipoles (phi=0) 1082 // compared the fringe field model used in Tracy 1083 // results: K. Brown's model is wrong for small ring like Thom-X!!!! 1084 // The original model of tracy is correct for tracking!!!!!!!!!! 1085 /* 1086 double psi; 1087 psi=gap*0.5*irho*(1+sin(dtor(phi))*sin(dtor(phi)))/cos(dtor(phi)); 1088 1089 if(Entrance){ 1090 x[x_] += irho/2*x[y_]*x[y_]; 1091 x[px_] += 0.5*x[x_]*x[x_] + irho * tan(dtor(phi)) * x[x_]-0.5*x[y_]*x[y_]; 1092 x[py_] -= -irho*tan(-dtor(psi))*x[y_]+1*x[x_]*x[y_]+irho*x[px_]*x[y_]+ (irho*psi/cos(-dtor(psi))/cos(-dtor(psi))) * x[y_] 1093 / (1.0 + x[delta_]); 1094 } 1095 else 1096 { 1097 x[x_] -= irho/2*x[y_]*x[y_]; 1098 x[px_] += 0.5*x[x_]*x[x_] + irho * tan(dtor(phi)) * x[x_]-0.5*x[y_]*x[y_]; 1099 x[py_] -= -irho*tan(-dtor(psi))*x[y_]+1*x[x_]*x[y_]-irho*x[px_]*x[y_]+ (irho*psi/cos(-dtor(psi))/cos(-dtor(psi))) * x[y_] 1100 / (1.0 + x[delta_]); 1101 } 1102 */ 1103 1104 //add the contribution of the entrance momentum of the particle, from Alex Loulergue. 1105 if(Entrance){ 1106 x[px_] += irho * tan(dtor(phi) +x[py_]/(1+x[delta_]*1)) * x[x_]/ (1.0 + x[delta_]*0); 1107 x[py_] -= irho * tan(dtor(phi) + x[px_]/(1+x[delta_]*1) - get_psi(irho, phi, gap)/(1+x[delta_]*0)) * x[y_] 1108 / (1.0 + x[delta_]*0); 1109 }else{ 1110 x[px_] += irho * tan(dtor(phi) - x[py_]/(1+x[delta_]*1)) * x[x_]/ (1.0 + x[delta_]*0); 1111 x[py_] -= irho * tan(dtor(phi) - x[px_]/(1+x[delta_]*1) - get_psi(irho, phi, gap)/(1+x[delta_]*0)) * x[y_] 1112 / (1.0 + x[delta_]*0); 1113 } 1114 1115 } else {//original one 1116 1117 //cout << "Dipole edge effect WITHOUT Alex's correction: " << endl; 781 // warning: => diverging Taylor map (see SSC-141) 1118 782 x[px_] += irho * tan(dtor(phi)) * x[x_]; 1119 x[py_] -= irho * tan(dtor(phi) - get_psi(irho, phi, gap)) * x[y_]/ (1.0 + x[delta_]*1); 1120 } 1121 } 1122 1123 1124 /****************************************************************** 1125 template<typename T> 1126 static void BendCurvature(double irho, double H, ss_vect<T> &x) 1127 1128 The leanding order term T211, T233, and T413 on page 117 & page 118 1129 of the dipole edge effect in SLAC-75, using the symplectic 1130 form in 1131 E. Forest: "Fringe field in MAD, Part II: Bend curvature in MAD-X for the 1132 mudule PTC". 1133 P.10 Eq. (5) and (42). 1134 1135 For an rectangular dipole, the bending curvature term is zero, since 1/R = 0. 1136 1137 irho: curvature of the central orbit inside the dipole 1138 H: curvature of the entrance/exit pole face of the dipole 1139 1140 Comments: 1141 Written by Jianfeng Zhang @ LAL, 01/10/2012. 1142 ******************************************************************/ 1143 template<typename T> 1144 static void BendCurvature(double irho, double H, ss_vect<T> &x) { 1145 1146 if(trace) 1147 cout << "Forest's bend curvature...."<<endl; 1148 1149 T pm2,u, coeff1, coeff2,coeff3; 1150 1151 ss_vect<T> x0; 1152 1153 x0 = x; 1154 1155 pm2 = sqr(1+x0[delta_]) - sqr(x0[px_]); 1156 u = irho*H/2/pm2; 1157 1158 coeff1 = u * 2*x0[px_]*(1+x0[delta_])/pm2; // 1159 coeff2 = u * (1+x0[delta_]); // 1160 coeff3 = u * (pm2 - 2*(1+x0[delta_]))/pm2; 1161 1162 1163 x[x_] += x0[x_]/(1-coeff1*x0[y_]*x0[y_]); 1164 x[px_] -= coeff2*x0[y_]*x0[y_] - irho*H/2*sqr(x0[x_]); 1165 x[py_] -= 2*coeff2*x[x_]*x0[y_]; 1166 x[ct_] -= coeff3*x[x_]*x0[y_]*x0[y_]; 1167 } 1168 1169 1170 1171 783 x[py_] -= irho * tan(dtor(phi) - get_psi(irho, phi, gap)) * x[y_] 784 / (1.0 + x[delta_]); 785 } else { 786 x[px_] += irho * tan(dtor(phi)) * x[x_]; 787 x[py_] -= irho * tan(dtor(phi) - get_psi(irho, phi, gap)) * x[y_]; 788 } 789 } 1172 790 1173 791 /**************************************************************** … … 1176 794 1177 795 Purpose: 1178 Rotate from the beam coorinate to the dipole face. 1179 This is a pure geometric operation, no physical meaning. 1180 1181 See P.307 Eq. (10.26) in 1182 E. Forest "Beam dynamics: A new attitude and framework". 1183 796 the effect of edge focusing of the dipole 1184 797 Input: 1185 798 phi: entrance or exit angle of the dipole edge 1186 799 x: initial cooridinate of the particle 1187 1188 800 Output: 1189 801 … … 1207 819 } 1208 820 1209 1210 821 /*************************************************************** 1211 822 template<typename T> … … 1213 824 1214 825 Purpose: 1215 the effect of longitudinal fringe field using exact Hamitonian. 1216 This is a hard effect model, the fringe field and edge focus 1217 happens at the entrance/exit point of the dipole pole face. 1218 1219 include only the first order of irho. 1220 Input: 826 the effect of longitudinal fringe field using exact Hamitonian 827 Input: 1221 828 1222 829 Output: … … 1242 849 x[ct_] = x1[ct_] - coeff * x1[px_] * sqr(x[y_]) * (1.0 + x1[delta_]) 1243 850 / ps3; 1244 } else {//give the error message and set the unstable x value during the tracking 1245 //this x value will be discard as an unstable value during the tracking 851 } else { 1246 852 printf("bend_fringe: *** Speed of light exceeded!\n"); 1247 x[y_] = 10; 1248 x[x_] = 10; 1249 x[py_] =10; 1250 x[ct_] = 10; 1251 //exit_(1); 1252 } 1253 } 1254 1255 /*************************************************************** 1256 template<typename T> 1257 void bend_fringe(double hb, double gap, ss_vect<T> &x) 1258 1259 Purpose: 1260 the effect of longitudinal fringe field using exact Hamitonian. 1261 This is a hard effect model, the fringe field and edge focus 1262 happens at the entrance/exit point of the dipole pole face. 1263 1264 include the second order of irho. 1265 1266 See E. Forest and et al. 1267 "Fringe field in MAD Part I: Second order Fringe in MAD-X for the module PTC", 1268 P. 8-9, Eq. (35) and (34). 1269 1270 Input: 1271 1272 Output: 1273 1274 Return: 1275 1276 ****************************************************************/ 1277 template<typename T> 1278 void bend_fringe(double hb, double gap, ss_vect<T> &x) { 1279 1280 bool track=false; 1281 1282 if(track) cout << "bend_fringe(): Forest's model"<<endl; 1283 1284 T coeff1,coeff2,coeff3,coeff4; 1285 T ps, ps2, ps3, ps5; 1286 1287 ss_vect<T> x1; 1288 1289 gap = gap*0.5; 1290 1291 x1 = x; 1292 ps = get_p_s(x); 1293 1294 if(ps==0) 1295 return; 1296 1297 ps2 = sqr(ps); 1298 ps3 = ps * ps2; 1299 ps5 = ps2*ps3; 1300 1301 coeff1 = 1.0 - 4.0*sqr(hb)*gap*x1[py_]*x1[y_]/ps3; 1302 coeff2 = sqr(hb)*gap*2*x1[px_]*(2*sqr(x1[px_])-sqr(1.0+x1[delta_]))/ps5 + 1303 hb*(ps/(sqr(1+x1[delta_])-sqr(x1[px_])) + 2*sqr(x1[px_])*ps/sqr(sqr(1+x1[delta_])-sqr(x1[px_]))); 1304 1305 coeff3 = hb*(x1[px_]/ps)/(1+sqr(x1[py_])/ps2) - sqr(hb)*gap*((ps2+sqr(x1[px_]))/ps3+sqr(x1[px_])/ps2*(ps2+x1[py_])/ps3); 1306 coeff4 = -sqr(hb)*gap*4*sqr(x1[px_])*(1+x1[delta_])/ps5; 1307 1308 if (coeff1 >= 0.0) { 1309 x[y_] = 2.0 * x1[y_] / (1.0 + sqrt(coeff1)); 1310 } else { 1311 //give the error message and set the unstable x value during the tracking 1312 //this x value will be discard as an unstable value during the tracking 1313 printf("bend_fringe: *** Speed of light exceeded!\n"); 1314 x[y_] = 10; 1315 x[x_] = 10; 1316 x[py_] =10; 1317 x[ct_] = 10; 1318 // exit_(1); 1319 } 1320 1321 x[x_] += 0.5*coeff2*sqr(x[y_]); 1322 x[py_]-= coeff3*x[y_]; 1323 x[ct_] -= 0.5*coeff4*sqr(x[y_]); 853 exit_(1); 854 } 1324 855 } 1325 856 … … 1450 981 elemtype *elemp; 1451 982 MpoleType *M; 1452 1453 ss_vect<T> x1, x2;1454 1455 983 1456 984 elemp = &Cell.Elem; … … 1460 988 GtoL(x, Cell.dS, Cell.dT, M->Pc0, M->Pc1, M->Ps1); 1461 989 1462 //entrance of the magnet1463 990 if ((M->Pmethod == Meth_Second) || (M->Pmethod == Meth_Fourth)) { /* fringe fields */ 1464 991 … … 1468 995 } 1469 996 1470 //fringe field and edge focusing of dipoles 1471 if (M->Pirho != 0.0 && M->dipEdge_effect1 == 1){ 1472 if (!globval.H_exact) { //big ring */ modified linear term T43 on page 117 & 118 in SLAC-75. 1473 EdgeFocus(M->Pirho, M->PTx1, M->Pgap, x,true); 1474 } else {//small and big rings; Forest's model 1475 if(M->PH1!=0){ 1476 // curvature of the magnet pole face; for a sector/wedge/rectangular dipole, this term is 0. 1477 BendCurvature(M->Pirho, M->PH1, x); 1478 } 1479 p_rot(M->PTx1, x); //rotate from cartesian cooridnate to curlinear curved beam coordinate; 1480 // since the map of a sector dipole is used in Tracy 3 1481 bend_fringe(M->Pirho, M->Pgap, x); //fringe field 1482 } 1483 } 997 if (!globval.H_exact) { 998 if (M->Pirho != 0.0) 999 EdgeFocus(M->Pirho, M->PTx1, M->Pgap, x); 1000 } else { 1001 p_rot(M->PTx1, x); 1002 bend_fringe(M->Pirho, x); 1003 } 1484 1004 } 1485 1005 1486 1006 if (M->Pthick == thick) { 1487 if (!globval.H_exact || ((M->PTx1 == 0.0) && (M->PTx2 == 0.0))) {// polar coordinates,curvilinear coordinates 1488 // if (M->n_design == Dip || ((M->PTx1 == 0.0) && (M->PTx2 == 0.0))) {// polar coordinates,curvilinear coordinates 1007 if (!globval.H_exact || ((M->PTx1 == 0.0) && (M->PTx2 == 0.0))) {// polar coordinates,curvilinear coordinates 1489 1008 h_ref = M->Pirho; 1490 1009 dL = elemp->PL / M->PN; … … 1494 1013 dL = elemp->PL / M->PN; 1495 1014 else 1496 dL = 1.0 / M->Pirho * (sin(dtor(M->PTx1)) + sin(dtor(M->PTx2))) //straight length of the dipole1015 dL = 1.0 / M->Pirho * (sin(dtor(M->PTx1)) + sin(dtor(M->PTx2))) 1497 1016 / M->PN; 1498 1017 } … … 1522 1041 1523 1042 case Meth_Second: 1524 1525 // cout << "Mpole_Pass: Meth_Second not supported" << endl; 1526 // exit_(0); 1527 // break; 1528 1529 //specially for the test of the dipole map,see Forest's beam dynamics, p361. eqn.(12.19) 1530 1531 dL1 = 0.5*dL; 1532 dL2 = dL; 1533 1534 for (seg = 1; seg <= M->PN; seg++) { 1535 dipole_kick(dL1,M->Pirho,h_ref,x); 1536 multipole_kick(M->Porder, M->PB, dkL1, M->Pirho, x); 1537 dipole_kick(dL1,M->Pirho,h_ref,x); 1538 } 1539 1540 1541 1542 case Meth_Fourth: //forth order symplectic integrator 1043 cout << "Mpole_Pass: Meth_Second not supported" << endl; 1044 exit_(0); 1045 break; 1046 1047 case Meth_Fourth: 1543 1048 if (M->Pthick == thick) { 1544 1049 dL1 = c_1 * dL; … … 1556 1061 } 1557 1062 1558 1063 Drift(dL1, x); 1559 1064 thin_kick(M->Porder, M->PB, dkL1, M->Pirho, h_ref, x); 1560 1065 Drift(dL2, x); 1561 1066 thin_kick(M->Porder, M->PB, dkL2, M->Pirho, h_ref, x); 1562 1067 1563 1068 if (globval.emittance && (!globval.Cavity_on) && (M->Pirho … … 1566 1071 dI4 += 4.0 * is_tps<tps>::get_dI4(x); 1567 1072 } 1568 1569 1073 1570 1074 Drift(dL2, x); 1571 1572 1075 thin_kick(M->Porder, M->PB, dkL1, M->Pirho, h_ref, x); 1076 Drift(dL1, x); 1573 1077 1574 1078 if (globval.emittance && (!globval.Cavity_on) && (M->Pirho … … 1594 1098 } 1595 1099 1596 //exit of the magnets1597 1100 if ((M->Pmethod == Meth_Second) || (M->Pmethod == Meth_Fourth)) { 1598 1599 /* dipole fringe fields */ 1600 if (M->Pirho != 0.0 && M->dipEdge_effect2 == 1){ 1601 if (!globval.H_exact) { //big ring, linear model correction 1602 EdgeFocus(M->Pirho, M->PTx2, M->Pgap, x,false); 1603 }else{ 1604 bend_fringe(-M->Pirho, M->Pgap,x); //Forest's fringe field of the dipole 1605 p_rot(M->PTx2, x); //rotate back to the cartesian cooridinate 1606 if(M->PH2!=0){ 1607 // curvature of the magnet pole face; for a sector/wedge/rectangular dipole, this term is 0. 1608 BendCurvature(M->Pirho, M->PH2, x); 1609 } 1610 } 1611 } 1612 //quadrupole fringe field 1101 /* fringe fields */ 1102 if (!globval.H_exact) { 1103 if (M->Pirho != 0.0) 1104 EdgeFocus(M->Pirho, M->PTx2, M->Pgap, x); 1105 } else { 1106 bend_fringe(-M->Pirho, x); 1107 p_rot(M->PTx2, x); 1108 } 1613 1109 if (globval.quad_fringe && (M->PB[Quad + HOMmax] != 0.0) && (M->quadFF2 1614 1110 == 1)) … … 2916 2412 mergeto4by5(M, ah, av); 2917 2413 } 2918 /* ************************************************************** 2919 * Compute transfert matrix for a quadrupole magnet 2414 2415 void Mpole_Setmatrix(int Fnum1, int Knum1, double K) { 2416 /* Compute transfert matrix for a quadrupole magnet 2920 2417 the transfert matrix A is plitted into two part 2921 2418 A = AD55xAU55 … … 2929 2426 corresponding to a half magnet w/ an entrance 2930 2427 angle and no exit angle. 2931 The linear fringe field is taken into account 2932 **************************************************************/ 2933 void Mpole_Setmatrix(int Fnum1, int Knum1, double K) { 2934 2428 The linear frindge field is taken into account */ 2935 2429 2936 2430 CellType *cellp; … … 3426 2920 printf("Elem_GetPos: there are no kids in family %d (%s)\n", Fnum1, 3427 2921 ElemFam[Fnum1 - 1].ElemF.PName); 3428 exit_( 1);2922 exit_(0); 3429 2923 } 3430 2924 … … 3457 2951 d_2 = 1e0 - 2e0 * d_1; 3458 2952 3459 3460 3461 3462 3463 2953 // classical radiation 3464 2954 // C_gamma = 8.846056192e-05; … … 3853 3343 M->PTx1 = 0.0; /* Entrance angle */ 3854 3344 M->PTx2 = 0.0; /* Exit angle */ 3855 M->PH1 = 0.0; /* Entrance pole face curvature*/3856 M->PH2 = 0.0; /* Exit pole face curvature */3857 3345 M->Pgap = 0.0; /* Gap for fringe field ??? */ 3858 3346 -
branches/tracy3-3.10.1b/tracy/tracy/src/t2lat.cc
r11 r23 44 44 leq, pwrsym, lss, geo, gtr, period_, charcon, stringcon, ident, geq, lsym, 45 45 bobrhosym, bobrhovsym, bobrhohsym, kxvsym, kxhsym, phisym, ksym, 46 tsym, t1sym, t2sym, h1sym,h2sym,46 tsym, t1sym, t2sym, 47 47 gapsym, thksym, invsym, thnsym, 48 48 endsym, tsksym, bemsym, corsym, prnsym, tblsym, possym, prmsym, … … 51 51 nbdsym, frgsym, latsym, mpsym, dbnsym, kssym, homsym, lmdsym, dtsym, xytsym, 52 52 vrfsym, harnumsym, frqsym, gstsym, typsym, rollsym, idsym, 53 fnamesym1, fnamesym2, scalingsym1, scalingsym2, fmsym, harmsym, sprsym, recsym, solsym, edge_effect1sym,edge_effect2sym,53 fnamesym1, fnamesym2, scalingsym1, scalingsym2, fmsym, harmsym, sprsym, recsym, solsym, 54 54 ff1sym, ff2sym, ffscalingsym, tiltsym 55 55 } Lat_symbol; /*\*/ 56 56 // idsym fnamesym1 fnamesym2 scalingsym added for insertion 57 57 // ring sym added 58 //edge_effect1sym, edge_effect2sym added, to turn on/off the edge effect of dipoles @ 05/10/2012 by Jianfeng Zhang59 58 // ff1sym ff2sym for quadrupole entrance and exit fringe field 60 59 // ffscalingsym scaling factor for entrance and exit fringe field. /*J.Zhang … … 658 657 if (!strncmp(id, "t ", sizeof(alfa_))) 659 658 *sym = tsym; 660 else if (!strncmp(id, "h1 ", sizeof(alfa_)))661 *sym = h1sym;662 else if (!strncmp(id, "h2 ", sizeof(alfa_)))663 *sym = h2sym;664 659 else if (!strncmp(id, "gap ", sizeof(alfa_))) 665 660 *sym = gapsym; … … 1059 1054 else if (!strncmp(fname, "t2 ", sizeof(partsName))) 1060 1055 x = WITH1->PTx2; 1061 else if (!strncmp(fname, "h1 ", sizeof(partsName)))1062 x = WITH1->PH1;1063 else if (!strncmp(fname, "h2 ", sizeof(partsName)))1064 x = WITH1->PH2;1065 1056 else if (!strncmp(fname, "gap ", sizeof(partsName))) 1066 1057 x = WITH1->Pgap; … … 2026 2017 struct LOC_Lat_DealElement V; 2027 2018 bool Result = false; 2028 double t=0.0, t1=0.0, t2=0.0, h1=0,h2=0,gap=0.0, QL = 0.0, QK=0.0; 2029 double QKick=0.0; /* kick angle of the corrector [rad]*/ 2030 int Kplane=0; /* kick plane of the corrector, 1 for H plane, -1 for V plane*/ 2031 double QKV=0.0, QKH=0.0, QKxV=0.0, QKxH=0.0, QPhi=0.0, QKS=0.0; 2032 double dt=0.0, Frf=0.0, Vrf=0.0; 2033 long harnum=0L; 2034 int k1=1; //number of cut slice of the element 2035 int k2=4; //integration method; Meth_Linear=0, Meth_First=1,Meth_Second=2,Meth_Fourth=4 2036 int edge_effect1=0,edge_effect2=0; //flag to turn on/off dipole fringe field 2037 int FF1=0, FF2=0; 2038 double FFscaling=0.0; 2019 double t, t1, t2, gap, QL = 0.0, QK; 2020 double QKick; /* kick angle of the corrector [rad]*/ 2021 int Kplane; /* kick plane of the corrector, 1 for H plane, -1 for V plane*/ 2022 double QKV, QKH, QKxV, QKxH, QPhi, QKS; 2023 double dt, Frf, Vrf; 2024 long k1, k2, harnum, FF1, FF2; 2025 double FFscaling; 2039 2026 Lat_symbol sym1; 2040 2027 symset mysys, SET; … … 2089 2076 test__(P_expset(SET, 1 << ((long)semicolon)), "<;> expected", &V); 2090 2077 GetSym__(&V); 2091 QL = *V.rnum;2092 2078 globval.Elem_nFam++; 2093 2079 if (globval.Elem_nFam <= Elem_nFamMax) { … … 2095 2081 WITH1 = &WITH->ElemF; 2096 2082 memcpy(WITH1->PName, ElementName, sizeof(partsName)); 2097 // WITH1->PL = *V.rnum; 2098 WITH1->PL = QL; 2083 WITH1->PL = *V.rnum; 2099 2084 WITH1->Pkind = PartsKind(drift); 2100 2085 Drift_Alloc(&WITH->ElemF); … … 2116 2101 T2 = <exit angle>, ( [degree] ) 2117 2102 gap = <total magnet gap>, ( [m] ) 2118 edge_effect1 = 1/0, turn on/ff the entrance edge effect,2119 and fringe field (if gap != 0)2120 edge_effect2 = 1/0, turn on/ff the exit edge effect,2121 and fringe field (if gap != 0)2122 2103 K = <K-value>, ( [m^-2] ) 2123 2104 ( K > 0 : focusing in horizontal plane ) … … 2135 2116 Example 2136 2117 2137 B: bending, L=0.70, T=10.0, T1:=5.0, T2:=5.0, H1=0, H2=0, gap=0.03, edge_effect1=1, edge_effect2=1,K=-1.0, N=8, Method=2;2118 B: bending, L=0.70, T=10.0, T1:=5.0, T2:=5.0, K=-1.0, N=8, Method=2; 2138 2119 2139 2120 *************************************************************************/ … … 2143 2124 QL = 0.0; /* L */ 2144 2125 QK = 0.0; /* K, quadrupole components*/ 2145 k1 = 1; /* N */2126 k1 = 0; /* N */ 2146 2127 t = 0.0; /* T */ 2147 2128 t1 = 0.0; /* T1 */ 2148 2129 t2 = 0.0; /* T2 */ 2149 h1 = 0.0;2150 h2 = 0.0;2151 2130 gap = 0.0; /* gap */ 2152 edge_effect1 = 0; /* edge_effect effect at the entrance */ 2153 edge_effect2 = 0; /* edge effect at the exit */ 2154 k2 = Meth_Fourth; /* method */ 2131 k2 = Meth_Linear; /* method */ 2155 2132 dt = 0.0; 2156 2133 ClearHOMandDBN(&V); … … 2163 2140 P_addset(mysys, (long)t1sym); 2164 2141 P_addset(mysys, (long)t2sym); 2165 P_addset(mysys, (long)h1sym);2166 P_addset(mysys, (long)h2sym);2167 2142 P_addset(mysys, (long)gapsym); 2168 P_addset(mysys, (long)edge_effect1sym);2169 P_addset(mysys, (long)edge_effect2sym);2170 2143 P_addset(mysys, (long)homsym); 2171 2144 P_addset(mysys, (long)dbnsym); … … 2205 2178 break; 2206 2179 2207 case h1sym:2208 h1 = EVAL_(&V);2209 break;2210 2211 case h2sym:2212 h2 = EVAL_(&V);2213 break;2214 2215 2180 case gapsym: 2216 2181 gap = EVAL_(&V); 2217 break;2218 2219 case edge_effect1sym:2220 edge_effect1 = (long)EVAL_(&V);2221 break;2222 2223 case edge_effect2sym:2224 edge_effect2 = (long)EVAL_(&V);2225 2182 break; 2226 2183 … … 2266 2223 else 2267 2224 WITH2->Pirho = t * M_PI / 180.0; 2268 WITH2->PTx1 = t1; WITH2->PTx2 = t2; //entrance and exit angle of the dipoles (relative to rectangular magnets) 2269 WITH2->PH1 = h1; WITH2->PH2 = h2; //entrance and exit angle of the dipoles 2270 WITH2->Pgap = gap; 2271 WITH2->dipEdge_effect1 = edge_effect1;//edge_effect effect at the entrance 2272 WITH2->dipEdge_effect2 = edge_effect2;//edge effect at the exit 2225 WITH2->PTx1 = t1; WITH2->PTx2 = t2; WITH2->Pgap = gap; 2273 2226 WITH2->n_design = Dip; 2274 2227 AssignHOM(globval.Elem_nFam, &V); … … 2302 2255 2303 2256 Q1: Quadrupole, L=0.5, K=2.213455, N=4, Method=4; 2304 Q1 : Quadrupole, L=0.5, K=2.213455, N=4, FF1 =1, FF2 =0, FFscaling=1, Method=4;2257 Q1 : Quadrupole, L=0.5, K=2.213455, N=4, FF1 =1, FF2, FFscaling=1, Method=4; 2305 2258 2306 2259 **************************************************************/ … … 2310 2263 QL = 0.0; /* L */ 2311 2264 QK = 0.0; /* K */ 2312 k1 = 1; /* N */2265 k1 = 0; /* N */ 2313 2266 k2 = Meth_Fourth; /* method */ 2314 2267 dt = 0.0; … … 2438 2391 QL = 0.0; /* L */ 2439 2392 QK = 0.0; /* K */ 2440 k1 = 1; /* N */2393 k1 = 0; /* N */ 2441 2394 k2 = Meth_Fourth; /* method */ 2442 2395 FF1 = 0; /* Entrance Fringe field */ … … 2653 2606 QKick = 0.0; /* kick angle of the corrector [rad]*/ 2654 2607 Kplane = 0; /* 1 is horizontal corrector, -1 is vertical corrector */ 2655 k1 = 1; /* N */2608 k1 = 0; /* N */ 2656 2609 k2 = Meth_Linear; /* method */ 2657 2610 dt = 0.0; … … 2931 2884 QL = 0.0; /* L */ 2932 2885 QK = 0.0; /* K */ 2933 k1 = 1; /* N */2886 k1 = 0; /* N */ 2934 2887 t = 0.0; /* T */ 2935 2888 t1 = 0.0; /* T1 */ 2936 2889 t2 = 0.0; /* T2 */ 2937 h1 = 0.0;2938 h2 = 0.0;2939 2890 gap = 0.0; /* gap */ 2940 k2 = Meth_ Fourth; /* method */2891 k2 = Meth_Linear; /* method */ 2941 2892 dt = 0.0; 2942 2893 ClearHOMandDBN(&V); … … 2947 2898 P_addset(mysys, (long)t1sym); 2948 2899 P_addset(mysys, (long)t2sym); 2949 P_addset(mysys, (long)h1sym);2950 P_addset(mysys, (long)h2sym);2951 2900 P_addset(mysys, (long)gapsym); 2952 2901 P_addset(mysys, (long)rollsym); … … 2983 2932 break; 2984 2933 2985 case h1sym:2986 h1 = EVAL_(&V);2987 break;2988 2989 case h2sym:2990 h2 = EVAL_(&V);2991 break;2992 2993 2934 case gapsym: 2994 2935 gap = EVAL_(&V); … … 3038 2979 } 3039 2980 WITH2->PN = k1; WITH2->Pmethod = k2; 3040 WITH2->PTx1 = t1; WITH2->PTx2 = t2; 3041 WITH2->PH1 = h1; WITH2->PH2 = h2; 3042 WITH2->Pgap = gap; 2981 WITH2->PTx1 = t1; WITH2->PTx2 = t2; WITH2->Pgap = gap; 3043 2982 WITH2->PdTpar = dt; 3044 2983 AssignHOM(globval.Elem_nFam, &V); … … 3083 3022 getest__(P_expset(SET, 1 << ((long)comma)), "<, > expected", &V); 3084 3023 GetSym__(&V); 3085 QL = 0e0; 3086 QK = 0e0; 3087 QKV = 0e0; 3088 QKH = 0e0; 3089 QKxV = 0e0; 3090 QKxH = 0e0; 3091 QPhi = 0e0; 3092 QKS = 0e0; 3093 k1 = 1; 3094 k2 = Meth_Fourth; 3095 dt = 0e0; 3024 QL = 0e0; QK = 0e0; QKV = 0e0; QKH = 0e0; QKxV = 0e0; QKxH = 0e0; 3025 QPhi = 0e0; QKS = 0e0; k1 = 0; k2 = Meth_Linear; dt = 0e0; 3096 3026 ClearHOMandDBN(&V); 3097 3027 P_addset(P_expset(mysys, 0), (long)lsym); … … 3219 3149 getest__(P_expset(SET, 1 << ((long)comma)), "<, > expected", &V); 3220 3150 GetSym__(&V); 3221 QL = 0.0; 3222 k1 = 1; 3223 strcpy(str1, ""); 3224 strcpy(str2, ""); 3151 QL = 0.0; k1 = 0; strcpy(str1, ""); strcpy(str2, ""); 3225 3152 P_addset(P_expset(mysys, 0), (long)lsym); 3226 3153 P_addset(mysys, (long)nsym); … … 3572 3499 QL = 0.0; /* L */ 3573 3500 QK = 0.0; /* K */ 3574 k1 = 1; /* N */3501 k1 = 0; /* N */ 3575 3502 P_addset(P_expset(mysys, 0), (long)lsym); 3576 3503 P_addset(mysys, (long)bobrhosym); … … 3731 3658 Reg("drift ", drfsym, &V); 3732 3659 Reg("dt ", dtsym, &V); 3733 Reg("edge_effect1 ", edge_effect1sym, &V); /* Jianfeng Zhang*/3734 Reg("edge_effect2 ", edge_effect2sym, &V); /* Jianfeng Zhang */3735 3660 Reg("end ", endsym, &V); 3736 3661 Reg("ff1 ", ff1sym, &V); /* Laurent */ … … 3746 3671 Reg("gap ", gapsym, &V); 3747 3672 Reg("ghost ", gstsym, &V); 3748 Reg("h1 ", h1sym, &V);3749 Reg("h2 ", h2sym, &V);3750 3673 Reg("harm ", harmsym, &V); 3751 3674 Reg("harnum ", harnumsym, &V); -
branches/tracy3-3.10.1b/tracy/tracy/src/tpsa_lin.cc
r3 r23 414 414 } 415 415 416 /**************************** 417 * tan(x) 418 * *************************/ 416 419 417 void datan(const tps_buf &x, tps_buf &z) 420 418 { … … 424 422 } 425 423 426 /************************* 427 * cotan(x) 428 * ***********************/ 429 void dactan(const tps_buf &x, tps_buf &z) 430 { 431 tps_buf c, s; 432 433 dacos(x, c); dasin(x, s); dadiv_(c, s, z); 434 } 435 436 /************************************* 437 * 438 * Purpose: 439 * Get the derivatives of the arcsin(x) 440 * 441 * d(arcsin(u))/dx = (1/sqrt(1-u^2))*du/dx; 442 * 443 * Input: 444 * x: u 445 * Output: 446 * z: the differential of x. 447 * 448 * 449 * Comments: 450 * 13/11/2012 451 * Written by Jianfeng Nadolski @ LAL 452 * 453 * ***********************************/ 454 void daarcsin(const tps_buf &x, tps_buf &z) 455 { 456 int i; 457 double a; //differential of x; a = sqrt(1/1-u^2) 458 459 a = x[0]; z[0] = asin(a); a = 1.0/sqrt(1.0-sqr(a)); 460 for (i = 1; i <= ss_dim; i++) 461 z[i] = a*x[i]; 462 } 463 464 /************************************* 465 * 466 * Purpose: 467 * Get the derivatives of the arccos(x) 468 * 469 * d(arccos(u))/dx = -(1/sqrt(1-u^2))*du/dx; 470 * 471 * Input: 472 * x: u 473 * Output: 474 * z: the differential of x. 475 * 476 * 477 * Comments: 478 * 13/11/2012 479 * Written by Jianfeng Nadolski @ LAL 480 * 481 * ***********************************/ 482 void daarccos(const tps_buf &x, tps_buf &z) 483 { 484 int i; 485 double a; //differential of x; a = -sqrt(1/1-u^2) 486 487 a = x[0]; z[0] = asin(a); a = -1.0/sqrt(1.0-sqr(a)); 488 for (i = 1; i <= ss_dim; i++) 489 z[i] = a*x[i]; 490 491 } 492 /************************************* 493 * 494 * Purpose: 495 * Get the derivatives of the arctan(x) 496 * 497 * d(arctan(u))/dx = (1/1+u^2)*du/dx; 498 * 499 * Input: 500 * x: u 501 * Output: 502 * z: the differential of x. 503 * 504 * 505 * ***********************************/ 424 506 425 void daarctan(const tps_buf &x, tps_buf &z) 507 426 { 508 427 int i; 509 double a; //differential of x; a = (1/1+u^2)428 double a; 510 429 511 430 a = x[0]; z[0] = atan(a); a = 1.0/(1.0+sqr(a)); … … 514 433 } 515 434 516 /*************************************517 *518 * Purpose:519 * Get the derivatives of the arcctan(x)520 *521 * d(arcctan(u))/dx = -(1/1+u^2)*du/dx;522 *523 * Input:524 * x: u525 * Output:526 * z: the differential of x.527 *528 *529 * ***********************************/530 void daarcctan(const tps_buf &x, tps_buf &z)531 {532 int i;533 double a; //differential of x; a = -(1/1+u^2)534 535 a = x[0]; z[0] = atan(a); a = -1.0/(1.0+sqr(a));536 for (i = 1; i <= ss_dim; i++)537 z[i] = a*x[i];538 }539 435 540 436 void dafun_(const char *fun, const tps_buf &x, tps_buf &z) 541 437 { 542 438 tps_buf u; 543 439 544 440 if (!strncmp(fun, "INV ", dafunlen)) 545 441 dainv_(x, u); … … 554 450 else if (!strncmp(fun, "COS ", dafunlen)) 555 451 dacos(x, u); 556 else if (!strncmp(fun, "TAN ", dafunlen))557 datan(x, u);558 else if (!strncmp(fun, "CTAN ", dafunlen))559 dactan(x, u);560 452 else if (!strncmp(fun, "SINH ", dafunlen)) 561 453 dasinh(x, u); 562 454 else if (!strncmp(fun, "COSH ", dafunlen)) 563 455 dacosh(x, u); 564 else if (!strncmp(fun, "ASIN", dafunlen)) 565 daarcsin(x, u); 566 else if (!strncmp(fun, "ACOS", dafunlen)) 567 daarccos(x, u); 456 else if (!strncmp(fun, "TAN ", dafunlen)) 457 datan(x, u); 568 458 else if (!strncmp(fun, "ATAN", dafunlen)) 569 459 daarctan(x, u); 570 else if (!strncmp(fun, "ACTAN", dafunlen))571 daarcctan(x, u);572 460 else { 573 461 printf("dafun: illegal function %s\n", fun); -
branches/tracy3-3.10.1b/tracy/tracy/src/tracy.cc
r11 r23 97 97 template void radiate(ss_vect<tps> &, const double, const double, const tps[]); 98 98 99 template void Drift(double, double, ss_vect<double> &);100 101 template void Drift(double, double, ss_vect<tps> &);102 103 99 template void Drift(double, ss_vect<double> &); 104 100 … … 109 105 template void bend_fringe(double, ss_vect<tps> &); 110 106 111 template void bend_fringe(double, double, ss_vect<double> &); 112 113 template void bend_fringe(double, double, ss_vect<tps> &); 114 115 template static void BendCurvature(double, double, ss_vect<double> &); 116 117 template static void BendCurvature(double, double, ss_vect<tps> &); 118 119 template static void EdgeFocus(double, double, double, ss_vect<double> &, bool); 120 121 template static void EdgeFocus(double, double, double, ss_vect<tps> &,bool); 107 template static void EdgeFocus(double, double, double, ss_vect<double> &); 108 109 template static void EdgeFocus(double, double, double, ss_vect<tps> &); 122 110 123 111 template void quad_fringe(double, ss_vect<double> &); … … 128 116 129 117 template void Drift_Pass(CellType &, ss_vect<tps> &); 130 131 132 template void dipole_kick(double, double, double, ss_vect<double> &);133 template void dipole_kick(double, double, double, ss_vect<tps> &);134 template void multipole_kick(int, double[], double, double, ss_vect<double> &);135 template void multipole_kick(int, double[], double, double, ss_vect<tps> &);136 118 137 119 template void thin_kick(int, double[], double, double, double,
Note: See TracChangeset
for help on using the changeset viewer.