def testsInitializers(self): # # initializers # a = S4Conic() print(a.info()) a = S4Conic.initialize_from_coefficients([1.0,1,1,1,1,1,1,1,1,1]) assert_equal(a.get_coefficients(),numpy.array([1.0,1,1,1,1,1,1,1,1,1])) print(a.info()) a = S4Conic.initialize_as_plane() assert_equal(a.get_coefficients(),numpy.array([0,0,0,0,0,0,0,0,-1.,0])) print(a.info())
def apply_local_refraction(self, beam): surface_shape = self.get_optical_element().get_surface_shape() ccc = S4Conic.initialize_from_coefficients( surface_shape.get_conic_coefficients()) oe = self.get_optical_element() refraction_index_object, refraction_index_image = oe.get_refraction_indices( ) beam_mirr, normal = ccc.apply_refraction_on_beam( beam, refraction_index_object, refraction_index_image) return beam_mirr, normal
def get_optical_surface_instance(self): surface_shape = self.get_surface_shape() switch_convexity = 0 if surface_shape.get_convexity() == Convexity.DOWNWARD else 1 radius = surface_shape.get_radius() if isinstance(surface_shape, SphericalCylinder): cylindrical = 1 cylangle = 0.0 if surface_shape.get_cylinder_direction() == Direction.TANGENTIAL else (0.5 * numpy.pi) elif isinstance(surface_shape, Sphere): cylindrical = 0 cylangle = 0.0 print(">>>>> S4SphereOpticalElement.get_optical_surface_instance(): R, cyl, cyl_angle, optical element, ", radius, cylindrical, cylangle, surface_shape) return S4Conic.initialize_as_sphere_from_curvature_radius(radius, cylindrical=cylindrical, cylangle=cylangle, switch_convexity=switch_convexity)
def get_optical_surface_instance(self): surface_shape = self.get_surface_shape() switch_convexity = 0 if surface_shape.get_convexity() == Convexity.DOWNWARD else 1 if isinstance(surface_shape, HyperbolicCylinder): print(">>>>> HyperbolicCylinder optical element", surface_shape) cylindrical = 1 cylangle = 0.0 if surface_shape.get_cylinder_direction() == Direction.TANGENTIAL else (0.5 * numpy.pi) elif isinstance(surface_shape, Hyperboloid): print(">>>>> Hyperboloid optical element", surface_shape) cylindrical = 0 cylangle = 0.0 return S4Conic.initialize_as_hyperboloid_from_focal_distances(surface_shape.get_p_focus(), surface_shape.get_q_focus(), surface_shape.get_grazing_angle(), cylindrical=cylindrical, cylangle=cylangle, switch_convexity=switch_convexity)
def get_optical_surface_instance(self): surface_shape = self.get_surface_shape() switch_convexity = 0 if surface_shape.get_convexity() == Convexity.DOWNWARD else 1 if surface_shape.get_at_infinity() == Side.SOURCE: p = 1e20 q = surface_shape.get_pole_to_focus() else: q = 1e20 p = surface_shape.get_pole_to_focus() if isinstance(surface_shape, ParabolicCylinder): print(">>>>> ParabolicCylinder optical element", surface_shape) cylindrical = 1 cylangle = 0.0 if surface_shape.get_cylinder_direction() == Direction.TANGENTIAL else (0.5 * numpy.pi) elif isinstance(surface_shape, Paraboloid): print(">>>>> Paraboloid optical element", surface_shape) cylindrical = 0 cylangle = 0.0 return S4Conic.initialize_as_paraboloid_from_focal_distances(p, q, surface_shape.get_grazing_angle(), cylindrical=cylindrical, cylangle=cylangle, switch_convexity=switch_convexity)
def get_optical_surface_instance(self): return S4Conic.initialize_as_plane()
def get_optical_surface_instance(self): surface_shape = self.get_surface_shape() print(">>>>> Conic optical element") return S4Conic.initialize_from_coefficients(surface_shape.get_conic_coefficients())
def minishadow_run_conic_mirror(shadow3_beam_source, shadow3_beam, oe0, oe1): # ; # ; ray tracing of a single conic mirror using minishadow # ; results are compared with shadow3 # ; # # copy source to new Beam object newbeam = Beam.initialize_from_array(shadow3_beam_source.rays.copy()) # ; # ; INPUTS # ; # fmirr = oe1.FMIRR # 1 p = oe1.T_SOURCE # 1000.0 # source-mirror q = oe1.T_IMAGE # 300.0 # mirror-image alpha = oe1.ALPHA # 0.0 # mirror orientation angle theta_grazing = (90.0 - oe1.T_INCIDENCE ) * numpy.pi / 180 # 5e-3 # grazing angle, rad fcyl = oe1.FCYL f_convex = oe1.F_CONVEX print("fmirr = %s, p=%f, q=%f, alpha=%f, theta_grazing=%f rad, fcyl=%d"%\ (fmirr,p,q,alpha,theta_grazing,fcyl)) # ccc = SurfaceConic() # ccc.set_sphere_from_focal_distances(p,q,theta_grazing,itype=fmirr,cylindrical=fcyl) if fmirr == 1: # sphere ccc = S4Conic.initialize_as_sphere_from_focal_distances( p, q, theta_grazing, cylindrical=fcyl, switch_convexity=f_convex) elif fmirr == 2: # Ellipsoid ccc = S4Conic.initialize_as_ellipsoid_from_focal_distances( p, q, theta_grazing, cylindrical=fcyl, switch_convexity=f_convex) elif fmirr == 3: # Toroidal raise Exception("fmirr=3 (toroidal) is NOT A CONIC surface") elif fmirr == 4: # Paraboloid ccc = S4Conic.initialize_as_paraboloid_from_focal_distances( p, q, theta_grazing, cylindrical=fcyl, switch_convexity=f_convex) elif fmirr == 5: ccc = S4Conic.initialize_as_plane() elif fmirr == 6: # Codling slit raise Exception("fmirr=6 (Codling slit) is NOT A CONIC surface") elif fmirr == 7: # Hyperboloid ccc = S4Conic.initialize_as_hyperboloid_from_focal_distances( p, q, theta_grazing, cylindrical=fcyl, switch_convexity=f_convex) elif fmirr == 8: # Cone raise Exception("fmirr=8 (Cone) is NOT A CONIC surface") else: raise Exception("fmirr invalid") print(ccc.info()) # # put beam in mirror reference system # # TODO: calculate rotation matrices? Invert them for putting back to the lab system? newbeam.rotate(alpha, axis=2) newbeam.rotate(theta_grazing, axis=1) newbeam.translation( [0.0, -p * numpy.cos(theta_grazing), p * numpy.sin(theta_grazing)]) # # # newbeam.rotate(alpha,axis=2) # # newbeam.rotate(theta_grazing,axis=1) # # newbeam.translation([0.0,-p*numpy.cos(theta_grazing),p*numpy.sin(theta_grazing)]) # # # # reflect beam in the mirror surface and dump mirr.01 # newbeam, tmp = ccc.apply_specular_reflection_on_beam(newbeam) Beam3.initialize_from_shadow4_beam(newbeam).write('minimirr.01') # # put beam in lab frame and compute image # newbeam.rotate(theta_grazing, axis=1) # TODO what about alpha? newbeam.retrace(q, resetY=True) Beam3.initialize_from_shadow4_beam(newbeam).write('ministar.01')
if __name__ == "__main__": fmirr = 1 p = 1000.0 # source-mirror q = 300.0 # mirror-image alpha = 0.0 # mirror orientation angle theta_grazing = 5e-3 # grazing angle, rad fcyl = 0 # oe1.FCYL f_convex = 0 # oe1.F_CONVEX print("fmirr = %s, p=%f, q=%f, alpha=%f, theta_grazing=%f rad, fcyl=%d"%\ (fmirr,p,q,alpha,theta_grazing,fcyl)) ccc = S4Conic() ccc.set_sphere_from_focal_distances( p, q, theta_grazing) # ,itype=fmirr,cylindrical=fcyl) print(ccc.info()) x0 = numpy.array([0.2, -0.50, 0.5]) v0 = numpy.array([0.0, 1.0, -1.0]) t_exact = ccc.calculate_intercept(x0, v0, keep=0) print("exact solution: ", t_exact) #[0][0]) # # mesh object using exact surface #