[3] | 1 | /* Tracy-2 |
---|
| 2 | |
---|
| 3 | J. Bengtsson, CBP, LBL 1990 - 1994 Pascal version |
---|
| 4 | SLS, PSI 1995 - 1997 |
---|
| 5 | M. Boege SLS, PSI 1998 C translation |
---|
| 6 | L. Nadolski SOLEIL 2002 Link to NAFF, Radia field maps |
---|
| 7 | J. Bengtsson NSLS-II, BNL 2004 - |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | To generate a lattice flat file. |
---|
| 11 | |
---|
| 12 | Type codes: |
---|
| 13 | |
---|
| 14 | marker -1 |
---|
| 15 | drift 0 |
---|
| 16 | multipole 1 |
---|
| 17 | cavity 2 |
---|
| 18 | thin kick 3 |
---|
| 19 | wiggler 4 |
---|
| 20 | kick_map 6 |
---|
| 21 | |
---|
| 22 | Integration methods: |
---|
| 23 | |
---|
| 24 | fourth order symplectic integrator 4 |
---|
| 25 | |
---|
| 26 | Format: |
---|
| 27 | |
---|
| 28 | name, family no, kid no, element no |
---|
| 29 | type code, integration method, no of integration steps |
---|
| 30 | vacuum apertures: xmin, xmax, ymin, ymax |
---|
| 31 | |
---|
| 32 | The following lines follows depending on element type. |
---|
| 33 | |
---|
| 34 | type |
---|
| 35 | |
---|
| 36 | 1) drift: L |
---|
| 37 | |
---|
| 38 | 2) multipole: |
---|
| 39 | a.) hor., ver. displacement, roll angle (design), roll angle (error); |
---|
| 40 | b.) L, 1/rho, entrance angle, exit angle, totoal magnet gap[m]; |
---|
| 41 | c.) number of orders with nonzero field components, design field order |
---|
| 42 | d.) The last lines are the nonzero multipole components, |
---|
| 43 | the format is: |
---|
| 44 | n, Bn , An |
---|
| 45 | where n is the field order, Bn is the upright |
---|
| 46 | field component, Bn is the skew field component |
---|
| 47 | |
---|
| 48 | 3) wiggler: L [m], lambda [m] |
---|
| 49 | no of harmonics |
---|
| 50 | harm no, kxV [1/m], BoBrhoV [1/m], kxH, BoBrhoH, phi |
---|
| 51 | ... |
---|
| 52 | |
---|
| 53 | 4) cavity: cavity voltage/beam energy [eV], omega/c, beam energy [eV] |
---|
| 54 | |
---|
| 55 | 5) thin kick: hor., ver. displacement, roll angle (total) |
---|
| 56 | no of nonzero multipole coeff. |
---|
| 57 | n, b , a |
---|
| 58 | n n |
---|
| 59 | ... |
---|
| 60 | |
---|
| 61 | 6) kick_map: order <file name> |
---|
| 62 | |
---|
| 63 | */ |
---|
| 64 | |
---|
| 65 | #define snamelen 10 |
---|
| 66 | |
---|
| 67 | // numerical type codes |
---|
| 68 | #define marker_ -1 |
---|
| 69 | #define drift_ 0 |
---|
| 70 | #define mpole_ 1 |
---|
| 71 | #define cavity_ 2 |
---|
| 72 | #define thinkick_ 3 |
---|
| 73 | #define wiggler_ 4 |
---|
| 74 | #define kick_map_ 6 |
---|
| 75 | |
---|
| 76 | /****************************************************************************** |
---|
| 77 | void prtName(FILE *fp, const int i, |
---|
| 78 | const int type, const int method, const int N) |
---|
| 79 | |
---|
| 80 | Purpose: |
---|
| 81 | Print out the general imformation of an element to a file |
---|
| 82 | |
---|
| 83 | Input: |
---|
| 84 | i index number in the whole lattice |
---|
| 85 | type predefined integer number for different type of element |
---|
| 86 | Type codes: |
---|
| 87 | marker -1 |
---|
| 88 | drift 0 |
---|
| 89 | multipole 1 |
---|
| 90 | cavity 2 |
---|
| 91 | thin kick 3 |
---|
| 92 | wiggler 4 |
---|
| 93 | kick_map 6 |
---|
| 94 | |
---|
| 95 | method integrated method |
---|
| 96 | N number of integration steps of the element |
---|
| 97 | |
---|
| 98 | Output: |
---|
| 99 | Output to the file as the first 3 lines in file "fp": |
---|
| 100 | |
---|
| 101 | L1: element name, family index, kid index, element index in the whole lattice |
---|
| 102 | L2: type code, integration method, number of integration steps |
---|
| 103 | L3: vacuum apertures: xmin, xmax, ymin, ymax |
---|
| 104 | |
---|
| 105 | Comments: |
---|
| 106 | Called by prtmfile() |
---|
| 107 | ******************************************************************************/ |
---|
| 108 | void prtName(FILE *fp, const int i, const int type, const int method, |
---|
| 109 | const int N) { |
---|
| 110 | fprintf(fp, "%-15s %4ld %4ld %4d\n", Cell[i].Elem.PName, Cell[i].Fnum, |
---|
| 111 | Cell[i].Knum, i); |
---|
| 112 | fprintf(fp, " %3d %3d %3d\n", type, method, N); |
---|
| 113 | fprintf(fp, " %23.16e %23.16e %23.16e %23.16e\n", Cell[i].maxampl[X_][0], |
---|
| 114 | Cell[i].maxampl[X_][1], Cell[i].maxampl[Y_][0], Cell[i].maxampl[Y_][1]); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | /****************************************************************************** |
---|
| 118 | void prtHOM(FILE *fp, const int n_design, const mpolArray PB, const int Order) |
---|
| 119 | |
---|
| 120 | Purpose: |
---|
| 121 | Print out all field component for multipole to a file |
---|
| 122 | |
---|
| 123 | Input: |
---|
| 124 | fp file name |
---|
| 125 | n_design design order of multipole |
---|
| 126 | PB multipole field components arry, format is: n Bn An |
---|
| 127 | Order maximum order of multipole |
---|
| 128 | |
---|
| 129 | Output: |
---|
| 130 | None |
---|
| 131 | |
---|
| 132 | Comments: |
---|
| 133 | Called by prtmfile() |
---|
| 134 | ******************************************************************************/ |
---|
| 135 | void prtHOM(FILE *fp, const int n_design, const mpolArray PB, const int Order) { |
---|
| 136 | int i = 0, nmpole = 0; |
---|
| 137 | |
---|
| 138 | for (i = 1; i <= Order; i++) { |
---|
| 139 | if ((PB[HOMmax - i] != 0.0) || (PB[HOMmax + i] != 0.0)) |
---|
| 140 | nmpole++; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | fprintf(fp, " %2d %2d\n", nmpole, n_design); |
---|
| 144 | |
---|
| 145 | for (i = 1; i <= Order; i++) { |
---|
| 146 | if ((PB[HOMmax - i] != 0.0) || (PB[HOMmax + i] != 0.0)) |
---|
| 147 | fprintf(fp, "%3d %23.16e %23.16e\n", i, PB[HOMmax + i], PB[HOMmax - i]); |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | /****************************************************************************** |
---|
| 152 | void prtmfile(const char mfile_dat[]) |
---|
| 153 | |
---|
| 154 | Purpose: |
---|
| 155 | Print out flatfile |
---|
| 156 | |
---|
| 157 | Input: |
---|
| 158 | fp filename |
---|
| 159 | |
---|
| 160 | Output: |
---|
| 161 | None |
---|
| 162 | |
---|
| 163 | Comments: |
---|
| 164 | |
---|
| 165 | ******************************************************************************/ |
---|
| 166 | void prtmfile(const char mfile_dat[]) { |
---|
| 167 | int i, j; |
---|
| 168 | FILE *mfile; |
---|
| 169 | |
---|
| 170 | mfile = file_write(mfile_dat); |
---|
| 171 | for (i = 0; i <= globval.Cell_nLoc; i++) { |
---|
| 172 | switch (Cell[i].Elem.Pkind) { |
---|
| 173 | case drift: |
---|
| 174 | prtName(mfile, i, drift_, 0, 0); |
---|
| 175 | fprintf(mfile, " %23.16e\n", Cell[i].Elem.PL); |
---|
| 176 | break; |
---|
| 177 | case Mpole: |
---|
| 178 | if (Cell[i].Elem.PL != 0.0) { |
---|
| 179 | prtName(mfile, i, mpole_, Cell[i].Elem.M->Pmethod, Cell[i].Elem.M->PN); |
---|
| 180 | fprintf(mfile, " %23.16e %23.16e %23.16e %23.16e\n", Cell[i].dS[X_], |
---|
| 181 | Cell[i].dS[Y_], Cell[i].Elem.M->PdTpar, Cell[i].Elem.M->PdTsys |
---|
| 182 | + Cell[i].Elem.M->PdTrms * Cell[i].Elem.M->PdTrnd); |
---|
| 183 | fprintf(mfile, " %23.16e %23.16e %23.16e %23.16e %23.16e\n", |
---|
| 184 | Cell[i].Elem.PL, Cell[i].Elem.M->Pirho, Cell[i].Elem.M->PTx1, |
---|
| 185 | Cell[i].Elem.M->PTx2, Cell[i].Elem.M->Pgap); |
---|
| 186 | prtHOM(mfile, Cell[i].Elem.M->n_design, Cell[i].Elem.M->PB, |
---|
| 187 | Cell[i].Elem.M->Porder); |
---|
| 188 | } else { |
---|
| 189 | prtName(mfile, i, thinkick_, Cell[i].Elem.M->Pmethod, |
---|
| 190 | Cell[i].Elem.M->PN); |
---|
| 191 | fprintf(mfile, " %23.16e %23.16e %23.16e\n", Cell[i].dS[X_], |
---|
| 192 | Cell[i].dS[Y_], Cell[i].Elem.M->PdTsys + Cell[i].Elem.M->PdTrms |
---|
| 193 | * Cell[i].Elem.M->PdTrnd); |
---|
| 194 | prtHOM(mfile, Cell[i].Elem.M->n_design, Cell[i].Elem.M->PB, |
---|
| 195 | Cell[i].Elem.M->Porder); |
---|
| 196 | } |
---|
| 197 | break; |
---|
| 198 | case Wigl: |
---|
| 199 | prtName(mfile, i, wiggler_, Cell[i].Elem.W->Pmethod, Cell[i].Elem.W->PN); |
---|
| 200 | fprintf(mfile, " %23.16e %23.16e\n", Cell[i].Elem.PL, |
---|
| 201 | Cell[i].Elem.W->lambda); |
---|
| 202 | fprintf(mfile, "%2d\n", Cell[i].Elem.W->n_harm); |
---|
| 203 | for (j = 0; j < Cell[i].Elem.W->n_harm; j++) { |
---|
| 204 | fprintf(mfile, "%2d %23.16e %23.16e %23.16e %23.16e %23.16e\n", |
---|
| 205 | Cell[i].Elem.W->harm[j], Cell[i].Elem.W->kxV[j], |
---|
| 206 | Cell[i].Elem.W->BoBrhoV[j], Cell[i].Elem.W->kxH[j], |
---|
| 207 | Cell[i].Elem.W->BoBrhoH[j], Cell[i].Elem.W->phi[j]); |
---|
| 208 | } |
---|
| 209 | break; |
---|
| 210 | case Cavity: |
---|
| 211 | prtName(mfile, i, cavity_, 0, 0); |
---|
| 212 | fprintf(mfile, " %23.16e %23.16e %d %23.16e\n", Cell[i].Elem.C->Pvolt |
---|
| 213 | / (1e9 * globval.Energy), 2.0 * M_PI * Cell[i].Elem.C->Pfreq / c0, |
---|
| 214 | Cell[i].Elem.C->Ph, 1e9 * globval.Energy); |
---|
| 215 | break; |
---|
| 216 | case marker: |
---|
| 217 | prtName(mfile, i, marker_, 0, 0); |
---|
| 218 | break; |
---|
| 219 | case Insertion: |
---|
| 220 | prtName(mfile, i, kick_map_, Cell[i].Elem.ID->Pmethod, |
---|
| 221 | Cell[i].Elem.ID->PN); |
---|
| 222 | if (Cell[i].Elem.ID->firstorder) |
---|
| 223 | fprintf(mfile, " %3.1lf %1d %s\n", Cell[i].Elem.ID->scaling1, 1, |
---|
| 224 | Cell[i].Elem.ID->fname1); |
---|
| 225 | if (Cell[i].Elem.ID->secondorder) |
---|
| 226 | fprintf(mfile, " %3.1lf %1d %s\n", Cell[i].Elem.ID->scaling1, 2, |
---|
| 227 | Cell[i].Elem.ID->fname2); |
---|
| 228 | break; |
---|
| 229 | default: |
---|
| 230 | fprintf(mfile, "prtmfile: unknown type\n"); |
---|
| 231 | break; |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | fclose(mfile); |
---|
| 235 | } |
---|