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 test(self): nx, ny, nz = 40, 50, 60 tmax = 10 # buffer instance if rank == 0: fields = Fields(10, ny, nz, mpi_type='x+') exmpi = ExchangeMpi(fields, 1, tmax) elif rank == 1: fields = Fields(3, ny, nz, mpi_type='x-') exmpi = ExchangeMpi(fields, 0, tmax) # generate random source nx, ny, nz = fields.ns ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype) fields.set_ehs(*ehs) # verify for tstep in xrange(1, tmax + 1): fields.update_e() fields.update_h() getf_dict = {} if rank == 0: getf_dict['e'] = GetFields(fields, ['ey', 'ez'], \ (nx-1, 0, 0), (nx-1, ny-2, nz-2)) getf_dict['h'] = GetFields(fields, ['hy', 'hz'], \ (1, 1, 1), (1, ny-1, nz-1)) for eh in ['e', 'h']: getf = getf_dict[eh] getf.get_event().wait() g0 = getf.get_fields() g1 = np.zeros_like(g0) comm.Recv(g1, 1, tag=10) norm = np.linalg.norm(g0 - g1) self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'x', 'e')) elif rank == 1: getf_dict['e'] = GetFields(fields, ['ey', 'ez'], \ (nx-2, 0, 0), (nx-2, ny-2, nz-2)) getf_dict['h'] = GetFields(fields, ['hy', 'hz'], \ (0, 1, 1), (0, ny-1, nz-1)) for eh in ['e', 'h']: getf = getf_dict[eh] getf.get_event().wait() comm.Send(getf.get_fields(), 0, tag=10)
def test(self): nx, ny, nz = 40, 50, 60 tmax = 10 # buffer instance if rank == 0: fields = Fields(10, ny, nz, mpi_type="x+") exmpi = ExchangeMpi(fields, 1, tmax) elif rank == 1: fields = Fields(3, ny, nz, mpi_type="x-") exmpi = ExchangeMpi(fields, 0, tmax) # generate random source nx, ny, nz = fields.ns ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype) fields.set_ehs(*ehs) # verify for tstep in xrange(1, tmax + 1): fields.update_e() fields.update_h() getf_dict = {} if rank == 0: getf_dict["e"] = GetFields(fields, ["ey", "ez"], (nx - 1, 0, 0), (nx - 1, ny - 2, nz - 2)) getf_dict["h"] = GetFields(fields, ["hy", "hz"], (1, 1, 1), (1, ny - 1, nz - 1)) for eh in ["e", "h"]: getf = getf_dict[eh] getf.get_event().wait() g0 = getf.get_fields() g1 = np.zeros_like(g0) comm.Recv(g1, 1, tag=10) norm = np.linalg.norm(g0 - g1) self.assertEqual(norm, 0, "%g, %s, %s" % (norm, "x", "e")) elif rank == 1: getf_dict["e"] = GetFields(fields, ["ey", "ez"], (nx - 2, 0, 0), (nx - 2, ny - 2, nz - 2)) getf_dict["h"] = GetFields(fields, ["hy", "hz"], (0, 1, 1), (0, ny - 1, nz - 1)) for eh in ["e", "h"]: getf = getf_dict[eh] getf.get_event().wait() comm.Send(getf.get_fields(), 0, tag=10)
def runTest(self): nx, ny, nz, str_f, pt0, pt1 = 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') getf = GetFields(fields, str_f, pt0, pt1) # host allocations ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype) eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs) ) fields.set_ehs(*ehs) # verify getf.get_event().wait() for str_f in str_fs: original = eh_dict[str_f][slice_xyz] 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 slice_xyz = common.slice_index_two_points(pt0, pt1) str_fs = common.convert_to_tuple(str_f) # instance fields = Fields(nx, ny, nz, '', 'single') getf = GetFields(fields, str_f, pt0, pt1) # host allocations ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype) eh_dict = dict(zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs)) fields.set_ehs(*ehs) # verify getf.get_event().wait() for str_f in str_fs: original = eh_dict[str_f][slice_xyz] copy = getf.get_fields(str_f) 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))
def runTest(self): axis, nx, ny, nz, mpi_type = self.args fields = Fields(nx, ny, nz, mpi_type=mpi_type) core = Core(fields) pbc = Pbc(fields, axis) # allocations ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype) fields.set_ehs(*ehs) # update fields.update_e() fields.update_h() fields.enqueue_barrier() # verify getf0, getf1 = {}, {} strfs_e = {'x':['ey', 'ez'], 'y':['ex', 'ez'], 'z':['ex', 'ey']}[axis] strfs_h = {'x':['hy', 'hz'], 'y':['hx', 'hz'], 'z':['hx', 'hy']}[axis] pt0 = (0, 0, 0) pt1 = { 'x': (0, ny-2, nz-2), \ 'y': (nx-2, 0, nz-2), \ 'z': (nx-2, ny-2, 0) }[axis] getf0['e'] = GetFields(fields, strfs_e, pt0, pt1) pt0 = { 'x': (nx-1, 0, 0), \ 'y': (0, ny-1, 0), \ 'z': (0, 0, nz-1) }[axis] pt1 = { 'x': (nx-1, ny-2, nz-2), \ 'y': (nx-2, ny-1, nz-2), \ 'z': (nx-2, ny-2, nz-1) }[axis] getf1['e'] = GetFields(fields, strfs_e, pt0, pt1) pt0 = { 'x': (0, 1, 1), \ 'y': (1, 0, 1), \ 'z': (1, 1, 0) }[axis] pt1 = { 'x': (0, ny-1, nz-1), \ 'y': (nx-1, 0, nz-1), \ 'z': (nx-1, ny-1, 0) }[axis] getf0['h'] = GetFields(fields, strfs_h, pt0, pt1) pt0 = { 'x': (nx-1, 1, 1), \ 'y': (1, ny-1, 1), \ 'z': (1, 1, nz-1) }[axis] pt1 = (nx-1, ny-1, nz-1) getf1['h'] = GetFields(fields, strfs_h, pt0, pt1) for getf in getf0.values() + getf1.values(): getf.get_event().wait() for eh in ['e', 'h']: g0 = getf0[eh].get_fields() g1 = getf1[eh].get_fields() norm = np.linalg.norm(g0 - g1) ''' print eh print g0 print g1 ''' self.assertEqual(norm, 0, '%g, %s, %s' % (norm, self.args, eh))
def runTest(self): axis, nx, ny, nz, mpi_type = self.args fields = Fields(nx, ny, nz, mpi_type=mpi_type) core = Core(fields) pbc = Pbc(fields, axis) # allocations ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype) fields.set_ehs(*ehs) # update fields.update_e() fields.update_h() fields.enqueue_barrier() # verify getf0, getf1 = {}, {} strfs_e = { 'x': ['ey', 'ez'], 'y': ['ex', 'ez'], 'z': ['ex', 'ey'] }[axis] strfs_h = { 'x': ['hy', 'hz'], 'y': ['hx', 'hz'], 'z': ['hx', 'hy'] }[axis] pt0 = (0, 0, 0) pt1 = { 'x': (0, ny-2, nz-2), \ 'y': (nx-2, 0, nz-2), \ 'z': (nx-2, ny-2, 0) }[axis] getf0['e'] = GetFields(fields, strfs_e, pt0, pt1) pt0 = { 'x': (nx-1, 0, 0), \ 'y': (0, ny-1, 0), \ 'z': (0, 0, nz-1) }[axis] pt1 = { 'x': (nx-1, ny-2, nz-2), \ 'y': (nx-2, ny-1, nz-2), \ 'z': (nx-2, ny-2, nz-1) }[axis] getf1['e'] = GetFields(fields, strfs_e, pt0, pt1) pt0 = { 'x': (0, 1, 1), \ 'y': (1, 0, 1), \ 'z': (1, 1, 0) }[axis] pt1 = { 'x': (0, ny-1, nz-1), \ 'y': (nx-1, 0, nz-1), \ 'z': (nx-1, ny-1, 0) }[axis] getf0['h'] = GetFields(fields, strfs_h, pt0, pt1) pt0 = { 'x': (nx-1, 1, 1), \ 'y': (1, ny-1, 1), \ 'z': (1, 1, nz-1) }[axis] pt1 = (nx - 1, ny - 1, nz - 1) getf1['h'] = GetFields(fields, strfs_h, pt0, pt1) for getf in getf0.values() + getf1.values(): getf.get_event().wait() for eh in ['e', 'h']: g0 = getf0[eh].get_fields() g1 = getf1[eh].get_fields() norm = np.linalg.norm(g0 - g1) ''' print eh print g0 print g1 ''' self.assertEqual(norm, 0, '%g, %s, %s' % (norm, self.args, eh))