コード例 #1
0
ファイル: test_objects.py プロジェクト: casselineau/Tracer
    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))
コード例 #2
0
ファイル: test_tracer_tree.py プロジェクト: kraken22/Tracer
    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)
コード例 #3
0
ファイル: test_objects.py プロジェクト: pcacunar/Tracer
    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))
コード例 #4
0
ファイル: test_objects.py プロジェクト: casselineau/Tracer
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)
コード例 #5
0
ファイル: test_objects.py プロジェクト: pcacunar/Tracer
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)
コード例 #6
0
ファイル: test_tracer_engine.py プロジェクト: joewan/tracer
 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)
コード例 #7
0
    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)
コード例 #8
0
ファイル: test_objects.py プロジェクト: pcacunar/Tracer
    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)
コード例 #9
0
ファイル: test_objects.py プロジェクト: casselineau/Tracer
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)
コード例 #10
0
ファイル: test_tracer_engine.py プロジェクト: joewan/tracer
    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)
コード例 #11
0
    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)
コード例 #12
0
ファイル: test_objects.py プロジェクト: pcacunar/Tracer
    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))
コード例 #13
0
    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)
コード例 #14
0
ファイル: test_tracer_tree.py プロジェクト: kraken22/Tracer
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)
コード例 #15
0
    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)
コード例 #16
0
ファイル: test_tracer_engine.py プロジェクト: joewan/tracer
    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)
コード例 #17
0
ファイル: test_tracer_tree.py プロジェクト: kraken22/Tracer
    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)
コード例 #18
0
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)
コード例 #19
0
ファイル: test_objects.py プロジェクト: pcacunar/Tracer
    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))
コード例 #20
0
    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)
コード例 #21
0
ファイル: test_objects.py プロジェクト: casselineau/Tracer
 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))
コード例 #22
0
ファイル: test_objects.py プロジェクト: casselineau/Tracer
 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)
コード例 #23
0
ファイル: test_objects.py プロジェクト: casselineau/Tracer
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)
コード例 #24
0
ファイル: test_tracer_engine.py プロジェクト: joewan/tracer
    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)
コード例 #25
0
    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)
コード例 #26
0
ファイル: test_objects.py プロジェクト: pcacunar/Tracer
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)
コード例 #27
0
    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)
コード例 #28
0
ファイル: test_tracer_tree.py プロジェクト: kraken22/Tracer
    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))
コード例 #29
0
ファイル: test_objects.py プロジェクト: casselineau/Tracer
    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))
コード例 #30
0
ファイル: test_objects.py プロジェクト: pcacunar/Tracer
    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.])
コード例 #31
0
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
コード例 #32
0
ファイル: test_tracer_engine.py プロジェクト: joewan/tracer
    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)
コード例 #33
0
ファイル: test_objects.py プロジェクト: pcacunar/Tracer
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)
コード例 #34
0
ファイル: test_objects.py プロジェクト: pcacunar/Tracer
class TestNestedAssemblies(unittest.TestCase):
    """
    Create an assembly within an assembly, with an object, and check that 
    all transformation activities are handled correctly.
    """
    flat_only = True

    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 test_initial_transforms(self):
        """Initial consrtruction yielded correct permanent and temporary transforms"""
        quarter_circle_trans = N.dot(self.eighth_circle_trans,
                                     self.eighth_circle_trans)

        # Surface transforms:
        N.testing.assert_array_almost_equal(self.surf._transform, N.eye(4))
        N.testing.assert_array_almost_equal(self.surf._temp_frame,
                                            quarter_circle_trans)

        # Object transform:
        N.testing.assert_array_almost_equal(self.obj.get_transform(),
                                            self.eighth_circle_trans)

        # Subassembly transform:
        N.testing.assert_array_almost_equal(self.sub_assembly.get_transform(),
                                            self.eighth_circle_trans)

    def test_retransform_object(self):
        """Changing an object's transform yield's correct resaults after retransform"""
        self.obj.set_transform(N.eye(4))
        self.assembly.transform_children()

        # Surface transforms:
        N.testing.assert_array_almost_equal(self.surf._transform, N.eye(4))
        N.testing.assert_array_almost_equal(self.surf._temp_frame,
                                            self.eighth_circle_trans)

        # Object transform:
        N.testing.assert_array_almost_equal(self.obj.get_transform(), N.eye(4))

        # Subassembly transform:
        N.testing.assert_array_almost_equal(self.sub_assembly.get_transform(),
                                            self.eighth_circle_trans)

    def test_retransform_subassembly(self):
        """Changing an assembly's transform yield's correct resaults after retransform"""
        self.sub_assembly.set_transform(N.eye(4))
        self.assembly.transform_children()

        # Surface transforms:
        N.testing.assert_array_almost_equal(self.surf._transform, N.eye(4))
        N.testing.assert_array_almost_equal(self.surf._temp_frame,
                                            self.eighth_circle_trans)

        # Object transform:
        N.testing.assert_array_almost_equal(self.obj.get_transform(),
                                            self.eighth_circle_trans)

        # Subassembly transform:
        N.testing.assert_array_almost_equal(self.sub_assembly.get_transform(),
                                            N.eye(4))

    def test_interface(self):
        """Can call getters on an assembly etc."""
        subs = self.assembly.get_assemblies()
        self.assertEqual(len(subs), 1)
        self.assertTrue(subs[0] is self.sub_assembly)
コード例 #35
0
ファイル: test_objects.py プロジェクト: casselineau/Tracer
class TestNestedAssemblies(unittest.TestCase):
    """
    Create an assembly within an assembly, with an object, and check that 
    all transformation activities are handled correctly.
    """
    flat_only = True
    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 test_initial_transforms(self):
        """Initial consrtruction yielded correct permanent and temporary transforms"""
        quarter_circle_trans = N.dot(self.eighth_circle_trans, self.eighth_circle_trans)
        
        # Surface transforms:
        N.testing.assert_array_almost_equal(self.surf._transform, N.eye(4))
        N.testing.assert_array_almost_equal(self.surf._temp_frame, quarter_circle_trans)
        
        # Object transform:
        N.testing.assert_array_almost_equal(self.obj.get_transform(),
            self.eighth_circle_trans)
        
        # Subassembly transform:
        N.testing.assert_array_almost_equal(self.sub_assembly.get_transform(),
            self.eighth_circle_trans)
    
    def test_retransform_object(self):
        """Changing an object's transform yield's correct resaults after retransform"""
        self.obj.set_transform(N.eye(4))
        self.assembly.transform_children()
        
        # Surface transforms:
        N.testing.assert_array_almost_equal(self.surf._transform, N.eye(4))
        N.testing.assert_array_almost_equal(self.surf._temp_frame, 
            self.eighth_circle_trans)
        
        # Object transform:
        N.testing.assert_array_almost_equal(self.obj.get_transform(),
            N.eye(4))
        
        # Subassembly transform:
        N.testing.assert_array_almost_equal(self.sub_assembly.get_transform(),
            self.eighth_circle_trans)
    
    def test_retransform_subassembly(self):
        """Changing an assembly's transform yield's correct resaults after retransform"""
        self.sub_assembly.set_transform(N.eye(4))
        self.assembly.transform_children()

        # Surface transforms:
        N.testing.assert_array_almost_equal(self.surf._transform, N.eye(4))
        N.testing.assert_array_almost_equal(self.surf._temp_frame,
            self.eighth_circle_trans)
        
        # Object transform:
        N.testing.assert_array_almost_equal(self.obj.get_transform(),
            self.eighth_circle_trans)
        
        # Subassembly transform:
        N.testing.assert_array_almost_equal(self.sub_assembly.get_transform(),
            N.eye(4))
    
    def test_interface(self):
        """Can call getters on an assembly etc."""
        subs = self.assembly.get_assemblies()
        self.assertEqual(len(subs), 1)
        self.assertTrue(subs[0] is self.sub_assembly)