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 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))
#exch = node.ExchangeMpiBufferBlock(fields, direction) #exch = node.ExchangeMpiBufferBlockSplit(fields, direction) exch = node.ExchangeMpiBufferNonBlockSplitEnqueue(fields, direction, tmax) if '+' in direction: cpu.Core(exch.cpuf_p) if '-' in direction: cpu.Core(exch.cpuf_m) is_master = True if rank == 0 else False if is_plot: Pbc(fields, 'yz') getf = GetFields(fields, 'ez', (0, 0, 0.5), (-1, -1, 0.5)) tfunc = lambda tstep: 40 * np.sin(0.05 * tstep) if rank < size - 1: IncidentDirect(fields, 'ez', (220, 0.5, 0), (220, 0.5, -1), tfunc) #if rank > 0: # IncidentDirect(fields, 'ez', (20, 0.5, 0), (20, 0.5, -1), tfunc) if is_master: # plot import matplotlib.pyplot as plt plt.ion() fig = plt.figure(figsize=(12, 8)) arr = np.zeros((size * nx, ny), fields.dtype) for i in range(1, size): plt.plot((i * nx, i * nx), (0, ny), color='k', linewidth=1.2) imag = plt.imshow(arr.T, interpolation='nearest', origin='lower', vmin=-0.7,
import matplotlib as mpl mpl.rc('image', interpolation='nearest', origin='lower') #plt.ion() fig = plt.figure(figsize=(14, 8)) # gpu device gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) device = gpu_devices[0] # z-axis nx, ny, nz = 180, 160, 2 fields = Fields(context, device, nx, ny, nz) Pbc(fields, 'xyz') Core(fields) IncidentDirect(fields, 'ey', (20, 0, 0), (20, ny - 1, nz - 1), tfunc) IncidentDirect(fields, 'ex', (0, 20, 0), (nx - 1, 20, nz - 1), tfunc) for tstep in xrange(1, tmax + 1): fields.update_e() fields.update_h() ax1 = fig.add_subplot(2, 3, 1) getf = GetFields(fields, 'ey', (0, 0, nz / 2), (nx - 1, ny - 1, nz / 2)) getf.get_event().wait() ax1.imshow(getf.get_fields().T, vmin=-1.1, vmax=1.1) ax1.set_title('%s, ey[20,:,:]' % repr(fields.ns)) ax1.set_xlabel('x') ax1.set_ylabel('y') ax2 = fig.add_subplot(2, 3, 4)
ax1 = fig.add_subplot(1, 3, 1) ax2 = fig.add_subplot(1, 3, 2) ax3 = fig.add_subplot(1, 3, 3) # gpu device gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) device = gpu_devices[0] # xy-plane nx, ny, nz = 180, 160, 2 fields = Fields(context, device, nx, ny, nz) Pbc(fields, 'z') Pml(fields, ('+-', '+-', ''), npml) Core(fields) IncidentDirect(fields, 'ez', (0.4, 0.3, 0), (0.4, 0.3, -1), tfunc) getf = GetFields(fields, 'ez', (0, 0, 0.5), (-1, -1, 0.5)) for tstep in xrange(1, tmax+1): fields.update_e() fields.update_h() getf.get_event().wait() ax1.imshow(getf.get_fields().T, vmin=-1.1, vmax=1.1) ax1.set_title('xy-plane') ax1.set_xlabel('x') ax1.set_ylabel('y') # yz-plane nx, ny, nz = 2, 180, 160 fields = Fields(context, device, nx, ny, nz)
from kemp.fdtd3d.gpu import Fields, Core, Pbc, IncidentDirect, GetFields nx, ny, nz = 160, 140, 32 tmax, tgap = 150, 10 # instances 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) Core(fields) Pbc(fields, 'xyz') tfunc = lambda tstep: np.sin(0.05 * tstep) IncidentDirect(fields, 'ez', (20, 0, 0), (20, ny-1, nz-1), tfunc) #IncidentDirect(fields, 'ez', (0, 20, 0), (nx-1, 20, nz-1), tfunc) getf = GetFields(fields, 'ez', (0, 0, nz/2), (nx-1, ny-1, nz/2)) 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()
import sys, os sys.path.append(os.path.expanduser('~')) from kemp.fdtd3d.util import common_gpu from kemp.fdtd3d.gpu import Fields, Core, Pbc, IncidentDirect, GetFields nx, ny, nz = 160, 140, 32 tmax, tgap = 150, 10 # instances 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) Core(fields) Pbc(fields, 'xyz') ''' tfunc = lambda tstep: np.sin(0.05 * tstep) IncidentDirect(fields, 'ez', (20, 0, 0), (20, ny-1, nz-1), tfunc) #IncidentDirect(fields, 'ez', (0, 20, 0), (nx-1, 20, nz-1), tfunc) getf = GetFields(fields, 'ez', (0, 0, nz/2), (nx-1, ny-1, nz/2)) 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
nx, ny, nz = 2, 250, 300 tmax, tgap = 1000, 10 npml = 10 # instances 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) Pbc(fields, 'x') Pml(fields, ('', '+-', '+-'), npml) Core(fields) tfunc = lambda tstep: 50 * np.sin(0.05 * tstep) IncidentDirect(fields, 'ex', (0, 0.4, 0.3), (-1, 0.4, 0.3), tfunc) getf = GetFields(fields, 'ex', (0.5, 0, 0), (0.5, -1, -1)) print fields.instance_list # 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')
from kemp.fdtd3d.util import common_gpu from kemp.fdtd3d.gpu import Fields, Core, Pbc, IncidentDirect, GetFields nx, ny, nz = 2, 160, 140 tmax, tgap = 150, 10 # instances 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) Pbc(fields, 'xyz') Core(fields) tfunc = lambda tstep: np.sin(0.05 * tstep) IncidentDirect(fields, 'ex', (0, 20, 0), (-1, 20, -1), tfunc) #IncidentDirect(fields, 'ex', (0, 0, 20), (-1, -1, 20), tfunc) getf = GetFields(fields, 'ex', (0.5, 0, 0), (0.5, -1, -1)) print fields.instance_list # 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')