def runTest(self): nx, ny, nz, str_f, pt0, pt1, is_array = self.args slice_xyz = common.slices_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(0, nx, ny, nz, '', 'single') tfunc = lambda tstep: np.sin(0.03 * tstep) incident = IncidentDirect(fields, str_f, pt0, pt1, tfunc, value) # host allocations eh = np.zeros(fields.ns_pitch, dtype=fields.dtype) # verify eh[slice_xyz] = fields.dtype(value) * fields.dtype(tfunc(1)) fields.update_e() fields.update_h() copy_eh_buf = fields.get_buf(str_f) copy_eh = np.zeros_like(eh) cuda.memcpy_dtoh(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)) fields.context_pop()
def runTest(self): nx, ny, nz, str_f, pt0, pt1, is_array = self.args slice_xyz = common.slices_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(0, nx, ny, nz, '', 'single') tfunc = lambda tstep: np.sin(0.03*tstep) incident = IncidentDirect(fields, str_f, pt0, pt1, tfunc, value) # host allocations eh = np.zeros(fields.ns_pitch, dtype=fields.dtype) # verify eh[slice_xyz] = fields.dtype(value) * fields.dtype(tfunc(1)) fields.update_e() fields.update_h() copy_eh_buf = fields.get_buf(str_f) copy_eh = np.zeros_like(eh) cuda.memcpy_dtoh(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)) fields.context_pop()
def runTest(self): axis, nx, ny, nz, precision_float = self.args gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) device = gpu_devices[0] fields = Fields(context, device, nx, ny, nz, '', precision_float) pbc = Pbc(fields, axis) # allocations ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype) fields.set_eh_bufs(*ehs) # update fields.update_e() fields.update_h() # verify getf0, getf1 = {}, {} strfs_e = {'x':['ey', 'ez'], 'y':['ex', 'ez'], 'z':['ex', 'ey']}[axis] strfs_h = {'x':['hy', 'hz'], 'y':['hx', 'hz'], 'z':['hx', 'hy']}[axis] pt0 = (0, 0, 0) pt1 = { 'x': (0, ny-2, nz-2), \ 'y': (nx-2, 0, nz-2), \ 'z': (nx-2, ny-2, 0) }[axis] getf0['e'] = GetFields(fields, strfs_e, pt0, pt1) pt0 = { 'x': (nx-1, 0, 0), \ 'y': (0, ny-1, 0), \ 'z': (0, 0, nz-1) }[axis] pt1 = { 'x': (nx-1, ny-2, nz-2), \ 'y': (nx-2, ny-1, nz-2), \ 'z': (nx-2, ny-2, nz-1) }[axis] getf1['e'] = GetFields(fields, strfs_e, pt0, pt1) pt0 = { 'x': (0, 1, 1), \ 'y': (1, 0, 1), \ 'z': (1, 1, 0) }[axis] pt1 = { 'x': (0, ny-1, nz-1), \ 'y': (nx-1, 0, nz-1), \ 'z': (nx-1, ny-1, 0) }[axis] getf0['h'] = GetFields(fields, strfs_h, pt0, pt1) pt0 = { 'x': (nx-1, 1, 1), \ 'y': (1, ny-1, 1), \ 'z': (1, 1, nz-1) }[axis] pt1 = (nx-1, ny-1, nz-1) getf1['h'] = GetFields(fields, strfs_h, pt0, pt1) for getf in getf0.values() + getf1.values(): getf.get_event().wait() for eh in ['e', 'h']: norm = np.linalg.norm( \ getf0[eh].get_fields() - getf1[eh].get_fields() ) self.assertEqual(norm, 0, '%g, %s, %s' % (norm, self.args, eh))
def runTest(self): nx, ny, nz, str_f, pt0, pt1, is_array = self.args slice_xyz = common.slices_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 gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) device = gpu_devices[0] qtask = QueueTask() fields = Fields(context, device, qtask, nx, ny, nz, '', 'single') tfunc = lambda tstep: np.sin(0.03*tstep) incident = IncidentDirect(fields, str_f, pt0, pt1, tfunc, value) # host allocations eh = np.zeros(fields.ns_pitch, dtype=fields.dtype) # verify eh[slice_xyz] = fields.dtype(value) * fields.dtype(tfunc(1)) fields.update_e() fields.update_h() fields.enqueue_barrier() copy_eh_buf = fields.get_buf(str_f) copy_eh = np.zeros_like(eh) 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))
def runTest(self): nx, ny, nz, str_f, pt0, pt1, is_array = self.args slice_xyz = common.slices_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 gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) device = gpu_devices[0] qtask = QueueTask() fields = Fields(context, device, qtask, nx, ny, nz, '', 'single') tfunc = lambda tstep: np.sin(0.03 * tstep) incident = IncidentDirect(fields, str_f, pt0, pt1, tfunc, value) # host allocations eh = np.zeros(fields.ns_pitch, dtype=fields.dtype) # verify eh[slice_xyz] = fields.dtype(value) * fields.dtype(tfunc(1)) fields.update_e() fields.update_h() fields.enqueue_barrier() copy_eh_buf = fields.get_buf(str_f) copy_eh = np.zeros_like(eh) 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))
#else: # getf = GetFields(fields, 'ez', (0, 0, 0), (0, 0, 0)) if is_master: print 'ns', fields.ns print 'nbytes (MB)', nx*ny*nz * 9 * 4. / (1024**2) from datetime import datetime from time import time, sleep t0 = datetime.now() t00 = time() # main loop for tstep in xrange(1, tmax+1): fields.update_e() exch.update_e() fields.update_h() exch.update_h() if tstep % 10 == 0 and is_plot: getf.get_event().wait() np.save('rank%d_%d' % (rank, tstep), getf.get_fields()) if is_master: print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)), sys.stdout.flush() for i in range(size): load_fail = True
#else: # getf = GetFields(fields, 'ez', (0, 0, 0), (0, 0, 0)) if is_master: print 'ns', fields.ns print 'nbytes (MB)', nx * ny * nz * 9 * 4. / (1024**2) from datetime import datetime from time import time, sleep t0 = datetime.now() t00 = time() # main loop for tstep in xrange(1, tmax + 1): fields.update_e() exch.update_e() fields.update_h() exch.update_h() if tstep % 10 == 0 and is_plot: getf.get_event().wait() np.save('rank%d_%d' % (rank, tstep), getf.get_fields()) if is_master: print( '[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep) / tmax * 100)), sys.stdout.flush()
# Plot import matplotlib.pyplot as plt plt.ion() imag = plt.imshow(output.get_fields().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): fdtd.update_e() src.update(tstep) pbc.update_e() fdtd.update_h() pbc.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() f = output.get_fields() imag.set_array(f.T**2) #plt.savefig('./simple.png')
output = GetFields(fdtd, 'ex', (1, 0, 0), (1, ny-1, nz-1)) # Plot import matplotlib.pyplot as plt plt.ion() imag = plt.imshow(output.get_fields().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): fdtd.update_e() src.update(tstep) pbc.update_e() fdtd.update_h() pbc.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() f = output.get_fields() imag.set_array(f.T**2 ) #plt.savefig('./simple.png') plt.draw()
def runTest(self): ufunc, nx, ny, nz, coeff_use, precision_float, tmax = self.args gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) device = gpu_devices[0] fields = Fields(context, device, nx, ny, nz, coeff_use, precision_float) core = Core(fields) # allocations ns = fields.ns dtype = fields.dtype strf_list = ["ex", "ey", "ez", "hx", "hy", "hz"] ehs = common_update.generate_random_ehs(nx, ny, nz, dtype, ufunc) fields.set_eh_bufs(*ehs) ces, chs = common_update.generate_random_cs(coeff_use, nx, ny, nz, dtype) if "e" in coeff_use: fields.set_ce_bufs(*ces) if "h" in coeff_use: fields.set_ch_bufs(*chs) tmpf = np.zeros(fields.ns_pitch, dtype=dtype) # update if ufunc == "e": for tstep in xrange(0, tmax): fields.update_e() common_update.update_e(ehs, ces) for strf, eh in zip(strf_list, ehs)[:3]: cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf)) norm = np.linalg.norm(eh - tmpf[:, :, fields.slice_z]) max_diff = np.abs(eh - tmpf[:, :, fields.slice_z]).max() self.assertEqual(norm, 0, "%s, %s, %g, %g" % (self.args, strf, norm, max_diff)) if fields.pad != 0: if strf == "ez": norm2 = np.linalg.norm(tmpf[:, :, -fields.pad :]) else: norm2 = np.linalg.norm(tmpf[:, :, -fields.pad - 1 :]) self.assertEqual(norm2, 0, "%s, %s, %g, padding" % (self.args, strf, norm2)) elif ufunc == "h": for tstep in xrange(0, tmax): fields.update_h() common_update.update_h(ehs, chs) for strf, eh in zip(strf_list, ehs)[3:]: cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf)) norm = np.linalg.norm(eh - tmpf[:, :, fields.slice_z]) max_diff = np.abs(eh - tmpf[:, :, fields.slice_z]).max() self.assertEqual(norm, 0, "%s, %s, %g, %g" % (self.args, strf, norm, max_diff)) if fields.pad != 0: if strf == "hz": norm2 = np.linalg.norm(tmpf[:, :, -fields.pad :]) else: norm2 = np.linalg.norm(tmpf[:, :, -fields.pad :]) self.assertEqual(norm2, 0, "%s, %s, %g, padding" % (self.args, strf, norm2))
def runTest(self): ufunc, nx, ny, nz, coeff_use, precision_float, tmax = self.args gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) device = gpu_devices[0] fields = Fields(context, device, nx, ny, nz, coeff_use, precision_float) core = Core(fields) # allocations ns = fields.ns dtype = fields.dtype strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz'] ehs = common_update.generate_random_ehs(nx, ny, nz, dtype, ufunc) fields.set_eh_bufs(*ehs) ces, chs = common_update.generate_random_cs(coeff_use, nx, ny, nz, dtype) if 'e' in coeff_use: fields.set_ce_bufs(*ces) if 'h' in coeff_use: fields.set_ch_bufs(*chs) tmpf = np.zeros(fields.ns_pitch, dtype=dtype) # update if ufunc == 'e': for tstep in xrange(0, tmax): fields.update_e() common_update.update_e(ehs, ces) for strf, eh in zip(strf_list, ehs)[:3]: cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf)) norm = np.linalg.norm(eh - tmpf[:, :, fields.slice_z]) max_diff = np.abs(eh - tmpf[:, :, fields.slice_z]).max() self.assertEqual( norm, 0, '%s, %s, %g, %g' % (self.args, strf, norm, max_diff)) if fields.pad != 0: if strf == 'ez': norm2 = np.linalg.norm(tmpf[:, :, -fields.pad:]) else: norm2 = np.linalg.norm(tmpf[:, :, -fields.pad - 1:]) self.assertEqual( norm2, 0, '%s, %s, %g, padding' % (self.args, strf, norm2)) elif ufunc == 'h': for tstep in xrange(0, tmax): fields.update_h() common_update.update_h(ehs, chs) for strf, eh in zip(strf_list, ehs)[3:]: cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf)) norm = np.linalg.norm(eh - tmpf[:, :, fields.slice_z]) max_diff = np.abs(eh - tmpf[:, :, fields.slice_z]).max() self.assertEqual( norm, 0, '%s, %s, %g, %g' % (self.args, strf, norm, max_diff)) if fields.pad != 0: if strf == 'hz': norm2 = np.linalg.norm(tmpf[:, :, -fields.pad:]) else: norm2 = np.linalg.norm(tmpf[:, :, -fields.pad:]) self.assertEqual( norm2, 0, '%s, %s, %g, padding' % (self.args, strf, norm2))
def runTest(self): axis, nx, ny, nz, precision_float = self.args gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) device = gpu_devices[0] fields = Fields(context, device, nx, ny, nz, '', precision_float) pbc = Pbc(fields, axis) # allocations ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype) fields.set_eh_bufs(*ehs) # update fields.update_e() fields.update_h() # verify getf0, getf1 = {}, {} strfs_e = { 'x': ['ey', 'ez'], 'y': ['ex', 'ez'], 'z': ['ex', 'ey'] }[axis] strfs_h = { 'x': ['hy', 'hz'], 'y': ['hx', 'hz'], 'z': ['hx', 'hy'] }[axis] pt0 = (0, 0, 0) pt1 = { 'x': (0, ny-2, nz-2), \ 'y': (nx-2, 0, nz-2), \ 'z': (nx-2, ny-2, 0) }[axis] getf0['e'] = GetFields(fields, strfs_e, pt0, pt1) pt0 = { 'x': (nx-1, 0, 0), \ 'y': (0, ny-1, 0), \ 'z': (0, 0, nz-1) }[axis] pt1 = { 'x': (nx-1, ny-2, nz-2), \ 'y': (nx-2, ny-1, nz-2), \ 'z': (nx-2, ny-2, nz-1) }[axis] getf1['e'] = GetFields(fields, strfs_e, pt0, pt1) pt0 = { 'x': (0, 1, 1), \ 'y': (1, 0, 1), \ 'z': (1, 1, 0) }[axis] pt1 = { 'x': (0, ny-1, nz-1), \ 'y': (nx-1, 0, nz-1), \ 'z': (nx-1, ny-1, 0) }[axis] getf0['h'] = GetFields(fields, strfs_h, pt0, pt1) pt0 = { 'x': (nx-1, 1, 1), \ 'y': (1, ny-1, 1), \ 'z': (1, 1, nz-1) }[axis] pt1 = (nx - 1, ny - 1, nz - 1) getf1['h'] = GetFields(fields, strfs_h, pt0, pt1) for getf in getf0.values() + getf1.values(): getf.get_event().wait() for eh in ['e', 'h']: norm = np.linalg.norm( \ getf0[eh].get_fields() - getf1[eh].get_fields() ) self.assertEqual(norm, 0, '%g, %s, %s' % (norm, self.args, eh))