Esempio n. 1
0
    def test_default_wake_length(self):
        test_object= InducedVoltageTime(
                None, self.profile, [self.impedance_source])

        np.testing.assert_allclose(
                test_object.wake_length,
                self.profile.bin_size * self.profile.n_slices)
Esempio n. 2
0
    def setUp(self):
        C = 2*np.pi*1100.009        # Ring circumference [m]
        gamma_t = 18.0              # Gamma at transition
        alpha = 1/gamma_t**2        # Momentum compaction factor
        p_s = 25.92e9               # Synchronous momentum at injection [eV]
        h = 4620                    # 200 MHz system harmonic
        phi = 0.                    # 200 MHz RF phase

        # With this setting, amplitude in the two four-section, five-section
        # cavities must converge, respectively, to
        # 2.0 MV = 4.5 MV * 4/18 * 2
        # 2.5 MV = 4.5 MV * 5/18 * 2
        V = 4.5e6                   # 200 MHz RF voltage

        N_t = 1                     # Number of turns to track

        self.ring = Ring(C, alpha, p_s, Particle=Proton(), n_turns=N_t)
        self.rf = RFStation(self.ring, h, V, phi)

        N_m = 1e6                   # Number of macro-particles for tracking
        N_b = 72*1.0e11             # Bunch intensity [ppb]

        # Gaussian beam profile
        self.beam = Beam(self.ring, N_m, N_b)
        sigma = 1.0e-9
        bigaussian(self.ring, self.rf, self.beam, sigma, seed=1234,
                   reinsertion=False)

        n_shift = 1550  # how many rf-buckets to shift beam
        self.beam.dt += n_shift * self.rf.t_rf[0, 0]

        self.profile = Profile(
            self.beam, CutOptions=CutOptions(
                cut_left=(n_shift-1.5)*self.rf.t_rf[0, 0],
                cut_right=(n_shift+2.5)*self.rf.t_rf[0, 0],
                n_slices=4*64))
        self.profile.track()

        # Cavities
        l_cav = 43*0.374
        v_g = 0.0946
        tau = l_cav/(v_g*c)*(1 + v_g)
        f_cav = 200.222e6
        n_cav = 2   # factor 2 because of two four/five-sections cavities
        short_cavity = TravelingWaveCavity(l_cav**2 * n_cav * 27.1e3 / 8,
                                           f_cav, 2*np.pi*tau)
        shortInducedVoltage = InducedVoltageTime(self.beam, self.profile,
                                                 [short_cavity])
        l_cav = 54*0.374
        tau = l_cav/(v_g*c)*(1 + v_g)
        long_cavity = TravelingWaveCavity(l_cav**2 * n_cav * 27.1e3 / 8, f_cav,
                                          2*np.pi*tau)
        longInducedVoltage = InducedVoltageTime(self.beam, self.profile,
                                                [long_cavity])
        self.induced_voltage = TotalInducedVoltage(
            self.beam, self.profile, [shortInducedVoltage, longInducedVoltage])
        self.induced_voltage.induced_voltage_sum()

        self.cavity_tracker = RingAndRFTracker(
            self.rf, self.beam, Profile=self.profile, interpolation=True,
            TotalInducedVoltage=self.induced_voltage)

        self.OTFB = SPSCavityFeedback(
            self.rf, self.beam, self.profile, G_llrf=5, G_tx=0.5, a_comb=15/16,
            turns=50, Commissioning=CavityFeedbackCommissioning())

        self.OTFB_tracker = RingAndRFTracker(self.rf, self.beam,
                                             Profile=self.profile,
                                             TotalInducedVoltage=None,
                                             CavityFeedback=self.OTFB,
                                             interpolation=True)
Esempio n. 3
0
# INDUCED VOLTAGE FROM IMPEDANCE-----------------------------------------------

imp_list = [resonator]

ind_volt_freq = InducedVoltageFreq(beam,
                                   slice_beam,
                                   imp_list,
                                   RFParams=RF_sct_par,
                                   frequency_resolution=1e3,
                                   multi_turn_wake=True,
                                   mtw_mode='time')

ind_volt_time = InducedVoltageTime(beam,
                                   slice_beam,
                                   imp_list,
                                   RFParams=RF_sct_par,
                                   wake_length=n_turns * bucket_length,
                                   multi_turn_wake=True)

ind_volt_freq_periodic = InducedVoltageFreq(beam, slice_beam, imp_list)

total_ind_volt_freq = TotalInducedVoltage(beam, slice_beam, [ind_volt_freq])

total_ind_volt_time = TotalInducedVoltage(beam, slice_beam, [ind_volt_time])

total_ind_volt_freq_periodic = TotalInducedVoltage(beam, slice_beam,
                                                   [ind_volt_freq_periodic])

# ACCELERATION MAP-------------------------------------------------------------

map_ = [total_ind_volt_freq] + [total_ind_volt_time]
ZoN = InductiveImpedance(beam, slice_beam, [100]*n_turns, RF_sct_par) 

R_S = 5e4
frequency_R = 10e6
Q = 1e2

resonator = Resonators(R_S, frequency_R, Q)

# INDUCED VOLTAGE FROM IMPEDANCE-----------------------------------------------

imp_list = [resonator]

ind_volt_freq = InducedVoltageFreq(beam, slice_beam, imp_list,
                    frequency_resolution=1e4)

ind_volt_time = InducedVoltageTime(beam, slice_beam, imp_list)

total_ind_volt_freq = TotalInducedVoltage(beam, slice_beam, [ind_volt_freq])

total_ind_volt_time = TotalInducedVoltage(beam, slice_beam, [ind_volt_time])

total_ind_volt_ZoN = TotalInducedVoltage(beam, slice_beam, [ZoN])

# PLOTS 

# ACCELERATION MAP-------------------------------------------------------------

map_ = [slice_beam] + [total_ind_volt_freq] + [total_ind_volt_time] + \
       [total_ind_volt_ZoN] + [ring_RF_section]

# TRACKING + PLOTS-------------------------------------------------------------
                                this_directory +
                                '../output_files/EX_05_output_data_res',
                                Profile=slice_beam_res,
                                buffer_time=1)

# LOAD IMPEDANCE TABLE--------------------------------------------------------

table = np.loadtxt(this_directory + '../input_files/EX_05_new_HQ_table.dat',
                   comments='!')

R_shunt = table[:, 2] * 10**6
f_res = table[:, 0] * 10**9
Q_factor = table[:, 1]
resonator = Resonators(R_shunt, f_res, Q_factor)

ind_volt_time = InducedVoltageTime(my_beam, slice_beam, [resonator])
ind_volt_freq = InducedVoltageFreq(my_beam_freq, slice_beam_freq, [resonator],
                                   1e5)
ind_volt_res = InducedVoltageResonator(my_beam_res, slice_beam_res, resonator)

tot_vol = TotalInducedVoltage(my_beam, slice_beam, [ind_volt_time])
tot_vol_freq = TotalInducedVoltage(my_beam_freq, slice_beam_freq,
                                   [ind_volt_freq])
tot_vol_res = TotalInducedVoltage(my_beam_res, slice_beam_res, [ind_volt_res])

# Analytic result-----------------------------------------------------------
VindGauss = np.zeros(len(slice_beam.bin_centers))
for r in range(len(Q_factor)):
    # Notice that the time-argument of inducedVoltageGauss is shifted by
    # mean(my_slices.bin_centers), because the analytical equation assumes the
    # Gauss to be centered at t=0, but the line density is centered at
Esempio n. 6
0
    def test_vind(self):

        # randomly chose omega_c from allowed range
        np.random.seed(1980)
        factor = np.random.uniform(0.9, 1.1)

        # round results to this digits
        digit_round = 8

        # SPS parameters
        C = 2 * np.pi * 1100.009  # Ring circumference [m]
        gamma_t = 18.0  # Gamma at transition
        alpha = 1 / gamma_t**2  # Momentum compaction factor
        p_s = 25.92e9  # Synchronous momentum at injection [eV]
        h = 4620  # 200 MHz system harmonic
        V = 4.5e6  # 200 MHz RF voltage
        phi = 0.  # 200 MHz RF phase

        # Beam and tracking parameters
        N_m = 1e5  # Number of macro-particles for tracking
        N_b = 1.0e11  # Bunch intensity [ppb]
        N_t = 1  # Number of turns to track

        ring = Ring(C, alpha, p_s, Proton(), n_turns=N_t)
        rf = RFStation(ring, h, V, phi)
        beam = Beam(ring, N_m, N_b)
        bigaussian(ring, rf, beam, 3.2e-9 / 4, seed=1234, reinsertion=True)

        n_shift = 5  # how many rf-buckets to shift beam
        beam.dt += n_shift * rf.t_rf[0, 0]
        profile = Profile(beam,
                          CutOptions=CutOptions(
                              cut_left=(n_shift - 1.5) * rf.t_rf[0, 0],
                              cut_right=(n_shift + 1.5) * rf.t_rf[0, 0],
                              n_slices=140))
        profile.track()

        l_cav = 16.082
        v_g = 0.0946
        tau = l_cav / (v_g * c) * (1 + v_g)
        TWC_impedance_source = TravelingWaveCavity(l_cav**2 * 27.1e3 / 8,
                                                   200.222e6, 2 * np.pi * tau)

        # Beam loading by convolution of beam and wake from cavity
        inducedVoltageTWC = InducedVoltageTime(beam, profile,
                                               [TWC_impedance_source])
        induced_voltage = TotalInducedVoltage(beam, profile,
                                              [inducedVoltageTWC])
        induced_voltage.induced_voltage_sum()
        V_ind_impSource = np.around(induced_voltage.induced_voltage,
                                    digit_round)

        # Beam loading via feed-back system
        OTFB_4 = SPSOneTurnFeedback(rf, beam, profile, 4, n_cavities=1)
        OTFB_4.counter = 0  # First turn

        OTFB_4.omega_c = factor * OTFB_4.TWC.omega_r
        # Compute impulse response
        OTFB_4.TWC.impulse_response_beam(OTFB_4.omega_c, profile.bin_centers)

        # Compute induced voltage in (I,Q) coordinates
        OTFB_4.beam_induced_voltage(lpf=False)
        # convert back to time
        V_ind_OTFB \
            = OTFB_4.V_fine_ind_beam.real \
                * np.cos(OTFB_4.omega_c*profile.bin_centers) \
            + OTFB_4.V_fine_ind_beam.imag \
                * np.sin(OTFB_4.omega_c*profile.bin_centers)
        V_ind_OTFB = np.around(V_ind_OTFB, digit_round)

        self.assertListEqual(
            V_ind_impSource.tolist(),
            V_ind_OTFB.tolist(),
            msg="In TravelingWaveCavity test_vind: induced voltages differ")
Esempio n. 7
0
    V_ind_beam = OTFB_3.V_fine_ind_beam +OTFB_4.V_fine_ind_beam + OTFB_5.V_fine_ind_beam
    plt.figure()
    convtime = np.linspace(-1e-9, -1e-9+len(V_ind_beam.real)*
                           profile.bin_size, len(V_ind_beam.real))
    plt.plot(convtime, V_ind_beam.real, 'b--')
    plt.plot(convtime[:140], V_ind_beam.real[:140], 'b', label='Re(Vind), OTFB')
    plt.plot(convtime, V_ind_beam.imag, 'r--')
    plt.plot(convtime[:140], V_ind_beam.imag[:140], 'r', label='Im(Vind), OTFB')
    plt.plot(convtime[:140], V_ind_beam.real[:140]*np.cos(OTFB_4.omega_c*convtime[:140]) \
             + V_ind_beam.imag[:140]*np.sin(OTFB_4.omega_c*convtime[:140]), 
             color='purple', label='Total, OTFB')

    # Comparison with impedances: FREQUENCY DOMAIN
    TWC200_4 = TravelingWaveCavity(0.876e6, 200.222e6, 3.899e-6)
    TWC200_5 = TravelingWaveCavity(1.38e6, 200.222e6, 4.897e-6)
    indVoltageTWC = InducedVoltageTime(beam, profile, [TWC200_4, TWC200_4, TWC200_5, TWC200_5])
    indVoltage = TotalInducedVoltage(beam, profile, [indVoltageTWC])
    indVoltage.induced_voltage_sum()
    plt.plot(indVoltage.time_array, indVoltage.induced_voltage, color='limegreen', label='Time domain w FFT')
    
    # Comparison with impedances: TIME DOMAIN
    TWC200_4.wake_calc(profile.bin_centers - profile.bin_centers[0])
    TWC200_5.wake_calc(profile.bin_centers - profile.bin_centers[0])
    wake1 = 2*(TWC200_4.wake + TWC200_5.wake)
    Vind = -profile.Beam.ratio*profile.Beam.Particle.charge*e*\
        np.convolve(wake1, profile.n_macroparticles, mode='full')[:140]
    plt.plot(convtime[:140], Vind, color='teal', label='Time domain w conv')
    
    # Wake from impulse response
    OTFB_4.TWC.impulse_response_gen(omega_c, profile.bin_centers)
    OTFB_5.TWC.impulse_response_gen(omega_c, profile.bin_centers)
Esempio n. 8
0
# Impedance model
R_shunt = 1e6
f_res = 915e6
Q_factor = 5000
resonator = Resonators(R_shunt, f_res, Q_factor)

# Set up of induced voltage

# Dictionary for compressed wake calculation
compression_dict = {}
compression_dict['n_window'] = int(2 * n_slices_per_bucket)
compression_dict['n_spacing'] = int(bunch_spacing * n_slices_per_bucket)

# Induced voltage with compressed convolution
ind_volt_time_compressed = InducedVoltageTime(
    beam, profile, [resonator], compression_dict=compression_dict)
tot_ind_volt_compressed = TotalInducedVoltage(beam, profile,
                                              [ind_volt_time_compressed])
profile.track()

# Performance test
n_test = 50
exec_time_c = np.zeros(n_test)
for k in range(n_test):
    t0 = time.perf_counter()
    tot_ind_volt_compressed.induced_voltage_sum()
    t1 = time.perf_counter()
    exec_time_c[k] = t1 - t0
print(
    f'Compressed convolution: mean {np.mean(exec_time_c):1.3e} s, std {np.std(exec_time_c):1.3e} s'
)
Esempio n. 9
0
 def test_wake_length_input(self):
     test_object= InducedVoltageTime(
             None, self.profile, [self.impedance_source],
             wake_length=11e-9)
     
     np.testing.assert_allclose(test_object.wake_length_input, 11e-9)
Esempio n. 10
0
    def test_default_n_rfft(self):
        test_object= InducedVoltageTime(
                None, self.profile, [self.impedance_source])

        np.testing.assert_equal(test_object.n_fft, 2*16)
Esempio n. 11
0
    def test_default_frequency_resolution(self):
        test_object= InducedVoltageTime(
                None, self.profile, [self.impedance_source])

        np.testing.assert_allclose(test_object.frequency_resolution,
               1/(self.profile.bin_size * 2*test_object.n_induced_voltage))