Ejemplo n.º 1
0
	def verify(s, pt0, pt1):
		print('pt0 = %s, pt1 = %s' % (pt0, pt1))
		slidx = common.get_slice_index(pt0, pt1)
		shape = common.get_shape(pt0, pt1)

		for strf in s.strf_list:
			# non-spatial
			fset = SetFields(s.fdtd, strf, pt0, pt1)
			values = np.random.rand(*shape).astype(s.fdtd.dtype)
			fset.set_fields(values)

			fget = GetFields(s.fdtd, strf, pt0, pt1)
			fget.get_event().wait()
			copy = fget.get_fields(strf)

			assert np.linalg.norm(values - copy) == 0

		if pt0 != pt1:
			for strf in s.strf_list:
				# spatial
				fset = SetFields(s.fdtd, strf, pt0, pt1, np.ndarray)
				values = np.random.rand(*shape).astype(s.fdtd.dtype)
				fset.set_fields(values)

				fget = GetFields(s.fdtd, strf, pt0, pt1)
				fget.get_event().wait()
				copy = fget.get_fields(strf)

				assert np.linalg.norm(values - copy) == 0
    def verify(s, pt0, pt1):
        print('pt0 = %s, pt1 = %s' % (pt0, pt1))
        slidx = common.get_slice_index(pt0, pt1)
        shape = common.get_shape(pt0, pt1)

        for strf in s.strf_list:
            # non-spatial
            fset = SetFields(s.fdtd, strf, pt0, pt1)
            values = np.random.rand(*shape).astype(s.fdtd.dtype)
            fset.set_fields(values)

            fget = GetFields(s.fdtd, strf, pt0, pt1)
            fget.get_event().wait()
            copy = fget.get_fields(strf)

            assert np.linalg.norm(values - copy) == 0

        if pt0 != pt1:
            for strf in s.strf_list:
                # spatial
                fset = SetFields(s.fdtd, strf, pt0, pt1, np.ndarray)
                values = np.random.rand(*shape).astype(s.fdtd.dtype)
                fset.set_fields(values)

                fget = GetFields(s.fdtd, strf, pt0, pt1)
                fget.get_event().wait()
                copy = fget.get_fields(strf)

                assert np.linalg.norm(values - copy) == 0
    def test_boundary(s):
        print('\n-- test boundary (two fields) --')
        shape_dict = {
            'x': (s.ny * 2, s.nz),
            'y': (s.nx * 2, s.nz),
            'z': (s.nx * 2, s.ny)
        }

        print('E fields')
        str_fs_dict = {'x': ['ey', 'ez'], 'y': ['ex', 'ez'], 'z': ['ex', 'ey']}
        pt0_dict = {
            'x': (s.nx - 1, 0, 0),
            'y': (0, s.ny - 1, 0),
            'z': (0, 0, s.nz - 1)
        }
        pt1 = (s.nx - 1, s.ny - 1, s.nz - 1)

        for axis in str_fs_dict.keys():
            print('direction : %s' % axis)
            str_fs = str_fs_dict[axis]
            pt0 = pt0_dict[axis]
            slidx = common.get_slice_index(pt0, pt1)
            fset = SetFields(s.fdtd, str_fs, pt0, pt1, np.ndarray)
            values = np.random.rand(*shape_dict[axis]).astype(s.fdtd.dtype)
            fset.set_fields(values)

            fget = GetFields(s.fdtd, str_fs, pt0, pt1)
            fget.get_event().wait()
            copy = fget.get_fields()

            assert np.linalg.norm(values - copy) == 0

        print('H fields')
        str_fs_dict = {'x': ['hy', 'hz'], 'y': ['hx', 'hz'], 'z': ['hx', 'hy']}
        pt0 = (0, 0, 0)
        pt1_dict = {
            'x': (0, s.ny - 1, s.nz - 1),
            'y': (s.nx - 1, 0, s.nz - 1),
            'z': (s.nx - 1, s.ny - 1, 0)
        }

        for axis in str_fs_dict.keys():
            print('direction : %s' % axis)
            str_fs = str_fs_dict[axis]
            pt1 = pt1_dict[axis]
            slidx = common.get_slice_index(pt0, pt1)
            fset = SetFields(s.fdtd, str_fs, pt0, pt1, np.ndarray)
            values = np.random.rand(*shape_dict[axis]).astype(s.fdtd.dtype)
            fset.set_fields(values)

            fget = GetFields(s.fdtd, str_fs, pt0, pt1)
            fget.get_event().wait()
            copy = fget.get_fields()

            assert np.linalg.norm(values - copy) == 0
Ejemplo n.º 4
0
	def test_boundary(s):
		print('\n-- test boundary (two fields) --')
		shape_dict = {'x':(s.ny*2, s.nz), 'y':(s.nx*2, s.nz), 'z':(s.nx*2, s.ny)}

		print('E fields')
		str_fs_dict = {'x':['ey','ez'], 'y':['ex','ez'], 'z':['ex','ey']}
		pt0_dict = {'x':(s.nx-1, 0, 0), 'y':(0, s.ny-1, 0), 'z':(0, 0, s.nz-1)}
		pt1 = (s.nx-1, s.ny-1, s.nz-1)

		for axis in str_fs_dict.keys():
			print('direction : %s' % axis)
			str_fs = str_fs_dict[axis]
			pt0 = pt0_dict[axis]
			slidx = common.get_slice_index(pt0, pt1)
			fset = SetFields(s.fdtd, str_fs, pt0, pt1, np.ndarray)
			values = np.random.rand(*shape_dict[axis]).astype(s.fdtd.dtype)
			fset.set_fields(values)

			fget = GetFields(s.fdtd, str_fs, pt0, pt1)
			fget.get_event().wait()
			copy = fget.get_fields()

			assert np.linalg.norm(values - copy) == 0


		print('H fields')
		str_fs_dict = {'x':['hy','hz'], 'y':['hx','hz'], 'z':['hx','hy']}
		pt0 = (0, 0, 0)
		pt1_dict = {'x':(0, s.ny-1, s.nz-1), 'y':(s.nx-1, 0, s.nz-1), 'z':(s.nx-1, s.ny-1, 0)}

		for axis in str_fs_dict.keys():
			print('direction : %s' % axis)
			str_fs = str_fs_dict[axis]
			pt1 = pt1_dict[axis]
			slidx = common.get_slice_index(pt0, pt1)
			fset = SetFields(s.fdtd, str_fs, pt0, pt1, np.ndarray)
			values = np.random.rand(*shape_dict[axis]).astype(s.fdtd.dtype)
			fset.set_fields(values)

			fget = GetFields(s.fdtd, str_fs, pt0, pt1)
			fget.get_event().wait()
			copy = fget.get_fields()

			assert np.linalg.norm(values - copy) == 0
Ejemplo n.º 5
0
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1, is_array = self.args

        slice_xyz = common.slice_index_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        fields = Fields(nx, ny, nz, '', 'single')
        setf = SetFields(fields, str_f, pt0, pt1, is_array) 
        
        # generate random source
        if is_array:
            shape = common.shape_two_points(pt0, pt1, len(str_fs))
            value = np.random.rand(*shape).astype(fields.dtype)
            split_value = np.split(value, len(str_fs))
            split_value_dict = dict( zip(str_fs, split_value) )
        else:
            value = np.random.ranf()

        # host allocations
        ehs = [np.zeros(fields.ns, dtype=fields.dtype) for i in range(6)]
        eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs) )

        # verify
        for str_f in str_fs:
            if is_array:
                eh_dict[str_f][slice_xyz] = split_value_dict[str_f]
            else:
                eh_dict[str_f][slice_xyz] = value

        setf.set_fields(value)
        fields.enqueue_barrier()

        for str_f in str_fs:
            original = eh_dict[str_f]
            copy = fields.get(str_f)[:,:,fields.slice_z]
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1, is_array = self.args

        slice_xyz = common.slice_index_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        fields = Fields(nx, ny, nz, '', 'single')
        setf = SetFields(fields, str_f, pt0, pt1, is_array)

        # generate random source
        if is_array:
            shape = common.shape_two_points(pt0, pt1, len(str_fs))
            value = np.random.rand(*shape).astype(fields.dtype)
            split_value = np.split(value, len(str_fs))
            split_value_dict = dict(zip(str_fs, split_value))
        else:
            value = np.random.ranf()

        # host allocations
        ehs = [np.zeros(fields.ns, dtype=fields.dtype) for i in range(6)]
        eh_dict = dict(zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs))

        # verify
        for str_f in str_fs:
            if is_array:
                eh_dict[str_f][slice_xyz] = split_value_dict[str_f]
            else:
                eh_dict[str_f][slice_xyz] = value

        setf.set_fields(value)
        fields.enqueue_barrier()

        for str_f in str_fs:
            original = eh_dict[str_f]
            copy = fields.get(str_f)[:, :, fields.slice_z]
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))