Home > atphysics > Radiation > atradoff.m

atradoff

PURPOSE ^

ATRADOFF switches radiation and cavity off

SYNOPSIS ^

function [ring2,radelemIndex,cavitiesIndex]=atradoff(ring1,varargin)

DESCRIPTION ^

ATRADOFF  switches radiation and cavity off

   [RING2,RADINDEX,CAVINDEX] = ATRADOFF(RING,CAVIPASS,BENDPASS,QUADPASS)
    Changes passmethods to turn off radiation damping. 

  INPUTS
  1. RING      initial AT structure
  2. CAVIPASS  pass method for cavities (default IdentityPass)
               '' makes no change,
  3. BENDPASS  pass method for bending magnets. Special values:
               '' makes no change,
               'auto' wille substitute 'RadPass' with 'Pass' in any method
               (default: 'auto')
  4. QUADPASS  pass method for quadrupoles
               '' makes no change,
               'auto' wille substitute 'RadPass' with 'Pass' in any method
               (default: '')

   OUPUTS
   1. RING2     Output ring
   2. RADINDEX  Indices of elements with radiation
   3. CAVINDEX  Indices of cavities

  See also ATRADON, ATCAVITYON, ATCAVITYOFF

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ring2,radelemIndex,cavitiesIndex]=atradoff(ring1,varargin)
0002 %ATRADOFF  switches radiation and cavity off
0003 %
0004 %   [RING2,RADINDEX,CAVINDEX] = ATRADOFF(RING,CAVIPASS,BENDPASS,QUADPASS)
0005 %    Changes passmethods to turn off radiation damping.
0006 %
0007 %  INPUTS
0008 %  1. RING      initial AT structure
0009 %  2. CAVIPASS  pass method for cavities (default IdentityPass)
0010 %               '' makes no change,
0011 %  3. BENDPASS  pass method for bending magnets. Special values:
0012 %               '' makes no change,
0013 %               'auto' wille substitute 'RadPass' with 'Pass' in any method
0014 %               (default: 'auto')
0015 %  4. QUADPASS  pass method for quadrupoles
0016 %               '' makes no change,
0017 %               'auto' wille substitute 'RadPass' with 'Pass' in any method
0018 %               (default: '')
0019 %
0020 %   OUPUTS
0021 %   1. RING2     Output ring
0022 %   2. RADINDEX  Indices of elements with radiation
0023 %   3. CAVINDEX  Indices of cavities
0024 %
0025 %  See also ATRADON, ATCAVITYON, ATCAVITYOFF
0026 
0027 [cavipass,bendpass,quadpass]=parseargs({'IdentityPass','auto',''},varargin);
0028 
0029 ring2=ring1;
0030 
0031 if ~isempty(cavipass)
0032     cavitiesIndex=atgetcells(ring2,'Frequency');
0033     if ~any(cavitiesIndex)
0034         warning('AT:atradon:NoCavity', 'No cavity found in the structure');
0035     end
0036     ring2(cavitiesIndex)=changepass(ring2(cavitiesIndex),cavipass);
0037 else
0038     cavitiesIndex=false(size(ring2));
0039 end
0040 
0041 if ~isempty(bendpass)
0042     isdipole=@(elem,bangle) bangle~=0;
0043     dipoles=atgetcells(ring2,'BendingAngle',isdipole);
0044     if sum(dipoles) <= 0
0045         warning('AT:atradon:NoBend', 'No dipole in the structure');
0046     end
0047     ring2(dipoles)=changepass(ring2(dipoles),bendpass);
0048 else
0049     dipoles=false(size(ring2));
0050 end
0051 
0052 if ~isempty(quadpass)
0053     isquadrupole=@(elem,polyb) length(polyb) >= 2 && polyb(2)~=0;
0054     quadrupoles=atgetcells(ring2,'PolynomB',isquadrupole) & ~dipoles;
0055     if sum(quadrupoles) <= 0
0056         warning('AT:atradon:NoQuad', 'No quadrupole in the structure');
0057     end
0058     ring2(quadrupoles)=changepass(ring2(quadrupoles),quadpass);
0059 else
0060     quadrupoles=false(size(ring2));
0061 end
0062 
0063 radelemIndex=dipoles|quadrupoles;
0064 
0065 disp(['Cavities located at position ' num2str(find(cavitiesIndex)')]);
0066 disp([num2str(sum(radelemIndex)) ' elements with radiation switched off']);
0067 
0068     function newline=changepass(line,newpass)
0069     if strcmp(newpass,'auto')
0070         passlist=strrep(atgetfieldvalues(line,'PassMethod'),'RadPass','Pass');
0071     else
0072         passlist=repmat({newpass},size(line));
0073     end
0074     newline=cellfun(@newelem,line,passlist,'UniformOutput',false);
0075 
0076         function elem=newelem(elem,newpass)
0077             elem.PassMethod=newpass;
0078             %elem=rmfield(elem,'Energy');
0079         end
0080     end
0081 
0082 end

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