1 | function [z] = wiggler(fname, Ltot, Lw, Bmax, Nstep, Nmeth, By, Bx, method) |
---|
2 | % wiggler(fname, Ltot, Lw, Bmax, Nstep, Nmeth, By, Bx, method) |
---|
3 | % |
---|
4 | % FamName family name |
---|
5 | % Ltot total length of the wiggle |
---|
6 | % Lw total length of the wiggle |
---|
7 | % Bmax peak wiggler field [Tesla] |
---|
8 | % Nstep num of integration steps per period |
---|
9 | % Nmeth symplectic integration method, 2nd or 4th order: 2 or 4 |
---|
10 | % By wiggler harmonics for horizontal wigglers |
---|
11 | % Bx wiggler harmonics for vertical wigglers |
---|
12 | % method name of the function to use for tracking |
---|
13 | % |
---|
14 | % returns assigned address in the FAMLIST that is uniquely identifies |
---|
15 | % the family |
---|
16 | |
---|
17 | %--------------------------------------------------------------------------- |
---|
18 | % Modification Log: |
---|
19 | % ----------------- |
---|
20 | % .03 2003-06-19 YK Wu, Duke University, wu@fel.duke.edu |
---|
21 | % Add checks for input arguments |
---|
22 | % .02 2003-06-18 YK Wu, Duke University |
---|
23 | % Add checks for inputs, add comments |
---|
24 | % |
---|
25 | % .01 2003-04-20 YK Wu, J. Li, Duke University |
---|
26 | % Define a wiggler element |
---|
27 | % |
---|
28 | %--------------------------------------------------------------------------- |
---|
29 | % Accelerator Physics Group, Duke FEL Lab, www.fel.duke.edu |
---|
30 | % |
---|
31 | |
---|
32 | global MaxOrder; |
---|
33 | global NumIntSteps; |
---|
34 | |
---|
35 | GWIG_EPS = 1e-6; |
---|
36 | dNw = abs(mod(Ltot/Lw, 1)); |
---|
37 | if dNw > GWIG_EPS |
---|
38 | error(' Wiggler: Ltot/Lw is not an integter.'); |
---|
39 | end |
---|
40 | |
---|
41 | ElemData.FamName = fname; % add check for identical family names |
---|
42 | ElemData.Length = Ltot; |
---|
43 | ElemData.Lw = Lw; |
---|
44 | ElemData.Bmax = Bmax; |
---|
45 | ElemData.Nstep = Nstep; |
---|
46 | ElemData.Nmeth = Nmeth; |
---|
47 | if ~isempty(By) |
---|
48 | ElemData.NHharm = length(By(1,:)); |
---|
49 | for i=1:ElemData.NHharm |
---|
50 | kx = By(3,i); ky = By(4,i); kz = By(5,i); |
---|
51 | dk = sqrt(abs(ky*ky - kz*kz - kx*kx))/abs(kz); |
---|
52 | if ( dk > GWIG_EPS ) then |
---|
53 | error([' Wiggler (H): kx^2 + kz^2 - ky^2 != 0!, i = ', num2str(i,3)]); |
---|
54 | end; |
---|
55 | end |
---|
56 | else |
---|
57 | ElemData.NHharm = 0; |
---|
58 | end |
---|
59 | |
---|
60 | if ~isempty(Bx) |
---|
61 | ElemData.NVharm = length(Bx(1,:)); |
---|
62 | for i=1:ElemData.NVharm |
---|
63 | kx = Bx(3,i); ky = Bx(4,i); kz = Bx(5,i); |
---|
64 | dk = sqrt(abs(kx*kx - kz*kz - ky*ky))/abs(kz); |
---|
65 | if ( dk > GWIG_EPS ) then |
---|
66 | error([' Wiggler (V): ky^2 + kz^2 - kx^2 != 0!, i = ', num2str(i,3)]); |
---|
67 | end; |
---|
68 | end |
---|
69 | else |
---|
70 | ElemData.NVharm = 0; |
---|
71 | end |
---|
72 | ElemData.By = By; |
---|
73 | ElemData.Bx = Bx; |
---|
74 | ElemData.R1 = diag(ones(6,1)); |
---|
75 | ElemData.R2 = diag(ones(6,1)); |
---|
76 | ElemData.T1 = zeros(1,6); |
---|
77 | ElemData.T2 = zeros(1,6); |
---|
78 | ElemData.PassMethod = method; |
---|
79 | |
---|
80 | |
---|
81 | global FAMLIST |
---|
82 | z = length(FAMLIST)+1; % number of declare families including this one |
---|
83 | FAMLIST{z}.FamName = fname; |
---|
84 | FAMLIST{z}.NumKids = 0; |
---|
85 | FAMLIST{z}.KidsList= []; |
---|
86 | FAMLIST{z}.ElemData= ElemData; |
---|