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))
Exemple #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))
Exemple #7
0
# instances 
gpu_devices = common_gpu.gpu_device_list(print_info=False)
context = cl.Context(gpu_devices)
mainf_list = [ cpu.Fields(cpu_nx, ny, nz) ]
mainf_list += [gpu.Fields(context, device, gpu_nx, ny, nz) for device in gpu_devices]

fields = Fields(mainf_list)
Core(fields)
Pbc(fields, 'xyz')
nx = fields.nx

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

#IncidentDirect(fields, 'ey', (20, 0, 0), (20, ny-1, nz-1), tfunc) 
#getf = GetFields(fields, 'ey', (0, 0, nz/2), (nx-1, ny-1, nz/2))

#IncidentDirect(fields, 'ex', (0, 20, 0), (nx-1, 20, nz-1), tfunc) 
#getf = GetFields(fields, 'ex', (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))
for i in fields.accum_nx_list[1:]:
	plt.plot((i,i), (0,ny), color='k', linewidth=2)
Exemple #8
0
        masks[1][-gw2:, :gw, nz / 2 - gw2 : nz / 2 + gw2] = False
        masks[2][-gw2:, :gw, nz / 2 - gw2 : nz / 2 + gw2] = False
    elif gpu_id == 1:
        masks[0][:gw2, :gw, nz / 2 - gw2 : nz / 2 + gw2] = False
        masks[1][:gw2, :gw, nz / 2 - gw2 : nz / 2 + gw2] = False
        masks[2][:gw2, :gw, nz / 2 - gw2 : nz / 2 + gw2] = False
    else:
        sys.exit()
    Drude(gpuf, (0, gj, 0), (-1, -1, -1), ep_inf=np.inf, drude_freq=0, gamma=0, mask_arrays=masks)

# fdtd core instance
Core(fields)

# save fields
save_j = int(save_y / x_unit)
getf_sm = GetFields(fields, ["ex", "ey", "ez"], (0, save_j, 0), (-1, save_j, -1), process="square_sum")
getf_plot = GetFields(fields, "ez", (0, 0, 0.5), (-1, -1, 0.5))

"""
# plot
import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure(figsize=(15,6))
# plot divided fdtd space
for i in fields.accum_nx_list[1:]:
    plt.plot((i,i), (0,ny), ':k')
# plot geometry
geo_pts = [(0,gj), (nx/2-gw2,gj), (nx/2-gw2,gj+gw), (nx/2+gw2,gj+gw), (nx/2+gw2,gj), (nx,gj)]
for (i0, j0), (i1, j1) in zip(geo_pts[:-1], geo_pts[1:]):
    plt.plot((i0,i1), (j0,j1), '-k')
Exemple #9
0
#mainf_list = [gpu.Fields(context, gpu_devices[0], gpu_nx, ny, nz)]
mainf_list = [
    gpu.Fields(context, device, gpu_nx, ny, nz) for device in gpu_devices
]
#mainf_list += [ cpu.Fields(cpu_nx, ny, nz)]

fields = Fields(mainf_list)
Pbc(fields, 'z')
Pml(fields, ('+-', '+-', ''), npml=10)
ExchangeNode(fields)
Core(fields)
nx = fields.nx

tfunc = lambda tstep: 50 * np.sin(0.05 * tstep)
IncidentDirect(fields, 'ez', (0.6, 0.7, 0), (0.6, 0.7, -1), tfunc)
getf = GetFields(fields, 'ez', (0, 0, 0.5), (-1, -1, 0.5))

print fields.instance_list

# 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)
Exemple #10
0
gpu_devices = common_gpu.gpu_device_list(print_info=False)
context = cl.Context(gpu_devices)
mainf_list = [
    gpu.Fields(context, device, gpu_nx, ny, nz) for device in gpu_devices
]
mainf_list.append(cpu.Fields(cpu_nx, ny, nz))
#mainf_list = [ cpu.Fields(160, ny, nz) ]

fields = Fields(mainf_list, pbc='yz', mpi_shape=(2, 1, 1), tmax=tmax)
Core(fields)
nx = fields.nx

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))
if rank == 0:
    buf = fields.buffer_dict['x+']
    print 'buf instance_list', buf.instance_list
    getf_buf = cpu.GetFields(buf, 'ez', (0, 0, nz / 2), (2, ny - 1, nz / 2))

#IncidentDirect(fields, 'ey', (20, 0, 0), (20, ny-1, nz-1), tfunc)
#getf = GetFields(fields, 'ey', (0, 0, nz/2), (nx-1, ny-1, nz/2))

#IncidentDirect(fields, 'ex', (0, 20, 0), (nx-1, 20, nz-1), tfunc)
#getf = GetFields(fields, 'ex', (0, 0, nz/2), (nx-1, ny-1, nz/2))

#print fields.updatef_list
"""
# plot
if rank == 0: