def one_pinch(save_rho=True, save_sigmas=False, save_coords=False): if os.path.exists('simulation_status.sta'): os.remove('simulation_status.sta') ring = sim_mod.get_serial_CPUring() list_slice_objects = ring.pieces_to_be_treated # Head is the last element list_machine_elements = ring.sim_content.mypart # Truck the beam to the first ecloud (excluded) for ee in list_machine_elements: if ee in ring.sim_content.my_list_eclouds: first_ecloud = ee break for ss in list_slice_objects[::-1]: ee.track(ss) # Record pinch info first_ecloud.save_ele_distributions_last_track = True first_ecloud.save_ele_field = True first_ecloud.save_ele_potential = True first_ecloud._reinitialize() # Needed to prepare storage space N_slices = len(list_slice_objects) z_centers = [] t_start = time.mktime(time.localtime()) for i_ss, ss in enumerate(list_slice_objects[::-1]): if np.mod(i_ss, 20)==0: print(("%d / %d"%(i_ss, N_slices))) first_ecloud.track(ss) if ss.slice_info != 'unsliced': z_centers.append(ss.slice_info['z_bin_center']) first_ecloud._finalize() z_centers = z_centers[::-1] # HEADTAIL convention t_end = time.mktime(time.localtime()) print(('Track time %.2f s' % (t_end - t_start))) dd = {} dd['phi'] = first_ecloud.phi_ele_last_track if save_rho: dd['rho'] = first_ecloud.rho_ele_last_track if save_sigmas: dd['sigma_x_beam'] = ring.sim_content.bunch.sigma_x() dd['sigma_y_beam'] = ring.sim_content.bunch.sigma_y() dd['sigma_z_beam'] = ring.sim_content.bunch.sigma_z() if save_coords: dd['xg'] = first_ecloud.spacech_ele.xg dd['yg'] = first_ecloud.spacech_ele.yg dd['zg'] = z_centers return dd
import sys sys.path.append('../../../') import PyPARIS_sim_class.Simulation as sim_mod ring = sim_mod.get_serial_CPUring() ring.run()
def one_pinch(mydict, lock, N_pinches=1, save_sigmas_and_coords=False, idd=0, grid=None, eden=None): os.mkdir('temp' + str(idd)) shutil.copytree('pyecloud_config', 'temp' + str(idd) + '/pyecloud_config') shutil.copyfile('Simulation_parameters.py', 'temp' + str(idd) + '/Simulation_parameters.py') shutil.copyfile('LHC_chm_ver.mat', 'temp' + str(idd) + '/LHC_chm_ver.mat') os.chdir('temp' + str(idd)) if os.path.exists('simulation_status.sta'): os.remove('simulation_status.sta') ring = sim_mod.get_serial_CPUring() list_slice_objects = ring.pieces_to_be_treated # Head is the last element list_machine_elements = ring.sim_content.mypart # Truck the beam to the first ecloud (excluded) for ee in list_machine_elements: if ee in ring.sim_content.my_list_eclouds: first_ecloud = ee break for ss in list_slice_objects[::-1]: ee.track(ss) # Record pinch info first_ecloud.save_ele_distributions_last_track = True # first_ecloud.save_ele_field = True first_ecloud.save_ele_potential = True first_ecloud._reinitialize() # Needed to prepare storage space if eden is not None: MP_e = first_ecloud.cloudsim.cloud_list[0].MP_e reweight = np.interp(MP_e.x_mp, eden['x_density'], eden['y_density'] / pp.init_unif_edens_dip) MP_e.nel_mp *= reweight MP_e.clean_small_MPs() N_slices = len(list_slice_objects) z_centers = [] t_start = time.mktime(time.localtime()) for i_ss, ss in enumerate(list_slice_objects[::-1]): if np.mod(i_ss, 20) == 0: print("%d / %d" % (i_ss, N_slices)) first_ecloud.track(ss) if ss.slice_info != 'unsliced': z_centers.append(ss.slice_info['z_bin_center']) first_ecloud._finalize() z_centers = z_centers[::-1] # HEADTAIL convention t_end = time.mktime(time.localtime()) print('Track time %.2f s' % (t_end - t_start)) while 1: if len([ temp_dirs for temp_dirs in os.listdir('.') if 'temp' in temp_dirs ]) < 110: break else: time.sleep(60) if save_sigmas_and_coords: grid['sigma_x_beam'] = ring.sim_content.bunch.sigma_x() grid['sigma_y_beam'] = ring.sim_content.bunch.sigma_y() grid['sigma_z_beam'] = ring.sim_content.bunch.sigma_z() grid['xg'] = first_ecloud.spacech_ele.xg grid['yg'] = first_ecloud.spacech_ele.yg grid['zg'] = z_centers first_ecloud.phi_ele_last_track /= (1. * N_pinches) first_ecloud.rho_ele_last_track /= (1. * N_pinches) lock.acquire() if 'phi' in mydict.keys(): mydict['phi'] += first_ecloud.phi_ele_last_track mydict['rho'] += first_ecloud.rho_ele_last_track else: mydict['phi'] = first_ecloud.phi_ele_last_track mydict['rho'] = first_ecloud.rho_ele_last_track lock.release() os.chdir('..') return idd
import sys sys.path.append('../../../') import PyPARIS_sim_class.Simulation as sim_mod import PyPARIS.communication_helpers as ch ring = sim_mod.get_serial_CPUring(init_sim_objects_auto=False) ring.sim_content.pp.enable_arc_quad = False ring.sim_content.init_all() slices = ring.sim_content.init_master() bunch = ring.sim_content.bunch import h5py with h5py.File('generated_bunch.h5', 'w') as fid: fid['bunch'] = ch.beam_2_buffer(bunch)