Example #1
0
def test_linopt6_rad(lattice):
    """Compare the results with and without radiation"""
    refpts = range(len(lattice) + 1)
    # Turn cavity ON, without radiation
    radlattice = lattice.radiation_on(dipole_pass=None, copy=True)
    ld04, rd4, ld4 = linopt6(lattice, refpts, get_w=True)
    ld06, rd6, ld6 = linopt6(radlattice, refpts, get_w=True)

    assert_close(rd4.tune, rd6.tune[:2], atol=1e-10, rtol=0)
    assert_close(rd4.chromaticity, rd6.chromaticity[:2], atol=1e-8, rtol=0)

    for field in ['s_pos', 'closed_orbit', 'dispersion', 'alpha', 'beta']:
        assert_close(ld4[field], ld6[field], atol=1.e-8, rtol=0, err_msg=field)
    assert_close(ld4.mu, ld6.mu[:, :2], atol=1.e-8, rtol=0)
    assert_close(ld4.W, ld6.W, atol=1e-6, rtol=2e-5)
Example #2
0
def test_6d_analysis(engine, lattices):
    """Compare linopt6 in 6D"""
    py_lattice, ml_lattice, _ = lattices
    fields = [('SPos', 's_pos'), ('ClosedOrbit', 'closed_orbit'), ('M', 'M'),
              ('A', 'A'), ('Dispersion', 'dispersion'), ('alpha', 'alpha'),
              ('beta', 'beta'), ('mu', 'mu'), ('W', 'W')]
    ml_lattice = engine.pyproxy('atradon', ml_lattice)
    py_lattice = py_lattice.radiation_on(copy=True)
    pypts = range(10)
    mlpts = _ml_refs(py_lattice, pypts)

    # python call
    py_data0, py_ringdata, py_data = linopt6(py_lattice,
                                             refpts=pypts,
                                             get_w=True)
    # Matlab call
    ml_ringdata, ml_data = engine.pyproxy('atlinopt6',
                                          ml_lattice,
                                          mlpts,
                                          'get_w',
                                          nargout=2)
    # Comparison
    assert_close(py_ringdata.tune,
                 _py_data(ml_ringdata['tune']),
                 atol=1.e-12,
                 rtol=0)
    assert_close(py_ringdata.chromaticity,
                 _py_data(ml_ringdata['chromaticity']),
                 atol=1.e-5,
                 rtol=0)

    _compare_6d(py_data, ml_data, fields, atol=1.e-6, rtol=1e-8)
Example #3
0
def test_linopt6_norad(lattice):
    """Compare the results of linopt2 and linopt6 in 4d"""
    refpts = range(len(lattice) + 1)
    ld02, rd2, ld2 = linopt2(lattice, refpts, get_w=True)
    ld06, rd6, ld6 = linopt6(lattice, refpts, get_w=True)
    assert_close(rd2.tune, rd6.tune, atol=1e-12, rtol=0)
    assert_close(rd2.chromaticity, rd6.chromaticity, atol=1e-12, rtol=0)

    for field in [
            's_pos', 'closed_orbit', 'dispersion', 'alpha', 'beta', 'mu'
    ]:
        assert_close(ld2[field], ld6[field], atol=1e-10, rtol=0, err_msg=field)
    assert_close(ld2.W, ld6.W, atol=1e-6, rtol=0)
Example #4
0
def test_linopt6(lattice, dp):
    """Compare the results of linopt and linopt6 in 4d"""
    refpts = range(21)
    lindata0, tune, chrom, lindata = linopt(lattice,
                                            dp,
                                            refpts,
                                            get_chrom=True)
    ld0, rd, ld = linopt6(lattice, refpts, dp=dp, get_chrom=True)
    assert_close(tune, rd.tune, rtol=1e-8)
    assert_close(chrom, rd.chromaticity, rtol=1e-8)

    assert_close(ld.beta, lindata.beta, rtol=1e-6)
    assert_close(ld.alpha, lindata.alpha, atol=1e-6, rtol=1e-6)
    assert_close(ld.dispersion, lindata.dispersion, atol=1e-9)
Example #5
0
def test_4d_analysis(engine, lattices, dp):
    """Compare linopt6 in 4D"""
    py_lattice, ml_lattice, _ = lattices
    fields = [
        ('SPos', 's_pos'),
        ('ClosedOrbit', 'closed_orbit'),
        ('M', 'M'),
        ('A', 'A'),
        ('Dispersion', 'dispersion'),
        ('alpha', 'alpha'),
        ('beta', 'beta'),
        ('mu', 'mu'),
    ]
    pypts = range(10)
    mlpts = _ml_refs(py_lattice, pypts)

    # python call
    py_data0, py_ringdata, py_data = linopt6(py_lattice,
                                             refpts=pypts,
                                             dp=dp,
                                             get_chrom=True)
    # Matlab call
    ml_data, ml_ringdata = engine.pyproxy('atlinopt6',
                                          ml_lattice,
                                          mlpts,
                                          'dp',
                                          dp,
                                          'get_chrom',
                                          nargout=2)
    # Comparison
    assert_close(py_ringdata.tune,
                 _py_data(ml_ringdata['tune']),
                 atol=1.e-8,
                 rtol=0)
    assert_close(py_ringdata.chromaticity,
                 _py_data(ml_ringdata['chromaticity']),
                 atol=1.e-8,
                 rtol=0)

    _compare_4d(py_data, ml_data, fields, atol=1.e-6, rtol=1e-8)