# boundary exchange
    args_list1 = [(nx, ny, nz, str_f, pt0, pt1) \
            for str_f, pt0, pt1 in [
                    [('ey', 'ez'), (0, 0, 0), (0, ny-2, nz-2)], 
                    [('ex', 'ez'), (0, 0, 0), (nx-2, 0, nz-2)],
                    [('ex', 'ey'), (0, 0, 0), (nx-2, ny-2, 0)],
                    [('hy', 'hz'), (nx-1, 1, 1), (nx-1, ny-1, nz-1)],
                    [('hx', 'hz'), (1, ny-1, 1), (nx-1, ny-1, nz-1)],
                    [('hx', 'hy'), (1, 1, nz-1), (nx-1, ny-1, nz-1)] ]]
    suite.addTests(TestGetFields(args) for args in args_list1)

    # random sets
    args_list2 = [(nx, ny, nz, str_f, pt0, pt1) \
            for str_f in ['ex', 'ey', 'ez', 'hx', 'hy', 'hz'] \
            for shape in ['point', 'line', 'plane', 'volume'] \
            for pt0, pt1 in common_random.set_two_points(shape, *ns) ]
    suite.addTests(TestGetFields(args) for args in args_list2) 


    # Test SetFieds
    # single sets
    suite.addTest(TestSetFields( (nx, ny, nz, 'ex', (0, 1, 0), (0, 1, nz-1), False) ))
    suite.addTest(TestSetFields( (nx, ny, nz, ['ex', 'ey'], (0, 1, 0), (0, 1, nz-1), False) ))
    suite.addTest(TestSetFields( (nx, ny, nz, 'ex', (0, 1, 0), (0, 1, nz-1), True) ))
    suite.addTest(TestSetFields( (nx, ny, nz, ['ex', 'ey'], (0, 1, 0), (0, 1, nz-1), True) ))

    # boundary exchange
    args_list3 = [(nx, ny, nz, str_f, pt0, pt1, is_array) \
            for str_f, pt0, pt1, is_array in [
                    [('ey', 'ez'), (0, 0, 0), (0, ny-2, nz-2), True], 
                    [('ex', 'ez'), (0, 0, 0), (nx-2, 0, nz-2), True],
        cl.enqueue_copy(fields.queue, copy_eh, copy_eh_buf)

        original = eh[slice_xyz]
        copy = copy_eh[slice_xyz]
        norm = np.linalg.norm(original - copy)
        self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))



if __name__ == '__main__':
    ns = nx, ny, nz = 40, 50, 60
    suite = unittest.TestSuite() 
    suite.addTest(TestIncidentDirect( (nx, ny, nz, 'ex', (0, 1, 2), (0, 1, nz-3), False) ))
    suite.addTest(TestIncidentDirect( (nx, ny, nz, 'ex', (9, 0, 0), (9, 49, 59), True) ))
    suite.addTest(TestIncidentDirect( (nx, ny, nz, 'ex', (0, 0, 0), (39, 49, 59), True) ))
    suite.addTest(TestIncidentDirect( (nx, ny, nz, 'ex', (0, 27, 22), (29, 47, 53), True) ))
    suite.addTest(TestIncidentDirect( (nx, ny, nz, 'ex', (4, 8, 44), (4, 8, 44), False) ))
    suite.addTest(TestIncidentDirect( (nx, ny, nz, 'ex', (4, 8, 44), (4, 8, 44), True) ))

    # random sets
    args_list = [(nx, ny, nz, str_f, pt0, pt1, is_array) \
            for str_f in ['ex', 'ey', 'ez', 'hx', 'hy', 'hz'] \
            for shape in ['point', 'line', 'plane', 'volume'] \
            for pt0, pt1 in common_random.set_two_points(shape, nx, ny, nz) \
            for is_array in [False, True] ]
    test_size = int( len(args_list)*0.1 )
    test_list = [args_list.pop( np.random.randint(len(args_list)) ) for i in xrange(test_size)]
    suite.addTests(TestIncidentDirect(args) for args in test_list) 

    unittest.TextTestRunner().run(suite) 
    # boundary exchange
    args_list1 = [(nx, ny, nz, str_f, pt0, pt1) \
            for str_f, pt0, pt1 in [
                    [('ey', 'ez'), (0, 0, 0), (0, ny-2, nz-2)], 
                    [('ex', 'ez'), (0, 0, 0), (nx-2, 0, nz-2)],
                    [('ex', 'ey'), (0, 0, 0), (nx-2, ny-2, 0)],
                    [('hy', 'hz'), (nx-1, 1, 1), (nx-1, ny-1, nz-1)],
                    [('hx', 'hz'), (1, ny-1, 1), (nx-1, ny-1, nz-1)],
                    [('hx', 'hy'), (1, 1, nz-1), (nx-1, ny-1, nz-1)] ]]
    suite.addTests(TestGetFields(args) for args in args_list1)

    # random sets
    args_list2 = [(nx, ny, nz, str_f, pt0, pt1) \
            for str_f in ['ex', 'ey', 'ez', 'hx', 'hy', 'hz'] \
            for shape in ['point', 'line', 'plane', 'volume'] \
            for pt0, pt1 in common_random.set_two_points(shape, *ns) ]
    test_size2 = int( len(args_list2)*0.1 )
    test_list2 = [args_list2.pop( np.random.randint(len(args_list2)) ) for i in xrange(test_size2)]
    suite.addTests(TestGetFields(args) for args in test_list2) 


    # Test SetFieds
    # single sets
    suite.addTest(TestSetFields( (nx, ny, nz, 'ex', (0, 1, 0), (0, 1, nz-1), False) ))
    suite.addTest(TestSetFields( (nx, ny, nz, ['ex', 'ey'], (0, 1, 0), (0, 1, nz-1), False) ))
    suite.addTest(TestSetFields( (nx, ny, nz, 'ex', (0, 1, 0), (0, 1, nz-1), True) ))
    suite.addTest(TestSetFields( (nx, ny, nz, ['ex', 'ey'], (0, 1, 0), (0, 1, nz-1), True) ))

    # boundary exchange
    args_list3 = [(nx, ny, nz, str_f, pt0, pt1, is_array) \
            for str_f, pt0, pt1, is_array in [
Beispiel #4
0
    suite = unittest.TestSuite()
    suite.addTest(
        TestIncidentDirect(
            (nx, ny, nz, 'ex', (0, 1, 2), (0, 1, nz - 3), False)))
    suite.addTest(
        TestIncidentDirect((nx, ny, nz, 'ex', (9, 0, 0), (9, 49, 59), True)))
    suite.addTest(
        TestIncidentDirect((nx, ny, nz, 'ex', (0, 0, 0), (39, 49, 59), True)))
    suite.addTest(
        TestIncidentDirect(
            (nx, ny, nz, 'ex', (0, 27, 22), (29, 47, 53), True)))
    suite.addTest(
        TestIncidentDirect((nx, ny, nz, 'ex', (4, 8, 44), (4, 8, 44), False)))
    suite.addTest(
        TestIncidentDirect((nx, ny, nz, 'ex', (4, 8, 44), (4, 8, 44), True)))

    # random sets
    args_list = [(nx, ny, nz, str_f, pt0, pt1, is_array) \
            for str_f in ['ex', 'ey', 'ez', 'hx', 'hy', 'hz'] \
            for shape in ['point', 'line', 'plane', 'volume'] \
            for pt0, pt1 in common_random.set_two_points(shape, nx, ny, nz) \
            for is_array in [False, True] ]
    test_size = int(len(args_list) * 0.1)
    test_list = [
        args_list.pop(np.random.randint(len(args_list)))
        for i in xrange(test_size)
    ]
    suite.addTests(TestIncidentDirect(args) for args in test_list)

    unittest.TextTestRunner().run(suite)