Home > lattice > ataddmpoleerrors.m

ataddmpoleerrors

PURPOSE ^

ataddrandmpole adds a random multipole component to all elements of type

SYNOPSIS ^

function newring = ataddmpoleerrors(ring,type,newindex,strength,radius,randflag)

DESCRIPTION ^

ataddrandmpole adds a random multipole component to all elements of type
'type' where type can be 'dipole', 'quadrupole', or 'sextupole'

[newring] = ATRANDMPOLE(ring,type,newindex,strength,radius)

ring = input ring
type = 'dipole', 'quadrupole' or 'sextupole'
newindex: index of Multipole to add
strength: strength of the multipole component at the given radius
radius: reference radius for defining the absolute strength
if randflag is set to 1, then the errors will be random, Gaussian
distributed
 The formula for the added errors is
 B^(N)_(n) = radius^(n-N)*b_n/b_N
 It represents the relative field error to the design value at the ref.
 radius
For example, to add a random octupole error of 1e-4 at 25 mm, relative to all
quadrupoles:
 newring =ataddrandmpole(ring,'quadrupole',4,.1e-4,.025,1);

See also: ataddmpolecomppoly attiltelem atshiftelem

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function newring = ataddmpoleerrors(ring,type,newindex,strength,radius,randflag)
0002 %ataddrandmpole adds a random multipole component to all elements of type
0003 %'type' where type can be 'dipole', 'quadrupole', or 'sextupole'
0004 %
0005 %[newring] = ATRANDMPOLE(ring,type,newindex,strength,radius)
0006 %
0007 %ring = input ring
0008 %type = 'dipole', 'quadrupole' or 'sextupole'
0009 %newindex: index of Multipole to add
0010 %strength: strength of the multipole component at the given radius
0011 %radius: reference radius for defining the absolute strength
0012 %if randflag is set to 1, then the errors will be random, Gaussian
0013 %distributed
0014 % The formula for the added errors is
0015 % B^(N)_(n) = radius^(n-N)*b_n/b_N
0016 % It represents the relative field error to the design value at the ref.
0017 % radius
0018 %For example, to add a random octupole error of 1e-4 at 25 mm, relative to all
0019 %quadrupoles:
0020 % newring =ataddrandmpole(ring,'quadrupole',4,.1e-4,.025,1);
0021 %
0022 %See also: ataddmpolecomppoly attiltelem atshiftelem
0023 
0024 % first find all elements of the given type.
0025 % then run through them, and
0026 % create a new element with new polynom, using ataddmpolecomppoly to make the new
0027 % PolyNom with a random strength scaled by strength and
0028 % atelem to make the element.  Now replace the old element with the new.
0029 
0030 if (strcmp(type,'dipole'))
0031     elemindex0=finddipoles(ring);
0032     elemindex=find(elemindex0);
0033     refindex=1;
0034 else
0035     if (strcmp(type,'quadrupole'))
0036     elemindex0=findquadrupoles(ring);
0037     elemindex=find(elemindex0);
0038     refindex=2;
0039     else
0040         elemindex=[];
0041     end
0042 end
0043 
0044 newring=ring;
0045 for j=1:length(elemindex)
0046 elmnt=ring{elemindex(j)};
0047 polyB = elmnt.PolynomB;
0048 
0049 if(randflag)
0050     strength = strength*randn;
0051 end
0052 polyB2 = ataddmpolecomppoly(polyB,refindex,newindex,strength,radius);
0053 elmnt.PolynomB=polyB2;
0054 elmnt.MaxOrder=length(polyB2);
0055 newring{elemindex(j)}=elmnt;
0056 end
0057 
0058 function quads = findquadrupoles(ring)
0059 dipoles = finddipoles(ring);
0060 isquadrupole=@(elem,polyb) length(polyb) >= 2 && polyb(2)~=0;
0061 quads=atgetcells(ring,'PolynomB',isquadrupole) & ~dipoles;
0062 
0063 function dipoles = finddipoles(ring)
0064 isdipole=@(elem,bangle) bangle~=0;
0065 dipoles=atgetcells(ring,'BendingAngle',isdipole);

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