def setUp(self): self.assembly = Assembly() surface1 = Surface(FlatGeometryManager(), opt.RefractiveHomogenous(1., 1.5), location=N.array([0, 0, -1.])) surface2 = Surface(FlatGeometryManager(), opt.RefractiveHomogenous(1., 1.5), location=N.array([0, 0, 1.])) object1 = AssembledObject(surfs=[surface1, surface2]) boundary = BoundarySphere(location=N.r_[0, 0., 3], radius=3.) surface3 = Surface(CutSphereGM(2., boundary), opt.perfect_mirror) object2 = AssembledObject(surfs=[surface3], transform=translate(0., 0., 2.)) self.assembly = Assembly(objects=[object1, object2]) x = 1. / (math.sqrt(2)) dir = N.c_[[0, 1., 0.], [0, x, x], [0, 0, 1.]] position = N.c_[[0, 0, 2.], [0, 0, 2.], [0, 0., 2.]] self._bund = RayBundle(position, dir, ref_index=N.ones(3), energy=N.ones(3)) self.engine = TracerEngine(self.assembly)
def setUp(self): self.assembly = Assembly() surface1 = Surface(flat_surface.FlatGeometryManager(), optics_callables.RefractiveHomogenous(1., 1.5), location=N.array([0, 0, -1.])) surface2 = Surface(flat_surface.FlatGeometryManager(), optics_callables.RefractiveHomogenous(1., 1.5), location=N.array([0, 0, 1.])) self.object1 = AssembledObject() self.object1.add_surface(surface1) self.object1.add_surface(surface2) boundary = BoundarySphere(location=N.r_[0, 0., 3], radius=3.) surface3 = Surface(CutSphereGM(2., boundary), optics_callables.perfect_mirror) self.object2 = AssembledObject() self.object2.add_surface(surface3) self.transform = generate_transform(N.r_[1, 0., 0], 0., N.c_[[0., 0, 2]]) self.assembly.add_object(self.object1) self.assembly.add_object(self.object2, self.transform) x = 1. / (math.sqrt(2)) dir = N.c_[[0, 1., 0.], [0, x, x], [0, 0, 1.]] position = N.c_[[0, 0, 2.], [0, 0, 2.], [0, 0., 2.]] self._bund = RayBundle(position, dir, energy=N.ones(3), ref_index=N.ones(3))
def test_all_refracted(self): dir = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]] / N.sqrt(3) position = N.c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]] en = N.r_[100, 200, 300, 400] bund = RayBundle(position, dir, energy=en, ref_index=N.ones(4)) gm = FlatGeometryManager() prm = gm.find_intersections(N.eye(4), bund) refractive = optics_callables.RefractiveHomogenous(1,1.5) selector = N.array([0, 1, 3]) gm.select_rays(selector) outg = refractive(gm, bund, selector) correct_pts = N.zeros((3,4)) correct_pts[:2,0] = 1 correct_pts = N.hstack((correct_pts[:,selector], correct_pts[:,selector])) N.testing.assert_array_equal(outg.get_vertices(), correct_pts) norm = N.c_[gm.get_normals()[:,0]] correct_refl_cos = -(dir*norm).sum(axis=0)[selector] correct_refr_cos = -N.sqrt(1 - (1./1.5)**2*(1 - correct_refl_cos**2)) outg_cos = (outg.get_directions()*norm).sum(axis=0) N.testing.assert_array_equal(outg_cos, N.r_[correct_refl_cos, correct_refr_cos]) N.testing.assert_array_equal(outg.get_energy().reshape(2,-1).sum(axis=0), \ N.r_[100, 200, 400]) # reflection and refraction sum to 100% N.testing.assert_array_equal(outg.get_parents(), N.tile(selector, 2))
def setUp(self): self.assembly = Assembly() surface1 = Surface(flat_surface.FlatGeometryManager(), optics_callables.RefractiveHomogenous(1., 1.5), location=N.array([0, 0, -1.])) surface2 = Surface(flat_surface.FlatGeometryManager(), optics_callables.RefractiveHomogenous(1.5, 1.), location=N.array([0, 0, 1.])) self.object = AssembledObject(surfs=[surface1, surface2]) self.assembly.add_object(self.object) x = 1 / (math.sqrt(2)) dir = N.c_[[0, -x, x]] position = N.c_[[0, 1, -2.]] self._bund = RayBundle(position, dir, energy=N.r_[1.], ref_index=N.r_[1.])
def setUp(self): """ Prepare an assembly with two subassemblies: one assembly representing a spherical lens behind a flat screen, and one asssembly representing a perfect mirror. The mirror will be placed at the two subassemblies' focus, so a paraxial ray will come back on the other side of the optical axis. Reference: In [1], the lensmaker equation """ # focal length = 1, thickness = 1/6 R = 1. / 6. back_surf = Surface(HemisphereGM(R), opt.RefractiveHomogenous(1., 1.5), location=N.r_[0., 0., -R / 2.]) front_surf = Surface(HemisphereGM(R), opt.RefractiveHomogenous(1., 1.5), location=N.r_[0., 0., R / 2.], rotation=rotx(N.pi / 2.)[:3, :3]) front_lens = AssembledObject(surfs=[back_surf, front_surf]) back_surf = Surface(RoundPlateGM(R), opt.RefractiveHomogenous(1., 1.5), location=N.r_[0., 0., -0.01]) front_surf = Surface(RoundPlateGM(R), opt.RefractiveHomogenous(1., 1.5), location=N.r_[0., 0., 0.01]) glass_screen = AssembledObject(surfs=[back_surf, front_surf], transform=translate(0., 0., 0.5)) lens_assembly = Assembly(objects=[glass_screen, front_lens]) lens_assembly.set_transform(translate(0., 0., 1.)) full_assembly = Assembly(objects=[rect_one_sided_mirror(1., 1., 0.)], subassemblies=[lens_assembly]) self.engine = TracerEngine(full_assembly)
def test_TIR(self): dir = N.c_[[0, N.cos(N.pi/180), -N.sin(N.pi/180)]] position = N.c_[[0,0,1]] en = N.r_[100] bund = RayBundle(position, dir, energy=en, ref_index=N.r_[1.5]) gm = FlatGeometryManager() prm = gm.find_intersections(N.eye(4), bund) refractive = optics_callables.RefractiveHomogenous(1.,1.5) selector = N.r_[0] gm.select_rays(selector) outg = refractive(gm, bund, selector) self.failUnlessEqual(outg.get_vertices().shape, (3,1)) N.testing.assert_array_equal(outg.get_directions(), N.c_[[0, N.cos(N.pi/180), N.sin(N.pi/180)]]) N.testing.assert_array_equal(outg.get_energy(), N.r_[100]) N.testing.assert_array_equal(outg.get_parents(), N.r_[0])