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)
class TestObjectBuilding1(unittest.TestCase): """Tests an object composed of sphere surfaces""" 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 test_object(self): """Tests that the assembly heirarchy works at a basic level""" self.engine = TracerEngine(self.assembly) inters = self.engine.ray_tracer(self._bund,1,.05)[0] correct_inters = N.c_[[0,0,2],[0,0,-2]] N.testing.assert_array_almost_equal(inters, correct_inters) def test_translation(self): """Tests an assembly that has been translated""" trans = N.array([[1,0,0,0],[0,1,0,0],[0,0,1,1],[0,0,0,1]]) self.assembly.transform_children(trans) self.engine = TracerEngine(self.assembly) params = self.engine.ray_tracer(self._bund,1,.05)[0] correct_params = N.c_[[0,0,3],[0,0,-1]] N.testing.assert_array_almost_equal(params, correct_params) def test_rotation_and_translation(self): """Tests an assembly that has been translated and rotated""" self._bund = RayBundle() self._bund.set_vertices(N.c_[[0,-5,1],[0,5,1]]) self._bund.set_directions(N.c_[[0,1,0],[0,1,0]]) self._bund.set_energy(N.r_[[1,1]]) self._bund.set_ref_index(N.r_[[1,1]]) trans = generate_transform(N.r_[[1,0,0]], N.pi/2, N.c_[[0,0,1]]) self.assembly.transform_children(trans) self.engine = TracerEngine(self.assembly) params = self.engine.ray_tracer(self._bund,1,.05)[0] correct_params = N.c_[[0,-2,1]] N.testing.assert_array_almost_equal(params, correct_params)
class TestAssemblyBuilding3(unittest.TestCase): """Tests an assembly composed of objects that are transformed rel. the 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_assembly1(self): """Tests the assembly after one iteration""" self.engine = TracerEngine(self.assembly) ans = self.engine.ray_tracer(self._bund, 1, .05) params = N.arctan(ans[1][1] / ans[1][2]) correct_params = N.r_[0.7853981, 0] N.testing.assert_array_almost_equal(params, correct_params) def test_assembly2(self): """Tests the assembly after two iterations""" self.engine = TracerEngine(self.assembly) params = self.engine.ray_tracer(self._bund, 2, .05)[0] correct_params = N.c_[[0, -1, 1], [0, -1, 1], [0, 0, 1]] N.testing.assert_array_almost_equal(params, correct_params) def test_assembly3(self): """Tests the assembly after three iterations""" self.engine = TracerEngine(self.assembly) params = self.engine.ray_tracer(self._bund, 3, .05)[0] correct_params = N.c_[[0, -2.069044, -1], [0, 0, -1]] N.testing.assert_array_almost_equal(params, correct_params)
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): 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)
class TestAssemblyBuilding3(unittest.TestCase): """Tests an assembly composed of objects that are transformed rel. the 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_assembly1(self): """Tests the assembly after one iteration""" self.engine = TracerEngine(self.assembly) ans = self.engine.ray_tracer(self._bund,1,.05) params = N.arctan(ans[1][1]/ans[1][2]) correct_params = N.r_[0.7853981, 0] N.testing.assert_array_almost_equal(params, correct_params) def test_assembly2(self): """Tests the assembly after two iterations""" self.engine = TracerEngine(self.assembly) params = self.engine.ray_tracer(self._bund,2,.05)[0] correct_params = N.c_[[0,-1,1], [0,-1,1],[0,0,1]] N.testing.assert_array_almost_equal(params, correct_params) def test_assembly3(self): """Tests the assembly after three iterations""" self.engine = TracerEngine(self.assembly) params = self.engine.ray_tracer(self._bund, 3,.05)[0] correct_params = N.c_[[0,-2.069044,-1],[0,0,-1]] N.testing.assert_array_almost_equal(params, correct_params)
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 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 TestTree(unittest.TestCase): """Tests an assembly composed of objects""" 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 test_tree1(self): """Tests that the tracing tree works, with three rays""" x = 1. / (math.sqrt(2)) dir = N.c_[[0, x, x], [0, -x, x], [0, 0, 1.]] position = N.c_[[0, 0, 2.], [0, 0, 2.], [0, 0., 2.]] bund = RayBundle(position, dir, energy=N.ones(3)) self.engine = TracerEngine(self.assembly) self.engine.ray_tracer(bund, 3, .05)[0] params = self.engine.tree.ordered_parents() correct_params = [N.r_[0, 1, 2], N.r_[1, 2], N.r_[0]] N.testing.assert_equal(params, correct_params) def test_tree2(self): """Tests that the tracing tree works, with a new set of rays""" x = 1. / (math.sqrt(2)) position = N.c_[[0, 0., -5.], [0, 0., 2.], [0, 2., -5.], [0, 0., 0], [0, 0, 2.]] dir = N.c_[[0, 0, 1.], [0, x, -x], [0, 0, -1.], [0, 0, 1.], [0, -x, x]] bund = RayBundle(position, dir, energy=N.ones(5)) self.engine = TracerEngine(self.assembly) self.engine.ray_tracer(bund, 3, .05)[0] params = self.engine.tree.ordered_parents() correct_params = [N.r_[0, 1, 3, 4], N.r_[2, 3, 1], N.r_[2, 1]] N.testing.assert_equal(params, correct_params)
class TestTree(unittest.TestCase): """Tests an assembly composed of objects""" 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 test_tree1(self): """Tests that the tracing tree works, with three rays""" x = 1./(math.sqrt(2)) dir = N.c_[[0,x,x],[0,-x,x],[0,0,1.]] position = N.c_[[0,0,2.],[0,0,2.],[0,0.,2.]] bund = RayBundle(position, dir, energy=N.ones(3)) self.engine = TracerEngine(self.assembly) self.engine.ray_tracer(bund,3,.05)[0] params = self.engine.tree.ordered_parents() correct_params = [N.r_[0,1,2],N.r_[1,2],N.r_[0]] N.testing.assert_equal(params, correct_params) def test_tree2(self): """Tests that the tracing tree works, with a new set of rays""" x = 1./(math.sqrt(2)) position = N.c_[[0,0.,-5.],[0,0.,2.],[0,2.,-5.],[0,0.,0],[0,0,2.]] dir = N.c_[[0,0,1.],[0,x,-x],[0,0,-1.],[0,0,1.],[0,-x,x]] bund = RayBundle(position, dir, energy=N.ones(5)) self.engine = TracerEngine(self.assembly) self.engine.ray_tracer(bund,3,.05)[0] params = self.engine.tree.ordered_parents() correct_params = [N.r_[0,1,3,4],N.r_[2,3,1],N.r_[2,1]] N.testing.assert_equal(params, correct_params)
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): 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)
class TestAssemblyBuilding4(unittest.TestCase): """Tests an assembly composed of objects""" 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 test_paraboloid1(self): """Tests a paraboloid""" self.engine = TracerEngine(self.assembly) params = self.engine.ray_tracer(self._bund,1,.05)[0] correct_params = N.c_[[0,0,0],[0,0.618033989, 0.381966011]] N.testing.assert_array_almost_equal(params, correct_params)
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): 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 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)
class TestAssemblyBuilding4(unittest.TestCase): """Tests an assembly composed of objects""" 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 test_paraboloid1(self): """Tests a paraboloid""" self.engine = TracerEngine(self.assembly) params = self.engine.ray_tracer(self._bund, 1, .05)[0] correct_params = N.c_[[0, 0, 0], [0, 0.618033989, 0.381966011]] N.testing.assert_array_almost_equal(params, correct_params)
class TestObjectBuilding1(unittest.TestCase): """Tests an object composed of sphere surfaces""" 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 test_object(self): """Tests that the assembly heirarchy works at a basic level""" self.engine = TracerEngine(self.assembly) inters = self.engine.ray_tracer(self._bund, 1, .05)[0] correct_inters = N.c_[[0, 0, 2], [0, 0, -2]] N.testing.assert_array_almost_equal(inters, correct_inters) def test_translation(self): """Tests an assembly that has been translated""" trans = N.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 1], [0, 0, 0, 1]]) self.assembly.transform_children(trans) self.engine = TracerEngine(self.assembly) params = self.engine.ray_tracer(self._bund, 1, .05)[0] correct_params = N.c_[[0, 0, 3], [0, 0, -1]] N.testing.assert_array_almost_equal(params, correct_params) def test_rotation_and_translation(self): """Tests an assembly that has been translated and rotated""" self._bund = RayBundle() self._bund.set_vertices(N.c_[[0, -5, 1], [0, 5, 1]]) self._bund.set_directions(N.c_[[0, 1, 0], [0, 1, 0]]) self._bund.set_energy(N.r_[[1, 1]]) self._bund.set_ref_index(N.r_[[1, 1]]) trans = generate_transform(N.r_[[1, 0, 0]], N.pi / 2, N.c_[[0, 0, 1]]) self.assembly.transform_children(trans) self.engine = TracerEngine(self.assembly) params = self.engine.ray_tracer(self._bund, 1, .05)[0] correct_params = N.c_[[0, -2, 1]] N.testing.assert_array_almost_equal(params, correct_params)