def est_bound(bound, mt_rcsl_go, l_rcsl_go, sig_mis_go, num): dum_bpn = np.array([[0, 0, 1]]) _, bp_symm_grp, _ = fpf.five_param_fz(sig_mis_go, dum_bpn) cube_grid, gs = make_grid(num, bp_symm_grp) req_bpn = 6 * gs * gs flag = True while flag: mil_ind_csl = gen_hkl(bound, mt_rcsl_go) ### Converting the miller indices to normals in po frame bpn_go = np.dot(l_rcsl_go, mil_ind_csl.transpose()).transpose() ### Finding the boundary plane normals in the FZ using five_param_fz bp_fz_norms_go1, bp_symm_grp, symm_grp_ax = fpf.five_param_fz(sig_mis_go, bpn_go) bp_fz_norms_go1_unq = GBt.unique_rows_tol(bp_fz_norms_go1, tol=1e-06) num_bpn_fz = len(bp_fz_norms_go1_unq) est_para = 20 if bp_symm_grp == "C_s": num_bpn_sp = 2 * num_bpn_fz elif bp_symm_grp == "C_2h": est_para = 50 num_bpn_sp = 4 * num_bpn_fz elif bp_symm_grp == "D_3d": num_bpn_sp = 12 * num_bpn_fz elif bp_symm_grp == "D_2h": num_bpn_sp = 8 * num_bpn_fz est_para = 200 elif bp_symm_grp == "D_4h": num_bpn_sp = 16 * num_bpn_fz elif bp_symm_grp == "D_6h": num_bpn_sp = 24 * num_bpn_fz elif bp_symm_grp == "D_8h": num_bpn_sp = 32 * num_bpn_fz elif bp_symm_grp == "O_h": num_bpn_sp = 48 * num_bpn_fz # para_1 = len(bp_fz_norms_go1)/num_bpn_fz if num_bpn_sp >= est_para * req_bpn: flag = False else: bound = bound * 2 print bound return bp_fz_norms_go1_unq, bp_symm_grp, symm_grp_ax, cube_grid, gs
def plots(mesh_size, sigma_val, n, lat_type): #################################################################################################################### ### Creating an array of boundary plane miller indices in CSL lattice mil_ind_csl = gen_miller_ind(mesh_size) #################################################################################################################### ### Creating an instance of lattice class elem = GBl.Lattice(lat_type) ### Getting the primitive lattice in orthogonal frame l_g_go = elem.l_g_go ### Extracting the sigma misorientation from the pickle file ### Misorientation is in the primitive frame of associated lattice gb_dir = os.path.dirname(inspect.getfile(GBpy)) pkl_path = gb_dir + '/pkl_files/cF_Id_csl_common_rotations.pkl' pkl_content = pickle.load(open(pkl_path)) sig_mis_N = pkl_content[str(sigma_val)]['N'][0] sig_mis_D = pkl_content[str(sigma_val)]['D'][0] sig_mis_g = sig_mis_N/sig_mis_D ### Converting the misorientation to orthogonal frame/superlattice of the crystal ### Done using similarity transformation sig_mis_go = np.dot(np.dot(l_g_go, sig_mis_g), np.linalg.inv(l_g_go)).reshape(1,3,3)[0] ### Getting the csl basis in primitive frame l_csl_g, l_dsc_g = GBfcd.find_csl_dsc(l_g_go, sig_mis_g) ### Converting the csl basis to orthogonal frame l_csl_go = np.dot(l_g_go, l_csl_g) ### reciprocal csl basis in po frame l_rcsl_go = GBfcd.reciprocal_mat(l_csl_go) ### Converting the miller indices to normals in po frame bpn_go = np.dot(l_rcsl_go, mil_ind_csl.transpose()).transpose() #################################################################################################################### ### Finding the boundary plane normals in the FZ using five_param_fz bp_fz_norms_go1, bp_symm_grp, symm_grp_ax = five_param_fz(sig_mis_go, bpn_go) ### Finding unique normals bp_fz_norms_go1_unq, bfz_unq_ind = GBt.unique_rows_tol(bp_fz_norms_go1, return_index=True) ### Finding the input hkl indices corresponding to unique FZ normals mil_ind_csl_unq = mil_ind_csl[bfz_unq_ind] #################################################################################################################### ### Calculating interplanar distance (d sigma hkl) for unique FZ bpn l_rcsl_go = GBfcd.reciprocal_mat(l_csl_go) mt_cslr_go = np.dot(l_rcsl_go.transpose(), l_rcsl_go) d_inv_sqr = np.diag(np.dot(np.dot(mil_ind_csl_unq, mt_cslr_go),mil_ind_csl_unq.transpose())) d_inv = np.sqrt(d_inv_sqr) d_sig_hkl = np.true_divide(1, d_inv) #################################################################################################################### ### Calculating unit cell area for 2-D csl unit cells for unique FZ bpn pl_den = [] num_bpn_unq = np.shape(bp_fz_norms_go1_unq)[0] for ct1 in range(num_bpn_unq): _, _, pl_den_csl = GBb2.bicryst_planar_den(bp_fz_norms_go1_unq[ct1, :], sig_mis_g, l_g_go, 'normal_go', 'g1') pl_den.append(pl_den_csl) pl_den = np.array(pl_den) a_sig_hkl = np.true_divide(1, pl_den) #################################################################################################################### ### Checking the csl primitive unit cell volume equality v_sig_hkl = np.multiply(d_sig_hkl, a_sig_hkl) # print v_sig_hkl v_basis = abs(np.linalg.det(l_csl_go)) if np.all(abs(v_sig_hkl-v_basis) < 1e-04): print "The two volumes match!" else: print " Mismatch!" #################################################################################################################### ### Sorting attributes in increasing order of 2d csl primitive unit cell area ind_area_sort = np.argsort(a_sig_hkl) a_sig_hkl_sort = np.sort(a_sig_hkl) d_sig_hkl_sort = d_sig_hkl[ind_area_sort] bp_fz_norms_go1_unq_sort = bp_fz_norms_go1_unq[ind_area_sort] #################################################################################################################### ### Check to ensure required number of unique bpn are returned if np.shape(bp_fz_norms_go1_unq_sort)[0] < n: print "Please input a larger mesh grid or reduce the number of boundaries!" n = np.shape(bp_fz_norms_go1_unq_sort)[0] #################################################################################################################### ### Selecting the lowest 'n' area boundaries and their attributes for plotting a_plot = a_sig_hkl_sort[:n] pd_plot = np.true_divide(1, a_plot) d_plot = d_sig_hkl_sort[:n] bp_fz_plot = bp_fz_norms_go1_unq_sort[:n] #################################################################################################################### ### d vs pd plot fig1 = plt.figure(figsize=(12, 12), facecolor='w') plt.margins(0.05) plt.xlabel('Interplanar spacing') plt.ylabel('Planar density of 2D-CSL') plt.plot(d_plot, pd_plot, 'ro') # plt.show() plt.savefig('d_vs_pd_' + str(mesh_size) + '_' + str(n)+ '.png', dpi=100, bbox_inches='tight') #################################################################################################################### ### FZ plot for the sorted and selected boundaries na = '_'+ str(mesh_size) + '_'+ str(n) plot_fig(symm_grp_ax, bp_fz_plot, np.pi/6, na) # plt.show() return
def pick_uni_bpn(num, sigma_val, lat_type, bound=10, plot_sw=False): ### Creating an instance of lattice class elem = GBl.Lattice(lat_type) ### Getting the primitive lattice in orthogonal frame l_g_go = elem.l_g_go ### Extracting the sigma misorientation from the pickle file ### Misorientation is in the primitive frame of associated lattice gb_dir = os.path.dirname(inspect.getfile(GBpy)) pkl_path = gb_dir + "/pkl_files/cF_Id_csl_common_rotations.pkl" pkl_content = pickle.load(open(pkl_path)) pub_out = [] for i in range(len(pkl_content[str(sigma_val)]["N"])): sig_mis_N = pkl_content[str(sigma_val)]["N"][i] sig_mis_D = pkl_content[str(sigma_val)]["D"][i] sig_mis_g = sig_mis_N / sig_mis_D sig_mis_go = np.dot(np.dot(l_g_go, sig_mis_g), np.linalg.inv(l_g_go)).reshape(1, 3, 3)[0] ### Getting the csl basis in primitive frame l_csl_g, l_dsc_g = GBfcd.find_csl_dsc(l_g_go, sig_mis_g) ### Converting the csl basis to orthogonal frame l_csl_go = np.dot(l_g_go, l_csl_g) ### reciprocal csl basis in po frame l_rcsl_go = GBfcd.reciprocal_mat(l_csl_go) mt_rcsl_go = np.dot(l_rcsl_go.transpose(), l_rcsl_go) bp_fz, bp_symm_grp, symm_grp_ax, cube_grid, gs = est_bound(bound, mt_rcsl_go, l_rcsl_go, sig_mis_go, num) bpn_sphr = fz2sphr(bp_fz, bp_symm_grp, symm_grp_ax) bpn = csl_area_sort(bpn_sphr, l_rcsl_go, mt_rcsl_go) bpn_grid = bpn_in_grid(bpn, cube_grid, gs, l_rcsl_go, mt_rcsl_go) bpn_grid_fz, _, _ = fpf.five_param_fz(sig_mis_go, bpn_grid) bpn_grid_fz = GBt.unique_rows_tol(bpn_grid_fz, tol=1e-06) bpn_sort, hkl_sort = csl_area_sort(bpn_grid_fz, l_rcsl_go, mt_rcsl_go, return_hkl=True) #### Preparing to pickle the contents num_hkl = len(hkl_sort) print num_hkl, "\n" hkl_save = np.hstack((np.arange(1, num_hkl + 1, 1).reshape(num_hkl, 1), hkl_sort)) bpn_save = np.hstack((np.arange(1, num_hkl + 1, 1).reshape(num_hkl, 1), bpn_sort)) mis_id = "Sig_" + str(sigma_val) + "_" + str(i) symm_ax = np.dot(np.linalg.inv(l_g_go), symm_grp_ax) sig_attr = [mis_id, hkl_save, bpn_save, sig_mis_g, bp_symm_grp, symm_ax] # pkl_file = mis_id + '.pkl' # jar = open(pkl_file, 'wb') # pickle.dump(sig_attr, jar) # jar.close() if plot_sw == True: plot_2d(bpn_grid, gs) grid_lines_sphr = grid(gs) plot_3d(grid_lines_sphr, bpn_grid) plot_3d(grid_lines_sphr, bpn) pub_out.append(sig_attr) # print pub_out, '\n' return pub_out