Exemple #1
0
def test_multipole():
    el = elements.Multipole()
    assert el.order == 0
    assert el.knl[el.order] == 0
    assert el.ksl[el.order] == 0
    el = elements.Multipole(knl=[1])
    assert el.knl == [1]
    assert el.ksl == [0]
    assert el.order == 0
    el = elements.Multipole(knl=[1, 2, 3])
    assert el.order == 2
    el = elements.Multipole(ksl=[1, 2, 3])
    assert el.order == 2
Exemple #2
0
def test_line():
    rfmultipole = elements.RFMultipole(frequency=100,
                                       knl=[0.1, 0.2],
                                       ksl=[0.3, 0.4])
    zero_drift = elements.Drift(0)
    line = pysixtrack.Line(
        elements=[zero_drift, rfmultipole, zero_drift],
        element_names=["zero_drift", "rfmultipole", "zero_drift"],
    )
    length = 1.4
    drift_exact = elements.DriftExact(length)
    multipole = elements.Multipole(knl=[0.1])
    aperture = elements.LimitEllipse(a=0.08, b=0.02)

    n_elements = 3
    position = 1
    drift_exact_name = "exact drift"
    line.insert_element(position, drift_exact, drift_exact_name)
    n_elements += 1
    assert len(line) == n_elements
    assert line.find_element_ids(drift_exact_name)[0] == position
    assert line.get_length() == length

    multipole_name = "multipole"
    line.insert_element(position, multipole, multipole_name)
    n_elements += 1
    line.insert_element(position + 1, aperture, "multipole_aperture")
    n_elements += 1
    assert len(line) == n_elements

    line._add_offset_error_to(multipole_name, dx=0, dy=0)
    n_elements += 2
    assert len(line) == n_elements

    line._add_offset_error_to(multipole_name, dx=0.2, dy=-0.003)
    n_elements += 2
    assert len(line) == n_elements

    line._add_tilt_error_to(multipole_name, angle=0)
    n_elements += 2
    assert len(line) == n_elements

    line._add_tilt_error_to(multipole_name, angle=0.1)
    n_elements += 2
    assert len(line) == n_elements

    line._add_multipole_error_to(multipole_name,
                                 knl=[0, 0.1],
                                 ksl=[-0.03, 0.01])
    # line._add_multipole_error_to(drift_exact,knl=[0,0.1],ksl=[-0.03,0.01])

    line_dict = line.to_dict()
    line = pysixtrack.Line.from_dict(line_dict)
    assert len(line) == n_elements

    line.append_line(pysixtrack.Line.from_dict(line_dict))
    n_elements *= 2
    assert len(line) == n_elements
    assert line.get_length() == 2 * length

    s_elements_d = line.get_s_elements("downstream")
    s_elements_u = line.get_s_elements("upstream")
    assert max(np.array(s_elements_d) - np.array(s_elements_u)) == length

    line.insert_element(1, elements.Multipole(), "inactive_multipole")
    n_elements += 1
    assert len(line) == n_elements
    assert len(line.remove_inactive_multipoles()) == n_elements - 1
    assert len(line) == n_elements
    line.remove_inactive_multipoles(inplace=True)
    n_elements -= 1
    assert len(line) == n_elements

    assert len(line.merge_consecutive_drifts()) == n_elements - 1
    line.merge_consecutive_drifts(inplace=True)
    n_elements -= 1
    assert len(line) == n_elements

    assert len(line.get_elements_of_type(elements.Drift)) == 2

    drifts = line.get_elements_of_type(elements.Drift)[0]
    n_zerolength_drifts = len([d for d in drifts if d.length == 0])
    assert (len(line.remove_zero_length_drifts()) == n_elements -
            n_zerolength_drifts)
    line.remove_zero_length_drifts(inplace=True)
    n_elements -= n_zerolength_drifts
    assert len(line) == n_elements
        def to_pysixtrack(elem):
            pysixtrack_elem = None

            try:
                type_id = elem._typeid
            except AttributeError:
                type_id = None

            cls = (type_id is not None
                   and BeamElementConverter._type_id_to_elem_map.get(
                       type_id, None) or None)

            if cls is not None:
                if type_id == 2:
                    pysixtrack_elem = pysixelem.Drift(length=elem.length)
                elif type_id == 3:
                    pysixtrack_elem = pysixelem.DriftExact(length=elem.length)
                elif type_id == 4:
                    pysixtrack_elem = pysixelem.Multipole(
                        knl=elem.knl,
                        ksl=elem.ksl,
                        hxl=elem.hxl,
                        hyl=elem.hyl,
                        length=elem.length,
                    )
                elif type_id == 5:
                    pysixtrack_elem = pysixelem.Cavity(
                        voltage=elem.voltage,
                        frequency=elem.frequency,
                        lag=elem.lag,
                    )
                elif type_id == 6:
                    pysixtrack_elem = pysixelem.XYShift(dx=elem.dx, dy=elem.dy)
                elif type_id == 7:
                    pysixtrack_elem = pysixelem.SRotation(angle=elem.angle_deg)
                elif type_id == 8:
                    pysixtrack_elem = pysixelem.BeamBeam4D(
                        q_part=elem.q_part,
                        N_part=elem.N_part,
                        sigma_x=elem.sigma_x,
                        sigma_y=elem.sigma_y,
                        beta_s=elem.beta_s,
                        min_sigma_diff=elem.min_sigma_diff,
                        Delta_x=elem.Delta_x,
                        Delta_y=elem.Delta_y,
                        Dpx_sub=elem.Dpx_sub,
                        Dpy_sub=elem.Dpy_sub,
                        enabled=elem.enabled,
                    )
                # elif type_id == 9:
                # pysixtrack_elem = pysixelem.BeamBeam6D()
                elif type_id == 10:
                    pysixtrack_elem = pysixelem.BeamMonitor(
                        num_stores=elem.num_stores,
                        start=elem.start,
                        skip=elem.skip,
                        max_particle_id=elem.max_particle_id,
                        min_particle_id=elem.min_particle_id,
                        is_rolling=elem.is_rolling,
                        is_turn_ordered=elem.is_turn_ordered,
                    )

            return pysixtrack_elem
Exemple #4
0
from pysixtrack import elements

el = elements.Drift()
el = elements.DriftExact()
el = elements.Multipole()
assert el.order == 0
el = elements.XYShift()
el = elements.SRotation()
el = elements.Cavity()
el = elements.Line()
el = elements.DipoleEdge()