hibtc / cpymad

Cython binding to MAD-X
http://hibtc.github.io/cpymad/
Other
27 stars 18 forks source link

How to change the magnetic value (i.e. angle for dipole) in a sequence? #37

Closed Landau1908 closed 8 years ago

Landau1908 commented 8 years ago

Hi, Thomas

How to change the value of a magnet in a sequence in cpymad? I want to change the value (i.e. angle) of some corrector, and to read the closed orbit of each BPM locations.

coldfix commented 8 years ago

EDIT: Sorry for being harsh.

For reference, here are the most relevant ways to achieve this. Assume, you have MAD-X elements, defined like this:

k1_qp1 = 1;
qp1: quadrupole, l=1, k1:=k1_qp1;
qp2: quadrupole, l=1, k1=1;
mul: multipole, knl={1, 1, 1};  ! a list

in MAD-X, you can change their values as follows:

K1_QP1 = 2;
qp2->k1 = 2;            ! also works for qp1
mul, knl={2, 2, 2};     ! this is the only method that works for lists
                        ! (but it also works for qp1,qp2 as well!)

where the syntax at the bottom is the most generic, i.e. can be used to modify the values for all cases, and the syntax in the middle can be used to modify either of the first two elements.

Now in cpymad, you have several options:

m.input('k1_qp1 = 2;')
m.input('qp2->k1 = 2;')
m.input('mul, knl={2, 2, 2}')
m.set_value('k1_qp1', 2)
m.set_value('qp2->k1', 2)
m.command('mul', knl=[2, 2, 2])
m.globals['k1_qp1'] = 2