Home > pubtools > LatticeTuningFunctions > correction > RDT > atavedata_mod.m

atavedata_mod

PURPOSE ^

ATAVEDATA Average of optical functions on selected elements

SYNOPSIS ^

function [lindata,avebeta,avemu,avedisp,nu,xsi]=atavedata_mod(ring,dpp,refpts,varargin)

DESCRIPTION ^

ATAVEDATA       Average of optical functions on selected elements

[LINDATA,AVEBETA,AVEMU,AVEDISP,TUNES,CHROMS]=ATAVEDATA(RING,DPP,REFPTS)

LINDATA : Identical to ATLINOPT output
AVEBEA :  Average Beta functions
AVEMU :   Average phase advance
AVEDISP : Average dispersion
TUNES : Vector of tunes
CHROMS : Vector of chromaticites

 function written by L.Farvacque

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [lindata,avebeta,avemu,avedisp,nu,xsi]=atavedata_mod(ring,dpp,refpts,varargin)
0002 %ATAVEDATA       Average of optical functions on selected elements
0003 %
0004 %[LINDATA,AVEBETA,AVEMU,AVEDISP,TUNES,CHROMS]=ATAVEDATA(RING,DPP,REFPTS)
0005 %
0006 %LINDATA : Identical to ATLINOPT output
0007 %AVEBEA :  Average Beta functions
0008 %AVEMU :   Average phase advance
0009 %AVEDISP : Average dispersion
0010 %TUNES : Vector of tunes
0011 %CHROMS : Vector of chromaticites
0012 %
0013 % function written by L.Farvacque
0014 
0015 lr=length(ring)+1;
0016 if islogical(refpts)
0017     refs=[refpts(:);false(lr-length(refpts),1)];
0018 else
0019     refs=false(lr,1); % lr
0020     refs(refpts)=true;
0021 end
0022 long=atgetcells(ring,'Length',@(elem,lg) lg>0) & refs(1:end-1); %lr-1
0023 needed=refs | [false;long]; %lr
0024 [lind,nu,xsi]=atlinopt(ring,dpp,find(needed),varargin{:}); %needed
0025 
0026 lindata=lind(refs(needed)); %refpts
0027 avebeta=cat(1,lindata.beta); %refpts
0028 avemu=cat(1,lindata.mu); %refpts
0029 avedisp=cat(2,lindata.Dispersion)'; %refpts
0030 
0031 if any(long)
0032     initial=[long(needed(1:end-1));false]; %needed
0033     final=[false;initial(1:end-1)]; %needed
0034 
0035     lg=initial(refs(needed)); % refpts
0036     L=atgetfieldvalues(ring(long),'Length'); %long
0037     
0038     beta0=avebeta(lg,:); %long
0039     alpha0=cat(1,lind(initial).alpha); %long
0040     mu0=avemu(lg,:); %long
0041     disp0=avedisp(lg,:); %long
0042     
0043     beta1=cat(1,lind(final).beta); %long
0044     alpha1=cat(1,lind(final).alpha); %long
0045     mu1=cat(1,lind(final).mu); %long
0046     disp1=cat(2,lind(final).Dispersion)'; %long
0047     
0048     L2=[L L]; %long
0049     avebeta(lg,:)=betadrift(beta0,beta1,alpha0,L2);
0050     avemu(lg,:)=0.5*(mu0+mu1);
0051     avedisp(lg,[1 3])=(disp1(:,[1 3])+disp0(:,[1 3]))*0.5;
0052     
0053     foc=atgetcells(ring(long),'PolynomB',@(el,polb) length(polb)>=2 && polb(2)~=0 && abs(polb(2))==max(abs(polb))) ; %long
0054     if any(foc)
0055         qp=false(size(long));
0056         qp(long)=foc;
0057         K=zeros(size(L)); %long
0058         K(foc)=atgetfieldvalues(ring(qp),'PolynomB',{2});
0059         K2=[K -K]; %long
0060         sel=false(size(avebeta,1)); %refpts
0061         sel(lg)=foc;
0062         avebeta(sel,:)=betafoc(beta1(foc,:),alpha0(foc,:),alpha1(foc,:),K2(foc,:),L2(foc,:));
0063         avedisp(sel,[1 3])=dispfoc(disp0(foc,[2 4]),disp1(foc,[2 4]),K2(foc,:),L2(foc,:));
0064     end
0065     avedisp(lg,[2 4])=(disp1(:,[1 3])-disp0(:,[1 3]))./L2;
0066 end
0067 
0068     function avebeta=betadrift(beta0,beta1,alpha0,L)
0069         gamma0=(alpha0.*alpha0+1)./beta0;
0070         avebeta=0.5*(beta0+beta1)-gamma0.*L.*L/6;
0071     end
0072 
0073     function avebeta=betafoc(beta1,alpha0,alpha1,K,L)
0074         gamma1=(alpha1.*alpha1+1)./beta1;
0075         avebeta=0.5*((gamma1+K.*beta1).*L+alpha1-alpha0)./K./L;
0076     end
0077 
0078     function avedisp=dispfoc(dispp0,dispp1,K,L)
0079         avedisp=(dispp0-dispp1)./K./L;
0080     end
0081 
0082 end

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005