def test_my_hyperbolic_mirror(): beam = Beam() beam.set_flat_divergence(0.005, 0.0005) p1 = 130. q1 = 0. spherical_mirror = Optical_element.initialize_as_spherical_mirror(p1, q1, theta=0, alpha=0, R=130.) beam = spherical_mirror.trace_optical_element(beam) p = 15 q = p1 - p theta = 0 * np.pi / 180 hyp_mirror = Optical_element.initialize_my_hyperboloid(p, q, theta) beam = hyp_mirror.trace_optical_element(beam) beam.plot_xz() assert_almost_equal(beam.x, 0., 10) assert_almost_equal(beam.y, 0., 10) assert_almost_equal(beam.z, 0., 10) if do_plot: plt.show()
def test_spherical_mirror(): print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> test_spherical_mirror") beam1 = Beam(5000) beam1.set_point(0, 0, 0) beam1.set_flat_divergence(5e-3, 5e-2) p = 2. q = 1. theta = 30 theta = theta * np.pi / 180 alpha = 0 * np.pi / 180 spherical_mirror = Optical_element.initialize_as_spherical_mirror( p, q, theta, alpha) #spherical_mirror.set_spherical_mirror_radius_from_focal_distances() print(spherical_mirror.R) beam1 = spherical_mirror.trace_optical_element(beam1) beam1.plot_xz() beam1.plot_xpzp() print(np.mean(beam1.flag)) if do_plot: plt.show() assert_almost_equal(np.abs(beam1.x).mean(), 0.0, 2) assert_almost_equal(np.abs(beam1.y).mean(), 0.0, 2) assert_almost_equal(np.abs(beam1.z).mean(), 0.0, 2)
def test_plane_mirror(): print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> test_plane_mirror") beam1 = Beam(5000) beam1.set_point(0, 0, 0) beam1.set_flat_divergence(5e-3, 5e-2) p = 1. q = 1. theta = np.pi / 4 alpha = 0 plane_mirror = Optical_element.initialize_as_plane_mirror( p, q, theta, alpha) xmin = -10**5 xmax = 10**5 ymin = 10**5 ymax = -10**5 bound = BoundaryRectangle(xmax, xmin, ymax, ymin) plane_mirror.rectangular_bound(bound) beam1 = plane_mirror.trace_optical_element(beam1) beam1.plot_xz() beam1.plot_xpzp() if do_plot: plt.show()
def test_montel_elliptical(): print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> test_montel_elliptical") beam = Beam(25000) beam.set_flat_divergence(25 * 1e-6, 25 * 1e-6) beam.set_rectangular_spot(xmax=25 * 1e-6, xmin=-25 * 1e-6, zmax=5 * 1e-6, zmin=-5 * 1e-6) beam.set_gaussian_divergence(25 * 1e-4, 25 * 1e-4) beam.flag *= 0 p = 5. q = 15. #theta = np.pi/2 - 0.15 theta = 85. * np.pi / 180 xmax = 0. xmin = -0.3 ymax = 0.1 ymin = -0.1 zmax = 0.3 zmin = 0. bound1 = BoundaryRectangle(xmax, xmin, ymax, ymin, zmax, zmin) bound2 = BoundaryRectangle(xmax, xmin, ymax, ymin, zmax, zmin) montel = CompoundOpticalElement.initialize_as_montel_ellipsoid( p=p, q=q, theta=theta, bound1=bound1, bound2=bound2) beam03 = montel.trace_montel(beam) print(beam03[2].N / 25000) plt.figure() plt.plot(beam03[0].x, beam03[0].z, 'ro') plt.plot(beam03[1].x, beam03[1].z, 'bo') plt.plot(beam03[2].x, beam03[2].z, 'go') plt.xlabel('x axis') plt.ylabel('z axis') plt.axis('equal') beam03[2].plot_xz(0) print("No reflection = %d\nOne reflection = %d\nTwo reflection = %d" % (beam03[0].N, beam03[1].N, beam03[2].N)) plt.show()
def test_ideal_lens_with_trace_optical_element(): print( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> test_ideal_lens_with_trace_optical_element" ) beam = Beam() beam.set_flat_divergence(0.05, 0.005) p = 1. q = 5. lens = Optical_element.ideal_lens(p, q) beam = lens.trace_optical_element(beam) beam.plot_xz() if do_plot: plt.show() assert_almost_equal(np.abs(beam.x).mean(), 0.0, 4) assert_almost_equal(np.abs(beam.z).mean(), 0.0, 4)
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 ####################
plt.show() if main == "__main2__": 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) beam = Beam(25000) beam.set_flat_divergence(25 * 1e-6, 25 * 1e-6) beam.set_rectangular_spot(xmax=25 * 1e-6, xmin=-25 * 1e-6, zmax=5 * 1e-6, zmin=-5 * 1e-6) beam.set_gaussian_divergence(25 * 1e-6, 25 * 1e-6) beam.set_divergences_collimated() beam.flag *= 0 p = 5. q = 15. theta = 88. * np.pi / 180. xmax = 0. xmin = -0.3
#class Montel(object): # # def __init__(self): # # self.p = 0. # self.q = 0. # self.theta = 0. # # self.ccc1 = None # self.ccc2 = None # if main == "__main__2__": beam = Beam(25000) beam.set_flat_divergence(dx=0.001, dz=0.001) #beam.set_divergences_collimated() 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) p = 5. q = 15. theta = 89.5 * np.pi / 180
from Beam import Beam from OpticalElement import Optical_element from Shape import BoundaryRectangle import numpy as np import matplotlib.pyplot as plt from numpy.testing import assert_almost_equal from Vector import Vector fx = 0.5 fz = 0.5 beam = Beam(5000) #beam.set_divergences_collimated() #beam.set_rectangular_spot(1.,-1.,1.,-1.) beam.set_flat_divergence(0.05, 0.05) beam.plot_xz() beam.plot_xpzp() lens = Optical_element() lens.set_parameters(p=2., q=5.) beam = lens.trace_ideal_lens(beam) beam.plot_xz() hyp = Optical_element.initialize_my_hyperboloid(p=5 - np.sqrt(2), q=np.sqrt(2), theta=0) beam = hyp.trace_optical_element(beam)