Exemplo n.º 1
0
######################################################

#BM_test=MagneticStructureBendingMagnet(Bo=0.8, div=5e-3, R=25.0)

E_1=7876.0

beam_test=ElectronBeam(Electron_energy=1.3, I_current=1.0)
beam_ESRF=ElectronBeam(Electron_energy=6.0, I_current=0.2)
und_test=Undulator(  K = 1.87,  period_length= 0.035, length=0.035 * 14)
ESRF18=Undulator( K = 1.68, period_length = 0.018, length=2.0)
ESRFBM=BM(Bo=0.8,horizontale_divergeance=0.005,electron_energy=6.0)



vx= 2e-4
vz= np.sqrt(beam_test.electron_speed()**2-vx**2)*codata.c

# initial_cond=np.array([ vx*codata.c,  0.00000000e+00 ,vz , 0.0 , 0.0 ,-0.42,])
#X=np.linspace(-0.02,0.02,150)
#Y=np.linspace(-0.02,0.02,150)
sim_test = create_simulation(magnetic_structure=und_test, electron_beam=beam_test, traj_method=TRAJECTORY_METHOD_ANALYTIC,
                            rad_method=RADIATION_METHOD_APPROX_FARFIELD, Nb_pts_trajectory=1000,distance=100)
sim_test.calculate_on_central_cone()
sim_test.change_energy_eV(E=2000)
#sim_test.change_harmonic_number(5.5)
#print(sim_test.source.choose_nb_pts_trajectory())
#print(sim_test.source.choose_distance_automatic())
#sim_test.print_parameters()


#sim_test.trajectory.plot_3D(title="Analytical electron trajectory in bending magnet")
Exemplo n.º 2
0
    def _buildForXY(self, electron_beam, x_0, y_0, xp_0, yp_0, z, X, Y):

        #TODO: X dimension equals Y dimension?
        Y = X

        beam = ElectronBeam(Electron_energy=electron_beam.energy(),
                            I_current=electron_beam.averageCurrent())
        undulator = Undulator(K=self._undulator.K_vertical(),
                              period_length=self._undulator.periodLength(),
                              length=self._undulator.length())

        initial_conditions = SourceUndulatorPlane(
            undulator=undulator, electron_beam=beam,
            magnetic_field=None).choose_initial_contidion_automatic()

        v_z = initial_conditions[2]

        initial_conditions[0] = xp_0 * speed_of_light
        initial_conditions[1] = yp_0 * speed_of_light
        initial_conditions[2] = np.sqrt(beam.electron_speed()**2 - xp_0**2 -
                                        yp_0**2) * speed_of_light
        initial_conditions[3] = x_0
        initial_conditions[4] = y_0

        if self._source_position == VIRTUAL_SOURCE_CENTER:
            initial_conditions[5] = 0.0
        print("initial cond:", initial_conditions)

        simulation = create_simulation(
            magnetic_structure=undulator,
            electron_beam=beam,
            traj_method=TRAJECTORY_METHOD_ODE,
            rad_method=RADIATION_METHOD_NEAR_FIELD,  #RADIATION_METHOD_FARFIELD,
            distance=z,
            X=X,
            Y=Y,
            photon_energy=self._photon_energy,
            initial_condition=initial_conditions)
        #simulation.trajectory.plot_3D()
        #simulation.trajectory.plot()
        #simulation.radiation.plot()

        electrical_field = simulation.radiation_fact.calculate_electrical_field(
            trajectory=simulation.trajectory,
            source=simulation.source,
            distance=simulation.radiation.distance,
            X_array=simulation.radiation.X,
            Y_array=simulation.radiation.Y)

        efield = electrical_field.electrical_field()[np.newaxis, :, :, :]
        efield = efield[:, :, :, 0:2]

        calc_wavefront = NumpyWavefront(
            e_field=efield,
            x_start=X.min(),
            x_end=X.max(),
            y_start=Y.min(),
            y_end=Y.max(),
            z=z,
            energies=np.array([self._photon_energy]),
        )

        #calc_wavefront.showEField()

        self._last_simulation = simulation
        self._last_initial_conditions = initial_conditions.copy()

        return calc_wavefront
Exemplo n.º 3
0
    def _buildForXY(self, electron_beam, x_0, y_0, xp_0, yp_0, z, X, Y):

        #TODO: X dimension equals Y dimension?
        Y = X

        beam = ElectronBeam(Electron_energy=electron_beam.energy(), I_current=electron_beam.averageCurrent())
        undulator = Undulator(K=self._undulator.K_vertical(),
                              period_length=self._undulator.periodLength(),
                              length=self._undulator.length())

        initial_conditions = SourceUndulatorPlane(undulator=undulator, electron_beam=beam, magnetic_field=None).choose_initial_contidion_automatic()

        v_z = initial_conditions[2]

        initial_conditions[0] = xp_0 * speed_of_light
        initial_conditions[1] = yp_0 * speed_of_light
        initial_conditions[2] = np.sqrt(beam.electron_speed()**2-xp_0**2-yp_0**2) * speed_of_light
        initial_conditions[3] = x_0
        initial_conditions[4] = y_0

        if self._source_position == VIRTUAL_SOURCE_CENTER:
            initial_conditions[5] = 0.0
        print("initial cond:", initial_conditions)

        simulation = create_simulation(magnetic_structure=undulator,
                                       electron_beam=beam,
                                       traj_method=TRAJECTORY_METHOD_ODE,
                                       rad_method=RADIATION_METHOD_NEAR_FIELD, #RADIATION_METHOD_FARFIELD,
                                       distance=z,
                                       X=X,
                                       Y=Y,
                                       photon_energy=self._photon_energy,
                                       initial_condition=initial_conditions)
        #simulation.trajectory.plot_3D()
        #simulation.trajectory.plot()
        #simulation.radiation.plot()

        electrical_field = simulation.radiation_fact.calculate_electrical_field(trajectory=simulation.trajectory,
                                                                                source=simulation.source,
                                                                                distance=simulation.radiation.distance,
                                                                                X_array=simulation.radiation.X,
                                                                                Y_array=simulation.radiation.Y)

        efield = electrical_field.electrical_field()[np.newaxis, :, :, :]
        efield = efield[:, :, :, 0:2]

        calc_wavefront = NumpyWavefront(e_field=efield,
                                        x_start=X.min(),
                                        x_end=X.max(),
                                        y_start=Y.min(),
                                        y_end=Y.max(),
                                        z=z,
                                        energies=np.array([self._photon_energy]),
                                        )

        #calc_wavefront.showEField()

        self._last_simulation = simulation
        self._last_initial_conditions = initial_conditions.copy()

        return calc_wavefront