def test_boundary_condition(): #beam1 = Beam(10000) #beam1.set_point(0, 0, 0) #beam1.set_flat_divergence(5e-3, 5e-2) shadow_beam = run_shadow_source() beam1 = Beam(10000) beam1.initialize_from_arrays( shadow_beam.getshonecol(1), shadow_beam.getshonecol(2), shadow_beam.getshonecol(3), shadow_beam.getshonecol(4), shadow_beam.getshonecol(5), shadow_beam.getshonecol(6), shadow_beam.getshonecol(10), 0 ) bound1=BoundaryRectangle(xmax=0.005,xmin=-0.005,ymax=0.05,ymin=-0.05) bound2=BoundaryRectangle(xmax=0.01,xmin=-0.01,ymax=0.1,ymin=-0.1) plane_mirror=Optical_element.initialize_as_plane_mirror(2,1,65*np.pi/180,0) parabolic_mirror=Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(5,2,28*np.pi/180,90*np.pi/180) plane_mirror.rectangular_bound(bound1) parabolic_mirror.rectangular_bound(bound2) beam1=plane_mirror.trace_optical_element(beam1) beam1=parabolic_mirror.trace_optical_element(beam1) beam1.plot_xz() plt.title("Total points plot") beam1.plot_good_xz() plt.title("Good points plot") print(beam1.flag) indices=np.where(beam1.flag>0) print("The good number of ray are: %f" %(beam1.flag[indices].size)) plt.show() shadow_beam=trace_shadow(shadow_beam) assert_almost_equal(beam1.x, shadow_beam.getshonecol(1), 8) assert_almost_equal(beam1.y, shadow_beam.getshonecol(2), 8) assert_almost_equal(beam1.z, shadow_beam.getshonecol(3), 8)
def test_kirk_patrick_baez(): #beam=Beam.initialize_as_person() #beam.set_flat_divergence(1e-12, 1e-12) #beam.x = beam.x*1e-3 #beam.z = beam.z*1e-3 shadow_beam = shadow_source() beam = Beam() beam.initialize_from_arrays(shadow_beam.getshonecol(1), shadow_beam.getshonecol(2), shadow_beam.getshonecol(3), shadow_beam.getshonecol(4), shadow_beam.getshonecol(5), shadow_beam.getshonecol(6), shadow_beam.getshonecol(10), 0) bound1 = BoundaryRectangle(xmax=2.5, xmin=-2.5, ymax=2.5, ymin=-2.5) bound2 = BoundaryRectangle(xmax=1., xmin=-1., ymax=1., ymin=-1.) kirk_patrick_baez = CompoundOpticalElement.initialize_as_kirkpatrick_baez( p=10., q=5., separation=4., theta=89 * np.pi / 180, bound1=bound1, bound2=bound2) beam = kirk_patrick_baez.trace_compound(beam) beam.plot_good_xz(0) indices = np.where(beam.flag > 0) assert_almost_equal(beam.x[indices], 0., 4) assert_almost_equal(beam.z[indices], 0., 4) beam.retrace(50.) beam.plot_good_xz() print(kirk_patrick_baez.info()) print("Number of good rays: %f" % (beam.number_of_good_rays())) #beam.histogram() if do_plot: plt.show()
def test_rectangular_shape(self): beam = Beam(round(1e5)) plane_mirror = Optical_element.initialize_as_surface_conic_plane( p=10., q=0., theta=0.) beam.set_flat_divergence(0.02, 0.1) xmax = 0.01 xmin = -0.0008 ymax = 1. ymin = -0.29 bound = BoundaryRectangle(xmax=xmax, xmin=xmin, ymax=ymax, ymin=ymin) plane_mirror.set_bound(bound) beam = plane_mirror.trace_optical_element(beam) beam.plot_xz() beam.plot_good_xz() indices = np.where(beam.flag > 0) assert_almost_equal(max(beam.x[indices]) - xmax, 0., 2) assert_almost_equal(-min(beam.x[indices]) + xmin, 0., 2) assert_almost_equal(max(beam.z[indices]) + ymin, 0., 2) assert_almost_equal(-min(beam.z[indices]) - ymax, 0., 2) print(max(beam.x[indices]), min(beam.x[indices]), max(beam.y[indices]), min(beam.y[indices])) if do_plot is True: plt.show() ######### BoundaryCircle has to be implemented in the code of intersection_with_optical_element ####################