Ejemplo n.º 1
0
ps_line, other = pysixtrack.Line.from_sixinput(sixinput)

# Build a pysixtracklib line from pyblep line
import pysixtracklib

pslib_line = pysixtracklib.Elements()
pslib_line.append_line(ps_line)
pslib_line.BeamMonitor(num_stores=1)

# Build a pysixtrack particle
ps_part = pysixtrack.Particles(p0c=7000e9)
ps_part.x = 1e-3
ps_part.px = 2e-4

# Build a pysixtracklib particle
pslib_part_set = pysixtracklib.ParticlesSet()
pslib_part = pslib_part_set.Particles(num_particles=1)
ps_part.partid = 0
ps_part.state = 1
ps_part.elemid = 0
ps_part.turn = 0
pslib_part.from_pysixtrack(ps_part, particle_index=0)

# Track with pysisxtrack
ps_line.track(ps_part)

# Track with sixtracklib
job = pysixtracklib.TrackJob(pslib_line, pslib_part_set)
job.track(until_turn=1)
job.collect()
import pickle
import os

with open('line.pkl', 'rb') as fid:
    line = pickle.load(fid)

import pysixtracklib
elements = pysixtracklib.Elements.fromline(line)

for name, etype, ele in line:
    getattr(elements, etype)(**ele._asdict())

elements.tofile("elements.buffer")

ps = pysixtracklib.ParticlesSet()
p = ps.Particles(num_particles=100)
p.set_reference(p0c=450e9)
ps.tofile('particles.buffer')

os.system(
    '../sixtracklib/build/examples/c99/track_io_c99 particles.buffer elements.buffer 10 1 1 1 >run.out'
)

res = pysixtracklib.ParticlesSet.fromfile('output_particles.bin')

# Test read
elements.fromfile("elements.buffer")
Ejemplo n.º 3
0
def track_particle_sixtracklib(line, partCO, Dx_wrt_CO_m, Dpx_wrt_CO_rad,
                               Dy_wrt_CO_m, Dpy_wrt_CO_rad, Dsigma_wrt_CO_m,
                               Ddelta_wrt_CO, n_turns):


    Dx_wrt_CO_m, Dpx_wrt_CO_rad,\
        Dy_wrt_CO_m, Dpy_wrt_CO_rad,\
        Dsigma_wrt_CO_m, Ddelta_wrt_CO = vectorize_all_coords(
                             Dx_wrt_CO_m, Dpx_wrt_CO_rad,
                             Dy_wrt_CO_m, Dpy_wrt_CO_rad,
                             Dsigma_wrt_CO_m, Ddelta_wrt_CO)

    part = pysixtrack.Particles(**partCO)

    import pysixtracklib
    elements = pysixtracklib.Elements.fromline(line)
    # for name, etype, ele in line:
    #     getattr(elements, etype)(**ele._asdict())
    elements.tofile("elements.buffer")

    n_part = len(Dx_wrt_CO_m)

    # Build PyST particle

    ps = pysixtracklib.ParticlesSet()
    p = ps.Particles(num_particles=n_part)

    for i_part in range(n_part):

        part = pysixtrack.Particles(**partCO)
        part.x += Dx_wrt_CO_m[i_part]
        part.px += Dpx_wrt_CO_rad[i_part]
        part.y += Dy_wrt_CO_m[i_part]
        part.py += Dpy_wrt_CO_rad[i_part]
        part.sigma += Dsigma_wrt_CO_m[i_part]
        part.delta += Ddelta_wrt_CO[i_part]

        part.partid = i_part
        part.state = 1

        p.fromPySixTrack(part, i_part)

    ps.tofile('particles.buffer')

    os.system(
        '../sixtracklib/build/examples/c99/track_io_c99 particles.buffer elements.buffer %d 0 %d 0'
        % (n_turns, n_turns))

    print("Done tracking. Loading data")
    # res = pysixtracklib.ParticlesSet.fromfile('particles.buffer')
    res = pysixtracklib.ParticlesSet.fromfile('output_particles.bin')

    x_tbt = []
    px_tbt = []
    y_tbt = []
    py_tbt = []
    sigma_tbt = []
    delta_tbt = []
    for i_turn in range(n_turns):
        x_tbt.append(res.particles[i_turn].x.copy())
        px_tbt.append(res.particles[i_turn].px.copy())
        y_tbt.append(res.particles[i_turn].y.copy())
        py_tbt.append(res.particles[i_turn].py.copy())
        sigma_tbt.append(res.particles[i_turn].sigma.copy())
        delta_tbt.append(res.particles[i_turn].delta.copy())

    x_tbt = np.array(x_tbt)
    px_tbt = np.array(px_tbt)
    y_tbt = np.array(y_tbt)
    py_tbt = np.array(py_tbt)
    sigma_tbt = np.array(sigma_tbt)
    delta_tbt = np.array(delta_tbt)

    return x_tbt, px_tbt, y_tbt, py_tbt, sigma_tbt, delta_tbt