def __init__(self, fields, str_f, pt0, pt1): """ """ common.check_type('fields', fields, Fields) common.check_type('str_f', str_f, (str, list, tuple), str) common.check_type('pt0', pt0, (list, tuple), int) common.check_type('pt1', pt1, (list, tuple), int) # local variables nodef = fields str_fs = common.convert_to_tuple(str_f) mainf_list = nodef.mainf_list anx = nodef.accum_nx_list for strf in str_fs: strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz'] common.check_value('str_f', strf, strf_list) for axis, n, p0, p1 in zip(['x', 'y', 'z'], nodef.ns, pt0, pt1): common.check_value('pt0 %s' % axis, p0, range(n)) common.check_value('pt1 %s' % axis, p1, range(n)) # allocation shape = common.shape_two_points(pt0, pt1, len(str_fs)) dummied_shape = common.shape_two_points(pt0, pt1, is_dummy=True) host_array = np.zeros(shape, dtype=nodef.dtype) split_host_array = np.split(host_array, len(str_fs)) split_host_array_dict = dict(zip(str_fs, split_host_array)) getf_list = [] slices_list = [] self.gpu, self.cpu = gpu, cpu for i, mainf in enumerate(mainf_list): nx0 = anx[i] nx1 = anx[i + 1] - 1 if i < len(mainf_list) - 1 else anx[i + 1] overlap = common.intersection_two_lines((nx0, nx1), (pt0[0], pt1[0])) if overlap != None: x0, y0, z0 = pt0 x1, y1, z1 = pt1 slice_pt0 = (overlap[0] - x0, 0, 0) slice_pt1 = (overlap[1] - x0, y1 - y0, z1 - z0) slices = [] for j, p0, p1 in zip([0, 1, 2], slice_pt0, slice_pt1): if dummied_shape[j] != 1: slices.append(slice(p0, p1 + 1)) slices_list.append(slices if slices != [] else [slice(0, 1)]) local_pt0 = (overlap[0] - nx0, y0, z0) local_pt1 = (overlap[1] - nx0, y1, z1) getf_list.append( getattr(self, mainf.device_type). \ GetFields(mainf, str_fs, local_pt0, local_pt1) ) # global variables self.str_fs = str_fs self.host_array = host_array self.split_host_array_dict = split_host_array_dict self.getf_list = getf_list self.slices_list = slices_list
def __init__(self, fields, str_f, pt0, pt1, is_array=False, is_overwrite=True): """ """ common.check_type('fields', fields, Fields) common.check_type('str_f', str_f, (str, list, tuple), str) common.check_type('pt0', pt0, (list, tuple), int) common.check_type('pt1', pt1, (list, tuple), int) common.check_type('is_array', is_array, bool) common.check_type('is_overwrite', is_overwrite, bool) # local variables nodef = fields str_fs = common.convert_to_tuple(str_f) mainf_list = nodef.mainf_list anx = nodef.accum_nx_list for strf in str_fs: strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz'] common.check_value('str_f', strf, strf_list) for axis, n, p0, p1 in zip(['x', 'y', 'z'], nodef.ns, pt0, pt1): common.check_value('pt0 %s' % axis, p0, range(n)) common.check_value('pt1 %s' % axis, p1, range(n)) # allocation dummied_shape = common.shape_two_points(pt0, pt1, is_dummy=True) setf_list = [] slices_list = [] self.gpu, self.cpu = gpu, cpu for i, mainf in enumerate(mainf_list): nx0 = anx[i] nx1 = anx[i + 1] overlap = common.intersection_two_lines((nx0, nx1), (pt0[0], pt1[0])) if overlap != None: x0, y0, z0 = pt0 x1, y1, z1 = pt1 slice_pt0 = (overlap[0] - x0, 0, 0) slice_pt1 = (overlap[1] - x0, y1 - y0, z1 - z0) slices = [] for j, p0, p1 in zip([0, 1, 2], slice_pt0, slice_pt1): if dummied_shape[j] != 1: slices.append(slice(p0, p1 + 1)) slices_list.append(slices if slices != [] else [slice(0, 1)]) local_pt0 = (overlap[0] - nx0, y0, z0) local_pt1 = (overlap[1] - nx0, y1, z1) setf_list.append( getattr(self, mainf.device_type). \ SetFields(mainf, str_fs, local_pt0, local_pt1, \ is_array, is_overwrite) ) # global variables and functions self.str_fs = str_fs self.dtype = nodef.dtype self.shape = common.shape_two_points(pt0, pt1, len(str_fs)) self.setf_list = setf_list self.slices_list = slices_list if is_array: self.set_fields = self.set_fields_spatial_value else: self.set_fields = self.set_fields_single_value
def __init__(self, fields, str_f, pt0, pt1): """ """ common.check_type('fields', fields, Fields) common.check_type('str_f', str_f, (str, list, tuple), str) common.check_type('pt0', pt0, (list, tuple), int) common.check_type('pt1', pt1, (list, tuple), int) # local variables nodef = fields str_fs = common.convert_to_tuple(str_f) mainf_list = nodef.mainf_list anx = nodef.accum_nx_list for strf in str_fs: strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz'] common.check_value('str_f', strf, strf_list) for axis, n, p0, p1 in zip(['x', 'y', 'z'], nodef.ns, pt0, pt1): common.check_value('pt0 %s' % axis, p0, range(n)) common.check_value('pt1 %s' % axis, p1, range(n)) # allocation shape = common.shape_two_points(pt0, pt1, len(str_fs)) dummied_shape = common.shape_two_points(pt0, pt1, is_dummy=True) host_array = np.zeros(shape, dtype=nodef.dtype) split_host_array = np.split(host_array, len(str_fs)) split_host_array_dict = dict( zip(str_fs, split_host_array) ) getf_list = [] slices_list = [] self.gpu, self.cpu = gpu, cpu for i, mainf in enumerate(mainf_list): nx0 = anx[i] nx1 = anx[i+1]-1 if i < len(mainf_list)-1 else anx[i+1] overlap = common.intersection_two_lines((nx0, nx1), (pt0[0], pt1[0])) if overlap != None: x0, y0, z0 = pt0 x1, y1, z1 = pt1 slice_pt0 = (overlap[0]-x0, 0, 0) slice_pt1 = (overlap[1]-x0, y1-y0, z1-z0) slices = [] for j, p0, p1 in zip([0, 1, 2], slice_pt0, slice_pt1): if dummied_shape[j] != 1: slices.append( slice(p0, p1+1) ) slices_list.append(slices if slices!=[] else [slice(0, 1)] ) local_pt0 = (overlap[0]-nx0, y0, z0) local_pt1 = (overlap[1]-nx0, y1, z1) getf_list.append( getattr(self, mainf.device_type). \ GetFields(mainf, str_fs, local_pt0, local_pt1) ) # global variables self.str_fs = str_fs self.host_array = host_array self.split_host_array_dict = split_host_array_dict self.getf_list = getf_list self.slices_list = slices_list
def __init__(self, fields, str_f, pt0, pt1, is_array=False, is_overwrite=True): """ """ common.check_type('fields', fields, Fields) common.check_type('str_f', str_f, (str, list, tuple), str) common.check_type('pt0', pt0, (list, tuple), int) common.check_type('pt1', pt1, (list, tuple), int) common.check_type('is_array', is_array, bool) common.check_type('is_overwrite', is_overwrite, bool) # local variables nodef = fields str_fs = common.convert_to_tuple(str_f) mainf_list = nodef.mainf_list anx = nodef.accum_nx_list for strf in str_fs: strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz'] common.check_value('str_f', strf, strf_list) for axis, n, p0, p1 in zip(['x', 'y', 'z'], nodef.ns, pt0, pt1): common.check_value('pt0 %s' % axis, p0, range(n)) common.check_value('pt1 %s' % axis, p1, range(n)) # allocation dummied_shape = common.shape_two_points(pt0, pt1, is_dummy=True) setf_list = [] slices_list = [] self.gpu, self.cpu = gpu, cpu for i, mainf in enumerate(mainf_list): nx0 = anx[i] nx1 = anx[i+1] overlap = common.intersection_two_lines((nx0, nx1), (pt0[0], pt1[0])) if overlap != None: x0, y0, z0 = pt0 x1, y1, z1 = pt1 slice_pt0 = (overlap[0]-x0, 0, 0) slice_pt1 = (overlap[1]-x0, y1-y0, z1-z0) slices = [] for j, p0, p1 in zip([0, 1, 2], slice_pt0, slice_pt1): if dummied_shape[j] != 1: slices.append( slice(p0, p1+1) ) slices_list.append(slices if slices!=[] else [slice(0, 1)] ) local_pt0 = (overlap[0]-nx0, y0, z0) local_pt1 = (overlap[1]-nx0, y1, z1) setf_list.append( getattr(self, mainf.device_type). \ SetFields(mainf, str_fs, local_pt0, local_pt1, \ is_array, is_overwrite) ) # global variables and functions self.str_fs = str_fs self.dtype = nodef.dtype self.shape = common.shape_two_points(pt0, pt1, len(str_fs)) self.setf_list = setf_list self.slices_list = slices_list if is_array: self.set_fields = self.set_fields_spatial_value else: self.set_fields = self.set_fields_single_value
def __init__(self, node_fields, str_f, pt0, pt1, tfunc, spatial_value=1., is_overwrite=False): """ """ common.check_type('node_fields', node_fields, NodeFields) common.check_value('str_f', str_f, ('ex', 'ey', 'ez', 'hx', 'hy', 'hz')) common.check_type('pt0', pt0, (list, tuple), int) common.check_type('pt1', pt1, (list, tuple), int) common.check_type('tfunc', tfunc, types.FunctionType) common.check_type('spatial_value', spatial_value, \ (np.ndarray, np.number, types.FloatType, types.IntType) ) common.check_type('is_overwrite', is_overwrite, bool) # local variables nodef = node_fields dtype = nodef.dtype is_array = True if isinstance(spatial_value, np.ndarray) else False mainf_list = nodef.mainf_list anx = nodef.accum_nx_list for axis, n, p0, p1 in zip(['x', 'y', 'z'], nodef.ns, pt0, pt1): common.check_value('pt0 %s' % axis, p0, range(n)) common.check_value('pt1 %s' % axis, p1, range(n)) if is_array: shape = common.shape_two_points(pt0, pt1) assert shape == spatial_value.shape, \ 'shape mismatch : %s, %s' % (shape, spatial_value.shape) assert dtype == spatial_value.dtype, \ 'dtype mismatch : %s, %s' % (dtype, spatial_value.dtype) else: spatial_value = dtype(spatial_value) # allocation dummied_shape = common.shape_two_points(pt0, pt1, is_dummy=True) incident_list = [] reduced_slices = [] self.gpu, self.cpu = gpu, cpu for i, mainf in enumerate(mainf_list): nx0 = anx[i] nx1 = anx[i+1] overlap = common.intersection_two_lines((nx0, nx1), (pt0[0], pt1[0])) if overlap != None: x0, y0, z0 = pt0 x1, y1, z1 = pt1 shift_pt0 = (overlap[0]-x0, y0-y0, z0-z0) shift_pt1 = (overlap[1]-x0, y1-y0, z1-z0) shift_slices = [slice(p0, p1+1) for p0, p1 in zip(shift_pt0, shift_pt1)] if is_array: reshaped_value = spatial_value.reshape(dummied_shape) dummied_array = reshaped_value[shift_slices] overlap_shape = common.shape_two_points(shift_pt0, shift_pt1) split_value = dummied_array.reshape(overlap_shape).copy() else: split_value = spatial_value local_pt0 = (overlap[0]-nx0, y0, z0) local_pt1 = (overlap[1]-nx0, y1, z1) incident_list.append( \ getattr(self, mainf.device_type). \ DirectIncident(mainf, str_f, local_pt0, local_pt1, \ tfunc, split_value, is_overwrite) ) # global variables self.incident_list = incident_list
def __init__(self, node_fields, str_f, pt0, pt1, tfunc, spatial_value=1., is_overwrite=False): """ """ common.check_type('node_fields', node_fields, NodeFields) common.check_value('str_f', str_f, ('ex', 'ey', 'ez', 'hx', 'hy', 'hz')) common.check_type('pt0', pt0, (list, tuple), int) common.check_type('pt1', pt1, (list, tuple), int) common.check_type('tfunc', tfunc, types.FunctionType) common.check_type('spatial_value', spatial_value, \ (np.ndarray, np.number, types.FloatType, types.IntType) ) common.check_type('is_overwrite', is_overwrite, bool) # local variables nodef = node_fields dtype = nodef.dtype is_array = True if isinstance(spatial_value, np.ndarray) else False mainf_list = nodef.mainf_list anx = nodef.accum_nx_list for axis, n, p0, p1 in zip(['x', 'y', 'z'], nodef.ns, pt0, pt1): common.check_value('pt0 %s' % axis, p0, range(n)) common.check_value('pt1 %s' % axis, p1, range(n)) if is_array: shape = common.shape_two_points(pt0, pt1) assert shape == spatial_value.shape, \ 'shape mismatch : %s, %s' % (shape, spatial_value.shape) assert dtype == spatial_value.dtype, \ 'dtype mismatch : %s, %s' % (dtype, spatial_value.dtype) else: spatial_value = dtype(spatial_value) # allocation dummied_shape = common.shape_two_points(pt0, pt1, is_dummy=True) incident_list = [] reduced_slices = [] self.gpu, self.cpu = gpu, cpu for i, mainf in enumerate(mainf_list): nx0 = anx[i] nx1 = anx[i + 1] overlap = common.intersection_two_lines((nx0, nx1), (pt0[0], pt1[0])) if overlap != None: x0, y0, z0 = pt0 x1, y1, z1 = pt1 shift_pt0 = (overlap[0] - x0, y0 - y0, z0 - z0) shift_pt1 = (overlap[1] - x0, y1 - y0, z1 - z0) shift_slices = [ slice(p0, p1 + 1) for p0, p1 in zip(shift_pt0, shift_pt1) ] if is_array: reshaped_value = spatial_value.reshape(dummied_shape) dummied_array = reshaped_value[shift_slices] overlap_shape = common.shape_two_points( shift_pt0, shift_pt1) split_value = dummied_array.reshape(overlap_shape).copy() else: split_value = spatial_value local_pt0 = (overlap[0] - nx0, y0, z0) local_pt1 = (overlap[1] - nx0, y1, z1) incident_list.append( \ getattr(self, mainf.device_type). \ DirectIncident(mainf, str_f, local_pt0, local_pt1, \ tfunc, split_value, is_overwrite) ) # global variables self.incident_list = incident_list