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
コード例 #2
0
import sys
sys.path.append('../../../')

import PyPARIS_sim_class.Simulation as sim_mod

ring = sim_mod.get_serial_CPUring()
ring.run()
コード例 #3
0
    if detuning_fit_order > 0:
        obdet = mfm.myloadmat_to_obj(z_strength_file)
        z_slices = obdet.z_slices
        p = np.polyfit(obdet.z_slices,
                       obdet.k_z_integrated,
                       deg=detuning_fit_order)
        alpha_N = p[::-1] * ecloud_strength_scale  # Here I fit the strength
        print('Detuning cefficients alpha_N:')
        print(alpha_N)
    else:
        alpha_N = alpha_N_custom

    alpha_N = alpha_N[:N_poly_cut] * alpha_scale

# Instantiate simulation
sim_content = sim_mod.Simulation(param_file=sim_param_file)

# Here sim_content.pp can be edited (directly and through files)
for ff in sim_param_amend_files:
    sim_content.pp.update(param_file=ff)

# Make the slice output file smaller
sim_content.pp.slice_stats_to_store = [
    'mean_x', 'mean_z', 'n_macroparticles_per_slice'
]

sim_content.pp.Qp_x = Qp_x

if add_alpha_0_to_tune:
    assert (only_phase_shift)
    sim_content.pp.Q_x += -(factor_alpha_0_to_tune * alpha_N[0] *
コード例 #4
0
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
コード例 #5
0
ecloud_strength_scale = 1.

sim_param_file = '../reference_simulation/Simulation_parameters.py'
sim_param_amend_files = ['../Simulation_parameters_amend.py',
                    'Simulation_parameters_amend_for_matrixsim.py']

include_non_linear_map = True
field_map_file = '../003_generate_field_map/field_map_lin.mat'

N_turns_footprint = 1024
N_particles_footprint = 5000
# end-settings-section


# Instantiate simulation
sim_content = sim_mod.Simulation(param_file=sim_param_file)

# Here sim_content.pp can be edited (directly and through files)
for ff in sim_param_amend_files:
    sim_content.pp.update(param_file=ff)

# Disable real e-clouds
sim_content.pp.enable_arc_dip = False
sim_content.pp.enable_arc_quad = False

# Switch off damper for footprint
sim_content.pp.enable_transverse_damper = False

# Add ring of CPU information
ring_cpu = pu.get_serial_CPUring(sim_content,
        init_sim_objects_auto=False)
コード例 #6
0
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)
コード例 #7
0
import sys
sys.path.append('../../../')

import PyPARIS_sim_class.Simulation as sim_mod
import PyPARIS.util as pu

sim_content = sim_mod.Simulation(
    param_file='param_folder/Simulation_parameters.py')

ring = pu.get_serial_CPUring(sim_content, init_sim_objects_auto=True)
ring.run()