source: MML/trunk/at/atdoc/howto_newpassmethods.txt @ 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: 7.8 KB
Line 
1Low-level element pass functions
2*****************************************************************************
3Each cell in THERING cell array represents a physical element such as
4drift or quadrupole magnet. The i-th element data is organized as
51-by-1 MATLAB 'structure'. This structure has a field
6THERING{i}.PassMethod that contains the actual name of the function to
7be called when propagating through this element with higher level
8routines such as RingPass or LinePass.
9
10For example in spear2 the first element in the ring is a drift 1.3448 m long:
11_________________________________________________________________________
12>> THERING{1}
13ans =
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
19and 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]')
22ans =
23
24   0.00134480000000
25   0.00100000000000
26                  0
27                  0
28                  0
29   0.00000067240000
30_______________________________________________________________________
31
32Accelerator Toolbox provides a number of low-level element pass functions.
33Each function propagates through an element assuming some physical model
34of that element. In the above example 'DriftPass' used the trivial solution
35of Hamiltonian equations in the field-free region.
36It is possible to call DriftPass
37on any other element type and thus treat it like a drift.
38For example a sextupole element structure contains fields
39that distinquish it from a drift such as multipole expansion
40of the field 'PolynomA','PolynomB' and
41misalignment data 'R1','R2','T1','T2'
42________________________________________________________________________
43» THERING{15}
44ans =
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
58Still the Toolbox allows to model it as a drift of the same length:
59________________________________________________________________
60DriftPass(THERING{15},[0.01, 0.001, 0 0 0 0]')
61ans =
62   0.01023335000000
63   0.00100000000000
64                  0
65                  0
66                  0
67   0.00000011667500
68________________________________________________________________
69
70Notice that the second component of the input vector
71(transverse momentum) did not change. That is
72the consequence of modeling a sextupole as a drift.
73
74The preferred pass function is the one with the most
75accurate physics model for this type of element.
76For sextuploe in this example 'StrMPoleSymplectic4Pass' function
77(fourth-order symplectic integrator described [])
78gives more physical answer.
79______________________________________________________________
80StrMPoleSymplectic4Pass (THERING{15},[0.01, 0.001, 0 0 0 0]')
81ans =
82   0.01022871381142
83   0.00095996232730
84                  0
85                  0
86                  0
87   0.00000011210045
88______________________________________________________________
89
90
91The user can choose the appropriate physics model for each element by setting
92the 'PassMethod' field to the name of the element-pass function from the Toolbox.
93The choice of the right  pass function (besides qualitatively correct physics model)
94also depends on other considerations
95
961. Speed - accuracy tradeoff
97
98For example:
99StrMPoleSymplectic4Pass is a fourth-order symplectic integrator
100StrMPoleSymplectic2Pass is second order.
101
1022. Different aspecsts of accelerator physics analyzed
103
104For example:
105To simulate classical radiation a different
106set of element pass functions should be used:
107BendLinearRadPass insted of BendLinearPass
108QuadLinearRadPass insted of QuadLinearPass and
109StrMPoleSymplectic2RadPass insted of StrMPoleSymplectic4Pass
110
111
112WARNING: Element type-function compatibility.
113
114As explained above, the Toolbox framework allows to use
115different pass functions on a particular element type.
116Reverse is also true: the same pass function can propagate
117particles through many different types of elements.
118THERE ARE RESTRICTIONS!!!
119Each element pass function searches the element data structure
120passed to it as an argument for specific fields.
121
122
1231.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
1342.Field name strings MUST MATCH EXACTLY, CASE SENSITIVE!!!
135
1363.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 
142ADD LATER!!!!!!!!!!! CONSISTENCY TABLE
143
144
145
146Making new element pass functions.
147***********************************************************************************
148
149One of the most attractive features of the Toolbox framework is
150the user's ability to add new element-tracking routines
151without touching any existing code.
152The user creates an 'm' or 'mex' function 'NewMethodPass'
153and makes it visible to MATLAB by placing it into a directory on
154the MATLAB search path. Simply setting the 'PassMethod' field of
155an element to 'NewMethodPass' will tell high-level routines (RingPass)
156to use this function.
157
158
159
160
161Functionality
1621.Canonical variables
1632.Input-Output arguments
1643.Vectorization
1654.Argument types and dimensions checks
1665.Internal Protection from floating point overflow
1676.Error/Warning generation
1687.Accompanying .m help file
169
170Naming conventions
1711. ends with "pass"
1722. Self-explanatory names (QuadLinearPass)
173
174
175Details of implementation
176
177Element tracking functions may be implemented in 3 different ways.
178
1791. m-function. Easy to write - excellet for prototyping purposes.
180         
1812. 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
1843. 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
191I.   m-file
192II.  mex-file, command line calling
193III. mex-file, command line and dynamic loading
194
195
196
197All 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
201This ensures that these functions will work at least in
202m-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
209C mex-function 
210
211Dynamic linking / loading compatibility
212
213
214High level pass functions
215**********************************************************************************
216LinePass and RingPass
217
218These high level functions do not call element pass functions directly.
219They do it using mxCallMATLAB function. There is some overhead associated
220with it but the advantages are:
2211. Platform independence
2222. If an element function works from command line - it will work in the
223   RingPass and LinePass
2243. Element pass functions can be prototyped in m-files
225
226
227RingPassWin, RingPassLinux...
228are versions of RingPass optimized for speed on a particular platform.
229
230On Windows RingPassW is faster especially for large number of turns 10+
2311. It eliminates overhead of mxCallMATLAB
2322. It uses the element pass-functions that access the element data fields
233   by number (mxGetFieldByNumber) - which is faster than 'by name' (mxGetField)
234   
Note: See TracBrowser for help on using the repository browser.