Home > pubtools > atundulator.m

atundulator

PURPOSE ^

define undulator model

SYNOPSIS ^

function undulator=atundulator(LUnd,nperiod,varargin)

DESCRIPTION ^

 define undulator model 
 
 input:
   Lund= undulator length
   nperiod = number of periods
   'BendAngle', value : half pole bending angle in rad
   'B0andEnergy', value (2x1): [half pole B0 field in T, Energy in eV]
                               converts to bending angle in rad.
   'magnetmodel', value : 'multipoles' (default) or 'rectangularbend'
   'PoleGap', value : drift space between gaps defualt (0.0) 

 if neither BendAngle nor B0andEnergy are provided then 'BendAngle' is 0.0 
 
 output: 
    cellarray of elements describing un undulator of length LUnd divided 
    in nperiod periods, each described as follows: 
    [negpole,drift,pospole,pospole,drift,negpole]
    if 'PoleGap' is 0.0 (default), then
    [negpole,pospole,pospole,negpole]

 example: 
 1)  und=atundulator(1.6,61,'B0andEnergy',[0.4 6.04e9])
 2)  und=atundulator(1.6,61,'BendAngle',-0.007984472464733)
 3)  und=atundulator(1.6,61,'B0andEnergy',[0.4 6.04e9],'magnetmodel','rectangularbend')
 4)  und=atundulator(1.6,61,'B0andEnergy',[0.4 6.04e9],'PoleGap',0.001);

see also:

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function undulator=atundulator(LUnd,nperiod,varargin)
0002 % define undulator model
0003 %
0004 % input:
0005 %   Lund= undulator length
0006 %   nperiod = number of periods
0007 %   'BendAngle', value : half pole bending angle in rad
0008 %   'B0andEnergy', value (2x1): [half pole B0 field in T, Energy in eV]
0009 %                               converts to bending angle in rad.
0010 %   'magnetmodel', value : 'multipoles' (default) or 'rectangularbend'
0011 %   'PoleGap', value : drift space between gaps defualt (0.0)
0012 %
0013 % if neither BendAngle nor B0andEnergy are provided then 'BendAngle' is 0.0
0014 %
0015 % output:
0016 %    cellarray of elements describing un undulator of length LUnd divided
0017 %    in nperiod periods, each described as follows:
0018 %    [negpole,drift,pospole,pospole,drift,negpole]
0019 %    if 'PoleGap' is 0.0 (default), then
0020 %    [negpole,pospole,pospole,negpole]
0021 %
0022 % example:
0023 % 1)  und=atundulator(1.6,61,'B0andEnergy',[0.4 6.04e9])
0024 % 2)  und=atundulator(1.6,61,'BendAngle',-0.007984472464733)
0025 % 3)  und=atundulator(1.6,61,'B0andEnergy',[0.4 6.04e9],'magnetmodel','rectangularbend')
0026 % 4)  und=atundulator(1.6,61,'B0andEnergy',[0.4 6.04e9],'PoleGap',0.001);
0027 %
0028 %see also:
0029 
0030 defaultAngPole=NaN;
0031 defaultB0andEnergy=[NaN NaN];
0032 defaultPoleGap=0;
0033 
0034 expectedmagmodels={'multipoles','rectangularbend'};
0035 
0036 p= inputParser;
0037 addRequired(p,'LUnd',@isnumeric);
0038 addRequired(p,'nperiod',@isnumeric);
0039 addParameter(p,'magnetmodel',expectedmagmodels{1},@(x)any(validatestring(x,expectedmagmodels)));
0040 addParameter(p,'BendAngle',defaultAngPole,@isnumeric);
0041 addParameter(p,'B0andEnergy',defaultB0andEnergy,@isnumeric);
0042 addParameter(p,'PoleGap',defaultPoleGap,@isnumeric);
0043 
0044 parse(p,LUnd,nperiod,varargin{:});
0045 magnetmodel=p.Results.magnetmodel;
0046 BendAngle=p.Results.BendAngle;
0047 B0andEnergy=p.Results.B0andEnergy;
0048 PoleGap=p.Results.PoleGap;
0049 
0050 % length of one period
0051 periodL=LUnd/nperiod;
0052 
0053 DistPole=PoleGap;
0054 LPole=(periodL-2*DistPole)/4;
0055 
0056 if ~isnan(B0andEnergy)
0057     B=B0andEnergy(1);%0.6;
0058     Brho=B0andEnergy(2)/299792458;
0059     AngPole=(B*LPole)/Brho;
0060 elseif ~isnan(BendAngle)
0061     AngPole=BendAngle;
0062 else
0063     AngPole=0.0;
0064 end
0065 
0066 switch magnetmodel
0067     
0068     case 'multipoles'
0069        
0070         undperiod=makeundperiod(...
0071             atmultipole('NegPole',LPole,0,-AngPole/LPole),...
0072             atmultipole('PosPole',LPole,0,AngPole/LPole),...
0073             atdrift('PoleGap',DistPole));
0074         
0075     case 'rectangularbend'
0076         
0077         undperiod=makeundperiod(...
0078             atrbend('NegPole',LPole,-AngPole,0,'BndMPoleSymplectic4Pass'),...
0079             atrbend('PosPole',LPole,AngPole,0,'BndMPoleSymplectic4Pass'),...
0080             atdrift('PoleGap',DistPole));
0081         
0082 end
0083 
0084 undulator=repmat(undperiod,nperiod,1);
0085 
0086 end
0087 
0088 
0089 function undper=makeundperiod(halfnegpole,halfpospole,driftpole)
0090 
0091 if driftpole.Length>0
0092     undper={...
0093         halfnegpole;...
0094         driftpole;...
0095         halfpospole;...
0096         halfpospole;...
0097         driftpole;...
0098         halfnegpole;...
0099         };
0100 elseif driftpole.Length==0
0101     undper={...
0102         halfnegpole;...
0103         halfpospole;...
0104         halfpospole;...
0105         halfnegpole;...
0106         };
0107 end
0108 
0109 end
0110

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