LATTICEDEMO self-running tutorial
Create elements
An element in Accelerator Toolbox is a 1-by-1 MATLAB STRUCTURE.
Functions are provided to easily create such structures with adequate fields.
The following code creates a structure D1 for a drift space and a structure QF for a quadrupole.
D1 = atdrift('DR01', 3.0);
QF = atquadrupole('QF', 1.0, 0.2);
Use whos, disp or just type variable's name without closing semicolon to print the element's info:
whos D1 QF
Name Size Bytes Class Attributes
D1 1x1 716 struct
QF 1x1 1646 struct
disp(D1);
FamName: 'DR01'
PassMethod: 'DriftPass'
Length: 3
Class: 'Drift'
QF
QF =
FamName: 'QF'
PassMethod: 'StrMPoleSymplectic4Pass'
Length: 1
Class: 'Quadrupole'
K: 0.2000
PolynomB: [0 0.2000]
PolynomA: [0 0]
MaxOrder: 1
NumIntSteps: 10
The next few lines will create another drift structure D2 from the exiting D1 and modify the values of fields 'FamName' and 'Length'
Create another quadrupole element structure QD from QF and modify the values of fields 'K' and 'PolynomB' to make it defocusing
The field 'PolynomB' is a vector of coefficients of the polynomial field expansion.
The second element (quadrupole coefficient) must be consistent with field 'K'
disp(QD);
FamName: 'QD'
PassMethod: 'StrMPoleSymplectic4Pass'
Length: 1
Class: 'Quadrupole'
K: -0.4000
PolynomB: [0 -0.4000]
PolynomA: [0 0]
MaxOrder: 1
NumIntSteps: 10
We have created four elements:
whos
Name Size Bytes Class Attributes
D1 1x1 716 struct
D2 1x1 716 struct
QD 1x1 1646 struct
QF 1x1 1646 struct
Build lattices
We are ultimately interested in sequences of elements to model storage ring lattices or single-pass beam transport lines.
The next section illustrates building such sequences. Accelerator Toolbox represents sequences of elements as MATLAB cell arrays where individual cells are 1-by-1 structures describing elements.
The following command creates a simple FODO cell by copying previously created element structures into a cell array fodocell:
fodocell = {QF D1 QD D2 QF};
whos fodocell
Name Size Bytes Class Attributes
fodocell 1x5 6890 cell
length is useful to find the number of elements in a sequence:
Use the {:} cell array syntax to print some or all elements:
fodocell{1}
ans =
FamName: 'QF'
PassMethod: 'StrMPoleSymplectic4Pass'
Length: 1
Class: 'Quadrupole'
K: 0.2000
PolynomB: [0 0.2000]
PolynomA: [0 0]
MaxOrder: 1
NumIntSteps: 10
fodocell{:}
ans =
FamName: 'QF'
PassMethod: 'StrMPoleSymplectic4Pass'
Length: 1
Class: 'Quadrupole'
K: 0.2000
PolynomB: [0 0.2000]
PolynomA: [0 0]
MaxOrder: 1
NumIntSteps: 10
ans =
FamName: 'DR01'
PassMethod: 'DriftPass'
Length: 3
Class: 'Drift'
ans =
FamName: 'QD'
PassMethod: 'StrMPoleSymplectic4Pass'
Length: 1
Class: 'Quadrupole'
K: -0.4000
PolynomB: [0 -0.4000]
PolynomA: [0 0]
MaxOrder: 1
NumIntSteps: 10
ans =
FamName: 'DR02'
PassMethod: 'DriftPass'
Length: 2
Class: 'Drift'
ans =
FamName: 'QF'
PassMethod: 'StrMPoleSymplectic4Pass'
Length: 1
Class: 'Quadrupole'
K: 0.2000
PolynomB: [0 0.2000]
PolynomA: [0 0]
MaxOrder: 1
NumIntSteps: 10
Let's build a cell array fodoring that represents a closed ring with 10 periods of fodocell the same way we would build any other array in MATLAB from the command line:
fodoring = [fodocell fodocell fodocell fodocell fodocell...
fodocell fodocell fodocell fodocell fodocell];
whos fodoring
Name Size Bytes Class Attributes
fodoring 1x50 68900 cell
The first element in fodoring is:
fodoring{1}
ans =
FamName: 'QF'
PassMethod: 'StrMPoleSymplectic4Pass'
Length: 1
Class: 'Quadrupole'
K: 0.2000
PolynomB: [0 0.2000]
PolynomA: [0 0]
MaxOrder: 1
NumIntSteps: 10
To inspect or change the value of a specific field we can use MATLAB syntax for accessing cells in cell arrays and field in structures
The lattice fodoring is a variable in MATLAB workspace.
We can use it in accelerator physics functions and scripts.
For example: the function findm44 finds 4-by-4 transverse transfer matrix
M = findm44(fodoring,0)
-0.6352 11.0305 0 0
-0.0763 -0.2497 0 0
0 0 -0.9706 0.3115
0 0 -0.0471 -1.0151
Summary
- Individual elements are represented by 1-by-1 MATLAB structures,
- Sequences of elements (lattices) are represented by 1-dimensional MATLAB cell arrays of structures,
- MATLAB syntax for handling structures and cell arrays applies.
No special language is required to define a lattice.