Home > lattice > element_creation > atwiggler.m

atwiggler

PURPOSE ^

atwiggler(fname, Ltot, Lw, Bmax, Nstep, Nmeth, By, Bx, method)

SYNOPSIS ^

function Elem = atwiggler(fname, Ltot, Lw, Bmax, Nstep, Nmeth, By, Bx, method)

DESCRIPTION ^

 atwiggler(fname, Ltot, Lw, Bmax, Nstep, Nmeth, By, Bx, method)

 FamName    family name
 Ltot        total length of the wiggle
 Lw        total length of the wiggle
 Bmax         peak wiggler field [Tesla]
 Nstep        num of integration steps per period
 Nmeth        symplectic integration method, 2nd or 4th order: 2 or 4
 By        wiggler harmonics for horizontal wigglers
 Bx        wiggler harmonics for vertical wigglers
 method        name of the function to use for tracking

 returns a wiggler structure with class 'Wiggler'

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function Elem = atwiggler(fname, Ltot, Lw, Bmax, Nstep, Nmeth, By, Bx, method)
0002 % atwiggler(fname, Ltot, Lw, Bmax, Nstep, Nmeth, By, Bx, method)
0003 %
0004 % FamName    family name
0005 % Ltot        total length of the wiggle
0006 % Lw        total length of the wiggle
0007 % Bmax         peak wiggler field [Tesla]
0008 % Nstep        num of integration steps per period
0009 % Nmeth        symplectic integration method, 2nd or 4th order: 2 or 4
0010 % By        wiggler harmonics for horizontal wigglers
0011 % Bx        wiggler harmonics for vertical wigglers
0012 % method        name of the function to use for tracking
0013 %
0014 % returns a wiggler structure with class 'Wiggler'
0015 
0016 %---------------------------------------------------------------------------
0017 % Modification Log:
0018 % -----------------
0019 % .03  2003-06-19    YK Wu, Duke University, wu@fel.duke.edu
0020 %                               Add checks for input arguments
0021 % .02  2003-06-18    YK Wu, Duke University
0022 %                Add checks for inputs, add comments
0023 %
0024 % .01  2003-04-20    YK Wu, J. Li, Duke University
0025 %                Define a wiggler element
0026 %
0027 %---------------------------------------------------------------------------
0028 %  Accelerator Physics Group, Duke FEL Lab, www.fel.duke.edu
0029 %
0030 
0031 global MaxOrder;
0032 global NumIntSteps;
0033 
0034 GWIG_EPS = 1e-6;
0035 dNw = abs(mod(Ltot/Lw, 1));
0036 if dNw > GWIG_EPS
0037   error(' Wiggler: Ltot/Lw is not an integter.');
0038 end
0039 
0040 Elem.FamName        = fname;  % add check for identical family names
0041 Elem.Length        = Ltot;
0042 Elem.Lw             = Lw;
0043 Elem.Bmax           = Bmax;
0044 Elem.Nstep        = Nstep;
0045 Elem.Nmeth          = Nmeth;
0046 if ~isempty(By)
0047   Elem.NHharm       = length(By(1,:));
0048   for i=1:Elem.NHharm
0049     kx = By(3,i); ky = By(4,i); kz = By(5,i);
0050     dk = sqrt(abs(ky*ky - kz*kz - kx*kx))/abs(kz);
0051     if ( dk > GWIG_EPS ) then
0052       error([' Wiggler (H): kx^2 + kz^2 - ky^2 != 0!, i = ', num2str(i,3)]);
0053     end;
0054   end
0055 else
0056   Elem.NHharm         = 0;
0057 end
0058 
0059 if ~isempty(Bx)
0060   Elem.NVharm         = length(Bx(1,:));
0061   for i=1:Elem.NVharm
0062     kx = Bx(3,i); ky = Bx(4,i); kz = Bx(5,i);
0063     dk = sqrt(abs(kx*kx - kz*kz - ky*ky))/abs(kz);
0064     if ( dk > GWIG_EPS ) then
0065       error([' Wiggler (V): ky^2 + kz^2 - kx^2 != 0!, i = ', num2str(i,3)]);
0066     end;
0067   end
0068 else
0069   Elem.NVharm         = 0;
0070 end
0071 Elem.By             = By;
0072 Elem.Bx             = Bx;
0073 Elem.R1             = diag(ones(6,1));
0074 Elem.R2             = diag(ones(6,1));
0075 Elem.T1             = zeros(1,6);
0076 Elem.T2             = zeros(1,6);
0077 Elem.PassMethod     = method;
0078 Elem.Class          = 'Wiggler';

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