1
- #include "atconstants.h"
2
1
#include "atelem.c"
3
2
#include "atlalib.c"
4
- #include "atphyslib.c"
5
- #include "driftkickrad.c" /* bndthinkickrad.c */
3
+ #include "diff_bend_fringe.c"
4
+ #include "diff_bnd_kick.c"
5
+ #include "diff_drift.c"
6
6
#include "quadfringe.c" /* QuadFringePassP, QuadFringePassN */
7
7
8
8
struct elem
@@ -47,7 +47,8 @@ void BndMPoleSymplectic4RadPass(double *r, double le, double irho, double *A, do
47
47
double * T1 , double * T2 ,
48
48
double * R1 , double * R2 ,
49
49
double * RApertures , double * EApertures ,
50
- double * KickAngle , double scaling , double E0 , int num_particles )
50
+ double * KickAngle , double scaling , double gamma , int num_particles ,
51
+ double * bdiff )
51
52
{
52
53
double SL = le /num_int_steps ;
53
54
double L1 = SL * DRIFT1 ;
@@ -58,14 +59,16 @@ void BndMPoleSymplectic4RadPass(double *r, double le, double irho, double *A, do
58
59
bool useLinFrEleExit = (fringeIntM0 != NULL && fringeIntP0 != NULL && FringeQuadExit == 2 );
59
60
double B0 = B [0 ];
60
61
double A0 = A [0 ];
62
+ double rad_const = RAD_CONST * pow (gamma , 3 );
63
+ double diff_const = DIF_CONST * pow (gamma , 5 );
61
64
62
65
if (KickAngle ) { /* Convert corrector component to polynomial coefficients */
63
66
B [0 ] -= sin (KickAngle [0 ])/le ;
64
67
A [0 ] += sin (KickAngle [1 ])/le ;
65
68
}
66
69
#pragma omp parallel for if (num_particles > OMP_PARTICLE_THRESHOLD) default(none) \
67
- shared(r,num_particles,R1,T1,R2,T2,RApertures,EApertures,\
68
- irho,gap,A,B,L1,L2,K1,K2,max_order,num_int_steps,E0 ,scaling,\
70
+ shared(r,num_particles,R1,T1,R2,T2,RApertures,EApertures,bdiff, \
71
+ irho,gap,A,B,L1,L2,K1,K2,max_order,num_int_steps,rad_const, diff_const ,scaling,\
69
72
FringeBendEntrance,entrance_angle,fint1,FringeBendExit,exit_angle,fint2,\
70
73
FringeQuadEntrance,useLinFrEleEntrance,FringeQuadExit,useLinFrEleExit,fringeIntM0,fringeIntP0)
71
74
for (int c = 0 ; c < num_particles ; c ++ ) { /* Loop over particles */
@@ -81,7 +84,7 @@ void BndMPoleSymplectic4RadPass(double *r, double le, double irho, double *A, do
81
84
if (RApertures ) checkiflostRectangularAp (r6 ,RApertures );
82
85
if (EApertures ) checkiflostEllipticalAp (r6 ,EApertures );
83
86
/* edge focus */
84
- edge_fringe_entrance (r6 , irho , entrance_angle , fint1 , gap , FringeBendEntrance );
87
+ diff_bend_fringe (r6 , irho , entrance_angle , fint1 , gap , FringeBendEntrance , 1.0 , bdiff );
85
88
/* quadrupole gradient fringe entrance*/
86
89
if (FringeQuadEntrance && B [1 ]!= 0 ) {
87
90
if (useLinFrEleEntrance ) /*Linear fringe fields from elegant*/
@@ -91,13 +94,13 @@ void BndMPoleSymplectic4RadPass(double *r, double le, double irho, double *A, do
91
94
}
92
95
/* integrator */
93
96
for (m = 0 ; m < num_int_steps ; m ++ ) { /* Loop over slices */
94
- ATdrift6 (r6 ,L1 );
95
- bndthinkickrad (r6 , A , B , K1 , irho , E0 , max_order );
96
- ATdrift6 (r6 ,L2 );
97
- bndthinkickrad (r6 , A , B , K2 , irho , E0 , max_order );
98
- ATdrift6 (r6 ,L2 );
99
- bndthinkickrad (r6 , A , B , K1 , irho , E0 , max_order );
100
- ATdrift6 (r6 ,L1 );
97
+ diff_drift (r6 , L1 , bdiff );
98
+ diff_bnd_kick (r6 , A , B , max_order , K1 , irho , rad_const , diff_const , bdiff );
99
+ diff_drift (r6 , L2 , bdiff );
100
+ diff_bnd_kick (r6 , A , B , max_order , K2 , irho , rad_const , diff_const , bdiff );
101
+ diff_drift (r6 , L2 , bdiff );
102
+ diff_bnd_kick (r6 , A , B , max_order , K1 , irho , rad_const , diff_const , bdiff );
103
+ diff_drift (r6 , L1 , bdiff );
101
104
}
102
105
/* quadrupole gradient fringe */
103
106
if (FringeQuadExit && B [1 ]!= 0 ) {
@@ -107,7 +110,7 @@ void BndMPoleSymplectic4RadPass(double *r, double le, double irho, double *A, do
107
110
QuadFringePassN (r6 , B [1 ]);
108
111
}
109
112
/* edge focus */
110
- edge_fringe_exit (r6 , irho , exit_angle , fint2 , gap , FringeBendExit );
113
+ diff_bend_fringe (r6 , irho , exit_angle , fint2 , gap , FringeBendExit , -1.0 , bdiff );
111
114
/* Check physical apertures at the exit of the magnet */
112
115
if (RApertures ) checkiflostRectangularAp (r6 ,RApertures );
113
116
if (EApertures ) checkiflostEllipticalAp (r6 ,EApertures );
@@ -128,7 +131,9 @@ void BndMPoleSymplectic4RadPass(double *r, double le, double irho, double *A, do
128
131
ExportMode struct elem * trackFunction (const atElem * ElemData ,struct elem * Elem ,
129
132
double * r_in , int num_particles , struct parameters * Param )
130
133
{
131
- double irho , energy ;
134
+ double irho , gamma ;
135
+ double * bdiff = Param -> bdiff ;
136
+
132
137
if (!Elem ) {
133
138
double Length , BendingAngle , EntranceAngle , ExitAngle , FullGap , Scaling ,
134
139
FringeInt1 , FringeInt2 , Energy ;
@@ -193,7 +198,7 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
193
198
Elem -> KickAngle = KickAngle ;
194
199
}
195
200
irho = Elem -> BendingAngle /Elem -> Length ;
196
- energy = atEnergy (Param -> energy , Elem -> Energy );
201
+ gamma = atGamma (Param -> energy , Elem -> Energy , Param -> rest_energy );
197
202
198
203
BndMPoleSymplectic4RadPass (r_in , Elem -> Length , irho , Elem -> PolynomA , Elem -> PolynomB ,
199
204
Elem -> MaxOrder , Elem -> NumIntSteps , Elem -> EntranceAngle , Elem -> ExitAngle ,
@@ -203,7 +208,7 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
203
208
Elem -> fringeIntM0 , Elem -> fringeIntP0 ,
204
209
Elem -> T1 , Elem -> T2 , Elem -> R1 , Elem -> R2 ,
205
210
Elem -> RApertures , Elem -> EApertures ,
206
- Elem -> KickAngle , Elem -> Scaling , energy , num_particles );
211
+ Elem -> KickAngle , Elem -> Scaling , gamma , num_particles , bdiff );
207
212
return Elem ;
208
213
}
209
214
@@ -224,6 +229,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
224
229
double * PolynomA , * PolynomB , * R1 , * R2 , * T1 , * T2 , * EApertures , * RApertures , * fringeIntM0 , * fringeIntP0 , * KickAngle ;
225
230
double irho ;
226
231
double * r_in ;
232
+ double Gamma ;
227
233
const mxArray * ElemData = prhs [0 ];
228
234
int num_particles = mxGetN (prhs [1 ]);
229
235
if (mxGetM (prhs [1 ]) != 6 ) mexErrMsgTxt ("Second argument must be a 6 x N matrix" );
@@ -260,6 +266,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
260
266
261
267
/* ALLOCATE memory for the output array of the same size as the input */
262
268
plhs [0 ] = mxDuplicateArray (prhs [1 ]);
269
+ Gamma = atGamma (Energy , Energy , rest_energy );
263
270
r_in = mxGetDoubles (plhs [0 ]);
264
271
265
272
BndMPoleSymplectic4RadPass (r_in , Length , irho , PolynomA , PolynomB ,
@@ -269,7 +276,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
269
276
FringeQuadEntrance , FringeQuadExit ,
270
277
fringeIntM0 , fringeIntP0 ,
271
278
T1 , T2 , R1 , R2 , RApertures , EApertures ,
272
- KickAngle , Scaling , Energy , num_particles );
279
+ KickAngle , Scaling , Gamma , num_particles , NULL );
273
280
} else if (nrhs == 0 ) {
274
281
/* list of required fields */
275
282
plhs [0 ] = mxCreateCellMatrix (9 ,1 );
0 commit comments