def main(): # make environment t1 = time.time() pot_region = (2 / np.sqrt(3), 2 / np.sqrt(3), 2 / np.sqrt(3)) radius = np.sqrt(pot_region[0]**2 + pot_region[1]**2 + pot_region[2]**2) region = (radius, radius, radius) nr = 201 gridpx = 200 gridpy = 200 gridpz = 200 x, y, z = grid(gridpx, gridpy, gridpz, region) xx, yy, zz = np.meshgrid(x, y, z) #make mesh #linear mesh #r =np.linspace(0.0001,region,nr) #log mesh #a = np.log(2) / (nr - 1) a = 0.03 b = radius / (np.e**(a * (nr - 1)) - 1) rofi = np.array([b * (np.e**(a * i) - 1) for i in range(nr)]) # make potential V = makepotential(xx, yy, zz, pot_region, pottype="cubic", potbottom=-1, potshow_f=False) # surface integral V_radial = surfaceintegral(x, y, z, rofi, V, method="lebedev_py", potshow_f=False) vofi = np.array(V_radial) # select method of surface integral """ #test 20191029 V_test = np.zeros(nr,dtype=np.float64) for i in range(nr): ri = rofi[i] if ri < pot_region[0]: V_test[i] = -1 elif ri >= pot_region[0] and ri < pot_region[0] * np.sqrt(2) : V_test[i] = -1 * ( 1 - 12 * np.pi * ri * ( ri - 0.5 * radius )/(4 * np.pi * ri**2)) elif ri >= pot_region[0] * np.sqrt(2) and ri <=radius: V_test[i] = -1 * ( ri - 0.5 * np.sqrt(3) * radius ) * ( 2 - 3 * np.sqrt(2) * ( np.sqrt(2) - 1 ) ) / ( ri**2 * (np.sqrt(2) - np.sqrt(3))**2) #plt.plot(rofi,V_test,marker=".") #plt.show() V_radial = V_test vofi = V_test """ # make basis node_open = 1 node_close = 2 node = node_open + node_close LMAX = 3 nstates = node * LMAX**2 all_basis = [] for lvalsh in range(LMAX): l_basis = [] # for open channel val = 1. slo = 0. for no in range(node_open): basis = Basis(nr) emin = -10. emax = 100. basis.make_basis(a, b, emin, emax, lvalsh, no, nr, rofi, slo, vofi, val) l_basis.append(basis) # for close channel val = 0. slo = -1. for nc in range(node_close): basis = Basis(nr) emin = -10. emax = 100. basis.make_basis(a, b, emin, emax, lvalsh, nc, nr, rofi, slo, vofi, val) l_basis.append(basis) all_basis.append(l_basis) with open("wavefunc_2.dat", mode="w") as fw_w: fw_w.write("#r, l, node, open or close = ") for l_basis in all_basis: for nyu_basis in l_basis: fw_w.write(str(nyu_basis.l)) fw_w.write(str(nyu_basis.node)) if nyu_basis.open: fw_w.write("open") else: fw_w.write("close") fw_w.write(" ") fw_w.write("\n") for i in range(nr): fw_w.write("{:>13.8f}".format(rofi[i])) for l_basis in all_basis: for nyu_basis in l_basis: fw_w.write("{:>13.8f}".format(nyu_basis.g[i])) fw_w.write("\n") Smat = np.zeros((LMAX, LMAX, node, node), dtype=np.float64) hsmat = np.zeros((LMAX, LMAX, node, node), dtype=np.float64) lmat = np.zeros((LMAX, LMAX, node, node), dtype=np.float64) qmat = np.zeros((LMAX, LMAX, node, node), dtype=np.float64) """ for l1 in range (LMAX): for n1 in range (node_open + node_close): print("l1 = ",l1,"n1 = ",n1,all_basis[l1][n1].val,all_basis[l1][n1].g[nr-1]) sys.exit() """ for l1 in range(LMAX): for l2 in range(LMAX): if l1 != l2: continue for n1 in range(node): for n2 in range(node): if all_basis[l1][n1].l != l1 or all_basis[l2][n2].l != l2: print("error: L is differnt") sys.exit() Smat[l1][l2][n1][n2] = integrate( all_basis[l1][n1].g[:nr] * all_basis[l2][n2].g[:nr], rofi, nr) hsmat[l1][l2][n1][ n2] = Smat[l1][l2][n1][n2] * all_basis[l2][n2].e lmat[l1][l2][n1][ n2] = all_basis[l1][n1].val * all_basis[l2][n2].slo qmat[l1][l2][n1][ n2] = all_basis[l1][n1].val * all_basis[l2][n2].val print("\nSmat") print(Smat) print("\nhsmat") print(hsmat) print("\nlmat") print(lmat) print("\nqmat") print(qmat) hs_L = np.zeros((LMAX, LMAX, node, node)) """ for l1 in range(LMAX): for n1 in range(node): for l2 in range(LMAX): for n2 in range(node): print("{:>8.4f}".format(lmat[l1][l2][n1][n2]),end="") print("") print("") """ print("hs_L") for l1 in range(LMAX): for n1 in range(node): for l2 in range(LMAX): for n2 in range(node): hs_L[l1][l2][n1][ n2] = hsmat[l1][l2][n1][n2] + lmat[l1][l2][n1][n2] print("{:>8.4f}".format(hs_L[l1][l2][n1][n2]), end="") print("") #make not spherical potential my_radial_interfunc = interpolate.interp1d(rofi, V_radial) V_ang = np.where( np.sqrt(xx * xx + yy * yy + zz * zz) < rofi[-1], V - my_radial_interfunc(np.sqrt(xx**2 + yy**2 + zz**2)), 0.) """ for i in range(gridpx): for j in range(gridpy): for k in range(gridpz): print(V_ang[i][j][k],end=" ") print("") print("\n") sys.exit() """ #WARING!!!!!!!!!!!!!!!!!!!!!! """ Fujikata rewrote ~/.local/lib/python3.6/site-packages/scipy/interpolate/interpolate.py line 690~702 To avoid exit with error "A value in x_new is below the interpolation range." """ #!!!!!!!!!!!!!!!!!!!!!!!!!!! """ with open ("V_ang.dat",mode = "w") as fw_a: for i in range(len(V_ang)): fw_a.write("{:>13.8f}".format(xx[50][i][50])) fw_a.write("{:>13.8f}\n".format(V_ang[i][50][50])) """ #mayavi.mlab.plot3d(xx,yy,V_ang) # mlab.contour3d(V_ang,color = (1,1,1),opacity = 0.1) # obj = mlab.volume_slice(V_ang) # mlab.show() umat_av = np.zeros((node, node, LMAX, LMAX, 2 * LMAX + 1, 2 * LMAX + 1), dtype=np.complex64) gridstart = 50 gridend = 60 gridrange = gridend - gridstart + 1 for ngrid in range(gridstart, gridend + 1): t1 = time.time() fw_u = open("umat_grid" + str(ngrid) + ".dat", mode="w") umat = np.zeros((node, node, LMAX, LMAX, 2 * LMAX + 1, 2 * LMAX + 1), dtype=np.complex64) my_V_ang_inter_func = RegularGridInterpolator((x, y, z), V_ang) igridpx = ngrid igridpy = ngrid igridpz = ngrid ix, iy, iz = grid(igridpx, igridpy, igridpz, region) ixx, iyy, izz = np.meshgrid(ix, iy, iz) V_ang_i = my_V_ang_inter_func((ixx, iyy, izz)) #mlab.contour3d(V_ang_i,color = (1,1,1),opacity = 0.1) #obj = mlab.volume_slice(V_ang_i) #mlab.show() dis = np.sqrt(ixx**2 + iyy**2 + izz**2) dis2 = ixx**2 + iyy**2 + izz**2 theta = np.where(dis != 0., np.arccos(izz / dis), 0.) phi = np.where( iyy**2 + ixx**2 != 0, np.where(iyy >= 0, np.arccos(ixx / np.sqrt(ixx**2 + iyy**2)), np.pi + np.arccos(ixx / np.sqrt(ixx**2 + iyy**2))), 0.) #phi = np.where( iyy != 0. , phi, 0.) #phi = np.where(iyy > 0, phi,-phi) # region_t = np.where(dis < rofi[-1],1,0) sph_harm_mat = np.zeros( (LMAX, 2 * LMAX + 1, igridpx, igridpy, igridpz), dtype=np.complex64) for l1 in range(LMAX): for m1 in range(-l1, l1 + 1): sph_harm_mat[l1][m1] = np.where(dis != 0., sph_harm(m1, l1, phi, theta), 0.) g_ln_mat = np.zeros((node, LMAX, igridpx, igridpy, igridpz), dtype=np.float64) for n1 in range(node): for l1 in range(LMAX): my_radial_g_inter_func = interpolate.interp1d( rofi, all_basis[l1][n1].g[:nr]) g_ln_mat[n1][l1] = my_radial_g_inter_func( np.sqrt(ixx**2 + iyy**2 + izz**2)) for n1 in range(node): for n2 in range(node): for l1 in range(LMAX): for l2 in range(LMAX): if all_basis[l1][n1].l != l1 or all_basis[l2][ n2].l != l2: print("error: L is differnt") sys.exit() # to avoid nan in region where it can not interpolate ie: dis > rofi g_V_g = np.where( dis < rofi[-1], g_ln_mat[n1][l1] * V_ang_i * g_ln_mat[n2][l2], 0.) for m1 in range(-l1, l1 + 1): for m2 in range(-l2, l2 + 1): #print("n1 = {} n2 = {} l1 = {} l2 = {} m1 = {} m2 = {}".format(n1,n2,l1,l2,m1,m2)) umat[n1][n2][l1][l2][m1][m2] = np.sum( np.where( dis2 != 0., sph_harm_mat[l1][m1].conjugate() * g_V_g * sph_harm_mat[l2][m2] / dis2, 0.)) * (2 * region[0] * 2 * region[1] * 2 * region[2]) / (igridpx * igridpy * igridpz) #print(umat[n1][n2][l1][l2][m1][m2]) count = 0 for l1 in range(LMAX): for l2 in range(LMAX): for m1 in range(-l1, l1 + 1): for m2 in range(-l2, l2 + 1): for n1 in range(node): for n2 in range(node): fw_u.write(str(count)) fw_u.write("{:>15.8f}{:>15.8f}\n".format( umat[n1][n2][l1][l2][m1][m2].real, umat[n1][n2][l1][l2][m1][m2].imag)) count += 1 umat_av += umat fw_u.close() t2 = time.time() print("grid = ", ngrid, "time = ", t2 - t1) umat_av /= gridrange count = 0 fw_u_av = open("umat_grid_av" + str(gridstart) + "_" + str(gridend) + ".dat", mode="w") for l1 in range(LMAX): for l2 in range(LMAX): for m1 in range(-l1, l1 + 1): for m2 in range(-l2, l2 + 1): for n1 in range(node): for n2 in range(node): fw_u_av.write(str(count)) fw_u_av.write("{:>15.8f}{:>15.8f}\n".format( umat_av[n1][n2][l1][l2][m1][m2].real, umat_av[n1][n2][l1][l2][m1][m2].imag)) count += 1 fw_u_av.close() ham_mat = np.zeros((nstates * nstates), dtype=np.float64) qmetric_mat = np.zeros((nstates * nstates), dtype=np.float64) for l1 in range(LMAX): for m1 in range(-l1, l1 + 1): for n1 in range(node): for l2 in range(LMAX): for m2 in range(-l2, l2 + 1): for n2 in range(node): if l1 == l2 and m1 == m2: ham_mat[l1**2 * node * LMAX**2 * node + (l1 + m1) * node * LMAX**2 * node + n1 * LMAX**2 * node + l2**2 * node + (l2 + m2) * node + n2] += hs_L[l1][l2][n1][n2] qmetric_mat[l1**2 * node * LMAX**2 * node + (l1 + m1) * node * LMAX**2 * node + n1 * LMAX**2 * node + l2**2 * node + (l2 + m2) * node + n2] = qmat[l1][l2][n1][n2] ham_mat[l1**2 * node * LMAX**2 * node + (l1 + m1) * node * LMAX**2 * node + n1 * LMAX**2 * node + l2**2 * node + (l2 + m2) * node + n2] += umat_av[n1][n2][l1][l2][m1][m2].real lambda_mat = np.zeros(nstates * nstates, dtype=np.float64) alphalong = np.zeros(nstates) betalong = np.zeros(nstates) revec = np.zeros(nstates * nstates) for e_num in range(1, 2): E = e_num * 10 lambda_mat = np.zeros(nstates * nstates, dtype=np.float64) lambda_mat -= ham_mat """ for i in range(nstates): lambda_mat[i + i * nstates] += E """ count = 0 fw_lam = open("lambda.dat", mode="w") for l1 in range(LMAX): for m1 in range(-l1, l1 + 1): for n1 in range(node): for l2 in range(LMAX): for m2 in range(-l2, l2 + 1): for n2 in range(node): if l1 == l2 and m1 == m2: lambda_mat[l1**2 * node * LMAX**2 * node + (l1 + m1) * node * LMAX**2 * node + n1 * LMAX**2 * node + l2**2 * node + (l2 + m2) * node + n2] += Smat[l1][l2][n1][n2] * E fw_lam.write(str(count)) fw_lam.write("{:>15.8f}\n".format( lambda_mat[l1**2 * node * LMAX**2 * node + (l1 + m1) * node * LMAX**2 * node + n1 * LMAX**2 * node + l2**2 * node + (l2 + m2) * node + n2])) count += 1 info = solve_genev(nstates, lambda_mat, qmetric_mat, alphalong, betalong, revec) print("info = ", info) print("alphalong") print(alphalong) print("betalong") print(betalong) #print(revec) k = 0 jk = np.zeros(nstates, dtype=np.int32) for i in range(nstates): if betalong[i] != 0.: jk[k] = i k += 1 fw_revec = open("revec.dat", mode="w") print("revec") for j in range(nstates): fw_revec.write("{:>4}".format(j)) for i in range(LMAX**2): fw_revec.write("{:>13.8f}".format(revec[j + jk[i] * nstates])) print("{:>11.6f}".format(revec[j + jk[i] * nstates]), end="") print("") fw_revec.write("\n") print("")
def main(): # make environment pot_region = (2 / np.sqrt(3), 2 / np.sqrt(3), 2 / np.sqrt(3)) radius = np.sqrt(pot_region[0]**2 + pot_region[1]**2 + pot_region[2]**2) region = (radius, radius, radius) nr = 201 gridpx = 200 gridpy = 200 gridpz = 200 x, y, z = grid(gridpx, gridpy, gridpz, region) xx, yy, zz = np.meshgrid(x, y, z) #make mesh #linear mesh #r =np.linspace(0.0001,region,nr) #log mesh a = np.log(2) / (nr - 1) b = radius / (np.e**(a * (nr - 1)) - 1) rofi = np.array([b * (np.e**(a * i) - 1) for i in range(nr)]) # make potential V = makepotential(xx, yy, zz, pot_region, pottype="cubic", potbottom=-1, potshow_f=False) # surface integral V_radial = surfaceintegral(x, y, z, rofi, V, method="lebedev_py", potshow_f=False) vofi = np.array(V_radial) # select method of surface integral # make basis node_open = 1 node_close = 2 LMAX = 10 all_basis = [] for lvalsh in range(LMAX): l_basis = [] # for open channel val = 1. slo = 0. for node in range(node_open): basis = Basis(nr) emin = -10. emax = 100. basis.make_basis(a, b, emin, emax, lvalsh, node, nr, rofi, slo, vofi, val) l_basis.append(basis) # for close channel val = 0. slo = -1. for node in range(node_close): basis = Basis(nr) emin = -10. emax = 100. basis.make_basis(a, b, emin, emax, lvalsh, node, nr, rofi, slo, vofi, val) l_basis.append(basis) all_basis.append(l_basis) with open("wavefunc.dat", mode="w") as fw_w: fw_w.write("#r, l, node, open or close = ") for l_basis in all_basis: for nyu_basis in l_basis: fw_w.write(str(nyu_basis.l)) fw_w.write(str(nyu_basis.node)) if nyu_basis.open: fw_w.write("open") else: fw_w.write("close") fw_w.write(" ") fw_w.write("\n") for i in range(nr): fw_w.write("{:>13.8f}".format(rofi[i])) for l_basis in all_basis: for nyu_basis in l_basis: fw_w.write("{:>13.8f}".format(nyu_basis.g[i])) fw_w.write("\n") hsmat = np.zeros( (LMAX, LMAX, node_open + node_close, node_open + node_close), dtype=np.float64) lmat = np.zeros( (LMAX, LMAX, node_open + node_close, node_open + node_close), dtype=np.float64) qmat = np.zeros( (LMAX, LMAX, node_open + node_close, node_open + node_close), dtype=np.float64) for l1 in range(LMAX): for l2 in range(LMAX): if l1 != l2: continue for n1 in range(node_open + node_close): for n2 in range(node_open + node_close): if all_basis[l1][n1].l != l1 or all_basis[l2][n2].l != l2: print("error: L is differnt") sys.exit() hsmat[l1][l2][n1][n2] = integrate( all_basis[l1][n1].g[:nr] * all_basis[l2][n2].g[:nr], rofi, nr) * all_basis[l1][n1].e lmat[l1][l2][n1][ n2] = all_basis[l1][n1].val * all_basis[l2][n2].slo qmat[l1][l2][n1][ n2] = all_basis[l1][n1].val * all_basis[l2][n2].val print("\nhsmat") print(hsmat) print("\nlmat") print(lmat) print("\nqmat") print(qmat) #make not spherical potential my_radial_interfunc = interpolate.interp1d(rofi, V_radial) #V_ang = np.where(np.sqrt(xx * xx + yy * yy + zz * zz) < rofi[-1] , V - my_radial_interfunc(np.sqrt(xx * xx + yy * yy + zz * zz)),0. ) #my_V_ang_inter_func = RegularGridInterpolator((x, y, z), V_ang) my_V_inter_func = RegularGridInterpolator((x, y, z), V) #WARING!!!!!!!!!!!!!!!!!!!!!! """ Fujikata rewrote ~/.local/lib/python3.6/site-packages/scipy/interpolate/interpolate.py line 690~702 To avoid exit with error "A value in x_new is below the interpolation range." """ #!!!!!!!!!!!!!!!!!!!!!!!!!!! #mayavi.mlab.plot3d(xx,yy,V_ang) # mlab.contour3d(V_ang,color = (1,1,1),opacity = 0.1) # obj = mlab.volume_slice(V_ang) # mlab.show() #for V_L fw_umat_vl = open("umat_vl_all.dat", mode="w") for LMAX_k in range(10, 13): fw_umat_vl_2 = open("umat_vl_L" + str(LMAX_k) + ".dat", mode="w") t1 = time.time() umat = np.zeros((node_open + node_close, node_open + node_close, LMAX, LMAX, 2 * LMAX + 1, 2 * LMAX + 1), dtype=np.complex64) #LMAX_k = 3 fw_umat_vl.write(str(LMAX_k)) igridnr = 201 leb_r = np.linspace(0, radius, igridnr) lebedev_num = lebedev_num_list[-8] V_L = np.zeros((LMAX_k, 2 * LMAX_k + 1, igridnr), dtype=np.complex64) leb_x = np.zeros(lebedev_num) leb_y = np.zeros(lebedev_num) leb_z = np.zeros(lebedev_num) leb_w = np.zeros(lebedev_num) lebedev(lebedev_num, leb_x, leb_y, leb_z, leb_w) theta = np.arccos(leb_z) phi = np.where( leb_x**2 + leb_y**2 != 0., np.where(leb_y >= 0, np.arccos(leb_x / np.sqrt(leb_x**2 + leb_y**2)), np.pi + np.arccos(leb_x / np.sqrt(leb_x**2 + leb_y**2))), 0.) for i in range(igridnr): V_leb_r = my_V_inter_func( np.array([leb_x, leb_y, leb_z]).T * leb_r[i]) * leb_w for k in range(LMAX_k): for q in range(-k, k + 1): V_L[k][q][i] = 4 * np.pi * np.sum( V_leb_r * sph_harm(q, k, phi, theta).conjugate()) """ for k in range(LMAX_k): for q in range(-k,k+1): print("k = ",k,"q = ", q) plt.plot(leb_r,V_L[k][q].real,marker=".") plt.show() sys.exit() """ g_ln = np.zeros((node_open + node_close, LMAX, igridnr), dtype=np.float64) for n1 in range(node_open + node_close): for l1 in range(LMAX): my_radial_g_inter_func = interpolate.interp1d( rofi, all_basis[l1][n1].g[:nr]) g_ln[n1][l1] = my_radial_g_inter_func(leb_r) C_kq = np.zeros( (LMAX, LMAX, 2 * LMAX + 1, 2 * LMAX + 1, LMAX_k, 2 * LMAX_k + 1), dtype=np.float64) for l1 in range(LMAX): for l2 in range(LMAX): for m1 in range(-l1, l1 + 1): for m2 in range(-l2, l2 + 1): for k in range(1, LMAX_k): for q in range(-k, k + 1): C_kq[l1][l2][m1][m2][k][q] = (-1)**( -m1) * np.sqrt( (2 * l1 + 1) * (2 * l2 + 1)) * Wigner3j( l1, 0, k, 0, l2, 0).doit() * Wigner3j( l1, -m1, k, q, l2, m2).doit() #print(l1,l2,m1,m2,k,q,C_kq[l1][l2][m1][m2][k][q]) count = 0 for l1 in range(LMAX): for l2 in range(LMAX): for m1 in range(-l1, l1 + 1): for m2 in range(-l2, l2 + 1): for n1 in range(node_open + node_close): for n2 in range(node_open + node_close): for k in range(1, LMAX_k): for q in range(-k, k + 1): umat[n1][n2][l1][l2][m1][m2] += simps( g_ln[n1][l1] * V_L[k][q] * g_ln[n2][l2], leb_r) * C_kq[l1][ l2][m1][m2][k][q] * np.sqrt( (2 * k + 1) / (4 * np.pi)) fw_umat_vl.write("{:>15.8f}".format( umat[n1][n2][l1][l2][m1][m2].real)) fw_umat_vl_2.write("{:>15.8f}".format(count)) fw_umat_vl_2.write("{:>15.8f}\n".format( umat[n1][n2][l1][l2][m1][m2].real)) count += 1 t2 = time.time() print("LMAX = ", LMAX_k, " time = ", t2 - t1) fw_umat_vl_2.close() fw_umat_vl.write("\n") fw_umat_vl.close()
def main(): # make environment pot_region = (2 / np.sqrt(3), 2 / np.sqrt(3), 2 / np.sqrt(3)) radius = np.sqrt(pot_region[0]**2 + pot_region[1]**2 + pot_region[2]**2) region = (radius, radius, radius) nr = 201 gridpx = 200 gridpy = 200 gridpz = 200 x, y, z = grid(gridpx, gridpy, gridpz, region) xx, yy, zz = np.meshgrid(x, y, z) #make mesh #linear mesh #r =np.linspace(0.0001,region,nr) #log mesh a = np.log(2) / (nr - 1) b = radius / (np.e**(a * (nr - 1)) - 1) rofi = np.array([b * (np.e**(a * i) - 1) for i in range(nr)]) # make potential V = makepotential(xx, yy, zz, pot_region, pottype="cubic", potbottom=-1, potshow_f=False) # surface integral V_radial = surfaceintegral(x, y, z, rofi, V, method="lebedev_py", potshow_f=False) vofi = np.array(V_radial) # select method of surface integral # make basis node_open = 1 node_close = 2 LMAX = 4 all_basis = [] for lvalsh in range(LMAX): l_basis = [] # for open channel val = 1. slo = 0. for node in range(node_open): basis = Basis(nr) emin = -10. emax = 100. basis.make_basis(a, b, emin, emax, lvalsh, node, nr, rofi, slo, vofi, val) l_basis.append(basis) # for close channel val = 0. slo = -1. for node in range(node_close): basis = Basis(nr) emin = -10. emax = 100. basis.make_basis(a, b, emin, emax, lvalsh, node, nr, rofi, slo, vofi, val) l_basis.append(basis) all_basis.append(l_basis) with open("wavefunc.dat", mode="w") as fw_w: fw_w.write("#r, l, node, open or close = ") for l_basis in all_basis: for nyu_basis in l_basis: fw_w.write(str(nyu_basis.l)) fw_w.write(str(nyu_basis.node)) if nyu_basis.open: fw_w.write("open") else: fw_w.write("close") fw_w.write(" ") fw_w.write("\n") for i in range(nr): fw_w.write("{:>13.8f}".format(rofi[i])) for l_basis in all_basis: for nyu_basis in l_basis: fw_w.write("{:>13.8f}".format(nyu_basis.g[i])) fw_w.write("\n") hsmat = np.zeros( (LMAX, LMAX, node_open + node_close, node_open + node_close), dtype=np.float64) lmat = np.zeros( (LMAX, LMAX, node_open + node_close, node_open + node_close), dtype=np.float64) qmat = np.zeros( (LMAX, LMAX, node_open + node_close, node_open + node_close), dtype=np.float64) for l1 in range(LMAX): for l2 in range(LMAX): if l1 != l2: continue for n1 in range(node_open + node_close): for n2 in range(node_open + node_close): if all_basis[l1][n1].l != l1 or all_basis[l2][n2].l != l2: print("error: L is differnt") sys.exit() hsmat[l1][l2][n1][n2] = integrate( all_basis[l1][n1].g[:nr] * all_basis[l2][n2].g[:nr], rofi, nr) * all_basis[l1][n1].e lmat[l1][l2][n1][ n2] = all_basis[l1][n1].val * all_basis[l2][n2].slo qmat[l1][l2][n1][ n2] = all_basis[l1][n1].val * all_basis[l2][n2].val print("\nhsmat") print(hsmat) print("\nlmat") print(lmat) print("\nqmat") print(qmat) #make not spherical potential my_radial_interfunc = interpolate.interp1d(rofi, V_radial) V_ang = np.where( np.sqrt(xx * xx + yy * yy + zz * zz) < rofi[-1], V - my_radial_interfunc(np.sqrt(xx * xx + yy * yy + zz * zz)), 0.) """ for i in range(gridpx): for j in range(gridpy): for k in range(gridpz): print(V_ang[i][j][k],end=" ") print("") print("\n") sys.exit() """ #WARING!!!!!!!!!!!!!!!!!!!!!! """ Fujikata rewrote ~/.local/lib/python3.6/site-packages/scipy/interpolate/interpolate.py line 690~702 To avoid exit with error "A value in x_new is below the interpolation range." """ #!!!!!!!!!!!!!!!!!!!!!!!!!!! """ with open ("V_ang.dat",mode = "w") as fw_a: for i in range(len(V_ang)): fw_a.write("{:>13.8f}".format(xx[50][i][50])) fw_a.write("{:>13.8f}\n".format(V_ang[i][50][50])) """ #mayavi.mlab.plot3d(xx,yy,V_ang) # mlab.contour3d(V_ang,color = (1,1,1),opacity = 0.1) # obj = mlab.volume_slice(V_ang) # mlab.show() fw_grid = open("umat_grid_all.dat", mode="w") for ngrid in range(20, 100): fw_grid_2 = open("umat_grid" + str(ngrid) + ".dat", mode="w") fw_grid.write(str(ngrid) + " ") t1 = time.time() umat = np.zeros((node_open + node_close, node_open + node_close, LMAX, LMAX, 2 * LMAX + 1, 2 * LMAX + 1), dtype=np.complex64) # umat_t = np.zeros((LMAX,LMAX,2 * LMAX + 1,2 * LMAX + 1,node_open + node_close,node_open + node_close), dtype = np.complex64) my_V_ang_inter_func = RegularGridInterpolator((x, y, z), V_ang) igridpx = ngrid igridpy = ngrid igridpz = ngrid ix, iy, iz = grid(igridpx, igridpy, igridpz, region) ixx, iyy, izz = np.meshgrid(ix, iy, iz) V_ang_i = my_V_ang_inter_func((ixx, iyy, izz)) #mlab.points3d(V_ang_i,scale_factor=0.4) # mlab.contour3d(V_ang_i,color = (1,1,1),opacity = 0.1) # obj = mlab.volume_slice(V_ang_i) #mlab.show() dis = np.sqrt(ixx**2 + iyy**2 + izz**2) dis2 = ixx**2 + iyy**2 + izz**2 theta = np.where(dis != 0., np.arccos(izz / dis), 0.) phi = np.where( iyy**2 + ixx**2 != 0, np.where(iyy >= 0, np.arccos(ixx / np.sqrt(ixx**2 + iyy**2)), np.pi + np.arccos(ixx / np.sqrt(ixx**2 + iyy**2))), 0.) # region_t = np.where(dis < rofi[-1],1,0) sph_harm_mat = np.zeros( (LMAX, 2 * LMAX + 1, igridpx, igridpy, igridpz), dtype=np.complex64) for l1 in range(LMAX): for m1 in range(-l1, l1 + 1): sph_harm_mat[l1][m1] = np.where(dis != 0., sph_harm(m1, l1, phi, theta), 0.) g_ln_mat = np.zeros( (node_open + node_close, LMAX, igridpx, igridpy, igridpz), dtype=np.float64) for n1 in range(node_open + node_close): for l1 in range(LMAX): my_radial_g_inter_func = interpolate.interp1d( rofi, all_basis[l1][n1].g[:nr]) g_ln_mat[n1][l1] = my_radial_g_inter_func( np.sqrt(ixx**2 + iyy**2 + izz**2)) for n1 in range(node_open + node_close): for n2 in range(node_open + node_close): for l1 in range(LMAX): for l2 in range(LMAX): if all_basis[l1][n1].l != l1 or all_basis[l2][ n2].l != l2: print("error: L is differnt") sys.exit() # to avoid nan in region where it can not interpolate ie: dis > rofi g_V_g = np.where( dis < rofi[-1], g_ln_mat[n1][l1] * V_ang_i * g_ln_mat[n2][l2], 0.) for m1 in range(-l1, l1 + 1): for m2 in range(-l2, l2 + 1): #print("n1 = {} n2 = {} l1 = {} l2 = {} m1 = {} m2 = {}".format(n1,n2,l1,l2,m1,m2)) umat[n1][n2][l1][l2][m1][m2] = np.sum( np.where( dis2 != 0., sph_harm_mat[l1][m1].conjugate() * g_V_g * sph_harm_mat[l2][m2] / dis2, 0.)) * (2 * region[0] * 2 * region[1] * 2 * region[2]) / (igridpx * igridpy * igridpz) fw_grid.write("{:>13.8f}".format( umat[n1][n2][l1][l2][m1][m2].real)) count = 0 for l1 in range(LMAX): for l2 in range(LMAX): for m1 in range(-l1, l1 + 1): for m2 in range(-l2, l2 + 1): for n1 in range(node_open + node_close): for n2 in range(node_open + node_close): fw_grid_2.write(str(count)) fw_grid_2.write("{:>15.8f}{:>15.8f}\n".format( umat[n1][n2][l1][l2][m1][m2].real, umat[n1][n2][l1][l2][m1][m2].imag)) count += 1 t2 = time.time() fw_grid.write("\n") print("grid = ", ngrid, "time = ", t2 - t1) fw_grid.close()
def main(): # make environment t1 = time.time() pot_region = (2 / np.sqrt(3), 2 / np.sqrt(3), 2 / np.sqrt(3)) radius = np.sqrt(pot_region[0]**2 + pot_region[1]**2 + pot_region[2]**2) region = (radius, radius, radius) nr = 201 gridpx = 131 gridpy = 131 gridpz = 131 x, y, z = grid(gridpx, gridpy, gridpz, region) xx, yy, zz = np.meshgrid(x, y, z) #make mesh #linear mesh #r =np.linspace(0.0001,region,nr) #log mesh a = np.log(2) / (nr - 1) b = radius / (np.e**(a * (nr - 1)) - 1) rofi = np.array([b * (np.e**(a * i) - 1) for i in range(nr)]) # make potential V = makepotential(xx, yy, zz, pot_region, pottype="cubic", potbottom=-1, potshow_f=False) # surface integral V_radial = surfaceintegral(x, y, z, rofi, V, method="lebedev_py", potshow_f=False) vofi = np.array(V_radial) # select method of surface integral # make basis node_open = 1 node_close = 2 LMAX = 4 all_basis = [] for lvalsh in range(LMAX): l_basis = [] # for open channel val = 1. slo = 0. for node in range(node_open): basis = Basis(nr) emin = -10. emax = 100. basis.make_basis(a, b, emin, emax, lvalsh, node, nr, rofi, slo, vofi, val) l_basis.append(basis) # for close channel val = 0. slo = -1. for node in range(node_close): basis = Basis(nr) emin = -10. emax = 100. basis.make_basis(a, b, emin, emax, lvalsh, node, nr, rofi, slo, vofi, val) l_basis.append(basis) all_basis.append(l_basis) with open("wavefunc.dat", mode="w") as fw_w: fw_w.write("#r, l, node, open or close = ") for l_basis in all_basis: for nyu_basis in l_basis: fw_w.write(str(nyu_basis.l)) fw_w.write(str(nyu_basis.node)) if nyu_basis.open: fw_w.write("open") else: fw_w.write("close") fw_w.write(" ") fw_w.write("\n") for i in range(nr): fw_w.write("{:>13.8f}".format(rofi[i])) for l_basis in all_basis: for nyu_basis in l_basis: fw_w.write("{:>13.8f}".format(nyu_basis.g[i])) fw_w.write("\n") hsmat = np.zeros( (LMAX, LMAX, node_open + node_close, node_open + node_close), dtype=np.float64) lmat = np.zeros( (LMAX, LMAX, node_open + node_close, node_open + node_close), dtype=np.float64) qmat = np.zeros( (LMAX, LMAX, node_open + node_close, node_open + node_close), dtype=np.float64) for l1 in range(LMAX): for l2 in range(LMAX): if l1 != l2: continue for n1 in range(node_open + node_close): for n2 in range(node_open + node_close): if all_basis[l1][n1].l != l1 or all_basis[l2][n2].l != l2: print("error: L is differnt") sys.exit() hsmat[l1][l2][n1][n2] = integrate( all_basis[l1][n1].g[:nr] * all_basis[l2][n2].g[:nr], rofi, nr) * all_basis[l1][n1].e lmat[l1][l2][n1][ n2] = all_basis[l1][n1].val * all_basis[l2][n2].slo qmat[l1][l2][n1][ n2] = all_basis[l1][n1].val * all_basis[l2][n2].val print("\nhsmat") print(hsmat) print("\nlmat") print(lmat) print("\nqmat") print(qmat) #make not spherical potential my_radial_interfunc = interpolate.interp1d(rofi, V_radial) V_ang = np.where( np.sqrt(xx * xx + yy * yy + zz * zz) < rofi[-1], V - my_radial_interfunc(np.sqrt(xx * xx + yy * yy + zz * zz)), 0.) """ for i in range(gridpx): for j in range(gridpy): for k in range(gridpz): print(V_ang[i][j][k],end=" ") print("") print("\n") sys.exit() """ #WARING!!!!!!!!!!!!!!!!!!!!!! """ Fujikata rewrote ~/.local/lib/python3.6/site-packages/scipy/interpolate/interpolate.py line 690~702 To avoid exit with error "A value in x_new is below the interpolation range." """ #!!!!!!!!!!!!!!!!!!!!!!!!!!! """ with open ("V_ang.dat",mode = "w") as fw_a: for i in range(len(V_ang)): fw_a.write("{:>13.8f}".format(xx[50][i][50])) fw_a.write("{:>13.8f}\n".format(V_ang[i][50][50])) """ #mayavi.mlab.plot3d(xx,yy,V_ang) # mlab.contour3d(V_ang,color = (1,1,1),opacity = 0.1) # obj = mlab.volume_slice(V_ang) # mlab.show() umat = np.zeros((node_open + node_close, node_open + node_close, LMAX, LMAX, 2 * LMAX + 1, 2 * LMAX + 1), dtype=np.complex64) # umat_t = np.zeros((LMAX,LMAX,2 * LMAX + 1,2 * LMAX + 1,node_open + node_close,node_open + node_close), dtype = np.complex64) # my_V_ang_inter_func = RegularGridInterpolator((x, y, z), V_ang) dis = np.sqrt(xx**2 + yy**2 + zz**2) dis2 = xx**2 + yy**2 + zz**2 theta = np.where(dis != 0., np.arccos(zz / dis), 0.) phi = np.where(xx**2 + yy**2 != 0., np.arccos(xx / np.sqrt(xx**2 + yy**2)), 0.) # region_t = np.where(dis < rofi[-1],1,0) sph_harm_mat = np.zeros((LMAX, 2 * LMAX + 1, gridpx, gridpy, gridpz), dtype=np.complex64) for l1 in range(LMAX): for m1 in range(-l1, l1 + 1): sph_harm_mat[l1][m1] = np.where(dis != 0., sph_harm(m1, l1, theta, phi), 0.) g_ln_mat = np.zeros((node_open + node_close, LMAX, gridpx, gridpy, gridpz), dtype=np.float64) for n1 in range(node_open + node_close): for l1 in range(LMAX): my_radial_g_inter_func = interpolate.interp1d( rofi, all_basis[l1][n1].g[:nr]) g_ln_mat[n1][l1] = my_radial_g_inter_func( np.sqrt(xx**2 + yy**2 + zz**2)) for n1 in range(node_open + node_close): for n2 in range(node_open + node_close): for l1 in range(LMAX): for l2 in range(LMAX): if all_basis[l1][n1].l != l1 or all_basis[l2][n2].l != l2: print("error: L is differnt") sys.exit() # to avoid nan in region where it can not interpolate ie: dis > rofi g_V_g = np.where( dis < rofi[-1], g_ln_mat[n1][l1] * V_ang * g_ln_mat[n2][l2], 0.) for m1 in range(-l1, l1 + 1): for m2 in range(-l2, l2 + 1): print( "n1 = {} n2 = {} l1 = {} l2 = {} m1 = {} m2 = {}" .format(n1, n2, l1, l2, m1, m2)) umat[n1][n2][l1][l2][m1][m2] = np.sum( sph_harm_mat[l1][m1] * g_V_g * sph_harm_mat[l2][m2].conjugate() / dis2) * ( 2 * region[0] * 2 * region[1] * 2 * region[2]) / (gridpx * gridpy * gridpz) #umat[l1][l2][m1][m2][n1][n2] = simps(simps(simps(g_V_g * sph_harm_mat[l1][m1] * sph_harm_mat[l2][m2],x = z,even="first"),x = y,even="first"),x = x,even="first") #umat[l1][l2][m1][m2][n1][n2] = simps(simps(simps(g_V_g * sph_harm_mat[l1][m1] * sph_harm_mat[l2][m2],x = z),x = y),x = x) #umat[l1][l2][m1][m2][n1][n2] = cumtrapz(cumtrapz(cumtrapz(g_V_g * sph_harm_mat[l1][m1] * sph_harm_mat[l2][m2],x = z),x = y),x = x) #umat[l1][l2][m1][m2][n1][n2] = np.sum( np.where( dis < rofi[-1] ,sph_harm(m1,l1,theta,phi) * g1 * V_ang * sph_harm(m2,l2,theta,phi) * g2 ,0. )) / (gridpx * gridpy * gridpz) # umat_t[l1][l2][m1][m2][n1][n2] = np.sum( np.where( np.sqrt(xx * xx + yy * yy + zz * zz) < rofi[-1] ,sph_harm(m1,l1,np.arccos(zz / np.sqrt(xx **2 + yy **2 + zz **2)),np.arccos(xx / np.sqrt(xx **2 + yy **2))) * my_radial_g1_inter_func(np.sqrt(xx**2 + yy **2 + zz **2)) * my_V_ang_inter_func((xx,yy,zz)) * sph_harm(m2,l2,np.arccos(zz / np.sqrt(xx **2 + yy **2 + zz **2)),np.arccos(xx / np.sqrt(xx **2 + yy **2))) * my_radial_g2_inter_func(np.sqrt(xx **2 + yy **2 + zz **2)),0. )) # print(umat_t[l1][l2][m1][m2][n1][n2]) """ for xi in x: for yi in y: for zi in z: if np.sqrt(xi**2 + yi **2 + zi **2) < rofi[-1]: umat_t[l1][l2][m1][m2][n1][n2] += sph_harm(m1,l1,np.arccos(zi / np.sqrt(xi **2 + yi **2 + zi **2)),np.arccos(xi / np.sqrt(xi **2 + yi **2))) * my_radial_g1_inter_func(np.sqrt(xi**2 + yi **2 + zi **2)) * my_V_ang_inter_func((xi,yi,zi)) * sph_harm(m2,l2,np.arccos(zi / np.sqrt(xi **2 + yi **2 + zi **2)),np.arccos(xi / np.sqrt(xi **2 + yi **2))) * my_radial_g2_inter_func(np.sqrt(xi **2 + yi **2 + zi **2)) print(umat[l1][l2][m1][m2][n1][n2]) print(umat_t[l1][l2][m1][m2][n1][n2]) print(umat_t[l1][l2][m1][m2][n1][n2] - umat[l1][l2][m1][m2][n1][n2]) """ #umat[l1][l2][m1][m2][n1][n2] = tplquad( lambda x, y, z : sph_harm(m1,l1,np.arccos(z / np.sqrt(x **2 + y **2 + z **2)),np.arccos(x / np.sqrt(x **2 + y **2))).real * my_radial_g1_inter_func(np.sqrt(x**2 + y **2 + z **2)) * my_V_ang_inter_func((x,y,z)) * sph_harm(m2,l2,np.arccos(z / np.sqrt(x **2 + y **2 + z **2)),np.arccos(x / np.sqrt(x **2 + y **2))).real * my_radial_g2_inter_func(np.sqrt(x **2 + y **2 + z **2)) if np.sqrt(x **2 + y **2 + z **2) < rofi[-1] else 0 , -region, region , -region, region, -region, region) print(umat[n1][n2][l1][l2][m1][m2]) t2 = time.time() print("time = ", t2 - t1)