def test_create_trajectory(self): # test le trajectoire ana lytic (des valeurs special # le Beta doit est constant pour certaine methode # les produi scalaire de l'acc avec la vitesse est ... # difference max entre deux trajectoire K = 1.87 lambda_u = 0.035 L = 0.035 * 14 E = 1.3 I = 1.0 undulator = Undulator(K=K, period_length=lambda_u, length=L) beam = ElectronBeam(Electron_energy=E, I_current=I) source = SourceUndulatorPlane(undulator=undulator, electron_beam=beam) fact_test = TrajectoryFactory(Nb_pts=201, method=TRAJECTORY_METHOD_ODE) traj_test = fact_test.create_from_source(source=source) self.assertFalse(fact_test.initial_condition is None) self.assertTrue( all(fact_test.initial_condition == source.choose_initial_contidion_automatic())) self.assertTrue(fact_test.method == TRAJECTORY_METHOD_ODE) scalar_product = traj_test.v_x * traj_test.a_x + traj_test.a_z * traj_test.v_z self.assertAlmostEqual(np.abs(scalar_product).max(), 0.0, 3)
def Example_list(): from pySRU.ElectronBeam import ElectronBeam beam_ESRF = ElectronBeam(Electron_energy=6.0, I_current=0.2) ESRF18 = Undulator(K=1.68, period_length=0.018, length=2.0) X = np.linspace(0.0, 0.0002, 1001) Y = np.linspace(0.0, 0.0002, 1001) simulation_test = create_simulation(magnetic_structure=ESRF18, electron_beam=beam_ESRF, X=X, Y=Y, XY_are_list=True) simulation_test.print_parameters() simulation_test.trajectory.plot_3D() simulation_test.radiation.plot() simulation_test.calculate_on_ring_number(ring_number_max=2) simulation_test.radiation.plot() simulation_test.radiation.plot_ring() observation_angle = np.linspace( 0.0, simulation_test.source.angle_ring_number(1, 2), 51) # TODO verifier quelle marche bien simulation_test.calculate_for_observation_angles( XY_are_list=True, observation_angle=observation_angle) simulation_test.radiation.plot()
def test_magn_field(self): 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.) self.create_magn_field_undulator_test( magnetic_structure=und_test, electron_beam=beam_test, method_traj=TRAJECTORY_METHOD_ODE) print("und_test, ok") self.create_magn_field_undulator_test( magnetic_structure=ESRF18, electron_beam=beam_ESRF, method_traj=TRAJECTORY_METHOD_ODE) print("esrf18, ok")
def Example_meshgrid(): from pySRU.ElectronBeam import ElectronBeam print( "======================================================================" ) print( "====== Undulator U18 from ESRF with K=1.68 =======" ) print( "======================================================================" ) beam_ESRF = ElectronBeam(Electron_energy=6.0, I_current=0.2) ESRF18 = Undulator(K=1.68, period_length=0.018, length=2.0) # # radiation in a defined meah # print('create radiation a given screen (40mm x 40mm @ 100 m )') X = np.linspace(-0.02, 0.02, 101) Y = np.linspace(-0.02, 0.02, 101) distance = 100.0 simulation_test = create_simulation( magnetic_structure=ESRF18, electron_beam=beam_ESRF, magnetic_field=None, photon_energy=None, traj_method=TRAJECTORY_METHOD_ANALYTIC, Nb_pts_trajectory=None, rad_method=RADIATION_METHOD_APPROX_FARFIELD, Nb_pts_radiation=101, initial_condition=None, distance=distance, XY_are_list=False, X=X, Y=Y) simulation_test.print_parameters() simulation_test.trajectory.plot_2D() simulation_test.radiation.plot( title=" radiation in a defined screen (40mm x 40mm @ 100 m )") # # up to a maximum X and Y # print('create simulation for a given maximum X and Y ') simulation_test = create_simulation( magnetic_structure=ESRF18, electron_beam=beam_ESRF, traj_method=TRAJECTORY_METHOD_ANALYTIC, rad_method=RADIATION_METHOD_APPROX_FARFIELD, distance=100, X=0.01, Y=0.01) simulation_test.radiation.plot( title='simulation for a maximum X=0.01 and Y=0.01')
def Example_minimum(): from pySRU.ElectronBeam import ElectronBeam print( "======================================================================" ) print( "====== Undulator from X-ray data booklet =======" ) print( "====== fig 2.5 in http://xdb.lbl.gov/Section2/Sec_2-1.html =======" ) print( "======================================================================" ) # note that the flux in the reference fig 2.6 is a factor 10 smaller than the calculated here. # This factor comes from the units: # here: phot / s / A / 0.1%bw / (mrad)^2 # ref : phot / s / A / 1%bw / (0.1 mrad)^2 undulator_test = Undulator(K=1.87, period_length=0.035, length=0.035 * 14) electron_beam_test = ElectronBeam(Electron_energy=1.3, I_current=1.0) simulation_test = create_simulation( magnetic_structure=undulator_test, electron_beam=electron_beam_test, magnetic_field=None, photon_energy=None, traj_method=TRAJECTORY_METHOD_ANALYTIC, Nb_pts_trajectory=None, rad_method=RADIATION_METHOD_APPROX_FARFIELD, Nb_pts_radiation=101, initial_condition=None, distance=None, XY_are_list=False, X=None, Y=None) simulation_test.print_parameters() simulation_test.trajectory.plot_3D(title="Electron Trajectory") simulation_test.radiation.plot(title="Flux in far field vs angle") # second calculation, change distance and also change the grid to accept the central cone simulation_test.change_distance(D=100) simulation_test.calculate_on_central_cone() simulation_test.radiation.plot(title="New distance: %3.1f m" % simulation_test.radiation.distance)
def test_create_radiation_undulator(self): undulator_test = Undulator(K=1.87, period_length=0.035, length=0.035 * 14) electron_beam_test = ElectronBeam(Electron_energy=1.3, I_current=1.0) source_test = SourceUndulatorPlane(undulator=undulator_test, electron_beam=electron_beam_test) traj_fact = TrajectoryFactory(Nb_pts=1001, method=TRAJECTORY_METHOD_ANALYTIC) traj = traj_fact.create_from_source(source_test) rad_fact = RadiationFactory( photon_frequency=source_test.harmonic_frequency(1), method=RADIATION_METHOD_NEAR_FIELD) rad = rad_fact.create_for_one_relativistic_electron(trajectory=traj, source=source_test) self.assertFalse(rad.X is None) self.assertFalse(rad.Y is None) self.assertFalse(rad.distance is None) rad_fact.method = RADIATION_METHOD_APPROX_FARFIELD rad2 = rad_fact.create_for_one_relativistic_electron( trajectory=traj, source=source_test) self.assertTrue(rad2.distance == None) rad2 = rad_fact.create_for_one_relativistic_electron( trajectory=traj, source=source_test, distance=rad.distance) self.assertFalse(rad.distance == None) err = rad.difference_with(rad2) self.assertTrue(rad.XY_are_similar_to(rad2)) self.assertTrue(rad.XY_are_similar_to(err)) self.assertTrue(rad.distance == rad2.distance) self.assertTrue(err.distance == rad2.distance) self.assertGreaterEqual(err.intensity.min(), 0.0) self.assertLessEqual(err.max(), rad.max() * 1e-1) # srio changed 1e-3 by 1e-1 traj_test2 = TrajectoryFactory( Nb_pts=1001, method=TRAJECTORY_METHOD_ODE, initial_condition=traj_fact.initial_condition).create_from_source( source_test) rad3 = rad_fact.create_for_one_relativistic_electron( trajectory=traj_test2, source=source_test, distance=rad.distance) err = rad2.difference_with(rad3) self.assertLessEqual(err.max(), rad2.max() * 1e-3)
def Example_spectrum_on_central_cone(): from pySRU.ElectronBeam import ElectronBeam print( "======================================================================" ) print( "====== Undulator U18 from ESRF with K=1.68 =======" ) print( "======================================================================" ) beam_ESRF = ElectronBeam(Electron_energy=6.0, I_current=0.2) ESRF18 = Undulator(K=1.68, period_length=0.018, length=2.0) simulation_test = create_simulation( magnetic_structure=ESRF18, electron_beam=beam_ESRF, magnetic_field=None, photon_energy=None, traj_method=TRAJECTORY_METHOD_ANALYTIC, Nb_pts_trajectory=None, rad_method=RADIATION_METHOD_APPROX_FARFIELD, Nb_pts_radiation=101, initial_condition=None, distance=None, XY_are_list=False, X=np.array([0]), Y=np.array([0])) harmonic_number = 1 x, y = simulation_test.calculate_spectrum_central_cone( harmonic_number=harmonic_number, theoretical_value=True, abscissas_array=None, use_eV=1) # dump file filename = "spectrum.spec" f = open(filename, 'w') f.write("#F %s\n\n#S 1 undulator flux using pySRU\n" % filename) f.write( "#N 2\n#L Photon energy [eV] Flux on central cone for harmonic %d [phot/s/0.1bw]\n" % harmonic_number) for i, xi in enumerate(x): f.write("%f %g\n" % (xi, y[i])) f.close() print("File written to disk: %s" % filename)
def Exemple_FARFIELD(): from pySRU.MagneticStructureUndulatorPlane import MagneticStructureUndulatorPlane as Undulator from pySRU.ElectronBeam import ElectronBeam from pySRU.SourceUndulatorPlane import SourceUndulatorPlane from pySRU.TrajectoryFactory import TrajectoryFactory,TRAJECTORY_METHOD_ODE,TRAJECTORY_METHOD_ANALYTIC import time undulator_test = Undulator(K=1.87, period_length=0.035, length=0.035 * 14) electron_beam_test = ElectronBeam(Electron_energy=1.3, I_current=1.0) magnetic_field_test = undulator_test.create_magnetic_field() magnetic_field_test.plot_z(0,0,np.linspace(-0.035 * (14+8) / 2,0.035 * (14+8) / 2,500)) source_test = SourceUndulatorPlane(undulator=undulator_test, electron_beam=electron_beam_test, magnetic_field=magnetic_field_test) traj = TrajectoryFactory(Nb_pts=2000, method=TRAJECTORY_METHOD_ODE).create_from_source(source_test) t0 = time.time() Rad = RadiationFactory(photon_frequency=source_test.harmonic_frequency(1), method=RADIATION_METHOD_APPROX_FARFIELD, Nb_pts=101 ).create_for_one_relativistic_electron(trajectory=traj, source=source_test) print("Elapsed time in RadiationFactory: ",time.time()-t0) print('Screen distance :') print(Rad.distance) print("screen shape ") print(Rad.intensity.shape) print('X max :') print(Rad.X.max()) print('Y max :') print(Rad.Y.max()) print('intensity max ()') print(Rad.max()) print('plot') Rad.plot(title="FAR FIELD")
def Example_spectrum_on_axis(): from pySRU.ElectronBeam import ElectronBeam print( "======================================================================" ) print( "====== Undulator U18 from ESRF with K=1.68 =======" ) print( "======================================================================" ) beam_ESRF = ElectronBeam(Electron_energy=6.0, I_current=0.2) ESRF18 = Undulator(K=1.68, period_length=0.018, length=2.0) # note that distance=None is important to get results in angles and therefore flux in ph/s/0.1%bw/mrad2 simulation_test = create_simulation( magnetic_structure=ESRF18, electron_beam=beam_ESRF, magnetic_field=None, photon_energy=None, traj_method=TRAJECTORY_METHOD_ANALYTIC, Nb_pts_trajectory=None, rad_method=RADIATION_METHOD_APPROX_FARFIELD, Nb_pts_radiation=101, initial_condition=None, distance=None, XY_are_list=False, X=np.array([0]), Y=np.array([0])) x, y = simulation_test.calculate_spectrum_on_axis(use_eV=1, do_plot=1) # dump file filename = "spectrum.spec" f = open(filename, 'w') f.write("#F %s\n\n#S 1 undulator flux using pySRU\n" % filename) f.write( "#N 2\n#L Photon energy [eV] Flux on axis [phot/s/0.1%bw/mrad2]\n") for i in range(x.size): f.write("%f %g\n" % (x[i], y[i])) f.close() print("File written to disk: %s" % filename)
def test_copy(self): K = 1.87 lambda_u = 0.035 L = 0.035 * 14 E = 1.3 I = 1.0 undulator = Undulator(K=K, period_length=lambda_u, length=L) beam = ElectronBeam(Electron_energy=E, I_current=I) source = SourceUndulatorPlane(undulator=undulator, electron_beam=beam) source2 = source.copy() source2.electron_beam.I_current = 0.3 self.assertEqual(source.I_current(), 1.0) self.assertEqual(source2.I_current(), 0.3) self.assertAlmostEqual( source.harmonic_frequency(1) / 1e17, 2.5346701615509917, 5) self.assertAlmostEqual(source.Lorentz_factor(), 2544.0367765521196, 2) self.assertAlmostEqual(source.electron_speed(), 0.99999992274559524, 5) self.assertEqual(source.magnetic_structure.period_number(), 14) self.assertAlmostEqual(source.choose_distance_automatic(2), 49.000000000000, 10)
def Example_meshgrid_on_central_cone_and_rings(): from pySRU.ElectronBeam import ElectronBeam print( "======================================================================" ) print( "====== Undulator U18 from ESRF with K=1.68 =======" ) print( "======================================================================" ) beam_ESRF = ElectronBeam(Electron_energy=6.0, I_current=0.2) ESRF18 = Undulator(K=1.68, period_length=0.018, length=2.0) # # radiation in a defined mesh with only one point to save time # distance = None simulation_test = create_simulation( magnetic_structure=ESRF18, electron_beam=beam_ESRF, magnetic_field=None, photon_energy=None, traj_method=TRAJECTORY_METHOD_ANALYTIC, Nb_pts_trajectory=None, rad_method=RADIATION_METHOD_APPROX_FARFIELD, Nb_pts_radiation=101, initial_condition=None, distance=distance, XY_are_list=False, X=np.array([0]), Y=np.array([0])) # # central cone # harmonic_number = 1 print( 'create radiation in a screen including central cone for harmonic %d' % harmonic_number) simulation_test.calculate_on_central_cone(harmonic_number=harmonic_number, npoints_x=50, npoints_y=50) simulation_test.print_parameters() simulation_test.radiation.plot(title=( "radiation in a screen including central cone, harmonic %d,at D=" + repr(distance)) % harmonic_number) # # up to a given ring # harmonic_number = 1 ring_number = 1 print('create radiation a given screen including ring %d for harmonic %d' % (ring_number, harmonic_number)) simulation_test.calculate_until_ring_number( harmonic_number=harmonic_number, ring_number=ring_number, XY_are_list=False, npoints=51) simulation_test.print_parameters() simulation_test.radiation.plot( title=" radiation in a screen containing harmonic %d up to ring %d ring" % (harmonic_number, ring_number))
def test_main(self): 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(E=6.0e9, Bo=0.8, div=5e-3, R=25.0, I=0.2) self.simul_undulator_theoric( magnetic_struc=und_test, electron_beam=beam_test, method_rad=RADIATION_METHOD_APPROX_FARFIELD, method_traj=TRAJECTORY_METHOD_ODE) print("Intensity ok") print(' undulator test ') self.simul_undulator_near_to_farfield( magnetic_struc=und_test, electron_beam=beam_test, method_traj=TRAJECTORY_METHOD_ANALYTIC) print("TRAJECTORY_METHOD_ANALYTIC ok") self.simul_undulator_near_to_farfield( magnetic_struc=und_test, electron_beam=beam_test, method_traj=TRAJECTORY_METHOD_ODE) print("TRAJECTORY_METHOD_ODE ok") self.simul_undulator_traj_method( magnetic_struc=und_test, electron_beam=beam_test, method_rad=RADIATION_METHOD_APPROX_FARFIELD) print('APPROX FARFIELD ok') self.simul_undulator_traj_method( magnetic_struc=und_test, electron_beam=beam_test, method_rad=RADIATION_METHOD_NEAR_FIELD) print('NEAR FIELD ok') print(' ') print('undulator ESRF18') self.simul_undulator_near_to_farfield( magnetic_struc=ESRF18, electron_beam=beam_ESRF, method_traj=TRAJECTORY_METHOD_ANALYTIC) print("TRAJECTORY_METHOD_ANALYTIC ok") self.simul_undulator_near_to_farfield( magnetic_struc=ESRF18, electron_beam=beam_ESRF, method_traj=TRAJECTORY_METHOD_ODE) print("TRAJECTORY_METHOD_ODE ok") #TODO marche pas ? self.simul_undulator_traj_method( magnetic_struc=ESRF18, electron_beam=beam_ESRF, method_rad=RADIATION_METHOD_APPROX_FARFIELD) print('APPROX FARFIELD ok') self.simul_undulator_traj_method( magnetic_struc=ESRF18, electron_beam=beam_ESRF, method_rad=RADIATION_METHOD_NEAR_FIELD) print('NEAR FIELD ok')
def main(mode_wavefront_before_lens): lens_diameter = 0.002 # 0.001 # 0.002 if mode_wavefront_before_lens == 'Undulator with lens': npixels_x = 512 else: npixels_x = int(2048*1.5) pixelsize_x = lens_diameter / npixels_x print("pixelsize: ",pixelsize_x) pixelsize_y = pixelsize_x npixels_y = npixels_x wavelength = 1.24e-10 propagation_distance = 30.0 defocus_factor = 1.0 # 1.0 is at focus propagation_steps = 1 # for Gaussian source sigma_x = lens_diameter / 400 # 5e-6 sigma_y = sigma_x # 5e-6 # for Hermite-Gauss, the H and V mode index (start from 0) hm = 3 hn = 1 # # initialize wavefronts of dimension equal to the lens # wf_fft = Wavefront2D.initialize_wavefront_from_range(x_min=-pixelsize_x*npixels_x/2,x_max=pixelsize_x*npixels_x/2, y_min=-pixelsize_y*npixels_y/2,y_max=pixelsize_y*npixels_y/2, number_of_points=(npixels_x,npixels_y),wavelength=wavelength) wf_convolution = Wavefront2D.initialize_wavefront_from_range(x_min=-pixelsize_x*npixels_x/2,x_max=pixelsize_x*npixels_x/2, y_min=-pixelsize_y*npixels_y/2,y_max=pixelsize_y*npixels_y/2, number_of_points=(npixels_x,npixels_y),wavelength=wavelength) if SRWLIB_AVAILABLE: wf_srw = Wavefront2D.initialize_wavefront_from_range(x_min=-pixelsize_x*npixels_x/2,x_max=pixelsize_x*npixels_x/2, y_min=-pixelsize_y*npixels_y/2,y_max=pixelsize_y*npixels_y/2, number_of_points=(npixels_x,npixels_y),wavelength=wavelength) # # calculate/define wavefront at zero distance downstream the lens # if mode_wavefront_before_lens == 'convergent spherical': # no need to propagate nor define lens wf_fft.set_spherical_wave(complex_amplitude=1.0,radius=-propagation_distance) wf_convolution.set_spherical_wave(complex_amplitude=1.0,radius=-propagation_distance) if SRWLIB_AVAILABLE: wf_srw.set_spherical_wave(complex_amplitude=1.0,radius=-propagation_distance) elif mode_wavefront_before_lens == 'divergent spherical with lens': # define wavefront at zero distance upstream the lens and apply lens focal_length = propagation_distance / 2. wf_fft.set_spherical_wave(complex_amplitude=1.0,radius=propagation_distance) wf_fft.apply_ideal_lens(focal_length,focal_length) wf_convolution.set_spherical_wave(complex_amplitude=1.0,radius=propagation_distance) wf_convolution.apply_ideal_lens(focal_length,focal_length) if SRWLIB_AVAILABLE: wf_srw.set_spherical_wave(complex_amplitude=1.0,radius=propagation_distance) wf_srw.apply_ideal_lens(focal_length,focal_length) elif mode_wavefront_before_lens == 'plane with lens': # define wavefront at zero distance upstream the lens and apply lens focal_length = propagation_distance wf_fft.set_plane_wave_from_complex_amplitude(1.0+0j) wf_fft.apply_ideal_lens(focal_length,focal_length) wf_convolution.set_plane_wave_from_complex_amplitude(1.0+0j) wf_convolution.apply_ideal_lens(focal_length,focal_length) if SRWLIB_AVAILABLE: wf_srw.set_plane_wave_from_complex_amplitude(1.0+0j) wf_srw.apply_ideal_lens(focal_length,focal_length) elif mode_wavefront_before_lens == 'Gaussian with lens': # define wavefront at source point, propagate to the lens and apply lens X = wf_fft.get_mesh_x() Y = wf_fft.get_mesh_y() intensity = numpy.exp( - X**2/(2*sigma_x**2)) * numpy.exp( - Y**2/(2*sigma_y**2)) wf_fft.set_complex_amplitude( numpy.sqrt(intensity) ) wf_convolution.set_complex_amplitude( numpy.sqrt(intensity) ) if SRWLIB_AVAILABLE: wf_srw.set_complex_amplitude( numpy.sqrt(intensity) ) # plot plot_image(wf_fft.get_intensity(),1e6*wf_fft.get_coordinate_x(),1e6*wf_fft.get_coordinate_y(), xtitle="X um (%d pixels)"%(wf_fft.size()[0]),ytitle="Y um (%d pixels)"%(wf_fft.size()[1]),title="Gaussian source",show=1) wf_fft, tmp1, tmp2 = propagation_to_image(wf_fft,method='fft',propagation_distance=propagation_distance, do_plot=0,plot_title="Before lens") wf_convolution, tmp1, tmp2 = propagation_to_image(wf_convolution,method='convolution',propagation_distance=propagation_distance, do_plot=0,plot_title="Before lens") if SRWLIB_AVAILABLE: wf_srw, tmp1, tmp2 = propagation_to_image(wf_srw,method='srw',propagation_distance=propagation_distance, do_plot=0,plot_title="Before lens") plot_image(wf_fft.get_intensity(),1e6*wf_fft.get_coordinate_x(),1e6*wf_fft.get_coordinate_y(), xtitle="X um (%d pixels)"%(wf_fft.size()[0]),ytitle="Y um",title="Before lens fft",show=1) plot_image(wf_convolution.get_intensity(),1e6*wf_fft.get_coordinate_x(),1e6*wf_fft.get_coordinate_y(), xtitle="X um (%d pixels)"%(wf_convolution.size()[0]),ytitle="Y um",title="Before lens convolution",show=1) focal_length = propagation_distance / 2 wf_fft.apply_ideal_lens(focal_length,focal_length) wf_convolution.apply_ideal_lens(focal_length,focal_length) if SRWLIB_AVAILABLE: wf_srw.apply_ideal_lens(focal_length,focal_length) elif mode_wavefront_before_lens == 'Hermite with lens': # define wavefront at source point, propagate to the lens and apply lens X = wf_fft.get_mesh_x() Y = wf_fft.get_mesh_y() efield = (hermite(hm)(numpy.sqrt(2)*X/sigma_x)*numpy.exp(-X**2/sigma_x**2))**2 \ * (hermite(hn)(numpy.sqrt(2)*Y/sigma_y)*numpy.exp(-Y**2/sigma_y**2))**2 wf_fft.set_complex_amplitude( efield ) wf_convolution.set_complex_amplitude( efield ) if SRWLIB_AVAILABLE: wf_srw.set_complex_amplitude( efield ) # plot plot_image(wf_fft.get_intensity(),1e6*wf_fft.get_coordinate_x(),1e6*wf_fft.get_coordinate_y(), xtitle="X um (%d pixels)"%(wf_fft.size()[0]),ytitle="Y um (%d pixels)"%(wf_fft.size()[0]),title="Hermite-Gauss source",show=1) wf_fft, tmp1, tmp2 = propagation_to_image(wf_fft,method='fft',propagation_distance=propagation_distance, do_plot=0,plot_title="Before lens") wf_convolution, tmp1, tmp2 = propagation_to_image(wf_convolution,method='convolution',propagation_distance=propagation_distance, do_plot=0,plot_title="Before lens") if SRWLIB_AVAILABLE: wf_srw, tmp1, tmp2 = propagation_to_image(wf_srw,method='srw',propagation_distance=propagation_distance, do_plot=0,plot_title="Before lens") plot_image(wf_fft.get_intensity(),1e6*wf_fft.get_coordinate_x(),1e6*wf_fft.get_coordinate_y(), xtitle="X um (%d pixels)"%(wf_fft.size()[0]),ytitle="Y um (%d pixels)"%(wf_fft.size()[0]),title="Before lens fft",show=1) plot_image(wf_convolution.get_intensity(),1e6*wf_fft.get_coordinate_x(),1e6*wf_fft.get_coordinate_y(), xtitle="X um (%d pixels)"%(wf_fft.size()[0]),ytitle="Y um (%d pixels)"%(wf_fft.size()[0]),title="Before lens convolution",show=1) focal_length = propagation_distance / 2 wf_fft.apply_ideal_lens(focal_length,focal_length) wf_convolution.apply_ideal_lens(focal_length,focal_length) if SRWLIB_AVAILABLE: wf_srw.apply_ideal_lens(focal_length,focal_length) elif mode_wavefront_before_lens == 'Undulator with lens': beamline = {} beamline['ElectronCurrent'] = 0.2 beamline['ElectronEnergy'] = 6.0 beamline['Kv'] = 1.68 # 1.87 beamline['NPeriods'] = 111 # 14 beamline['PeriodID'] = 0.018 # 0.035 beamline['distance'] = propagation_distance gamma = beamline['ElectronEnergy'] / (codata_mee * 1e-3) print ("Gamma: %f \n"%(gamma)) resonance_wavelength = (1 + beamline['Kv']**2 / 2.0) / 2 / gamma**2 * beamline["PeriodID"] resonance_energy = m2ev / resonance_wavelength print ("Resonance wavelength [A]: %g \n"%(1e10*resonance_wavelength)) print ("Resonance energy [eV]: %g \n"%(resonance_energy)) # red shift 100 eV resonance_energy = resonance_energy - 100 myBeam = ElectronBeam(Electron_energy=beamline['ElectronEnergy'], I_current=beamline['ElectronCurrent']) myUndulator = MagneticStructureUndulatorPlane(K=beamline['Kv'], period_length=beamline['PeriodID'], length=beamline['PeriodID']*beamline['NPeriods']) XX = wf_fft.get_mesh_x() YY = wf_fft.get_mesh_y() X = wf_fft.get_coordinate_x() Y = wf_fft.get_coordinate_y() source = SourceUndulatorPlane(undulator=myUndulator, electron_beam=myBeam, magnetic_field=None) omega = resonance_energy * codata.e / codata.hbar Nb_pts_trajectory = int(source.choose_nb_pts_trajectory(0.01,photon_frequency=omega)) print("Number of trajectory points: ",Nb_pts_trajectory) traj_fact = TrajectoryFactory(Nb_pts=Nb_pts_trajectory,method=TRAJECTORY_METHOD_ODE, initial_condition=None) print("Number of trajectory points: ",traj_fact.Nb_pts) if (traj_fact.initial_condition == None): traj_fact.initial_condition = source.choose_initial_contidion_automatic() print("Number of trajectory points: ",traj_fact.Nb_pts,traj_fact.initial_condition) #print('step 2') rad_fact = RadiationFactory(method=RADIATION_METHOD_NEAR_FIELD, photon_frequency=omega) #print('step 3') trajectory = traj_fact.create_from_source(source=source) #print('step 4') radiation = rad_fact.create_for_one_relativistic_electron(trajectory=trajectory, source=source, XY_are_list=False,distance=beamline['distance'], X=X, Y=Y) efield = rad_fact.calculate_electrical_field(trajectory=trajectory,source=source, distance=beamline['distance'],X_array=XX,Y_array=YY) tmp = efield.electrical_field()[:,:,0] wf_fft.set_photon_energy(resonance_energy) wf_convolution.set_photon_energy(resonance_energy) if SRWLIB_AVAILABLE: wf_srw.set_photon_energy(resonance_energy) wf_fft.set_complex_amplitude( tmp ) wf_convolution.set_complex_amplitude( numpy.sqrt(tmp) ) if SRWLIB_AVAILABLE: wf_srw.set_complex_amplitude( numpy.sqrt(tmp) ) # plot plot_image(wf_fft.get_intensity(),1e6*wf_fft.get_coordinate_x(),1e6*wf_fft.get_coordinate_y(), xtitle="X um (%d pixels)"%(wf_fft.size()[0]),ytitle="Y um (%d pixels)"%(wf_fft.size()[0]),title="UND source at lens plane",show=1) # apply lens focal_length = propagation_distance / 2 wf_fft.apply_ideal_lens(focal_length,focal_length) wf_convolution.apply_ideal_lens(focal_length,focal_length) if SRWLIB_AVAILABLE: wf_srw.apply_ideal_lens(focal_length,focal_length) else: raise Exception("Unknown mode") plot_image(wf_fft.get_phase(),1e6*wf_fft.get_coordinate_x(),1e6*wf_fft.get_coordinate_y(), title="Phase just after the lens",xtitle="X um (%d pixels)"%(wf_fft.size()[0]),ytitle="Y um (%d pixels)"%(wf_fft.size()[0]),show=1) wf_fft, x_fft, y_fft = propagation_to_image(wf_fft,do_plot=0,method='fft', propagation_steps=propagation_steps, propagation_distance = propagation_distance, defocus_factor=defocus_factor) wf_convolution, x_convolution, y_convolution = propagation_to_image(wf_convolution,do_plot=0,method='convolution', propagation_steps=propagation_steps, propagation_distance = propagation_distance, defocus_factor=defocus_factor) if SRWLIB_AVAILABLE: wf_srw, x_srw, y_srw = propagation_to_image(wf_srw,do_plot=0,method='srw', propagation_steps=propagation_steps, propagation_distance = propagation_distance, defocus_factor=defocus_factor) plot_image(wf_fft.get_intensity(),1e6*wf_fft.get_coordinate_x(),1e6*wf_fft.get_coordinate_y(), title="Intensity at image plane",xtitle="X um (%d pixels)"%(wf_fft.size()[0]),ytitle="Y um (%d pixels)"%(wf_fft.size()[0]),show=1) if do_plot: if SRWLIB_AVAILABLE: x = x_fft y = numpy.vstack((y_fft,y_srw,y_convolution)) plot_table(1e6*x,y,legend=["fft","srw","convolution"],ytitle="Intensity",xtitle="x coordinate [um]", title="Comparison 1:1 focusing "+mode_wavefront_before_lens) else: x = x_fft y = numpy.vstack((y_fft,y_convolution)) plot_table(1e6*x,y,legend=["fft","convolution"],ytitle="Intensity",xtitle="x coordinate [um]", title="Comparison 1:1 focusing "+mode_wavefront_before_lens)
return simulation_test if __name__ == "__main__": from srxraylib.plot.gol import set_qt set_qt() print("======================================================================") print("====== Undulator U18 from ESRF with K=1.68 =======") print("======================================================================") beam_ALSU = ElectronBeam(Electron_energy=2.0, I_current=0.5) # ESRF18 = Undulator(K=1.68, period_length=0.018, length=2.0) id = Undulator(K=2.0, period_length=0.4, length=1.6) # # radiation in a defined mesh with only one point to save time # distance = None simulation_test = create_simulation(magnetic_structure=id, electron_beam=beam_ALSU, magnetic_field=None, photon_energy=None, traj_method=TRAJECTORY_METHOD_ANALYTIC, Nb_pts_trajectory=None, rad_method=RADIATION_METHOD_APPROX_FARFIELD, Nb_pts_radiation=101,
def main(mode_wavefront_before_lens): # \ | / # * | | | * # / | \ # <------- d ---------------><--------- d -------> # d is propagation_distance # wavefron names at different positions # wf1 wf2 wf3 wf4 lens_diameter = 0.002 # 0.001 # 0.002 if mode_wavefront_before_lens == 'Undulator with lens': npixels_x = 512 else: npixels_x = int(2048 * 1.5) pixelsize_x = lens_diameter / npixels_x print("pixelsize: ", pixelsize_x) pixelsize_y = pixelsize_x npixels_y = npixels_x wavelength = 1.24e-10 propagation_distance = 30.0 defocus_factor = 1.0 # 1.0 is at focus propagation_steps = 1 # for Gaussian source sigma_x = lens_diameter / 400 # 5e-6 sigma_y = sigma_x # 5e-6 # for Hermite-Gauss, the H and V mode index (start from 0) hm = 3 hn = 1 if mode_wavefront_before_lens == 'convergent spherical': # no need to propagate nor define lens wf3 = GenericWavefront2D.initialize_wavefront_from_range( x_min=-pixelsize_x * npixels_x / 2, x_max=pixelsize_x * npixels_x / 2, y_min=-pixelsize_y * npixels_y / 2, y_max=pixelsize_y * npixels_y / 2, number_of_points=(npixels_x, npixels_y), wavelength=wavelength) wf3.set_spherical_wave(complex_amplitude=1.0, radius=-propagation_distance) elif mode_wavefront_before_lens == 'divergent spherical with lens': # define wavefront at zero distance upstream the lens and apply lens focal_length = propagation_distance / 2. wf2 = GenericWavefront2D.initialize_wavefront_from_range( x_min=-pixelsize_x * npixels_x / 2, x_max=pixelsize_x * npixels_x / 2, y_min=-pixelsize_y * npixels_y / 2, y_max=pixelsize_y * npixels_y / 2, number_of_points=(npixels_x, npixels_y), wavelength=wavelength) wf2.set_spherical_wave(complex_amplitude=1.0, radius=propagation_distance) wf3 = apply_lens(wf2, focal_length) elif mode_wavefront_before_lens == 'plane with lens': # define wavefront at zero distance upstream the lens and apply lens focal_length = propagation_distance wf2 = GenericWavefront2D.initialize_wavefront_from_range( x_min=-pixelsize_x * npixels_x / 2, x_max=pixelsize_x * npixels_x / 2, y_min=-pixelsize_y * npixels_y / 2, y_max=pixelsize_y * npixels_y / 2, number_of_points=(npixels_x, npixels_y), wavelength=wavelength) wf2.set_plane_wave_from_complex_amplitude(1.0 + 0j) wf3 = apply_lens(wf2, focal_length) elif mode_wavefront_before_lens == 'Gaussian with lens': # define wavefront at source point, propagate to the lens and apply lens wf1 = GenericWavefront2D.initialize_wavefront_from_range( x_min=-pixelsize_x * npixels_x / 2, x_max=pixelsize_x * npixels_x / 2, y_min=-pixelsize_y * npixels_y / 2, y_max=pixelsize_y * npixels_y / 2, number_of_points=(npixels_x, npixels_y), wavelength=wavelength) X = wf1.get_mesh_x() Y = wf1.get_mesh_y() intensity = numpy.exp(-X**2 / (2 * sigma_x**2)) * numpy.exp(-Y**2 / (2 * sigma_y**2)) wf1.set_complex_amplitude(numpy.sqrt(intensity)) # plot plot_image(wf1.get_intensity(), 1e6 * wf1.get_coordinate_x(), 1e6 * wf1.get_coordinate_y(), xtitle="X um", ytitle="Y um", title="Gaussian source", show=1) wf2, x2, h2 = propagation_in_vacuum( wf1, propagation_distance=propagation_distance) plot_image(wf2.get_intensity(), 1e6 * wf2.get_coordinate_x(), 1e6 * wf2.get_coordinate_y(), xtitle="X um", ytitle="Y um", title="Before lens fft", show=1) focal_length = propagation_distance / 2 wf3 = apply_lens(wf2, focal_length) elif mode_wavefront_before_lens == 'Hermite with lens': # define wavefront at source point, propagate to the lens and apply lens wf1 = GenericWavefront2D.initialize_wavefront_from_range( x_min=-pixelsize_x * npixels_x / 2, x_max=pixelsize_x * npixels_x / 2, y_min=-pixelsize_y * npixels_y / 2, y_max=pixelsize_y * npixels_y / 2, number_of_points=(npixels_x, npixels_y), wavelength=wavelength) X = wf1.get_mesh_x() Y = wf1.get_mesh_y() efield = (hermite(hm)(numpy.sqrt(2)*X/sigma_x)*numpy.exp(-X**2/sigma_x**2))**2 \ * (hermite(hn)(numpy.sqrt(2)*Y/sigma_y)*numpy.exp(-Y**2/sigma_y**2))**2 wf1.set_complex_amplitude(efield) # plot plot_image(wf1.get_intensity(), 1e6 * wf1.get_coordinate_x(), 1e6 * wf1.get_coordinate_y(), xtitle="X um", ytitle="Y um", title="Hermite-Gauss source", show=1) wf2, x2, h2 = propagation_in_vacuum(wf1, propagation_distance=30.0, defocus_factor=1.0, propagation_steps=1) plot_image(wf2.get_intensity(), 1e6 * wf2.get_coordinate_x(), 1e6 * wf2.get_coordinate_y(), xtitle="X um", ytitle="Y um", title="Before lens %s" % USE_PROPAGATOR, show=1) wf3 = apply_lens(wf2, focal_length=propagation_distance / 2) elif mode_wavefront_before_lens == 'Undulator with lens': beamline = {} # beamline['name'] = "ESRF_NEW_OB" # beamline['ElectronBeamDivergenceH'] = 5.2e-6 # these values are not used (zero emittance) # beamline['ElectronBeamDivergenceV'] = 1.4e-6 # these values are not used (zero emittance) # beamline['ElectronBeamSizeH'] = 27.2e-6 # these values are not used (zero emittance) # beamline['ElectronBeamSizeV'] = 3.4e-6 # these values are not used (zero emittance) # beamline['ElectronEnergySpread'] = 0.001 # these values are not used (zero emittance) beamline['ElectronCurrent'] = 0.2 beamline['ElectronEnergy'] = 6.0 beamline['Kv'] = 1.68 # 1.87 beamline['NPeriods'] = 111 # 14 beamline['PeriodID'] = 0.018 # 0.035 beamline['distance'] = propagation_distance # beamline['gapH'] = pixelsize_x*npixels_x # beamline['gapV'] = pixelsize_x*npixels_x gamma = beamline['ElectronEnergy'] / (codata_mee * 1e-3) print("Gamma: %f \n" % (gamma)) resonance_wavelength = ( 1 + beamline['Kv']**2 / 2.0) / 2 / gamma**2 * beamline["PeriodID"] resonance_energy = m2ev / resonance_wavelength print("Resonance wavelength [A]: %g \n" % (1e10 * resonance_wavelength)) print("Resonance energy [eV]: %g \n" % (resonance_energy)) # red shift 100 eV resonance_energy = resonance_energy - 100 myBeam = ElectronBeam(Electron_energy=beamline['ElectronEnergy'], I_current=beamline['ElectronCurrent']) myUndulator = MagneticStructureUndulatorPlane( K=beamline['Kv'], period_length=beamline['PeriodID'], length=beamline['PeriodID'] * beamline['NPeriods']) wf2 = GenericWavefront2D.initialize_wavefront_from_range( x_min=-pixelsize_x * npixels_x / 2, x_max=pixelsize_x * npixels_x / 2, y_min=-pixelsize_y * npixels_y / 2, y_max=pixelsize_y * npixels_y / 2, number_of_points=(npixels_x, npixels_y), wavelength=wavelength) XX = wf2.get_mesh_x() YY = wf2.get_mesh_y() X = wf2.get_coordinate_x() Y = wf2.get_coordinate_y() source = SourceUndulatorPlane(undulator=myUndulator, electron_beam=myBeam, magnetic_field=None) omega = resonance_energy * codata.e / codata.hbar Nb_pts_trajectory = int( source.choose_nb_pts_trajectory(0.01, photon_frequency=omega)) print("Number of trajectory points: ", Nb_pts_trajectory) traj_fact = TrajectoryFactory(Nb_pts=Nb_pts_trajectory, method=TRAJECTORY_METHOD_ODE, initial_condition=None) print("Number of trajectory points: ", traj_fact.Nb_pts) if (traj_fact.initial_condition == None): traj_fact.initial_condition = source.choose_initial_contidion_automatic( ) print("Number of trajectory points: ", traj_fact.Nb_pts, traj_fact.initial_condition) rad_fact = RadiationFactory(method=RADIATION_METHOD_NEAR_FIELD, photon_frequency=omega) #print('step 3') trajectory = traj_fact.create_from_source(source=source) #print('step 4') radiation = rad_fact.create_for_one_relativistic_electron( trajectory=trajectory, source=source, XY_are_list=False, distance=beamline['distance'], X=X, Y=Y) efield = rad_fact.calculate_electrical_field( trajectory=trajectory, source=source, distance=beamline['distance'], X_array=XX, Y_array=YY) tmp = efield.electrical_field()[:, :, 0] wf2.set_photon_energy(resonance_energy) wf2.set_complex_amplitude(tmp) # plot plot_image(wf2.get_intensity(), 1e6 * wf2.get_coordinate_x(), 1e6 * wf2.get_coordinate_y(), xtitle="X um", ytitle="Y um", title="UND source at lens plane", show=1) # apply lens focal_length = propagation_distance / 2 wf3 = apply_lens(wf2, focal_length=focal_length) else: raise Exception("Unknown mode") plot_image(wf3.get_phase(), 1e6 * wf3.get_coordinate_x(), 1e6 * wf3.get_coordinate_y(), title="Phase just after the lens %s" % USE_PROPAGATOR, xtitle="X um", ytitle="Y um", show=1) wf4, x4, h4 = propagation_in_vacuum( wf3, propagation_distance=propagation_distance, defocus_factor=1.0, propagation_steps=1) plot_image(wf4.get_intensity(), 1e6 * wf4.get_coordinate_x(), 1e6 * wf4.get_coordinate_y(), title="Intensity at focal point %s" % USE_PROPAGATOR, xtitle="X um", ytitle="Y um", show=1) plot(1e4 * x4, h4, xtitle='x [um]', ytitle='intensity', title='horizontal profile', show=True)
from pySRU.MagneticStructureBendingMagnet import MagneticStructureBendingMagnet as BM from pySRU.ElectronBeam import ElectronBeam from pySRU.Source import Source from pySRU.Simulation import Simulation ,create_simulation from pySRU.TrajectoryFactory import TRAJECTORY_METHOD_ANALYTIC,TRAJECTORY_METHOD_ODE from pySRU.RadiationFactory import RADIATION_METHOD_NEAR_FIELD, RADIATION_METHOD_APPROX_FARFIELD,RADIATION_METHOD_APPROX eV_to_J=1.602176487e-19 ###################################################### #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)
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
def Example_spectrum_on_slit(): from pySRU.ElectronBeam import ElectronBeam print( "======================================================================" ) print( "====== Undulator U18 from ESRF with K=1.68 =======" ) print( "======================================================================" ) beam_ESRF = ElectronBeam(Electron_energy=6.0, I_current=0.2) ESRF18 = Undulator(K=1.68, period_length=0.018, length=2.0) print( 'create radiation a given screen (.025 x .025 mrad) accepting central cone' ) is_quadrant = 1 distance = None # using angles if is_quadrant: X = np.linspace(0, 0.0125e-3, 26) Y = np.linspace(0, 0.0125e-3, 26) else: X = np.linspace(-0.0125e-3, 0.0125e-3, 51) Y = np.linspace(-0.0125e-3, 0.0125e-3, 51) if distance != None: X *= distance Y *= distance simulation_test = create_simulation( magnetic_structure=ESRF18, electron_beam=beam_ESRF, magnetic_field=None, photon_energy=None, traj_method=TRAJECTORY_METHOD_ANALYTIC, Nb_pts_trajectory=None, rad_method=RADIATION_METHOD_APPROX_FARFIELD, Nb_pts_radiation=101, initial_condition=None, distance=distance, XY_are_list=False, X=X, Y=Y) simulation_test.print_parameters() simulation_test.radiation.plot( title=("radiation in a screen for first harmonic")) print("Integrated flux at resonance: %g photons/s/0.1bw" % (simulation_test.radiation.integration(is_quadrant=is_quadrant))) x, y = simulation_test.calculate_spectrum_on_slit(abscissas_array=None, use_eV=1, is_quadrant=is_quadrant) # dump file filename = "spectrum.spec" f = open(filename, 'w') f.write("#F %s\n\n#S 1 undulator flux using pySRU\n" % filename) f.write("#N 2\n#L Photon energy [eV] Flux on slit [phot/s/0.1%bw]\n") for i in range(x.size): f.write("%f %g\n" % (x[i], y[i])) f.close() print("File written to disk: %s" % filename)
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
print(" velocity average in Z direction (c units)") print(undulator.average_z_speed_in_undulator()) print(" first harmonic frequency (Hz)") print(undulator.harmonic_frequency(1)) print(" angle (rad) of the first ring for the first harmonic ") print(undulator.angle_ring_number(1, 1)) print(' magnetic field intensity (T)') print(undulator.magnetic_field_strength()) print(' Magnetic field intensity in (0,0,0)') Bx = undulator.magnetic_field.Bx(z=0.0, y=0.0, x=0.0) By = undulator.magnetic_field.By(z=0.0, y=0.0, x=0.0) Bz = undulator.magnetic_field.Bz(z=0.0, y=0.0, x=0.0) B = np.array([Bx, By, Bz]) print(B) print('On axis peak intensity Fn(K)') print(undulator.Fn(1)) if __name__ == "__main__": electron_beam_test = ElectronBeam(Electron_energy=1.3, I_current=1.0) undulator_test = MagneticStructureUndulatorPlane(K=1.87, period_length=0.035, length=0.035 * 14) source = SourceUndulatorPlane(electron_beam=electron_beam_test, undulator=undulator_test) Example1_undulator(source)
# # simulation_test.trajectory.plot_3D(title="Electron Trajectory") # # simulation_test.radiation.plot(title="Flux in far field vs angle") print( "======================================================================" ) print( "====== Undulator U18 from ESRF with K=1.68 =======" ) print( "======================================================================" ) beam_ESRF = ElectronBeam(Electron_energy=6.0, I_current=0.2) # ESRF18 = Undulator(K=1.68, period_length=0.018, length=2.0) ESRF18 = Undulator(K=1.0, period_length=0.1, length=1.0) # # radiation in a defined mesh with only one point to save time # distance = None simulation_test = create_simulation( magnetic_structure=ESRF18, electron_beam=beam_ESRF, magnetic_field=None, photon_energy=None, traj_method=TRAJECTORY_METHOD_ANALYTIC, Nb_pts_trajectory=None,