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
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 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) --') 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 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 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))
import matplotlib.pyplot as plt plt.ion() imag = plt.imshow(fdtd.ez[:,:,nz/2].T, cmap=plt.cm.hot, origin='lower', vmin=0, vmax=0.05) plt.colorbar() # Main loop from datetime import datetime t0 = datetime.now() for tstep in xrange(1, tmax+1): qtask.enqueue(fdtd.update_e) qtask.enqueue(src.update, [tstep]) qtask.enqueue(fdtd.update_h) if tstep % tgap == 0: with LockQueueTask(qtask): f = output.get_fields() print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)), sys.stdout.flush() imag.set_array(f.T**2) 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('')
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('')
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('')
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)] for rect in rects: plt.gca().add_patch(rect) imag.set_array( getf.get_fields().T ) plt.show() #plt.savefig('cpml.png') print('\n[%s] %d/%d (%d %%)' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)) print('')
vmin=0, vmax=0.05) plt.colorbar() # Main loop from datetime import datetime t0 = datetime.now() for tstep in xrange(1, tmax + 1): qtask.enqueue(fdtd.update_e) qtask.enqueue(src.update, [tstep]) qtask.enqueue(fdtd.update_h) if tstep % tgap == 0: with LockQueueTask(qtask): f = output.get_fields() print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep) / tmax * 100)), sys.stdout.flush() imag.set_array(f.T**2) 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('')