MAD-X
This module allows to run MAD-X through cpymad. A sequence loaded with georges_core.sequence can be send to MAD-X to compute the Twiss or perform a tracking simulation.
The example below creates a simple line with georges-core and perform a Twiss with cpymad and the results are shown in a figure.
import georges_core
import georges_core.madx
from georges_core.units import ureg as _ureg
from georges_core.sequences import Element
from georges_core.sequences import PlacementSequence, SequenceMetadata
import matplotlib.pyplot as plt
aper1 = 5 *_ureg.cm
aper2 = 3.5 * _ureg.cm
d1 = Element.Drift(NAME="D1",
L=0.3* _ureg.m,
APERTYPE="RECTANGULAR",
APERTURE=[aper1, aper2])
qf = Element.Quadrupole(NAME="Q1",
L=0.3*_ureg.m,
K1=2*_ureg.m**-2,
APERTYPE="RECTANGULAR",
APERTURE=[aper1, aper2])
d2 = Element.Drift(NAME="D2",
L=0.3*_ureg.m,
APERTYPE="CIRCULAR",
APERTURE=[aper1])
b1 = Element.SBend(NAME="B1",
L=1*_ureg.m,
ANGLE=30*_ureg.degrees,
K1=0*_ureg.m**-2,
APERTYPE="CIRCULAR",
APERTURE=[aper1, aper1])
d3 = Element.Drift(NAME="D3",
L=0.3*_ureg.m,
APERTYPE="CIRCULAR",
APERTURE=[aper1, aper1])
qd = Element.Quadrupole(NAME="Q2",
L=0.3*_ureg.m,
K1=-2*_ureg.m**-2,
APERTYPE="RECTANGULAR",
APERTURE=[aper1, aper2])
d4 = Element.Drift(NAME="D4",
L=0.3*_ureg.m,
APERTYPE="CIRCULAR",
APERTURE=[aper1, aper1])
b2 = Element.SBend(NAME="B2",
L=1*_ureg.m,
ANGLE=-30*_ureg.degrees,
K1=0*_ureg.m**-2,
APERTYPE="RECTANGULAR",
APERTURE=[aper1, aper2])
d5 = Element.Drift(NAME="D5",
L=0.3*_ureg.m,
APERTYPE="CIRCULAR",
APERTURE=[aper1, aper1])
sequence = PlacementSequence(name="seq", metadata=SequenceMetadata(kinematics=georges_core.Kinematics(230 *_ureg.MeV)))
sequence.place(d1,at_entry=0*_ureg.m)
sequence.place_after_last(qf)
sequence.place_after_last(d2)
sequence.place_after_last(b1)
sequence.place_after_last(d3)
sequence.place_after_last(qd)
sequence.place_after_last(d4)
sequence.place_after_last(b2)
sequence.place_after_last(d5)
mad_input = georges_core.madx.MadX(sequence=sequence)
twiss = mad_input.twiss(sequence='seq');
plt.plot(twiss.s, twiss.betx)
plt.xlabel('S')
plt.ylabel('BETX')
plt.show()
++++++++++++++++++++++++++++++++++++++++++++
+ MAD-X 5.09.00 (64 bit, Linux) +
+ Support: mad@cern.ch, http://cern.ch/mad +
+ Release date: 2023.05.05 +
+ Execution date: 2023.12.04 15:50:53 +
++++++++++++++++++++++++++++++++++++++++++++
enter Twiss module
iteration: 1 error: 0.000000E+00 deltap: 0.000000E+00
orbit: 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00
++++++ table: summ
length orbit5 alfa gammatr
4.1 -0 -0.0507080576 -4.440803049
q1 dq1 betxmax dxmax
0.320359787 -0.5044283351 4.585234699 0.3336379866
dxrms xcomax xcorms q2
0.1941087334 0 0 0.197886853
dq2 betymax dymax dyrms
-0.7348395415 6.47917673 -0 0
ycomax ycorms deltap synch_1
0 0 0 0
synch_2 synch_3 synch_4 synch_5
0 0 0 0
synch_6 synch_8 nflips dqmin
0 0 0 0
dqmin_phase
0
Note
This instance of cpymad can be easily converted into a BDSIM input using pybdsim