1 | Low-level element pass functions |
---|
2 | ***************************************************************************** |
---|
3 | Each cell in THERING cell array represents a physical element such as |
---|
4 | drift or quadrupole magnet. The i-th element data is organized as |
---|
5 | 1-by-1 MATLAB 'structure'. This structure has a field |
---|
6 | THERING{i}.PassMethod that contains the actual name of the function to |
---|
7 | be called when propagating through this element with higher level |
---|
8 | routines such as RingPass or LinePass. |
---|
9 | |
---|
10 | For example in spear2 the first element in the ring is a drift 1.3448 m long: |
---|
11 | _________________________________________________________________________ |
---|
12 | >> THERING{1} |
---|
13 | ans = |
---|
14 | FamName: 'DR01' |
---|
15 | Length: 1.34480000000000 |
---|
16 | PassMethod: 'DriftPass' |
---|
17 | _________________________________________________________________________ |
---|
18 | 'DriftPass' is the name of the actual function on the MATLAB search path |
---|
19 | and it can be called from the command line or used in an m-script: |
---|
20 | _______________________________________________________________________ |
---|
21 | >>DriftPass(THERING{2}, [0 0.001 0 0 0 0]') |
---|
22 | ans = |
---|
23 | |
---|
24 | 0.00134480000000 |
---|
25 | 0.00100000000000 |
---|
26 | 0 |
---|
27 | 0 |
---|
28 | 0 |
---|
29 | 0.00000067240000 |
---|
30 | _______________________________________________________________________ |
---|
31 | |
---|
32 | Accelerator Toolbox provides a number of low-level element pass functions. |
---|
33 | Each function propagates through an element assuming some physical model |
---|
34 | of that element. In the above example 'DriftPass' used the trivial solution |
---|
35 | of Hamiltonian equations in the field-free region. |
---|
36 | It is possible to call DriftPass |
---|
37 | on any other element type and thus treat it like a drift. |
---|
38 | For example a sextupole element structure contains fields |
---|
39 | that distinquish it from a drift such as multipole expansion |
---|
40 | of the field 'PolynomA','PolynomB' and |
---|
41 | misalignment data 'R1','R2','T1','T2' |
---|
42 | ________________________________________________________________________ |
---|
43 | » THERING{15} |
---|
44 | ans = |
---|
45 | FamName: 'SF' |
---|
46 | Length: 0.23335000000000 |
---|
47 | MaxOrder: 3 |
---|
48 | NumIntSteps: 10 |
---|
49 | R1: [6x6 double] |
---|
50 | R2: [6x6 double] |
---|
51 | T1: [0 0 0 0 0 0] |
---|
52 | T2: [0 0 0 0 0 0] |
---|
53 | PolynomA: [0 0 0] |
---|
54 | PolynomB: [0 0 1.67686888860000] |
---|
55 | PassMethod: 'StrSymplectic4Pass' |
---|
56 | ________________________________________________________________________ |
---|
57 | |
---|
58 | Still the Toolbox allows to model it as a drift of the same length: |
---|
59 | ________________________________________________________________ |
---|
60 | DriftPass(THERING{15},[0.01, 0.001, 0 0 0 0]') |
---|
61 | ans = |
---|
62 | 0.01023335000000 |
---|
63 | 0.00100000000000 |
---|
64 | 0 |
---|
65 | 0 |
---|
66 | 0 |
---|
67 | 0.00000011667500 |
---|
68 | ________________________________________________________________ |
---|
69 | |
---|
70 | Notice that the second component of the input vector |
---|
71 | (transverse momentum) did not change. That is |
---|
72 | the consequence of modeling a sextupole as a drift. |
---|
73 | |
---|
74 | The preferred pass function is the one with the most |
---|
75 | accurate physics model for this type of element. |
---|
76 | For sextuploe in this example 'StrMPoleSymplectic4Pass' function |
---|
77 | (fourth-order symplectic integrator described []) |
---|
78 | gives more physical answer. |
---|
79 | ______________________________________________________________ |
---|
80 | StrMPoleSymplectic4Pass (THERING{15},[0.01, 0.001, 0 0 0 0]') |
---|
81 | ans = |
---|
82 | 0.01022871381142 |
---|
83 | 0.00095996232730 |
---|
84 | 0 |
---|
85 | 0 |
---|
86 | 0 |
---|
87 | 0.00000011210045 |
---|
88 | ______________________________________________________________ |
---|
89 | |
---|
90 | |
---|
91 | The user can choose the appropriate physics model for each element by setting |
---|
92 | the 'PassMethod' field to the name of the element-pass function from the Toolbox. |
---|
93 | The choice of the right pass function (besides qualitatively correct physics model) |
---|
94 | also depends on other considerations |
---|
95 | |
---|
96 | 1. Speed - accuracy tradeoff |
---|
97 | |
---|
98 | For example: |
---|
99 | StrMPoleSymplectic4Pass is a fourth-order symplectic integrator |
---|
100 | StrMPoleSymplectic2Pass is second order. |
---|
101 | |
---|
102 | 2. Different aspecsts of accelerator physics analyzed |
---|
103 | |
---|
104 | For example: |
---|
105 | To simulate classical radiation a different |
---|
106 | set of element pass functions should be used: |
---|
107 | BendLinearRadPass insted of BendLinearPass |
---|
108 | QuadLinearRadPass insted of QuadLinearPass and |
---|
109 | StrMPoleSymplectic2RadPass insted of StrMPoleSymplectic4Pass |
---|
110 | |
---|
111 | |
---|
112 | WARNING: Element type-function compatibility. |
---|
113 | |
---|
114 | As explained above, the Toolbox framework allows to use |
---|
115 | different pass functions on a particular element type. |
---|
116 | Reverse is also true: the same pass function can propagate |
---|
117 | particles through many different types of elements. |
---|
118 | THERE ARE RESTRICTIONS!!! |
---|
119 | Each element pass function searches the element data structure |
---|
120 | passed to it as an argument for specific fields. |
---|
121 | |
---|
122 | |
---|
123 | 1.Element data structure MUST have ALL the fields used by the pass function |
---|
124 | For example: |
---|
125 | if 'QuadLinearPass' is used on a drift elemet structure with fields |
---|
126 | |
---|
127 | FamName: 'DR01' |
---|
128 | Length: 1.34480000000000 |
---|
129 | PassMethod: 'DriftPass' |
---|
130 | |
---|
131 | it will not find the field 'K' needed to |
---|
132 | calculate the quadrupole matrix in the linear model. |
---|
133 | |
---|
134 | 2.Field name strings MUST MATCH EXACTLY, CASE SENSITIVE!!! |
---|
135 | |
---|
136 | 3.There MUST be a consistency of field names between different element types |
---|
137 | if they are to use the same pass function. |
---|
138 | For example: |
---|
139 | what makes DriftPass in our examples so universal is that ALL element types store |
---|
140 | the physical length in the field named 'Length' , NOT 'length' or 'L' |
---|
141 | |
---|
142 | ADD LATER!!!!!!!!!!! CONSISTENCY TABLE |
---|
143 | |
---|
144 | |
---|
145 | |
---|
146 | Making new element pass functions. |
---|
147 | *********************************************************************************** |
---|
148 | |
---|
149 | One of the most attractive features of the Toolbox framework is |
---|
150 | the user's ability to add new element-tracking routines |
---|
151 | without touching any existing code. |
---|
152 | The user creates an 'm' or 'mex' function 'NewMethodPass' |
---|
153 | and makes it visible to MATLAB by placing it into a directory on |
---|
154 | the MATLAB search path. Simply setting the 'PassMethod' field of |
---|
155 | an element to 'NewMethodPass' will tell high-level routines (RingPass) |
---|
156 | to use this function. |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | |
---|
161 | Functionality |
---|
162 | 1.Canonical variables |
---|
163 | 2.Input-Output arguments |
---|
164 | 3.Vectorization |
---|
165 | 4.Argument types and dimensions checks |
---|
166 | 5.Internal Protection from floating point overflow |
---|
167 | 6.Error/Warning generation |
---|
168 | 7.Accompanying .m help file |
---|
169 | |
---|
170 | Naming conventions |
---|
171 | 1. ends with "pass" |
---|
172 | 2. Self-explanatory names (QuadLinearPass) |
---|
173 | |
---|
174 | |
---|
175 | Details of implementation |
---|
176 | |
---|
177 | Element tracking functions may be implemented in 3 different ways. |
---|
178 | |
---|
179 | 1. m-function. Easy to write - excellet for prototyping purposes. |
---|
180 | |
---|
181 | 2. Compiled C or FORTRAN mex-file only with command-line comapatiblility. |
---|
182 | The internal tracking function is only visible to mexFunction in that file |
---|
183 | |
---|
184 | 3. Compiled C or FORTRAN mex-file that in addition to mexFunction |
---|
185 | also exports its internal tracking function for use in other |
---|
186 | mex-files |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | I. m-file |
---|
192 | II. mex-file, command line calling |
---|
193 | III. mex-file, command line and dynamic loading |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | All element tracking functions must support the command line callinng syntax |
---|
198 | |
---|
199 | x_out = quadinpass(THERING{10},[0.001 0 0 0 0 0]'); |
---|
200 | |
---|
201 | This ensures that these functions will work at least in |
---|
202 | m-scripts that use 'feval' in the 'for' loop: |
---|
203 | |
---|
204 | X0 = [0.001 0 -0.001 0 0 0]'; |
---|
205 | for k=1:length(THERING) |
---|
206 | X0 = feval(RING{k}.PassMethod,RING{k-1},X0); |
---|
207 | end |
---|
208 | |
---|
209 | C mex-function |
---|
210 | |
---|
211 | Dynamic linking / loading compatibility |
---|
212 | |
---|
213 | |
---|
214 | High level pass functions |
---|
215 | ********************************************************************************** |
---|
216 | LinePass and RingPass |
---|
217 | |
---|
218 | These high level functions do not call element pass functions directly. |
---|
219 | They do it using mxCallMATLAB function. There is some overhead associated |
---|
220 | with it but the advantages are: |
---|
221 | 1. Platform independence |
---|
222 | 2. If an element function works from command line - it will work in the |
---|
223 | RingPass and LinePass |
---|
224 | 3. Element pass functions can be prototyped in m-files |
---|
225 | |
---|
226 | |
---|
227 | RingPassWin, RingPassLinux... |
---|
228 | are versions of RingPass optimized for speed on a particular platform. |
---|
229 | |
---|
230 | On Windows RingPassW is faster especially for large number of turns 10+ |
---|
231 | 1. It eliminates overhead of mxCallMATLAB |
---|
232 | 2. It uses the element pass-functions that access the element data fields |
---|
233 | by number (mxGetFieldByNumber) - which is faster than 'by name' (mxGetField) |
---|
234 | |
---|