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') # Plot import matplotlib.pyplot as plt plt.ion() global_ez = np.ones((ngpu * (nx - 1) + 1, ny), dtype=fdtds[0].dtype) imag = plt.imshow(global_ez.T, cmap=plt.cm.hot, origin='lower', vmin=0, vmax=0.05) plt.colorbar()
from kemp.fdtd3d.exchange_boundary import ExchangeInternal import numpy as np import pyopencl as cl nx, ny, nz = 120, 320, 320 tmax, tgap = 300, 5 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(fdtd, 'ez', (0, 0, nz/2), (nx-2, ny-1, nz/2)) for fdtd in fdtds] src_e = DirectSrc(fdtds[1], 'ez', (nx/3*2, ny/2, 0), (nx/3*2, ny/2, nz-1), lambda tstep: np.sin(0.1 * tstep)) exch = ExchangeInternal(fdtds, 'x') # Plot import matplotlib.pyplot as plt plt.ion() idxs = [0] + [i*nx - i for i in range(1, ngpu+1)] # [0, 239, 478, 717] for idx in idxs[1:]: plt.plot((idx,idx), (0,ny), color='w', linewidth=0.2) global_ez = np.ones((idxs[-1], ny), dtype=fdtds[0].dtype) imag = plt.imshow(global_ez.T, cmap=plt.cm.hot, origin='lower', vmin=0, vmax=0.05) plt.colorbar()
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() # Main loop from datetime import datetime t0 = datetime.now() for tstep in xrange(1, tmax+1):
from kemp.fdtd3d import common_gpu from kemp.fdtd3d.gpu import Fields, DirectSrc, GetFields, PbcInt import numpy as np import pyopencl as cl nx, ny, nz = 2, 640, 640 tmax, tgap = 1000, 10 gpu_id = 0 gpu_devices = common_gpu.get_gpu_devices() context = cl.Context(gpu_devices) device = gpu_devices[gpu_id] fdtd = Fields(context, device, nx, ny, nz, coeff_use='') src = DirectSrc(fdtd, 'ex', (1, ny / 5 * 4, nz / 5 * 3), (1, ny / 5 * 4, nz / 5 * 3), lambda tstep: np.sin(0.1 * tstep)) pbc = PbcInt(fdtd, 'x') 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