Skip to content

Commit f0fec91

Browse files
committed
Add test
1 parent 3a3f972 commit f0fec91

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

tests/test_survey.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,5 +492,110 @@ def test_survey_against_madx():
492492

493493
xo.assert_allclose(sv.s[1:], sv_mad.s, atol=1e-14, rtol=0)
494494

495+
xo.assert_allclose(p[:, 0], 1e-3, atol=1e-14)
496+
xo.assert_allclose(p[:, 1], 2e-3, atol=1e-14)
497+
498+
def test_survey_transforms_native_loader():
499+
500+
from cpymad.madx import Madx
501+
502+
seq_src = ("""
503+
504+
on_srot = 1;
505+
pi = 3.14159265358979323846;
506+
507+
tr1: translation, dx=1e-2, dy=2e-2;
508+
509+
rs2: srotation, angle=-1.04*on_srot;
510+
511+
r3: yrotation, angle=-0.1;
512+
r4: yrotation, angle=0.1;
513+
514+
rx1 : xrotation, angle=0.1;
515+
rx2 : xrotation, angle=-0.1;
516+
517+
bh1 : sbend, angle=0.1, k0=1e-22, l=0.1;
518+
bh2 : sbend, angle=-0.1, k0=1e-22, l=0.1;
519+
520+
bv1: sbend, tilt=pi/2, angle=0.2, k0=1e-22, l=0.1;
521+
bv2: sbend, tilt=pi/2, angle=-0.2, k0=1e-22, l=0.1;
522+
523+
ss: sequence,l=20;
524+
tr1, at=5;
525+
rs2, at=5.5;
526+
rx1, at=6;
527+
rx2, at=7;
528+
r3, at=8;
529+
r4, at=9;
530+
bh1, at=10;
531+
bh2, at=11;
532+
bv1, at=12;
533+
bv2, at=14;
534+
end: marker, at=16;
535+
endsequence;
536+
""")
537+
538+
mad = Madx()
539+
mad.input(seq_src)
540+
541+
mad.input("""
542+
beam;
543+
use,sequence=ss;
544+
twiss,betx=1,bety=1,x=1e-3,y=2e-3;
545+
survey;
546+
547+
ptc_create_universe;
548+
ptc_create_layout, model=1, method=6, exact=True, NST=100;
549+
ptc_align;
550+
ptc_twiss, icase=56, betx=1., bety=1., betz=1,x=1e-3, y=2e-3;
551+
552+
""")
553+
554+
line = xt.load(string=seq_src, format='madx').ss
555+
line.particle_ref = xt.Particles(p0c=1E9)
556+
557+
line['bh1'].k0_from_h = False
558+
line['bh2'].k0_from_h = False
559+
line['bh1'].k0 = 0
560+
line['bh2'].k0 = 0
561+
562+
sv_mad = xt.Table(mad.table.survey)
563+
tw_ptc = xt.Table(mad.table.ptc_twiss)
564+
565+
line.build_tracker()
566+
567+
line.tracker.track_flags.XS_FLAG_IGNORE_GLOBAL_APERTURE = True
568+
line.configure_drift_model(model='exact')
569+
570+
sv = line.survey()
571+
tw = line.twiss(betx=1, bety=1, x=1e-3, y=2e-3)
572+
573+
p = tw.x[:, None] * sv.ex + tw.y[:, None] * sv.ey + sv.p0
574+
X = p[:, 0]
575+
Y = p[:, 1]
576+
Z = p[:, 2]
577+
578+
assert (tw.name == np.array(
579+
['drift_1', 'tr1', 'drift_2', 'rs2', 'drift_3', 'rx1', 'drift_4',
580+
'rx2', 'drift_5', 'r3', 'drift_6', 'r4', 'drift_7', 'bh1',
581+
'drift_8', 'bh2', 'drift_9', 'bv1', 'drift_10', 'bv2', 'drift_11',
582+
'end', 'drift_12', '_end_point'], dtype=object)).all()
583+
584+
assert (tw_ptc.name == np.array(['ss$start:1', 'drift_0:0', 'tr1:1', 'drift_1:0', 'rs2:1',
585+
'drift_2:0', 'rx1:1', 'drift_3:0', 'rx2:1', 'drift_4:0', 'r3:1',
586+
'drift_5:0', 'r4:1', 'drift_6:0', 'bh1:1', 'drift_7:0', 'bh2:1',
587+
'drift_8:0', 'bv1:1', 'drift_9:0', 'bv2:1', 'drift_10:0', 'end:1',
588+
'drift_11:0', 'ss$end:1'], dtype=object)).all()
589+
590+
# MAD gives results at the end of the element
591+
xo.assert_allclose(tw.x[1:], tw_ptc.x[1:-1], atol=1e-14, rtol=0)
592+
xo.assert_allclose(tw.y[1:], tw_ptc.y[1:-1], atol=1e-14, rtol=0)
593+
594+
xo.assert_allclose(sv.X[1:], sv_mad.x[1:-1], atol=1e-14, rtol=0)
595+
xo.assert_allclose(sv.Y[1:], sv_mad.y[1:-1], atol=1e-14, rtol=0)
596+
xo.assert_allclose(sv.Z[1:], sv_mad.z[1:-1], atol=1e-14, rtol=0)
597+
598+
xo.assert_allclose(sv.s[1:], sv_mad.s[1:-1], atol=1e-14, rtol=0)
599+
495600
xo.assert_allclose(p[:, 0], 1e-3, atol=1e-14)
496601
xo.assert_allclose(p[:, 1], 2e-3, atol=1e-14)

0 commit comments

Comments
 (0)