0001 function [nux,nuy,diffu]=fmap_soleilnu(nx,ny,ax,ay)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 pathold = path;
0020
0021 if (~findstr(pathold,'matlab\at\accelerator\simulator\element'))
0022 atinit;
0023 end
0024
0025 solamor2
0026 radiationoff;
0027 cavityoff;
0028
0029
0030
0031
0032
0033
0034 plotbeta;
0035
0036
0037
0038
0039
0040 fprintf('Type any key to continue ...\n');
0041 pause;
0042
0043 NT = 1024;
0044
0045 T = ringpass(THERING,[0;0;0;0;0;0],1);
0046
0047 for i=1:nx
0048 ampx = ax*sqrt(i/nx);
0049
0050 for j=1:ny
0051 ampy = ay*sqrt(j/ny);
0052 sampx = int2str(ampx);
0053 sampy = int2str(ampy);
0054
0055 fprintf('amp_x=%g mm, amp_y=%g mm\n',ampx,ampy);
0056
0057 X0=[ampx/1000 0 ampy/1000 0 0 0]';
0058
0059 clear LOSSFLAG
0060 cpustart=cputime;
0061 T = ringpass(THERING,X0,NT,'reuse');
0062 cpustop=cputime;
0063 fprintf('track time for 1024 turns : %g s\n',cpustop-cpustart);
0064
0065
0066 Tx = T(1,:);
0067 Txp = T(2,:);
0068 Ty = T(3,:);
0069 Typ = T(4,:);
0070 TE = T(5,:);
0071 Tphi = T(6,:);
0072
0073 if (length(Ty)==1024) & (all(Ty<0.04)) ...
0074 & (~any(isnan(Ty))) & (LOSSFLAG==0)
0075
0076 cpustart=cputime;
0077 [tmpnux1]=abs(calcnaff(Tx(1:512),Txp(1:512),1)/(2*pi));
0078 [tmpnuy1]=abs(calcnaff(Ty(1:512),Typ(1:512),1)/(2*pi));
0079 [tmpnux2]=abs(calcnaff(Tx(513:1024),Txp(513:1024),1)/(2*pi));
0080 [tmpnuy2]=abs(calcnaff(Ty(513:1024),Typ(513:1024),1)/(2*pi));
0081
0082 cpustop=cputime;
0083 fprintf('NAFF CPU time (4*512 turns) : %g s\n',cpustop-cpustart);
0084
0085
0086 nux(i,j)=0.0; nuy(i,j) = 0.0;
0087 pampx(i,j)=-1;pampy(i,j)=-1;
0088
0089
0090 pampx(i,j)=ampx;
0091 pampy(i,j)=ampy;
0092 if ((abs(tmpnuy1(1))>0.001) & (abs(tmpnuy1(1)-tmpnux1(1))>0.001))
0093 nuy(i,j)=tmpnuy1(1);
0094 else
0095 nuy(i,j)=tmpnuy1(2);
0096 end
0097
0098 if (abs(tmpnux1(1))>0.001)
0099 nux(i,j)=tmpnux1(1);
0100 else
0101 nux(i,j)=tmpnux1(2);
0102 end
0103
0104 if ((abs(tmpnuy2(1))>0.001) & (abs(tmpnuy2(1)-tmpnux2(1))>0.001))
0105 nuy2=tmpnuy2(1);
0106 else
0107 nuy2=tmpnuy2(2);
0108 end
0109
0110 if (abs(tmpnux2(1))>0.001)
0111 nux2=tmpnux2(1);
0112 else
0113 nux2=tmpnux2(2);
0114 end
0115
0116
0117 if (length(nuy2)==1) & (length(nux2)==1) & (length(nux(i,j))==1) & (length(nuy(i,j))==1)
0118 diffu(i,j)=log10(sqrt((tmpnuy2-nuy(i,j))^2+(tmpnux2-nux(i,j))^2)/512);
0119 else
0120 diffu(i,j) = -3;
0121 end
0122
0123 if (diffu(i,j) < (-10))
0124 diffu(i,j) = -10;
0125 end
0126
0127 taxi = ax*sqrt(i/nx);
0128 taxii = ax*sqrt((i-1)/nx);
0129 tayj = ay*sqrt(j/ny);
0130 tayjj = ay*sqrt((j-1)/ny);
0131
0132 if (i>1) & (j>1)
0133 xpos(:,(i-1)*(ny)+j) = [taxii;taxii;taxi;taxi];
0134 ypos(:,(i-1)*(ny)+j) = [tayjj;tayj;tayj;tayjj];
0135 elseif (i>1)
0136 xpos(:,(i-1)*(ny)+j) = [taxii;taxii;taxi;taxi];
0137 ypos(:,(i-1)*(ny)+j) = [0;tayj;tayj;0];
0138 elseif (j>1)
0139 xpos(:,(i-1)*(ny)+j) = [0;0;taxi;taxi];
0140 ypos(:,(i-1)*(ny)+j) = [tayjj;tayj;tayj;tayjj];
0141 else
0142 xpos(:,(i-1)*(ny)+j) = [0;0;taxi;taxi];
0143 ypos(:,(i-1)*(ny)+j) = [0;tayj;tayj;0];
0144 end
0145
0146 nuxpos(:,(i-1)*(ny)+j) = ...
0147 [nux(i,j)-.0001;nux(i,j)-.0001;nux(i,j)+.0001;nux(i,j)+.0001];
0148 nuypos(:,(i-1)*(ny)+j) = ...
0149 [nuy(i,j)-.0006;nuy(i,j)+.0006;nuy(i,j)+.0006;nuy(i,j)-.0006];
0150
0151 diffuvec(1:4,(i-1)*(ny)+j) = diffu(i,j);
0152
0153
0154 else
0155 nux(i,j)=0.0; nuy(i,j)=0.0;
0156 pampx(i,j)=-1;pampy(i,j)=-1;
0157 xpos(:,(i-1)*(ny)+j) = [0;0;0;0];
0158 ypos(:,(i-1)*(ny)+j) = [0;0;0;0];
0159 nuxpos(:,(i-1)*(ny)+j) = [0;0;0;0];
0160 nuypos(:,(i-1)*(ny)+j) = [0;0;0;0];
0161 diffu(i,j)=-10;
0162 diffuvec(1:4,(i-1)*(ny)+j) = [-10;-10;-10;-10];
0163 end
0164
0165 if nux(i,j) & nuy(i,j)
0166 fprintf('nu_x=%g, nu_y=%g\n',14+nux(i,j),8+nuy(i,j));
0167 else
0168 fprintf('particle lost\n');
0169 end
0170
0171 end
0172
0173 save 'freqmap_new' nux nuy diffu nuxpos nuypos xpos ypos diffuvec pampx pampy
0174
0175 end
0176
0177 f1=figure;
0178 plot(18+nux,10+nuy,'b.');
0179 axis([18.2 18.5 10.0 10.5]);
0180 title('SOLEIL lattice, calculated frequency map (NAFF)');
0181 xlabel('\nu_x');
0182 ylabel('\nu_y');
0183 pause(0.1);
0184
0185 if min(size(diffu)) > 1
0186
0187 figure;
0188 fill(xpos,ypos,diffuvec);
0189 axis([0 ax 0 ay]);
0190 caxis([-10 -3]);
0191 hold on;
0192 shading flat;
0193 colormap('jet');
0194 colorbar;
0195 title('SOLEIL lattice, calculated frequency map (NAFF)');
0196 xlabel('x position [mm] (injection straight)');
0197 ylabel('y position [mm]');
0198 hold off;
0199
0200 figure;
0201 fill(18+nuxpos,10+nuypos,diffuvec);
0202 axis([18.2 18.5 10.0 10.5]);
0203 caxis([-10 -3]);
0204 hold on;
0205 shading flat;
0206 colormap('jet');
0207 colorbar;
0208 title('SOLEIL lattice, calculated frequency map (NAFF)');
0209 xlabel('\nu_x');
0210 ylabel('\nu_y');
0211 hold off;
0212
0213 end