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
	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) --')

        print('E fields')
        str_fs_dict = {'x': ['ey', 'ez'], 'y': ['ex', 'ez'], 'z': ['ex', 'ey']}
        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)
            fget = GetFields(s.fdtd, str_fs, pt0, pt1)
            fget.get_event().wait()

            for strf in str_fs:
                original = s.fhosts[strf][slidx]
                copy = fget.get_fields(strf)
                assert np.linalg.norm(original - copy) == 0

        print('H fields')
        str_fs_dict = {'x': ['hy', 'hz'], 'y': ['hx', 'hz'], 'z': ['hx', 'hy']}
        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)
            fget = GetFields(s.fdtd, str_fs, pt0, pt1)
            fget.get_event().wait()

            for strf in str_fs:
                original = s.fhosts[strf][slidx]
                copy = fget.get_fields(strf)
                assert np.linalg.norm(original - 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
	def verify(s, pt0, pt1):
		print('pt0 = %s, pt1 = %s' % (pt0, pt1))
		slidx = common.get_slice_index(pt0, pt1)

		for strf in s.strf_list:
			fget = GetFields(s.fdtd, strf, pt0, pt1)
			fget.get_event().wait()
			original = s.fhosts[strf][slidx]
			copy = fget.get_fields(strf)
			#print original, copy
			assert np.linalg.norm(original - copy) == 0
    def verify(s, pt0, pt1):
        print('pt0 = %s, pt1 = %s' % (pt0, pt1))
        slidx = common.get_slice_index(pt0, pt1)

        for strf in s.strf_list:
            fget = GetFields(s.fdtd, strf, pt0, pt1)
            fget.get_event().wait()
            original = s.fhosts[strf][slidx]
            copy = fget.get_fields(strf)
            #print original, copy
            assert np.linalg.norm(original - copy) == 0
	def test_boundary(s):
		print('\n-- test boundary (two fields) --')

		print('E fields')
		str_fs_dict = {'x':['ey','ez'], 'y':['ex','ez'], 'z':['ex','ey']}
		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)
			fget = GetFields(s.fdtd, str_fs, pt0, pt1)
			fget.get_event().wait()

			for strf in str_fs:
				original = s.fhosts[strf][slidx]
				copy = fget.get_fields(strf)
				assert np.linalg.norm(original - copy) == 0


		print('H fields')
		str_fs_dict = {'x':['hy','hz'], 'y':['hx','hz'], 'z':['hx','hy']}
		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)
			fget = GetFields(s.fdtd, str_fs, pt0, pt1)
			fget.get_event().wait()

			for strf in str_fs:
				original = s.fhosts[strf][slidx]
				copy = fget.get_fields(strf)
				assert np.linalg.norm(original - copy) == 0
    def __init__(s, fields, str_fs, pt0, pt1):
        s.emf = fields
        if type(str_fs) == str:
            s.str_fs = [str_fs]
        else:
            s.str_fs = str_fs

        s.str_fs_size = len(s.str_fs)
        s.slidx = common.get_slice_index(pt0, pt1)
        s.shape = common.get_shape(pt0, pt1)
        s.shape[0] *= s.str_fs_size
        s.fhost = np.zeros(s.shape, dtype=s.emf.dtype)
        s.split_fs = dict(zip(s.str_fs, np.array_split(s.fhost, s.str_fs_size)))
Example #10
0
    def __init__(s, fields, str_fs, pt0, pt1, dtype_values=None):
        s.emf = fields
        if type(str_fs) == str:
            s.str_fs = [str_fs]
        else:
            s.str_fs = str_fs

        s.str_fs_size = len(s.str_fs)
        s.slidx = common.get_slice_index(pt0, pt1)

        if dtype_values == np.ndarray:
            s.func = s.set_fields_spatial_values
        else:
            s.func = s.set_fields_single_value
    def __init__(s, fields, str_fs, pt0, pt1):
        s.emf = fields
        if type(str_fs) == str:
            s.str_fs = [
                str_fs,
            ]
        else:
            s.str_fs = str_fs

        s.str_fs_size = len(s.str_fs)
        s.slidx = common.get_slice_index(pt0, pt1)
        s.shape = common.get_shape(pt0, pt1)
        s.shape[0] *= s.str_fs_size
        s.fhost = np.zeros(s.shape, dtype=s.emf.dtype)
        s.split_fs = dict(zip(s.str_fs, np.array_split(s.fhost,
                                                       s.str_fs_size)))
    def __init__(s, fields, str_fs, pt0, pt1, dtype_values=None):
        s.emf = fields
        if type(str_fs) == str:
            s.str_fs = [
                str_fs,
            ]
        else:
            s.str_fs = str_fs

        s.str_fs_size = len(s.str_fs)
        s.slidx = common.get_slice_index(pt0, pt1)

        if dtype_values == np.ndarray:
            s.func = s.set_fields_spatial_values
        else:
            s.func = s.set_fields_single_value