The elegant code offers the function that can generate random multipole error coefficients with the input parameters
I saw the example PAR/randomMultipoles
There, by using the sddsrandmult code, the multipole coeffecients are calculated.
However, I am confused the meaning of the input parameters such as "dx_pole", "dy_pole", "dradius", "dx_split", "dy_split", and "dphi_halves".
First of all, please let me know the exact definition of input parameters : "dx_pole", "dy_pole", "dradius", "dx_split", "dy_split", and "dphi_halves".
I read the reference paper (K. Halbach, NIM Vol. 74, No. 1, 1969) and the source code of the sddsrandmult.c but the meaning of input parameters are still unclear to me.
N = coefs[iN].N;
crot = cos(PI/2./N);
srot = sin(PI/2./N);
for (i_case=0; i_case<n_cases; i_case++) {
/* calculate the parameters for the halves */
dxh = gauss_rn_lim(0.0, dx_split, 2.0, random_1);
dyh = gauss_rn_lim(0.0, dy_split, 2.0, random_1);
dr = gauss_rn_lim(0.0, dradius, 2.0, random_1);
dphi = gauss_rn_lim(0.0, dphi_halves, 2.0, random_1);
for (i=0; i<n_harm+1; i++)
f = g = 0;
for (m=0; m<2*N; m++) {
/* sum over all poles */
/*  fractional dx and dy in coordinate system N, for which magnet looks normally oriented */
fdx = gauss_rn_lim(0.0, dx_pole, 2.0, random_1) + (m<N?dxh:dxh);
fdy = gauss_rn_lim(0.0, dy_pole, 2.0, random_1) + (m<N?dyh:dyh);
/*  angle of pole in system S, where magnet has a pole on the x axis */
alpha = (PI/N)*m;
/*  (fdx, fdy) rotated into system S, with radial errors */
fdX = crot*fdx + srot*fdy + dr*cos(alpha) ;
fdY = srot*fdx + crot*fdy + dr*sin(alpha) ;
/*  angle and magnitude of displacement vector in S system */
if (fdX==0 && fdY==0)
gamma = eps = 0;
else {
gamma = atan2(fdY, fdX);
eps = hypot(fdY, fdX);
}
exp1 = cexpi(gammaalpha);
exp2 = std::conj(exp1);
for (i=1; i<=n_harm; i++) {
/* loop over all harmonics */
dHn = (exp1*(coefs[iN].bm[i1]coefs[iN].am[i1])*eps/2.0 +
exp2*(coefs[iN].bm[i1]+coefs[iN].am[i1])*eps/2.0)
*cexpi((N+i)*alpha)*cexpi(PI/2(PI*i)/(2.*N));
f[i1] += dHn.real();
g[i1] += dHn.imag();
}
}
/* add rotation error contribution */
if (dphi_halves) {
for (i=1; i<=n_harm; i++) {
/* loop over all harmonics */
if ((i+N)%2 && dphi_halves && coefs[iN].rhom[i1])
f[i1] += dphi*coefs[iN].rhom[i1]/cos(PI*i/(2*N));
}
}
/* find maximum total error for all harmonics greater in harmonic number to the fundamental */
for (i=N; i<n_harm; i++) {
f[n_harm] += fabs(f);
g[n_harm] += fabs(g);
}
/* keep statistics on rms for each harmonic */
for (i=0; i<n_harm; i++) {
frms += sqr(f);
grms += sqr(g);
}
for (i=0; i<n_harm; i++)
fprintf(fpSDDS, "%13.6le ", f*ipow(reference_radius/bore_radius, i));
fprintf(fpSDDS, "%13.6le ", f);
for (i=0; i<n_harm; i++)
fprintf(fpSDDS, "%13.6le ", g[i]*ipow(reference_radius/bore_radius, i));
fprintf(fpSDDS, "%13.6le ", g[i]);
fputc('\n', fpSDDS);
}
I think this part is the key of the code.
In calculating dfX or dfY, why the crot and srot are constant regardless of the pole (m=0,1,2,..)? and on the other hand, why alpha is varied with the pole (m=0,1,2...)?
All contribution of the poles are the summation of each pole's perturbation.
f[i1] += dHn.real();
g[i1] += dHn.imag();
This two lines do it? Do I understand the code in the right way?
The meaning of the input parameters on the command "perturbation"
Moderators: cyao, michael_borland

 Posts: 1815
 Joined: 19 May 2008, 09:33
 Location: Argonne National Laboratory
 Contact:
Re: The meaning of the input parameters on the command "perturbation"
The meaning of those terms is explained on the manual page for sddsrandmult.
The code was written nearly 30 years ago, so I'm a bit hazy on the details. However, what I recall is that the calculations for each pole are done in the frame in which that pole is on the x axis. The contributions are then rotated back into the normal magnet frame before being added in to the total. The backrotation includes not only the geometrical rotation angle, but also reflects the fact that high multipoles have a morerapid dependence on angle than the main multipole.
Hope this helps.
Michael
The code was written nearly 30 years ago, so I'm a bit hazy on the details. However, what I recall is that the calculations for each pole are done in the frame in which that pole is on the x axis. The contributions are then rotated back into the normal magnet frame before being added in to the total. The backrotation includes not only the geometrical rotation angle, but also reflects the fact that high multipoles have a morerapid dependence on angle than the main multipole.
Hope this helps.
Michael
Re: The meaning of the input parameters on the command "perturbation"
Thank you I will check it more by myself.
I have one more question. If I want to check the applied multipole errors. Where can I see it? Specially I want to know the random multipole is well applied for each quadrupole or sextupole.
In *.lte file, I insert the random multipole error for the quadrupole "Q1" with "RANDOM_MULTIPOLES = *.sdds" parameter setting. In this case, the Q1 quadrupoles have random multipole error along the ring(There are many Q1s in the ring). I want to check the each Q1's multipole fields whether the random error is inserted in appropriate way.
*.param or *.new file looks don't contain the multipole error information. Also, *.erl file only contains the error command information.
How can I see the multipole errors of each elements?
I have one more question. If I want to check the applied multipole errors. Where can I see it? Specially I want to know the random multipole is well applied for each quadrupole or sextupole.
In *.lte file, I insert the random multipole error for the quadrupole "Q1" with "RANDOM_MULTIPOLES = *.sdds" parameter setting. In this case, the Q1 quadrupoles have random multipole error along the ring(There are many Q1s in the ring). I want to check the each Q1's multipole fields whether the random error is inserted in appropriate way.
*.param or *.new file looks don't contain the multipole error information. Also, *.erl file only contains the error command information.
How can I see the multipole errors of each elements?