def runTest(self):
        nx, ny, nz, str_f, pt0, pt1, is_array, mpi_type = self.args

        slices = common.slice_index_two_points(pt0, pt1)

        # generate random source
        if is_array:
            shape = common.shape_two_points(pt0, pt1)
            value = np.random.rand(*shape).astype(np.float32)
        else:
            value = np.random.ranf()

        # instance
        fields = Fields(nx, ny, nz, '', 'single', 0, mpi_type=mpi_type)

        tfunc = lambda tstep: np.sin(0.03*tstep)
        incident = DirectIncident(fields, str_f, pt0, pt1, tfunc, value) 

        # host allocations
        eh = np.zeros(fields.ns_pitch, dtype=fields.dtype)
        getf = GetFields(fields, str_f, pt0, pt1)

        # verify
        eh[slices] = fields.dtype(value) * fields.dtype(tfunc(1))
        fields.update_e()
        fields.update_h()
        fields.enqueue_barrier()

        original = eh[slices]
        getf.get_event().wait()
        copy = getf.get_fields()
        norm = np.linalg.norm(original - copy)
        self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
	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 runTest(self):
        nx, ny, nz, str_f, pt0, pt1, is_array, mpi_type = self.args

        slices = common.slice_index_two_points(pt0, pt1)

        # generate random source
        if is_array:
            shape = common.shape_two_points(pt0, pt1)
            value = np.random.rand(*shape).astype(np.float32)
        else:
            value = np.random.ranf()

        # instance
        fields = Fields(nx, ny, nz, '', 'single', 0, mpi_type=mpi_type)

        tfunc = lambda tstep: np.sin(0.03 * tstep)
        incident = DirectIncident(fields, str_f, pt0, pt1, tfunc, value)

        # host allocations
        eh = np.zeros(fields.ns_pitch, dtype=fields.dtype)
        getf = GetFields(fields, str_f, pt0, pt1)

        # verify
        eh[slices] = fields.dtype(value) * fields.dtype(tfunc(1))
        fields.update_e()
        fields.update_h()
        fields.enqueue_barrier()

        original = eh[slices]
        getf.get_event().wait()
        copy = getf.get_fields()
        norm = np.linalg.norm(original - copy)
        self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
    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 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
Exemplo n.º 10
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
Exemplo n.º 11
0
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1 = 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')
        getf = GetFields(fields, str_f, pt0, pt1) 
        
        # host allocations
        ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype)
        eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs) )
        fields.set_ehs(*ehs)

        # verify
        getf.get_event().wait()

        for str_f in str_fs:
            original = eh_dict[str_f][slice_xyz]
            copy = getf.get_fields(str_f)
            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 = 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')
        getf = GetFields(fields, str_f, pt0, pt1)

        # host allocations
        ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype)
        eh_dict = dict(zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs))
        fields.set_ehs(*ehs)

        # verify
        getf.get_event().wait()

        for str_f in str_fs:
            original = eh_dict[str_f][slice_xyz]
            copy = getf.get_fields(str_f)
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
Exemplo n.º 13
0
print fields.instance_list

# plot
import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure(figsize=(12,8))
imag = plt.imshow(np.zeros((nx, ny), fields.dtype).T, interpolation='nearest', origin='lower', vmin=-1.1, vmax=1.1)
plt.colorbar()

# main loop
from datetime import datetime
t0 = datetime.now()

for tstep in xrange(1, tmax+1):
    fields.update_e()
    fields.update_h()

    if tstep % tgap == 0:
        print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)),
        sys.stdout.flush()

        getf.get_event().wait()
        imag.set_array( getf.get_fields().T )
        #plt.savefig('./png/%.6d.png' % tstep)
        plt.draw()

plt.show()
print('\n[%s] %d/%d (%d %%)' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100))
print('')
Exemplo n.º 14
0
# main loop
from datetime import datetime
from time import time
t0 = datetime.now()
t00 = time()

gtmp = GetFields(fields, 'ez', (0, 0, 0), (0, 0, 0))
gtmp2 = GetFields(fields2, 'ez', (0, 0, 0), (0, 0, 0))
for tstep in xrange(1, tmax + 1):
    fields.update_e()
    fields2.update_e()
    fields.update_h()
    fields2.update_h()
    '''
    if tstep % tgap == 0:
        print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)),
        sys.stdout.flush()

        getf.get_event().wait()
        imag.set_array( getf.get_fields().T )
        #plt.savefig('./png/%.6d.png' % tstep)
        plt.draw()
    '''

#plt.show()
gtmp.get_event().wait()
gtmp2.get_event().wait()
dt = time() - t00
print dt / tmax
#print('[%s] %d/%d (%d %%) %f Mpoint/s' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100, nx*ny*nz*tmax/dt/1e6) )
Exemplo n.º 15
0
from datetime import datetime
from time import time
t0 = datetime.now()
t00 = time()

gtmp = GetFields(fields, 'ez', (0, 0, 0), (0, 0, 0))
gtmp2 = GetFields(fields2, 'ez', (0, 0, 0), (0, 0, 0))
for tstep in xrange(1, tmax+1):
    fields.update_e()
    fields2.update_e()
    fields.update_h()
    fields2.update_h()

    '''
    if tstep % tgap == 0:
        print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)),
        sys.stdout.flush()

        getf.get_event().wait()
        imag.set_array( getf.get_fields().T )
        #plt.savefig('./png/%.6d.png' % tstep)
        plt.draw()
    '''

#plt.show()
gtmp.get_event().wait()
gtmp2.get_event().wait()
dt = time() - t00
print dt/tmax
#print('[%s] %d/%d (%d %%) %f Mpoint/s' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100, nx*ny*nz*tmax/dt/1e6) )
Exemplo n.º 16
0
for tstep in xrange(1, tmax+1):
    fields.update_e()
    fields.update_h()

    if tstep % tgap == 0:
        print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)),
        sys.stdout.flush()

        '''
        getf.get_event().wait()
        imag.set_array( getf.get_fields().T )
        #plt.savefig('./png/%.6d.png' % tstep)
        plt.draw()
     '''
    
getf.get_event().wait()

# plot
import matplotlib.pyplot as plt
#plt.ion()
fig = plt.figure(figsize=(12,8))
imag = plt.imshow(np.zeros((ny, nz), fields.dtype).T, interpolation='nearest', origin='lower', vmin=-1.1, vmax=1.1)
plt.xlabel('y')
plt.ylabel('z')
plt.colorbar()

from matplotlib.patches import Rectangle
rects = [Rectangle((ny-npml, 0), npml, nz, alpha=0.1), \
         Rectangle((0, 0), npml, nz, alpha=0.1), \
         Rectangle((0, nz-npml), ny, npml, alpha=0.1), \
         Rectangle((0, 0), ny, npml, alpha=0.1)]
Exemplo n.º 17
0
plt.colorbar()


# Main loop
from datetime import datetime
t0 = datetime.now()

for tstep in xrange(1, tmax+1):
	fdtd.update_e()
	src.update(tstep)

	fdtd.update_h()

	if tstep % tgap == 0:
		print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)),
		sys.stdout.flush()

		output.get_event().wait()
		imag.set_array(output.get_fields().T**2 )
		#plt.savefig('./single.png')
		plt.draw()

print('[%s] %d/%d (%d %%)' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100))
'''
imag.set_array(fdtd.ez[:,:,nz/5*4].T**2 )
plt.savefig('./simple.png')
plt.show()
'''

print('')