qmsolve包可以将薛定谔方程可视化,下面介绍一下一维自由微观粒子的薛定谔方程解。
import numpy as np
from qmsolve import Hamiltonian, SingleParticle, TimeSimulation, init_visualization, femtoseconds, m_e, Å
#定义势能项为零
def potential_barrier(particle):
#每个粒子点的势能都要设置
barrier = np.zeros(np.shape(particle.x))
return barrier
#建立哈密顿系统,粒子=单粒子(m_e为电子质量),势能项,空间维度为1,
#绘制线的步数为600,运动范围为150
H = Hamiltonian(particles = SingleParticle(m = m_e),
potential = potential_barrier,
spatial_ndim = 1, N = 600, extent = 150 * Å)
#定义初态为高斯波包
def initial_wavefunction(particle):
σ = 0.7 * Å #方差
v0 = 40 * Å / femtoseconds #速度
p_x0 = m_e * v0 #动量项
return np.exp( -1/(4* σ**2) * ((particle.x+100)**2) / np.sqrt(2*np.pi* σ**2)) *np.exp(p_x0*particle.x*1j)#particle.x+100为初始位置
#总时长
total_time = 0.5 * femtoseconds * 4
#设立含时哈密顿量解,利用分步傅里叶法
sim = TimeSimulation(hamiltonian = H, method = "split-step")
#开始模拟,初态,总时间,时间间隔
sim.run(initial_wavefunction, total_time = total_time, dt = total_time/9000., store_steps = 800)
#画出波函数时间演化图
visualization = init_visualization(sim)
visualization.animate(animation_duration = 5, fps = 30,)
可得:
qmsolve包的作者会将该时间演化输出保存为mp4格式,如果要保存为gif动态图需要修改一下源代码:
打开C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\qmsolve\visualization\single_particle_1D.py,(这是我电脑包的地址),打开此文件,在464行和465行之间加代码:a.save("freedom.gif",writer="pillow",dpi = 80),即可保存为gif文件。
标签:visualization,波函数,barrier,particle,微观粒子,qmsolve,np,total From: https://blog.csdn.net/qq_37668266/article/details/136771668