示例#1
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, use_cpu_core, split, tmax = self.args
        fields = Fields(nx, ny, nz, coeff_use, precision_float, use_cpu_core)
        core = Core(fields)

        strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz']
        slice_xyz = [slice(None, None), slice(None, None), fields.slice_z]

        # allocations
        ns = fields.ns
        dtype = fields.dtype

        ehs = common_update.generate_random_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_ehs(*ehs)

        ces, chs = common_update.generate_random_cs(coeff_use, nx, ny, nz, dtype)
        if 'e' in coeff_use:
            fields.set_ces(*ces)
        if 'h' in coeff_use:
            fields.set_chs(*chs)

        # update
        if ufunc == 'e':
            for tstep in xrange(0, tmax):
                fields.update_e()
                common_update.update_e(ehs, ces)
            fields.enqueue_barrier()

            for strf, eh in zip(strf_list, ehs)[:3]:
                norm = np.linalg.norm(eh - fields.get(strf)[slice_xyz])
                max_diff = np.abs(eh - fields.get(strf)[slice_xyz]).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % (self.args, strf, norm, max_diff) )

                if fields.pad != 0:
                    if strf == 'ez':
                        norm2 = np.linalg.norm(fields.get(strf)[:,:,-fields.pad:])
                    else:
                        norm2 = np.linalg.norm(fields.get(strf)[:,:,-fields.pad-1:])
                    self.assertEqual(norm2, 0, '%s, %s, %g, padding' % (self.args, strf, norm2) )

        elif ufunc == 'h':
            for tstep in xrange(0, tmax):
                fields.update_h()
                common_update.update_h(ehs, chs)
            fields.enqueue_barrier()

            for strf, eh in zip(strf_list, ehs)[3:]:
                norm = np.linalg.norm(eh - fields.get(strf)[slice_xyz])
                max_diff = np.abs(eh - fields.get(strf)[slice_xyz]).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % \
                        (self.args, strf, norm, max_diff) )

                if fields.pad != 0:
                    if strf == 'hz':
                        norm2 = np.linalg.norm(fields.get(strf)[:,:,-fields.pad:])
                    else:
                        norm2 = np.linalg.norm(fields.get(strf)[:,:,-fields.pad:])
                    self.assertEqual(norm2, 0, '%s, %s, %g, padding' % (self.args, strf, norm2) )
示例#2
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, use_cpu_core, split, tmax = self.args
        fields = Fields(nx, ny, nz, coeff_use, precision_float, use_cpu_core)
        core = Core(fields)

        strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz']
        slice_xyz = [slice(None, None), slice(None, None), fields.slice_z]

        # allocations
        ns = fields.ns
        dtype = fields.dtype

        ehs = common_update.generate_random_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_ehs(*ehs)

        ces, chs = common_update.generate_random_cs(coeff_use, nx, ny, nz,
                                                    dtype)
        if 'e' in coeff_use:
            fields.set_ces(*ces)
        if 'h' in coeff_use:
            fields.set_chs(*chs)

        # update
        if ufunc == 'e':
            for tstep in xrange(0, tmax):
                fields.update_e()
                common_update.update_e(ehs, ces)
            fields.enqueue_barrier()

            for strf, eh in zip(strf_list, ehs)[:3]:
                norm = np.linalg.norm(eh - fields.get(strf)[slice_xyz])
                max_diff = np.abs(eh - fields.get(strf)[slice_xyz]).max()
                self.assertEqual(
                    norm, 0,
                    '%s, %s, %g, %g' % (self.args, strf, norm, max_diff))

                if fields.pad != 0:
                    if strf == 'ez':
                        norm2 = np.linalg.norm(
                            fields.get(strf)[:, :, -fields.pad:])
                    else:
                        norm2 = np.linalg.norm(
                            fields.get(strf)[:, :, -fields.pad - 1:])
                    self.assertEqual(
                        norm2, 0,
                        '%s, %s, %g, padding' % (self.args, strf, norm2))

        elif ufunc == 'h':
            for tstep in xrange(0, tmax):
                fields.update_h()
                common_update.update_h(ehs, chs)
            fields.enqueue_barrier()

            for strf, eh in zip(strf_list, ehs)[3:]:
                norm = np.linalg.norm(eh - fields.get(strf)[slice_xyz])
                max_diff = np.abs(eh - fields.get(strf)[slice_xyz]).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % \
                        (self.args, strf, norm, max_diff) )

                if fields.pad != 0:
                    if strf == 'hz':
                        norm2 = np.linalg.norm(
                            fields.get(strf)[:, :, -fields.pad:])
                    else:
                        norm2 = np.linalg.norm(
                            fields.get(strf)[:, :, -fields.pad:])
                    self.assertEqual(
                        norm2, 0,
                        '%s, %s, %g, padding' % (self.args, strf, norm2))
示例#3
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, tmax = self.args

        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)
        device = gpu_devices[0]
        fields = Fields(context, device, nx, ny, nz, coeff_use, precision_float)
        core = Core(fields)

        # allocations
        ns = fields.ns
        dtype = fields.dtype
        strf_list = ["ex", "ey", "ez", "hx", "hy", "hz"]

        ehs = common_update.generate_random_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_eh_bufs(*ehs)

        ces, chs = common_update.generate_random_cs(coeff_use, nx, ny, nz, dtype)
        if "e" in coeff_use:
            fields.set_ce_bufs(*ces)
        if "h" in coeff_use:
            fields.set_ch_bufs(*chs)

        tmpf = np.zeros(fields.ns_pitch, dtype=dtype)

        # update
        if ufunc == "e":
            for tstep in xrange(0, tmax):
                fields.update_e()
                common_update.update_e(ehs, ces)

            for strf, eh in zip(strf_list, ehs)[:3]:
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(eh - tmpf[:, :, fields.slice_z])
                max_diff = np.abs(eh - tmpf[:, :, fields.slice_z]).max()
                self.assertEqual(norm, 0, "%s, %s, %g, %g" % (self.args, strf, norm, max_diff))

                if fields.pad != 0:
                    if strf == "ez":
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad :])
                    else:
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad - 1 :])
                    self.assertEqual(norm2, 0, "%s, %s, %g, padding" % (self.args, strf, norm2))

        elif ufunc == "h":
            for tstep in xrange(0, tmax):
                fields.update_h()
                common_update.update_h(ehs, chs)

            for strf, eh in zip(strf_list, ehs)[3:]:
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(eh - tmpf[:, :, fields.slice_z])
                max_diff = np.abs(eh - tmpf[:, :, fields.slice_z]).max()
                self.assertEqual(norm, 0, "%s, %s, %g, %g" % (self.args, strf, norm, max_diff))

                if fields.pad != 0:
                    if strf == "hz":
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad :])
                    else:
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad :])
                    self.assertEqual(norm2, 0, "%s, %s, %g, padding" % (self.args, strf, norm2))
示例#4
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, tmax = self.args

        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)
        device = gpu_devices[0]
        fields = Fields(context, device, nx, ny, nz, coeff_use,
                        precision_float)
        core = Core(fields)

        # allocations
        ns = fields.ns
        dtype = fields.dtype
        strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz']

        ehs = common_update.generate_random_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_eh_bufs(*ehs)

        ces, chs = common_update.generate_random_cs(coeff_use, nx, ny, nz,
                                                    dtype)
        if 'e' in coeff_use:
            fields.set_ce_bufs(*ces)
        if 'h' in coeff_use:
            fields.set_ch_bufs(*chs)

        tmpf = np.zeros(fields.ns_pitch, dtype=dtype)

        # update
        if ufunc == 'e':
            for tstep in xrange(0, tmax):
                fields.update_e()
                common_update.update_e(ehs, ces)

            for strf, eh in zip(strf_list, ehs)[:3]:
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(eh - tmpf[:, :, fields.slice_z])
                max_diff = np.abs(eh - tmpf[:, :, fields.slice_z]).max()
                self.assertEqual(
                    norm, 0,
                    '%s, %s, %g, %g' % (self.args, strf, norm, max_diff))

                if fields.pad != 0:
                    if strf == 'ez':
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad:])
                    else:
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad - 1:])
                    self.assertEqual(
                        norm2, 0,
                        '%s, %s, %g, padding' % (self.args, strf, norm2))

        elif ufunc == 'h':
            for tstep in xrange(0, tmax):
                fields.update_h()
                common_update.update_h(ehs, chs)

            for strf, eh in zip(strf_list, ehs)[3:]:
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(eh - tmpf[:, :, fields.slice_z])
                max_diff = np.abs(eh - tmpf[:, :, fields.slice_z]).max()
                self.assertEqual(
                    norm, 0,
                    '%s, %s, %g, %g' % (self.args, strf, norm, max_diff))

                if fields.pad != 0:
                    if strf == 'hz':
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad:])
                    else:
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad:])
                    self.assertEqual(
                        norm2, 0,
                        '%s, %s, %g, padding' % (self.args, strf, norm2))