使用 scipy.integrate.odeint 在调用时完成了过多的工作(可能是错误的 Dfun 类型)

问题描述 投票:0回答:1

我正在用 Python 编写一个代码来预测氢的能级,我将使用它作为研究夸克元素能级的模板。我使用

scipy.integrate.odeint()
函数来求解 Shroedinger 方程,对于最高
n=6
的较低能级,它工作得很好。我不认为我有太多需要超越这一点,但 odeint 返回
Excess work done on this call (perhaps wrong Dfun type).
这只会鼓励我扩展我可以预测的内容。

我使用的薛定谔方程替换是:

u'' - (l*(l+1)/r**2 - 2mu_e(E-V_emag(r))) * u = 0
=>
u' = v
v' = ((l*(l+1))/(r**2) - 2.0*mu_e*(E - V_emag(r)))*u

然后我在其上使用

scipy.integrate.odeint()
并迭代能量并使用我定义的其他函数来评估结果中的转折点和节点。我找到能量水平的方法是找到尽可能低的 E 值,其中转折点和节点的数量与其应有的数量相匹配;然后将
L
加 1 并找到新的地面能量,例如如果
L=0
我会找到
n=1
能量,如果
L=3
,我会找到
n=2
能量。

一旦代码递增到

L=7
,它不会返回任何有用的内容。
r
的范围已扩大,但我尝试保持不变以减少步骤数,但无济于事。该代码是自学的,因此在我的研究中我读到了有关雅可比行列式的内容。恐怕我还没有弄清楚它们是什么或者我是否需要它们。有什么想法吗?

def v_emag(r):
    v = -alpha/r
    return v

def s_e(y,r,l,E): #Shroedinger equation for electromagntism
    x = numpy.zeros_like(y)
    x[0] = y[1]
    x[1] = ((l*(l+1))/(r**2) - 2.0*mu_e*(E - V_emag(r)))*y[0]
    return x

def i_s_e(l,E,start=0.001,stop=None,step=(0.005*bohr)):
    if stop is None:
        stop = ((l+1)*30-10)*bohr
    r = numpy.arange(start,stop,step)
    y = odeint(s_e,y0,r,args=(l,E))
    return y

def inormalise_e(l,E,start=0.001,stop=None,step=(0.005*bohr)):
    if stop is None:
        stop = ((l+1)*30-10)*bohr
    r = numpy.arange(start,stop,step)
    f = i_s_e(l,E,start,stop,step)[:,0]
    f2 = f**2
    area = numpy.trapz(f2,x=r)
    return f/(numpy.sqrt(area))

def inodes_e(l,E,start=0.001,stop=None,step=(0.005*bohr)):
    if stop is None:
        stop = ((l+1)*30-10)*bohr
    x = i_s_e(l,E,start,stop,step)
    r = numpy.arange(start,stop,step)
    k=0
    for i in range(len(r)-1):
        if x[i,0]*x[i+1,0] < 0: #If u value times next u value <0,
            k+=1               #crossing of u=0 has occured, therefore count node
    return k

def iturns_e(l,E,start=0.001,stop=None,step=(0.005*bohr)):
    if stop is None:
        stop = ((l+1)*30-10)*bohr
    x = i_s_e(l,E,start,stop,step)
    r = numpy.arange(start,stop,step)
    k = 0
    for i in range(len(r)-1):
        if x[i,1]*x[i+1,1] < 0: #If du/dr value times next du/dr value <0,
            k=k+1               #crossing of du/dr=0, therefore a maximum/minimum
    return k

l = 0
while l < 10:    #The ground state for a system with a non-zero angular momentum will
    E1 = -1.5e-08    #be the energy level of principle quantum number l-1, therefore
    E3 = 0           #by changing l, we can find n by searching for the ground state
    E2 = 0.5*(E1+E3)
    i = 0
    while i < 40:
        N1 = inodes_e(l,E1)
        N2 = inodes_e(l,E2)
        N3 = inodes_e(l,E3)
        T1 = iturns_e(l,E1)
        T2 = iturns_e(l,E2)
        T3 = iturns_e(l,E3)
        if N1 != N2:# and T1 != T2: #Looks in lower half first, therefore will tend to ground state
            E3 = E2
            E2 = 0.5*(E1+E3)
        elif N2 != N3:# and T2 != T3:
            E1 = E2
            E2 = 0.5*(E1+E3)
        else:
            print "Can't find satisfactory E in range"
            break

        i += 1
    x = inormalise_e(l,E2)
    if x[((l+1)**2)/0.005] > (x[2*((l+1)**2)/0.005]) and iturns_e(l,E2+1e-20)==1:
        print 'Energy of state: n =',(l+1),'is: ',(E2*(10**9)),'eV'
        l += 1
    else:
        E1 = E2+10e-20
python scipy physics odeint
1个回答
0
投票

我不知道你的代码到底出了什么问题,也不完全确定你的

while i<40:
循环在做什么,所以如果我错了,也许你可以纠正以下内容。

如果您想要该系统的某个

n, l
的波函数,您可以将能量计算为 E = RH/n^2,其中 RH 是里德伯常数,因此您不需要计算节点。如果您确实需要计算节点数,那么
(n,l)
对应的数字是
n-l-1
,因此您可以改变 E 并观察固定 l 的节点数变化。

在我看来,主要问题是你的 r 范围不够大,无法包含所有节点(对于大 n ~ l ),并且

odeint
不知道远离 other (非物理)渐近解,psi ~ exp(+ cr),因此在某些条件下,对于较大的 r,将 psi 发送到 ±无穷大。

如果有帮助的话,这就是我想出的方法来找到 SE 方程的数值解:您需要根据

r
改变
n,l
范围,以避免上述问题(例如,看看如果你要求
n, l = 10, 9
)。

import numpy as np
import scipy as sp
from scipy.integrate import odeint

m_e, m_p, hbar = sp.constants.m_e, sp.constants.m_p, sp.constants.hbar
mu_e = m_e*m_p/(m_e + m_p)
bohr = sp.constants.physical_constants['Bohr radius'][0]
Rinfhc = sp.constants.physical_constants['Rydberg constant times hc in J'][0]
RHhc = Rinfhc * mu_e / m_e

fac = sp.constants.e**2/4/sp.pi/sp.constants.epsilon_0

def V(r):
    return -fac/r

def deriv(y, r, l, E):
    y1, y2 = y
    dy1dr = y2
    dy2dr = -2*y2/r - (2*mu_e/hbar**2*(E - V(r)) - l*(l+1)/r**2)*y1
    return dy1dr, dy2dr

def solveSE(l, E, y0):
    rstep = 0.001 * bohr
    rmin = rstep
    rmax = 200*l * bohr         # 
    r = np.arange(rmin, rmax, rstep)
    y, dydt = odeint(deriv, y0, r, args=(l,E)).T
    return r, y, dydt

n = 10
l = 2
y0 = (bohr, -bohr)
E = -RHhc / n**2
r, psi, dpsi_dr = solveSE(l, E, y0)

import pylab
pylab.plot(r, psi)
pylab.show()
© www.soinside.com 2019 - 2024. All rights reserved.