Ejemplo n.º 1
0
class TestTraceProtocol(unittest.TestCase):
    def setUp(self):
        self._surf = Surface(FlatGeometryManager(), perfect_mirror)
        
        dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]]).T / math.sqrt(3)
        position = c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]]
        self._bund = RayBundle(position, dir, energy=N.ones(4)*100)
    
    def test_register_incoming(self):
        """Flat mirror: a simple bundle is registered correctly"""
        correct_params = r_[[math.sqrt(3)]*4]
        params = self._surf.register_incoming(self._bund)
        
        N.testing.assert_array_almost_equal(params, correct_params)
    
    def test_get_outgoing(self):
        """Flat mirror: the correct outgoing bundle is returned"""
        params = self._surf.register_incoming(self._bund)
        self._surf.select_rays(N.arange(4))
        outg = self._surf.get_outgoing()
        
        correct_pts = N.zeros((3,4))
        correct_pts[:2,0] = 1
        N.testing.assert_array_equal(outg.get_vertices(), correct_pts)
        
        correct_dirs = N.c_[[1, 1, 1], [-1, 1, 1], [-1, -1, 1], [1, -1, 1]] / N.sqrt(3)
        N.testing.assert_array_equal(outg.get_directions(), correct_dirs)
        
        N.testing.assert_array_equal(outg.get_energy(), N.ones(4)*100)
        N.testing.assert_array_equal(outg.get_parents(), N.arange(4))
Ejemplo n.º 2
0
class TestParabolicDish(unittest.TestCase):
    def setUp(self):
        pos = N.zeros((3, 4))
        pos[0] = N.r_[0, 0.5, 2, -2]
        pos[2] = 2.
        dir = N.tile(N.c_[[0, 0, -1]], (1, 4))

        self.bund = RayBundle()
        self.bund.set_vertices(pos)
        self.bund.set_directions(dir)

        self.surf = Surface(ParabolicDishGM(2., 1.), opt.perfect_mirror)

    def test_selection_at_origin(self):
        """Simple dish rejects missing rays"""
        misses = N.isinf(self.surf.register_incoming(self.bund))
        N.testing.assert_array_equal(misses, N.r_[False, False, True, True])

    def test_transformed(self):
        """Translated and rotated dish rejects missing rays"""
        trans = generate_transform(N.r_[1., 0., 0.], N.pi / 4.,
                                   N.c_[[0., 0., 1.]])

        self.surf.transform_frame(trans)
        misses = N.isinf(self.surf.register_incoming(self.bund))
        N.testing.assert_array_equal(misses, N.r_[False, False, True, True])

    def test_mesh(self):
        """Parabolic dish mesh looks OK"""
        p = ParabolicDishGM(5, 3)
        x, y, z = p.mesh(5)

        N.testing.assert_array_almost_equal(z, p.a * (x**2 + y**2))
        self.failIf(N.any(x**2 + y**2 > 6.25))
Ejemplo n.º 3
0
class TestParabolicDish(unittest.TestCase):
    def setUp(self):
        pos = N.zeros((3,4))
        pos[0] = N.r_[0, 0.5, 2, -2]
        pos[2] = 2.
        dir = N.tile(N.c_[[0,0,-1]], (1,4))

        self.bund = RayBundle()
        self.bund.set_vertices(pos)
        self.bund.set_directions(dir)

        self.surf = Surface(ParabolicDishGM(2., 1.), opt.perfect_mirror)
    
    def test_selection_at_origin(self):
        """Simple dish rejects missing rays"""
        misses = N.isinf(self.surf.register_incoming(self.bund))
        N.testing.assert_array_equal(misses, N.r_[False, False, True, True])
    
    def test_transformed(self):
        """Translated and rotated dish rejects missing rays"""
        trans = generate_transform(N.r_[1., 0., 0.], N.pi/4., N.c_[[0., 0., 1.]])
        
        self.surf.transform_frame(trans)
        misses = N.isinf(self.surf.register_incoming(self.bund))
        N.testing.assert_array_equal(misses, N.r_[False, False, True, True])
    
    def test_mesh(self):
        """Parabolic dish mesh looks OK"""
        p = ParabolicDishGM(5, 3)
        x, y, z = p.mesh(5)
        
        N.testing.assert_array_almost_equal(z, p.a*(x**2 + y**2))
        self.failIf(N.any(x**2 + y**2 > 6.25))
Ejemplo n.º 4
0
class TestTraceProtocol(unittest.TestCase):
    def setUp(self):
        self._surf = Surface(FlatGeometryManager(), perfect_mirror)

        dir = N.array([[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]
                       ]).T / math.sqrt(3)
        position = c_[[0, 0, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]]
        self._bund = RayBundle(position, dir, energy=N.ones(4) * 100)

    def test_register_incoming(self):
        """Flat mirror: a simple bundle is registered correctly"""
        correct_params = r_[[math.sqrt(3)] * 4]
        params = self._surf.register_incoming(self._bund)

        N.testing.assert_array_almost_equal(params, correct_params)

    def test_get_outgoing(self):
        """Flat mirror: the correct outgoing bundle is returned"""
        params = self._surf.register_incoming(self._bund)
        self._surf.select_rays(N.arange(4))
        outg = self._surf.get_outgoing()

        correct_pts = N.zeros((3, 4))
        correct_pts[:2, 0] = 1
        N.testing.assert_array_equal(outg.get_vertices(), correct_pts)

        correct_dirs = N.c_[[1, 1, 1], [-1, 1, 1], [-1, -1, 1],
                            [1, -1, 1]] / N.sqrt(3)
        N.testing.assert_array_equal(outg.get_directions(), correct_dirs)

        N.testing.assert_array_equal(outg.get_energy(), N.ones(4) * 100)
        N.testing.assert_array_equal(outg.get_parents(), N.arange(4))
Ejemplo n.º 5
0
 def runTest(self):
     pos = N.array([[0, 1.5], [0, -1.5], [1, 0], [-1, 0], [0.1, 0.1], [-0.1, 0.6]])
     bund = RayBundle()
     bund.set_vertices(N.vstack((pos.T, N.ones(pos.shape[0]))))
     bund.set_directions(N.tile(N.c_[[0,0,-1]], (1,6)))
     surf = Surface(HexagonalParabolicDishGM(2., 1.), opt.perfect_mirror)
     
     misses = N.isinf(surf.register_incoming(bund))
     N.testing.assert_array_equal(misses, N.r_[True, True, True, True, False, False])
Ejemplo n.º 6
0
    def runTest(self):
        pos = N.array([[0, 1.5], [0, -1.5], [1, 0], [-1, 0], [0.1, 0.1],
                       [-0.1, 0.6]])
        bund = RayBundle()
        bund.set_vertices(N.vstack((pos.T, N.ones(pos.shape[0]))))
        bund.set_directions(N.tile(N.c_[[0, 0, -1]], (1, 6)))
        surf = Surface(HexagonalParabolicDishGM(2., 1.), opt.perfect_mirror)

        misses = N.isinf(surf.register_incoming(bund))
        N.testing.assert_array_equal(
            misses, N.r_[True, True, True, True, False, False])
Ejemplo n.º 7
0
 def test_selection(self):
     pos = N.zeros((3,4))
     pos[0] = N.r_[0, 0.5, 2, -2]
     pos[2] = 1.
     dir = N.tile(N.c_[[0,0,-1]], (1,4))
     bund = RayBundle(pos, dir)
     
     surf = Surface(RoundPlateGM(1), opt.perfect_mirror)
     misses = N.isinf(surf.register_incoming(bund))
     
     N.testing.assert_array_equal(misses, N.r_[False, False, True, True])
Ejemplo n.º 8
0
	def test_selection(self):
		pos = N.zeros((3,4))
		pos[0] = N.r_[0, 0.05, 0.2, -0.3]
		pos[2] = 1.
		dir = N.tile(N.c_[[0,0,-1]], (1,4))
		bund = RayBundle(pos, dir)
		
		surf = Surface(ExtrudedRectPlateGM(width=1, height=1, extr_center=N.vstack([0.2,0.1]), extr_width=0.2, extr_height=0.4), opt.perfect_mirror)
		misses = N.isinf(surf.register_incoming(bund))

		N.testing.assert_array_equal(misses, N.r_[False, False, True, False])