def set_savefields(self, str_f, pt0, pt1, tstep_range, dir_path, tag=0): common.check_type('str_f', str_f, (str, list, tuple), str) common.check_type('pt0', pt0, (list, tuple), (int, float)) common.check_type('pt1', pt1, (list, tuple), (int, float)) common.check_type('tstep_range', tstep_range, (list, tuple), int) common.check_type('dir_path', dir_path, str) common.check_type('tag', tag, int) pt0 = common.convert_indices(self.ns, pt0) pt1 = common.convert_indices(self.ns, pt1) t0 = common.convert_index(self.max_tstep, tstep_range[0]) t1 = common.convert_index(self.max_tstep, tstep_range[1]) + 1 tgap = tstep_range[2] tmax = self.max_tstep tag = tag if tag not in self.savef_tag_list else max(self.savef_tag_list)+1 self.savef_tag_list.append(tag) if is_mpi: overlap = common.overlap_two_regions(self.node_pt0, self.node_pt1, pt0, pt1) if overlap != None: sx0, sy0, sz0 = self.node_pt0 ox0, oy0, oz0 = overlap[0] ox1, oy1, oz1 = overlap[1] local_pt0 = (ox0-sx0, oy0-sy0, oz0-sz0) local_pt1 = (ox1-sx0, oy1-sy0, oz1-sz0) savef = node.SaveFields(self.nodef, str_f, local_pt0, local_pt1, dir_path, tag, tmax, True, rank) self.savef_list.append(savef) else: savef = node.SaveFields(self.nodef, str_f, pt0, pt1, dir_path, tag, tmax) self.savef_list.append(savef) # save the subdomain informations as pickle if self.is_master: if is_mpi: divide_info_dict = common_mpi.divide_info_dict(size, self.mpi_shape, pt0, pt1, self.asn_dict) else: divide_info_dict = { \ 'shape': common.shape_two_points(pt0, pt1), \ 'pt0': pt0, \ 'pt1': pt1, \ 'anx_list': self.nodef.accum_nx_list } divide_info_dict['str_fs'] = common.convert_to_tuple(str_f) divide_info_dict['tmax'] = tmax divide_info_dict['tgap'] = tgap pkl_file = open(dir_path + 'divide_info.pkl', 'wb') pickle.dump(divide_info_dict, pkl_file) pkl_file.close() self.t0 = t0 self.t1 = t1 self.tgap = tgap
def set_incident_direct(self, str_f, pt0, pt1, tfunc, spatial_value=1., is_overwrite=False): common.check_value('str_f', str_f, ('ex', 'ey', 'ez', 'hx', 'hy', 'hz')) common.check_type('pt0', pt0, (list, tuple), (int, float)) common.check_type('pt1', pt1, (list, tuple), (int, float)) 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) pt0 = list(common.convert_indices(self.ns, pt0)) pt1 = list(common.convert_indices(self.ns, pt1)) if is_mpi: node_pt0 = list(self.node_pt0) node_pt1 = list(self.node_pt1) for i, axis in enumerate(['x', 'y', 'z']): if self.nodef.buffer_dict.has_key('%s+' % axis): node_pt1[i] += 1 if self.nodef.buffer_dict.has_key('%s-' % axis): node_pt0[i] -= 1 if coord[i] == 0 and pt0[i] == 0: pt0[i] -= 1 if coord[i] == self.mpi_shape[i] - 1 and pt1[ i] == self.ns[i] - 1: pt1[i] += 1 overlap = common.overlap_two_regions(node_pt0, node_pt1, pt0, pt1) if overlap != None: sx0, sy0, sz0 = self.node_pt0 ox0, oy0, oz0 = overlap[0] ox1, oy1, oz1 = overlap[1] local_pt0 = (ox0 - sx0, oy0 - sy0, oz0 - sz0) local_pt1 = (ox1 - sx0, oy1 - sy0, oz1 - sz0) node.IncidentDirect(self.nodef, str_f, local_pt0, local_pt1, tfunc, spatial_value, is_overwrite) else: node.IncidentDirect(self.nodef, str_f, pt0, pt1, tfunc, spatial_value, is_overwrite)
def set_incident_direct(self, str_f, pt0, pt1, tfunc, spatial_value=1., is_overwrite=False): common.check_value('str_f', str_f, ('ex', 'ey', 'ez', 'hx', 'hy', 'hz')) common.check_type('pt0', pt0, (list, tuple), (int, float)) common.check_type('pt1', pt1, (list, tuple), (int, float)) 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) pt0 = list( common.convert_indices(self.ns, pt0) ) pt1 = list( common.convert_indices(self.ns, pt1) ) if is_mpi: node_pt0 = list(self.node_pt0) node_pt1 = list(self.node_pt1) for i, axis in enumerate(['x', 'y', 'z']): if self.nodef.buffer_dict.has_key('%s+' % axis): node_pt1[i] += 1 if self.nodef.buffer_dict.has_key('%s-' % axis): node_pt0[i] -= 1 if coord[i] == 0 and pt0[i] == 0: pt0[i] -= 1 if coord[i] == self.mpi_shape[i]-1 and pt1[i] == self.ns[i]-1: pt1[i] += 1 overlap = common.overlap_two_regions(node_pt0, node_pt1, pt0, pt1) if overlap != None: sx0, sy0, sz0 = self.node_pt0 ox0, oy0, oz0 = overlap[0] ox1, oy1, oz1 = overlap[1] local_pt0 = (ox0-sx0, oy0-sy0, oz0-sz0) local_pt1 = (ox1-sx0, oy1-sy0, oz1-sz0) node.IncidentDirect(self.nodef, str_f, local_pt0, local_pt1, tfunc, spatial_value, is_overwrite) else: node.IncidentDirect(self.nodef, str_f, pt0, pt1, tfunc, spatial_value, is_overwrite)
def __init__(self, node_fields, str_f, pt0, pt1, tfunc, spatial_value=1., is_overwrite=False): """ """ common.check_type('node_fields', node_fields, Fields) 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 buffer_dict = nodef.buffer_dict anx = nodef.accum_nx_list nx, ny, nz = nodef.ns for axis, n, p0, p1 in zip(['x', 'y', 'z'], nodef.ns, pt0, pt1): start, end = 0, n if buffer_dict.has_key(axis + '+'): end = n + 1 if buffer_dict.has_key(axis + '-'): start = -1 common.check_value('pt0 %s' % axis, p0, range(start, end)) common.check_value('pt1 %s' % axis, p1, range(start, end)) 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) # global valriables self.str_f = str_f self.pt0 = pt0 self.pt1 = pt1 self.tfunc = tfunc self.spatial_value = spatial_value self.is_overwrite = is_overwrite self.is_array = is_array self.cpu = cpu if 'gpu' in [f.device_type for f in nodef.updatef_list]: from kemp.fdtd3d import gpu self.gpu = gpu # create IncidentDirect instance for i, mainf in enumerate(mainf_list): fields_pt0 = (anx[i], 0, 0) fields_pt1 = (anx[i + 1] - 1, ny - 1, nz - 1) overlap = common.overlap_two_regions(fields_pt0, fields_pt1, pt0, pt1) if overlap != None: self.create_instance(mainf, fields_pt0, fields_pt1, overlap[0], overlap[1]) # for buffer for direction, buffer in buffer_dict.items(): fields_pt0 = { \ 'x+': (anx[-1]-1, 0, 0), \ 'y+': (0, ny-2, 0), \ 'z+': (0, 0, nz-2), \ 'x-': (-1, 0, 0), \ 'y-': (0, -1, 0), \ 'z-': (0, 0, -1) }[direction] fields_pt1 = { \ 'x+': (anx[-1]+1, ny-1, nz-1), \ 'y+': (nx-1, ny, nz-1), \ 'z+': (nx-1, ny-1, nz), \ 'x-': (1, ny-1, nz-1), \ 'y-': (nx-1, 1, nz-1), \ 'z-': (nx-1, ny-1, 1) }[direction] overlap = common.overlap_two_regions(fields_pt0, fields_pt1, pt0, pt1) if overlap != None: self.create_instance(buffer, fields_pt0, fields_pt1, overlap[0], overlap[1])
def set_savefields(self, str_f, pt0, pt1, tstep_range, dir_path, tag=0): common.check_type('str_f', str_f, (str, list, tuple), str) common.check_type('pt0', pt0, (list, tuple), (int, float)) common.check_type('pt1', pt1, (list, tuple), (int, float)) common.check_type('tstep_range', tstep_range, (list, tuple), int) common.check_type('dir_path', dir_path, str) common.check_type('tag', tag, int) pt0 = common.convert_indices(self.ns, pt0) pt1 = common.convert_indices(self.ns, pt1) t0 = common.convert_index(self.max_tstep, tstep_range[0]) t1 = common.convert_index(self.max_tstep, tstep_range[1]) + 1 tgap = tstep_range[2] tmax = self.max_tstep tag = tag if tag not in self.savef_tag_list else max( self.savef_tag_list) + 1 self.savef_tag_list.append(tag) if is_mpi: overlap = common.overlap_two_regions(self.node_pt0, self.node_pt1, pt0, pt1) if overlap != None: sx0, sy0, sz0 = self.node_pt0 ox0, oy0, oz0 = overlap[0] ox1, oy1, oz1 = overlap[1] local_pt0 = (ox0 - sx0, oy0 - sy0, oz0 - sz0) local_pt1 = (ox1 - sx0, oy1 - sy0, oz1 - sz0) savef = node.SaveFields(self.nodef, str_f, local_pt0, local_pt1, dir_path, tag, tmax, True, rank) self.savef_list.append(savef) else: savef = node.SaveFields(self.nodef, str_f, pt0, pt1, dir_path, tag, tmax) self.savef_list.append(savef) # save the subdomain informations as pickle if self.is_master: if is_mpi: divide_info_dict = common_mpi.divide_info_dict( size, self.mpi_shape, pt0, pt1, self.asn_dict) else: divide_info_dict = { \ 'shape': common.shape_two_points(pt0, pt1), \ 'pt0': pt0, \ 'pt1': pt1, \ 'anx_list': self.nodef.accum_nx_list } divide_info_dict['str_fs'] = common.convert_to_tuple(str_f) divide_info_dict['tmax'] = tmax divide_info_dict['tgap'] = tgap pkl_file = open(dir_path + 'divide_info.pkl', 'wb') pickle.dump(divide_info_dict, pkl_file) pkl_file.close() self.t0 = t0 self.t1 = t1 self.tgap = tgap
def __init__(self, node_fields, str_f, pt0, pt1, tfunc, spatial_value=1., is_overwrite=False): """ """ common.check_type('node_fields', node_fields, Fields) 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 buffer_dict = nodef.buffer_dict anx = nodef.accum_nx_list nx, ny, nz = nodef.ns for axis, n, p0, p1 in zip(['x', 'y', 'z'], nodef.ns, pt0, pt1): start, end = 0, n if buffer_dict.has_key(axis+'+'): end = n + 1 if buffer_dict.has_key(axis+'-'): start = -1 common.check_value('pt0 %s' % axis, p0, range(start, end)) common.check_value('pt1 %s' % axis, p1, range(start, end)) 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) # global valriables self.str_f = str_f self.pt0 = pt0 self.pt1 = pt1 self.tfunc= tfunc self.spatial_value = spatial_value self.is_overwrite = is_overwrite self.is_array = is_array self.cpu = cpu if 'gpu' in [f.device_type for f in nodef.updatef_list]: from kemp.fdtd3d import gpu self.gpu = gpu # create IncidentDirect instance for i, mainf in enumerate(mainf_list): fields_pt0 = (anx[i], 0, 0) fields_pt1 = (anx[i+1]-1, ny-1, nz-1) overlap = common.overlap_two_regions(fields_pt0, fields_pt1, pt0, pt1) if overlap != None: self.create_instance(mainf, fields_pt0, fields_pt1, overlap[0], overlap[1]) # for buffer for direction, buffer in buffer_dict.items(): fields_pt0 = { \ 'x+': (anx[-1]-1, 0, 0), \ 'y+': (0, ny-2, 0), \ 'z+': (0, 0, nz-2), \ 'x-': (-1, 0, 0), \ 'y-': (0, -1, 0), \ 'z-': (0, 0, -1) }[direction] fields_pt1 = { \ 'x+': (anx[-1]+1, ny-1, nz-1), \ 'y+': (nx-1, ny, nz-1), \ 'z+': (nx-1, ny-1, nz), \ 'x-': (1, ny-1, nz-1), \ 'y-': (nx-1, 1, nz-1), \ 'z-': (nx-1, ny-1, 1) }[direction] overlap = common.overlap_two_regions(fields_pt0, fields_pt1, pt0, pt1) if overlap != None: self.create_instance(buffer, fields_pt0, fields_pt1, overlap[0], overlap[1])