Example #1
0
machine.one_turn_map = new_one_turn_map

# generate a bunch
bunch = machine.generate_6D_Gaussian_bunch(n_macroparticles=30000,
                                           intensity=1.15e11,
                                           epsn_x=epsn_x,
                                           epsn_y=epsn_y,
                                           sigma_z=0.2)

t_start_slice = time.mktime(time.localtime())
for ii in xrange(N_turns):
    slices_list = bunch.extract_slices(slicer)

    for slice_obj in slices_list[::-1]:
        machine.track(slice_obj)  #, verbose = True)
    print 'Turn', ii

    bunch = sum(slices_list)

    machine.longitudinal_map.track(bunch)

    for ec in ecloud_list:
        ec.finalize_and_reinitialize()
t_end_slice = time.mktime(time.localtime())
print 'Sliced %.2e s per turn' % (
    (t_end_slice - t_start_slice) / float(N_turns))

# Simulate bunch mode
machine_whole_bunch = SPS(n_segments=N_kicks,
                          machine_configuration='Q20-injection',
                          Dt_ref=25e-12,
                          pyecl_input_folder='./drift_sim',
                          x_aper=x_aper,
                          y_aper=y_aper,
                          Dh_sc=Dh_sc,
                          init_unif_edens_flag=init_unif_edens_flag,
                          init_unif_edens=init_unif_edens,
                          N_mp_max=N_mp_max,
                          nel_mp_ref_0=nel_mp_ref_0)

# install ecloud in the machine
machine.install_after_each_transverse_segment(ecloud)

# setup transverse losses (to "protect" the ecloud)
import PyHEADTAIL.aperture.aperture as aperture
apt_xy = aperture.EllipticalApertureXY(x_aper=ecloud.cloudsim.chamb.x_aper,
                                       y_aper=ecloud.cloudsim.chamb.y_aper)
machine.one_turn_map.append(apt_xy)

# generate a bunch
bunch = machine.generate_6D_Gaussian_bunch(n_macroparticles=300000,
                                           intensity=1.5e11,
                                           epsn_x=epsn_x,
                                           epsn_y=epsn_y,
                                           sigma_z=.11)

# simulate
for i_turn in range(N_turns):
    print('Turn', i_turn)
    machine.track(bunch, verbose=True)
yp_before = bunch.yp[bunch.id<=n_part_per_turn]

rms_err_x_list = []
rms_err_y_list = []

# pl.figure(1000)
# pl.plot(bunch.z, bunch.id, '.', markersize=1)
# pl.show()



for ii in xrange(N_turns-1):
	slices_list = bunch.extract_slices(slicer)
	
	for slice_obj in slices_list[::-1]:
		machine.track(slice_obj)#, verbose = True)
	print 'Turn', ii
	
	
	bunch = sum(slices_list)
	
	machine.longitudinal_map.track(bunch)
	
	for ec in ecloud_list:
		ec.finalize_and_reinitialize()
	

	# id and momenta after track
	id_after = bunch.id[bunch.id<=n_part_per_turn]
	xp_after = bunch.xp[bunch.id<=n_part_per_turn]
	z_after = bunch.z[bunch.id<=n_part_per_turn]
bunch.xp[:n_part_per_turn] = xp[0,:]
bunch.y[:n_part_per_turn] = y[0,:]
bunch.yp[:n_part_per_turn] = yp[0,:]
bunch.z[:n_part_per_turn] = z[0,:]
bunch.dp[:n_part_per_turn] =zp[0,:]

# save id and momenta before track
id_before = bunch.id[bunch.id<=n_part_per_turn]
xp_before = bunch.xp[bunch.id<=n_part_per_turn]
yp_before = bunch.yp[bunch.id<=n_part_per_turn]

rms_err_x_list = []
rms_err_y_list = []
for ii in xrange(N_turns-1):
	# track
	machine.track(bunch)#, verbose = True)
	print 'Turn', ii

	# id and momenta after track
	id_after = bunch.id[bunch.id<=n_part_per_turn]
	xp_after = bunch.xp[bunch.id<=n_part_per_turn]
	z_after = bunch.z[bunch.id<=n_part_per_turn]
	yp_after = bunch.yp[bunch.id<=n_part_per_turn]

	# sort id and momenta after track
	indsort = np.argsort(id_after)
	id_after = np.take(id_after, indsort)
	xp_after = np.take(xp_after, indsort)
	yp_after = np.take(yp_after, indsort)
	z_after = np.take(z_after, indsort)
Example #5
0
id_before = bunch.id[bunch.id <= n_part_per_turn]
xp_before = bunch.xp[bunch.id <= n_part_per_turn]
yp_before = bunch.yp[bunch.id <= n_part_per_turn]

rms_err_x_list = []
rms_err_y_list = []

# pl.figure(1000)
# pl.plot(bunch.z, bunch.id, '.', markersize=1)
# pl.show()

for ii in range(N_turns - 1):
    slices_list = bunch.extract_slices(slicer)

    for slice_obj in slices_list[::-1]:
        machine.track(slice_obj)  # , verbose = True)
    print('Turn', ii)

    bunch = sum(slices_list)

    machine.longitudinal_map.track(bunch)

    for ec in ecloud_list:
        ec.finalize_and_reinitialize()

    # id and momenta after track
    id_after = bunch.id[bunch.id <= n_part_per_turn]
    xp_after = bunch.xp[bunch.id <= n_part_per_turn]
    z_after = bunch.z[bunch.id <= n_part_per_turn]
    yp_after = bunch.yp[bunch.id <= n_part_per_turn]