source: MML/trunk/at/simulator/element/user/wiggler.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 11 years ago

Initial import--MML version from SOLEIL@2013

File size: 2.6 KB
Line 
1function [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
32global MaxOrder;
33global NumIntSteps;
34
35GWIG_EPS = 1e-6;
36dNw = abs(mod(Ltot/Lw, 1));
37if dNw > GWIG_EPS
38  error(' Wiggler: Ltot/Lw is not an integter.');
39end
40
41ElemData.FamName        = fname;  % add check for identical family names
42ElemData.Length         = Ltot;
43ElemData.Lw             = Lw;
44ElemData.Bmax           = Bmax;
45ElemData.Nstep          = Nstep;
46ElemData.Nmeth          = Nmeth;
47if ~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
56else
57  ElemData.NHharm         = 0;
58end
59
60if ~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
69else
70  ElemData.NVharm         = 0;
71end
72ElemData.By             = By;
73ElemData.Bx             = Bx;
74ElemData.R1             = diag(ones(6,1));
75ElemData.R2             = diag(ones(6,1));
76ElemData.T1             = zeros(1,6);
77ElemData.T2             = zeros(1,6);
78ElemData.PassMethod     = method;
79
80
81global FAMLIST
82z = length(FAMLIST)+1; % number of declare families including this one
83FAMLIST{z}.FamName = fname;
84FAMLIST{z}.NumKids = 0;
85FAMLIST{z}.KidsList= [];
86FAMLIST{z}.ElemData= ElemData;
Note: See TracBrowser for help on using the repository browser.