示例#1
0
    def test_WrongTrackingFunction(self):
        with self.assertRaises(RuntimeError):
            SparseSlices(self.rf_station,
                         self.beam,
                         self.n_slices_rf,
                         self.filling_pattern,
                         tracker='something horribly wrong')

        nonuniform_profile = SparseSlices(self.rf_station, self.beam,
                                          self.n_slices_rf,
                                          self.filling_pattern)

        self.assertEqual(nonuniform_profile.bin_centers_array.shape,
                         (2, self.n_slices_rf),
                         msg='Wrong shape of bin_centers_array!')
示例#2
0
    def test_Ctracker(self):
        rtol = 1e-6  # relative tolerance
        atol = 0  # absolute tolerance

        nonuniform_profile = SparseSlices(self.rf_station,
                                          self.beam,
                                          self.n_slices_rf,
                                          self.filling_pattern,
                                          tracker='C',
                                          direct_slicing=True)

        for bunch in range(2):
            indexes = (self.uniform_profile.bin_centers>nonuniform_profile.cut_left_array[bunch])\
                * (self.uniform_profile.bin_centers<nonuniform_profile.cut_right_array[bunch])

            np.testing.assert_allclose(
                self.uniform_profile.bin_centers[indexes],
                nonuniform_profile.bin_centers_array[bunch],
                rtol=rtol,
                atol=atol,
                err_msg=f'Bins for bunch {bunch} do not agree ' +
                'for tracker="C"')

            np.testing.assert_allclose(
                self.uniform_profile.n_macroparticles[indexes],
                nonuniform_profile.n_macroparticles_array[bunch],
                rtol=rtol,
                atol=atol,
                err_msg=f'Profiles for bunch {bunch} do not agree ' +
                'for tracker="C"')
示例#3
0
                                   distribution_type=distribution_type,
                                   distribution_variable=distribution_variable,
                                   seed=134253)

indexes = np.arange(n_macroparticles)

for i in range(int(np.sum(filling_pattern))):
    beam.dt[indexes[int(i * len(beam.dt) //
                        np.sum(filling_pattern))]:indexes[int(
                            (i + 1) * len(beam.dt) // np.sum(filling_pattern) -
                            1)]] += (bucket_length *
                                     np.where(filling_pattern)[0][i])

import time

slice_beam = SparseSlices(RF_sct_par, beam, n_slices, filling_pattern)

t0 = time.time()
slice_beam.track()
print('Time for optimized C++ track ', time.time() - t0)
plt.figure()
for i in range(int(np.sum(filling_pattern))):
    plt.plot(slice_beam.profiles_list[i].bin_centers,
             slice_beam.profiles_list[i].n_macroparticles,
             'b',
             lw=2)

for i in range(int(np.sum(filling_pattern))):
    slice_beam.profiles_list[i].n_macroparticles *= 0

slice_beam = SparseSlices(RF_sct_par,
matched_from_distribution_function(beam, full_tracker, emittance=emittance,
                                   distribution_type=distribution_type, 
                                   distribution_variable=distribution_variable
                                   , seed=134253)

indexes = np.arange(n_macroparticles)

for i in range(int(np.sum(filling_pattern))):
    beam.dt[indexes[int(i*len(beam.dt)//np.sum(filling_pattern))]: 
        indexes[int((i+1)*len(beam.dt)//np.sum(filling_pattern)-1)]] += (
        bucket_length * np.where(filling_pattern)[0][i])

import time


slice_beam = SparseSlices(RF_sct_par, beam, n_slices, filling_pattern)

t0 = time.time()
slice_beam.track()
print( 'Time for optimized C++ track ', time.time() - t0 )
plt.figure()
for i in range(int(np.sum(filling_pattern))):
    plt.plot(slice_beam.slices_array[i].bin_centers,
             slice_beam.slices_array[i].n_macroparticles,'b',lw=2)



for i in range(int(np.sum(filling_pattern))):
    slice_beam.slices_array[i].n_macroparticles *= 0