#!/usr/bin/env python import sys sys.path.append('/home/kifang') from kemp.fdtd3d import common_gpu from kemp.fdtd3d.gpu import Fields, DirectSrc, GetFields, ExchangeFields import numpy as np import pyopencl as cl nx, ny, nz = 240, 640, 640 tmax, tgap = 200, 10 divide_axes = 'x' gpu_devices = common_gpu.get_gpu_devices() context = cl.Context(gpu_devices) ngpu = len(gpu_devices) fdtds = [ Fields(context, device, nx, ny, nz, coeff_use='') for device in gpu_devices ] outputs = [GetFields(fdtds[0], 'ez', (0, 0, nz / 2), (nx - 1, ny - 1, nz / 2))] outputs += [ GetFields(fdtd, 'ez', (1, 0, nz / 2), (nx - 1, ny - 1, nz / 2)) for fdtd in fdtds[1:] ] src = DirectSrc(fdtds[1], 'ez', (nx / 5 * 4, ny / 2, 0), (nx / 5 * 4, ny / 2, nz - 1), lambda tstep: np.sin(0.1 * tstep)) exch = ExchangeFields(fdtds, 'x')
import sys sys.path.append('/home/kifang') from kemp.fdtd3d import common_gpu from kemp.fdtd3d.gpu import Fdtd, DirectSrc, GetFields import numpy as np import pyopencl as cl nx, ny, nz = 240, 256, 256 # 540 MB #nx, ny, nz = 512, 480, 480 # 3.96 GB #nx, ny, nz = 480, 480, 480 # 3.71 GB tmax, tgap = 200, 10 gpu_id = 0 gpu_devices = common_gpu.get_gpu_devices() context = cl.Context(gpu_devices) device = gpu_devices[gpu_id] fdtd = Fdtd(context, device, nx, ny, nz, coeff_use='') src = DirectSrc(fdtd, 'ez', (nx/3*2, ny/2, 0), (nx/3*2, ny/2, nz-1), lambda tstep: np.sin(0.1 * tstep)) output = GetFields(fdtd, 'ez', (0, 0, nz/2), (nx-1, ny-1, nz/2)) # Plot import matplotlib.pyplot as plt plt.ion() imag = plt.imshow(output.get_fields('ez').T, cmap=plt.cm.hot, origin='lower', vmin=0, vmax=0.05) plt.colorbar()