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) a = 0.0001 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. ) #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.dat",mode="w") umat = np.zeros((node_open + node_close,node_open + node_close,LMAX,LMAX,2 * LMAX + 1,2 * LMAX + 1), dtype = np.complex64) LMAX_k = 9 igridnr = 201 leb_r = np.linspace(0,radius,igridnr) lebedev_num = lebedev_num_list[-1] 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(count)) fw_umat_vl.write("{:>15.8f}\n".format(umat[n1][n2][l1][l2][m1][m2].real)) count += 1 fw_umat_vl.close()
def test_cg(): cg = CG(1, 2, 3, 4, 5, 6) wigner3j = Wigner3j(1, 2, 3, 4, 5, 6) wigner6j = Wigner6j(1, 2, 3, 4, 5, 6) wigner9j = Wigner9j(1, 2, 3, 4, 5, 6, 7, 8, 9) assert str(cg) == 'CG(1, 2, 3, 4, 5, 6)' ascii_str = \ """\ 5,6 \n\ C \n\ 1,2,3,4\ """ ucode_str = \ u("""\ 5,6 \n\ C \n\ 1,2,3,4\ """) assert pretty(cg) == ascii_str assert upretty(cg) == ucode_str assert latex(cg) == r'C^{5,6}_{1,2,3,4}' sT(cg, "CG(Integer(1), Integer(2), Integer(3), Integer(4), Integer(5), Integer(6))") assert str(wigner3j) == 'Wigner3j(1, 2, 3, 4, 5, 6)' ascii_str = \ """\ /1 3 5\\\n\ | |\n\ \\2 4 6/\ """ ucode_str = \ u("""\ ⎛1 3 5⎞\n\ ⎜ ⎟\n\ ⎝2 4 6⎠\ """) assert pretty(wigner3j) == ascii_str assert upretty(wigner3j) == ucode_str assert latex(wigner3j) == \ r'\left(\begin{array}{ccc} 1 & 3 & 5 \\ 2 & 4 & 6 \end{array}\right)' sT(wigner3j, "Wigner3j(Integer(1), Integer(2), Integer(3), Integer(4), Integer(5), Integer(6))") assert str(wigner6j) == 'Wigner6j(1, 2, 3, 4, 5, 6)' ascii_str = \ """\ /1 2 3\\\n\ < >\n\ \\4 5 6/\ """ ucode_str = \ u("""\ ⎧1 2 3⎫\n\ ⎨ ⎬\n\ ⎩4 5 6⎭\ """) assert pretty(wigner6j) == ascii_str assert upretty(wigner6j) == ucode_str assert latex(wigner6j) == \ r'\left\{\begin{array}{ccc} 1 & 2 & 3 \\ 4 & 5 & 6 \end{array}\right\}' sT(wigner6j, "Wigner6j(Integer(1), Integer(2), Integer(3), Integer(4), Integer(5), Integer(6))") assert str(wigner9j) == 'Wigner9j(1, 2, 3, 4, 5, 6, 7, 8, 9)' ascii_str = \ """\ /1 2 3\\\n\ | |\n\ <4 5 6>\n\ | |\n\ \\7 8 9/\ """ ucode_str = \ u("""\ ⎧1 2 3⎫\n\ ⎪ ⎪\n\ ⎨4 5 6⎬\n\ ⎪ ⎪\n\ ⎩7 8 9⎭\ """) assert pretty(wigner9j) == ascii_str assert upretty(wigner9j) == ucode_str assert latex(wigner9j) == \ r'\left\{\begin{array}{ccc} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array}\right\}' sT(wigner9j, "Wigner9j(Integer(1), Integer(2), Integer(3), Integer(4), Integer(5), Integer(6), Integer(7), Integer(8), Integer(9))")
def test_big_expr(): f = Function('f') x = symbols('x') e1 = Dagger(AntiCommutator(Operator('A') + Operator('B'), Pow(DifferentialOperator(Derivative(f(x), x), f(x)), 3))*TensorProduct(Jz**2, Operator('A') + Operator('B')))*(JzBra(1, 0) + JzBra(1, 1))*(JzKet(0, 0) + JzKet(1, -1)) e2 = Commutator(Jz**2, Operator('A') + Operator('B'))*AntiCommutator(Dagger(Operator('C')*Operator('D')), Operator('E').inv()**2)*Dagger(Commutator(Jz, J2)) e3 = Wigner3j(1, 2, 3, 4, 5, 6)*TensorProduct(Commutator(Operator('A') + Dagger(Operator('B')), Operator('C') + Operator('D')), Jz - J2)*Dagger(OuterProduct(Dagger(JzBra(1, 1)), JzBra(1, 0)))*TensorProduct(JzKetCoupled(1, 1, (1, 1)) + JzKetCoupled(1, 0, (1, 1)), JzKetCoupled(1, -1, (1, 1))) e4 = (ComplexSpace(1)*ComplexSpace(2) + FockSpace()**2)*(L2(Interval( 0, oo)) + HilbertSpace()) assert str(e1) == '(Jz**2)x(Dagger(A) + Dagger(B))*{Dagger(DifferentialOperator(Derivative(f(x), x),f(x)))**3,Dagger(A) + Dagger(B)}*(<1,0| + <1,1|)*(|0,0> + |1,-1>)' ascii_str = \ """\ / 3 \\ \n\ |/ +\\ | \n\ 2 / + +\\ <| /d \\ | + +> \n\ /J \\ x \\A + B /*||DifferentialOperator|--(f(x)),f(x)| | ,A + B |*(<1,0| + <1,1|)*(|0,0> + |1,-1>)\n\ \\ z/ \\\\ \dx / / / \ """ ucode_str = \ u("""\ ⎧ 3 ⎫ \n\ ⎪⎛ †⎞ ⎪ \n\ 2 ⎛ † †⎞ ⎨⎜ ⎛d ⎞ ⎟ † †⎬ \n\ ⎛J ⎞ ⨂ ⎝A + B ⎠⋅⎪⎜DifferentialOperator⎜──(f(x)),f(x)⎟ ⎟ ,A + B ⎪⋅(⟨1,0❘ + ⟨1,1❘)⋅(❘0,0⟩ + ❘1,-1⟩)\n\ ⎝ z⎠ ⎩⎝ ⎝dx ⎠ ⎠ ⎭ \ """) assert pretty(e1) == ascii_str assert upretty(e1) == ucode_str assert latex(e1) == \ r'{\left(J_z\right)^{2}}\otimes \left({A^{\dag} + B^{\dag}}\right) \left\{\left(DifferentialOperator\left(\frac{d}{d x} f{\left (x \right )},f{\left (x \right )}\right)^{\dag}\right)^{3},A^{\dag} + B^{\dag}\right\} \left({\left\langle 1,0\right|} + {\left\langle 1,1\right|}\right) \left({\left|0,0\right\rangle } + {\left|1,-1\right\rangle }\right)' sT(e1, "Mul(TensorProduct(Pow(JzOp(Symbol('J')), Integer(2)), Add(Dagger(Operator(Symbol('A'))), Dagger(Operator(Symbol('B'))))), AntiCommutator(Pow(Dagger(DifferentialOperator(Derivative(Function('f')(Symbol('x')), Symbol('x')),Function('f')(Symbol('x')))), Integer(3)),Add(Dagger(Operator(Symbol('A'))), Dagger(Operator(Symbol('B'))))), Add(JzBra(Integer(1),Integer(0)), JzBra(Integer(1),Integer(1))), Add(JzKet(Integer(0),Integer(0)), JzKet(Integer(1),Integer(-1))))") assert str(e2) == '[Jz**2,A + B]*{E**(-2),Dagger(D)*Dagger(C)}*[J2,Jz]' ascii_str = \ """\ [ 2 ] / -2 + +\\ [ 2 ]\n\ [/J \\ ,A + B]*<E ,D *C >*[J ,J ]\n\ [\\ z/ ] \\ / [ z]\ """ ucode_str = \ u("""\ ⎡ 2 ⎤ ⎧ -2 † †⎫ ⎡ 2 ⎤\n\ ⎢⎛J ⎞ ,A + B⎥⋅⎨E ,D ⋅C ⎬⋅⎢J ,J ⎥\n\ ⎣⎝ z⎠ ⎦ ⎩ ⎭ ⎣ z⎦\ """) assert pretty(e2) == ascii_str assert upretty(e2) == ucode_str assert latex(e2) == \ r'\left[\left(J_z\right)^{2},A + B\right] \left\{\left(E\right)^{-2},D^{\dag} C^{\dag}\right\} \left[J^2,J_z\right]' sT(e2, "Mul(Commutator(Pow(JzOp(Symbol('J')), Integer(2)),Add(Operator(Symbol('A')), Operator(Symbol('B')))), AntiCommutator(Pow(Operator(Symbol('E')), Integer(-2)),Mul(Dagger(Operator(Symbol('D'))), Dagger(Operator(Symbol('C'))))), Commutator(J2Op(Symbol('J')),JzOp(Symbol('J'))))") assert str(e3) == \ "Wigner3j(1, 2, 3, 4, 5, 6)*[Dagger(B) + A,C + D]x(-J2 + Jz)*|1,0><1,1|*(|1,0,j1=1,j2=1> + |1,1,j1=1,j2=1>)x|1,-1,j1=1,j2=1>" ascii_str = \ """\ [ + ] / 2 \\ \n\ /1 3 5\\*[B + A,C + D]x |- J + J |*|1,0><1,1|*(|1,0,j1=1,j2=1> + |1,1,j1=1,j2=1>)x |1,-1,j1=1,j2=1>\n\ | | \\ z/ \n\ \\2 4 6/ \ """ ucode_str = \ u("""\ ⎡ † ⎤ ⎛ 2 ⎞ \n\ ⎛1 3 5⎞⋅⎣B + A,C + D⎦⨂ ⎜- J + J ⎟⋅❘1,0⟩⟨1,1❘⋅(❘1,0,j₁=1,j₂=1⟩ + ❘1,1,j₁=1,j₂=1⟩)⨂ ❘1,-1,j₁=1,j₂=1⟩\n\ ⎜ ⎟ ⎝ z⎠ \n\ ⎝2 4 6⎠ \ """) assert pretty(e3) == ascii_str assert upretty(e3) == ucode_str assert latex(e3) == \ r'\left(\begin{array}{ccc} 1 & 3 & 5 \\ 2 & 4 & 6 \end{array}\right) {\left[B^{\dag} + A,C + D\right]}\otimes \left({- J^2 + J_z}\right) {\left|1,0\right\rangle }{\left\langle 1,1\right|} \left({{\left|1,0,j_{1}=1,j_{2}=1\right\rangle } + {\left|1,1,j_{1}=1,j_{2}=1\right\rangle }}\right)\otimes {{\left|1,-1,j_{1}=1,j_{2}=1\right\rangle }}' sT(e3, "Mul(Wigner3j(Integer(1), Integer(2), Integer(3), Integer(4), Integer(5), Integer(6)), TensorProduct(Commutator(Add(Dagger(Operator(Symbol('B'))), Operator(Symbol('A'))),Add(Operator(Symbol('C')), Operator(Symbol('D')))), Add(Mul(Integer(-1), J2Op(Symbol('J'))), JzOp(Symbol('J')))), OuterProduct(JzKet(Integer(1),Integer(0)),JzBra(Integer(1),Integer(1))), TensorProduct(Add(JzKetCoupled(Integer(1),Integer(0),Tuple(Integer(1), Integer(1)),Tuple(Tuple(Integer(1), Integer(2), Integer(1)))), JzKetCoupled(Integer(1),Integer(1),Tuple(Integer(1), Integer(1)),Tuple(Tuple(Integer(1), Integer(2), Integer(1))))), JzKetCoupled(Integer(1),Integer(-1),Tuple(Integer(1), Integer(1)),Tuple(Tuple(Integer(1), Integer(2), Integer(1))))))") assert str(e4) == '(C(1)*C(2)+F**2)*(L2([0, oo))+H)' ascii_str = \ """\ // 1 2\\ x2\\ / 2 \\\n\ \\\\C x C / + F / x \L + H/\ """ ucode_str = \ u("""\ ⎛⎛ 1 2⎞ ⨂2⎞ ⎛ 2 ⎞\n\ ⎝⎝C ⨂ C ⎠ ⊕ F ⎠ ⨂ ⎝L ⊕ H⎠\ """) assert pretty(e4) == ascii_str assert upretty(e4) == ucode_str assert latex(e4) == \ r'\left(\left(\mathcal{C}^{1}\otimes \mathcal{C}^{2}\right)\oplus {\mathcal{F}}^{\otimes 2}\right)\otimes \left({\mathcal{L}^2}\left( \left[0, \infty\right) \right)\oplus \mathcal{H}\right)' sT(e4, "TensorProductHilbertSpace((DirectSumHilbertSpace(TensorProductHilbertSpace(ComplexSpace(Integer(1)),ComplexSpace(Integer(2))),TensorPowerHilbertSpace(FockSpace(),Integer(2)))),(DirectSumHilbertSpace(L2(Interval(Integer(0), oo, False, True)),HilbertSpace())))")
gg3 = gam3(potargs) gg4 = gam4(potargs) zz1 = zeta1(potargs) zz2 = zeta2(potargs) zz3 = zeta3(potargs) zz4 = zeta4(potargs) nn1 = eta1(potargs) nn2 = eta2(potargs) nn3 = eta3(potargs) kk1 = kappa1(potargs) kk2 = kappa2(potargs) kk3 = kappa3(potargs) # this might overdo it but the sympy expressions # were handled erroneously before w3j_m2 = (Wigner3j(1, Lrel - 1, Lrel, 0, 0, 0).doit())**2 w3j_p2 = (Wigner3j(1, Lrel + 1, Lrel, 0, 0, 0).doit())**2 wigm = 0 if (w3j_m2 == 0) else float(w3j_m2.evalf()) wigp = 0 if (w3j_p2 == 0) else float(w3j_p2.evalf()) if pedantic: print("Lambda = %2.2f A = %d\n" % (Lamb, Ncore)) print("a core = %4.4f\n" % coreosci) print("LEC 2b = %+6.4e LEC 3b = %+6.4e\n" % (LeC, LeD)) print(' 1 2 3 4') print("alpha = %+6.4e %+6.4e %+6.4e %+6.4e" % (aa1, aa2, aa3, aa4)) print("beta = %+6.4e %+6.4e %+6.4e %+6.4e" % (bb1, bb2, bb3, bb4)) print("gamma = %+6.4e %+6.4e %+6.4e %+6.4e" % (gg1, gg2, gg3, gg4))
def test_sympy__physics__quantum__cg__Wigner3j(): from sympy.physics.quantum.cg import Wigner3j assert _test_args(Wigner3j(6, 0, 4, 0, 2, 0))
def test_doit(): assert Wigner3j(1/2, -1/2, 1/2, 1/2, 0, 0).doit() == -sqrt(2)/2 assert Wigner6j(1, 2, 3, 2, 1, 2).doit() == sqrt(21)/105 assert Wigner9j( 2, 1, 1, S(3)/2, S(1)/2, 1, S(1)/2, S(1)/2, 0).doit() == sqrt(2)/12 assert CG(1/2, 1/2, 1/2, -1/2, 1, 0).doit() == sqrt(2)/2