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)

        # 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 = 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))
예제 #4
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))
예제 #5
0
coeff_use = 'e'
precision_float = 'single'

# instances 
gpu_devices = common_gpu.gpu_device_list(print_info=False)
context = cl.Context(gpu_devices)
device = gpu_devices[0]
gpuf = gpu.Fields(context, device, nx, ny, nz, coeff_use, precision_float)
buffer_dict = {}
if rank == 0: 
    buffer_dict['x+'] = BufferFields(gpuf, 'x+', tmax, ny, nz, coeff_use, precision_float)
elif rank == 1: 
    buffer_dict['x-'] = BufferFields(gpuf, 'x-', tmax, ny, nz, coeff_use, precision_float)

fields = Fields([gpuf], buffer_dict)
Core(fields)
Pbc(fields, 'yz')

if rank == 0:
    print 'ns', fields.ns
    print 'nbytes (MB)', nx*ny*nz * 9 * 4. / (1024**2)

    tfunc = lambda tstep: 40 * np.sin(0.05 * tstep)
    gpu.IncidentDirect(gpuf, 'ez', (220, 20, 0), (220, 20, -1), tfunc) 
    getf = gpu.GetFields(gpuf, 'ez', (0, 0, 0.5), (-1, -1, 0.5))

    # plot
    import matplotlib.pyplot as plt
    plt.ion()
    fig = plt.figure(figsize=(12,8))
예제 #6
0
from kemp.fdtd3d.node import Fields, Core, IncidentDirect, GetFields, Pbc
from kemp.fdtd3d import gpu, cpu


ny, nz = 140, 2
gpu_nx = 141
cpu_nx = 20
tmax, tgap = 150, 10 

# 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))
예제 #7
0
ny, nz = 140, 32
gpu_nx = 141
cpu_nx = 20
tmax, tgap = 150, 10

# instances
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))
예제 #8
0
precision_float = 'single'

# instances
gpu_devices = common_gpu.gpu_device_list(print_info=False)
context = cl.Context(gpu_devices)
device = gpu_devices[0]
gpuf = gpu.Fields(context, device, nx, ny, nz, coeff_use, precision_float)
buffer_dict = {}
if rank == 0:
    buffer_dict['x+'] = BufferFields(gpuf, 'x+', tmax, ny, nz, coeff_use,
                                     precision_float)
elif rank == 1:
    buffer_dict['x-'] = BufferFields(gpuf, 'x-', tmax, ny, nz, coeff_use,
                                     precision_float)

fields = Fields([gpuf], buffer_dict)
Core(fields)
Pbc(fields, 'yz')

if rank == 0:
    print 'ns', fields.ns
    print 'nbytes (MB)', nx * ny * nz * 9 * 4. / (1024**2)

    tfunc = lambda tstep: 40 * np.sin(0.05 * tstep)
    gpu.IncidentDirect(gpuf, 'ez', (220, 20, 0), (220, 20, -1), tfunc)
    getf = gpu.GetFields(gpuf, 'ez', (0, 0, 0.5), (-1, -1, 0.5))

    # plot
    import matplotlib.pyplot as plt
    plt.ion()
    fig = plt.figure(figsize=(12, 8))