def initialize_as_montel_ellipsoid(cls, p, q, theta_z, theta_x=None, bound1=None, bound2=None, angle_of_mismatch=0., fp=None, fq=None): beta = np.pi / 2 + angle_of_mismatch #### angle beetween the two mirror, if angle_of_mismatch is <0 the two mirror are closer if theta_x == None: theta_x = theta_z oe1 = Optical_element.initialize_as_surface_conic_ellipsoid_from_focal_distances( p=p, q=q, theta=theta_z, alpha=0., cylindrical=1, fp=fp, fq=fq) oe2 = Optical_element.initialize_as_surface_conic_ellipsoid_from_focal_distances( p=p, q=q, theta=theta_x, alpha=0., cylindrical=1, fp=fp, fq=fq) oe1.set_bound(bound1) oe2.rotation_surface_conic(beta, 'y') oe2.set_bound(bound2) distance_of_the_screen = q ccc = np.array( [0., 0., 0., 0., 0., 0., 0., 1., 0., -distance_of_the_screen]) screen = Optical_element.initialize_as_surface_conic_from_coefficients( ccc) screen.set_parameters(p, q, 0., 0., "Surface conical mirror") return CompoundOpticalElement(oe_list=[oe1, oe2, screen], oe_name="Montel ellipsoid")
def initialize_as_kirkpatrick_baez_parabolic(cls, p, q, separation, theta, bound1=None, bound2=None, infinity_location='p'): p1 = p - 0.5 * separation q1 = p - p1 q2 = q - 0.5 * separation p2 = q - q2 f1p = p1 f1q = p + q - p1 f2q = q2 f2p = p + q - q2 oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p= f1p, q= f1q, theta= theta, alpha=0., cylindrical=1, infinity_location=infinity_location) #oe1.bound = bound1 oe1.set_bound(bound1) oe1.p = p1 oe1.q = q1 oe2 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p= f2p, q= f2q, theta= theta, alpha=90.*np.pi/180, cylindrical=1, infinity_location=infinity_location) #oe2.bound = bound2 oe2.set_bound(bound2) oe2.p = p2 oe2.q = q2 print(oe1.ccc_object.get_coefficients()) print(oe2.ccc_object.get_coefficients()) return CompoundOpticalElement(oe_list=[oe1,oe2],oe_name="Kirkpatrick Baez")
def initialize_as_kirkpatrick_baez(cls, p, q, separation, theta, bound1=None, bound2=None): p1 = p - 0.5 * separation q1 = p - p1 q2 = q - 0.5 * separation p2 = q - q2 f1p = p1 f1q = p + q - p1 f2q = q2 f2p = p + q - q2 oe1 = Optical_element.initialize_as_surface_conic_ellipsoid_from_focal_distances( p=f1p, q=f1q, theta=theta, alpha=0., cylindrical=1) #oe1.bound = bound1 oe1.set_bound(bound1) oe1.p = p1 oe1.q = q1 oe2 = Optical_element.initialize_as_surface_conic_ellipsoid_from_focal_distances( p=f2p, q=f2q, theta=theta, alpha=90. * np.pi / 180, cylindrical=1) #oe2.bound = bound2 oe2.set_bound(bound2) oe2.p = p2 oe2.q = q2 return CompoundOpticalElement(oe_list=[oe1, oe2], oe_name="Kirkpatrick Baez")
def initialiaze_as_wolter_1(cls,p1,q1,z0): theta1 = 0. alpha1 = 0. print(q1) print(2*z0) print("dof=%f" %(2*z0-q1)) oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p1, 0., theta1, alpha1, "p", 2*z0-q1) oe2 = Optical_element.initialize_my_hyperboloid(p=0., q=q1, theta=90 * np.pi / 180, alpha=0, wolter=1, z0=z0,distance_of_focalization=2*z0-q1) return CompoundOpticalElement(oe_list=[oe1,oe2],oe_name="Wolter 1")
def initialiaze_as_wolter_2(cls,p1,q1,z0): #q1 = - q1 focal = q1+2*z0 print("focal=%f" %(focal)) theta1 = 0. alpha1 = 0. oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p1,0.,theta1,alpha1,"p", focal) oe2 = Optical_element.initialize_my_hyperboloid(p=0. ,q=-(focal-2*z0), theta=90*np.pi/180, alpha=0, wolter=2, z0=z0, distance_of_focalization=focal) return CompoundOpticalElement(oe_list=[oe1,oe2],oe_name="Wolter 2")
def initialiaze_as_wolter_1_with_two_parameters(cls, p1, R, theta): cp1 = -2 * R / np.tan(theta) cp2 = 2 * R * np.tan(theta) cp = max(cp1, cp2) f = cp / 4 print("focal=%f" % (f)) oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances( p=p1, q=f, theta=0., alpha=0., infinity_location="p") s1 = R / np.tan(2 * theta) s2 = R / np.tan(4 * theta) c = (s1 - s2) / 2 z0 = f + c b1 = np.sqrt(0.5 * c**2 + 0.5 * R**2 + 0.5 * R**4 / cp**2 - R**2 * z0 / cp + 0.5 * z0**2 - 0.5 / cp**2 * np.sqrt( (-c**2 * cp**2 - cp**2 * R**2 - R**4 + 2 * cp * R**2 * z0 - cp**2 * z0**2)**2 - 4 * cp**2 * (c**2 * R**4 - 2 * c**2 * cp * R**2 * z0 + c**2 * cp**2 * z0**2))) b2 = np.sqrt(0.5 * c**2 + 0.5 * R**2 + 0.5 * R**4 / cp**2 - R**2 * z0 / cp + 0.5 * z0**2 + 0.5 / cp**2 * np.sqrt( (-c**2 * cp**2 - cp**2 * R**2 - R**4 + 2 * cp * R**2 * z0 - cp**2 * z0**2)**2 - 4 * cp**2 * (c**2 * R**4 - 2 * c**2 * cp * R**2 * z0 + c**2 * cp**2 * z0**2))) b = min(b1, b2) a = np.sqrt(c**2 - b**2) ccc = np.array([ -1 / a**2, -1 / a**2, 1 / b**2, 0., 0., 0., 0., 0., -2 * z0 / b**2, z0**2 / b**2 - 1 ]) oe2 = Optical_element.initialize_as_surface_conic_from_coefficients( ccc) oe2.set_parameters(p=0., q=z0 + c, theta=90 * np.pi / 180, alpha=0., type="My hyperbolic mirror") #oe2.type = "My hyperbolic mirror" #oe2.p = 0. #oe2.q = z0 + c #oe2.theta = 90 * np.pi / 180 #oe2.alpha = 0. return CompoundOpticalElement(oe_list=[oe1, oe2], oe_name="Wolter 1")
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()
def initialize_as_wolter_3(cls, p, q, distance_between_the_foci): f=-q oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p=p, q=f, theta=0., alpha=0., infinity_location="p") #c = z0+np.abs(f) c = distance_between_the_foci/2 z0 = np.abs(c)-np.abs(f) b = c+100 a = np.sqrt((b**2-c**2)) ccc = np.array([1/a**2, 1/a**2, 1/b**2, 0., 0., 0., 0., 0., -2*z0/b**2, z0**2/b**2-1]) oe2 = Optical_element.initialize_as_surface_conic_from_coefficients(ccc) oe2.set_parameters(p=0., q=z0+z0+np.abs(q), theta=90*np.pi/180) return CompoundOpticalElement(oe_list=[oe1,oe2],oe_name="Wolter 3")
def initialiaze_as_wolter_12(cls, p1, q1, focal_parabola, Rmin): focal = focal_parabola d = q1 - focal_parabola z0 = focal_parabola + d / 2 print("focal=%f" % (focal)) theta1 = 0. alpha1 = 0. oe1 = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances( p1, 0., theta1, alpha1, "p", focal) ccc = oe1.ccc_object.get_coefficients() cp = -ccc[8] print("R=%f, d=%f, cp=%f, z0=%f" % (Rmin, d, cp, z0)) #b1 = np.sqrt(0.125*d**2+Rmin+2*Rmin**4/cp**2-2*Rmin**2*z0/cp+0.5*z0**2-0.125/cp**2*np.sqrt((-cp**2*d**2-8*cp**2*Rmin-16*Rmin**4+16*cp*Rmin**2*z0-4*cp*z0**2)**2-16*cp**2*(4*d**2*Rmin**4-4*cp*d**2*Rmin**2*z0+cp**2*d**2*z0**2))) #b2 = np.sqrt(0.125*d**2+Rmin+2*Rmin**4/cp**2-2*Rmin**2*z0/cp+0.5*z0**2+0.125/cp**2*np.sqrt((-cp**2*d**2-8*cp**2*Rmin-16*Rmin**4+16*cp*Rmin**2*z0-4*cp*z0**2)**2-16*cp**2*(4*d**2*Rmin**4-4*cp*d**2*Rmin**2*z0+cp**2*d**2*z0**2))) p1 = -cp**2 * d**2 - 8 * cp**2 * Rmin - 16 * Rmin**4 + 16 * cp * Rmin**2 * z0 - 4 * cp**2 * z0**2 p1 = p1**2 p2 = 16 * cp**2 * (4 * d**2 * Rmin**4 - 4 * cp * d**2 * Rmin**2 * z0 + cp**2 * d**2 * z0**2) sp = 0.125 / cp**2 * np.sqrt(p1 - p2) sp0 = 0.125 * d**2 + Rmin + 2 * Rmin**4 / cp**2 - 2 * Rmin**2 * z0 / cp + 0.5 * z0**2 b = np.sqrt(sp0 - sp) a = np.sqrt(d**2 / 4 - b**2) print("a=%f, b=%f" % (a, b)) #oe2 = Optical_element.initialize_my_hyperboloid(p=0. ,q=-(focal-2*z0), theta=90*np.pi/180, alpha=0, wolter=1.1, z0=z0, distance_of_focalization=focal) cc = np.array([ -1 / a**2, -1 / a**2, 1 / b**2, 0., 0., 0., 0., 0., -2 * z0 / b**2, (z0 / b)**2 - 1 ]) oe2 = Optical_element.initialize_as_surface_conic_from_coefficients(cc) oe2.type = "My hyperbolic mirror" oe2.set_parameters(p=0., q=q1, theta=90. * np.pi / 180, alpha=0.) return CompoundOpticalElement(oe_list=[oe1, oe2], oe_name="Wolter 1.2")
def test_spherical_mirror(self): print(">>>>>>>>>>>>>>> test_spherical_mirror") shadow_beam = run_shadow_source() beam1=Beam() 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), ) #beam1 = Beam(5000) #beam1.set_point(0, 0, 0) #beam1.set_flat_divergence(5e-3, 5e-2) p=2. q=1. theta=41*np.pi/180 shadow_beam = run_shadow_source() spherical_mirror=Optical_element.initialize_as_surface_conic_sphere_from_focal_distances(p,q, theta) beam1=spherical_mirror.trace_optical_element(beam1) if do_plot: beam1.plot_xz() beam1.plot_xpzp() plt.title("Spherical mirror with p=2, q=1, theta=41") plt.show() shadow_beam = run_shadow_spherical_mirror(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_ideal_lens_with_trace_optical_element(self): 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.initialiaze_as_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_ellipsoidal_mirror(self): print(">>>>>>>>>>>>>>> test_ellipsoidal_mirror") #beam1=Beam(5000) #beam1.set_point(0,0,0) #beam1.set_flat_divergence(5e-3,5e-2) shadow_beam = run_shadow_source() beam1=Beam() 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), ) p=20. q=10. theta=50*np.pi/180 spherical_mirror=Optical_element.initialize_as_surface_conic_ellipsoid_from_focal_distances(p,q,theta) beam1=spherical_mirror.trace_optical_element(beam1) if do_plot: beam1.plot_xz() beam1.plot_xpzp() plt.title("Ellipsoidal mirror with p=20, q=10, theta=50") plt.show() shadow_beam = run_shadow_elliptical_mirror(beam1) assert_almost_equal(beam1.vx, shadow_beam.getshonecol(4), 1) assert_almost_equal(beam1.vy, shadow_beam.getshonecol(5), 1) assert_almost_equal(beam1.vz, shadow_beam.getshonecol(6), 1)
def test_paraboloid_mirror(self): print(">>>>>>>>>>>>>>> test_paraboloid_mirror") #beam1=Beam(5000) #beam1.set_point(0,0,0) #beam1.set_flat_divergence(5e-3,5e-2) shadow_beam = run_shadow_source() beam1=Beam() 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), ) p=10. q=20. theta=72*np.pi/180 alpha=0*np.pi/180 spherical_mirror=Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances(p,q,theta,alpha) beam1=spherical_mirror.trace_optical_element(beam1) if do_plot: beam1.plot_xz() beam1.plot_xpzp() plt.title("Paraboloid mirror with p=10, q=20, theta=72") print(spherical_mirror.ccc_object.get_coefficients()) plt.show() shadow_beam = run_shadow_parabolic_mirror(shadow_beam) assert_almost_equal(beam1.x, shadow_beam.getshonecol(1), 7) assert_almost_equal(beam1.y, shadow_beam.getshonecol(2), 7) assert_almost_equal(beam1.z, shadow_beam.getshonecol(3), 7)
def test_ideal_lens_collimated_beam(self): print( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> test_ideal_lens_collimated_beam" ) beam = Beam() beam.set_circular_spot(20 * 1e-9) beam.set_divergences_collimated() beam.plot_xz() p = 1. q = 5. lens = Optical_element.initialiaze_as_ideal_lens(p, q, q, 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)
oe0.write("start.00") beam.genSource(oe0) if iwrite: oe0.write("end.00") beam.write("begin.dat") return beam if main == "__ideal_lenses__": beam = beam() ideal_lens_1 = Optical_element.initialiaze_as_ideal_lens(p=0.4, q=0.3, fx=0.4, fz=0.4) ideal_lens_2_04 = Optical_element.initialiaze_as_ideal_lens(p=0.3, q=0.4, fx=0.4, fz=0.4) ideal_lens_2_1471 = Optical_element.initialiaze_as_ideal_lens(p=0.3, q=1.471, fx=1.471, fz=1.471) beam = ideal_lens_1.trace_optical_element(beam) beam_04 = beam.duplicate() beam_1471 = beam.duplicate()
zmax = 0.01 zmin = 0.0 bound = BoundaryRectangle(xmax=xmax, xmin=xmin, ymax=ymax, ymin=ymin, zmax=zmax, zmin=zmin) montel = CompoundOpticalElement.initialize_as_montel_parabolic( p=0.351, q=1., theta=theta, bound1=bound, bound2=bound, infinity_location='p') par = Optical_element.initialize_as_surface_conic_paraboloid_from_focal_distances( 0.351, 1., theta, 0.0, 'p', None, 1) #velocity = Vector(beam.vx, beam.vy, beam.vz) #velocity.rotation(-gamma, 'z') #velocity.rotation(-alpha, 'x') #beam.vx = velocity.x #beam.vy = velocity.y #beam.vz = velocity.z # # #print(beam.vx, beam.vy, beam.vz) # # #position = Vector(beam.x, beam.y, beam.z) #position.rotation(-gamma, 'z') #position.rotation(-alpha, 'x')