0001 function [energy,nbper,voltage,harmnumber,U0]=atenergy(ring)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 global GLOBVAL
0015
0016 params=atgetcells(ring(:,1),'Class','RingParam');
0017 cavities=atgetcells(ring(:,1),'Frequency');
0018 dipoles=atgetcells(ring(:,1),'BendingAngle');
0019 theta=atgetfieldvalues(ring(dipoles),'BendingAngle');
0020 if any(params)
0021 parmelem=ring{find(params,1)};
0022 energy=parmelem.Energy;
0023 if nargout >= 2
0024 nbper=parmelem.Periodicity;
0025 end
0026 else
0027 if any(cavities) && isfield(ring{find(cavities,1)},'Energy')
0028 energy=ring{find(cavities,1)}.Energy;
0029 elseif isfield(GLOBVAL,'E0')
0030 energy=GLOBVAL.E0;
0031 else
0032 error('AT:NoEnergy',...
0033 'Energy not defined (searched in ''RingParam'',''RFCavity'',GLOBVAL.E0)');
0034 end
0035 if nargout >= 2
0036 if size(ring,2) > 1
0037 nbper=size(ring,2);
0038 else
0039 nbp=2*pi/sum(theta);
0040 nbper=round(nbp);
0041 if ~isfinite(nbp)
0042 warning('AT:WrongNumberOfCells','No bending in the cell, ncells set to 1');
0043 nbper=1;
0044 elseif abs(nbp-nbper) > 1.e-4
0045 warning('AT:WrongNumberOfCells','non integer number of cells: ncells = %g -> %g',nbp,nbper);
0046 end
0047 end
0048 end
0049 end
0050
0051 if nargout >= 3
0052 if any(cavities)
0053 voltage=nbper*sum(atgetfieldvalues(ring(cavities),'Voltage'));
0054 harmnumber=nbper*atgetfieldvalues(ring(find(cavities,1)),'HarmNumber');
0055 elseif nargout >= 5
0056 voltage=NaN;
0057 harmnumber=NaN;
0058 else
0059 error('AT:NoCavity','No cavity element in the ring');
0060 end
0061 end
0062 if nargout >= 5
0063
0064 cgamma=4e9*pi*PhysConstant.classical_electron_radius.value/3/...
0065 PhysConstant.electron_mass_energy_equivalent_in_MeV.value^3;
0066 lendp=atgetfieldvalues(ring(dipoles),'Length');
0067 losses=atgetfieldvalues(ring(atgetcells(ring,'I2')),'I2');
0068 I2=nbper*(sum(abs(theta.*theta./lendp))+sum(losses));
0069 U0=cgamma/2/pi*(energy*1.e-9)^4*I2*1e9;
0070 end
0071 end