Home > atphysics > atavedata.m

atavedata

PURPOSE ^

ATAVEDATA Average of optical functions on selected elements

SYNOPSIS ^

function [lindata,avebeta,avemu,avedisp,nu,xsi]=atavedata(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

[LINDATA,AVEBETA,AVEMU,AVEDISP,TUNES,CHROMS]=ATAVEDATA(RING,DPP,REFPTS,ORBITIN)
    does not search for closed orbit. instead ORBITIN is used

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [lindata,avebeta,avemu,avedisp,nu,xsi]=atavedata(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 %[LINDATA,AVEBETA,AVEMU,AVEDISP,TUNES,CHROMS]=ATAVEDATA(RING,DPP,REFPTS,ORBITIN)
0014 %    does not search for closed orbit. instead ORBITIN is used
0015 
0016 lr=length(ring)+1;
0017 if islogical(refpts)
0018     refs=[refpts(:);false(lr-length(refpts),1)];
0019 else
0020     refs=false(lr,1); % lr
0021     refs(refpts)=true;
0022 end
0023 long=atgetcells(ring,'Length',@(elem,lg) lg>0) & refs(1:end-1); %lr-1
0024 needed=refs | [false;long]; %lr
0025 [lind,nu,xsi]=atlinopt(ring,dpp,find(needed),varargin{:}); %needed
0026 
0027 lindata=lind(refs(needed)); %refpts
0028 avebeta=cat(1,lindata.beta); %refpts
0029 avemu=cat(1,lindata.mu); %refpts
0030 avedisp=cat(2,lindata.Dispersion)'; %refpts
0031 
0032 if any(long)
0033     initial=[long(needed(1:end-1));false]; %needed
0034     final=[false;initial(1:end-1)]; %needed
0035 
0036     lg=initial(refs(needed)); % refpts
0037     L=atgetfieldvalues(ring(long),'Length'); %long
0038     
0039     beta0=avebeta(lg,:); %long
0040     alpha0=cat(1,lind(initial).alpha); %long
0041     mu0=avemu(lg,:); %long
0042     disp0=avedisp(lg,:); %long
0043     
0044     beta1=cat(1,lind(final).beta); %long
0045     alpha1=cat(1,lind(final).alpha); %long
0046     mu1=cat(1,lind(final).mu); %long
0047     disp1=cat(2,lind(final).Dispersion)'; %long
0048     
0049     L2=[L L]; %long
0050     avebeta(lg,:)=betadrift(beta0,beta1,alpha0,L2);
0051     avemu(lg,:)=0.5*(mu0+mu1);
0052     avedisp(lg,[1 3])=(disp1(:,[1 3])+disp0(:,[1 3]))*0.5;
0053     
0054     foc=atgetcells(ring(long),'PolynomB',@(el,polb) length(polb)>=2 && polb(2)~=0); %long
0055     if any(foc)
0056         qp=false(size(long));
0057         qp(long)=foc;
0058         K=zeros(size(L)); %long
0059         K(foc)=atgetfieldvalues(ring(qp),'PolynomB',{2});
0060         K2=[K -K]; %long
0061         sel=false(size(avebeta,1)); %refpts
0062         sel(lg)=foc;
0063         avebeta(sel,:)=betafoc(beta1(foc,:),alpha0(foc,:),alpha1(foc,:),K2(foc,:),L2(foc,:));
0064         avedisp(sel,[1 3])=dispfoc(disp0(foc,[2 4]),disp1(foc,[2 4]),K2(foc,:),L2(foc,:));
0065     end
0066     avedisp(lg,[2 4])=(disp1(:,[1 3])-disp0(:,[1 3]))./L2;
0067 end
0068 
0069     function avebeta=betadrift(beta0,beta1,alpha0,L)
0070         gamma0=(alpha0.*alpha0+1)./beta0;
0071         avebeta=0.5*(beta0+beta1)-gamma0.*L.*L/6;
0072     end
0073 
0074     function avebeta=betafoc(beta1,alpha0,alpha1,K,L)
0075         gamma1=(alpha1.*alpha1+1)./beta1;
0076         avebeta=0.5*((gamma1+K.*beta1).*L+alpha1-alpha0)./K./L;
0077     end
0078 
0079     function avedisp=dispfoc(dispp0,dispp1,K,L)
0080         avedisp=(dispp0-dispp1)./K./L;
0081     end
0082 
0083 end

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