def setUp(self): surface1 = Surface(HemisphereGM(2.), opt.perfect_mirror, rotation=general_axis_rotation( N.r_[1, 0, 0], N.pi / 2.)) surface2 = Surface(HemisphereGM(2.), opt.perfect_mirror, location=N.array([0, -2, 0]), rotation=general_axis_rotation( N.r_[1, 0, 0], -N.pi / 2.)) self._bund = RayBundle() self._bund.set_directions(N.c_[[0, 1, 0]]) self._bund.set_vertices(N.c_[[0, -1, 0]]) self._bund.set_energy(N.r_[[1]]) self._bund.set_ref_index(N.r_[[1]]) assembly = Assembly() object1 = AssembledObject() object2 = AssembledObject() object1.add_surface(surface1) object2.add_surface(surface2) assembly.add_object(object1) assembly.add_object(object2) self.engine = TracerEngine(assembly)
def setUp(self): self.num_rays = 10 dir = N.tile(N.c_[[0, 0, -1]], (1, self.num_rays)) theta = N.linspace(0, 2 * N.pi, self.num_rays, endpoint=False) position = N.vstack( (N.cos(theta), N.sin(theta), N.ones(self.num_rays))) self._bund = RayBundle(position, dir) self.gm = HemisphereGM(radius=2.) self.prm = self.gm.find_intersections(N.eye(4), self._bund)
def setUp(self): self.num_rays = 10 dir = N.tile(N.c_[[0, 0, -1]], (1, self.num_rays)) theta = N.linspace(0, 2*N.pi, self.num_rays, endpoint=False) position = N.vstack((N.cos(theta), N.sin(theta), N.ones(self.num_rays))) self._bund = RayBundle(position, dir) self.gm = HemisphereGM(radius=2.) self.prm = self.gm.find_intersections(N.eye(4), self._bund)
def setUp(self): self.assembly = Assembly() surface1 = Surface(HemisphereGM(3.), optics_callables.perfect_mirror, location=N.array([0, 0, -1.]), rotation=general_axis_rotation(N.r_[1, 0, 0], N.pi)) surface2 = Surface(HemisphereGM(3.), optics_callables.perfect_mirror, location=N.array([0, 0, 1.])) self.object = AssembledObject() self.object.add_surface(surface1) self.object.add_surface(surface2) self.assembly.add_object(self.object) dir = N.c_[[0, 0, 1.], [0, 0, 1.]] position = N.c_[[0, 0, -3.], [0, 0, -1.]] self._bund = RayBundle(position, dir, energy=N.ones(2))
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 setUp(self): surface = Surface(HemisphereGM(1.), opt.perfect_mirror, rotation=general_axis_rotation(N.r_[1, 0, 0], N.pi)) self._bund = RayBundle(energy=N.ones(3)) self._bund.set_directions(N.c_[[0, 1, 0], [0, 1, 0], [0, -1, 0]]) self._bund.set_vertices(N.c_[[0, -2., 0.001], [0, 0, 0.001], [0, 2, 0.001]]) assembly = Assembly() object = AssembledObject() object.add_surface(surface) assembly.add_object(object) self.engine = TracerEngine(assembly)
class TestInterface(unittest.TestCase): def setUp(self): self.num_rays = 10 dir = N.tile(N.c_[[0, 0, -1]], (1, self.num_rays)) theta = N.linspace(0, 2 * N.pi, self.num_rays, endpoint=False) position = N.vstack( (N.cos(theta), N.sin(theta), N.ones(self.num_rays))) self._bund = RayBundle(position, dir) self.gm = HemisphereGM(radius=2.) self.prm = self.gm.find_intersections(N.eye(4), self._bund) def test_find_intersections(self): """The correct parametric locations are found for hemisphere geometry""" self.failUnlessEqual(self.prm.shape, (self.num_rays, )) N.testing.assert_array_almost_equal(self.prm, 1 + 2 * N.sin(N.pi / 3)) def test_get_normals(self): """Hemisphere surface returns center-pointing normals""" self.gm.select_rays(N.arange(self.num_rays)) n = self.gm.get_normals() N.testing.assert_array_almost_equal(n[-1, 0], n[-1, 1:]) N.testing.assert_array_almost_equal( self._bund.get_vertices()[:2], -n[:2] / N.sqrt( (n[:2]**2).sum(axis=0))) def test_inters_points_global(self): """Hemisphere returns correct intersections""" self.gm.select_rays(N.arange(self.num_rays)) pts = self.gm.get_intersection_points_global() N.testing.assert_array_equal(pts[:2], self._bund.get_vertices()[:2]) N.testing.assert_array_almost_equal(pts[2], -2 * N.sin(N.pi / 3)) def test_mesh(self): """The HemisphereGM mesh represents the lower hemisphere only""" x, y, z = self.gm.mesh(10) self.failUnless(N.all(z <= 1e-15)) self.failIf(N.any(x**2 + y**2 > 4.0001))
class TestInterface(unittest.TestCase): def setUp(self): self.num_rays = 10 dir = N.tile(N.c_[[0, 0, -1]], (1, self.num_rays)) theta = N.linspace(0, 2*N.pi, self.num_rays, endpoint=False) position = N.vstack((N.cos(theta), N.sin(theta), N.ones(self.num_rays))) self._bund = RayBundle(position, dir) self.gm = HemisphereGM(radius=2.) self.prm = self.gm.find_intersections(N.eye(4), self._bund) def test_find_intersections(self): """The correct parametric locations are found for hemisphere geometry""" self.failUnlessEqual(self.prm.shape, (self.num_rays,)) N.testing.assert_array_almost_equal(self.prm, 1 + 2*N.sin(N.pi/3)) def test_get_normals(self): """Hemisphere surface returns center-pointing normals""" self.gm.select_rays(N.arange(self.num_rays)) n = self.gm.get_normals() N.testing.assert_array_almost_equal(n[-1,0], n[-1,1:]) N.testing.assert_array_almost_equal(self._bund.get_vertices()[:2], -n[:2]/N.sqrt((n[:2]**2).sum(axis=0))) def test_inters_points_global(self): """Hemisphere returns correct intersections""" self.gm.select_rays(N.arange(self.num_rays)) pts = self.gm.get_intersection_points_global() N.testing.assert_array_equal(pts[:2], self._bund.get_vertices()[:2]) N.testing.assert_array_almost_equal(pts[2], -2*N.sin(N.pi/3)) def test_mesh(self): """The HemisphereGM mesh represents the lower hemisphere only""" x, y, z = self.gm.mesh(10) self.failUnless(N.all(z <= 1e-15)) self.failIf(N.any(x**2 + y**2 > 4.0001))