Home > lattice > atdivelem.m

atdivelem

PURPOSE ^

LINE=ATDIVELEM(ELEM,FRAC) divide an element into pieces

SYNOPSIS ^

function line = atdivelem(elem,frac)

DESCRIPTION ^

LINE=ATDIVELEM(ELEM,FRAC) divide an element into pieces

ELEM:  Element to be divided
FRAC:  Length of each piece, as a fraction of the total length

LINE:  Cell array 

 The sum of frac elements does not need to be 1, however for bending
 magnets, the length will be divided according to FRAC, but the total
 bending angle will be divided according to FRAC/SUM(FRAC) so that the
 total bending angle is kept.

 Example:

>> qf=atquadrupole('QF',0.1,0.5);
>> line=atdivelem(qf,[0.5;0.5]); % Split a quadrupole in two halves

 See also ATINSERTELEMS ATSLICE ATSPLITELEM

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function line = atdivelem(elem,frac)
0002 %LINE=ATDIVELEM(ELEM,FRAC) divide an element into pieces
0003 %
0004 %ELEM:  Element to be divided
0005 %FRAC:  Length of each piece, as a fraction of the total length
0006 %
0007 %LINE:  Cell array
0008 %
0009 % The sum of frac elements does not need to be 1, however for bending
0010 % magnets, the length will be divided according to FRAC, but the total
0011 % bending angle will be divided according to FRAC/SUM(FRAC) so that the
0012 % total bending angle is kept.
0013 %
0014 % Example:
0015 %
0016 %>> qf=atquadrupole('QF',0.1,0.5);
0017 %>> line=atdivelem(qf,[0.5;0.5]); % Split a quadrupole in two halves
0018 %
0019 % See also ATINSERTELEMS ATSLICE ATSPLITELEM
0020 
0021 line=atsetfieldvalues(repmat({elem},length(frac),1),'Length',elem.Length*frac(:));
0022 if isfield(elem,'T1')
0023     line(2:end)=cellfun(@(elem) rmfield(elem,'T1'),line(2:end),'UniformOutput',false);
0024 end
0025 if isfield(elem,'R1')
0026     line(2:end)=cellfun(@(elem) rmfield(elem,'R1'),line(2:end),'UniformOutput',false);
0027 end
0028 if isfield(elem,'T2')
0029     line(1:end-1)=cellfun(@(elem) rmfield(elem,'T2'),line(1:end-1),'UniformOutput',false);
0030 end
0031 if isfield(elem,'R2')
0032     line(1:end-1)=cellfun(@(elem) rmfield(elem,'R2'),line(1:end-1),'UniformOutput',false);
0033 end
0034 if isfield(elem,'BendingAngle')
0035     line=atsetfieldvalues(line,'BendingAngle',elem.BendingAngle*frac(:)/sum(frac));
0036 end
0037 if isfield(elem,'EntranceAngle')
0038     drentrangle=zeros(size(line));
0039     drentrangle(1)=elem.EntranceAngle;
0040     line=atsetfieldvalues(line,'EntranceAngle',drentrangle);
0041 end
0042 if isfield(elem,'ExitAngle')
0043     drexitangle=zeros(size(line));
0044     drexitangle(end)=elem.ExitAngle;
0045     line=atsetfieldvalues(line,'ExitAngle',drexitangle);
0046 end
0047 if isfield(elem,'FringeInt1')
0048     fringe1=zeros(size(line));
0049     fringe1(1)=elem.FringeInt1;
0050     line=atsetfieldvalues(line,'FringeInt1',fringe1);
0051 end
0052 if isfield(elem,'FringeInt2')
0053     fringe2=zeros(size(line));
0054     fringe2(end)=elem.FringeInt2;
0055     line=atsetfieldvalues(line,'FringeInt2',fringe2);
0056 end
0057 if isfield(elem,'FringeBendEntrance')
0058     fringe1=zeros(size(line));
0059     fringe1(1)=elem.FringeBendEntrance;
0060     line=atsetfieldvalues(line,'FringeBendEntrance',fringe1);
0061 end
0062 if isfield(elem,'FringeBendExit')
0063     fringe2=zeros(size(line));
0064     fringe2(end)=elem.FringeBendExit;
0065     line=atsetfieldvalues(line,'FringeBendExit',fringe2);
0066 end
0067 if isfield(elem,'FringeQuadEntrance')
0068     fringe1=zeros(size(line));
0069     fringe1(1)=elem.FringeQuadEntrance;
0070     line=atsetfieldvalues(line,'FringeQuadEntrance',fringe1);
0071 end
0072 if isfield(elem,'FringeQuadExit')
0073     fringe2=zeros(size(line));
0074     fringe2(end)=elem.FringeQuadExit;
0075     line=atsetfieldvalues(line,'FringeQuadExit',fringe2);
0076 end
0077 
0078 if isfield(elem,'FullGap')
0079     fringe2=zeros(size(line));
0080     fringe2([1,end])=elem.FullGap;
0081     line=atsetfieldvalues(line,'FullGap',fringe2);
0082 end
0083 if isfield(elem,'EdgeEffect1')
0084     fringe2=zeros(size(line));
0085     fringe2(1)=elem.EdgeEffect1;
0086     line=atsetfieldvalues(line,'EdgeEffect1',fringe2);
0087 end
0088 if isfield(elem,'EdgeEffect2')
0089     fringe2=zeros(size(line));
0090     fringe2(end)=elem.EdgeEffect2;
0091     line=atsetfieldvalues(line,'EdgeEffect2',fringe2);
0092 end
0093 
0094 end

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