Example #1
0
def test_drift_offset(rin):
    d = elements.Drift('drift', 1)
    rin[0, 0] = 1e-6
    rin[2, 0] = 2e-6
    rin_orig = rin.copy()
    element_pass(d, rin)
    numpy.testing.assert_equal(rin, rin_orig)
Example #2
0
def test_monitor(rin):
    mon = elements.Monitor('monitor')
    assert mon.Length == 0
    rin = numpy.array(numpy.random.rand(*rin.shape), order='F')
    rin_orig = rin.copy()
    element_pass(mon, rin)
    numpy.testing.assert_equal(rin, rin_orig)
Example #3
0
def test_marker(rin):
    m = elements.Marker('marker')
    assert m.Length == 0
    rin = numpy.array(numpy.random.rand(*rin.shape), order='F')
    rin_orig = numpy.array(rin, copy=True, order='F')
    element_pass(m, rin)
    numpy.testing.assert_equal(rin, rin_orig)
Example #4
0
def test_aperture_inside_limits(rin):
    a = elements.Aperture('aperture', [-1e-3, 1e-3, -1e-4, 1e-4])
    assert a.Length == 0
    rin[0, 0] = 1e-5
    rin[2, 0] = -1e-5
    rin_orig = rin.copy()
    element_pass(a, rin)
    numpy.testing.assert_equal(rin, rin_orig)
Example #5
0
def test_m66(rin, n):
    m = numpy.random.rand(6, 6)
    m66 = elements.M66('m66', m)
    assert m66.Length == 0
    rin[n, 0] = 1e-6
    element_pass(m66, rin)
    expected = numpy.array([m[0, n], m[1, n], m[2, n], m[3, n], m[4, n],
                            m[5, n]]).reshape(6, 1) * 1e-6
    numpy.testing.assert_equal(rin, expected)
Example #6
0
def test_corrector(rin):
    c = elements.Corrector('corrector', 0.0, numpy.array([0.9, 0.5],
                                                         dtype=numpy.float64))
    assert c.Length == 0
    rin[0, 0] = 1e-6
    rin_orig = rin.copy()
    rin_orig[1] = 0.9
    rin_orig[3] = 0.5
    element_pass(c, rin)
    numpy.testing.assert_equal(rin, rin_orig)
Example #7
0
def test_drift_divergence(rin):
    d = elements.Drift('drift', 1.0)
    assert d.Length == 1
    rin[1, 0] = 1e-6
    rin[3, 0] = -2e-6
    element_pass(d, rin)
    # results from Matlab
    rin_expected = numpy.array([1e-6, 1e-6, -2e-6, -2e-6, 0,
                                2.5e-12]).reshape(6, 1)
    numpy.testing.assert_equal(rin, rin_expected)
Example #8
0
def test_wiggler(rin):
    period = 0.05
    periods = 23
    bmax = 1
    by = numpy.array([1, 1, 0, 1, 1, 0], dtype=numpy.float64)
    c = elements.Wiggler('wiggler', period * periods, period, bmax, 3e9, By=by)
    assert abs(c.Length - 1.15) < 1e-10
    # Expected value from Matlab AT.
    expected = numpy.array(rin, copy=True)
    expected[5] = 0.000000181809691064259
    element_pass(c, rin)
    numpy.testing.assert_allclose(rin, expected, atol=1e-12)
Example #9
0
def test_quad(rin):
    q = elements.Quadrupole('quad', 0.4, k=1)
    rin[0, 0] = 1e-6
    element_pass(q, rin)
    expected = numpy.array([0.9210610203854122, -0.3894182419439, 0,
                            0, 0, 0.0000000103303797478]).reshape(6, 1) * 1e-6
    numpy.testing.assert_allclose(rin, expected)
    assert q.K == 1
    q.PolynomB[1] = 0.2
    assert q.K == 0.2
    q.K = 0.1
    assert q.PolynomB[1] == 0.1
Example #10
0
def test_dipole_bend_synonym(rin, dipole_class):
    b = dipole_class('dipole', 1.0, 0.1, EntranceAngle=0.05, ExitAngle=0.05)
    rin[0, 0] = 1e-6
    rin_orig = rin.copy()
    element_pass(b, rin)
    rin_expected = numpy.array([1e-6, 0, 0, 0, 0, 1e-7]).reshape((6, 1))
    numpy.testing.assert_almost_equal(rin_orig, rin_expected)
    assert b.K == 0.0
    b.PolynomB[1] = 0.2
    assert b.K == 0.2
    b.K = 0.1
    assert b.PolynomB[1] == 0.1
Example #11
0
def test_drift_two_particles(rin):
    d = elements.Drift('drift', 1.0)
    assert d.Length == 1
    two_rin = numpy.array(numpy.concatenate((rin, rin), axis=1), order='F')
    # particle one is offset
    two_rin[0, 0] = 1e-6
    two_rin[2, 0] = 2e-6
    # particle two has divergence
    two_rin[1, 1] = 1e-6
    two_rin[3, 1] = -2e-6
    two_rin_orig = two_rin.copy()
    element_pass(d, two_rin)
    # results from Matlab
    p1_expected = numpy.array(two_rin_orig[:, 0]).reshape(6, 1)
    p2_expected = numpy.array([1e-6, 1e-6, -2e-6, -2e-6, 0,
                               2.5e-12]).reshape(6, 1)
    two_rin_expected = numpy.concatenate((p1_expected, p2_expected), axis=1)
    numpy.testing.assert_equal(two_rin, two_rin_expected)