def runTest(self): nx, ny, nz, str_f, pt0, pt1 = self.args slices = common.slice_index_two_points(pt0, pt1) str_fs = common.convert_to_tuple(str_f) # instance gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) mainf_list = [gpu.Fields(context, device, nx, ny, nz) \ for device in gpu_devices] mainf_list.append(cpu.Fields(nx, ny, nz)) nodef = NodeFields(mainf_list) dtype = nodef.dtype anx = nodef.accum_nx_list getf = NodeGetFields(nodef, str_f, pt0, pt1) # generate random source global_ehs = [np.zeros(nodef.ns, dtype) for i in range(6)] eh_dict = dict(zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], global_ehs)) for i, f in enumerate(mainf_list[:-1]): nx, ny, nz = f.ns ehs = common_update.generate_random_ehs(nx, ny, nz, dtype) f.set_eh_bufs(*ehs) for eh, geh in zip(ehs, global_ehs): geh[anx[i]:anx[i + 1], :, :] = eh[:-1, :, :] f = mainf_list[-1] nx, ny, nz = f.ns ehs = common_update.generate_random_ehs(nx, ny, nz, dtype) f.set_ehs(*ehs) for eh, geh in zip(ehs, global_ehs): geh[anx[-2]:anx[-1] + 1, :, :] = eh[:] # verify getf.wait() for str_f in str_fs: original = eh_dict[str_f][slices] 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 slices = common.slice_index_two_points(pt0, pt1) str_fs = common.convert_to_tuple(str_f) # instance gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) mainf_list = [gpu.Fields(context, device, nx, ny, nz) \ for device in gpu_devices] mainf_list.append( cpu.Fields(nx, ny, nz) ) nodef = NodeFields(mainf_list) dtype = nodef.dtype anx = nodef.accum_nx_list getf = NodeGetFields(nodef, str_f, pt0, pt1) # generate random source global_ehs = [np.zeros(nodef.ns, dtype) for i in range(6)] eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], global_ehs) ) for i, f in enumerate(mainf_list[:-1]): nx, ny, nz = f.ns ehs = common_update.generate_random_ehs(nx, ny, nz, dtype) f.set_eh_bufs(*ehs) for eh, geh in zip(ehs, global_ehs): geh[anx[i]:anx[i+1],:,:] = eh[:-1,:,:] f = mainf_list[-1] nx, ny, nz = f.ns ehs = common_update.generate_random_ehs(nx, ny, nz, dtype) f.set_ehs(*ehs) for eh, geh in zip(ehs, global_ehs): geh[anx[-2]:anx[-1]+1,:,:] = eh[:] # verify getf.wait() for str_f in str_fs: original = eh_dict[str_f][slices] 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, is_array = 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 gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) mainf_list = [gpu.Fields(context, device, nx, ny, nz) \ for device in gpu_devices] mainf_list.append( cpu.Fields(nx, ny, nz) ) nodef = NodeFields(mainf_list) dtype = nodef.dtype anx = nodef.accum_nx_list tfunc = lambda tstep: np.sin(0.03*tstep) incident = NodeDirectIncident(nodef, str_f, pt0, pt1, tfunc, value) # allocations for verify eh = np.zeros(nodef.ns, dtype) getf = NodeGetFields(nodef, str_f, pt0, pt1) # verify eh[slices] = dtype(value) * dtype(tfunc(1)) e_or_h = str_f[0] nodef.update_e() nodef.update_h() getf.wait() original = eh[slices] 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, is_array = 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 gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) mainf_list = [gpu.Fields(context, device, nx, ny, nz) \ for device in gpu_devices] mainf_list.append(cpu.Fields(nx, ny, nz)) nodef = NodeFields(mainf_list) dtype = nodef.dtype anx = nodef.accum_nx_list tfunc = lambda tstep: np.sin(0.03 * tstep) incident = NodeDirectIncident(nodef, str_f, pt0, pt1, tfunc, value) # allocations for verify eh = np.zeros(nodef.ns, dtype) getf = NodeGetFields(nodef, str_f, pt0, pt1) # verify eh[slices] = dtype(value) * dtype(tfunc(1)) e_or_h = str_f[0] nodef.update_e() nodef.update_h() getf.wait() original = eh[slices] copy = getf.get_fields(str_f) norm = np.linalg.norm(original - copy) self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
plt.plot((anx, anx), (0, ny), color='w', linewidth=0.2) imag = plt.imshow(np.zeros((nodef.nx, ny), nodef.dtype).T, cmap=plt.cm.hot, origin='lower', vmin=0, vmax=2.) plt.colorbar() # main loop from datetime import datetime t0 = datetime.now() for tstep in xrange(1, tmax+1): nodef.update_e() pbc_x.update_e() exchange.update_e() nodef.update_h() pbc_x.update_h() exchange.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.wait() imag.set_array( np.abs(getf.get_fields().T) ) #plt.savefig('./png/%.6d.png' % tstep) plt.draw() plt.show() #getf.wait() #print('\n[%s] %d/%d (%d %%)' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)) print('')