0001 function [B, M, r] = findelemraddiffm(ELEM,rin, varargin);
0002
0003
0004 MaxOrder = 2;
0005
0006 B = zeros(6);
0007 M = eye(6);
0008 r = rin;
0009
0010 switch ELEM.PassMethod
0011 case {'BndMPoleSymplectic4Pass', 'BndMPoleSymplectic4RadPass'}
0012 invrho = ELEM.BendingAngle/ELEM.Length;
0013 if isfield(ELEM,'T1')
0014 r = r + ELEM.T1';
0015 end
0016 if isfield(ELEM,'R1')
0017 r = ELEM.R1*r;
0018 B = ELEM.R1*B*ELEM.R1';
0019 M = ELEM.R1*M;
0020 end
0021
0022
0023 E = eye(6);
0024 E(2,1) = invrho*tan(ELEM.EntranceAngle);
0025 if isfield(ELEM,'FullGap') & isfield(ELEM,'FringeInt1')
0026 E(4,3) = -invrho*tan(ELEM.EntranceAngle...
0027 -ELEM.FullGap*ELEM.FringeInt1...
0028 *(1+sin(ELEM.EntranceAngle)^2)/cos(ELEM.EntranceAngle)...
0029 /(1+r(5)));
0030 else
0031 E(4,3) = -invrho*tan(ELEM.EntranceAngle);
0032 end
0033
0034 r = E*r;
0035 M = E*M;
0036 B = E*B*E';
0037
0038
0039 [Bbody, Mbody, r] = findthickmpoleraddiffm(r,...
0040 ELEM.PolynomA, ELEM.PolynomB, ELEM.Length, invrho, ...
0041 ELEM.Energy, MaxOrder,ELEM.NumIntSteps);
0042
0043
0044 B = Mbody*B*Mbody'+Bbody;
0045 M = Mbody*M;
0046
0047
0048 E = eye(6);
0049 E(2,1) = invrho*tan(ELEM.ExitAngle);
0050 if isfield(ELEM,'FullGap') & isfield(ELEM,'FringeInt2')
0051 E(4,3) = -invrho*tan(ELEM.ExitAngle...
0052 -ELEM.FullGap*ELEM.FringeInt1...
0053 *(1+sin(ELEM.ExitAngle)^2)/cos(ELEM.ExitAngle)...
0054 /(1+r(5)));
0055 else
0056 E(4,3) = -invrho*tan(ELEM.ExitAngle);
0057 end
0058
0059 r = E*r;
0060 M = E*M;
0061 B = E*B*E';
0062
0063
0064 if isfield(ELEM,'R2')
0065 r = ELEM.R2*r;
0066 B = ELEM.R2*B*ELEM.R2';
0067 M = ELEM.R2*M;
0068 end
0069
0070 if isfield(ELEM,'T2')
0071 r = r + ELEM.T2';
0072 end
0073
0074 case {'StrMPoleSymplectic4Pass', 'StrMPoleSymplectic4RadPass'}
0075
0076 if isfield(ELEM,'T1')
0077 r = r + ELEM.T1;
0078 end
0079 if isfield(ELEM,'R1')
0080 r = ELEM.R1*r;
0081 B = ELEM.R1*B*ELEM.R1';
0082 M = ELEM.R1*M;
0083 end
0084
0085
0086 [Bbody, Mbody, r] = findthickmpoleraddifm(r,...
0087 ELEM.PolynomA, ELEM.PolynomB, ELEM.Length, invrho, ...
0088 ELEM.Energy, MaxOrder,ELEM.NumIntSteps);
0089
0090
0091 B = Mbody*B*Mbody'+Bbody;
0092 M = Mbody*M;
0093
0094
0095 if isfield(ELEM,'R2')
0096 r = ELEM.R2*r;
0097 B = ELEM.R2*B*ELEM.R2';
0098 M = ELEM.R2*M;
0099 end
0100
0101 if isfield(ELEM,'T2')
0102 r = r + ELEM.T2;
0103 end
0104
0105 case 'BendLinearPass'
0106
0107
0108 elem = ELEM;
0109 elem.PassMethod = 'BndMPoleSymplectic4Pass';
0110 elem.PolynomB = [0 0 0];
0111 elem.PolynomB = [0 elem.K 0];
0112 elem.NumIntSteps = 10;
0113 elem.MaxOrder = 2;
0114 [B, M, r] = findelemraddiffm(elem,rin);
0115
0116 case 'IdentityPass'
0117
0118
0119 otherwise
0120 M = findelemm66(ELEM,ELEM.PassMethod,rin);
0121 r = feval(ELEM.PassMethod,ELEM,rin);
0122 B = M*B*M';
0123
0124 end