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))
class TestParabolicDish(unittest.TestCase): def setUp(self): pos = N.zeros((3, 4)) pos[0] = N.r_[0, 0.5, 2, -2] pos[2] = 2. dir = N.tile(N.c_[[0, 0, -1]], (1, 4)) self.bund = RayBundle() self.bund.set_vertices(pos) self.bund.set_directions(dir) self.surf = Surface(ParabolicDishGM(2., 1.), opt.perfect_mirror) def test_selection_at_origin(self): """Simple dish rejects missing rays""" misses = N.isinf(self.surf.register_incoming(self.bund)) N.testing.assert_array_equal(misses, N.r_[False, False, True, True]) def test_transformed(self): """Translated and rotated dish rejects missing rays""" trans = generate_transform(N.r_[1., 0., 0.], N.pi / 4., N.c_[[0., 0., 1.]]) self.surf.transform_frame(trans) misses = N.isinf(self.surf.register_incoming(self.bund)) N.testing.assert_array_equal(misses, N.r_[False, False, True, True]) def test_mesh(self): """Parabolic dish mesh looks OK""" p = ParabolicDishGM(5, 3) x, y, z = p.mesh(5) N.testing.assert_array_almost_equal(z, p.a * (x**2 + y**2)) self.failIf(N.any(x**2 + y**2 > 6.25))
class TestTraceProtocol(unittest.TestCase): def setUp(self): self._surf = Surface(FlatGeometryManager(), perfect_mirror) dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]]).T / math.sqrt(3) position = c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]] self._bund = RayBundle(position, dir, energy=N.ones(4)*100) def test_register_incoming(self): """Flat mirror: a simple bundle is registered correctly""" correct_params = r_[[math.sqrt(3)]*4] params = self._surf.register_incoming(self._bund) N.testing.assert_array_almost_equal(params, correct_params) def test_get_outgoing(self): """Flat mirror: the correct outgoing bundle is returned""" params = self._surf.register_incoming(self._bund) self._surf.select_rays(N.arange(4)) outg = self._surf.get_outgoing() correct_pts = N.zeros((3,4)) correct_pts[:2,0] = 1 N.testing.assert_array_equal(outg.get_vertices(), correct_pts) correct_dirs = N.c_[[1, 1, 1], [-1, 1, 1], [-1, -1, 1], [1, -1, 1]] / N.sqrt(3) N.testing.assert_array_equal(outg.get_directions(), correct_dirs) N.testing.assert_array_equal(outg.get_energy(), N.ones(4)*100) N.testing.assert_array_equal(outg.get_parents(), N.arange(4))
def setUp(self): self._surf = Surface(FlatGeometryManager(), perfect_mirror) dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1] ]).T / math.sqrt(3) position = c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]] self._bund = RayBundle(position, dir, energy=N.ones(4) * 100)
class TestTraceProtocol(unittest.TestCase): def setUp(self): self._surf = Surface(FlatGeometryManager(), perfect_mirror) dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1] ]).T / math.sqrt(3) position = c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]] self._bund = RayBundle(position, dir, energy=N.ones(4) * 100) def test_register_incoming(self): """Flat mirror: a simple bundle is registered correctly""" correct_params = r_[[math.sqrt(3)] * 4] params = self._surf.register_incoming(self._bund) N.testing.assert_array_almost_equal(params, correct_params) def test_get_outgoing(self): """Flat mirror: the correct outgoing bundle is returned""" params = self._surf.register_incoming(self._bund) self._surf.select_rays(N.arange(4)) outg = self._surf.get_outgoing() correct_pts = N.zeros((3, 4)) correct_pts[:2, 0] = 1 N.testing.assert_array_equal(outg.get_vertices(), correct_pts) correct_dirs = N.c_[[1, 1, 1], [-1, 1, 1], [-1, -1, 1], [1, -1, 1]] / N.sqrt(3) N.testing.assert_array_equal(outg.get_directions(), correct_dirs) N.testing.assert_array_equal(outg.get_energy(), N.ones(4) * 100) N.testing.assert_array_equal(outg.get_parents(), N.arange(4))
class TestParabolicDish(unittest.TestCase): def setUp(self): pos = N.zeros((3,4)) pos[0] = N.r_[0, 0.5, 2, -2] pos[2] = 2. dir = N.tile(N.c_[[0,0,-1]], (1,4)) self.bund = RayBundle() self.bund.set_vertices(pos) self.bund.set_directions(dir) self.surf = Surface(ParabolicDishGM(2., 1.), opt.perfect_mirror) def test_selection_at_origin(self): """Simple dish rejects missing rays""" misses = N.isinf(self.surf.register_incoming(self.bund)) N.testing.assert_array_equal(misses, N.r_[False, False, True, True]) def test_transformed(self): """Translated and rotated dish rejects missing rays""" trans = generate_transform(N.r_[1., 0., 0.], N.pi/4., N.c_[[0., 0., 1.]]) self.surf.transform_frame(trans) misses = N.isinf(self.surf.register_incoming(self.bund)) N.testing.assert_array_equal(misses, N.r_[False, False, True, True]) def test_mesh(self): """Parabolic dish mesh looks OK""" p = ParabolicDishGM(5, 3) x, y, z = p.mesh(5) N.testing.assert_array_almost_equal(z, p.a*(x**2 + y**2)) self.failIf(N.any(x**2 + y**2 > 6.25))
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 runTest(self): pos = N.array([[0, 1.5], [0, -1.5], [1, 0], [-1, 0], [0.1, 0.1], [-0.1, 0.6]]) bund = RayBundle() bund.set_vertices(N.vstack((pos.T, N.ones(pos.shape[0])))) bund.set_directions(N.tile(N.c_[[0,0,-1]], (1,6))) surf = Surface(HexagonalParabolicDishGM(2., 1.), opt.perfect_mirror) misses = N.isinf(surf.register_incoming(bund)) N.testing.assert_array_equal(misses, N.r_[True, True, True, True, False, False])
def runTest(self): pos = N.array([[0, 1.5], [0, -1.5], [1, 0], [-1, 0], [0.1, 0.1], [-0.1, 0.6]]) bund = RayBundle() bund.set_vertices(N.vstack((pos.T, N.ones(pos.shape[0])))) bund.set_directions(N.tile(N.c_[[0, 0, -1]], (1, 6))) surf = Surface(HexagonalParabolicDishGM(2., 1.), opt.perfect_mirror) misses = N.isinf(surf.register_incoming(bund)) N.testing.assert_array_equal( misses, N.r_[True, True, True, True, False, False])
def test_selection(self): pos = N.zeros((3,4)) pos[0] = N.r_[0, 0.05, 0.2, -0.3] pos[2] = 1. dir = N.tile(N.c_[[0,0,-1]], (1,4)) bund = RayBundle(pos, dir) surf = Surface(ExtrudedRectPlateGM(width=1, height=1, extr_center=N.vstack([0.2,0.1]), extr_width=0.2, extr_height=0.4), opt.perfect_mirror) misses = N.isinf(surf.register_incoming(bund)) N.testing.assert_array_equal(misses, N.r_[False, False, True, False])
def setUp(self): pos = N.zeros((3, 4)) pos[0] = N.r_[0, 0.5, 2, -2] pos[2] = 2. dir = N.tile(N.c_[[0, 0, -1]], (1, 4)) self.bund = RayBundle() self.bund.set_vertices(pos) self.bund.set_directions(dir) self.surf = Surface(ParabolicDishGM(2., 1.), opt.perfect_mirror)
def test_selection(self): pos = N.zeros((3,4)) pos[0] = N.r_[0, 0.5, 2, -2] pos[2] = 1. dir = N.tile(N.c_[[0,0,-1]], (1,4)) bund = RayBundle(pos, dir) surf = Surface(RoundPlateGM(1), opt.perfect_mirror) misses = N.isinf(surf.register_incoming(bund)) N.testing.assert_array_equal(misses, N.r_[False, False, True, True])
def setUp(self): absorptive = Surface(RectPlateGM(1., 1.), opt.Reflective(1.), location=N.r_[0.5, 0., 1.]) reflective = Surface(RectPlateGM(1., 1.), opt.Reflective(0.), location=N.r_[-0.5, 0., 1.]) self.assembly = Assembly( objects=[AssembledObject(surfs=[absorptive, reflective])]) # 4 rays: two toward absorptive, two toward reflective. pos = N.zeros((3, 4)) pos[0] = N.r_[0.5, 0.25, -0.25, -0.5] direct = N.zeros((3, 4)) direct[2] = 1. self.bund = RayBundle(pos, direct, energy=N.ones(4))
def setUp(self): self.assembly = Assembly() surface1 = Surface(FlatGeometryManager(), opt.perfect_mirror) self.object1 = AssembledObject() self.object1.add_surface(surface1) boundary = BoundarySphere(location=N.r_[0, 0., 3], radius=3.) surface3 = Surface(CutSphereGM(2., boundary), opt.perfect_mirror) self.object2 = AssembledObject() self.object2.add_surface(surface3) self.transform1 = generate_transform(N.r_[1., 0, 0], N.pi / 4, N.c_[[0, 0, -1.]]) self.transform2 = translate(0., 0., 2.) self.assembly.add_object(self.object1, self.transform1) self.assembly.add_object(self.object2, self.transform2)
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): 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): self.x = 1 / (math.sqrt(2)) dir = N.c_[[0, -self.x, self.x], [0, 0, -1]] position = N.c_[[0, 2, 1], [0, 2, 1]] self._bund = RayBundle(position, dir, energy=N.ones(2)) rot1 = general_axis_rotation([1, 0, 0], N.pi / 4) surf1 = Surface(FlatGeometryManager(), opt.perfect_mirror, rotation=rot1) surf2 = Surface(FlatGeometryManager(), opt.perfect_mirror) assembly = Assembly() object = AssembledObject() object.add_surface(surf1) object.add_surface(surf2) assembly.add_object(object) self.engine = TracerEngine(assembly)
def setUp(self): pos = N.zeros((3,4)) pos[0] = N.r_[0, 0.5, 2, -2] pos[2] = 2. dir = N.tile(N.c_[[0,0,-1]], (1,4)) self.bund = RayBundle() self.bund.set_vertices(pos) self.bund.set_directions(dir) self.surf = Surface(ParabolicDishGM(2., 1.), opt.perfect_mirror)
def setUp(self): dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1] ]).T / math.sqrt(3) position = N.c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]] self._bund = RayBundle(position, dir, energy=N.ones(4)) self.assembly = Assembly() object = AssembledObject() object.add_surface(Surface(FlatGeometryManager(), opt.perfect_mirror)) self.assembly.add_object(object) self.engine = TracerEngine(self.assembly)
def setUp(self): self.eighth_circle_trans = generate_transform(N.r_[1., 0, 0], N.pi / 4, N.c_[[0., 1, 0]]) self.surf = Surface(flat_surface.FlatGeometryManager(), \ optics_callables.perfect_mirror) self.obj = AssembledObject(surfs=[self.surf]) self.sub_assembly = Assembly() self.sub_assembly.add_object(self.obj, self.eighth_circle_trans) self.assembly = Assembly() self.assembly.add_assembly(self.sub_assembly, self.eighth_circle_trans)
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): self.assembly = Assembly() surface1 = Surface(Paraboloid(), optics_callables.perfect_mirror) self.object = AssembledObject() self.object.add_surface(surface1) self.assembly.add_object(self.object) x = 1. / (math.sqrt(2)) dir = N.c_[[0, 0, -1.], [0, x, -x]] position = N.c_[[0, 0, 1.], [0, 0, 1.]] self._bund = RayBundle(position, dir, energy=N.ones(2), ref_index=N.ones(2))
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)
def cavity_receiver(width, height, absorptivity=1.): """ Constructs a lambertian receiver consisting of three faces. Returns a list of receiving faces, the assembled object """ front = Surface(RectPlateGM(width, height),opt.LambertianReceiver(absorptivity),location=r_[0.,0.,0.],rotation=general_axis_rotation(r_[1,0,0],N.pi/2)) left = Surface(RectPlateGM(width, height),opt.LambertianReceiver(absorptivity),location=r_[width/2,width/2,0.],rotation=general_axis_rotation(r_[0,1,0],N.pi/-2)) left.width = width left.height = height/2. right = Surface(RectPlateGM(width, height),opt.LambertianReceiver(absorptivity),location=r_[width/-2,width/2,0.],rotation=general_axis_rotation(r_[0,1,0],N.pi/2)) right.width = width right.height = height/2. rec_obj = AssembledObject(surfs=[left, front, right]) #obj.surfaces_for_next_iteration = types.MethodType(surfaces_for_next_iteration, obj, obj.__class__) return rec_obj,[left, front, right], [left, front, right]
def two_sided_receiver(width, height, absorptivity=1., location=None): """ Constructs a receiver centred at a location and parallel to the xz plane Arguments: width - the extent along the x axis in the local frame. height - the extent along the y axis in the local frame. absorptivity - the ratio of energy incident on the reflective side that's not reflected back. Returns: front - the receiving surface obj - the AssembledObject containing both surfaces """ front = Surface(RectPlateGM(height, width), ReflectiveReceiver(absorptivity), location, rotation=rotation_matrix(N.pi / 2.0, 0.0, 0.0)) obj = AssembledObject(surfs=[front]) return front, obj
def thin_bladed_receiver(width, height, absorptivity, blades): """ Constructs lambertian receiver consisting of thin blades. """ front = Surface(RectPlateGM(width, height),opt.LambertianReceiver(absorptivity),location=r_[0.,width/-2.,0.],rotation=general_axis_rotation(r_[1,0,0],N.pi/2)) n = 0 front.axis = [1,0,0] front.tilt = N.pi/2 crit_ls = [] crit_ls.append(front) while n < blades: blade = Surface(RectPlateGM(width, height),opt.LambertianReceiver(absorptivity),location=r_[width/2-(n*width/(blades-1)),0.,0.],rotation=general_axis_rotation(r_[0,1,0],N.pi/-2)) blade.number = n+1 blade.axis = [0,1,0] blade.tilt = N.pi/2 crit_ls.append(blade) n += 1 rec_obj = AssembledObject(surfs=crit_ls) #obj.surfaces_for_next_iteration = types.MethodType(surfaces_for_next_iteration, obj, obj.__class__) return rec_obj, obj_ls, crit_ls
def test_intersect_ray2(self): rot = general_axis_rotation([1, 0, 0], N.pi / 4) surface = Surface(FlatGeometryManager(), opt.perfect_mirror, rotation=rot) assembly = Assembly() object = AssembledObject() object.add_surface(surface) assembly.add_object(object) engine = TracerEngine(assembly) surfaces = assembly.get_surfaces() objects = assembly.get_objects() surfs_per_obj = [len(obj.get_surfaces()) for obj in objects] surf_ownership = N.repeat(N.arange(len(objects)), surfs_per_obj) ray_ownership = -1 * N.ones(self._bund.get_num_rays()) surfs_relevancy = N.ones((len(surfaces), self._bund.get_num_rays()), dtype=N.bool) params = engine.intersect_ray(self._bund, surfaces, objects, \ surf_ownership, ray_ownership, surfs_relevancy)[0] correct_params = N.array([[False, True, False]]) N.testing.assert_array_almost_equal(params, correct_params)
def setUp(self): self._surf = Surface(FlatGeometryManager(), perfect_mirror) dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]]).T / math.sqrt(3) position = c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]] self._bund = RayBundle(position, dir, energy=N.ones(4)*100)