Bending Magnet Integrator

B1H=atrbend('B1H',0.092324800,23.366300)

B1H =

FamName: 'B1H'
Length: 0.0923
PolynomA: [0 0 0]
PolynomB: [0 0 0]
MaxOrder: 1
NumIntSteps: 10
BendingAngle: 23.3663
EntranceAngle: 11.6831
ExitAngle: 11.6831
K: 0
PassMethod: 'BendLinearPass'
Class: 'Bend'

esrf{14}

ans =

FamName: 'B1H'
Length: 2.1573
PolynomA: [0 0 0]
PolynomB: [0 0 0]
MaxOrder: 1
NumIntSteps: 10
BendingAngle: 0.0923
EntranceAngle: 0.0491
ExitAngle: 0.0432
K: 0
PassMethod: 'BndMPoleSymplectic4E2Pass'
Class: 'Bend'
BetaCode: 'DI'
FullGap: 0
FringeInt: 0
Energy: 6.0400e+09

static void bndthinkick(double* r, double* A, double* B, double L, double irho, int max_order)
/*
(1) PolynomA is neglected.
(2) The vector potential is expanded up to 4th order of x and y.
(3) Coefficients in PolynomB higher than 4th order is treated as if they are on straight geometry.
(4) The Hamiltonian is H2 = - h x delta - (1+h x)As/Brho-B0 x/Brho
*/
{ int i;
double ReSum = 0; /*B[max_order];*/
double ImSum = 0; /*A[max_order];*/
double ReSumTemp;
double K1,K2,K3,h;
K1 = B[1];
if (max_order>=2)
K2=B[2];
else
K2=0;
if (max_order>=3)
K3=B[3];
else
K3=0;
h=irho;
ReSum = B[max_order];
for(i=max_order-1;i>=0;i—)
{ ReSumTemp = ReSum*r[0] - ImSum*r[2] + B[i];
ImSum = ImSum*r[0] + ReSum*r[2] ;
ReSum = ReSumTemp;
}
r[1] -= L*(-h*r[4] + ReSum + h*(h*r[0]+K1*(r[0]*r[0]-0.5*r[2]*r[2])+K2*(r[0]*r[0]*r[0]-4.0/3.0*r[0]*r[2]*r[2])) );
r[3] += L*(ImSum+h*(K1*r[0]*r[2]+4.0/3.0*K2*r[0]*r[0]*r[2]+(h/6.0*K1-K2/3.0)*r[2]*r[2]*r[2])) ;
r[5] += L*h*r[0]; /* pathlength */
}
/* the pseudo-drift element described by Hamiltonian H1 = (1+hx) (px^2+py^2)/2(1+delta), */
static void ATbendhxdrift6(double* r, double L,double h)
{
double hs = h*L;
double i1pd = 1.0/(1+r[4]);
double x=r[0],px=r[1],y=r[2],py=r[3];
r[0] += (1+h*x)*px*i1pd*L+1/4.*hs*L*(px*px-py*py)*i1pd*i1pd; /* (1.0/h+x)*((1.0+hs*px*i1pd/2.)*(1.0+hs*px*i1pd/2.)-(hs*py*i1pd/2.)*(hs*py*i1pd/2.))-1./h;*/
r[1] -= hs*(px*px+py*py)*i1pd/2.0;
r[2]+= (1.0+h*x)*i1pd*py*L*(1.+px*hs/2.0);
r[5]+= (1.0+h*x)*i1pd*i1pd*L/2.0*(px*px+py*py);
}
void BndMPoleSymplectic4E2Pass(double *r, double le, double irho, double *A, double *B,
int max_order, int num_int_steps,
double entrance_angle, double exit_angle,
double fint1, double fint2, double gap,double h1,double h2,
double *T1, double *T2,
double *R1, double *R2, int num_particles)
{ int c,m;
double *r6;
double SL, L1, L2, K1, K2;
bool useT1, useT2, useR1, useR2, useFringe1, useFringe2;
SL = le/num_int_steps;
L1 = SL*DRIFT1;
L2 = SL*DRIFT2;
K1 = SL*KICK1;
K2 = SL*KICK2;
if(T1==NULL)
useT1=false;
else
useT1=true;
if(T2==NULL)
useT2=false;
else
useT2=true;
if(R1==NULL)
useR1=false;
else
useR1=true;
if(R2==NULL)
useR2=false;
else
useR2=true;
/* if either is 0 - do not calculate fringe effects */
if( fint1==0 || gap==0)
useFringe1 = false;
else
useFringe1=true;
if( fint2==0 || gap==0)
useFringe2 = false;
else
useFringe2=true;
for(c = 0;c<num_particles;c++) /* Loop over particles */
{ r6 = r+c*6;
if(!mxIsNaN(r6[0]))
{
/* misalignment at entrance */
if(useT1)
ATaddvv(r6,T1);
if(useR1)
ATmultmv(r6,R1);
/* edge focus */
if(useFringe1)
{
edge_fringe2A(r6, irho, entrance_angle,fint1,gap,h1,B[1]);
/* edge_fringe(r6, irho, entrance_angle,fint1,gap);*/
}
else
{
/* edge(r6, irho, entrance_angle); */
edge_fringe2A(r6, irho, entrance_angle,0,0,h1,B[1]);
}
/* integrator */
for(m=0; m < num_int_steps; m++) /* Loop over slices*/
{ r6 = r+c*6;
ATbendhxdrift6(r6,L1,irho);
bndthinkick(r6, A, B, K1, irho, max_order);
ATbendhxdrift6(r6,L2,irho);
bndthinkick(r6, A, B, K2, irho, max_order);
ATbendhxdrift6(r6,L2,irho);
bndthinkick(r6, A, B, K1, irho, max_order);
ATbendhxdrift6(r6,L1,irho);
}
/* edge focus */
if(useFringe2)
{
edge_fringe2B(r6, irho, exit_angle,fint2,gap,h2,B[1]);
/* edge_fringe(r6, irho, exit_angle,fint2,gap); */
}
else
{
/* edge(r6, irho, exit_angle); */
edge_fringe2B(r6, irho, exit_angle,0,0,h2,B[1]);
}
/* Misalignment at exit */
if(useR2)
ATmultmv(r6,R2);
if(useT2)
ATaddvv(r6,T2);
}
}
}

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License