|
| 1 | +# Example input for longitudinal simulation with phase loop (LHC) |
| 2 | +# No intensity effects |
| 3 | + |
| 4 | + |
| 5 | +import time |
| 6 | +import numpy as np |
| 7 | + |
| 8 | +from llrf.RF_noise import * |
| 9 | +from input_parameters.general_parameters import * |
| 10 | +from input_parameters.rf_parameters import * |
| 11 | +from trackers.longitudinal_tracker import * |
| 12 | +from llrf.feedbacks import * |
| 13 | +from beams.beams import * |
| 14 | +from beams.longitudinal_distributions import * |
| 15 | +from beams.slices import * |
| 16 | +from monitors.monitors import * |
| 17 | +from longitudinal_plots.plot_settings import * |
| 18 | +from longitudinal_plots.plot_beams import * |
| 19 | +from longitudinal_plots.plot_llrf import * |
| 20 | +from longitudinal_plots.plot_slices import * |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +# Simulation parameters -------------------------------------------------------- |
| 25 | +# Bunch parameters |
| 26 | +N_b = 1.e9 # Intensity |
| 27 | +N_p = 10001 # Macro-particles |
| 28 | +tau_0 = 0.4 # Initial bunch length, 4 sigma [ns] |
| 29 | + |
| 30 | +# Machine and RF parameters |
| 31 | +C = 26658.883 # Machine circumference [m] |
| 32 | +p_s = 450.e9 # Synchronous momentum [eV] |
| 33 | +h = 35640 # Harmonic number |
| 34 | +V = 6.e6 # RF voltage [eV] |
| 35 | +dphi = 0 # Phase modulation/offset |
| 36 | +gamma_t = 55.759505 # Transition gamma |
| 37 | +alpha = 1./gamma_t/gamma_t # First order mom. comp. factor |
| 38 | + |
| 39 | +# Tracking details |
| 40 | +N_t = 1001 # Number of turns to track |
| 41 | +dt_plt = 200 # Time steps between plots |
| 42 | +dt_mon = 1 # Time steps between monitoring |
| 43 | + |
| 44 | + |
| 45 | +# Simulation setup ------------------------------------------------------------- |
| 46 | +print "Setting up the simulation..." |
| 47 | +print "" |
| 48 | + |
| 49 | +# Define general parameters |
| 50 | +general_params = GeneralParameters(N_t, C, alpha, p_s, 'proton') |
| 51 | + |
| 52 | +# Define RF station parameters, phase loop, and corresponding tracker |
| 53 | +RF_params = RFSectionParameters(general_params, 1, h, V, dphi) |
| 54 | +PL_gain = 1./(5.*general_params.t_rev[0]) |
| 55 | +print "PL gain is %.4e 1/s, Trev = %.4e s" %(PL_gain, general_params.t_rev[0]) |
| 56 | +PL = PhaseLoop(general_params, RF_params, PL_gain, sampling_frequency = 1, |
| 57 | + machine = 'LHC') |
| 58 | +long_tracker = RingAndRFSection(RF_params, PhaseLoop=PL) |
| 59 | + |
| 60 | +print "General and RF parameters set..." |
| 61 | + |
| 62 | + |
| 63 | +# Define beam and distribution |
| 64 | +beam = Beam(general_params, N_p, N_b) |
| 65 | +# Generate new distribution |
| 66 | +longitudinal_bigaussian(general_params, RF_params, beam, tau_0/4, seed=1234, |
| 67 | + xunit = 'ns', reinsertion = 'on') |
| 68 | +print "Beam set and distribution generated..." |
| 69 | + |
| 70 | + |
| 71 | +# Need slices for the Gaussian fit; slice for the first plot |
| 72 | +slice_beam = Slices(beam, 100, slicing_coord = 'theta')#, #fit_option = 'gaussian', |
| 73 | + #slice_immediately = 'on') |
| 74 | + |
| 75 | +# Define what to save in file |
| 76 | +bunchmonitor = BunchMonitor('output_data', N_t+1, "Longitudinal", PhaseLoop=PL)#slice_beam, PL) |
| 77 | + |
| 78 | +print "Statistics set..." |
| 79 | + |
| 80 | +# Initialize plots |
| 81 | +PlotSettings().set_plot_format() |
| 82 | + |
| 83 | +# Accelerator map |
| 84 | +map_ = [slice_beam] + [bunchmonitor] +[long_tracker] |
| 85 | +print "Map set" |
| 86 | +print "" |
| 87 | + |
| 88 | + |
| 89 | +# Initial injection kick/error |
| 90 | +beam.theta += 1.e-5 |
| 91 | +#beam.dE *= -1. |
| 92 | +bunchmonitor.track(beam) |
| 93 | +slice_beam.track(beam) |
| 94 | + |
| 95 | + |
| 96 | +# Tracking --------------------------------------------------------------------- |
| 97 | +for i in range(N_t): |
| 98 | + t0 = time.clock() |
| 99 | + |
| 100 | + |
| 101 | + # Plot has to be done before tracking (at least for cases with separatrix) |
| 102 | + if (i % dt_plt) == 0: |
| 103 | + print "Outputting at time step %d..." %i |
| 104 | + print " Beam momentum %.6e eV" %beam.momentum |
| 105 | + print " Beam gamma %3.3f" %beam.gamma_r |
| 106 | + print " Beam beta %3.3f" %beam.beta_r |
| 107 | + print " Beam energy %.6e eV" %beam.energy |
| 108 | + print " Four-times r.m.s. bunch length %.4e rad" %(4.*beam.sigma_theta) |
| 109 | + #print " Gaussian bunch length %.4e rad" %beam.bl_gauss |
| 110 | + print "" |
| 111 | + # In plots, you can choose following units: rad, ns, m |
| 112 | + plot_long_phase_space(beam, general_params, RF_params, 0, 0.0001763, |
| 113 | + -450, 450, separatrix_plot = True) |
| 114 | + plot_beam_profile(i, general_params, slice_beam) |
| 115 | + plot_COM_motion(beam, general_params, RF_params, 'output_data', |
| 116 | + 0.8e-4, 1.1e-4, -75, 75, separatrix_plot = False) |
| 117 | + |
| 118 | + |
| 119 | + # Track |
| 120 | + slice_beam.track(beam) |
| 121 | + #slice_beam.mean_theta = beam.theta[0] # For single particle |
| 122 | + long_tracker.track(beam) |
| 123 | + bunchmonitor.track(beam) |
| 124 | + |
| 125 | + # These plots have to be done after the tracking |
| 126 | + if (i % dt_plt) == 0 and i > dt_mon: |
| 127 | + plot_bunch_length_evol(beam, 'output_data', general_params, i, |
| 128 | + output_freq=dt_mon, unit='ns') |
| 129 | + #plot_bunch_length_evol_gaussian(beam, 'output_data', general_params, |
| 130 | + # slice_beam, i, output_freq=dt_mon, unit='ns') |
| 131 | + plot_position_evol(beam, 'output_data', general_params, i, |
| 132 | + output_freq=dt_mon, unit = None, style = '.') |
| 133 | + plot_PL_phase_corr(PL, 'output_data', i, output_freq=dt_mon) |
| 134 | + plot_PL_freq_corr(PL, 'output_data', i, output_freq=dt_mon) |
| 135 | + |
| 136 | + |
| 137 | + # Define losses according to separatrix and/or longitudinal position |
| 138 | + #beam.losses_separatrix(general_params, rf_params) |
| 139 | + #beam.losses_longitudinal_cut(0.28e-4, 0.75e-4) |
| 140 | + |
| 141 | + |
| 142 | +bunchmonitor.h5file.close() |
| 143 | +print "Done!" |
| 144 | +print "" |
| 145 | + |
0 commit comments