0001 function [newring,newringrad] = atfastring(ring0,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 global GLOBVAL
0031
0032 [doplot,varargin]=getflag(varargin,'Plot');
0033 split=getargs(varargin,{[]});
0034 if nargin < 2
0035 split=[];
0036 end
0037 if islogical(split)
0038 iend=[find(split) length(ring0)+1];
0039 else
0040 iend=[split length(ring0)+1];
0041 end
0042 ibeg=[1 iend(1:end-1)];
0043
0044 xm=0.001;
0045 zm=0.0005;
0046 GLOBVAL.E0=atenergy(ring0);
0047 [lindata,tunes,xsi]=atlinopt(ring0,0);
0048 gamma=(1+lindata.alpha.*lindata.alpha)./lindata.beta;
0049
0050 ringv=arrayfun(@rearrange,ibeg,iend,'UniformOutput',false);
0051 ring=cat(1,ringv{:});
0052 markers=atgetcells(ring,'FamName','xbeg|xend');
0053 ringrad=atradon(ring);
0054
0055 orbit4=zeros(6,sum(markers));
0056 orbit4(1:5,:)=findsyncorbit(ring,0,markers);
0057 orbit4=num2cell(orbit4,1);
0058 r1=detuning(ring,gamma,xm,zm,orbit4(:,1));
0059
0060 orbit6=num2cell(findorbit6(ringrad,markers),1);
0061
0062 counter=0;
0063 [rv,rvrad]=cellfun(@rebuild,ringv,orbit4(1:2:end),orbit6(1:2:end),...
0064 orbit4(2:2:end),orbit6(2:2:end),'UniformOutput',false);
0065 nonlin_elem=atbaselem('NonLinear','DeltaQPass',...
0066 'Betax',lindata.beta(1),'Betay',lindata.beta(2),...
0067 'Alphax',lindata.alpha(1),'Alphay',lindata.alpha(2),...
0068 'Qpx',xsi(1),'Qpy',xsi(2),...
0069 'A1',r1(1),'A2',r1(2),'A3',r1(4),...
0070 'T1',-orbit4{end},'T2',orbit4{end});
0071 nonlin_elemrad=atbaselem('NonLinear','DeltaQPass',...
0072 'Betax',lindata.beta(1),'Betay',lindata.beta(2),...
0073 'Alphax',lindata.alpha(1),'Alphay',lindata.alpha(2),...
0074 'Qpx',xsi(1),'Qpy',xsi(2),...
0075 'A1',r1(1),'A2',r1(2),'A3',r1(4),...
0076 'T1',-orbit6{end},'T2',orbit6{end});
0077 newring=cat(1,rv{:},nonlin_elem);
0078 newringrad=cat(1,rvrad{:},nonlin_elemrad);
0079
0080 function rg=rearrange(i1,i2)
0081 slice=ring0(i1:i2-1);
0082 cav=atgetcells(slice,'Frequency') | atgetcells(slice,'Class','RingParam');
0083 rg=[slice(cav);atmarker('xbeg');slice(~cav);atmarker('xend')];
0084 end
0085 function [rg,rgrad]=rebuild(slice,o4b,o6b,o4e,o6e)
0086 counter=counter+1;
0087 cc=num2str(counter);
0088
0089
0090 i1=find(atgetcells(slice,'FamName','xbeg'),1);
0091 dipoles=atgetcells(slice,'BendingAngle');
0092 theta=atgetfieldvalues(slice(dipoles),'BendingAngle');
0093 lendp=atgetfieldvalues(slice(dipoles),'Length');
0094 s=diff(findspos(slice,[1 length(slice)+1]));
0095 I2=sum(abs(theta.*theta./lendp));
0096
0097 m66norad=symplectify(findm66(slice(i1:end),[],o4b));
0098 lin_elem=atM66(['Linear_' cc],m66norad,'T1',-o4b,'T2',o4e,'Length',s,'I2',I2);
0099 rg=[slice(1:i1-1);lin_elem];
0100
0101 [slicerad,radindex]=atradon(slice);
0102 diff_elem=atQuantDiff(['Diffusion_' cc],quantumDiff(slicerad,radindex,o6b));
0103 m66rad=findm66(slicerad(i1:end),[],o6b);
0104 lin_elemrad=atM66(['Linear_' cc],m66rad,'T1',-o6b,'T2',o6e,'Length',s,'I2',I2);
0105 rgrad=[slicerad(1:i1-1);lin_elemrad;diff_elem];
0106 end
0107 function r=detuning(ring,gamma,xm,zm,orbit)
0108 x2=linspace(0,xm.*xm,10);
0109 z2=linspace(0,zm.*zm,10);
0110 [nuxx,nuzx]=atnuampl(ring,sqrt(x2),1,orbit);
0111 [nuxz,nuzz]=atnuampl(ring,sqrt(z2),3,orbit);
0112 if doplot
0113 tune0=floor([nuxx(1);nuzz(1)]);
0114 subplot(2,1,1);
0115 plot(x2,[nuxx;nuzx]-tune0(:,ones(1,10)));
0116 subplot(2,1,2);
0117 plot(z2,[nuxz;nuzz]-tune0(:,ones(1,10)));
0118 end
0119 rx=([nuxx-nuxx(1);nuzx-nuzx(1)]*x2')./(x2([1 1],:)*x2')/gamma(1);
0120 rz=([nuxz-nuxz(1);nuzz-nuzz(1)]*z2')./(z2([1 1],:)*z2')/gamma(2);
0121 r=2*[rx;rz];
0122 end
0123 end