def runTest(self):
        nx, ny, nz, str_f, pt0, pt1, is_array = self.args

        slices = common.slices_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 = Fields(mainf_list)
        dtype = nodef.dtype
        anx = nodef.accum_nx_list

        getf = GetFields(nodef, str_f, (0, 0, 0),
                         (nodef.nx - 1, ny - 1, nz - 1))
        setf = SetFields(nodef, str_f, pt0, pt1, is_array)

        # generate random source
        if is_array:
            shape = common.shape_two_points(pt0, pt1, len(str_fs))
            value = np.random.rand(*shape).astype(nodef.dtype)
            split_value = np.split(value, len(str_fs))
            split_value_dict = dict(zip(str_fs, split_value))
        else:
            value = np.random.ranf()

        # host allocations
        global_ehs = [np.zeros(nodef.ns, dtype) for i in range(6)]
        eh_dict = dict(zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], global_ehs))

        # verify
        for str_f in str_fs:
            if is_array:
                eh_dict[str_f][slices] = split_value_dict[str_f]
            else:
                eh_dict[str_f][slices] = value

        setf.set_fields(value)
        gpu_getf = gpu.GetFields(mainf_list[0], str_fs, (0, 0, 0),
                                 (nx - 1, ny - 1, nz - 1))
        gpu_getf.get_event().wait()
        getf.wait()

        for str_f in str_fs:
            original = eh_dict[str_f]
            copy = getf.get_fields(str_f)
            norm = np.linalg.norm(original - copy)
            #if norm != 0:
            #print '\ngpu getf\n', gpu_getf.get_fields(str_f)
            #print original[slices]
            #print copy[slices]
            self.assertEqual(norm, 0, '%s, %g, %s' % (self.args, norm, str_f))
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1, is_array = self.args

        slices = common.slices_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 = Fields(mainf_list)
        dtype = nodef.dtype
        anx = nodef.accum_nx_list

        getf = GetFields(nodef, str_f, (0, 0, 0), (nodef.nx-1, ny-1, nz-1)) 
        setf = SetFields(nodef, str_f, pt0, pt1, is_array) 
        
        # generate random source
        if is_array:
            shape = common.shape_two_points(pt0, pt1, len(str_fs))
            value = np.random.rand(*shape).astype(nodef.dtype)
            split_value = np.split(value, len(str_fs))
            split_value_dict = dict( zip(str_fs, split_value) )
        else:
            value = np.random.ranf()

        # host allocations
        global_ehs = [np.zeros(nodef.ns, dtype) for i in range(6)]
        eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], global_ehs) )

        # verify
        for str_f in str_fs:
            if is_array:
                eh_dict[str_f][slices] = split_value_dict[str_f]
            else:
                eh_dict[str_f][slices] = value

        setf.set_fields(value)
        gpu_getf = gpu.GetFields(mainf_list[0], str_fs, (0, 0, 0), (nx-1, ny-1, nz-1))
        gpu_getf.get_event().wait()
        getf.wait()
        

        for str_f in str_fs:
            original = eh_dict[str_f]
            copy = getf.get_fields(str_f)
            norm = np.linalg.norm(original - copy)
            #if norm != 0:
                #print '\ngpu getf\n', gpu_getf.get_fields(str_f)
                #print original[slices]
                #print copy[slices]
            self.assertEqual(norm, 0, '%s, %g, %s' % (self.args, norm, str_f))
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1 = self.args

        slices = common.slices_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 = Fields(mainf_list)
        dtype = nodef.dtype
        anx = nodef.accum_nx_list

        getf = GetFields(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_random.generate_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_random.generate_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.slices_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 = Fields(mainf_list)
        dtype = nodef.dtype
        anx = nodef.accum_nx_list

        getf = GetFields(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_random.generate_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_random.generate_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))
Esempio n. 5
0
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1, is_array = self.args

        slices = 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)

        mainf_list = [cpu.Fields(nx, ny, nz)]
        mainf_list += [gpu.Fields(context, device, nx, ny, nz) \
                for device in gpu_devices]
        nodef = Fields(mainf_list)
        dtype = nodef.dtype
        anx = nodef.accum_nx_list

        tfunc = lambda tstep: np.sin(0.03 * tstep)
        incident = IncidentDirect(nodef, str_f, pt0, pt1, tfunc, value)

        # allocations for verify
        eh = np.zeros(nodef.ns, dtype)
        getf = GetFields(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.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)

        mainf_list = [ cpu.Fields(nx, ny, nz) ]
        mainf_list += [gpu.Fields(context, device, nx, ny, nz) \
                for device in gpu_devices]
        nodef = Fields(mainf_list)
        dtype = nodef.dtype
        anx = nodef.accum_nx_list

        tfunc = lambda tstep: np.sin(0.03*tstep)
        incident = IncidentDirect(nodef, str_f, pt0, pt1, tfunc, value) 

        # allocations for verify
        eh = np.zeros(nodef.ns, dtype)
        getf = GetFields(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))
Esempio n. 7
0
# plot
import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure(figsize=(12,8))
for i in fields.accum_nx_list[1:]:
	plt.plot((i,i), (0,ny), color='k', linewidth=2)
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()

for tstep in xrange(1, tmax+1):
    fields.update_e()
    fields.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( getf.get_fields().T )
        #plt.savefig('./png/%.6d.png' % tstep)
        plt.draw()

plt.show()
print('\n[%s] %d/%d (%d %%)' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100))
print('')
Esempio n. 8
0
from datetime import datetime

t0 = datetime.now()

for tstep in xrange(1, tmax + 1):
    fields.update_e()
    fields.update_h()

    if tstep > save_tstep:
        getf_sm.enqueue_kernel()

    if tstep % tgap == 0:
        print("[%s] %d/%d (%d %%)\r" % (datetime.now() - t0, tstep, tmax, float(tstep) / tmax * 100)),
        sys.stdout.flush()

        getf_plot.wait()
        """
        imag.set_array( getf_plot.get_fields().T )
        #plt.savefig('./png/%.6d.png' % tstep)
        plt.draw()
        """

print("[%s] %d/%d (%d %%)\r" % (datetime.now() - t0, tstep, tmax, float(tstep) / tmax * 100)),
print("")

# reflectance
getf_sm.wait(exec_kernel=False)
ex_r = getf_sm.get_fields("ex")
ey_r = getf_sm.get_fields("ey")
ez_r = getf_sm.get_fields("ez")
reflect = (ex_r + ey_r + ez_r).mean()