Пример #1
0
    def test_affect_only_dE(self):
        atol = 0
        rtol = 1e-7

        # incoherent synchrotron radiation, no displacement of beam
        iSR = SynchrotronRadiation(self.ring,
                                   self.rf_station,
                                   self.beam,
                                   self.R_bend,
                                   seed=self.seed,
                                   n_kicks=1,
                                   shift_beam=False,
                                   python=True,
                                   quantum_excitation=False)
        iSR.track()
        np.testing.assert_allclose([np.mean(self.beam.dt)],
                                   [1.0010434293297664e-09],
                                   atol=atol,
                                   rtol=rtol,
                                   err_msg='SR affected mean beam.dt')
        np.testing.assert_allclose([np.std(self.beam.dt)],
                                   [9.956848503354043e-12],
                                   atol=atol,
                                   rtol=rtol,
                                   err_msg='SR affected std beam.dt')
Пример #2
0
    def test_synchrotron_radiation_python_vs_C_double_kick(self):
        atol = 0
        rtol = 1e-7

        iSR = SynchrotronRadiation(self.ring, self.rf_station, self.beam, self.R_bend,
                                   n_kicks=2, shift_beam=False,
                                   python=True, quantum_excitation=False, seed=self.seed)
        iSR.track()  # Python implementation

        beam_C = Beam(self.ring, self.n_macroparticles, self.intensity)
        bigaussian(self.ring, self.rf_station, beam_C,
                   self.sigma_dt, seed=self.seed)

        iSR = SynchrotronRadiation(self.ring, self.rf_station, beam_C, self.R_bend,
                                   n_kicks=2, shift_beam=False,
                                   python=False, quantum_excitation=False, seed=self.seed)
        iSR.track()  # C implementation


        np.testing.assert_allclose([np.mean(self.beam.dE)], [np.mean(beam_C.dE)],
                                   atol=atol, rtol=rtol,
                                   err_msg='Python anc C yield different avg beam.dE for two kicks')
        np.testing.assert_allclose([np.std(self.beam.dE)], [np.std(beam_C.dE)],
                                   atol=atol, rtol=rtol,
                                   err_msg='Python anc C yield different std beam.dE for two kicks')
Пример #3
0
    def test_U0(self):

        # LEP, values from S. Lee 2nd ed., table 4.2
        circumference = 26658.9  # [m]
        energy = 55e9  # [eV]
        R_bend = 3096.2  # bending radius [m]
        alpha = 1e-3  # dummy value

        ring = Ring(circumference,
                    alpha,
                    energy,
                    Positron(),
                    synchronous_data_type='total energy',
                    n_turns=1)

        rf_station_dummy = RFStation(ring, 42, 1e6, 0, n_rf=1)

        iSR = SynchrotronRadiation(ring,
                                   rf_station_dummy,
                                   None,
                                   R_bend,
                                   shift_beam=False,
                                   quantum_excitation=False)

        self.assertEqual(int(iSR.U0 / 1e6), 261, msg="Wrong U0")
Пример #4
0
    def test_with_quant_exc_100t_parallel(self):
        os.environ['OMP_NUM_THREADS'] = '2'
        turns = 100
        atol = 0
        rtol_avg = 1e-2
        rtol_std = 1e-1
        SR = []
        SR_cpp = []

        for i in range(self.n_sections):
            SR.append(
                SynchrotronRadiation(self.general_params,
                                     self.RF_sct_par[i],
                                     self.beam,
                                     self.rho,
                                     quantum_excitation=True,
                                     python=True))

            SR_cpp.append(
                SynchrotronRadiation(self.general_params,
                                     self.RF_sct_par_cpp[i],
                                     self.beam_cpp,
                                     self.rho,
                                     quantum_excitation=True,
                                     python=False))
        map_ = []
        for i in range(self.n_sections):
            map_ += [self.longitudinal_tracker[i]] + [SR[i]]
        map_ += [self.slice_beam]

        map_cpp = []
        for i in range(self.n_sections):
            map_cpp += [self.longitudinal_tracker_cpp[i]] + [SR_cpp[i]]
        map_cpp += [self.slice_beam_cpp]

        avg_dt = np.zeros(turns)
        std_dt = np.zeros(turns)
        avg_dE = np.zeros(turns)
        std_dE = np.zeros(turns)

        avg_dt_cpp = np.zeros(turns)
        std_dt_cpp = np.zeros(turns)
        avg_dE_cpp = np.zeros(turns)
        std_dE_cpp = np.zeros(turns)

        for i in range(turns):
            for m in map_:
                m.track()
            for m in map_cpp:
                m.track()
            avg_dt[i] = np.mean(self.beam.dt)
            std_dt[i] = np.std(self.beam.dt)
            avg_dE[i] = np.mean(self.beam.dE)
            std_dE[i] = np.std(self.beam.dE)

            avg_dt_cpp[i] = np.mean(self.beam_cpp.dt)
            std_dt_cpp[i] = np.std(self.beam_cpp.dt)
            avg_dE_cpp[i] = np.mean(self.beam_cpp.dE)
            std_dE_cpp[i] = np.std(self.beam_cpp.dE)

        np.testing.assert_allclose(
            avg_dt,
            avg_dt_cpp,
            atol=atol,
            rtol=rtol_avg,
            err_msg="Pyhton and C++ avg beam dt arrays not close")
        np.testing.assert_allclose(
            std_dt,
            std_dt_cpp,
            atol=atol,
            rtol=rtol_std,
            err_msg="Pyhton and C++ std beam dt arrays not close")

        np.testing.assert_allclose(
            avg_dE,
            avg_dE_cpp,
            atol=atol,
            rtol=rtol_avg,
            err_msg="Pyhton and C++ avg beam dE arrays not close")
        np.testing.assert_allclose(
            std_dE,
            std_dE_cpp,
            atol=atol,
            rtol=rtol_std,
            err_msg="Pyhton and C++ std beam dE arrays not close")
Пример #5
0
                                   full_tracker,
                                   emittance=emittance,
                                   distribution_type=distribution_type,
                                   distribution_variable=distribution_variable,
                                   seed=1000)

slice_beam.track()

# Synchrotron radiation objects without quantum excitation
rho = 11e3
SR = []
for i in range(n_sections):
    SR.append(
        SynchrotronRadiation(general_params,
                             RF_sct_par[i],
                             beam,
                             rho,
                             quantum_excitation=False,
                             python=True))

SR[0].print_SR_params()

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

map_ = []
for i in range(n_sections):
    map_ += [longitudinal_tracker[i]] + [SR[i]]
map_ += [slice_beam]

# TRACKING + PLOTS-------------------------------------------------------------

avg_dt = np.zeros(n_turns)