Home > atdemos > opticsAndBeamSizes > latticedemo.m

latticedemo

PURPOSE ^

LATTICEDEMO self-running tutorial

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

LATTICEDEMO self-running tutorial
 demonstrates 
 1. ELEMENT, family of ELEMENTS, sequence of ELEMENTS 
 2. Lattice representation
 3. Creating a lattice 
 4. Creating and editing lattice files

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %LATTICEDEMO self-running tutorial
0002 % demonstrates
0003 % 1. ELEMENT, family of ELEMENTS, sequence of ELEMENTS
0004 % 2. Lattice representation
0005 % 3. Creating a lattice
0006 % 4. Creating and editing lattice files
0007 clear all
0008 clc
0009 echo on
0010 % An element in Accelerator Toolbox is a 1-by-1 MATLAB STRUCTURE
0011 % The folowing code creates a structure D1 for a drift space
0012 % and a structure QF for a quadrupole.
0013 
0014 D1.FamName = 'DR01';
0015 D1.Length  = 3;
0016 D1.PassMethod = 'DriftPass';
0017 
0018 QF.FamName = 'QF';
0019 QF.Length = 1;
0020 QF.K = 0.2;
0021 QF.MaxOrder = 3;
0022 QF.NumIntSteps = 1;
0023 QF.PolynomA= [0 0 0];
0024 QF.PolynomB= [0 0.2 0];
0025 QF.R1= eye(6);
0026 QF.R2= eye(6);
0027 QF.T1= [0 0 0 0 0 0];
0028 QF.T2= [0 0 0 0 0 0];
0029 QF.PassMethod= 'QuadLinearPass';
0030 
0031 pause % Press any key to continue
0032 clc
0033 % Use WHOS, DISP or just type variable's name without closing semicolon
0034 % to print the element's info:
0035 
0036 whos D1 QF                   
0037 disp(D1)                      
0038 QF                            
0039 
0040 pause % Press any key to continue
0041 clc
0042 % The next few lines will create another drift structure D2 from the exiting D1
0043 % and modify the values of fields 'FamName' and 'Length'
0044 
0045 D2 = D1;
0046 
0047 D2.FamName = 'DR02';
0048 D2.Length = 2;
0049 
0050 disp(D2)
0051 pause % Press any key to continue
0052 clc
0053 % Create another quadrupole element structure QD from QF and modify
0054 % the values of fields 'K' and 'PolynomB' to make it defocusing
0055 QD = QF;
0056 QD.FamName = 'QD';
0057 QD.K = -0.4;
0058 % Field 'PolynomB is a vector with polynomial field expansion coefficients.
0059 % The second element (quadrupole coefficient) must be consistent with field 'K'
0060 QD.PolynomB(2) = QD.K;
0061 
0062 disp(QD)
0063 pause % Press any key to continue
0064 clc
0065 % We have declared four elements:
0066 whos
0067 
0068 % They are now independent from each other
0069 
0070 % We are ultimately interested in sequences of elements
0071 % to model storage ring lattices or single-pass beam transport lines.
0072 % The next section will illustrate building of such sequences
0073 
0074 
0075 
0076 pause % Press any key to continue
0077 clc
0078 % Accelerator Toolbox represents sequences of elements as MATLAB cell arrays
0079 % where individual cells are 1-by-1 structures containing element data
0080 % The following commad creates a simple FODO cell by copying previously
0081 % created element structures for drifts and quadrupole magnets to a cell array FODOCELL:
0082 
0083 FODOCELL = {QF D1 QD D2 QF};
0084 
0085 whos FODOCELL
0086 % LENGTH is useful to find the number of elements in a sequence
0087 
0088 L = length(FODOCELL) 
0089 pause % Press any key to continue;
0090 clc
0091 % Use {:} cell array syntax to print some or all elements
0092 FODOCELL{1}
0093 pause % FODOCELL{:} will print a long list of all elements. Press any key to continue
0094 clc
0095 FODOCELL{:}
0096 pause % Press any key to continue;
0097 clc
0098 % Let's build a cell array THERING that represents a closed ring
0099 % with 10 periods of FODOCELL the same way we would build
0100 % any other array in MATLAB from the comman dline
0101 
0102 THERING = [FODOCELL FODOCELL FODOCELL FODOCELL FODOCELL...
0103            FODOCELL FODOCELL FODOCELL FODOCELL FODOCELL]; 
0104         
0105 whos THERING
0106 pause % Press any key to continue;
0107 clc
0108 % The first element in THERING is
0109 THERING{1}
0110 
0111 % To inspect or change the value of a specific field we can use MATLAB syntax
0112 % for accessing cells in cell arrays and field in structures
0113 oldK = THERING{1}.K
0114 
0115 THERING{1}.K = 0.25;
0116 
0117 newK = THERING{1}.K
0118 
0119 pause % Press any key to continue;
0120 clc
0121 % Lattice THERING is a variable in MATLAB workspace.
0122 % We can use it in accelerator physics functions and scripts
0123 %
0124 % For example: function FindM44 finds 4-by-4 transverse transfer matrix
0125 M = findm44(THERING,0)
0126 pause % Press any key to continue;
0127 clc
0128 % -----------------------------------------------------------------------
0129 % SUMMARY
0130 % 1. Individual elements are represented by 1-by-1  MATLAB structures
0131 
0132 % 2. Element sequences (lattices) are represented by 1-dimensional
0133 %    MATLAB cell arrays of stuctures
0134 
0135 % 3. MATLAB syntax for hanling structures and cell arrays applies.
0136 %    No special language is required to define a lattice.
0137 
0138 % --------------------------------------------------------------------------
0139 
0140 pause % Press any key to continue;
0141 echo off
0142 clc

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