Home > atphysics > Radiation > atenergy.m

atenergy

PURPOSE ^

ENERGY=ATENERGY(RING) Gets the RING energy

SYNOPSIS ^

function [energy,nbper,voltage,harmnumber,U0]=atenergy(ring)

DESCRIPTION ^

ENERGY=ATENERGY(RING) Gets the RING energy
   ATENERGY looks for the machine energy in:
       1) the 1st 'RingParam' element
       2) the 1st 'RFCavity' element
       3) the field "E0" of the global variable "GLOBVAL"

[ENERGY,PERIODS]=ATENERGY(RING) also outputs the number of periods

[ENERGY,PERIODS,VOLTAGE,HARMNUMBER]=ATENERGY(RING) also outputs the harmonic number

[ENERGY,PERIODS,VOLTAGE,HARMNUMBER,U0]=ATENERGY(RING) also outputs total losses in eV

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [energy,nbper,voltage,harmnumber,U0]=atenergy(ring)
0002 %ENERGY=ATENERGY(RING) Gets the RING energy
0003 %   ATENERGY looks for the machine energy in:
0004 %       1) the 1st 'RingParam' element
0005 %       2) the 1st 'RFCavity' element
0006 %       3) the field "E0" of the global variable "GLOBVAL"
0007 %
0008 %[ENERGY,PERIODS]=ATENERGY(RING) also outputs the number of periods
0009 %
0010 %[ENERGY,PERIODS,VOLTAGE,HARMNUMBER]=ATENERGY(RING) also outputs the harmonic number
0011 %
0012 %[ENERGY,PERIODS,VOLTAGE,HARMNUMBER,U0]=ATENERGY(RING) also outputs total losses in eV
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     % Losses = Cgamma/2/pi*EGeV^4*I2
0064     cgamma=4e9*pi*PhysConstant.classical_electron_radius.value/3/...
0065         PhysConstant.electron_mass_energy_equivalent_in_MeV.value^3; % [m/GeV^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));            % [m-1]
0069     U0=cgamma/2/pi*(energy*1.e-9)^4*I2*1e9;                          % [eV]
0070 end
0071 end

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