def test_up_down(self):
        """Rays coming from below are absorbed, from above reflected"""
        going_down = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]] / N.sqrt(3)
        going_up = going_down.copy()
        going_up[2] = 1 / N.sqrt(3)
        
        pos_up = N.c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]]
        pos_down = pos_up.copy()
        pos_down[2] = -1

        bund = RayBundle()
        bund.set_directions(N.hstack((going_down, going_up)))
        bund.set_vertices(N.hstack((pos_up, pos_down)))
        bund.set_energy(N.tile(100, 8))
        bund.set_ref_index(N.tile(1, 8))
        
        gm = FlatGeometryManager()
        prm = gm.find_intersections(N.eye(4), bund)
        absref = optics_callables.AbsorberReflector(0.)
        selector = N.arange(8)
        gm.select_rays(selector)
        outg = absref(gm, bund, selector)
        
        e = outg.get_energy()
        N.testing.assert_array_equal(e[:4], 100)
        N.testing.assert_array_equal(e[4:], 0)
Beispiel #2
0
    def test_up_down(self):
        """Rays coming from below are absorbed, from above reflected"""
        going_down = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]] / N.sqrt(3)
        going_up = going_down.copy()
        going_up[2] = 1 / N.sqrt(3)
        
        pos_up = N.c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]]
        pos_down = pos_up.copy()
        pos_down[2] = -1

        bund = RayBundle()
        bund.set_directions(N.hstack((going_down, going_up)))
        bund.set_vertices(N.hstack((pos_up, pos_down)))
        bund.set_energy(N.tile(100, 8))
        bund.set_ref_index(N.tile(1, 8))
        
        gm = FlatGeometryManager()
        prm = gm.find_intersections(N.eye(4), bund)
        absref = optics_callables.AbsorberReflector(0.)
        selector = N.arange(8)
        gm.select_rays(selector)
        outg = absref(gm, bund, selector)
        
        e = outg.get_energy()
        N.testing.assert_array_equal(e[:4], 100)
        N.testing.assert_array_equal(e[4:], 0)
 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))
Beispiel #4
0
    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)
Beispiel #5
0
    def setUp(self):
        dir = N.c_[[1, 1, 1], [-1, 1, 1], [-1, -1, 1],
                   [1, -1, 1]] / math.sqrt(3)
        position = N.c_[[0, 0, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)
Beispiel #6
0
 def setUp(self):
     """Set up the ray bundle and geometry"""
     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]
     self._bund = RayBundle(position, dir, energy=en)
     
     self.gm = FlatGeometryManager()
     self.prm = self.gm.find_intersections(N.eye(4), self._bund)
Beispiel #7
0
    def setUp(self):
        dir = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1],
                   [1, -1, -1]] / math.sqrt(3)
        position = N.c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        frame = SP.translate(1., 0., 0.)
        self.prm = self.gm.find_intersections(frame, self._bund)
Beispiel #8
0
    def setUp(self):
        s2 = math.sqrt(2)
        dir = N.c_[[1, 0, -s2], [-1, 0, -s2], [-1, -s2, 0],
                   [1, -s2, 0]] / math.sqrt(3)
        position = N.c_[[0, 1 / s2, 1 / s2], [1, 0, s2], [1, s2, 0],
                        [-1, s2, 0]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        frame = SP.generate_transform(N.r_[1., 0, 0], -N.pi / 4.,
                                      N.zeros((3, 1)))
        self.prm = self.gm.find_intersections(frame, self._bund)
class TestBacksideNormals(unittest.TestCase):
    def setUp(self):
        dir = N.c_[[1, 1, 1], [-1, 1, 1], [-1, -1, 1], [1, -1, 1]] / math.sqrt(3)
        position = N.c_[[0,0,-1], [1,-1,-1], [1,1,-1], [-1,1,-1]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)
    
    def test_get_normals(self):
        """A translated flat geometry manager returns parallel normals"""
        self.gm.select_rays(N.arange(4))
        n = self.gm.get_normals()
        N.testing.assert_array_equal(n, N.tile(N.c_[[0, 0, -1]], (1,4)))
Beispiel #10
0
class TestBacksideNormals(unittest.TestCase):
    def setUp(self):
        dir = N.c_[[1, 1, 1], [-1, 1, 1], [-1, -1, 1],
                   [1, -1, 1]] / math.sqrt(3)
        position = N.c_[[0, 0, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)

    def test_get_normals(self):
        """A translated flat geometry manager returns parallel normals"""
        self.gm.select_rays(N.arange(4))
        n = self.gm.get_normals()
        N.testing.assert_array_equal(n, N.tile(N.c_[[0, 0, -1]], (1, 4)))
    def setUp(self):
        dir = N.c_[[1, 1, 1], [-1, 1, 1], [-1, -1, 1], [1, -1, 1]] / math.sqrt(3)
        position = N.c_[[0,0,-1], [1,-1,-1], [1,1,-1], [-1,1,-1]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)
Beispiel #12
0
    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 setUp(self):
     dir = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]] / math.sqrt(3)
     position = N.c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]]
     self._bund = RayBundle(position, dir)
     
     self.gm = FlatGeometryManager()
     frame = SP.translate(1., 0., 0.)
     self.prm = self.gm.find_intersections(frame, self._bund)
class TestFlatGeomTranslated(unittest.TestCase):
    def setUp(self):
        dir = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]] / math.sqrt(3)
        position = N.c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]]
        self._bund = RayBundle(position, dir)
        
        self.gm = FlatGeometryManager()
        frame = SP.translate(1., 0., 0.)
        self.prm = self.gm.find_intersections(frame, self._bund)
        
    def test_find_intersections(self):
        """The correct parametric locations are found for translated flat geometry"""
        self.failUnlessEqual(self.prm.shape, (4,),
            "Shape of parametric location array is wrong: " + \
            str(self.prm.shape))
        N.testing.assert_array_almost_equal(self.prm, N.sqrt(3))
    
    def test_get_normals(self):
        """A translated flat geometry manager returns parallel normals"""
        self.gm.select_rays(N.arange(4))
        n = self.gm.get_normals()
        N.testing.assert_array_equal(n, N.tile(N.c_[[0, 0, 1]], (1,4)))
    
    def test_inters_points_global(self):
        """When translated, a flat surface returns correct intersections"""
        correct_pts = N.zeros((3,4))
        correct_pts[:2,0] = 1
        
        self.gm.select_rays(N.arange(4))
        pts = self.gm.get_intersection_points_global()
        N.testing.assert_array_equal(pts, correct_pts)
Beispiel #15
0
class TestFlatGeomTranslated(unittest.TestCase):
    def setUp(self):
        dir = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1],
                   [1, -1, -1]] / math.sqrt(3)
        position = N.c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        frame = SP.translate(1., 0., 0.)
        self.prm = self.gm.find_intersections(frame, self._bund)

    def test_find_intersections(self):
        """The correct parametric locations are found for translated flat geometry"""
        self.failUnlessEqual(self.prm.shape, (4,),
            "Shape of parametric location array is wrong: " + \
            str(self.prm.shape))
        N.testing.assert_array_almost_equal(self.prm, N.sqrt(3))

    def test_get_normals(self):
        """A translated flat geometry manager returns parallel normals"""
        self.gm.select_rays(N.arange(4))
        n = self.gm.get_normals()
        N.testing.assert_array_equal(n, N.tile(N.c_[[0, 0, 1]], (1, 4)))

    def test_inters_points_global(self):
        """When translated, a flat surface returns correct intersections"""
        correct_pts = N.zeros((3, 4))
        correct_pts[:2, 0] = 1

        self.gm.select_rays(N.arange(4))
        pts = self.gm.get_intersection_points_global()
        N.testing.assert_array_equal(pts, correct_pts)
Beispiel #16
0
 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])
    def setUp(self):
        s2 = math.sqrt(2)
        dir = N.c_[[1, 0, -s2], [-1, 0, -s2], [-1, -s2, 0], [1, -s2, 0]] / math.sqrt(3)
        position = N.c_[[0,1/s2,1/s2], [1,0,s2], [1,s2,0], [-1,s2,0]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        frame = SP.generate_transform(N.r_[1., 0, 0], -N.pi/4., N.zeros((3,1)))
        self.prm = self.gm.find_intersections(frame, self._bund)
Beispiel #18
0
 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])
Beispiel #19
0
 def setUp(self):
     """Set up the ray bundle and geometry"""
     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]
     self._bund = RayBundle(position, dir, energy=en)
     
     self.gm = FlatGeometryManager()
     self.prm = self.gm.find_intersections(N.eye(4), self._bund)
Beispiel #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)
Beispiel #21
0
class TestReflective(unittest.TestCase):
    def setUp(self):
        """Set up the ray bundle and geometry"""
        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]
        self._bund = RayBundle(position, dir, energy=en)

        self.gm = FlatGeometryManager()
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)

    def test_with_absorptivity(self):
        """A correct bundle is generated by reflective, with energy reduced correctly"""
        reflective = optics_callables.Reflective(0.1)
        self.gm.select_rays(N.arange(4))
        outg = reflective(self.gm, self._bund, N.arange(4))

        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.r_[90, 180, 270,
                                                             360])
        N.testing.assert_array_equal(outg.get_parents(), N.arange(4))

    def test_without_absorptivity(self):
        """Perfect mirroring works"""
        reflective = optics_callables.Reflective(0)
        self.gm.select_rays(N.arange(4))
        outg = reflective(self.gm, self._bund, N.arange(4))
        N.testing.assert_array_equal(outg.get_energy(), N.r_[100, 200, 300,
                                                             400])

    def test_receiver(self):
        """A receiver memorizes all lifetime hits"""
        receiver = optics_callables.ReflectiveReceiver()  # Perfect absorber
        self.gm.select_rays(N.arange(4))

        # Round one:
        outg = receiver(self.gm, self._bund, N.arange(4))
        N.testing.assert_array_equal(outg.get_energy(), 0)
        absorbed, hits = receiver.get_all_hits()
        N.testing.assert_array_equal(absorbed, N.r_[100, 200, 300, 400])
        correct_pts = N.zeros((3, 4))
        correct_pts[:2, 0] = 1
        N.testing.assert_array_equal(hits, correct_pts)

        # Round two:
        outg = receiver(self.gm, self._bund, N.arange(4))
        absorbed, hits = receiver.get_all_hits()
        N.testing.assert_array_equal(absorbed,
                                     N.tile(N.r_[100, 200, 300, 400], 2))
        N.testing.assert_array_equal(hits, N.tile(correct_pts, (1, 2)))
Beispiel #22
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)
Beispiel #23
0
 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))
Beispiel #24
0
class TestReflective(unittest.TestCase):
    def setUp(self):
        """Set up the ray bundle and geometry"""
        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]
        self._bund = RayBundle(position, dir, energy=en)
        
        self.gm = FlatGeometryManager()
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)
    
    def test_with_absorptivity(self):
        """A correct bundle is generated by reflective, with energy reduced correctly"""
        reflective = optics_callables.Reflective(0.1)
        self.gm.select_rays(N.arange(4))
        outg = reflective(self.gm, self._bund, N.arange(4))
        
        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.r_[90, 180, 270, 360])
        N.testing.assert_array_equal(outg.get_parents(), N.arange(4))
    
    def test_without_absorptivity(self):
        """Perfect mirroring works"""
        reflective = optics_callables.Reflective(0)
        self.gm.select_rays(N.arange(4))
        outg = reflective(self.gm, self._bund, N.arange(4))
        N.testing.assert_array_equal(outg.get_energy(), N.r_[100, 200, 300, 400])
    
    def test_receiver(self):
        """A receiver memorizes all lifetime hits"""
        receiver = optics_callables.ReflectiveReceiver() # Perfect absorber
        self.gm.select_rays(N.arange(4))
        
        # Round one:
        outg = receiver(self.gm, self._bund, N.arange(4))
        N.testing.assert_array_equal(outg.get_energy(), 0)
        absorbed, hits = receiver.get_all_hits()
        N.testing.assert_array_equal(absorbed, N.r_[100, 200, 300, 400])
        correct_pts = N.zeros((3,4))
        correct_pts[:2,0] = 1
        N.testing.assert_array_equal(hits, correct_pts)
        
        # Round two:
        outg = receiver(self.gm, self._bund, N.arange(4))
        absorbed, hits = receiver.get_all_hits()
        N.testing.assert_array_equal(absorbed, N.tile(N.r_[100, 200, 300, 400], 2))
        N.testing.assert_array_equal(hits, N.tile(correct_pts, (1,2)))
Beispiel #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(FlatGeometryManager(),
                            opt.RefractiveHomogenous(1., 1.5),
                            location=N.r_[0., 0., -0.01])
        front_surf = Surface(FlatGeometryManager(),
                             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)
Beispiel #26
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)
Beispiel #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)
Beispiel #28
0
class TestFlatGeomTilted(unittest.TestCase):
    """Use a flat surface rotated about the x axis by 45 degrees"""
    def setUp(self):
        s2 = math.sqrt(2)
        dir = N.c_[[1, 0, -s2], [-1, 0, -s2], [-1, -s2, 0],
                   [1, -s2, 0]] / math.sqrt(3)
        position = N.c_[[0, 1 / s2, 1 / s2], [1, 0, s2], [1, s2, 0],
                        [-1, s2, 0]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        frame = SP.generate_transform(N.r_[1., 0, 0], -N.pi / 4.,
                                      N.zeros((3, 1)))
        self.prm = self.gm.find_intersections(frame, self._bund)

    def test_find_intersections(self):
        """The correct parametric locations are found for flat geometry"""
        self.failUnlessEqual(self.prm.shape, (4,),
            "Shape of parametric location array is wrong: " + \
            str(self.prm.shape))
        N.testing.assert_array_almost_equal(self.prm, math.sqrt(3))

    def test_get_normals(self):
        """A tilted flat geometry manager returns parallel normals"""
        s2 = math.sqrt(2)
        self.gm.select_rays(N.arange(4))
        n = self.gm.get_normals()
        N.testing.assert_array_almost_equal(
            n, N.tile(N.c_[[0, 1 / s2, 1 / s2]], (1, 4)))

    def test_select_rays_normals(self):
        """A tilted flat geometry manager returns normals only for selected rays"""
        s2 = math.sqrt(2)
        self.gm.select_rays(N.r_[1, 3])
        n = self.gm.get_normals()
        N.testing.assert_array_almost_equal(
            n, N.tile(N.c_[[0, 1 / s2, 1 / s2]], (1, 2)))

    def test_inters_points_global(self):
        """On the basic setup, a tilted flat surface returns correct intersections"""
        correct_pts = N.zeros((3, 4))
        s2 = math.sqrt(2)
        correct_pts[:, 0] = N.r_[1, 1 / s2, -1 / s2]

        self.gm.select_rays(N.arange(4))
        pts = self.gm.get_intersection_points_global()
        N.testing.assert_array_almost_equal(pts, correct_pts)

    def test_select_rays_inters(self):
        """With dropped rays, a tilted flat surface returns correct intersections"""
        s2 = math.sqrt(2)
        correct_pts = N.zeros((3, 2))

        self.gm.select_rays(N.r_[1, 3])
        pts = self.gm.get_intersection_points_global()
        N.testing.assert_array_almost_equal(pts, correct_pts)
class TestFlatGeomManagerInterface(unittest.TestCase):
    def setUp(self):
        dir = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]] / math.sqrt(3)
        position = N.c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)
        
    def test_find_intersections(self):
        """The correct parametric locations are found for flat geometry"""
        self.failUnlessEqual(self.prm.shape, (4,), 
            "Shape of parametric location array is wrong: " + \
            str(self.prm.shape))
        N.testing.assert_array_almost_equal(self.prm, N.sqrt(3))
    
    def test_get_normals(self):
        """A flat geometry manager returns parallel normals"""
        self.gm.select_rays(N.arange(4))
        n = self.gm.get_normals()
        N.testing.assert_array_equal(n, N.tile(N.c_[[0, 0, 1]], (1,4)))
        
    def test_select_rays_normals(self):
        """Correct normals when some rays not selected"""
        self.gm.select_rays(N.r_[1,3])
        n = self.gm.get_normals()
        N.testing.assert_array_equal(n, N.tile(N.c_[[0, 0, 1]], (1,2)))
    
    def test_inters_points_global(self):
        """On the basic setup, a flat surface returns correct intersections"""
        correct_pts = N.zeros((3,4))
        correct_pts[:2,0] = 1
        
        self.gm.select_rays(N.arange(4))
        pts = self.gm.get_intersection_points_global()
        N.testing.assert_array_equal(pts, correct_pts)
        
    def select_rays_inters(self):
        """Correct intersections when some rays not selected"""
        correct_pts = N.zeros((3,2))
        correct_pts[:2,0] = 1
        pts = self.gm.get_intersection_points_global()
        N.testing.assert_array_equal(pts, correct_pts)
class TestFlatGeomTilted(unittest.TestCase):
    """Use a flat surface rotated about the x axis by 45 degrees"""
    def setUp(self):
        s2 = math.sqrt(2)
        dir = N.c_[[1, 0, -s2], [-1, 0, -s2], [-1, -s2, 0], [1, -s2, 0]] / math.sqrt(3)
        position = N.c_[[0,1/s2,1/s2], [1,0,s2], [1,s2,0], [-1,s2,0]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        frame = SP.generate_transform(N.r_[1., 0, 0], -N.pi/4., N.zeros((3,1)))
        self.prm = self.gm.find_intersections(frame, self._bund)
        
    def test_find_intersections(self):
        """The correct parametric locations are found for flat geometry"""
        self.failUnlessEqual(self.prm.shape, (4,), 
            "Shape of parametric location array is wrong: " + \
            str(self.prm.shape))
        N.testing.assert_array_almost_equal(self.prm, math.sqrt(3))
    
    def test_get_normals(self):
        """A tilted flat geometry manager returns parallel normals"""
        s2 = math.sqrt(2)
        self.gm.select_rays(N.arange(4))
        n = self.gm.get_normals()
        N.testing.assert_array_almost_equal(n, N.tile(N.c_[[0,1/s2,1/s2]], (1,4)))
        
    def test_select_rays_normals(self):
        """A tilted flat geometry manager returns normals only for selected rays"""
        s2 = math.sqrt(2)
        self.gm.select_rays(N.r_[1,3])
        n = self.gm.get_normals()
        N.testing.assert_array_almost_equal(n, N.tile(N.c_[[0,1/s2,1/s2]], (1,2)))
    
    def test_inters_points_global(self):
        """On the basic setup, a tilted flat surface returns correct intersections"""
        correct_pts = N.zeros((3,4))
        s2 = math.sqrt(2)
        correct_pts[:,0] = N.r_[1, 1/s2, -1/s2]
        
        self.gm.select_rays(N.arange(4))
        pts = self.gm.get_intersection_points_global()
        N.testing.assert_array_almost_equal(pts, correct_pts)
    
    def test_select_rays_inters(self):
        """With dropped rays, a tilted flat surface returns correct intersections"""
        s2 = math.sqrt(2)
        correct_pts = N.zeros((3,2))
        
        self.gm.select_rays(N.r_[1,3])
        pts = self.gm.get_intersection_points_global()
        N.testing.assert_array_almost_equal(pts, correct_pts)
Beispiel #31
0
class TestFlatGeomManagerInterface(unittest.TestCase):
    def setUp(self):
        dir = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1],
                   [1, -1, -1]] / math.sqrt(3)
        position = N.c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]]
        self._bund = RayBundle(position, dir)

        self.gm = FlatGeometryManager()
        self.prm = self.gm.find_intersections(N.eye(4), self._bund)

    def test_find_intersections(self):
        """The correct parametric locations are found for flat geometry"""
        self.failUnlessEqual(self.prm.shape, (4,),
            "Shape of parametric location array is wrong: " + \
            str(self.prm.shape))
        N.testing.assert_array_almost_equal(self.prm, N.sqrt(3))

    def test_get_normals(self):
        """A flat geometry manager returns parallel normals"""
        self.gm.select_rays(N.arange(4))
        n = self.gm.get_normals()
        N.testing.assert_array_equal(n, N.tile(N.c_[[0, 0, 1]], (1, 4)))

    def test_select_rays_normals(self):
        """Correct normals when some rays not selected"""
        self.gm.select_rays(N.r_[1, 3])
        n = self.gm.get_normals()
        N.testing.assert_array_equal(n, N.tile(N.c_[[0, 0, 1]], (1, 2)))

    def test_inters_points_global(self):
        """On the basic setup, a flat surface returns correct intersections"""
        correct_pts = N.zeros((3, 4))
        correct_pts[:2, 0] = 1

        self.gm.select_rays(N.arange(4))
        pts = self.gm.get_intersection_points_global()
        N.testing.assert_array_equal(pts, correct_pts)

    def select_rays_inters(self):
        """Correct intersections when some rays not selected"""
        correct_pts = N.zeros((3, 2))
        correct_pts[:2, 0] = 1
        pts = self.gm.get_intersection_points_global()
        N.testing.assert_array_equal(pts, correct_pts)