sys.path.append('../../') import dynamics_Boris_f2py as dynB import MP_system as MPs from geom_impact_ellip import ellip_cham_geom_object Dt = 25e-10 N_steps = 1000000 B = 0 N_sub_steps = 1 B_map_file = 'analytic_qaudrupole_unit_grad' fact_Bmap = 12. * 0.6 dynamicsB = dynB.pusher_Boris(Dt, 0., B, 0., B_map_file, fact_Bmap, None, N_sub_steps=N_sub_steps) chamb = ellip_cham_geom_object(.02, .02) N_mp_max = 1000 nel_mp_ref_0 = -1 fact_split = -1 fact_clean = -1 N_mp_regen_low = -1 N_mp_regen = -1 N_mp_after_regen = -1 Dx_hist = -1 Nx_regen = -1 Ny_regen = -1
def read_input_files_and_init_components(pyecl_input_folder='./', **kwargs): b_par, x_aper, y_aper, B,\ gas_ion_flag, P_nTorr, sigma_ion_MBarn, Temp_K, unif_frac, E_init_ion,\ Emax, del_max, R0, E_th, sigmafit, mufit,\ Dt, t_end, lam_th, t_ion, N_mp_max,\ N_mp_regen, N_mp_after_regen, fact_split, fact_clean, nel_mp_ref_0,\ Nx_regen, Ny_regen, Nvx_regen, Nvy_regen, Nvz_regen,regen_hist_cut,\ N_mp_regen_low,\ Dt_sc, Dh_sc, t_sc_ON,Dx_hist,r_center, scrub_en_th,\ progress_path, logfile_path, flag_movie, flag_sc_movie,\ Dt_En_hist, Nbin_En_hist,En_hist_max, \ photoem_flag, inv_CDF_refl_photoem_file, k_pe_st, refl_frac, alimit, e_pe_sigma,\ e_pe_max,x0_refl, y0_refl, out_radius, \ switch_model, switch_no_increase_energy, thresh_low_energy, save_mp_state_time_file, \ init_unif_flag, Nel_init_unif, E_init_unif, x_max_init_unif, x_min_init_unif, y_max_init_unif, y_min_init_unif,\ chamb_type, filename_chm, flag_detailed_MP_info, flag_hist_impact_seg,\ track_method, B0x, B0y, B0z, B_map_file, Bz_map_file, N_sub_steps, fact_Bmap, B_zero_thrhld,\ N_mp_soft_regen, N_mp_after_soft_regen,\ flag_verbose_file, flag_verbose_stdout,\ flag_presence_sec_beams, sec_b_par_list, phem_resc_fac, dec_fac_secbeam_prof, el_density_probes, save_simulation_state_time_file,\ x_min_hist_det, x_max_hist_det, y_min_hist_det, y_max_hist_det, Dx_hist_det, dec_fact_out, stopfile, sparse_solver, B_multip, \ PyPICmode, filename_init_MP_state,\ init_unif_edens_flag, init_unif_edens, E_init_unif_edens,\ x_max_init_unif_edens, x_min_init_unif_edens, y_max_init_unif_edens, y_min_init_unif_edens, flag_assume_convex, E0, s_param,\ filen_main_outp,\ f_telescope, target_grid, N_nodes_discard, N_min_Dh_main = \ read_parameter_files(pyecl_input_folder) for attr in kwargs.keys(): print 'Ecloud init. From kwargs: %s = %s'%(attr, repr(kwargs[attr])) tmpattr = kwargs[attr] exec('%s=tmpattr'%attr) ########################################## pyeclsaver=pysav.pyecloud_saver(logfile_path) if switch_model=='ECLOUD_nunif': flag_non_unif_sey = 1 else: flag_non_unif_sey = 0 if chamb_type=='ellip': chamb=ellip_cham_geom_object(x_aper, y_aper, flag_verbose_file=flag_verbose_file) elif chamb_type=='polyg' or chamb_type=='polyg_cython': import geom_impact_poly_fast_impact as gipfi chamb=gipfi.polyg_cham_geom_object(filename_chm, flag_non_unif_sey, flag_verbose_file=flag_verbose_file, flag_verbose_stdout=flag_verbose_stdout, flag_assume_convex=flag_assume_convex) elif chamb_type=='polyg_numpy': raise ValueError("chamb_type='polyg_numpy' not supported anymore") #~ chamb=gip.polyg_cham_geom_object(filename_chm, flag_non_unif_sey, #~ flag_verbose_file=flag_verbose_file, flag_verbose_stdout=flag_verbose_stdout) elif chamb_type=='rect': import geom_impact_rect_fast_impact as girfi chamb = girfi.rect_cham_geom_object(x_aper, y_aper, flag_verbose_file=flag_verbose_file, flag_verbose_stdout=flag_verbose_stdout) else: raise ValueError('Chamber type not recognized (choose: ellip/rect/polyg)') MP_e=MPs.MP_system(N_mp_max, nel_mp_ref_0, fact_split, fact_clean, N_mp_regen_low, N_mp_regen, N_mp_after_regen, Dx_hist, Nx_regen, Ny_regen, Nvx_regen, Nvy_regen, Nvz_regen, regen_hist_cut, chamb, N_mp_soft_regen=N_mp_soft_regen, N_mp_after_soft_regen=N_mp_after_soft_regen) beamtim=beatim.beam_and_timing(b_par.flag_bunched_beam, b_par.fact_beam, b_par.coast_dens, b_par.beam_field_file,lam_th, b_spac=b_par.b_spac, sigmaz=b_par.sigmaz,t_offs=b_par.t_offs, filling_pattern_file=b_par.filling_pattern_file, Dt=Dt, t_end=t_end, beam_long_prof_file=b_par.beam_long_prof_file, Dh_beam_field=b_par.Dh_beam_field, f_telescope_beam = b_par.f_telescope_beam, target_grid_beam = b_par.target_grid_beam, N_nodes_discard_beam = b_par.N_nodes_discard_beam, N_min_Dh_main_beam = b_par.N_min_Dh_main_beam, chamb=chamb, sigmax=b_par.sigmax, sigmay=b_par.sigmay, x_beam_pos = b_par.x_beam_pos, y_beam_pos = b_par.y_beam_pos, save_beam_field_file_as=b_par.save_beam_field_file_as, Nx=b_par.Nx, Ny=b_par.Ny, nimag=b_par.nimag, progress_mapgen_file = (progress_path+'_mapgen')) if sparse_solver=='klu': print '''sparse_solver: 'klu' no longer supported --> going to PyKLU''' sparse_solver='PyKLU' spacech_ele = scc.space_charge(chamb, Dh_sc, Dt_sc=Dt_sc, sparse_solver=sparse_solver, PyPICmode=PyPICmode, f_telescope = f_telescope, target_grid = target_grid, N_nodes_discard = N_nodes_discard, N_min_Dh_main = N_min_Dh_main) sec_beams_list=[] if flag_presence_sec_beams: N_sec_beams = len(sec_b_par_list) for ii in xrange(N_sec_beams): print 'Initialize secondary beam %d/%d'%(ii+1, N_sec_beams) sb_par = sec_b_par_list[ii] sec_beams_list.append(beatim.beam_and_timing(sb_par.flag_bunched_beam, sb_par.fact_beam, sb_par.coast_dens, sb_par.beam_field_file,lam_th, b_spac=sb_par.b_spac, sigmaz=sb_par.sigmaz,t_offs=sb_par.t_offs, filling_pattern_file=sb_par.filling_pattern_file, Dt=Dt, t_end=t_end, beam_long_prof_file=sb_par.beam_long_prof_file, Dh_beam_field=sb_par.Dh_beam_field, f_telescope_beam = sb_par.f_telescope_beam, target_grid_beam = sb_par.target_grid_beam, N_nodes_discard_beam = sb_par.N_nodes_discard_beam, N_min_Dh_main_beam = sb_par.N_min_Dh_main_beam, chamb=chamb, sigmax=sb_par.sigmax, sigmay=sb_par.sigmay, x_beam_pos = sb_par.x_beam_pos, y_beam_pos = sb_par.y_beam_pos, save_beam_field_file_as=sb_par.save_beam_field_file_as, flag_secodary_beam = True, t_primary_beam = beamtim.t, Nx=sb_par.Nx, Ny=sb_par.Ny, nimag=sb_par.nimag, progress_mapgen_file = (progress_path+('_mapgen_sec_%d'%ii)))) kwargs = {} if E0 is not None: kwargs.update({'E0':E0}) #If E0 is not provided use default value for each object if s_param is not None: if switch_model==0 or switch_model=='ECLOUD': kwargs.update({'s':s_param}) else: raise ValueError('s parameter can be changed only in the ECLOUD sec. emission model!') if switch_model==0 or switch_model=='ECLOUD': sey_mod=SEY_model_ECLOUD(Emax,del_max,R0,**kwargs) elif switch_model==1 or switch_model=='ACC_LOW': sey_mod=SEY_model_acc_low_ene(Emax,del_max,R0,**kwargs) elif switch_model=='ECLOUD_nunif': sey_mod=SEY_model_ECLOUD_non_unif(chamb, Emax,del_max,R0,**kwargs) elif switch_model=='cos_low_ene': sey_mod=SEY_model_cos_le(Emax,del_max,R0,**kwargs) elif switch_model=='flat_low_ene': sey_mod=SEY_model_flat_le(Emax,del_max,R0) flag_seg = (flag_hist_impact_seg==1) impact_man=imc.impact_management(switch_no_increase_energy, chamb, sey_mod, E_th, sigmafit, mufit, Dx_hist, scrub_en_th, Nbin_En_hist, En_hist_max, thresh_low_energy=thresh_low_energy, flag_seg=flag_seg) resgasion_sec_beam_list=[] if gas_ion_flag==1: resgasion=gic.residual_gas_ionization(unif_frac, P_nTorr, sigma_ion_MBarn,Temp_K,chamb,E_init_ion) else: resgasion=None if photoem_flag==1: phemiss=gpc.photoemission(inv_CDF_refl_photoem_file, k_pe_st, refl_frac, e_pe_sigma, e_pe_max,alimit, \ x0_refl, y0_refl, out_radius, chamb, phem_resc_fac) else: phemiss=None pyeclsaver.start_observing(MP_e, beamtim, impact_man, r_center, Dt_En_hist, logfile_path, progress_path, flag_detailed_MP_info=flag_detailed_MP_info, flag_movie=flag_movie, flag_sc_movie=flag_sc_movie, save_mp_state_time_file=save_mp_state_time_file, flag_presence_sec_beams=flag_presence_sec_beams, sec_beams_list=sec_beams_list, dec_fac_secbeam_prof=dec_fac_secbeam_prof, el_density_probes=el_density_probes, save_simulation_state_time_file = save_simulation_state_time_file, x_min_hist_det=x_min_hist_det, x_max_hist_det=x_max_hist_det, y_min_hist_det=y_min_hist_det, y_max_hist_det=y_max_hist_det, Dx_hist_det=Dx_hist_det, dec_fact_out=dec_fact_out, stopfile=stopfile, filen_main_outp=filen_main_outp) if track_method == 'Boris': dynamics=dynB.pusher_Boris(Dt, B0x, B0y, B0z, \ B_map_file, fact_Bmap, Bz_map_file,N_sub_steps=N_sub_steps) elif track_method == 'StrongBdip': dynamics=dyndip.pusher_dipole_magnet(Dt,B) elif track_method == 'StrongBgen': dynamics=dyngen.pusher_strong_B_generalized(Dt, B0x, B0y, \ B_map_file, fact_Bmap, B_zero_thrhld) elif track_method == 'BorisMultipole': import dynamics_Boris_multipole as dynmul dynamics=dynmul.pusher_Boris_multipole(Dt=Dt, N_sub_steps=N_sub_steps, B_multip = B_multip) else: raise ValueError("""track_method should be 'Boris' or 'StrongBdip' or 'StrongBgen' or 'BorisMultipole'""") if init_unif_flag==1: print "Adding inital %.2e electrons to the initial distribution"%Nel_init_unif MP_e.add_uniform_MP_distrib(Nel_init_unif, E_init_unif, x_max_init_unif, x_min_init_unif, y_max_init_unif, y_min_init_unif) if init_unif_edens_flag==1: print "Adding inital %.2e electrons/m^3 to the initial distribution"%init_unif_edens MP_e.add_uniform_ele_density(n_ele=init_unif_edens, E_init=E_init_unif_edens, x_max=x_max_init_unif_edens, x_min=x_min_init_unif_edens, y_max=y_max_init_unif_edens, y_min=y_min_init_unif_edens) if filename_init_MP_state!=-1 and filename_init_MP_state is not None: print "Adding inital electrons from: %s"%filename_init_MP_state MP_e.add_from_file(filename_init_MP_state) return beamtim,MP_e, dynamics,impact_man, pyeclsaver, \ gas_ion_flag, resgasion, t_ion, \ spacech_ele,t_sc_ON, photoem_flag, phemiss,\ flag_presence_sec_beams, sec_beams_list
# Ex_n=array([0.,0.]) # Ey_n=array([0.,0.]) # # x_mpB=array([0.0156605126754]) # y_mpB=array([0.0154002281106]) # z_mpB=array([1.59147686348e-05]) # # vx_mpB=array([335546.817425]) # vy_mpB=array([-170848.411391]) # vz_mpB=array([223792.460031]) #=============================================================================== dynamicsB=dynB.pusher_Boris(Dt, 0., B, 0., \ B_map_file, fact_Bmap, None,N_sub_steps=N_sub_steps) dynamicsGen= dyngen.pusher_strong_B_generalized(Dt, 0., B, \ B_map_file, fact_Bmap, 1e-6) chamb=ellip_cham_geom_object(.02, .02) N_mp_max = 1000 nel_mp_ref_0 = -1 fact_split = -1 fact_clean = -1 N_mp_regen_low = -1 N_mp_regen =-1 N_mp_after_regen = -1 Dx_hist=-1 Nx_regen=-1 Ny_regen=-1
import dynamics_dipole as dyndip import dynamics_Boris_f2py as dynB import dynamics_strong_B_generalized as dyngen from numpy import array import MP_system as MPs from geom_impact_ellip import ellip_cham_geom_object Dt=25e-12; N_steps=10000 B=0.1 N_sub_steps=10 dynamicsd=dyndip.pusher_dipole_magnet(Dt,B) dynamicsB=dynB.pusher_Boris(Dt, 0., B, 0., \ None, None, None,N_sub_steps=N_sub_steps) chamb=ellip_cham_geom_object(.02, .02) N_mp_max = 1000 nel_mp_ref_0 = -1 fact_split = -1 fact_clean = -1 N_mp_regen_low = -1 N_mp_regen =-1 N_mp_after_regen = -1 Dx_hist=-1 Nx_regen=-1 Ny_regen=-1 Nvx_regen=-1 Nvy_regen =-1 Nvz_regen=-1 regen_hist_cut=-1
def read_input_files_and_init_components(pyecl_input_folder='./', **kwargs): b_par, x_aper, y_aper, B,\ gas_ion_flag, P_nTorr, sigma_ion_MBarn, Temp_K, unif_frac, E_init_ion,\ Emax, del_max, R0, E_th, sigmafit, mufit,\ Dt, t_end, lam_th, t_ion, N_mp_max,\ N_mp_regen, N_mp_after_regen, fact_split, fact_clean, nel_mp_ref_0,\ Nx_regen, Ny_regen, Nvx_regen, Nvy_regen, Nvz_regen,regen_hist_cut,\ N_mp_regen_low,\ Dt_sc, Dh_sc, t_sc_ON,Dx_hist,r_center, scrub_en_th,\ progress_path, logfile_path, flag_movie, flag_sc_movie,\ Dt_En_hist, Nbin_En_hist,En_hist_max, \ photoem_flag, inv_CDF_refl_photoem_file, k_pe_st, refl_frac, alimit, e_pe_sigma,\ e_pe_max,x0_refl, y0_refl, out_radius, \ switch_model, switch_no_increase_energy, thresh_low_energy, save_mp_state_time_file, \ init_unif_flag, Nel_init_unif, E_init_unif, x_max_init_unif, x_min_init_unif, y_max_init_unif, y_min_init_unif,\ chamb_type, filename_chm, flag_detailed_MP_info, flag_hist_impact_seg,\ track_method, B0x, B0y, B0z, B_map_file, Bz_map_file, N_sub_steps, fact_Bmap, B_zero_thrhld,\ N_mp_soft_regen, N_mp_after_soft_regen,\ flag_verbose_file, flag_verbose_stdout,\ flag_presence_sec_beams, sec_b_par_list, phem_resc_fac, dec_fac_secbeam_prof, el_density_probes, save_simulation_state_time_file,\ x_min_hist_det, x_max_hist_det, y_min_hist_det, y_max_hist_det, Dx_hist_det, dec_fact_out, stopfile, sparse_solver, B_multip, \ PyPICmode, filename_init_MP_state,\ init_unif_edens_flag, init_unif_edens, E_init_unif_edens,\ x_max_init_unif_edens, x_min_init_unif_edens, y_max_init_unif_edens, y_min_init_unif_edens, flag_assume_convex, E0,\ filen_main_outp = \ read_parameter_files(pyecl_input_folder) for attr in kwargs.keys(): print 'Ecloud init. From kwargs: %s = %s'%(attr, repr(kwargs[attr])) tmpattr = kwargs[attr] exec('%s=tmpattr'%attr) ########################################## pyeclsaver=pysav.pyecloud_saver(logfile_path) if switch_model=='ECLOUD_nunif': flag_non_unif_sey = 1 else: flag_non_unif_sey = 0 if chamb_type=='ellip': chamb=ellip_cham_geom_object(x_aper, y_aper, flag_verbose_file=flag_verbose_file) elif chamb_type=='polyg' or chamb_type=='polyg_cython': import geom_impact_poly_fast_impact as gipfi chamb=gipfi.polyg_cham_geom_object(filename_chm, flag_non_unif_sey, flag_verbose_file=flag_verbose_file, flag_verbose_stdout=flag_verbose_stdout, flag_assume_convex=flag_assume_convex) elif chamb_type=='polyg_numpy': raise ValueError("chamb_type='polyg_numpy' not supported anymore") #~ chamb=gip.polyg_cham_geom_object(filename_chm, flag_non_unif_sey, #~ flag_verbose_file=flag_verbose_file, flag_verbose_stdout=flag_verbose_stdout) elif chamb_type=='rect': import geom_impact_rect_fast_impact as girfi chamb = girfi.rect_cham_geom_object(x_aper, y_aper, flag_verbose_file=flag_verbose_file, flag_verbose_stdout=flag_verbose_stdout) else: raise ValueError('Chamber type not recognized (choose: ellip/rect/polyg)') MP_e=MPs.MP_system(N_mp_max, nel_mp_ref_0, fact_split, fact_clean, N_mp_regen_low, N_mp_regen, N_mp_after_regen, Dx_hist, Nx_regen, Ny_regen, Nvx_regen, Nvy_regen, Nvz_regen, regen_hist_cut, chamb, N_mp_soft_regen=N_mp_soft_regen, N_mp_after_soft_regen=N_mp_after_soft_regen) beamtim=beatim.beam_and_timing(b_par.flag_bunched_beam, b_par.fact_beam, b_par.coast_dens, b_par.beam_field_file,lam_th, b_spac=b_par.b_spac, sigmaz=b_par.sigmaz,t_offs=b_par.t_offs, filling_pattern_file=b_par.filling_pattern_file, Dt=Dt, t_end=t_end, beam_long_prof_file=b_par.beam_long_prof_file, Dh_beam_field=b_par.Dh_beam_field, chamb=chamb, sigmax=b_par.sigmax, sigmay=b_par.sigmay, x_beam_pos = b_par.x_beam_pos, y_beam_pos = b_par.y_beam_pos, save_beam_field_file_as=b_par.save_beam_field_file_as, Nx=b_par.Nx, Ny=b_par.Ny, nimag=b_par.nimag, progress_mapgen_file = (progress_path+'_mapgen')) if sparse_solver=='klu': print '''sparse_solver: 'klu' no longer supported --> going to PyKLU''' sparse_solver='PyKLU' spacech_ele = scc.space_charge(chamb, Dh_sc, Dt_sc=Dt_sc, sparse_solver=sparse_solver, PyPICmode=PyPICmode) sec_beams_list=[] if flag_presence_sec_beams: N_sec_beams = len(sec_b_par_list) for ii in xrange(N_sec_beams): print 'Initialize secondary beam %d/%d'%(ii+1, N_sec_beams) sb_par = sec_b_par_list[ii] sec_beams_list.append(beatim.beam_and_timing(sb_par.flag_bunched_beam, sb_par.fact_beam, sb_par.coast_dens, sb_par.beam_field_file,lam_th, b_spac=sb_par.b_spac, sigmaz=sb_par.sigmaz,t_offs=sb_par.t_offs, filling_pattern_file=sb_par.filling_pattern_file, Dt=Dt, t_end=t_end, beam_long_prof_file=sb_par.beam_long_prof_file, Dh_beam_field=sb_par.Dh_beam_field, chamb=chamb, sigmax=sb_par.sigmax, sigmay=sb_par.sigmay, x_beam_pos = sb_par.x_beam_pos, y_beam_pos = sb_par.y_beam_pos, save_beam_field_file_as=sb_par.save_beam_field_file_as, flag_secodary_beam = True, t_primary_beam = beamtim.t, Nx=sb_par.Nx, Ny=sb_par.Ny, nimag=sb_par.nimag, progress_mapgen_file = (progress_path+('_mapgen_sec_%d'%ii)))) if E0 is not None: kwargs = {'E0':E0} else: #If E0 is not provided use default value for each object kwargs = {} if switch_model==0 or switch_model=='ECLOUD': sey_mod=SEY_model_ECLOUD(Emax,del_max,R0,**kwargs) elif switch_model==1 or switch_model=='ACC_LOW': sey_mod=SEY_model_acc_low_ene(Emax,del_max,R0,**kwargs) elif switch_model=='ECLOUD_nunif': sey_mod=SEY_model_ECLOUD_non_unif(chamb, Emax,del_max,R0,**kwargs) elif switch_model=='cos_low_ene': sey_mod=SEY_model_cos_le(Emax,del_max,R0,**kwargs) elif switch_model=='flat_low_ene': sey_mod=SEY_model_flat_le(Emax,del_max,R0) flag_seg = (flag_hist_impact_seg==1) impact_man=imc.impact_management(switch_no_increase_energy, chamb, sey_mod, E_th, sigmafit, mufit, Dx_hist, scrub_en_th, Nbin_En_hist, En_hist_max, thresh_low_energy=thresh_low_energy, flag_seg=flag_seg) resgasion_sec_beam_list=[] if gas_ion_flag==1: resgasion=gic.residual_gas_ionization(unif_frac, P_nTorr, sigma_ion_MBarn,Temp_K,chamb,E_init_ion) else: resgasion=None if photoem_flag==1: phemiss=gpc.photoemission(inv_CDF_refl_photoem_file, k_pe_st, refl_frac, e_pe_sigma, e_pe_max,alimit, \ x0_refl, y0_refl, out_radius, chamb, phem_resc_fac) else: phemiss=None pyeclsaver.start_observing(MP_e, beamtim, impact_man, r_center, Dt_En_hist, logfile_path, progress_path, flag_detailed_MP_info=flag_detailed_MP_info, flag_movie=flag_movie, flag_sc_movie=flag_sc_movie, save_mp_state_time_file=save_mp_state_time_file, flag_presence_sec_beams=flag_presence_sec_beams, sec_beams_list=sec_beams_list, dec_fac_secbeam_prof=dec_fac_secbeam_prof, el_density_probes=el_density_probes, save_simulation_state_time_file = save_simulation_state_time_file, x_min_hist_det=x_min_hist_det, x_max_hist_det=x_max_hist_det, y_min_hist_det=y_min_hist_det, y_max_hist_det=y_max_hist_det, Dx_hist_det=Dx_hist_det, dec_fact_out=dec_fact_out, stopfile=stopfile, filen_main_outp=filen_main_outp) if track_method == 'Boris': dynamics=dynB.pusher_Boris(Dt, B0x, B0y, B0z, \ B_map_file, fact_Bmap, Bz_map_file,N_sub_steps=N_sub_steps) elif track_method == 'StrongBdip': dynamics=dyndip.pusher_dipole_magnet(Dt,B) elif track_method == 'StrongBgen': dynamics=dyngen.pusher_strong_B_generalized(Dt, B0x, B0y, \ B_map_file, fact_Bmap, B_zero_thrhld) elif track_method == 'BorisMultipole': import dynamics_Boris_multipole as dynmul dynamics=dynmul.pusher_Boris_multipole(Dt=Dt, N_sub_steps=N_sub_steps, B_multip = B_multip) else: raise ValueError("""track_method should be 'Boris' or 'StrongBdip' or 'StrongBgen' or 'BorisMultipole'""") if init_unif_flag==1: print "Adding inital %.2e electrons to the initial distribution"%Nel_init_unif MP_e.add_uniform_MP_distrib(Nel_init_unif, E_init_unif, x_max_init_unif, x_min_init_unif, y_max_init_unif, y_min_init_unif) if init_unif_edens_flag==1: print "Adding inital %.2e electrons/m^3 to the initial distribution"%init_unif_edens MP_e.add_uniform_ele_density(n_ele=init_unif_edens, E_init=E_init_unif_edens, x_max=x_max_init_unif_edens, x_min=x_min_init_unif_edens, y_max=y_max_init_unif_edens, y_min=y_min_init_unif_edens) if filename_init_MP_state!=-1 and filename_init_MP_state is not None: print "Adding inital electrons from: %s"%filename_init_MP_state MP_e.add_from_file(filename_init_MP_state) return beamtim,MP_e, dynamics,impact_man, pyeclsaver, \ gas_ion_flag, resgasion, t_ion, \ spacech_ele,t_sc_ON, photoem_flag, phemiss,\ flag_presence_sec_beams, sec_beams_list
def __init__(self, L_ecloud, slicer, Dt_ref, pyecl_input_folder='./'): print 'PyECLOUD for PyHEADTAIL' print 'Initializing ecloud from folder: '+pyecl_input_folder self.slicer = slicer self.Dt_ref = Dt_ref self.L_ecloud = L_ecloud b_par, x_aper, y_aper, B,\ gas_ion_flag, P_nTorr, sigma_ion_MBarn, Temp_K, unif_frac, E_init_ion,\ Emax, del_max, R0, E_th, sigmafit, mufit,\ Dt, t_end, lam_th, t_ion, N_mp_max,\ N_mp_regen, N_mp_after_regen, fact_split, fact_clean, nel_mp_ref_0,\ Nx_regen, Ny_regen, Nvx_regen, Nvy_regen, Nvz_regen,regen_hist_cut,\ N_mp_regen_low,\ Dt_sc, Dh_sc, t_sc_ON,Dx_hist,r_center, scrub_en_th,\ progress_path, logfile_path, flag_movie, flag_sc_movie,\ Dt_En_hist, Nbin_En_hist,En_hist_max, \ photoem_flag, inv_CDF_refl_photoem_file, k_pe_st, refl_frac, alimit, e_pe_sigma,\ e_pe_max,x0_refl, y0_refl, out_radius, \ switch_model, switch_no_increase_energy, thresh_low_energy, save_mp_state_time_file, \ init_unif_flag, Nel_init_unif, E_init_unif, x_max_init_unif, x_min_init_unif, y_max_init_unif, y_min_init_unif,\ chamb_type, filename_chm, flag_detailed_MP_info, flag_hist_impact_seg,\ track_method, B0x, B0y, B0z, B_map_file, Bz_map_file, N_sub_steps, fact_Bmap, B_zero_thrhld,\ N_mp_soft_regen, N_mp_after_soft_regen,\ flag_verbose_file, flag_verbose_stdout,\ flag_presence_sec_beams, sec_b_par_list, phem_resc_fac, dec_fac_secbeam_prof, el_density_probes, save_simulation_state_time_file,\ x_min_hist_det, x_max_hist_det, y_min_hist_det, y_max_hist_det, Dx_hist_det, dec_fact_out, stopfile= \ read_parameter_files_pyhdtl(pyecl_input_folder) #pyeclsaver=pysav.pyecloud_saver(logfile_path) if switch_model=='ECLOUD_nunif': flag_non_unif_sey = 1 else: flag_non_unif_sey = 0 if chamb_type=='ellip': chamb=ellip_cham_geom_object(x_aper, y_aper, flag_verbose_file=flag_verbose_file) elif chamb_type=='polyg': chamb=polyg_cham_geom_object(filename_chm, flag_non_unif_sey, flag_verbose_file=flag_verbose_file, flag_verbose_stdout=flag_verbose_stdout) else: raise ValueError('Chamber type not recognized (choose: ellip/polyg)') MP_e=MPs.MP_system(N_mp_max, nel_mp_ref_0, fact_split, fact_clean, N_mp_regen_low, N_mp_regen, N_mp_after_regen, Dx_hist, Nx_regen, Ny_regen, Nvx_regen, Nvy_regen, Nvz_regen, regen_hist_cut, chamb, N_mp_soft_regen=N_mp_soft_regen, N_mp_after_soft_regen=N_mp_after_soft_regen) spacech_ele = scc.space_charge(chamb, Dh_sc, Dt_sc=Dt_sc) #~ sec_beams_list=[] #~ if flag_presence_sec_beams: #~ N_sec_beams = len(sec_b_par_list) #~ for ii in xrange(N_sec_beams): #~ print 'Initialize secondary beam %d/%d'%(ii+1, N_sec_beams) #~ sb_par = sec_b_par_list[ii] #~ sec_beams_list.append(beatim.beam_and_timing(sb_par.flag_bunched_beam, sb_par.fact_beam, sb_par.coast_dens, sb_par.beam_field_file,lam_th, #~ b_spac=sb_par.b_spac, sigmaz=sb_par.sigmaz,t_offs=sb_par.t_offs, filling_pattern_file=sb_par.filling_pattern_file, Dt=Dt, t_end=t_end, #~ beam_long_prof_file=sb_par.beam_long_prof_file, Dh_beam_field=sb_par.Dh_beam_field, chamb=chamb, sigmax=sb_par.sigmax, sigmay=sb_par.sigmay, #~ x_beam_pos = sb_par.x_beam_pos, y_beam_pos = sb_par.y_beam_pos, save_beam_field_file_as=sb_par.save_beam_field_file_as, #~ flag_secodary_beam = True, t_primary_beam = beamtim.t, #~ Nx=sb_par.Nx, Ny=sb_par.Ny, nimag=sb_par.nimag, progress_mapgen_file = (progress_path+('_mapgen_sec_%d'%ii)))) if switch_model==0 or switch_model=='ECLOUD': sey_mod=SEY_model_ECLOUD(Emax,del_max,R0) elif switch_model==1 or switch_model=='ACC_LOW': sey_mod=SEY_model_acc_low_ene(Emax,del_max,R0) elif switch_model=='ECLOUD_nunif': sey_mod=SEY_model_ECLOUD_non_unif(chamb, Emax,del_max,R0) elif switch_model=='cos_low_ene': sey_mod=SEY_model_cos_le(Emax,del_max,R0) elif switch_model=='flat_low_ene': sey_mod=SEY_model_flat_le(Emax,del_max,R0) flag_seg = (flag_hist_impact_seg==1) impact_man=imc.impact_management(switch_no_increase_energy, chamb, sey_mod, E_th, sigmafit, mufit, Dx_hist, scrub_en_th, Nbin_En_hist, En_hist_max, thresh_low_energy=thresh_low_energy, flag_seg=flag_seg) if track_method == 'Boris': dynamics=dynB.pusher_Boris(Dt, B0x, B0y, B0z, \ B_map_file, fact_Bmap, Bz_map_file,N_sub_steps=N_sub_steps) #~ elif track_method == 'StrongBdip': #~ dynamics=dyndip.pusher_dipole_magnet(Dt,B) #~ elif track_method == 'StrongBgen': #~ dynamics=dyngen.pusher_strong_B_generalized(Dt, B0x, B0y, \ #~ B_map_file, fact_Bmap, B_zero_thrhld) else: raise ValueError("""track_method should be 'Boris' - others are not implemented in the PyHEADTAIL module""") if init_unif_flag==1: MP_e.add_uniform_MP_distrib(Nel_init_unif, E_init_unif, x_max_init_unif, x_min_init_unif, y_max_init_unif, y_min_init_unif) spacech_ele.flag_decimate = False self.MP_e = MP_e self.dynamics = dynamics self.impact_man = impact_man self.spacech_ele = spacech_ele self.save_ele_distributions_last_track = False self.save_ele_potential_and_field = False self.save_ele_MP_position = False self.save_ele_MP_velocity = False self.save_ele_MP_size = False self.init_x = self.MP_e.x_mp.copy() self.init_y = self.MP_e.y_mp.copy() self.init_z = self.MP_e.z_mp.copy() self.init_vx = self.MP_e.vx_mp.copy() self.init_vy = self.MP_e.vy_mp.copy() self.init_vz = self.MP_e.vz_mp.copy() self.init_nel = self.MP_e.nel_mp.copy() self.init_N_mp = self.MP_e.N_mp
import dynamics_dipole as dyndip import dynamics_Boris_f2py as dynB import dynamics_strong_B_generalized as dyngen from numpy import array import MP_system as MPs from geom_impact_ellip import ellip_cham_geom_object Dt = 25e-12 N_steps = 10000 B = 0.1 N_sub_steps = 10 dynamicsd = dyndip.pusher_dipole_magnet(Dt, B) dynamicsB=dynB.pusher_Boris(Dt, 0., B, 0., \ None, None, None,N_sub_steps=N_sub_steps) chamb = ellip_cham_geom_object(.02, .02) N_mp_max = 1000 nel_mp_ref_0 = -1 fact_split = -1 fact_clean = -1 N_mp_regen_low = -1 N_mp_regen = -1 N_mp_after_regen = -1 Dx_hist = -1 Nx_regen = -1 Ny_regen = -1 Nvx_regen = -1 Nvy_regen = -1 Nvz_regen = -1 regen_hist_cut = -1
def __init__(self, L_ecloud, slicer, Dt_ref, pyecl_input_folder='./', flag_clean_slices=False, slice_by_slice_mode=False, space_charge_obj=None, **kwargs): print 'PyECLOUD Version 5.5.3' print 'PyHEADTAIL module' print 'Initializing ecloud from folder: ' + pyecl_input_folder self.slicer = slicer self.Dt_ref = Dt_ref self.L_ecloud = L_ecloud self.pyecl_input_folder = pyecl_input_folder self.kwargs = kwargs b_par, x_aper, y_aper, B,\ gas_ion_flag, P_nTorr, sigma_ion_MBarn, Temp_K, unif_frac, E_init_ion,\ Emax, del_max, R0, E_th, sigmafit, mufit,\ Dt, t_end, lam_th, t_ion, N_mp_max,\ N_mp_regen, N_mp_after_regen, fact_split, fact_clean, nel_mp_ref_0,\ Nx_regen, Ny_regen, Nvx_regen, Nvy_regen, Nvz_regen,regen_hist_cut,\ N_mp_regen_low,\ Dt_sc, Dh_sc, t_sc_ON,Dx_hist,r_center, scrub_en_th,\ progress_path, logfile_path, flag_movie, flag_sc_movie,\ Dt_En_hist, Nbin_En_hist,En_hist_max, \ photoem_flag, inv_CDF_refl_photoem_file, k_pe_st, refl_frac, alimit, e_pe_sigma,\ e_pe_max,x0_refl, y0_refl, out_radius, \ switch_model, switch_no_increase_energy, thresh_low_energy, save_mp_state_time_file, \ init_unif_flag, Nel_init_unif, E_init_unif, x_max_init_unif, x_min_init_unif, y_max_init_unif, y_min_init_unif,\ chamb_type, filename_chm, flag_detailed_MP_info, flag_hist_impact_seg,\ track_method, B0x, B0y, B0z, B_map_file, Bz_map_file, N_sub_steps, fact_Bmap, B_zero_thrhld,\ N_mp_soft_regen, N_mp_after_soft_regen,\ flag_verbose_file, flag_verbose_stdout,\ flag_presence_sec_beams, sec_b_par_list, phem_resc_fac, dec_fac_secbeam_prof, el_density_probes, save_simulation_state_time_file,\ x_min_hist_det, x_max_hist_det, y_min_hist_det, y_max_hist_det, Dx_hist_det, dec_fact_out, stopfile, sparse_solver, B_multip,\ PyPICmode, filename_init_MP_state,\ init_unif_edens_flag, init_unif_edens, E_init_unif_edens,\ x_max_init_unif_edens, x_min_init_unif_edens, y_max_init_unif_edens, y_min_init_unif_edens, flag_assume_convex,\ f_telescope, target_grid, N_nodes_discard, N_min_Dh_main = \ read_parameter_files_pyhdtl(pyecl_input_folder) for attr in kwargs.keys(): print 'Ecloud init. From kwargs: %s = %s' % (attr, repr(kwargs[attr])) tmpattr = kwargs[attr] exec('%s=tmpattr' % attr) #pyeclsaver=pysav.pyecloud_saver(logfile_path) if switch_model == 'ECLOUD_nunif': flag_non_unif_sey = 1 else: flag_non_unif_sey = 0 if chamb_type == 'ellip': chamb = ellip_cham_geom_object(x_aper, y_aper, flag_verbose_file=flag_verbose_file) elif chamb_type == 'polyg' or chamb_type == 'polyg_cython': import geom_impact_poly_fast_impact as gipfi chamb = gipfi.polyg_cham_geom_object( filename_chm, flag_non_unif_sey, flag_verbose_file=flag_verbose_file, flag_verbose_stdout=flag_verbose_stdout, flag_assume_convex=flag_assume_convex) elif chamb_type == 'polyg_numpy': raise ValueError("chamb_type='polyg_numpy' not supported anymore") #~ chamb=gip.polyg_cham_geom_object(filename_chm, flag_non_unif_sey, #~ flag_verbose_file=flag_verbose_file, flag_verbose_stdout=flag_verbose_stdout) elif chamb_type == 'rect': import geom_impact_rect_fast_impact as girfi chamb = girfi.rect_cham_geom_object( x_aper, y_aper, flag_verbose_file=flag_verbose_file, flag_verbose_stdout=flag_verbose_stdout) else: raise ValueError( 'Chamber type not recognized (choose: ellip/rect/polyg)') MP_e = MPs.MP_system(N_mp_max, nel_mp_ref_0, fact_split, fact_clean, N_mp_regen_low, N_mp_regen, N_mp_after_regen, Dx_hist, Nx_regen, Ny_regen, Nvx_regen, Nvy_regen, Nvz_regen, regen_hist_cut, chamb, N_mp_soft_regen=N_mp_soft_regen, N_mp_after_soft_regen=N_mp_after_soft_regen) if sparse_solver == 'klu': print '''sparse_solver: 'klu' no longer supported --> going to PyKLU''' sparse_solver = 'PyKLU' if space_charge_obj is not None: spacech_ele = space_charge_obj else: spacech_ele = scc.space_charge(chamb, Dh_sc, Dt_sc=Dt_sc, sparse_solver=sparse_solver, PyPICmode=PyPICmode, f_telescope=f_telescope, target_grid=target_grid, N_nodes_discard=N_nodes_discard, N_min_Dh_main=N_min_Dh_main) if switch_model == 0 or switch_model == 'ECLOUD': sey_mod = SEY_model_ECLOUD(Emax, del_max, R0) elif switch_model == 1 or switch_model == 'ACC_LOW': sey_mod = SEY_model_acc_low_ene(Emax, del_max, R0) elif switch_model == 'ECLOUD_nunif': sey_mod = SEY_model_ECLOUD_non_unif(chamb, Emax, del_max, R0) elif switch_model == 'cos_low_ene': sey_mod = SEY_model_cos_le(Emax, del_max, R0) elif switch_model == 'flat_low_ene': sey_mod = SEY_model_flat_le(Emax, del_max, R0) flag_seg = (flag_hist_impact_seg == 1) impact_man = imc.impact_management(switch_no_increase_energy, chamb, sey_mod, E_th, sigmafit, mufit, Dx_hist, scrub_en_th, Nbin_En_hist, En_hist_max, thresh_low_energy=thresh_low_energy, flag_seg=flag_seg) if track_method == 'Boris': dynamics=dynB.pusher_Boris(Dt, B0x, B0y, B0z, \ B_map_file, fact_Bmap, Bz_map_file,N_sub_steps=N_sub_steps) #~ elif track_method == 'StrongBdip': #~ dynamics=dyndip.pusher_dipole_magnet(Dt,B) #~ elif track_method == 'StrongBgen': #~ dynamics=dyngen.pusher_strong_B_generalized(Dt, B0x, B0y, \ #~ B_map_file, fact_Bmap, B_zero_thrhld) elif track_method == 'BorisMultipole': import dynamics_Boris_multipole as dynmul dynamics = dynmul.pusher_Boris_multipole(Dt=Dt, N_sub_steps=N_sub_steps, B_multip=B_multip) else: raise ValueError( """track_method should be 'Boris' or 'BorisMultipole' - others are not implemented in the PyEC4PyHT module""" ) if init_unif_flag == 1: print "Adding inital %.2e electrons to the initial distribution" % Nel_init_unif MP_e.add_uniform_MP_distrib(Nel_init_unif, E_init_unif, x_max_init_unif, x_min_init_unif, y_max_init_unif, y_min_init_unif) if init_unif_edens_flag == 1: print "Adding inital %.2e electrons/m^3 to the initial distribution" % init_unif_edens MP_e.add_uniform_ele_density(n_ele=init_unif_edens, E_init=E_init_unif_edens, x_max=x_max_init_unif_edens, x_min=x_min_init_unif_edens, y_max=y_max_init_unif_edens, y_min=y_min_init_unif_edens) if filename_init_MP_state != -1 and filename_init_MP_state is not None: print "Adding inital electrons from: %s" % filename_init_MP_state MP_e.add_from_file(filename_init_MP_state) self.x_beam_offset = 0. self.y_beam_offset = 0. if 'x_beam_offset' in kwargs.keys(): self.x_beam_offset = kwargs['x_beam_offset'] if 'y_beam_offset' in kwargs.keys(): self.y_beam_offset = kwargs['y_beam_offset'] # initialize proton density probes self.save_ele_field_probes = False self.x_probes = -1 self.y_probes = -1 self.Ex_ele_last_track_at_probes = -1 self.Ey_ele_last_track_at_probes = -1 if 'probes_position' in kwargs.keys(): self.save_ele_field_probes = True self.probes_position = kwargs['probes_position'] self.N_probes = len(self.probes_position) self.x_probes = [] self.y_probes = [] for ii_probe in xrange(self.N_probes): self.x_probes.append(probes_position[ii_probe]['x']) self.y_probes.append(probes_position[ii_probe]['y']) self.x_probes = np.array(self.x_probes) self.y_probes = np.array(self.y_probes) self.N_tracks = 0 spacech_ele.flag_decimate = False self.MP_e = MP_e self.dynamics = dynamics self.impact_man = impact_man self.spacech_ele = spacech_ele self.save_ele_distributions_last_track = False self.save_ele_potential_and_field = False self.save_ele_potential = False self.save_ele_field = False self.save_ele_MP_position = False self.save_ele_MP_velocity = False self.save_ele_MP_size = False self.track_only_first_time = False self.init_x = self.MP_e.x_mp[:self.MP_e.N_mp].copy() self.init_y = self.MP_e.y_mp[:self.MP_e.N_mp].copy() self.init_z = self.MP_e.z_mp[:self.MP_e.N_mp].copy() self.init_vx = self.MP_e.vx_mp[:self.MP_e.N_mp].copy() self.init_vy = self.MP_e.vy_mp[:self.MP_e.N_mp].copy() self.init_vz = self.MP_e.vz_mp[:self.MP_e.N_mp].copy() self.init_nel = self.MP_e.nel_mp[:self.MP_e.N_mp].copy() self.init_N_mp = self.MP_e.N_mp self.flag_clean_slices = flag_clean_slices self.slice_by_slice_mode = slice_by_slice_mode if self.slice_by_slice_mode: self.track = self._track_in_single_slice_mode self.finalize_and_reinitialize = self._finalize_and_reinitialize