Example #1
0
    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))
Example #5
0
gpu_devices = common_gpu.gpu_device_list(print_info=False)
context = cl.Context(gpu_devices)

mainf_list = [gpu.Fields(context, device, nx_gpu, ny, nz) for device in gpu_devices]
mainf_list.append( cpu.Fields(nx_cpu, ny, nz) )
nodef = NodeFields(mainf_list)
core = NodeCore(nodef)
exchange = NodeExchange(nodef)
pbc = NodePbc(nodef, 'y')
pbc = NodePbc(nodef, 'z')
pbc_x = NodePbc(nodef, 'x')

tfunc = lambda tstep: np.sin(0.1 * tstep)
#incident = NodeDirectIncident(nodef, 'ez', (0, 20, 0), (nodef.nx-1, 20, nz-1), tfunc) 
incident = NodeDirectIncident(nodef, 'ez', (20, 0, 0), (20, ny-1, nz-1), tfunc) 
getf = NodeGetFields(nodef, 'ez', (0, 0, 2), (nodef.nx-1, ny-1, 2))

# plot
import matplotlib.pyplot as plt
plt.figure(figsize=(12,8))
plt.ion()
for anx in nodef.accum_nx_list[1:]:
	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):
# instances
gpu_devices = common_gpu.gpu_device_list(print_info=False)
context = cl.Context(gpu_devices)

mainf_list = [gpu.Fields(context, device, nx_gpu, ny, nz) for device in gpu_devices]
mainf_list.append( cpu.Fields(nx_cpu, ny, nz) )
nodef = NodeFields(mainf_list)
core = NodeCore(nodef)
exchange = NodeExchange(nodef)
pbc = NodePbc(nodef, 'y')
#pbc_x = NodePbc(nodef, 'x')

tfunc = lambda tstep: np.sin(0.1 * tstep)
incident = NodeDirectIncident(nodef, 'ey', (100, 0, 150), (100, ny-1, 150), tfunc) 
getf = NodeGetFields(nodef, 'ey', (0, 64, 0), (nodef.nx-1, 64, nz-1))

# plot
import matplotlib.pyplot as plt
plt.figure(figsize=(12,8))
plt.ion()
for anx in nodef.accum_nx_list[1:]:
	plt.plot((anx, anx), (0, nz), color='w', linewidth=0.2)
imag = plt.imshow(np.zeros((nodef.nx, nz), nodef.dtype).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):