Exemple #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) )
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1, is_array = self.args

        slice_xyz = common.slice_index_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        fields = Fields(nx, ny, nz, '', 'single')
        setf = SetFields(fields, 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(fields.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
        ehs = [np.zeros(fields.ns, dtype=fields.dtype) for i in range(6)]
        eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs) )

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

        setf.set_fields(value)
        fields.enqueue_barrier()

        for str_f in str_fs:
            original = eh_dict[str_f]
            copy = fields.get(str_f)[:,:,fields.slice_z]
            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

        slice_xyz = common.slice_index_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        fields = Fields(nx, ny, nz, '', 'single')
        setf = SetFields(fields, 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(fields.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
        ehs = [np.zeros(fields.ns, dtype=fields.dtype) for i in range(6)]
        eh_dict = dict(zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs))

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

        setf.set_fields(value)
        fields.enqueue_barrier()

        for str_f in str_fs:
            original = eh_dict[str_f]
            copy = fields.get(str_f)[:, :, fields.slice_z]
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
    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))
# z-axis
nx, ny, nz = 180, 160, 2
fields = Fields(QueueTask(), nx, ny, nz)
Core(fields)
Pbc(fields, 'xyz')
IncidentDirect(fields, 'ey', (20, 0, 0), (20, -1, -1), tfunc)
IncidentDirect(fields, 'ex', (0, 20, 0), (-1, 20, -1), tfunc)

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

ax1 = fig.add_subplot(2, 3, 1)
ax1.imshow(fields.get('ey')[:, :, nz / 2].T, vmin=-1.1, vmax=1.1)
ax1.set_title('%s, ey[20,:,:]' % repr(fields.ns))
ax1.set_xlabel('x')
ax1.set_ylabel('y')

ax2 = fig.add_subplot(2, 3, 4)
ax2.imshow(fields.get('ex')[:, :, nz / 2].T, vmin=-1.1, vmax=1.1)
ax2.set_title('%s, ex[:,20,:]' % repr(fields.ns))
ax2.set_xlabel('x')
ax2.set_ylabel('y')

# y-axis
nx, ny, nz = 180, 2, 160
fields = Fields(QueueTask(), nx, ny, nz)
Core(fields)
Pbc(fields, 'xyz')
# z-axis
nx, ny, nz = 180, 160, 2
fields = Fields(nx, ny, nz)
Core(fields)
Pbc(fields, 'xyz')
IncidentDirect(fields, 'ey', (20, 0, 0), (20, ny-1, nz-1), tfunc) 
IncidentDirect(fields, 'ex', (0, 20, 0), (nx-1, 20, nz-1), tfunc) 

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

ax1 = fig.add_subplot(2, 3, 1)
ax1.imshow(fields.get('ey')[:,:,nz/2].T, vmin=-1.1, vmax=1.1)
ax1.set_title('%s, ey[20,:,:]' % repr(fields.ns))
ax1.set_xlabel('x')
ax1.set_ylabel('y')

ax2 = fig.add_subplot(2, 3, 4)
ax2.imshow(fields.get('ex')[:,:,nz/2].T, vmin=-1.1, vmax=1.1)
ax2.set_title('%s, ex[:,20,:]' % repr(fields.ns))
ax2.set_xlabel('x')
ax2.set_ylabel('y')

# y-axis 
nx, ny, nz = 180, 2, 160
fields = Fields(nx, ny, nz)
Core(fields)
Pbc(fields, 'xyz')