心得体会,搜索官方文档。
充分利用numpy广播特性,优化了Hatree-Fork自洽计算过程(Hatree-Fork过程不是计算瓶颈)
# Hatree_Fork 自洽计算过程
def Hatree_Fock(ks, Nup_avg,Ndown_avg, U, mu,T, N, ncc):
m = 2*N
nk = ks.size
for i in range(ncc):
Nup_avg_tmp = np.zeros((m,m),dtype='double')
Ndown_avg_tmp = np.zeros((m,m),dtype='double')
for i in range(nk):
Hk0 = Hamiltonian_H0(ks[i],N)
Hk_up = Hk0 + U*(Ndown_avg -0.5*np.eye(m))
Hk_down = Hk0 + U*(Nup_avg - 0.5*np.eye(m))
Ek_up, Ak_up = eigh(Hk_up)
Ek_down, Ak_down = eigh(Hk_down)
fermi_up = fermi(Ek_up,mu,T).reshape(1,m)
fermi_down = fermi(Ek_down,mu,T).reshape(1,m)
Nk_up = (Ak_up*Ak_up.conj()*fermi_up).sum(axis=1,dtype='double')
Nk_down = (Ak_down*Ak_down.conj()*fermi_down).sum(axi