update
This commit is contained in:
69
academic_codes/2019.10.23_Hamiltonian_and_bands_of_graphene/1D_graphene.py
Executable file
69
academic_codes/2019.10.23_Hamiltonian_and_bands_of_graphene/1D_graphene.py
Executable file
@@ -0,0 +1,69 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/408
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import cmath
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k, N, M, t1): # Haldane哈密顿量(N是条带的宽度参数)
|
||||||
|
# 初始化为零矩阵
|
||||||
|
h00 = np.zeros((4*N, 4*N), dtype=complex)
|
||||||
|
h01 = np.zeros((4*N, 4*N), dtype=complex)
|
||||||
|
|
||||||
|
# 原胞内的跃迁h00
|
||||||
|
for i in range(N):
|
||||||
|
h00[i*4+0, i*4+0] = M
|
||||||
|
h00[i*4+1, i*4+1] = -M
|
||||||
|
h00[i*4+2, i*4+2] = M
|
||||||
|
h00[i*4+3, i*4+3] = -M
|
||||||
|
|
||||||
|
# 最近邻
|
||||||
|
h00[i*4+0, i*4+1] = t1
|
||||||
|
h00[i*4+1, i*4+0] = t1
|
||||||
|
h00[i*4+1, i*4+2] = t1
|
||||||
|
h00[i*4+2, i*4+1] = t1
|
||||||
|
h00[i*4+2, i*4+3] = t1
|
||||||
|
h00[i*4+3, i*4+2] = t1
|
||||||
|
for i in range(N-1):
|
||||||
|
# 最近邻
|
||||||
|
h00[i*4+3, (i+1)*4+0] = t1
|
||||||
|
h00[(i+1)*4+0, i*4+3] = t1
|
||||||
|
|
||||||
|
# 原胞间的跃迁h01
|
||||||
|
for i in range(N):
|
||||||
|
# 最近邻
|
||||||
|
h01[i*4+1, i*4+0] = t1
|
||||||
|
h01[i*4+2, i*4+3] = t1
|
||||||
|
|
||||||
|
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
hamiltonian0 = functools.partial(hamiltonian, N=40, M=0, t1=1)
|
||||||
|
k = np.linspace(-pi, pi, 300)
|
||||||
|
plot_bands_one_dimension(k, hamiltonian0)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_one_dimension(k, hamiltonian):
|
||||||
|
dim = hamiltonian(0).shape[0]
|
||||||
|
dim_k = k.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim_k, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k0 in k:
|
||||||
|
matrix0 = hamiltonian(k0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
i0 += 1
|
||||||
|
for dim0 in range(dim):
|
||||||
|
plt.plot(k, eigenvalue_k[:, dim0], '-k')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
66
academic_codes/2019.10.23_Hamiltonian_and_bands_of_graphene/2D_graphene.py
Executable file
66
academic_codes/2019.10.23_Hamiltonian_and_bands_of_graphene/2D_graphene.py
Executable file
@@ -0,0 +1,66 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/408
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import cmath
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k1, k2, M, t1, a=1/sqrt(3)): # Haldane哈密顿量(a为原子间距,不赋值的话默认为1/sqrt(3))
|
||||||
|
# 初始化为零矩阵
|
||||||
|
h0 = np.zeros((2, 2), dtype=complex)
|
||||||
|
h1 = np.zeros((2, 2), dtype=complex)
|
||||||
|
h2 = np.zeros((2, 2), dtype=complex)
|
||||||
|
|
||||||
|
# 质量项(mass term),用于打开带隙
|
||||||
|
h0[0, 0] = M
|
||||||
|
h0[1, 1] = -M
|
||||||
|
|
||||||
|
# 最近邻项
|
||||||
|
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
|
||||||
|
h1[0, 1] = h1[1, 0].conj()
|
||||||
|
|
||||||
|
# # 最近邻项也可写成这种形式
|
||||||
|
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
|
||||||
|
# h1[0, 1] = h1[1, 0].conj()
|
||||||
|
|
||||||
|
matrix = h0 + h1
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
hamiltonian0 = functools.partial(hamiltonian, M=0, t1=1, a=1/sqrt(3)) # 使用偏函数,固定一些参数
|
||||||
|
k1 = np.linspace(-2*pi, 2*pi, 800)
|
||||||
|
k2 = np.linspace(-2*pi, 2*pi, 800)
|
||||||
|
plot_bands_two_dimension(k1, k2, hamiltonian0)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_two_dimension(k1, k2, hamiltonian):
|
||||||
|
from matplotlib import cm
|
||||||
|
dim = hamiltonian(0, 0).shape[0]
|
||||||
|
dim1 = k1.shape[0]
|
||||||
|
dim2 = k2.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim2, dim1, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k10 in k1:
|
||||||
|
j0 = 0
|
||||||
|
for k20 in k2:
|
||||||
|
matrix0 = hamiltonian(k10, k20)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
j0 += 1
|
||||||
|
i0 += 1
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.gca(projection='3d')
|
||||||
|
k1, k2 = np.meshgrid(k1, k2)
|
||||||
|
for dim0 in range(dim):
|
||||||
|
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,94 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/410
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import cmath
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k, N, M, t1, t2, phi): # Haldane哈密顿量(N是条带的宽度参数)
|
||||||
|
# 初始化为零矩阵
|
||||||
|
h00 = np.zeros((4*N, 4*N), dtype=complex)
|
||||||
|
h01 = np.zeros((4*N, 4*N), dtype=complex)
|
||||||
|
|
||||||
|
# 原胞内的跃迁h00
|
||||||
|
for i in range(N):
|
||||||
|
h00[i*4+0, i*4+0] = M
|
||||||
|
h00[i*4+1, i*4+1] = -M
|
||||||
|
h00[i*4+2, i*4+2] = M
|
||||||
|
h00[i*4+3, i*4+3] = -M
|
||||||
|
|
||||||
|
# 最近邻
|
||||||
|
h00[i*4+0, i*4+1] = t1
|
||||||
|
h00[i*4+1, i*4+0] = t1
|
||||||
|
h00[i*4+1, i*4+2] = t1
|
||||||
|
h00[i*4+2, i*4+1] = t1
|
||||||
|
h00[i*4+2, i*4+3] = t1
|
||||||
|
h00[i*4+3, i*4+2] = t1
|
||||||
|
|
||||||
|
# 次近邻
|
||||||
|
h00[i*4+0, i*4+2] = t2*cmath.exp(-1j*phi) # 逆时针为正,顺时针为负
|
||||||
|
h00[i*4+2, i*4+0] = h00[i*4+0, i*4+2].conj()
|
||||||
|
h00[i*4+1, i*4+3] = t2*cmath.exp(-1j*phi)
|
||||||
|
h00[i*4+3, i*4+1] = h00[i*4+1, i*4+3].conj()
|
||||||
|
for i in range(N-1):
|
||||||
|
# 最近邻
|
||||||
|
h00[i*4+3, (i+1)*4+0] = t1
|
||||||
|
h00[(i+1)*4+0, i*4+3] = t1
|
||||||
|
|
||||||
|
# 次近邻
|
||||||
|
h00[i*4+2, (i+1)*4+0] = t2*cmath.exp(1j*phi)
|
||||||
|
h00[(i+1)*4+0, i*4+2] = h00[i*4+2, (i+1)*4+0].conj()
|
||||||
|
h00[i*4+3, (i+1)*4+1] = t2*cmath.exp(1j*phi)
|
||||||
|
h00[(i+1)*4+1, i*4+3] = h00[i*4+3, (i+1)*4+1].conj()
|
||||||
|
|
||||||
|
# 原胞间的跃迁h01
|
||||||
|
for i in range(N):
|
||||||
|
# 最近邻
|
||||||
|
h01[i*4+1, i*4+0] = t1
|
||||||
|
h01[i*4+2, i*4+3] = t1
|
||||||
|
|
||||||
|
# 次近邻
|
||||||
|
h01[i*4+0, i*4+0] = t2*cmath.exp(1j*phi)
|
||||||
|
h01[i*4+1, i*4+1] = t2*cmath.exp(-1j*phi)
|
||||||
|
h01[i*4+2, i*4+2] = t2*cmath.exp(1j*phi)
|
||||||
|
h01[i*4+3, i*4+3] = t2*cmath.exp(-1j*phi)
|
||||||
|
|
||||||
|
h01[i*4+1, i*4+3] = t2*cmath.exp(1j*phi)
|
||||||
|
h01[i*4+2, i*4+0] = t2*cmath.exp(-1j*phi)
|
||||||
|
if i != 0:
|
||||||
|
h01[i*4+1, (i-1)*4+3] = t2*cmath.exp(1j*phi)
|
||||||
|
for i in range(N-1):
|
||||||
|
h01[i*4+2, (i+1)*4+0] = t2*cmath.exp(-1j*phi)
|
||||||
|
|
||||||
|
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
hamiltonian0 = functools.partial(hamiltonian, N=40, M=2/3, t1=1, t2=1/3, phi=pi/4)
|
||||||
|
k = np.linspace(-pi, pi, 300)
|
||||||
|
plot_bands_one_dimension(k, hamiltonian0)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_one_dimension(k, hamiltonian):
|
||||||
|
dim = hamiltonian(0).shape[0]
|
||||||
|
dim_k = k.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim_k, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k0 in k:
|
||||||
|
matrix0 = hamiltonian(k0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
i0 += 1
|
||||||
|
for dim0 in range(dim):
|
||||||
|
plt.plot(k, eigenvalue_k[:, dim0], '-k')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,70 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/410
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import cmath
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量(a为原子间距,不赋值的话默认为1/sqrt(3))
|
||||||
|
# 初始化为零矩阵
|
||||||
|
h0 = np.zeros((2, 2), dtype=complex)
|
||||||
|
h1 = np.zeros((2, 2), dtype=complex)
|
||||||
|
h2 = np.zeros((2, 2), dtype=complex)
|
||||||
|
|
||||||
|
# 质量项(mass term),用于打开带隙
|
||||||
|
h0[0, 0] = M
|
||||||
|
h0[1, 1] = -M
|
||||||
|
|
||||||
|
# 最近邻项
|
||||||
|
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
|
||||||
|
h1[0, 1] = h1[1, 0].conj()
|
||||||
|
|
||||||
|
# 最近邻项也可写成这种形式
|
||||||
|
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)-t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
|
||||||
|
# h1[0, 1] = h1[1, 0].conj()
|
||||||
|
|
||||||
|
# 次近邻项
|
||||||
|
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
|
||||||
|
matrix = h0 + h1 + h2 + h2.transpose().conj()
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=1/sqrt(3))
|
||||||
|
k1 = np.linspace(-2*pi, 2*pi, 500)
|
||||||
|
k2 = np.linspace(-2*pi, 2*pi, 500)
|
||||||
|
plot_bands_two_dimension(k1, k2, hamiltonian0)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_two_dimension(k1, k2, hamiltonian):
|
||||||
|
from matplotlib import cm
|
||||||
|
dim = hamiltonian(0, 0).shape[0]
|
||||||
|
dim1 = k1.shape[0]
|
||||||
|
dim2 = k2.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim2, dim1, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k10 in k1:
|
||||||
|
j0 = 0
|
||||||
|
for k20 in k2:
|
||||||
|
matrix0 = hamiltonian(k10, k20)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
j0 += 1
|
||||||
|
i0 += 1
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.gca(projection='3d')
|
||||||
|
k1, k2 = np.meshgrid(k1, k2)
|
||||||
|
for dim0 in range(dim):
|
||||||
|
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,101 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/948
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import copy
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_00(width=10): # 不赋值时默认为10
|
||||||
|
h00 = np.zeros((width, width))
|
||||||
|
for width0 in range(width-1):
|
||||||
|
h00[width0, width0+1] = 1
|
||||||
|
h00[width0+1, width0] = 1
|
||||||
|
return h00
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_01(width=10): # 不赋值时默认为10
|
||||||
|
h01 = np.identity(width)
|
||||||
|
return h01
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_time = time.time()
|
||||||
|
h00 = matrix_00(width=5)
|
||||||
|
h01 = matrix_01(width=5)
|
||||||
|
fermi_energy_array = np.arange(-4, 4, .01)
|
||||||
|
plot_conductance_energy(fermi_energy_array, h00, h01)
|
||||||
|
end_time = time.time()
|
||||||
|
print('运行时间=', end_time-start_time)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_conductance_energy(fermi_energy_array, h00, h01): # 画电导与费米能关系图
|
||||||
|
dim = fermi_energy_array.shape[0]
|
||||||
|
cond = np.zeros(dim)
|
||||||
|
i0 = 0
|
||||||
|
for fermi_energy0 in fermi_energy_array:
|
||||||
|
cond0 = np.real(conductance(fermi_energy0 + 1e-12j, h00, h01))
|
||||||
|
cond[i0] = cond0
|
||||||
|
i0 += 1
|
||||||
|
plt.plot(fermi_energy_array, cond, '-k')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵T。dim是传递矩阵h00和h01的维度
|
||||||
|
transfer = np.zeros((2*dim, 2*dim))*(0+0j) # 乘0+0j,把变量转为复数
|
||||||
|
transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00) # np.dot()等效于np.matmul()
|
||||||
|
transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj())
|
||||||
|
transfer[dim:2*dim, 0:dim] = np.identity(dim)
|
||||||
|
transfer[dim:2*dim, dim:2*dim] = 0 # a:b代表 a <= x < b,左闭右开
|
||||||
|
return transfer # 返回转移矩阵
|
||||||
|
|
||||||
|
|
||||||
|
def green_function_lead(fermi_energy, h00, h01, dim): # 电极的表面格林函数
|
||||||
|
transfer = transfer_matrix(fermi_energy, h00, h01, dim)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(transfer)
|
||||||
|
ind = np.argsort(np.abs(eigenvalue))
|
||||||
|
temp = np.zeros((2*dim, 2*dim))*(1+0j)
|
||||||
|
i0 = 0
|
||||||
|
for ind0 in ind:
|
||||||
|
temp[:, i0] = eigenvector[:, ind0]
|
||||||
|
i0 += 1
|
||||||
|
s1 = temp[dim:2*dim, 0:dim]
|
||||||
|
s2 = temp[0:dim, 0:dim]
|
||||||
|
s3 = temp[dim:2*dim, dim:2*dim]
|
||||||
|
s4 = temp[0:dim, dim:2*dim]
|
||||||
|
right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1)))
|
||||||
|
left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4)))
|
||||||
|
return right_lead_surface, left_lead_surface # 返回右电极的表面格林函数和左电极的表面格林函数
|
||||||
|
|
||||||
|
|
||||||
|
def self_energy_lead(fermi_energy, h00, h01, dim): # 电极的自能
|
||||||
|
right_lead_surface, left_lead_surface = green_function_lead(fermi_energy, h00, h01, dim)
|
||||||
|
right_self_energy = np.dot(np.dot(h01, right_lead_surface), h01.transpose().conj())
|
||||||
|
left_self_energy = np.dot(np.dot(h01.transpose().conj(), left_lead_surface), h01)
|
||||||
|
return right_self_energy, left_self_energy # 返回右边电极自能和左边电极自能
|
||||||
|
|
||||||
|
|
||||||
|
def conductance(fermi_energy, h00, h01, nx=300): # 计算电导
|
||||||
|
dim = h00.shape[0]
|
||||||
|
right_self_energy, left_self_energy = self_energy_lead(fermi_energy, h00, h01, dim)
|
||||||
|
for ix in range(nx):
|
||||||
|
if ix == 0:
|
||||||
|
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-left_self_energy)
|
||||||
|
green_0n_n = copy.deepcopy(green_nn_n) # 如果直接用等于,两个变量会指向相同的id,改变一个值,另外一个值可能会发生改变,容易出错,所以要用上这个COPY
|
||||||
|
elif ix != nx-1:
|
||||||
|
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
|
||||||
|
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
|
||||||
|
else:
|
||||||
|
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)-right_self_energy)
|
||||||
|
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
|
||||||
|
right_self_energy = (right_self_energy - right_self_energy.transpose().conj())*(0+1j)
|
||||||
|
left_self_energy = (left_self_energy - left_self_energy.transpose().conj())*(0+1j)
|
||||||
|
transmission = np.trace(np.dot(np.dot(np.dot(left_self_energy, green_0n_n), right_self_energy), green_0n_n.transpose().conj()))
|
||||||
|
return transmission # 返回电导值
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,43 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/962
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(width=2, length=4): # 有一定宽度和长度的方格子
|
||||||
|
h00 = np.zeros((width*length, width*length))
|
||||||
|
for i0 in range(length):
|
||||||
|
for j0 in range(width-1):
|
||||||
|
h00[i0*width+j0, i0*width+j0+1] = 1
|
||||||
|
h00[i0*width+j0+1, i0*width+j0] = 1
|
||||||
|
for i0 in range(length-1):
|
||||||
|
for j0 in range(width):
|
||||||
|
h00[i0*width+j0, (i0+1)*width+j0] = 1
|
||||||
|
h00[(i0+1)*width+j0, i0*width+j0] = 1
|
||||||
|
return h00
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
h0 = hamiltonian()
|
||||||
|
dim = h0.shape[0]
|
||||||
|
n = 4 # 选取第n个能级
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(h0) # 本征值、本征矢
|
||||||
|
# print(h0)
|
||||||
|
# print('哈密顿量的维度:', dim) # 哈密顿量的维度
|
||||||
|
# print('本征矢的维度:', eigenvector.shape) # 本征矢的维度
|
||||||
|
# print('能级(未排序):', eigenvalue) # 输出本征值。因为体系是受限的,所以是离散的能级
|
||||||
|
# print('选取第', n, '个能级,为', eigenvalue[n-1]) # 从1开始算,查看第n个能级是什么(这里本征值未排序)
|
||||||
|
# print('第', n, '个能级对应的波函数:', eigenvector[:, n-1]) # 查看第n个能级对应的波函数
|
||||||
|
print('\n波函数模的平方:\n', np.square(np.abs(eigenvector[:, n-1]))) # 查看第n个能级对应的波函数模的平方
|
||||||
|
green = np.linalg.inv((eigenvalue[n-1]+1e-15j)*np.eye(dim)-h0) # 第n个能级对应的格林函数
|
||||||
|
total = np.trace(np.imag(green)) # 求该能级格林函数的迹,对应的是总态密度(忽略符号和系数)
|
||||||
|
print('归一化后的态密度分布:')
|
||||||
|
for i in range(dim):
|
||||||
|
print(np.imag(green)[i, i]/total) # 第n个能级单位化后的态密度分布
|
||||||
|
print('观察以上两个分布的数值情况,可以发现两者完全相同。')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,114 @@
|
|||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import os
|
||||||
|
os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
# 万有引力常数
|
||||||
|
G = 1
|
||||||
|
|
||||||
|
# 三体的质量
|
||||||
|
m1 = 10 # 绿色
|
||||||
|
m2 = 1000 # 红色
|
||||||
|
m3 = 10 # 蓝色
|
||||||
|
|
||||||
|
# 三体的初始位置
|
||||||
|
x1 = 0 # 绿色
|
||||||
|
y1 = 500
|
||||||
|
x2 = 0 # 红色
|
||||||
|
y2 = 0
|
||||||
|
x3 = 0 # 蓝色
|
||||||
|
y3 = 1000
|
||||||
|
|
||||||
|
# 三体的初始速度
|
||||||
|
v1_x = 1.5 # 绿色
|
||||||
|
v1_y = 0
|
||||||
|
v2_x = 0 # 红色
|
||||||
|
v2_y = 0
|
||||||
|
v3_x = 0.8 # 蓝色
|
||||||
|
v3_y = 0
|
||||||
|
|
||||||
|
# 步长
|
||||||
|
t = 0.1
|
||||||
|
|
||||||
|
plt.ion() # 开启交互模式
|
||||||
|
observation_max = 100 # 视线范围初始值
|
||||||
|
x1_all = [x1] # 轨迹初始值
|
||||||
|
y1_all = [y1]
|
||||||
|
x2_all = [x2]
|
||||||
|
y2_all = [y2]
|
||||||
|
x3_all = [x3]
|
||||||
|
y3_all = [y3]
|
||||||
|
|
||||||
|
i0 = 0
|
||||||
|
for i in range(1000000):
|
||||||
|
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
|
||||||
|
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
|
||||||
|
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
|
||||||
|
|
||||||
|
# 对物体1的计算
|
||||||
|
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式)
|
||||||
|
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
|
||||||
|
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
|
||||||
|
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
|
||||||
|
v1_x = v1_x + a1_x*t # 物体1的速度
|
||||||
|
v1_y = v1_y + a1_y*t # 物体1的速度
|
||||||
|
x1 = x1 + v1_x*t # 物体1的水平位置
|
||||||
|
y1 = y1 + v1_y*t # 物体1的垂直位置
|
||||||
|
x1_all = np.append(x1_all, x1) # 记录轨迹
|
||||||
|
y1_all = np.append(y1_all, y1) # 记录轨迹
|
||||||
|
|
||||||
|
# 对物体2的计算
|
||||||
|
a2_1 = G*m1/(distance12**2)
|
||||||
|
a2_3 = G*m3/(distance23**2)
|
||||||
|
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
|
||||||
|
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
|
||||||
|
v2_x = v2_x + a2_x*t
|
||||||
|
v2_y = v2_y + a2_y*t
|
||||||
|
x2 = x2 + v2_x*t
|
||||||
|
y2 = y2 + v2_y*t
|
||||||
|
x2_all = np.append(x2_all, x2)
|
||||||
|
y2_all = np.append(y2_all, y2)
|
||||||
|
|
||||||
|
# 对物体3的计算
|
||||||
|
a3_1 = G*m1/(distance13**2)
|
||||||
|
a3_2 = G*m2/(distance23**2)
|
||||||
|
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
|
||||||
|
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
|
||||||
|
v3_x = v3_x + a3_x*t
|
||||||
|
v3_y = v3_y + a3_y*t
|
||||||
|
x3 = x3 + v3_x*t
|
||||||
|
y3 = y3 + v3_y*t
|
||||||
|
x3_all = np.append(x3_all, x3)
|
||||||
|
y3_all = np.append(y3_all, y3)
|
||||||
|
|
||||||
|
# 选择观测坐标
|
||||||
|
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
|
||||||
|
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
|
||||||
|
while True:
|
||||||
|
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
|
||||||
|
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
|
||||||
|
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
|
||||||
|
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
|
||||||
|
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
|
||||||
|
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
|
||||||
|
|
||||||
|
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。
|
||||||
|
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
|
||||||
|
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
|
||||||
|
plt.plot(x1_all, y1_all, '-g') # 画轨迹
|
||||||
|
plt.plot(x2_all, y2_all, '-r')
|
||||||
|
plt.plot(x3_all, y3_all, '-b')
|
||||||
|
|
||||||
|
|
||||||
|
# plt.show() # 显示图像
|
||||||
|
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
|
||||||
|
|
||||||
|
if np.mod(i, 100) == 0: # 当运动明显时,把图画出来
|
||||||
|
print(i0)
|
||||||
|
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
|
||||||
|
i0 += 1
|
||||||
|
plt.clf() # 清空
|
@@ -0,0 +1,110 @@
|
|||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import os
|
||||||
|
os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
# 万有引力常数
|
||||||
|
G = 1
|
||||||
|
|
||||||
|
# 三体的质量
|
||||||
|
m1 = 3 # 绿色
|
||||||
|
m2 = 100 # 红色
|
||||||
|
m3 = 10 # 蓝色
|
||||||
|
|
||||||
|
# 三体的初始位置
|
||||||
|
x1 = 0 # 绿色
|
||||||
|
y1 = -100
|
||||||
|
x2 = 0 # 红色
|
||||||
|
y2 = 0
|
||||||
|
x3 = 0 # 蓝色
|
||||||
|
y3 = 50
|
||||||
|
|
||||||
|
# 三体的初始速度
|
||||||
|
v1_x = 1 # 绿色
|
||||||
|
v1_y = 0
|
||||||
|
v2_x = 0 # 红色
|
||||||
|
v2_y = 0
|
||||||
|
v3_x = 2 # 蓝色
|
||||||
|
v3_y = 0
|
||||||
|
|
||||||
|
# 步长
|
||||||
|
t = 0.05
|
||||||
|
|
||||||
|
plt.ion() # 开启交互模式
|
||||||
|
observation_max = 100 # 观测坐标范围初始值
|
||||||
|
x1_all = [x1] # 轨迹初始值
|
||||||
|
y1_all = [y1]
|
||||||
|
x2_all = [x2]
|
||||||
|
y2_all = [y2]
|
||||||
|
x3_all = [x3]
|
||||||
|
y3_all = [y3]
|
||||||
|
|
||||||
|
i0 = 0
|
||||||
|
for i in range(100000000000):
|
||||||
|
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
|
||||||
|
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
|
||||||
|
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
|
||||||
|
# 对物体1的计算
|
||||||
|
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式)
|
||||||
|
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
|
||||||
|
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
|
||||||
|
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
|
||||||
|
v1_x = v1_x + a1_x*t # 物体1的速度
|
||||||
|
v1_y = v1_y + a1_y*t # 物体1的速度
|
||||||
|
x1 = x1 + v1_x*t # 物体1的水平位置
|
||||||
|
y1 = y1 + v1_y*t # 物体1的垂直位置
|
||||||
|
x1_all = np.append(x1_all, x1) # 记录轨迹
|
||||||
|
y1_all = np.append(y1_all, y1) # 记录轨迹
|
||||||
|
# 对物体2的计算
|
||||||
|
a2_1 = G*m1/(distance12**2)
|
||||||
|
a2_3 = G*m3/(distance23**2)
|
||||||
|
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
|
||||||
|
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
|
||||||
|
v2_x = v2_x + a2_x*t
|
||||||
|
v2_y = v2_y + a2_y*t
|
||||||
|
x2 = x2 + v2_x*t
|
||||||
|
y2 = y2 + v2_y*t
|
||||||
|
x2_all = np.append(x2_all, x2)
|
||||||
|
y2_all = np.append(y2_all, y2)
|
||||||
|
# 对物体3的计算
|
||||||
|
a3_1 = G*m1/(distance13**2)
|
||||||
|
a3_2 = G*m2/(distance23**2)
|
||||||
|
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
|
||||||
|
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
|
||||||
|
v3_x = v3_x + a3_x*t
|
||||||
|
v3_y = v3_y + a3_y*t
|
||||||
|
x3 = x3 + v3_x*t
|
||||||
|
y3 = y3 + v3_y*t
|
||||||
|
x3_all = np.append(x3_all, x3)
|
||||||
|
y3_all = np.append(y3_all, y3)
|
||||||
|
|
||||||
|
# 选择观测坐标
|
||||||
|
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
|
||||||
|
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
|
||||||
|
while True:
|
||||||
|
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
|
||||||
|
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
|
||||||
|
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
|
||||||
|
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
|
||||||
|
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
|
||||||
|
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
|
||||||
|
|
||||||
|
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,画出来的面积越大。视线范围越宽,球看起来越小。
|
||||||
|
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
|
||||||
|
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
|
||||||
|
plt.plot(x1_all, y1_all, '-g') # 画轨迹
|
||||||
|
plt.plot(x2_all, y2_all, '-r')
|
||||||
|
plt.plot(x3_all, y3_all, '-b')
|
||||||
|
|
||||||
|
# plt.show() # 显示图像
|
||||||
|
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
|
||||||
|
|
||||||
|
if np.mod(i, 200) == 0:
|
||||||
|
print(i0)
|
||||||
|
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
|
||||||
|
i0 += 1
|
||||||
|
plt.clf() # 清空
|
@@ -0,0 +1,110 @@
|
|||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import os
|
||||||
|
os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
# 万有引力常数
|
||||||
|
G = 1
|
||||||
|
|
||||||
|
# 三体的质量
|
||||||
|
m1 = 3 # 绿色
|
||||||
|
m2 = 100 # 红色
|
||||||
|
m3 = 10 # 蓝色
|
||||||
|
|
||||||
|
# 三体的初始位置
|
||||||
|
x1 = 0 # 绿色
|
||||||
|
y1 = -100
|
||||||
|
x2 = 0 # 红色
|
||||||
|
y2 = 0
|
||||||
|
x3 = 0 # 蓝色
|
||||||
|
y3 = 50
|
||||||
|
|
||||||
|
# 三体的初始速度
|
||||||
|
v1_x = 1 # 绿色
|
||||||
|
v1_y = 0
|
||||||
|
v2_x = 0 # 红色
|
||||||
|
v2_y = 0
|
||||||
|
v3_x = 2 # 蓝色
|
||||||
|
v3_y = 0
|
||||||
|
|
||||||
|
# 步长
|
||||||
|
t = 0.1
|
||||||
|
|
||||||
|
plt.ion() # 开启交互模式
|
||||||
|
observation_max = 100 # 观测坐标范围初始值
|
||||||
|
x1_all = [x1] # 轨迹初始值
|
||||||
|
y1_all = [y1]
|
||||||
|
x2_all = [x2]
|
||||||
|
y2_all = [y2]
|
||||||
|
x3_all = [x3]
|
||||||
|
y3_all = [y3]
|
||||||
|
|
||||||
|
i0 = 0
|
||||||
|
for i in range(100000000000):
|
||||||
|
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
|
||||||
|
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
|
||||||
|
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
|
||||||
|
# 对物体1的计算
|
||||||
|
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式)
|
||||||
|
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
|
||||||
|
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
|
||||||
|
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
|
||||||
|
v1_x = v1_x + a1_x*t # 物体1的速度
|
||||||
|
v1_y = v1_y + a1_y*t # 物体1的速度
|
||||||
|
x1 = x1 + v1_x*t # 物体1的水平位置
|
||||||
|
y1 = y1 + v1_y*t # 物体1的垂直位置
|
||||||
|
x1_all = np.append(x1_all, x1) # 记录轨迹
|
||||||
|
y1_all = np.append(y1_all, y1) # 记录轨迹
|
||||||
|
# 对物体2的计算
|
||||||
|
a2_1 = G*m1/(distance12**2)
|
||||||
|
a2_3 = G*m3/(distance23**2)
|
||||||
|
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
|
||||||
|
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
|
||||||
|
v2_x = v2_x + a2_x*t
|
||||||
|
v2_y = v2_y + a2_y*t
|
||||||
|
x2 = x2 + v2_x*t
|
||||||
|
y2 = y2 + v2_y*t
|
||||||
|
x2_all = np.append(x2_all, x2)
|
||||||
|
y2_all = np.append(y2_all, y2)
|
||||||
|
# 对物体3的计算
|
||||||
|
a3_1 = G*m1/(distance13**2)
|
||||||
|
a3_2 = G*m2/(distance23**2)
|
||||||
|
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
|
||||||
|
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
|
||||||
|
v3_x = v3_x + a3_x*t
|
||||||
|
v3_y = v3_y + a3_y*t
|
||||||
|
x3 = x3 + v3_x*t
|
||||||
|
y3 = y3 + v3_y*t
|
||||||
|
x3_all = np.append(x3_all, x3)
|
||||||
|
y3_all = np.append(y3_all, y3)
|
||||||
|
|
||||||
|
# 选择观测坐标
|
||||||
|
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
|
||||||
|
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
|
||||||
|
while True:
|
||||||
|
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
|
||||||
|
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
|
||||||
|
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
|
||||||
|
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
|
||||||
|
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
|
||||||
|
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
|
||||||
|
|
||||||
|
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,画出来的面积越大。视线范围越宽,球看起来越小。
|
||||||
|
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
|
||||||
|
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
|
||||||
|
plt.plot(x1_all, y1_all, '-g') # 画轨迹
|
||||||
|
plt.plot(x2_all, y2_all, '-r')
|
||||||
|
plt.plot(x3_all, y3_all, '-b')
|
||||||
|
|
||||||
|
# plt.show() # 显示图像
|
||||||
|
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
|
||||||
|
|
||||||
|
if np.mod(i, 100) == 0:
|
||||||
|
print(i0)
|
||||||
|
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
|
||||||
|
i0 += 1
|
||||||
|
plt.clf() # 清空
|
@@ -0,0 +1,113 @@
|
|||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import os
|
||||||
|
os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
# 万有引力常数
|
||||||
|
G = 1
|
||||||
|
|
||||||
|
# 三体的质量
|
||||||
|
m1 = 15 # 绿色
|
||||||
|
m2 = 12 # 红色
|
||||||
|
m3 = 8 # 蓝色
|
||||||
|
|
||||||
|
# 三体的初始位置
|
||||||
|
x1 = 300 # 绿色
|
||||||
|
y1 = 50
|
||||||
|
x2 = -100 # 红色
|
||||||
|
y2 = -200
|
||||||
|
x3 = -100 # 蓝色
|
||||||
|
y3 = 150
|
||||||
|
|
||||||
|
# 三体的初始速度
|
||||||
|
v1_x = 0 # 绿色
|
||||||
|
v1_y = 0
|
||||||
|
v2_x = 0 # 红色
|
||||||
|
v2_y = 0
|
||||||
|
v3_x = 0 # 蓝色
|
||||||
|
v3_y = 0
|
||||||
|
|
||||||
|
# 步长
|
||||||
|
t = 0.05
|
||||||
|
|
||||||
|
plt.ion() # 开启交互模式
|
||||||
|
observation_max = 100 # 视线范围初始值
|
||||||
|
x1_all = [x1] # 轨迹初始值
|
||||||
|
y1_all = [y1]
|
||||||
|
x2_all = [x2]
|
||||||
|
y2_all = [y2]
|
||||||
|
x3_all = [x3]
|
||||||
|
y3_all = [y3]
|
||||||
|
|
||||||
|
i0 = 0
|
||||||
|
for i in range(1000000):
|
||||||
|
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
|
||||||
|
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
|
||||||
|
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
|
||||||
|
|
||||||
|
# 对物体1的计算
|
||||||
|
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式)
|
||||||
|
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
|
||||||
|
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
|
||||||
|
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
|
||||||
|
v1_x = v1_x + a1_x*t # 物体1的速度
|
||||||
|
v1_y = v1_y + a1_y*t # 物体1的速度
|
||||||
|
x1 = x1 + v1_x*t # 物体1的水平位置
|
||||||
|
y1 = y1 + v1_y*t # 物体1的垂直位置
|
||||||
|
x1_all = np.append(x1_all, x1) # 记录轨迹
|
||||||
|
y1_all = np.append(y1_all, y1) # 记录轨迹
|
||||||
|
|
||||||
|
# 对物体2的计算
|
||||||
|
a2_1 = G*m1/(distance12**2)
|
||||||
|
a2_3 = G*m3/(distance23**2)
|
||||||
|
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
|
||||||
|
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
|
||||||
|
v2_x = v2_x + a2_x*t
|
||||||
|
v2_y = v2_y + a2_y*t
|
||||||
|
x2 = x2 + v2_x*t
|
||||||
|
y2 = y2 + v2_y*t
|
||||||
|
x2_all = np.append(x2_all, x2)
|
||||||
|
y2_all = np.append(y2_all, y2)
|
||||||
|
|
||||||
|
# 对物体3的计算
|
||||||
|
a3_1 = G*m1/(distance13**2)
|
||||||
|
a3_2 = G*m2/(distance23**2)
|
||||||
|
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
|
||||||
|
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
|
||||||
|
v3_x = v3_x + a3_x*t
|
||||||
|
v3_y = v3_y + a3_y*t
|
||||||
|
x3 = x3 + v3_x*t
|
||||||
|
y3 = y3 + v3_y*t
|
||||||
|
x3_all = np.append(x3_all, x3)
|
||||||
|
y3_all = np.append(y3_all, y3)
|
||||||
|
|
||||||
|
# 选择观测坐标
|
||||||
|
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
|
||||||
|
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
|
||||||
|
while True:
|
||||||
|
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
|
||||||
|
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
|
||||||
|
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
|
||||||
|
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
|
||||||
|
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
|
||||||
|
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
|
||||||
|
|
||||||
|
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。
|
||||||
|
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
|
||||||
|
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
|
||||||
|
plt.plot(x1_all, y1_all, '-g') # 画轨迹
|
||||||
|
plt.plot(x2_all, y2_all, '-r')
|
||||||
|
plt.plot(x3_all, y3_all, '-b')
|
||||||
|
|
||||||
|
# plt.show() # 显示图像
|
||||||
|
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
|
||||||
|
|
||||||
|
if np.mod(i, 1000) == 0: # 当运动明显时,把图画出来
|
||||||
|
print(i0)
|
||||||
|
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
|
||||||
|
i0 += 1
|
||||||
|
plt.clf() # 清空
|
@@ -0,0 +1,113 @@
|
|||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import os
|
||||||
|
os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
# 万有引力常数
|
||||||
|
G = 1
|
||||||
|
|
||||||
|
# 三体的质量
|
||||||
|
m1 = 15 # 绿色
|
||||||
|
m2 = 12 # 红色
|
||||||
|
m3 = 8 # 蓝色
|
||||||
|
|
||||||
|
# 三体的初始位置
|
||||||
|
x1 = 300 # 绿色
|
||||||
|
y1 = 50
|
||||||
|
x2 = -100 # 红色
|
||||||
|
y2 = -200
|
||||||
|
x3 = -100 # 蓝色
|
||||||
|
y3 = 150
|
||||||
|
|
||||||
|
# 三体的初始速度
|
||||||
|
v1_x = 0 # 绿色
|
||||||
|
v1_y = 0
|
||||||
|
v2_x = 0 # 红色
|
||||||
|
v2_y = 0
|
||||||
|
v3_x = 0 # 蓝色
|
||||||
|
v3_y = 0
|
||||||
|
|
||||||
|
# 步长
|
||||||
|
t = 0.1
|
||||||
|
|
||||||
|
plt.ion() # 开启交互模式
|
||||||
|
observation_max = 100 # 视线范围初始值
|
||||||
|
x1_all = [x1] # 轨迹初始值
|
||||||
|
y1_all = [y1]
|
||||||
|
x2_all = [x2]
|
||||||
|
y2_all = [y2]
|
||||||
|
x3_all = [x3]
|
||||||
|
y3_all = [y3]
|
||||||
|
|
||||||
|
i0 = 0
|
||||||
|
for i in range(1000000):
|
||||||
|
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
|
||||||
|
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
|
||||||
|
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
|
||||||
|
|
||||||
|
# 对物体1的计算
|
||||||
|
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式)
|
||||||
|
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
|
||||||
|
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
|
||||||
|
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
|
||||||
|
v1_x = v1_x + a1_x*t # 物体1的速度
|
||||||
|
v1_y = v1_y + a1_y*t # 物体1的速度
|
||||||
|
x1 = x1 + v1_x*t # 物体1的水平位置
|
||||||
|
y1 = y1 + v1_y*t # 物体1的垂直位置
|
||||||
|
x1_all = np.append(x1_all, x1) # 记录轨迹
|
||||||
|
y1_all = np.append(y1_all, y1) # 记录轨迹
|
||||||
|
|
||||||
|
# 对物体2的计算
|
||||||
|
a2_1 = G*m1/(distance12**2)
|
||||||
|
a2_3 = G*m3/(distance23**2)
|
||||||
|
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
|
||||||
|
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
|
||||||
|
v2_x = v2_x + a2_x*t
|
||||||
|
v2_y = v2_y + a2_y*t
|
||||||
|
x2 = x2 + v2_x*t
|
||||||
|
y2 = y2 + v2_y*t
|
||||||
|
x2_all = np.append(x2_all, x2)
|
||||||
|
y2_all = np.append(y2_all, y2)
|
||||||
|
|
||||||
|
# 对物体3的计算
|
||||||
|
a3_1 = G*m1/(distance13**2)
|
||||||
|
a3_2 = G*m2/(distance23**2)
|
||||||
|
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
|
||||||
|
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
|
||||||
|
v3_x = v3_x + a3_x*t
|
||||||
|
v3_y = v3_y + a3_y*t
|
||||||
|
x3 = x3 + v3_x*t
|
||||||
|
y3 = y3 + v3_y*t
|
||||||
|
x3_all = np.append(x3_all, x3)
|
||||||
|
y3_all = np.append(y3_all, y3)
|
||||||
|
|
||||||
|
# 选择观测坐标
|
||||||
|
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
|
||||||
|
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
|
||||||
|
while True:
|
||||||
|
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
|
||||||
|
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
|
||||||
|
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
|
||||||
|
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
|
||||||
|
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
|
||||||
|
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
|
||||||
|
|
||||||
|
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。
|
||||||
|
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
|
||||||
|
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
|
||||||
|
plt.plot(x1_all, y1_all, '-g') # 画轨迹
|
||||||
|
plt.plot(x2_all, y2_all, '-r')
|
||||||
|
plt.plot(x3_all, y3_all, '-b')
|
||||||
|
|
||||||
|
# plt.show() # 显示图像
|
||||||
|
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
|
||||||
|
|
||||||
|
if np.mod(i, 500) == 0: # 当运动明显时,把图画出来
|
||||||
|
print(i0)
|
||||||
|
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
|
||||||
|
i0 += 1
|
||||||
|
plt.clf() # 清空
|
@@ -0,0 +1,73 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/1145
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def integral(): # 直接数值积分
|
||||||
|
integral_value = 0
|
||||||
|
for x in np.arange(0, 1, 1/10**7):
|
||||||
|
integral_value = integral_value + x**2*(1/10**7) # 对x^2在0和1之间积分
|
||||||
|
return integral_value
|
||||||
|
|
||||||
|
|
||||||
|
def MC_1(): # 蒙特卡洛求定积分1:投点法
|
||||||
|
n = 10**7
|
||||||
|
x_min, x_max = 0.0, 1.0
|
||||||
|
y_min, y_max = 0.0, 1.0
|
||||||
|
count = 0
|
||||||
|
for i in range(0, n):
|
||||||
|
x = random.uniform(x_min, x_max)
|
||||||
|
y = random.uniform(y_min, y_max)
|
||||||
|
# x*x > y,表示该点位于曲线的下面。所求的积分值即为曲线下方的面积与正方形面积的比。
|
||||||
|
if x * x > y:
|
||||||
|
count += 1
|
||||||
|
integral_value = count / n
|
||||||
|
return integral_value
|
||||||
|
|
||||||
|
|
||||||
|
def MC_2(): # 蒙特卡洛求定积分2:期望法
|
||||||
|
n = 10**7
|
||||||
|
x_min, x_max = 0.0, 1.0
|
||||||
|
integral_value = 0
|
||||||
|
for i in range(n):
|
||||||
|
x = random.uniform(x_min, x_max)
|
||||||
|
integral_value = integral_value + (1-0)*x**2
|
||||||
|
integral_value = integral_value/n
|
||||||
|
return integral_value
|
||||||
|
|
||||||
|
|
||||||
|
print('【计算时间】')
|
||||||
|
start_clock = time.perf_counter() # 或者用time.clock()
|
||||||
|
a00 = 1/3 # 理论值
|
||||||
|
end_clock = time.perf_counter()
|
||||||
|
print('理论值(解析):', end_clock-start_clock)
|
||||||
|
start_clock = time.perf_counter()
|
||||||
|
a0 = integral() # 直接数值积分
|
||||||
|
end_clock = time.perf_counter()
|
||||||
|
print('直接数值积分:', end_clock-start_clock)
|
||||||
|
start_clock = time.perf_counter()
|
||||||
|
a1 = MC_1() # 用蒙特卡洛求积分投点法
|
||||||
|
end_clock = time.perf_counter()
|
||||||
|
print('用蒙特卡洛求积分_投点法:', end_clock-start_clock)
|
||||||
|
start_clock = time.perf_counter()
|
||||||
|
a2 = MC_2()
|
||||||
|
end_clock = time.perf_counter()
|
||||||
|
print('用蒙特卡洛求积分_期望法:', end_clock-start_clock, '\n')
|
||||||
|
|
||||||
|
print('【计算结果】')
|
||||||
|
print('理论值(解析):', a00)
|
||||||
|
print('直接数值积分:', a0)
|
||||||
|
print('用蒙特卡洛求积分_投点法:', a1)
|
||||||
|
print('用蒙特卡洛求积分_期望法:', a2, '\n')
|
||||||
|
|
||||||
|
print('【计算误差】')
|
||||||
|
print('理论值(解析):', 0)
|
||||||
|
print('直接数值积分:', abs(a0-1/3))
|
||||||
|
print('用蒙特卡洛求积分_投点法:', abs(a1-1/3))
|
||||||
|
print('用蒙特卡洛求积分_期望法:', abs(a2-1/3))
|
||||||
|
|
@@ -0,0 +1,56 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/2033
|
||||||
|
"""
|
||||||
|
|
||||||
|
import kwant
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
L = 3
|
||||||
|
W = 2
|
||||||
|
|
||||||
|
lat = kwant.lattice.square(a=1, norbs=1) # 定义lattice
|
||||||
|
print('\nlat:\n', lat)
|
||||||
|
|
||||||
|
syst = kwant.Builder() # 定义中心区的Builder
|
||||||
|
print('\nsyst:\n', syst)
|
||||||
|
|
||||||
|
syst_finalized = syst.finalized()
|
||||||
|
hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量
|
||||||
|
print('\nhamiltonian_1(定义):\n', hamiltonian)
|
||||||
|
|
||||||
|
syst[(lat(x, y) for x in range(L) for y in range(W))] = 0 # 晶格初始化为0
|
||||||
|
|
||||||
|
kwant.plot(syst) # 画出syst的示意图
|
||||||
|
|
||||||
|
syst_finalized = syst.finalized()
|
||||||
|
hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量
|
||||||
|
print('\nhamiltonian_2(初始化):\n', hamiltonian)
|
||||||
|
|
||||||
|
syst[lat.neighbors()] = 1 # 添加最近邻跃迁
|
||||||
|
|
||||||
|
kwant.plot(syst) # 画出syst的示意图
|
||||||
|
|
||||||
|
syst_finalized = syst.finalized()
|
||||||
|
hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量
|
||||||
|
print('\nhamiltonian_3(最近邻赋值):\n', hamiltonian)
|
||||||
|
|
||||||
|
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0))) # 定义电极的Builder
|
||||||
|
lead[(lat(0, j) for j in range(W))] = 0 # 电极晶格初始化
|
||||||
|
lead[lat.neighbors()] = 1 # 添加最近邻跃迁
|
||||||
|
syst.attach_lead(lead) # 中心区加上左电极
|
||||||
|
syst.attach_lead(lead.reversed()) # 用reversed()方法得到右电极
|
||||||
|
|
||||||
|
# 画出syst的示意图
|
||||||
|
kwant.plot(syst)
|
||||||
|
|
||||||
|
# 查看哈密顿量(加了电极后,并不影响syst哈密顿量)
|
||||||
|
syst_finalized = syst.finalized()
|
||||||
|
hamiltonian = syst_finalized.hamiltonian_submatrix()
|
||||||
|
print('\nhamiltonian_4(加了电极后):\n', hamiltonian)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,94 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/2033
|
||||||
|
"""
|
||||||
|
|
||||||
|
import kwant
|
||||||
|
import numpy as np
|
||||||
|
from matplotlib import pyplot
|
||||||
|
|
||||||
|
|
||||||
|
def make_system():
|
||||||
|
a = 1 # 晶格常数
|
||||||
|
lat = kwant.lattice.square(a) # 创建晶格,方格子
|
||||||
|
|
||||||
|
syst = kwant.Builder() # 建立中心体系
|
||||||
|
t = 1.0 # hopping值
|
||||||
|
W = 5 # 中心体系宽度
|
||||||
|
L = 40 # 中心体系长度
|
||||||
|
|
||||||
|
# 给中心体系赋值
|
||||||
|
for i in range(L):
|
||||||
|
for j in range(W):
|
||||||
|
syst[lat(i, j)] = 0
|
||||||
|
if j > 0:
|
||||||
|
syst[lat(i, j), lat(i, j-1)] = -t # hopping in y-direction
|
||||||
|
if i > 0:
|
||||||
|
syst[lat(i, j), lat(i-1, j)] = -t # hopping in x-direction
|
||||||
|
|
||||||
|
sym_left_lead = kwant.TranslationalSymmetry((-a, 0)) # 电极的平移对称性,(-a, 0)代表远离中心区的方向,向左
|
||||||
|
left_lead = kwant.Builder(sym_left_lead) # 建立左电极体系
|
||||||
|
# 给电极体系赋值
|
||||||
|
for j in range(W):
|
||||||
|
left_lead[lat(0, j)] = 0
|
||||||
|
if j > 0:
|
||||||
|
left_lead[lat(0, j), lat(0, j - 1)] = -t
|
||||||
|
left_lead[lat(1, j), lat(0, j)] = -t # 这里写一个即可,因为平移对称性已经声明了
|
||||||
|
syst.attach_lead(left_lead) # 把左电极接在中心区
|
||||||
|
|
||||||
|
sym_right_lead = kwant.TranslationalSymmetry((a, 0))
|
||||||
|
right_lead = kwant.Builder(sym_right_lead)
|
||||||
|
for j in range(W):
|
||||||
|
right_lead[lat(0, j)] = 0
|
||||||
|
if j > 0:
|
||||||
|
right_lead[lat(0, j), lat(0, j - 1)] = -t
|
||||||
|
right_lead[lat(1, j), lat(0, j)] = -t
|
||||||
|
syst.attach_lead(right_lead) # 把右电极接在中心区
|
||||||
|
|
||||||
|
kwant.plot(syst) # 把电极-中心区-电极图画出来,通过图像可以看出有没有写错
|
||||||
|
syst = syst.finalized() # 结束体系的制作。这个语句不可以省。这个语句是把Builder对象转换成可计算的对象。
|
||||||
|
return syst
|
||||||
|
|
||||||
|
|
||||||
|
def make_system_with_less_code():
|
||||||
|
a = 1 # 晶格常数
|
||||||
|
lat = kwant.lattice.square(a) # 创建晶格,方格子
|
||||||
|
|
||||||
|
syst = kwant.Builder() # 建立中心体系
|
||||||
|
t = 1.0 # hopping值
|
||||||
|
W = 5 # 中心体系宽度
|
||||||
|
L = 40 # 中心体系长度
|
||||||
|
|
||||||
|
# 中心区
|
||||||
|
syst[(lat(x, y) for x in range(L) for y in range(W))] = 0
|
||||||
|
syst[lat.neighbors()] = -t # 用neighbors()方法
|
||||||
|
|
||||||
|
# 电极
|
||||||
|
lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0)))
|
||||||
|
lead[(lat(0, j) for j in range(W))] = 0
|
||||||
|
lead[lat.neighbors()] = -t # 用neighbors()方法
|
||||||
|
syst.attach_lead(lead) # 左电极
|
||||||
|
syst.attach_lead(lead.reversed()) # 用reversed()方法得到右电极
|
||||||
|
|
||||||
|
kwant.plot(syst) # 把电极-中心区-电极图画出来,通过图像可以看出有没有写错
|
||||||
|
syst = syst.finalized() # 结束体系的制作。这个语句不可以省。这个语句是把Builder对象转换成可计算的对象。
|
||||||
|
return syst
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
syst = make_system()
|
||||||
|
# syst = make_system_with_less_code() # 和上面的一样,只是用更少的代码写
|
||||||
|
energies = np.linspace(-4, 4, 200)
|
||||||
|
data = []
|
||||||
|
for energy in energies:
|
||||||
|
smatrix = kwant.smatrix(syst, energy) # compute the transmission probability from lead 0 to lead 1
|
||||||
|
data.append(smatrix.transmission(1, 0))
|
||||||
|
pyplot.plot(energies, data)
|
||||||
|
pyplot.xlabel("energy [t]")
|
||||||
|
pyplot.ylabel("conductance [e^2/h]")
|
||||||
|
pyplot.show()
|
||||||
|
# pyplot.savefig('conductance' + '.eps')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,84 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/2327
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import * # 引入sqrt(), pi, exp等
|
||||||
|
import cmath # 要处理复数情况,用到cmath.exp()
|
||||||
|
import functools # 使用偏函数functools.partial()
|
||||||
|
|
||||||
|
|
||||||
|
def get_terms(A, B, C, D, M, a):
|
||||||
|
E_s = C+M-4*(D+B)/(a**2)
|
||||||
|
E_p = C-M-4*(D-B)/(a**2)
|
||||||
|
V_ss = (D+B)/(a**2)
|
||||||
|
V_pp = (D-B)/(a**2)
|
||||||
|
V_sp = -1j*A/(2*a)
|
||||||
|
H0 = np.zeros((4, 4))*(1+0j) # 在位能 (on-site energy)
|
||||||
|
H1 = np.zeros((4, 4))*(1+0j) # x方向的跃迁 (hopping)
|
||||||
|
H2 = np.zeros((4, 4))*(1+0j) # y方向的跃迁 (hopping)
|
||||||
|
H0[0, 0] = E_s
|
||||||
|
H0[1, 1] = E_p
|
||||||
|
H0[2, 2] = E_s
|
||||||
|
H0[3, 3] = E_p
|
||||||
|
|
||||||
|
H1[0, 0] = V_ss
|
||||||
|
H1[1, 1] = V_pp
|
||||||
|
H1[2, 2] = V_ss
|
||||||
|
H1[3, 3] = V_pp
|
||||||
|
H1[0, 1] = V_sp
|
||||||
|
H1[1, 0] = -np.conj(V_sp)
|
||||||
|
H1[2, 3] = np.conj(V_sp)
|
||||||
|
H1[3, 2] = -V_sp
|
||||||
|
|
||||||
|
H2[0, 0] = V_ss
|
||||||
|
H2[1, 1] = V_pp
|
||||||
|
H2[2, 2] = V_ss
|
||||||
|
H2[3, 3] = V_pp
|
||||||
|
H2[0, 1] = 1j*V_sp
|
||||||
|
H2[1, 0] = 1j*np.conj(V_sp)
|
||||||
|
H2[2, 3] = -1j*np.conj(V_sp)
|
||||||
|
H2[3, 2] = -1j*V_sp
|
||||||
|
return H0, H1, H2
|
||||||
|
|
||||||
|
|
||||||
|
def BHZ_model(k, A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01, a=1, N=100): # 这边数值是不赋值时的默认参数
|
||||||
|
H0, H1, H2 = get_terms(A, B, C, D, M, a)
|
||||||
|
H00 = np.zeros((4*N, 4*N))*(1+0j) # 元胞内,条带宽度为N
|
||||||
|
H01 = np.zeros((4*N, 4*N))*(1+0j) # 条带方向元胞间的跃迁
|
||||||
|
for i in range(N):
|
||||||
|
H00[i*4+0:i*4+4, i*4+0:i*4+4] = H0 # a:b代表 a <= x < b
|
||||||
|
H01[i*4+0:i*4+4, i*4+0:i*4+4] = H1
|
||||||
|
for i in range(N-1):
|
||||||
|
H00[i*4+0:i*4+4, (i+1)*4+0:(i+1)*4+4] = H2
|
||||||
|
H00[(i+1)*4+0:(i+1)*4+4, i*4+0:i*4+4] = np.conj(np.transpose(H2))
|
||||||
|
H = H00 + H01 * cmath.exp(-1j * k) + H01.transpose().conj() * cmath.exp(1j * k)
|
||||||
|
return H
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
hamiltonian0 = functools.partial(BHZ_model, N=50) # 使用偏函数,固定一些参数
|
||||||
|
k = np.linspace(-pi, pi, 300) # 300
|
||||||
|
plot_bands_one_dimension(k, hamiltonian0)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_one_dimension(k, hamiltonian, filename='bands_1D'):
|
||||||
|
dim = hamiltonian(0).shape[0]
|
||||||
|
dim_k = k.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim_k, dim)) # np.zeros()里要用tuple
|
||||||
|
i0 = 0
|
||||||
|
for k0 in k:
|
||||||
|
matrix0 = hamiltonian(k0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
i0 += 1
|
||||||
|
for dim0 in range(dim):
|
||||||
|
plt.plot(k, eigenvalue_k[:, dim0], '-k') # -.
|
||||||
|
# plt.savefig(filename + '.jpg') # plt.savefig(filename+'.eps')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,33 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/1247
|
||||||
|
"""
|
||||||
|
|
||||||
|
import random
|
||||||
|
import math
|
||||||
|
import numpy as np
|
||||||
|
from scipy.stats import norm
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
|
def function(x): # 期望样品的分布,target distribution function
|
||||||
|
y = (norm.pdf(x, loc=2, scale=1)+norm.pdf(x, loc=-5, scale=1.5))/2 # loc代表了均值,scale代表标准差
|
||||||
|
return y
|
||||||
|
|
||||||
|
|
||||||
|
T = 100000 # 取T个样品
|
||||||
|
pi = [0 for i in range(T)] # 任意选定一个马尔科夫链初始状态
|
||||||
|
for t in np.arange(1, T):
|
||||||
|
pi_star = np.random.uniform(-10, 10) # a proposed distribution, 例如是均匀分布的,或者是一个依赖pi[t - 1]的分布
|
||||||
|
alpha = min(1, (function(pi_star) / function(pi[t - 1]))) # 接收率
|
||||||
|
u = random.uniform(0, 1)
|
||||||
|
if u < alpha:
|
||||||
|
pi[t] = pi_star # 以alpha的概率接收转移
|
||||||
|
else:
|
||||||
|
pi[t] = pi[t - 1] # 不接收转移
|
||||||
|
|
||||||
|
pi = np.array(pi) # 转成numpy格式
|
||||||
|
print(pi.shape) # 查看抽样样品的维度
|
||||||
|
plt.plot(pi, function(pi), '*') # 画出抽样样品期望的分布 # 或用plt.scatter(pi, function(pi))
|
||||||
|
plt.hist(pi, bins=100, density=1, facecolor='red', alpha=0.7) # 画出抽样样品的分布 # bins是分布柱子的个数,density是归一化,后面两个参数是管颜色的
|
||||||
|
plt.show()
|
@@ -0,0 +1,18 @@
|
|||||||
|
% This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
% The newest version of this code is on the web page: https://www.guanjihuan.com/archives/1247
|
||||||
|
|
||||||
|
clc;clear all;clf;
|
||||||
|
s=100000; % 取的样品数
|
||||||
|
f=[1,2,3,3,3,3,6,5,4,3,2,1]; % 期望得到样品的分布函数
|
||||||
|
d=zeros(1,s); % 初始状态
|
||||||
|
x=1;
|
||||||
|
for i=1:s
|
||||||
|
y=unidrnd(12); % 1到12随机整数
|
||||||
|
alpha=min(1,f(y)/f(x)); % 接收率
|
||||||
|
u=rand;
|
||||||
|
if u<alpha % 以alpha的概率接收转移
|
||||||
|
x=y;
|
||||||
|
end
|
||||||
|
d(i)=x;
|
||||||
|
end
|
||||||
|
hist(d,1:1:12);
|
@@ -0,0 +1,97 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/1249
|
||||||
|
"""
|
||||||
|
|
||||||
|
import random
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
import copy
|
||||||
|
import math
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
size = 30 # 体系大小
|
||||||
|
T = 2 # 温度
|
||||||
|
ising = get_one_sample(sizeOfSample=size, temperature=T) # 得到符合玻尔兹曼分布的ising模型
|
||||||
|
plot(ising) # 画图
|
||||||
|
energy_s = []
|
||||||
|
for i in range(size):
|
||||||
|
for j in range(size):
|
||||||
|
energy_s0 = getEnergy(i=i, j=j, S=ising) # 获取格点的能量
|
||||||
|
energy_s = np.append(energy_s, [energy_s0], axis=0)
|
||||||
|
plt.hist(energy_s, bins=50, density=1, facecolor='red', alpha=0.7) # 画出格点能量分布 # bins是分布柱子的个数,density是归一化,后面两个参数是管颜色的
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
def get_one_sample(sizeOfSample, temperature):
|
||||||
|
S = 2 * np.pi * np.random.random(size=(sizeOfSample, sizeOfSample)) # 随机初始状态,角度是0到2pi
|
||||||
|
print('体系大小:', S.shape)
|
||||||
|
initialEnergy = calculateAllEnergy(S) # 计算随机初始状态的能量
|
||||||
|
print('系统的初始能量是:', initialEnergy)
|
||||||
|
newS = np.array(copy.deepcopy(S))
|
||||||
|
for i00 in range(1000): # 循环一定次数,得到平衡的抽样分布
|
||||||
|
newS = Metropolis(newS, temperature) # Metropolis方法抽样,得到玻尔兹曼分布的样品体系
|
||||||
|
newEnergy = calculateAllEnergy(newS)
|
||||||
|
if np.mod(i00, 100) == 0:
|
||||||
|
print('循环次数%i, 当前系统能量是:' % (i00+1), newEnergy)
|
||||||
|
print('循环次数%i, 当前系统能量是:' % (i00 + 1), newEnergy)
|
||||||
|
return newS
|
||||||
|
|
||||||
|
|
||||||
|
def Metropolis(S, T): # S是输入的初始状态, T是温度
|
||||||
|
delta_max = 0.5 * np.pi # 角度最大的变化度数,默认是90度,也可以调整为其他
|
||||||
|
k = 1 # 玻尔兹曼常数
|
||||||
|
for i in range(S.shape[0]):
|
||||||
|
for j in range(S.shape[0]):
|
||||||
|
delta = (2 * np.random.random() - 1) * delta_max # 角度变化在-90度到90度之间
|
||||||
|
newAngle = S[i, j] + delta # 新角度
|
||||||
|
energyBefore = getEnergy(i=i, j=j, S=S, angle=None) # 获取该格点的能量
|
||||||
|
energyLater = getEnergy(i=i, j=j, S=S, angle=newAngle) # 获取格点变成新角度时的能量
|
||||||
|
alpha = min(1.0, math.exp(-(energyLater - energyBefore)/(k * T))) # 这个接受率对应的是玻尔兹曼分布
|
||||||
|
if random.uniform(0, 1) <= alpha:
|
||||||
|
S[i, j] = newAngle # 接受新状态
|
||||||
|
else:
|
||||||
|
pass # 保持为上一个状态
|
||||||
|
return S
|
||||||
|
|
||||||
|
|
||||||
|
def getEnergy(i, j, S, angle=None): # 计算(i,j)位置的能量,为周围四个的相互能之和
|
||||||
|
width = S.shape[0]
|
||||||
|
height = S.shape[1]
|
||||||
|
top_i = i - 1 if i > 0 else width - 1 # 用到周期性边界条件
|
||||||
|
bottom_i = i + 1 if i < (width - 1) else 0
|
||||||
|
left_j = j - 1 if j > 0 else height - 1
|
||||||
|
right_j = j + 1 if j < (height - 1) else 0
|
||||||
|
environment = [[top_i, j], [bottom_i, j], [i, left_j], [i, right_j]]
|
||||||
|
energy = 0
|
||||||
|
if angle == None:
|
||||||
|
for num_i in range(4):
|
||||||
|
energy += -np.cos(S[i, j] - S[environment[num_i][0], environment[num_i][1]])
|
||||||
|
else:
|
||||||
|
for num_i in range(4):
|
||||||
|
energy += -np.cos(angle - S[environment[num_i][0], environment[num_i][1]])
|
||||||
|
return energy
|
||||||
|
|
||||||
|
|
||||||
|
def calculateAllEnergy(S): # 计算整个体系的能量
|
||||||
|
energy = 0
|
||||||
|
for i in range(S.shape[0]):
|
||||||
|
for j in range(S.shape[1]):
|
||||||
|
energy += getEnergy(i, j, S)
|
||||||
|
return energy/2 # 作用两次要减半
|
||||||
|
|
||||||
|
|
||||||
|
def plot(S): # 画图
|
||||||
|
X, Y = np.meshgrid(np.arange(0, S.shape[0]), np.arange(0, S.shape[0]))
|
||||||
|
U = np.cos(S)
|
||||||
|
V = np.sin(S)
|
||||||
|
plt.figure()
|
||||||
|
plt.quiver(X, Y, U, V, units='inches')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
@@ -0,0 +1,76 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/1249
|
||||||
|
"""
|
||||||
|
|
||||||
|
import random
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
import copy
|
||||||
|
import math
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
size = 30 # 体系大小
|
||||||
|
for T in np.linspace(0.02, 5, 100):
|
||||||
|
ising, magnetism = get_one_sample(sizeOfSample=size, temperature=T)
|
||||||
|
print('温度=', T, ' 磁矩=', magnetism, ' 总能量=', calculateAllEnergy(ising))
|
||||||
|
plt.plot(T, magnetism, 'o')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
def get_one_sample(sizeOfSample, temperature):
|
||||||
|
newS = np.zeros((sizeOfSample, sizeOfSample)) # 初始状态
|
||||||
|
magnetism = 0
|
||||||
|
for i00 in range(100):
|
||||||
|
newS = Metropolis(newS, temperature)
|
||||||
|
magnetism = magnetism + abs(sum(sum(np.cos(newS))))/newS.shape[0]**2
|
||||||
|
magnetism = magnetism/100
|
||||||
|
return newS, magnetism
|
||||||
|
|
||||||
|
|
||||||
|
def Metropolis(S, T): # S是输入的初始状态, T是温度
|
||||||
|
k = 1 # 玻尔兹曼常数
|
||||||
|
for i in range(S.shape[0]):
|
||||||
|
for j in range(S.shape[0]):
|
||||||
|
newAngle = np.random.randint(-1, 1)*np.pi
|
||||||
|
energyBefore = getEnergy(i=i, j=j, S=S, angle=None) # 获取该格点的能量
|
||||||
|
energyLater = getEnergy(i=i, j=j, S=S, angle=newAngle) # 获取格点变成新角度时的能量
|
||||||
|
alpha = min(1.0, math.exp(-(energyLater - energyBefore)/(k * T))) # 这个接受率对应的是玻尔兹曼分布
|
||||||
|
if random.uniform(0, 1) <= alpha:
|
||||||
|
S[i, j] = newAngle # 接受新状态
|
||||||
|
else:
|
||||||
|
pass # 保持为上一个状态
|
||||||
|
return S
|
||||||
|
|
||||||
|
|
||||||
|
def getEnergy(i, j, S, angle=None): # 计算(i,j)位置的能量,为周围四个的相互能之和
|
||||||
|
width = S.shape[0]
|
||||||
|
height = S.shape[1]
|
||||||
|
top_i = i - 1 if i > 0 else width - 1 # 用到周期性边界条件
|
||||||
|
bottom_i = i + 1 if i < (width - 1) else 0
|
||||||
|
left_j = j - 1 if j > 0 else height - 1
|
||||||
|
right_j = j + 1 if j < (height - 1) else 0
|
||||||
|
environment = [[top_i, j], [bottom_i, j], [i, left_j], [i, right_j]]
|
||||||
|
energy = 0
|
||||||
|
if angle == None:
|
||||||
|
for num_i in range(4):
|
||||||
|
energy += -np.cos(S[i, j] - S[environment[num_i][0], environment[num_i][1]])
|
||||||
|
else:
|
||||||
|
for num_i in range(4):
|
||||||
|
energy += -np.cos(angle - S[environment[num_i][0], environment[num_i][1]])
|
||||||
|
return energy
|
||||||
|
|
||||||
|
|
||||||
|
def calculateAllEnergy(S): # 计算整个体系的能量
|
||||||
|
energy = 0
|
||||||
|
for i in range(S.shape[0]):
|
||||||
|
for j in range(S.shape[1]):
|
||||||
|
energy += getEnergy(i, j, S)
|
||||||
|
return energy/2 # 作用两次要减半
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
11
academic_codes/2019.12.03_create_GIF_with_python/create_GIF_with_python.py
Executable file
11
academic_codes/2019.12.03_create_GIF_with_python/create_GIF_with_python.py
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
import imageio
|
||||||
|
import numpy as np
|
||||||
|
import os
|
||||||
|
os.chdir('D:/data') # 设置文件读取和保存位置
|
||||||
|
|
||||||
|
images = []
|
||||||
|
for i in range(1000):
|
||||||
|
image = str(i)+'.jpg'
|
||||||
|
im = imageio.imread(image)
|
||||||
|
images.append(im)
|
||||||
|
imageio.mimsave("a.gif", images, 'GIF', duration=0.1) # durantion是延迟时间
|
@@ -0,0 +1,160 @@
|
|||||||
|
! This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
! The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3785
|
||||||
|
|
||||||
|
module global
|
||||||
|
implicit none
|
||||||
|
double precision sqrt3,Pi
|
||||||
|
parameter(sqrt3=1.7320508075688773d0,Pi=3.14159265358979324d0)
|
||||||
|
end module global
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
program QPI !QPI主程序
|
||||||
|
use blas95
|
||||||
|
use lapack95,only:GETRF,GETRI
|
||||||
|
use global
|
||||||
|
implicit none
|
||||||
|
integer i,j,info,index_0(4)
|
||||||
|
double precision omega,kx,ky,Eigenvalues(4),eta,V0,kx1,kx2,ky1,ky2,qx,qy,time_begin,time_end
|
||||||
|
parameter(eta=0.005)
|
||||||
|
complex*16 H0(4,4),green_0(4,4),green_1(4,4),green_0_k1(4,4),green_0_k2(4,4),A_spectral,V(4,4),gamma_0(4,4),Temp_0(4,4),T(4,4),g_1,rho_1
|
||||||
|
character(len=*):: Flname
|
||||||
|
parameter(Flname='') !可以写上输出文件路径,也可以不写,输出存在当前文件的路径
|
||||||
|
|
||||||
|
omega=0.070d0
|
||||||
|
open(unit=10,file=Flname//'Spectral function_w=0.07.txt')
|
||||||
|
open(unit=20,file=Flname//'QPI_intra_nonmag_w=0.07.txt')
|
||||||
|
call CPU_TIME(time_begin)
|
||||||
|
|
||||||
|
!计算谱函数A(kx,ky)
|
||||||
|
write(10,"(f20.10,x)",advance='no') 0
|
||||||
|
do ky=-Pi,Pi,0.01d0 !谱函数图案的精度
|
||||||
|
write(10,"(f20.10,x)",advance='no') ky
|
||||||
|
enddo
|
||||||
|
write(10,"(a)",advance='yes') ' '
|
||||||
|
do kx=-Pi,Pi,0.01d0 !谱函数图案的精度
|
||||||
|
write(10,"(f20.10,x)",advance='no') kx
|
||||||
|
do ky=-Pi,Pi,0.01d0 !谱函数图案的精度
|
||||||
|
call Greenfunction_clean(kx,ky,eta,omega,green_0)
|
||||||
|
A_spectral=-(green_0(1,1)+green_0(3,3))/Pi
|
||||||
|
write(10,"(f20.10)",advance='no') imag(A_spectral)
|
||||||
|
enddo
|
||||||
|
write(10,"(a)",advance='yes') ' '
|
||||||
|
enddo
|
||||||
|
|
||||||
|
!计算QPI(qx,qy)
|
||||||
|
V0=0.4d0
|
||||||
|
V=0.d0
|
||||||
|
V(1,1)=V0
|
||||||
|
V(2,2)=-V0
|
||||||
|
V(3,3)=V0
|
||||||
|
V(4,4)=-V0
|
||||||
|
gamma_0=0.d0
|
||||||
|
do kx=-Pi,Pi,0.01
|
||||||
|
do ky=-Pi,Pi,0.01
|
||||||
|
call Greenfunction_clean(kx,ky,eta,omega,green_0)
|
||||||
|
do i=1,4
|
||||||
|
do j=1,4
|
||||||
|
gamma_0(i,j)=gamma_0(i,j)+green_0(i,j)*0.01*0.01
|
||||||
|
enddo
|
||||||
|
enddo
|
||||||
|
enddo
|
||||||
|
enddo
|
||||||
|
gamma_0=gamma_0/(2*Pi)/(2*Pi)
|
||||||
|
call gemm(V,gamma_0,Temp_0)
|
||||||
|
do i=1,4
|
||||||
|
Temp_0(i,i)=1-Temp_0(i,i)
|
||||||
|
enddo
|
||||||
|
call GETRF( Temp_0,index_0,info ); call GETRI( Temp_0,index_0,info) !求逆
|
||||||
|
call gemm(Temp_0,V,T) !矩阵乘积
|
||||||
|
write(20,"(f20.10,x)",advance='no') 0
|
||||||
|
do qy=-Pi,Pi,0.01 !QPI图案的精度
|
||||||
|
write(20,"(f20.10,x)",advance='no') qy
|
||||||
|
enddo
|
||||||
|
write(20,"(a)",advance='yes') ' '
|
||||||
|
do qx=-Pi,Pi,0.01 !QPI图案的精度
|
||||||
|
write(*,"(a)",advance='no') 'qx='
|
||||||
|
write(*,*) qx !屏幕输出可以实时查看计算进度
|
||||||
|
write(20,"(f20.10)",advance='no') qx
|
||||||
|
do qy=-Pi,Pi,0.01 !QPI图案的精度
|
||||||
|
rho_1=0.d0
|
||||||
|
do kx1=-Pi,Pi,0.06 !积分的精度
|
||||||
|
kx2=kx1+qx
|
||||||
|
do ky1=-Pi,Pi,0.06 !积分的精度
|
||||||
|
ky2=ky1+qy
|
||||||
|
call Greenfunction_clean(kx1,ky1,eta,omega,green_0_k1)
|
||||||
|
call Greenfunction_clean(kx2,ky2,eta,omega,green_0_k2)
|
||||||
|
call gemm(green_0_k1,T,Temp_0)
|
||||||
|
call gemm(Temp_0, green_0_k2, green_1)
|
||||||
|
g_1=green_1(1,1)-dconjg(green_1(1,1))+green_1(3,3)-dconjg(green_1(3,3))
|
||||||
|
rho_1=rho_1+g_1*0.06*0.06
|
||||||
|
enddo
|
||||||
|
enddo
|
||||||
|
rho_1=rho_1/(2*Pi)/(2*Pi)/(2*Pi)*(0.d0,1.d0)
|
||||||
|
write(20,"(f20.10,x,f20.10)",advance='no') real(rho_1)
|
||||||
|
enddo
|
||||||
|
write(20,"(a)",advance='yes') ' '
|
||||||
|
enddo
|
||||||
|
|
||||||
|
call CPU_TIME(time_end)
|
||||||
|
write(*,"(a)",advance='no') 'The running time of this task='
|
||||||
|
write (*,*) time_end-time_begin !屏幕输出总的计算时间,单位为秒(按照当前步长的精度,在个人计算机上运算大概需要4个小时)
|
||||||
|
end program
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
subroutine Greenfunction_clean(kx,ky,eta,omega,green_0) !干净体系的格林函数
|
||||||
|
use blas95
|
||||||
|
use lapack95,only:GETRF,GETRI
|
||||||
|
use global
|
||||||
|
integer info,index_0(4)
|
||||||
|
double precision, intent(in):: kx,ky,eta,omega
|
||||||
|
complex*16 H0(4,4)
|
||||||
|
complex*16,intent(out):: green_0(4,4)
|
||||||
|
call Hamiltonian(kx,ky,H0)
|
||||||
|
green_0=H0
|
||||||
|
do i=1,4
|
||||||
|
green_0(i,i)=omega+(0.d0,1.d0)*eta-green_0(i,i)
|
||||||
|
enddo
|
||||||
|
call GETRF( green_0,index_0,info ); call GETRI( green_0,index_0,info );
|
||||||
|
end subroutine Greenfunction_clean
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
subroutine Hamiltonian(kx,ky,Matrix) !哈密顿量
|
||||||
|
use global
|
||||||
|
implicit none
|
||||||
|
integer i,j
|
||||||
|
double precision t1,t2,t3,t4,mu,epsilon_x,epsilon_y,epsilon_xy,delta_1,delta_2,delta_0
|
||||||
|
double precision, intent(in):: kx,ky
|
||||||
|
complex*16,intent(out):: Matrix(4,4)
|
||||||
|
|
||||||
|
t1=-1;t2=1.3;t3=-0.85;t4=-0.85;delta_0=0.1;mu=1.54
|
||||||
|
Matrix=(0.d0,0.d0)
|
||||||
|
|
||||||
|
epsilon_x=-2*t1*dcos(kx)-2*t2*dcos(ky)-4*t3*dcos(kx)*dcos(ky)
|
||||||
|
epsilon_y=-2*t1*dcos(ky)-2*t2*dcos(kx)-4*t3*dcos(kx)*dcos(ky)
|
||||||
|
epsilon_xy=-4*t4*dsin(kx)*dsin(ky)
|
||||||
|
delta_1=delta_0*dcos(kx)*dcos(ky)
|
||||||
|
delta_2=delta_1
|
||||||
|
|
||||||
|
Matrix(1,1)=epsilon_x-mu
|
||||||
|
Matrix(2,2)=-epsilon_x+mu
|
||||||
|
Matrix(3,3)=epsilon_y-mu
|
||||||
|
Matrix(4,4)=-epsilon_y+mu
|
||||||
|
|
||||||
|
Matrix(1,2)=delta_1
|
||||||
|
Matrix(2,1)=delta_1
|
||||||
|
Matrix(1,3)=epsilon_xy
|
||||||
|
Matrix(3,1)=epsilon_xy
|
||||||
|
Matrix(1,4)=0.d0
|
||||||
|
Matrix(4,1)=0.d0
|
||||||
|
|
||||||
|
Matrix(2,3)=0.d0
|
||||||
|
Matrix(3,2)=0.d0
|
||||||
|
Matrix(2,4)=-epsilon_xy
|
||||||
|
Matrix(4,2)=-epsilon_xy
|
||||||
|
|
||||||
|
Matrix(3,4)=delta_2
|
||||||
|
Matrix(4,3)=delta_2
|
||||||
|
end subroutine Hamiltonian
|
@@ -0,0 +1,158 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3785
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from matplotlib.colors import ListedColormap
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def green_function(fermi_energy, k1, k2, hamiltonian): # 计算格林函数
|
||||||
|
matrix0 = hamiltonian(k1, k2)
|
||||||
|
dim = matrix0.shape[0]
|
||||||
|
green = np.linalg.inv(fermi_energy * np.identity(dim) - matrix0)
|
||||||
|
return green
|
||||||
|
|
||||||
|
|
||||||
|
def spectral_function(fermi_energy, k1, k2, hamiltonian): # 计算谱函数
|
||||||
|
dim1 = k1.shape[0]
|
||||||
|
dim2 = k2.shape[0]
|
||||||
|
spectrum = np.zeros((dim1, dim2))
|
||||||
|
i0 = 0
|
||||||
|
for k10 in k1:
|
||||||
|
j0 = 0
|
||||||
|
for k20 in k2:
|
||||||
|
green = green_function(fermi_energy, k10, k20, hamiltonian)
|
||||||
|
spectrum[i0, j0] = (np.imag(green[0,0])+np.imag(green[2,2]))/(-pi)
|
||||||
|
j0 += 1
|
||||||
|
i0 += 1
|
||||||
|
# print(spectrum)
|
||||||
|
print()
|
||||||
|
print('Spectral function显示的网格点 =', k1.shape[0], '*', k1.shape[0], '; 步长 =', k1[1] - k1[0])
|
||||||
|
print()
|
||||||
|
return spectrum
|
||||||
|
|
||||||
|
|
||||||
|
def qpi(fermi_energy, q1, q2, hamiltonian, potential_i): # 计算QPI
|
||||||
|
dim = hamiltonian(0, 0).shape[0]
|
||||||
|
ki1 = np.arange(-pi, pi, 0.01) # 计算gamma_0时,k的积分密度
|
||||||
|
ki2 = np.arange(-pi, pi, 0.01)
|
||||||
|
print('gamma_0的积分网格点 =', ki1.shape[0], '*', ki1.shape[0], '; 步长 =', ki1[1] - ki1[0])
|
||||||
|
gamma_0 = integral_of_green(fermi_energy, ki1, ki2, hamiltonian)/np.square(2*pi)
|
||||||
|
t_matrix = np.dot(np.linalg.inv(np.identity(dim)-np.dot(potential_i, gamma_0)), potential_i)
|
||||||
|
ki1 = np.arange(-pi, pi, 0.06) # 计算induced_local_density时,k的积分密度
|
||||||
|
ki2 = np.arange(-pi, pi, 0.06)
|
||||||
|
print('局域态密度变化的积分网格点 =', ki1.shape[0], '*', ki1.shape[0], '; 步长 =', ki1[1] - ki1[0])
|
||||||
|
print('QPI显示的网格点 =', q1.shape[0], '*', q1.shape[0], '; 步长 =', q1[1] - q1[0])
|
||||||
|
step_length = ki1[1] - ki1[0]
|
||||||
|
induced_local_density = np.zeros((q1.shape[0], q2.shape[0]))*(1+0j)
|
||||||
|
print()
|
||||||
|
i0 = 0
|
||||||
|
for q10 in q1:
|
||||||
|
print('i0=', i0)
|
||||||
|
j0 = 0
|
||||||
|
for q20 in q2:
|
||||||
|
for ki10 in ki1:
|
||||||
|
for ki20 in ki2:
|
||||||
|
green_01 = green_function(fermi_energy, ki10, ki20, hamiltonian)
|
||||||
|
green_02 = green_function(fermi_energy, ki10+q10, ki20+q20, hamiltonian)
|
||||||
|
induced_green = np.dot(np.dot(green_01, t_matrix), green_02)
|
||||||
|
temp = induced_green[0, 0]-induced_green[0, 0].conj()+induced_green[2, 2]-induced_green[2, 2].conj()
|
||||||
|
induced_local_density[i0, j0] = induced_local_density[i0, j0]+temp*np.square(step_length)
|
||||||
|
j0 += 1
|
||||||
|
i0 += 1
|
||||||
|
write_matrix_k1_k2(q1, q2, np.real(induced_local_density*1j/np.square(2*pi)/(2*pi)), 'QPI') # 数据写入文件(临时写入,会被多次替代)
|
||||||
|
induced_local_density = np.real(induced_local_density*1j/np.square(2*pi)/(2*pi))
|
||||||
|
return induced_local_density
|
||||||
|
|
||||||
|
|
||||||
|
def integral_of_green(fermi_energy, ki1, ki2, hamiltonian): # 在计算QPI时需要对格林函数积分
|
||||||
|
dim = hamiltonian(0, 0).shape[0]
|
||||||
|
integral_value = np.zeros((dim, dim))*(1+0j)
|
||||||
|
step_length = ki1[1]-ki1[0]
|
||||||
|
for ki10 in ki1:
|
||||||
|
for ki20 in ki2:
|
||||||
|
green = green_function(fermi_energy, ki10, ki20, hamiltonian)
|
||||||
|
integral_value = integral_value+green*np.square(step_length)
|
||||||
|
return integral_value
|
||||||
|
|
||||||
|
|
||||||
|
def write_matrix_k1_k2(x1, x2, value, filename='matrix_k1_k2'): # 把矩阵数据写入文件(格式化输出)
|
||||||
|
with open(filename+'.txt', 'w') as f:
|
||||||
|
np.set_printoptions(suppress=True) # 取消输出科学记数法
|
||||||
|
f.write('0 ')
|
||||||
|
for x10 in x1:
|
||||||
|
f.write(str(x10)+' ')
|
||||||
|
f.write('\n')
|
||||||
|
i0 = 0
|
||||||
|
for x20 in x2:
|
||||||
|
f.write(str(x20))
|
||||||
|
for j0 in range(x1.shape[0]):
|
||||||
|
f.write(' '+str(value[i0, j0])+' ')
|
||||||
|
f.write('\n')
|
||||||
|
i0 += 1
|
||||||
|
|
||||||
|
|
||||||
|
def plot_contour(x1, x2, value, filename='contour'): # 直接画出contour图像(保存图像)
|
||||||
|
plt.contourf(x1, x2, value) #, cmap=plt.cm.hot)
|
||||||
|
plt.savefig(filename+'.eps')
|
||||||
|
# plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(kx, ky): # 体系的哈密顿量
|
||||||
|
t1 = -1; t2 = 1.3; t3 = -0.85; t4 = -0.85; delta_0 = 0.1; mu = 1.54
|
||||||
|
epsilon_x = -2*t1*cos(kx)-2*t2*cos(ky)-4*t3*cos(kx)*cos(ky)
|
||||||
|
epsilon_y = -2*t1*cos(ky)-2*t2*cos(kx)-4*t3*cos(kx)*cos(ky)
|
||||||
|
epsilon_xy = -4*t4*sin(kx)*sin(ky)
|
||||||
|
delta_1 = delta_0*cos(kx)*cos(ky)
|
||||||
|
delta_2 = delta_0*cos(kx)*cos(ky)
|
||||||
|
h = np.zeros((4, 4))
|
||||||
|
h[0, 0] = epsilon_x-mu
|
||||||
|
h[1, 1] = -epsilon_x+mu
|
||||||
|
h[2, 2] = epsilon_y-mu
|
||||||
|
h[3, 3] = -epsilon_y+mu
|
||||||
|
|
||||||
|
h[0, 1] = delta_1
|
||||||
|
h[1, 0] = delta_1
|
||||||
|
h[0, 2] = epsilon_xy
|
||||||
|
h[2, 0] = epsilon_xy
|
||||||
|
h[0, 3] = 0
|
||||||
|
h[3, 0] = 0
|
||||||
|
|
||||||
|
h[1, 2] = 0
|
||||||
|
h[2, 1] = 0
|
||||||
|
h[1, 3] = -epsilon_xy
|
||||||
|
h[3, 1] = -epsilon_xy
|
||||||
|
|
||||||
|
h[2, 3] = delta_2
|
||||||
|
h[3, 2] = delta_2
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main(): # 主程序
|
||||||
|
start_clock = time.perf_counter()
|
||||||
|
fermi_energy = 0.07 # 费米能
|
||||||
|
energy_broadening_width = 0.005 # 展宽
|
||||||
|
k1 = np.arange(-pi, pi, 0.01) # 谱函数的图像精度
|
||||||
|
k2 = np.arange(-pi, pi, 0.01)
|
||||||
|
spectrum = spectral_function(fermi_energy+energy_broadening_width*1j, k1, k2, hamiltonian) # 调用谱函数子程序
|
||||||
|
write_matrix_k1_k2(k1, k2, spectrum, 'Spectral_function') # 把谱函数的数据写入文件
|
||||||
|
# plot_contour(k1, k2, spectrum, 'Spectral_function') # 直接显示谱函数的图像(保存图像)
|
||||||
|
|
||||||
|
q1 = np.arange(-pi, pi, 0.01) # QPI数的图像精度
|
||||||
|
q2 = np.arange(-pi, pi, 0.01)
|
||||||
|
potential_i = (0.4+0j)*np.identity(hamiltonian(0, 0).shape[0]) # 杂质势
|
||||||
|
potential_i[1, 1] = - potential_i[1, 1] # for nonmagnetic
|
||||||
|
potential_i[3, 3] = - potential_i[3, 3]
|
||||||
|
induced_local_density = qpi(fermi_energy+energy_broadening_width*1j, q1, q2, hamiltonian, potential_i) # 调用QPI子程序
|
||||||
|
write_matrix_k1_k2(q1, q2, induced_local_density, 'QPI') # 把QPI数据写入文件(这里用的方法是计算结束后一次性把数据写入)
|
||||||
|
# plot_contour(q1, q2, induced_local_density, 'QPI') # 直接显示QPI图像(保存图像)
|
||||||
|
end_clock = time.perf_counter()
|
||||||
|
print('CPU执行时间=', end_clock - start_clock)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,48 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3895
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import cmath
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k, N, t): # 准一维方格子哈密顿量
|
||||||
|
# 初始化为零矩阵
|
||||||
|
h00 = np.zeros((N, N), dtype=complex)
|
||||||
|
h01 = np.zeros((N, N), dtype=complex)
|
||||||
|
for i in range(N-1): # 原胞内的跃迁h00
|
||||||
|
h00[i, i+1] = t
|
||||||
|
h00[i+1, i] = t
|
||||||
|
for i in range(N): # 原胞间的跃迁h01
|
||||||
|
h01[i, i] = t
|
||||||
|
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
H_k = functools.partial(hamiltonian, N=10, t=1)
|
||||||
|
k = np.linspace(-pi, pi, 300)
|
||||||
|
plot_bands_one_dimension(k, H_k)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_one_dimension(k, hamiltonian):
|
||||||
|
dim = hamiltonian(0).shape[0]
|
||||||
|
dim_k = k.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim_k, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k0 in k:
|
||||||
|
matrix0 = hamiltonian(k0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
i0 += 1
|
||||||
|
for dim0 in range(dim):
|
||||||
|
plt.plot(k, eigenvalue_k[:, dim0], '-k')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,130 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3888
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import copy
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_00(width=10): # 电极元胞内跃迁,width不赋值时默认为10
|
||||||
|
h00 = np.zeros((width, width))
|
||||||
|
for width0 in range(width-1):
|
||||||
|
h00[width0, width0+1] = 1
|
||||||
|
h00[width0+1, width0] = 1
|
||||||
|
return h00
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_01(width=10): # 电极元胞间跃迁,width不赋值时默认为10
|
||||||
|
h01 = np.identity(width)
|
||||||
|
return h01
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_LC(width=10, length=300): # 左电极跳到中心区
|
||||||
|
h_LC = np.zeros((width, width*length))
|
||||||
|
for width0 in range(width):
|
||||||
|
h_LC[width0, width0] = 1
|
||||||
|
return h_LC
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_CR(width=10, length=300): # 中心区跳到右电极
|
||||||
|
h_CR = np.zeros((width*length, width))
|
||||||
|
for width0 in range(width):
|
||||||
|
h_CR[width*(length-1)+width0, width0] = 1
|
||||||
|
return h_CR
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_center(width=10, length=300): # 中心区哈密顿量
|
||||||
|
hamiltonian = np.zeros((width*length, width*length))
|
||||||
|
for length0 in range(length-1):
|
||||||
|
for width0 in range(width):
|
||||||
|
hamiltonian[width*length0+width0, width*(length0+1)+width0] = 1 # 长度方向跃迁
|
||||||
|
hamiltonian[width*(length0+1)+width0, width*length0+width0] = 1
|
||||||
|
for length0 in range(length):
|
||||||
|
for width0 in range(width-1):
|
||||||
|
hamiltonian[width*length0+width0, width*length0+width0+1] = 1 # 宽度方向跃迁
|
||||||
|
hamiltonian[width*length0+width0+1, width*length0+width0] = 1
|
||||||
|
# 中间加势垒
|
||||||
|
for j0 in range(6):
|
||||||
|
for i0 in range(6):
|
||||||
|
hamiltonian[width*(np.int(length/2)-3+j0)+np.int(width/2)-3+i0, width*(np.int(length/2)-3+j0)+np.int(width/2)-3+i0]= 1e8
|
||||||
|
return hamiltonian
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_time = time.time()
|
||||||
|
fermi_energy = 1
|
||||||
|
width = 60
|
||||||
|
length = 100
|
||||||
|
h00 = matrix_00(width)
|
||||||
|
h01 = matrix_01(width)
|
||||||
|
G_n = Green_n(fermi_energy+1j*1e-9, h00, h01, width, length)
|
||||||
|
# 下面是提取数据并画图
|
||||||
|
direction_x = np.zeros((width, length))
|
||||||
|
direction_y = np.zeros((width, length))
|
||||||
|
for length0 in range(length-1):
|
||||||
|
for width0 in range(width):
|
||||||
|
direction_x[width0, length0] = G_n[width*length0+width0, width*(length0+1)+width0]
|
||||||
|
for length0 in range(length):
|
||||||
|
for width0 in range(width-1):
|
||||||
|
direction_y[width0, length0] = G_n[width*length0+width0, width*length0+width0+1]
|
||||||
|
# print(direction_x)
|
||||||
|
# print(direction_y)
|
||||||
|
X, Y = np.meshgrid(range(length), range(width))
|
||||||
|
plt.quiver(X, Y, direction_x, direction_y)
|
||||||
|
plt.show()
|
||||||
|
end_time = time.time()
|
||||||
|
print('运行时间=', end_time-start_time)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵T。dim是传递矩阵h00和h01的维度
|
||||||
|
transfer = np.zeros((2*dim, 2*dim))*(0+0j) # 0+0j用来转为复数,不然下面赋值会提示忽略了虚数部分
|
||||||
|
transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00) # np.dot()等效于np.matmul()
|
||||||
|
transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj())
|
||||||
|
transfer[dim:2*dim, 0:dim] = np.identity(dim)
|
||||||
|
transfer[dim:2*dim, dim:2*dim] = 0 # a:b代表 a <= x < b
|
||||||
|
return transfer # 返回转移矩阵
|
||||||
|
|
||||||
|
|
||||||
|
def green_function_lead(fermi_energy, h00, h01, dim): # 电极的表面格林函数
|
||||||
|
transfer = transfer_matrix(fermi_energy, h00, h01, dim)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(transfer)
|
||||||
|
ind = np.argsort(np.abs(eigenvalue))
|
||||||
|
temp = np.zeros((2*dim, 2*dim))*(1+0j)
|
||||||
|
i0 = 0
|
||||||
|
for ind0 in ind:
|
||||||
|
temp[:, i0] = eigenvector[:, ind0]
|
||||||
|
i0 += 1
|
||||||
|
s1 = temp[dim:2*dim, 0:dim]
|
||||||
|
s2 = temp[0:dim, 0:dim]
|
||||||
|
s3 = temp[dim:2*dim, dim:2*dim]
|
||||||
|
s4 = temp[0:dim, dim:2*dim]
|
||||||
|
right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1)))
|
||||||
|
left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4)))
|
||||||
|
return right_lead_surface, left_lead_surface # 返回右电极的表面格林函数和左电极的表面格林函数
|
||||||
|
|
||||||
|
|
||||||
|
def self_energy_lead(fermi_energy, h00, h01, width, length): # 电极的自能
|
||||||
|
h_LC = matrix_LC(width, length)
|
||||||
|
h_CR = matrix_CR(width, length)
|
||||||
|
right_lead_surface, left_lead_surface = green_function_lead(fermi_energy, h00, h01, width)
|
||||||
|
right_self_energy = np.dot(np.dot(h_CR, right_lead_surface), h_CR.transpose().conj())
|
||||||
|
left_self_energy = np.dot(np.dot(h_LC.transpose().conj(), left_lead_surface), h_LC)
|
||||||
|
return right_self_energy, left_self_energy # 返回右电极的自能和左电极的自能
|
||||||
|
|
||||||
|
|
||||||
|
def Green_n(fermi_energy, h00, h01, width, length): # 计算G_n
|
||||||
|
right_self_energy, left_self_energy = self_energy_lead(fermi_energy, h00, h01, width, length)
|
||||||
|
hamiltonian = matrix_center(width, length)
|
||||||
|
green = np.linalg.inv(fermi_energy*np.identity(width*length)-hamiltonian-left_self_energy-right_self_energy)
|
||||||
|
right_self_energy = (right_self_energy - right_self_energy.transpose().conj())*(0+1j)
|
||||||
|
left_self_energy = (left_self_energy - left_self_energy.transpose().conj())*(0+1j)
|
||||||
|
G_n = np.imag(np.dot(np.dot(green, left_self_energy), green.transpose().conj()))
|
||||||
|
return G_n
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,50 @@
|
|||||||
|
% This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
% The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3932
|
||||||
|
|
||||||
|
% 陈数定义法
|
||||||
|
clear;clc;
|
||||||
|
n=100; % 积分密度
|
||||||
|
delta=1e-9; % 求导的偏离量
|
||||||
|
C=0;
|
||||||
|
for kx=-pi:(1/n):pi
|
||||||
|
for ky=-pi:(1/n):pi
|
||||||
|
VV=get_vector(HH(kx,ky));
|
||||||
|
Vkx=get_vector(HH(kx+delta,ky)); % 略偏离kx的波函数
|
||||||
|
Vky=get_vector(HH(kx,ky+delta)); % 略偏离ky的波函数
|
||||||
|
Vkxky=get_vector(HH(kx+delta,ky+delta)); % 略偏离kx,ky的波函数
|
||||||
|
if sum((abs(Vkx-VV)))>0.01 % 为了波函数的连续性(这里的不连续只遇到符号问题,所以可以直接这么处理)
|
||||||
|
Vkx=-Vkx;
|
||||||
|
end
|
||||||
|
|
||||||
|
if sum((abs(Vky-VV)))>0.01
|
||||||
|
Vky=-Vky;
|
||||||
|
end
|
||||||
|
|
||||||
|
if sum(abs(Vkxky-VV))>0.01
|
||||||
|
Vkxky=-Vkxky;
|
||||||
|
end
|
||||||
|
% 价带的波函数的berry connection,求导后内积
|
||||||
|
Ax=VV'*(Vkx-VV)/delta; % Berry connection Ax
|
||||||
|
Ay=VV'*(Vky-VV)/delta; % Berry connection Ay
|
||||||
|
Ax_delta_ky=Vky'*(Vkxky-Vky)/delta; % 略偏离ky的berry connection Ax
|
||||||
|
Ay_delta_kx=Vkx'*(Vkxky-Vkx)/delta; % 略偏离kx的berry connection Ay
|
||||||
|
% berry curvature
|
||||||
|
F=((Ay_delta_kx-Ay)-(Ax_delta_ky-Ax))/delta;
|
||||||
|
% chern number
|
||||||
|
C=C+F*(1/n)^2;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
C=C/(2*pi*1i)
|
||||||
|
|
||||||
|
function vector_new = get_vector(H)
|
||||||
|
[vector,eigenvalue] = eig(H);
|
||||||
|
[eigenvalue, index]=sort(diag(eigenvalue), 'descend');
|
||||||
|
vector_new = vector(:, index(2));
|
||||||
|
end
|
||||||
|
|
||||||
|
function H=HH(kx,ky)
|
||||||
|
H(1,2)=2*cos(kx)-1i*2*cos(ky);
|
||||||
|
H(2,1)=2*cos(kx)+1i*2*cos(ky);
|
||||||
|
H(1,1)=-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky);
|
||||||
|
H(2,2)=-(-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky));
|
||||||
|
end
|
@@ -0,0 +1,70 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3932
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import * # 引入pi, cos等
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(kx, ky): # 量子反常霍尔QAH模型(该参数对应的陈数为2)
|
||||||
|
t1 = 1.0
|
||||||
|
t2 = 1.0
|
||||||
|
t3 = 0.5
|
||||||
|
m = -1.0
|
||||||
|
matrix = np.zeros((2, 2))*(1+0j)
|
||||||
|
matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky)
|
||||||
|
matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky)
|
||||||
|
matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)
|
||||||
|
matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky))
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_time = time.time()
|
||||||
|
n = 100 # 积分密度
|
||||||
|
delta = 1e-9 # 求导的偏离量
|
||||||
|
chern_number = 0 # 陈数初始化
|
||||||
|
for kx in np.arange(-pi, pi, 2*pi/n):
|
||||||
|
for ky in np.arange(-pi, pi, 2*pi/n):
|
||||||
|
H = hamiltonian(kx, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
|
||||||
|
# print(np.argsort(np.real(eigenvalue))[0]) # 排序索引(从小到大)
|
||||||
|
# print(eigenvalue) # 排序前的本征值
|
||||||
|
# print(np.sort(np.real(eigenvalue))) # 排序后的本征值(从小到大)
|
||||||
|
|
||||||
|
H_delta_kx = hamiltonian(kx+delta, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
|
||||||
|
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
|
||||||
|
|
||||||
|
H_delta_ky = hamiltonian(kx, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
|
||||||
|
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
|
||||||
|
|
||||||
|
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
|
||||||
|
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
|
||||||
|
|
||||||
|
# 价带的波函数的贝里联络(berry connection) # 求导后内积
|
||||||
|
A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Ax(x分量)
|
||||||
|
A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ay(y分量)
|
||||||
|
|
||||||
|
A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax
|
||||||
|
A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay
|
||||||
|
|
||||||
|
# 贝里曲率(berry curvature)
|
||||||
|
F = (A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta
|
||||||
|
|
||||||
|
# 陈数(chern number)
|
||||||
|
chern_number = chern_number + F*(2*pi/n)**2
|
||||||
|
chern_number = chern_number/(2*pi*1j)
|
||||||
|
print('Chern number = ', chern_number)
|
||||||
|
end_time = time.time()
|
||||||
|
print('运行时间(min)=', (end_time-start_time)/60)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,108 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3932
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import * # 引入pi, cos等
|
||||||
|
import time
|
||||||
|
import cmath
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(kx, ky): # 量子反常霍尔QAH模型(该参数对应的陈数为2)
|
||||||
|
t1 = 1.0
|
||||||
|
t2 = 1.0
|
||||||
|
t3 = 0.5
|
||||||
|
m = -1.0
|
||||||
|
matrix = np.zeros((2, 2))*(1+0j)
|
||||||
|
matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky)
|
||||||
|
matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky)
|
||||||
|
matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)
|
||||||
|
matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky))
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_time = time.time()
|
||||||
|
n = 20 # 积分密度
|
||||||
|
delta = 1e-9 # 求导的偏离量
|
||||||
|
chern_number = 0 # 陈数初始化
|
||||||
|
for kx in np.arange(-pi, pi, 2*pi/n):
|
||||||
|
for ky in np.arange(-pi, pi, 2*pi/n):
|
||||||
|
H = hamiltonian(kx, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
|
||||||
|
|
||||||
|
H_delta_kx = hamiltonian(kx+delta, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
|
||||||
|
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
|
||||||
|
|
||||||
|
H_delta_ky = hamiltonian(kx, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
|
||||||
|
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
|
||||||
|
|
||||||
|
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
|
||||||
|
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
|
||||||
|
|
||||||
|
vector_delta_kx = find_vector_with_the_same_gauge(vector_delta_kx, vector)
|
||||||
|
vector_delta_ky = find_vector_with_the_same_gauge(vector_delta_ky, vector)
|
||||||
|
vector_delta_kx_ky = find_vector_with_the_same_gauge(vector_delta_kx_ky, vector)
|
||||||
|
|
||||||
|
# 价带的波函数的贝里联络(berry connection) # 求导后内积
|
||||||
|
A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Ax(x分量)
|
||||||
|
A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ay(y分量)
|
||||||
|
|
||||||
|
A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax
|
||||||
|
A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay
|
||||||
|
|
||||||
|
# 贝里曲率(berry curvature)
|
||||||
|
F = (A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta
|
||||||
|
|
||||||
|
# 陈数(chern number)
|
||||||
|
chern_number = chern_number + F*(2*pi/n)**2
|
||||||
|
chern_number = chern_number/(2*pi*1j)
|
||||||
|
print('Chern number = ', chern_number)
|
||||||
|
end_time = time.time()
|
||||||
|
print('运行时间(min)=', (end_time-start_time)/60)
|
||||||
|
|
||||||
|
|
||||||
|
def find_vector_with_the_same_gauge(vector_1, vector_0):
|
||||||
|
# 寻找近似的同一的规范
|
||||||
|
phase_1_pre = 0
|
||||||
|
phase_2_pre = pi
|
||||||
|
n_test = 10001
|
||||||
|
for i0 in range(n_test):
|
||||||
|
test_1 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_1_pre) - vector_0))
|
||||||
|
test_2 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_2_pre) - vector_0))
|
||||||
|
if test_1 < 1e-6:
|
||||||
|
phase = phase_1_pre
|
||||||
|
# print('Done with i0=', i0)
|
||||||
|
break
|
||||||
|
if i0 == n_test-1:
|
||||||
|
phase = phase_1_pre
|
||||||
|
print('Gauge Not Found with i0=', i0)
|
||||||
|
if test_1 < test_2:
|
||||||
|
if i0 == 0:
|
||||||
|
phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
phase_1 = phase_1_pre
|
||||||
|
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
if i0 == 0:
|
||||||
|
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_2_pre
|
||||||
|
phase_1_pre = phase_1
|
||||||
|
phase_2_pre = phase_2
|
||||||
|
vector_1 = vector_1*cmath.exp(1j*phase)
|
||||||
|
# print('二分查找找到的规范=', phase)
|
||||||
|
return vector_1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,40 @@
|
|||||||
|
% This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
% The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4179
|
||||||
|
|
||||||
|
% 陈数高效法
|
||||||
|
clear;clc;
|
||||||
|
n=1000 % 积分密度
|
||||||
|
delta=2*pi/n;
|
||||||
|
C=0;
|
||||||
|
for kx=-pi:(2*pi/n):pi
|
||||||
|
for ky=-pi:(2*pi/n):pi
|
||||||
|
VV=get_vector(HH(kx,ky));
|
||||||
|
Vkx=get_vector(HH(kx+delta,ky)); % 略偏离kx的波函数
|
||||||
|
Vky=get_vector(HH(kx,ky+delta)); % 略偏离ky的波函数
|
||||||
|
Vkxky=get_vector(HH(kx+delta,ky+delta)); % 略偏离kx,ky的波函数
|
||||||
|
|
||||||
|
Ux = VV'*Vkx/abs(VV'*Vkx);
|
||||||
|
Uy = VV'*Vky/abs(VV'*Vky);
|
||||||
|
Ux_y = Vky'*Vkxky/abs(Vky'*Vkxky);
|
||||||
|
Uy_x = Vkx'*Vkxky/abs(Vkx'*Vkxky);
|
||||||
|
|
||||||
|
% berry curvature
|
||||||
|
F=log(Ux*Uy_x*(1/Ux_y)*(1/Uy));
|
||||||
|
% chern number
|
||||||
|
C=C+F;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
C=C/(2*pi*1i)
|
||||||
|
|
||||||
|
function vector_new = get_vector(H)
|
||||||
|
[vector,eigenvalue] = eig(H);
|
||||||
|
[eigenvalue, index]=sort(diag(eigenvalue), 'descend');
|
||||||
|
vector_new = vector(:, index(2));
|
||||||
|
end
|
||||||
|
|
||||||
|
function H=HH(kx,ky)
|
||||||
|
H(1,2)=2*cos(kx)-1i*2*cos(ky);
|
||||||
|
H(2,1)=2*cos(kx)+1i*2*cos(ky);
|
||||||
|
H(1,1)=-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky);
|
||||||
|
H(2,2)=-(-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky));
|
||||||
|
end
|
@@ -0,0 +1,65 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4179
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import * # 引入pi, cos等
|
||||||
|
import cmath
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(kx, ky): # 量子反常霍尔QAH模型(该参数对应的陈数为2)
|
||||||
|
t1 = 1.0
|
||||||
|
t2 = 1.0
|
||||||
|
t3 = 0.5
|
||||||
|
m = -1.0
|
||||||
|
matrix = np.zeros((2, 2))*(1+0j)
|
||||||
|
matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky)
|
||||||
|
matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky)
|
||||||
|
matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)
|
||||||
|
matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky))
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_time = time.time()
|
||||||
|
n = 100
|
||||||
|
delta = 2*pi/n
|
||||||
|
chern_number = 0 # 陈数初始化
|
||||||
|
for kx in np.arange(-pi, pi, 2*pi/n):
|
||||||
|
for ky in np.arange(-pi, pi, 2*pi/n):
|
||||||
|
H = hamiltonian(kx, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
|
||||||
|
|
||||||
|
H_delta_kx = hamiltonian(kx+delta, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
|
||||||
|
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
|
||||||
|
|
||||||
|
H_delta_ky = hamiltonian(kx, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
|
||||||
|
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
|
||||||
|
|
||||||
|
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
|
||||||
|
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
|
||||||
|
|
||||||
|
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
|
||||||
|
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
|
||||||
|
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
|
||||||
|
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
|
||||||
|
|
||||||
|
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
|
||||||
|
|
||||||
|
# 陈数(chern number)
|
||||||
|
chern_number = chern_number + F
|
||||||
|
chern_number = chern_number/(2*pi*1j)
|
||||||
|
print('Chern number = ', chern_number)
|
||||||
|
end_time = time.time()
|
||||||
|
print('运行时间(min)=', (end_time-start_time)/60)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,69 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4322
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import cmath
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k, N):
|
||||||
|
# 初始化为零矩阵
|
||||||
|
h = np.zeros((4*N, 4*N), dtype=complex)
|
||||||
|
|
||||||
|
t=1
|
||||||
|
a=1
|
||||||
|
t0=0.2 # 层间跃迁
|
||||||
|
V=0.2 # 层间的势能差为2V
|
||||||
|
|
||||||
|
for i in range(N):
|
||||||
|
h[i*4+0, i*4+0] = V
|
||||||
|
h[i*4+1, i*4+1] = V
|
||||||
|
h[i*4+2, i*4+2] = -V
|
||||||
|
h[i*4+3, i*4+3] = -V
|
||||||
|
|
||||||
|
h[i*4+0, i*4+1] = -t*(1+cmath.exp(1j*k*a))
|
||||||
|
h[i*4+1, i*4+0] = -t*(1+cmath.exp(-1j*k*a))
|
||||||
|
h[i*4+2, i*4+3] = -t*(1+cmath.exp(1j*k*a))
|
||||||
|
h[i*4+3, i*4+2] = -t*(1+cmath.exp(-1j*k*a))
|
||||||
|
|
||||||
|
h[i*4+0, i*4+3] = -t0
|
||||||
|
h[i*4+3, i*4+0] = -t0
|
||||||
|
|
||||||
|
for i in range(N-1):
|
||||||
|
# 最近邻
|
||||||
|
h[i*4+1, (i+1)*4+0] = -t
|
||||||
|
h[(i+1)*4+0, i*4+1] = -t
|
||||||
|
|
||||||
|
h[i*4+3, (i+1)*4+2] = -t
|
||||||
|
h[(i+1)*4+2, i*4+3] = -t
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
hamiltonian0 = functools.partial(hamiltonian, N=100)
|
||||||
|
k = np.linspace(-pi, pi, 400)
|
||||||
|
plot_bands_one_dimension(k, hamiltonian0)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_one_dimension(k, hamiltonian):
|
||||||
|
dim = hamiltonian(0).shape[0]
|
||||||
|
dim_k = k.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim_k, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k0 in k:
|
||||||
|
matrix0 = hamiltonian(k0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
i0 += 1
|
||||||
|
print(k0)
|
||||||
|
for dim0 in range(dim):
|
||||||
|
plt.plot(k, eigenvalue_k[:, dim0], '-k')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,83 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4322
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import cmath
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k, N):
|
||||||
|
# 初始化为零矩阵
|
||||||
|
h = np.zeros((4*N, 4*N), dtype=complex)
|
||||||
|
h11 = np.zeros((4*N, 4*N), dtype=complex) # 元胞内
|
||||||
|
h12 = np.zeros((4*N, 4*N), dtype=complex) # 元胞间
|
||||||
|
|
||||||
|
t=1
|
||||||
|
a=1
|
||||||
|
t0=0.2 # 层间跃迁
|
||||||
|
V=0.2 # 层间的势能差为2V
|
||||||
|
|
||||||
|
for i in range(N):
|
||||||
|
h11[i*2+0, i*2+0] = V
|
||||||
|
h11[i*2+1, i*2+1] = V
|
||||||
|
|
||||||
|
|
||||||
|
h11[N*2+i*2+0, N*2+i*2+0] = -V
|
||||||
|
h11[N*2+i*2+1, N*2+i*2+1] = -V
|
||||||
|
|
||||||
|
|
||||||
|
h11[i*2+0, i*2+1] = -t
|
||||||
|
h11[i*2+1, i*2+0] = -t
|
||||||
|
|
||||||
|
|
||||||
|
h11[N*2+i*2+0, N*2+i*2+1] = -t
|
||||||
|
h11[N*2+i*2+1, N*2+i*2+0] = -t
|
||||||
|
|
||||||
|
h11[i*2+0, N*2+i*2+1] = -t0
|
||||||
|
h11[N*2+i*2+1, i*2+0] = -t0
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(N-1):
|
||||||
|
h11[i*2+1, (i+1)*2+0] = -t
|
||||||
|
h11[(i+1)*2+0, i*2+1] = -t
|
||||||
|
|
||||||
|
h11[N*2+i*2+1, N*2+(i+1)*2+0] = -t
|
||||||
|
h11[N*2+(i+1)*2+0, N*2+i*2+1] = -t
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(N):
|
||||||
|
h12[i*2+0, i*2+1] = -t
|
||||||
|
h12[N*2+i*2+0, N*2+i*2+1] = -t
|
||||||
|
|
||||||
|
h= h11 + h12*cmath.exp(-1j*k*a) + h12.transpose().conj()*cmath.exp(1j*k*a)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
hamiltonian0 = functools.partial(hamiltonian, N=100)
|
||||||
|
k = np.linspace(-pi, pi, 400)
|
||||||
|
plot_bands_one_dimension(k, hamiltonian0)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_one_dimension(k, hamiltonian):
|
||||||
|
dim = hamiltonian(0).shape[0]
|
||||||
|
dim_k = k.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim_k, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k0 in k:
|
||||||
|
matrix0 = hamiltonian(k0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
i0 += 1
|
||||||
|
print(k0)
|
||||||
|
for dim0 in range(dim):
|
||||||
|
plt.plot(k, eigenvalue_k[:, dim0], '-k')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,56 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4622
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
|
||||||
|
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(width=8, length=8): # 石墨烯格子的哈密顿量。这里width要求为4的倍数
|
||||||
|
h = np.zeros((width*length, width*length))
|
||||||
|
# y方向的跃迁
|
||||||
|
for x in range(length):
|
||||||
|
for y in range(width-1):
|
||||||
|
h[x*width+y, x*width+y+1] = 1
|
||||||
|
h[x*width+y+1, x*width+y] = 1
|
||||||
|
|
||||||
|
# x方向的跃迁
|
||||||
|
for x in range(length-1):
|
||||||
|
for y in range(width):
|
||||||
|
if np.mod(y, 4)==0:
|
||||||
|
h[x*width+y+1, (x+1)*width+y] = 1
|
||||||
|
h[(x+1)*width+y, x*width+y+1] = 1
|
||||||
|
|
||||||
|
h[x*width+y+2, (x+1)*width+y+3] = 1
|
||||||
|
h[(x+1)*width+y+3, x*width+y+2] = 1
|
||||||
|
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
plot_precision = 0.01 # 画图的精度
|
||||||
|
Fermi_energy_array = np.arange(-5, 5, plot_precision) # 计算中取的费米能Fermi_energy组成的数组
|
||||||
|
dim_energy = Fermi_energy_array.shape[0] # 需要计算的费米能的个数
|
||||||
|
total_DOS_array = np.zeros((dim_energy)) # 计算结果(总态密度total_DOS)放入该数组中
|
||||||
|
h = hamiltonian() # 体系的哈密顿量
|
||||||
|
dim = h.shape[0] # 哈密顿量的维度
|
||||||
|
i0 = 0
|
||||||
|
for Fermi_energy in Fermi_energy_array:
|
||||||
|
print(Fermi_energy) # 查看计算的进展情况
|
||||||
|
green = np.linalg.inv((Fermi_energy+0.1j)*np.eye(dim)-h) # 体系的格林函数
|
||||||
|
total_DOS = -np.trace(np.imag(green))/pi # 通过格林函数求得总态密度
|
||||||
|
total_DOS_array[i0] = total_DOS # 记录每个Fermi_energy对应的总态密度
|
||||||
|
i0 += 1
|
||||||
|
sum_up = np.sum(total_DOS_array)*plot_precision # 用于图像归一化
|
||||||
|
plt.plot(Fermi_energy_array, total_DOS_array/sum_up, '-') # 画DOS(E)图像
|
||||||
|
plt.xlabel('费米能')
|
||||||
|
plt.ylabel('总态密度')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,52 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4622
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
|
||||||
|
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(width=10, length=10): # 方格子哈密顿量
|
||||||
|
h = np.zeros((width*length, width*length))
|
||||||
|
# y方向的跃迁
|
||||||
|
for x in range(length):
|
||||||
|
for y in range(width-1):
|
||||||
|
h[x*width+y, x*width+y+1] = 1
|
||||||
|
h[x*width+y+1, x*width+y] = 1
|
||||||
|
|
||||||
|
# x方向的跃迁
|
||||||
|
for x in range(length-1):
|
||||||
|
for y in range(width):
|
||||||
|
h[x*width+y, (x+1)*width+y] = 1
|
||||||
|
h[(x+1)*width+y, x*width+y] = 1
|
||||||
|
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
plot_precision = 0.01 # 画图的精度
|
||||||
|
Fermi_energy_array = np.arange(-5, 5, plot_precision) # 计算中取的费米能Fermi_energy组成的数组
|
||||||
|
dim_energy = Fermi_energy_array.shape[0] # 需要计算的费米能的个数
|
||||||
|
total_DOS_array = np.zeros((dim_energy)) # 计算结果(总态密度total_DOS)放入该数组中
|
||||||
|
h = hamiltonian() # 体系的哈密顿量
|
||||||
|
dim = h.shape[0] # 哈密顿量的维度
|
||||||
|
i0 = 0
|
||||||
|
for Fermi_energy in Fermi_energy_array:
|
||||||
|
print(Fermi_energy) # 查看计算的进展情况
|
||||||
|
green = np.linalg.inv((Fermi_energy+0.1j)*np.eye(dim)-h) # 体系的格林函数
|
||||||
|
total_DOS = -np.trace(np.imag(green))/pi # 通过格林函数求得总态密度
|
||||||
|
total_DOS_array[i0] = total_DOS # 记录每个Fermi_energy对应的总态密度
|
||||||
|
i0 += 1
|
||||||
|
sum_up = np.sum(total_DOS_array)*plot_precision # 用于图像归一化
|
||||||
|
plt.plot(Fermi_energy_array, total_DOS_array/sum_up, '-') # 画DOS(E)图像
|
||||||
|
plt.xlabel('费米能')
|
||||||
|
plt.ylabel('总态密度')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,84 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4396
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import copy
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_00(width): # 一个切片(slide)内的哈密顿量
|
||||||
|
h00 = np.zeros((width, width))
|
||||||
|
for width0 in range(width-1):
|
||||||
|
h00[width0, width0+1] = 1
|
||||||
|
h00[width0+1, width0] = 1
|
||||||
|
return h00
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_01(width): # 切片之间的跃迁项(hopping)
|
||||||
|
h01 = np.identity(width)
|
||||||
|
return h01
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_whole(width, length): # 方格子整体的哈密顿量,宽度为width,长度为length
|
||||||
|
hamiltonian = np.zeros((width*length, width*length))
|
||||||
|
for x in range(length):
|
||||||
|
for y in range(width-1):
|
||||||
|
hamiltonian[x*width+y, x*width+y+1] = 1
|
||||||
|
hamiltonian[x*width+y+1, x*width+y] = 1
|
||||||
|
for x in range(length-1):
|
||||||
|
for y in range(width):
|
||||||
|
hamiltonian[x*width+y, (x+1)*width+y] = 1
|
||||||
|
hamiltonian[(x+1)*width+y, x*width+y] = 1
|
||||||
|
return hamiltonian
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
width =4 # 方格子的宽度
|
||||||
|
length = 200 # 方格子的长度
|
||||||
|
h00 = matrix_00(width) # 一个切片(slide)内的哈密顿量
|
||||||
|
h01 = matrix_01(width) # 切片之间的跃迁项(hopping)
|
||||||
|
hamiltonian = matrix_whole(width, length) # 方格子整体的哈密顿量,宽度为width,长度为length
|
||||||
|
fermi_energy = 0.1 # 费米能取为0.1为例。按理来说计算格林函数时,这里需要加上一个无穷小的虚数,但Python中好像不加也不会有什么问题。
|
||||||
|
|
||||||
|
start_1= time.perf_counter()
|
||||||
|
green = General_way(fermi_energy, hamiltonian) # 利用通常直接求逆的方法得到整体的格林函数green
|
||||||
|
end_1 = time.perf_counter()
|
||||||
|
start_2= time.perf_counter()
|
||||||
|
green_0n_n = Dyson_way(fermi_energy, h00, h01, length) # 利用Dyson方程得到的格林函数green_0n
|
||||||
|
end_2 = time.perf_counter()
|
||||||
|
|
||||||
|
# print(green)
|
||||||
|
print('\n整体格林函数中的一个分块矩阵green_0n:\n', green[0:width, (length-1)*width+0:(length-1)*width+width]) # a:b代表 a <= x < b,左闭右开
|
||||||
|
print('Dyson方程得到的格林函数green_0n:\n', green_0n_n)
|
||||||
|
print('观察以上两个矩阵,可以直接看出两个矩阵完全相同。\n')
|
||||||
|
|
||||||
|
print('General_way执行时间=', end_1-start_1)
|
||||||
|
print('Dyson_way执行时间=', end_2-start_2)
|
||||||
|
|
||||||
|
|
||||||
|
def General_way(fermi_energy, hamiltonian):
|
||||||
|
dim_hamiltonian = hamiltonian.shape[0]
|
||||||
|
green = np.linalg.inv((fermi_energy)*np.eye(dim_hamiltonian)-hamiltonian)
|
||||||
|
return green
|
||||||
|
|
||||||
|
|
||||||
|
def Dyson_way(fermi_energy, h00, h01, length):
|
||||||
|
dim = h00.shape[0]
|
||||||
|
for ix in range(length):
|
||||||
|
if ix == 0:
|
||||||
|
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00) # 如果有左电极,还需要减去左电极的自能left_self_energy
|
||||||
|
green_0n_n = copy.deepcopy(green_nn_n) # 如果直接用等于,两个变量会指向相同的id,改变一个值,另外一个值可能会发生改变,容易出错,所以要用上这个COPY
|
||||||
|
elif ix != length-1:
|
||||||
|
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
|
||||||
|
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
|
||||||
|
else: # 这里和(elif ix != length-1)中的内容完全一样,但如果有右电极,这里是还需要减去右电极的自能right_self_energy
|
||||||
|
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
|
||||||
|
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
|
||||||
|
return green_0n_n
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,104 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4829
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import cmath
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k, N, M, t1, t2, phi): # Kane-Mele model
|
||||||
|
# 初始化为零矩阵
|
||||||
|
h00 = np.zeros((2*4*N, 2*4*N), dtype=complex) # 因为自旋有上有下,所以整个维度要乘2。这里4是元胞内部重复单位的大小,规定元胞大小以4来倍增。
|
||||||
|
h01 = np.zeros((2*4*N, 2*4*N), dtype=complex)
|
||||||
|
|
||||||
|
for spin in range(2):
|
||||||
|
# 原胞内的跃迁h00
|
||||||
|
for i in range(N):
|
||||||
|
# 最近邻
|
||||||
|
h00[i*4*2+0*2+spin, i*4*2+1*2+spin] = t1
|
||||||
|
h00[i*4*2+1*2+spin, i*4*2+0*2+spin] = t1
|
||||||
|
|
||||||
|
h00[i*4*2+1*2+spin, i*4*2+2*2+spin] = t1
|
||||||
|
h00[i*4*2+2*2+spin, i*4*2+1*2+spin] = t1
|
||||||
|
|
||||||
|
h00[i*4*2+2*2+spin, i*4*2+3*2+spin] = t1
|
||||||
|
h00[i*4*2+3*2+spin, i*4*2+2*2+spin] = t1
|
||||||
|
|
||||||
|
# 次近邻
|
||||||
|
h00[i*4*2+0*2+spin, i*4*2+2*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
|
||||||
|
h00[i*4*2+2*2+spin, i*4*2+0*2+spin] = h00[i*4*2+0*2+spin, i*4*2+2*2+spin].conj()
|
||||||
|
h00[i*4*2+1*2+spin, i*4*2+3*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
|
||||||
|
h00[i*4*2+3*2+spin, i*4*2+1*2+spin] = h00[i*4*2+1*2+spin, i*4*2+3*2+spin].conj()
|
||||||
|
|
||||||
|
for i in range(N-1):
|
||||||
|
# 最近邻
|
||||||
|
h00[i*4*2+3*2+spin, (i+1)*4*2+0*2+spin] = t1
|
||||||
|
h00[(i+1)*4*2+0*2+spin, i*4*2+3*2+spin] = t1
|
||||||
|
|
||||||
|
# 次近邻
|
||||||
|
h00[i*4*2+2*2+spin, (i+1)*4*2+0*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
|
||||||
|
h00[(i+1)*4*2+0*2+spin, i*4*2+2*2+spin] = h00[i*4*2+2*2+spin, (i+1)*4*2+0*2+spin].conj()
|
||||||
|
h00[i*4*2+3*2+spin, (i+1)*4*2+1*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
|
||||||
|
h00[(i+1)*4*2+1*2+spin, i*4*2+3*2+spin] = h00[i*4*2+3*2+spin, (i+1)*4*2+1*2+spin].conj()
|
||||||
|
|
||||||
|
# 原胞间的跃迁h01
|
||||||
|
for i in range(N):
|
||||||
|
# 最近邻
|
||||||
|
h01[i*4*2+1*2+spin, i*4*2+0*2+spin] = t1
|
||||||
|
h01[i*4*2+2*2+spin, i*4*2+3*2+spin] = t1
|
||||||
|
|
||||||
|
# 次近邻
|
||||||
|
h01[i*4*2+0*2+spin, i*4*2+0*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
|
||||||
|
h01[i*4*2+1*2+spin, i*4*2+1*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
|
||||||
|
h01[i*4*2+2*2+spin, i*4*2+2*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
|
||||||
|
h01[i*4*2+3*2+spin, i*4*2+3*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
|
||||||
|
|
||||||
|
h01[i*4*2+1*2+spin, i*4*2+3*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
|
||||||
|
h01[i*4*2+2*2+spin, i*4*2+0*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
|
||||||
|
|
||||||
|
if i != 0:
|
||||||
|
h01[i*4*2+1*2+spin, (i-1)*4*2+3*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
|
||||||
|
|
||||||
|
for i in range(N-1):
|
||||||
|
h01[i*4*2+2*2+spin, (i+1)*4*2+0*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
|
||||||
|
|
||||||
|
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def sign_spin(spin):
|
||||||
|
if spin==0:
|
||||||
|
sign=1
|
||||||
|
else:
|
||||||
|
sign=-1
|
||||||
|
return sign
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
hamiltonian0 = functools.partial(hamiltonian, N=20, M=0, t1=1, t2=0.03, phi=pi/2)
|
||||||
|
k = np.linspace(0, 2*pi, 300)
|
||||||
|
plot_bands_one_dimension(k, hamiltonian0)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_one_dimension(k, hamiltonian):
|
||||||
|
dim = hamiltonian(0).shape[0]
|
||||||
|
dim_k = k.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim_k, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k0 in k:
|
||||||
|
matrix0 = hamiltonian(k0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
i0 += 1
|
||||||
|
for dim0 in range(dim):
|
||||||
|
plt.plot(k, eigenvalue_k[:, dim0], '-k')
|
||||||
|
plt.ylim(-1, 1)
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,91 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5133
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import * # 引入pi, cos等
|
||||||
|
import cmath
|
||||||
|
import time
|
||||||
|
import functools # 使用偏函数functools.partial()
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量(a为原子间距,不赋值的话默认为1/sqrt(3))
|
||||||
|
# 初始化为零矩阵
|
||||||
|
h0 = np.zeros((2, 2))*(1+0j) # 乘(1+0j)是为了把h0转为复数
|
||||||
|
h1 = np.zeros((2, 2))*(1+0j)
|
||||||
|
h2 = np.zeros((2, 2))*(1+0j)
|
||||||
|
|
||||||
|
# 质量项(mass term), 用于打开带隙
|
||||||
|
h0[0, 0] = M
|
||||||
|
h0[1, 1] = -M
|
||||||
|
|
||||||
|
# 最近邻项
|
||||||
|
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
|
||||||
|
h1[0, 1] = h1[1, 0].conj()
|
||||||
|
|
||||||
|
#次近邻项 # 对应陈数为-1
|
||||||
|
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
|
||||||
|
# # 次近邻项 # 对应陈数为1
|
||||||
|
# h2[0, 0] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
# h2[1, 1] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
|
||||||
|
matrix = h0 + h1 + h2 + h2.transpose().conj()
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_clock = time.perf_counter()
|
||||||
|
delta = 0.005
|
||||||
|
chern_number = 0 # 陈数初始化
|
||||||
|
|
||||||
|
# 几个坐标中常出现的项
|
||||||
|
a = 1/sqrt(3)
|
||||||
|
aa1 = 4*sqrt(3)*pi/9/a
|
||||||
|
aa2 = 2*sqrt(3)*pi/9/a
|
||||||
|
bb1 = 2*pi/3/a
|
||||||
|
|
||||||
|
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数
|
||||||
|
|
||||||
|
for kx in np.arange(-aa1, aa1, delta):
|
||||||
|
print(kx)
|
||||||
|
for ky in np.arange(-bb1, bb1, delta):
|
||||||
|
if (-aa2<=kx<=aa2) or (kx>aa2 and -(aa1-kx)*tan(pi/3)<=ky<=(aa1-kx)*tan(pi/3)) or (kx<-aa2 and -(kx-(-aa1))*tan(pi/3)<=ky<=(kx-(-aa1))*tan(pi/3)): # 限制在六角格子布里渊区内
|
||||||
|
|
||||||
|
H = hamiltonian0(kx, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
|
||||||
|
|
||||||
|
H_delta_kx = hamiltonian0(kx+delta, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
|
||||||
|
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
|
||||||
|
|
||||||
|
H_delta_ky = hamiltonian0(kx, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
|
||||||
|
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
|
||||||
|
|
||||||
|
H_delta_kx_ky = hamiltonian0(kx+delta, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
|
||||||
|
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
|
||||||
|
|
||||||
|
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
|
||||||
|
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
|
||||||
|
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
|
||||||
|
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
|
||||||
|
|
||||||
|
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
|
||||||
|
|
||||||
|
# 陈数(chern number)
|
||||||
|
chern_number = chern_number + F
|
||||||
|
|
||||||
|
chern_number = chern_number/(2*pi*1j)
|
||||||
|
print('Chern number = ', chern_number)
|
||||||
|
end_clock = time.perf_counter()
|
||||||
|
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,87 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5133
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import * # 引入pi, cos等
|
||||||
|
import cmath
|
||||||
|
import time
|
||||||
|
import functools # 使用偏函数functools.partial()
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量(a为原子间距,不赋值的话默认为1/sqrt(3))
|
||||||
|
# 初始化为零矩阵
|
||||||
|
h0 = np.zeros((2, 2))*(1+0j) # 乘(1+0j)是为了把h0转为复数
|
||||||
|
h1 = np.zeros((2, 2))*(1+0j)
|
||||||
|
h2 = np.zeros((2, 2))*(1+0j)
|
||||||
|
|
||||||
|
# 质量项(mass term), 用于打开带隙
|
||||||
|
h0[0, 0] = M
|
||||||
|
h0[1, 1] = -M
|
||||||
|
|
||||||
|
# 最近邻项
|
||||||
|
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
|
||||||
|
h1[0, 1] = h1[1, 0].conj()
|
||||||
|
|
||||||
|
#次近邻项 # 对应陈数为-1
|
||||||
|
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
|
||||||
|
# # 次近邻项 # 对应陈数为1
|
||||||
|
# h2[0, 0] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
# h2[1, 1] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
|
||||||
|
matrix = h0 + h1 + h2 + h2.transpose().conj()
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_clock = time.perf_counter()
|
||||||
|
delta = 0.005
|
||||||
|
chern_number = 0 # 陈数初始化
|
||||||
|
|
||||||
|
# 常出现的项
|
||||||
|
a = 1/sqrt(3)
|
||||||
|
bb1 = 2*sqrt(3)*pi/3/a
|
||||||
|
bb2 = 2*pi/3/a
|
||||||
|
|
||||||
|
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数
|
||||||
|
|
||||||
|
for kx in np.arange(0 , bb1, delta):
|
||||||
|
print(kx)
|
||||||
|
for ky in np.arange(0, 2*bb2, delta):
|
||||||
|
H = hamiltonian0(kx, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
|
||||||
|
|
||||||
|
H_delta_kx = hamiltonian0(kx+delta, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
|
||||||
|
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
|
||||||
|
|
||||||
|
H_delta_ky = hamiltonian0(kx, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
|
||||||
|
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
|
||||||
|
|
||||||
|
H_delta_kx_ky = hamiltonian0(kx+delta, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
|
||||||
|
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
|
||||||
|
|
||||||
|
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
|
||||||
|
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
|
||||||
|
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
|
||||||
|
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
|
||||||
|
|
||||||
|
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
|
||||||
|
# 陈数(chern number)
|
||||||
|
chern_number = chern_number + F
|
||||||
|
|
||||||
|
chern_number = chern_number/(2*pi*1j)
|
||||||
|
print('Chern number = ', chern_number)
|
||||||
|
end_clock = time.perf_counter()
|
||||||
|
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,95 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5133
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import * # 引入pi, cos等
|
||||||
|
import cmath
|
||||||
|
import time
|
||||||
|
import functools # 使用偏函数functools.partial()
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量(a为原子间距,不赋值的话默认为1/sqrt(3))
|
||||||
|
# 初始化为零矩阵
|
||||||
|
h0 = np.zeros((2, 2))*(1+0j) # 乘(1+0j)是为了把h0转为复数
|
||||||
|
h1 = np.zeros((2, 2))*(1+0j)
|
||||||
|
h2 = np.zeros((2, 2))*(1+0j)
|
||||||
|
|
||||||
|
# 质量项(mass term), 用于打开带隙
|
||||||
|
h0[0, 0] = M
|
||||||
|
h0[1, 1] = -M
|
||||||
|
|
||||||
|
# 最近邻项
|
||||||
|
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
|
||||||
|
h1[0, 1] = h1[1, 0].conj()
|
||||||
|
|
||||||
|
#次近邻项 # 对应陈数为-1
|
||||||
|
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
|
||||||
|
# # 次近邻项 # 对应陈数为1
|
||||||
|
# h2[0, 0] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
# h2[1, 1] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
|
|
||||||
|
matrix = h0 + h1 + h2 + h2.transpose().conj()
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_clock = time.perf_counter()
|
||||||
|
delta = 0.005
|
||||||
|
chern_number = 0 # 陈数初始化
|
||||||
|
|
||||||
|
# 常出现的项
|
||||||
|
a = 1/sqrt(3)
|
||||||
|
bb1 = 2*sqrt(3)*pi/3/a
|
||||||
|
bb2 = 2*pi/3/a
|
||||||
|
|
||||||
|
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数
|
||||||
|
|
||||||
|
for k1 in np.arange(0 , 1, delta):
|
||||||
|
print(k1)
|
||||||
|
for k2 in np.arange(0, 1, delta):
|
||||||
|
# 坐标变换
|
||||||
|
kx = (k1-k2)*bb1
|
||||||
|
ky = (k1+k2)*bb2
|
||||||
|
|
||||||
|
# 这里乘2或除以2是为了保证“步长与积分个数的乘积刚好为布里渊区面积”
|
||||||
|
delta_x = delta*bb1*2
|
||||||
|
delta_y = delta*bb2*2/2
|
||||||
|
|
||||||
|
H = hamiltonian0(kx, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
|
||||||
|
|
||||||
|
H_delta_kx = hamiltonian0(kx+delta_x, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
|
||||||
|
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
|
||||||
|
|
||||||
|
H_delta_ky = hamiltonian0(kx, ky+delta_y)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
|
||||||
|
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
|
||||||
|
|
||||||
|
H_delta_kx_ky = hamiltonian0(kx+delta_x, ky+delta_y)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
|
||||||
|
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
|
||||||
|
|
||||||
|
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
|
||||||
|
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
|
||||||
|
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
|
||||||
|
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
|
||||||
|
|
||||||
|
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
|
||||||
|
# 陈数(chern number)
|
||||||
|
chern_number = chern_number + F
|
||||||
|
|
||||||
|
chern_number = chern_number/(2*pi*1j)
|
||||||
|
print('Chern number = ', chern_number)
|
||||||
|
end_clock = time.perf_counter()
|
||||||
|
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,41 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5025
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import cmath
|
||||||
|
import time
|
||||||
|
|
||||||
|
def hamiltonian(k): # SSH模型
|
||||||
|
v=0.6
|
||||||
|
w=1
|
||||||
|
matrix = np.zeros((2, 2), dtype=complex)
|
||||||
|
matrix[0,1] = v+w*cmath.exp(-1j*k)
|
||||||
|
matrix[1,0] = v+w*cmath.exp(1j*k)
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_clock = time.perf_counter()
|
||||||
|
delta_1 = 1e-9 # 求导的步长(求导的步长可以尽可能短)
|
||||||
|
delta_2 = 1e-5 # 积分的步长(积分步长和计算时间相关,因此取一个合理值即可)
|
||||||
|
W = 0 # Winding number初始化
|
||||||
|
for k in np.arange(-pi, pi, delta_2):
|
||||||
|
H = hamiltonian(k)
|
||||||
|
log0 = cmath.log(H[0, 1])
|
||||||
|
|
||||||
|
H_delta = hamiltonian(k+delta_1)
|
||||||
|
log1 = cmath.log(H_delta[0, 1])
|
||||||
|
|
||||||
|
W = W + (log1-log0)/delta_1*delta_2 # Winding number
|
||||||
|
print('Winding number = ', W/2/pi/1j)
|
||||||
|
end_clock = time.perf_counter()
|
||||||
|
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,42 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5025
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import cmath
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k): # SSH模型
|
||||||
|
v=0.6
|
||||||
|
w=1
|
||||||
|
matrix = np.zeros((2, 2), dtype=complex)
|
||||||
|
matrix[0,1] = v+w*cmath.exp(-1j*k)
|
||||||
|
matrix[1,0] = v+w*cmath.exp(1j*k)
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
k = np.linspace(-pi, pi, 100)
|
||||||
|
plot_bands_one_dimension(k, hamiltonian)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_one_dimension(k, hamiltonian):
|
||||||
|
dim = hamiltonian(0).shape[0]
|
||||||
|
dim_k = k.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim_k, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k0 in k:
|
||||||
|
matrix0 = hamiltonian(k0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
i0 += 1
|
||||||
|
for dim0 in range(dim):
|
||||||
|
plt.plot(k, eigenvalue_k[:, dim0], '-k')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,23 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5375
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def hamiltonian(width=3, length=3): # 方格子哈密顿量
|
||||||
|
h = np.zeros((width*length, width*length))
|
||||||
|
# y方向的跃迁
|
||||||
|
for x in range(length):
|
||||||
|
for y in range(width-1):
|
||||||
|
h[x*width+y, x*width+y+1] = 1
|
||||||
|
h[x*width+y+1, x*width+y] = 1
|
||||||
|
# x方向的跃迁
|
||||||
|
for x in range(length-1):
|
||||||
|
for y in range(width):
|
||||||
|
h[x*width+y, (x+1)*width+y] = 1
|
||||||
|
h[(x+1)*width+y, x*width+y] = 1
|
||||||
|
return h
|
||||||
|
|
||||||
|
h = hamiltonian()
|
||||||
|
print(h)
|
@@ -0,0 +1,21 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5375
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def hamiltonian(width=3, length=3): # 方格子哈密顿量
|
||||||
|
hopping_x = np.zeros((length, length))
|
||||||
|
hopping_y = np.zeros((width, width))
|
||||||
|
for i in range(length-1):
|
||||||
|
hopping_x[i, i+1] = 1
|
||||||
|
hopping_x[i+1, i] = 1
|
||||||
|
for i in range(width-1):
|
||||||
|
hopping_y[i, i+1] = 1
|
||||||
|
hopping_y[i+1, i] = 1
|
||||||
|
h = np.kron(hopping_x, np.eye(width))+np.kron(np.eye(length), hopping_y)
|
||||||
|
return h
|
||||||
|
|
||||||
|
h = hamiltonian()
|
||||||
|
print(h)
|
@@ -0,0 +1,30 @@
|
|||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
k1 = np.arange(-pi, pi, 0.05)
|
||||||
|
k2 = np.arange(-pi, pi, 0.05)
|
||||||
|
value = np.ones((k2.shape[0], k1.shape[0]))
|
||||||
|
plot_matrix(k1, k2, value)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_matrix(k1, k2, matrix):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from mpl_toolkits.mplot3d import Axes3D
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator, FormatStrFormatter
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.gca(projection='3d')
|
||||||
|
k1, k2 = np.meshgrid(k1, k2)
|
||||||
|
ax.plot_surface(k1, k2, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
plt.xlabel('k1')
|
||||||
|
plt.ylabel('k2')
|
||||||
|
ax.set_zlabel('Z')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,31 @@
|
|||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
k1 = np.arange(-pi, pi, 0.05)
|
||||||
|
k2 = np.arange(-pi, pi, 0.05)
|
||||||
|
value = np.ones((k2.shape[0], k1.shape[0]))
|
||||||
|
write_matrix(k1, k2, value)
|
||||||
|
|
||||||
|
|
||||||
|
def write_matrix(k1, k2, matrix):
|
||||||
|
with open('a.txt', 'w') as f:
|
||||||
|
# np.set_printoptions(suppress=True) # 取消输出科学记数法
|
||||||
|
f.write('0 ')
|
||||||
|
for k10 in k1:
|
||||||
|
f.write(str(k10)+' ')
|
||||||
|
f.write('\n')
|
||||||
|
i0 = 0
|
||||||
|
for k20 in k2:
|
||||||
|
f.write(str(k20))
|
||||||
|
for j0 in range(k1.shape[0]):
|
||||||
|
f.write(' '+str(matrix[i0, j0])+' ')
|
||||||
|
f.write('\n')
|
||||||
|
i0 += 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,35 @@
|
|||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
k = np.arange(-pi, pi, 0.05)
|
||||||
|
plot_bands_one_dimension(k, hamiltonian)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_one_dimension(k, hamiltonian):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
dim = hamiltonian(0).shape[0]
|
||||||
|
dim_k = k.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim_k, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k0 in k:
|
||||||
|
matrix0 = hamiltonian(k0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
i0 += 1
|
||||||
|
for dim0 in range(dim):
|
||||||
|
plt.plot(k, eigenvalue_k[:, dim0], '-k')
|
||||||
|
plt.xlabel('k')
|
||||||
|
plt.ylabel('E')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,47 @@
|
|||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k1, k2):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
k1 = np.arange(-pi, pi, 0.05)
|
||||||
|
k2 = np.arange(-pi, pi, 0.05)
|
||||||
|
plot_bands_two_dimension(k1, k2, hamiltonian)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_two_dimension(k1, k2, hamiltonian):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from mpl_toolkits.mplot3d import Axes3D
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator, FormatStrFormatter
|
||||||
|
dim = hamiltonian(0, 0).shape[0]
|
||||||
|
dim1 = k1.shape[0]
|
||||||
|
dim2 = k2.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim2, dim1, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k20 in k2:
|
||||||
|
j0 = 0
|
||||||
|
for k10 in k1:
|
||||||
|
matrix0 = hamiltonian(k10, k20)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[i0, j0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
j0 += 1
|
||||||
|
i0 += 1
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.gca(projection='3d')
|
||||||
|
k1, k2 = np.meshgrid(k1, k2)
|
||||||
|
for dim0 in range(dim):
|
||||||
|
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
plt.xlabel('k1')
|
||||||
|
plt.ylabel('k2')
|
||||||
|
ax.set_zlabel('E')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,31 @@
|
|||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
k = np.arange(-pi, pi, 0.05)
|
||||||
|
write_bands_one_dimension(k, hamiltonian)
|
||||||
|
|
||||||
|
|
||||||
|
def write_bands_one_dimension(k, hamiltonian):
|
||||||
|
dim = hamiltonian(0).shape[0]
|
||||||
|
f = open('a.txt','w')
|
||||||
|
for k0 in k:
|
||||||
|
f.write(str(k0)+' ')
|
||||||
|
matrix0 = hamiltonian(k0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue = np.sort(np.real(eigenvalue))
|
||||||
|
for dim0 in range(dim):
|
||||||
|
f.write(str(eigenvalue[dim0])+' ')
|
||||||
|
f.write('\n')
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,42 @@
|
|||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k1, k2):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
k1 = np.arange(-pi, pi, 0.05)
|
||||||
|
k2 = np.arange(-pi, pi, 0.05)
|
||||||
|
write_bands_two_dimension(k1, k2, hamiltonian)
|
||||||
|
|
||||||
|
|
||||||
|
def write_bands_two_dimension(k1, k2, hamiltonian):
|
||||||
|
f1 = open('a1.txt', 'w')
|
||||||
|
f2 = open('a2.txt', 'w')
|
||||||
|
f1.write('0 ')
|
||||||
|
f2.write('0 ')
|
||||||
|
for k10 in k1:
|
||||||
|
f1.write(str(k10)+' ')
|
||||||
|
f2.write(str(k10)+' ')
|
||||||
|
f1.write('\n')
|
||||||
|
f2.write('\n')
|
||||||
|
for k20 in k2:
|
||||||
|
f1.write(str(k20)+' ')
|
||||||
|
f2.write(str(k20)+' ')
|
||||||
|
for k10 in k1:
|
||||||
|
matrix0 = hamiltonian(k10, k20)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue = np.sort(np.real(eigenvalue))
|
||||||
|
f1.write(str(eigenvalue[0])+' ')
|
||||||
|
f2.write(str(eigenvalue[1])+' ')
|
||||||
|
f1.write('\n')
|
||||||
|
f2.write('\n')
|
||||||
|
f1.close()
|
||||||
|
f2.close()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
7
academic_codes/2020.08.29_several_python_functions/python_structure.py
Executable file
7
academic_codes/2020.08.29_several_python_functions/python_structure.py
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
import numpy as np # 导入numpy库,用来存储和处理大型矩阵,比python自带的嵌套列表更高效。numpy库还包含了许多数学函数库。python+numpy等同于matlab。
|
||||||
|
|
||||||
|
def main(): # 主函数的内容放在这里。
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == '__main__': # 如果是当前文件直接运行,执行main()函数中的内容;如果是import当前文件,则不执行。同时将main()语句放在最后运行,可以避免书写的函数出现未定义的情况。
|
||||||
|
main()
|
@@ -0,0 +1,4 @@
|
|||||||
|
1 1.2 2.4
|
||||||
|
2 5.5 3.2
|
||||||
|
3 6.7 7.1
|
||||||
|
4 3.6 4.9
|
@@ -0,0 +1,4 @@
|
|||||||
|
0 1 2 3 4
|
||||||
|
1 1.3 2.7 6.7 8.3
|
||||||
|
2 4.3 2.9 5.4 7.4
|
||||||
|
3 9.1 8.2 2.6 3.1
|
@@ -0,0 +1,47 @@
|
|||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
x, y = read_one_dimension('1D_data.txt')
|
||||||
|
for dim0 in range(y.shape[1]):
|
||||||
|
plt.plot(x, y[:, dim0], '-k')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
def read_one_dimension(file_name):
|
||||||
|
f = open(file_name, 'r')
|
||||||
|
text = f.read()
|
||||||
|
f.close()
|
||||||
|
row_list = np.array(text.split('\n')) # 根据“回车”分割成每一行
|
||||||
|
# print('文本格式:')
|
||||||
|
# print(text)
|
||||||
|
# print('row_list:')
|
||||||
|
# print(row_list)
|
||||||
|
# print('column:')
|
||||||
|
dim_column = np.array(row_list[0].split()).shape[0] # 列数
|
||||||
|
x = np.array([])
|
||||||
|
y = np.array([])
|
||||||
|
for row in row_list:
|
||||||
|
column = np.array(row.split()) # 每一行根据“空格”继续分割
|
||||||
|
# print(column)
|
||||||
|
if column.shape[0] != 0: # 解决最后一行空白的问题
|
||||||
|
x = np.append(x, [float(column[0])], axis=0) # 第一列为x数据
|
||||||
|
y_row = np.zeros(dim_column-1)
|
||||||
|
for dim0 in range(dim_column-1):
|
||||||
|
y_row[dim0] = float(column[dim0+1])
|
||||||
|
if np.array(y).shape[0] == 0:
|
||||||
|
y = [y_row]
|
||||||
|
else:
|
||||||
|
y = np.append(y, [y_row], axis=0)
|
||||||
|
# print('x:')
|
||||||
|
# print(x)
|
||||||
|
# print('y:')
|
||||||
|
# print(y)
|
||||||
|
return x, y
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,69 @@
|
|||||||
|
import numpy as np
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
x1, x2, matrix = read_two_dimension('2D_data.txt')
|
||||||
|
plot_matrix(x1, x2, matrix)
|
||||||
|
|
||||||
|
|
||||||
|
def read_two_dimension(file_name):
|
||||||
|
f = open(file_name, 'r')
|
||||||
|
text = f.read()
|
||||||
|
f.close()
|
||||||
|
row_list = np.array(text.split('\n')) # 根据“回车”分割成每一行
|
||||||
|
# print('文本格式:')
|
||||||
|
# print(text)
|
||||||
|
# print('row_list:')
|
||||||
|
# print(row_list)
|
||||||
|
# print('column:')
|
||||||
|
dim_column = np.array(row_list[0].split()).shape[0] # 列数
|
||||||
|
x1 = np.array([])
|
||||||
|
x2 = np.array([])
|
||||||
|
matrix = np.array([])
|
||||||
|
for i0 in range(row_list.shape[0]):
|
||||||
|
column = np.array(row_list[i0].split()) # 每一行根据“空格”继续分割
|
||||||
|
# print(column)
|
||||||
|
if i0 == 0:
|
||||||
|
x1_str = column[1::] # x1坐标(去除第一个在角落的值)
|
||||||
|
x1 = np.zeros(x1_str.shape[0])
|
||||||
|
for i00 in range(x1_str.shape[0]):
|
||||||
|
x1[i00] = float(x1_str[i00]) # 字符串转浮点
|
||||||
|
elif column.shape[0] != 0: # 解决最后一行空白的问题
|
||||||
|
x2 = np.append(x2, [float(column[0])], axis=0) # 第一列为x数据
|
||||||
|
matrix_row = np.zeros(dim_column-1)
|
||||||
|
for dim0 in range(dim_column-1):
|
||||||
|
matrix_row[dim0] = float(column[dim0+1])
|
||||||
|
if np.array(matrix).shape[0] == 0:
|
||||||
|
matrix = [matrix_row]
|
||||||
|
else:
|
||||||
|
matrix = np.append(matrix, [matrix_row], axis=0)
|
||||||
|
# print('x1:')
|
||||||
|
# print(x1)
|
||||||
|
# print('x2:')
|
||||||
|
# print(x2)
|
||||||
|
# print('matrix:')
|
||||||
|
# print(matrix)
|
||||||
|
return x1, x2, matrix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def plot_matrix(x1, x2, matrix):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from mpl_toolkits.mplot3d import Axes3D
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator, FormatStrFormatter
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.gca(projection='3d')
|
||||||
|
x1, x2 = np.meshgrid(x1, x2)
|
||||||
|
ax.plot_surface(x1, x2, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
plt.xlabel('x1')
|
||||||
|
plt.ylabel('x2')
|
||||||
|
ax.set_zlabel('z')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,18 @@
|
|||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置路径
|
||||||
|
|
||||||
|
|
||||||
|
f = open('a.txt', 'w')
|
||||||
|
f.write('0 ')
|
||||||
|
for k1 in np.arange(-pi, pi, 0.05):
|
||||||
|
f.write(str(k1)+' ')
|
||||||
|
f.write('\n')
|
||||||
|
for k2 in np.arange(-pi, pi, 0.05):
|
||||||
|
f.write(str(k2)+' ')
|
||||||
|
for k1 in np.arange(-pi, pi, 0.05):
|
||||||
|
data = 1000 # 运算数据
|
||||||
|
f.write(str(data)+' ')
|
||||||
|
f.write('\n')
|
||||||
|
f.close()
|
@@ -0,0 +1,68 @@
|
|||||||
|
% This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
% The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5778
|
||||||
|
|
||||||
|
clear;clc;
|
||||||
|
delta=0.1;
|
||||||
|
Z2=0;
|
||||||
|
for kx=-pi:0.1:0
|
||||||
|
for ky=-pi:0.1:pi
|
||||||
|
[V1,V2]=get_vector(Hamiltonian(kx,ky));
|
||||||
|
[Vkx1,Vkx2]=get_vector(Hamiltonian(kx+delta,ky)); % 略偏离kx的波函数
|
||||||
|
[Vky1,Vky2]=get_vector(Hamiltonian(kx,ky+delta)); % 略偏离ky的波函数
|
||||||
|
[Vkxky1,Vkxky2]=get_vector(Hamiltonian(kx+delta,ky+delta)); % 略偏离kx,ky的波函数
|
||||||
|
|
||||||
|
Ux = dot_and_det(V1, Vkx1, V2, Vkx2);
|
||||||
|
Uy = dot_and_det(V1, Vky1, V2, Vky2);
|
||||||
|
Ux_y = dot_and_det(Vky1, Vkxky1, Vky2, Vkxky2);
|
||||||
|
Uy_x = dot_and_det(Vkx1, Vkxky1, Vkx2, Vkxky2);
|
||||||
|
|
||||||
|
F=imag(log(Ux*Uy_x*(conj(Ux_y))*(conj(Uy))));
|
||||||
|
A=imag(log(Ux))+imag(log(Uy_x))+imag(log(conj(Ux_y)))+imag(log(conj(Uy)));
|
||||||
|
|
||||||
|
Z2 = Z2+(A-F)/(2*pi);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Z2= mod(Z2, 2)
|
||||||
|
|
||||||
|
|
||||||
|
function dd = dot_and_det(a1,b1,a2,b2) % 内积组成的矩阵对应的行列式
|
||||||
|
x1=a1'*b1;
|
||||||
|
x2=a2'*b2;
|
||||||
|
x3=a1'*b2;
|
||||||
|
x4=a2'*b1;
|
||||||
|
dd =x1*x2-x3*x4;
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function [vector_new_1, vector_new_2] = get_vector(H)
|
||||||
|
[vector,eigenvalue] = eig(H);
|
||||||
|
[eigenvalue, index]=sort(diag(eigenvalue), 'ascend');
|
||||||
|
vector_new_2 = vector(:, index(2));
|
||||||
|
vector_new_1 = vector(:, index(1));
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function H=Hamiltonian(kx,ky) % BHZ模型
|
||||||
|
A=0.3645/5;
|
||||||
|
B=-0.686/25;
|
||||||
|
C=0;
|
||||||
|
D=-0.512/25;
|
||||||
|
M=-0.01;
|
||||||
|
|
||||||
|
H=zeros(4,4);
|
||||||
|
varepsilon = C-2*D*(2-cos(kx)-cos(ky));
|
||||||
|
d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky));
|
||||||
|
d1_d2 = A*(sin(kx)+1j*sin(ky));
|
||||||
|
H(1, 1) = varepsilon+d3;
|
||||||
|
H(2, 2) = varepsilon-d3;
|
||||||
|
H(1, 2) = conj(d1_d2);
|
||||||
|
H(2, 1) = d1_d2 ;
|
||||||
|
|
||||||
|
varepsilon = C-2*D*(2-cos(-kx)-cos(-ky));
|
||||||
|
d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky));
|
||||||
|
d1_d2 = A*(sin(-kx)+1j*sin(-ky));
|
||||||
|
H(3, 3) = varepsilon+d3;
|
||||||
|
H(4, 4) = varepsilon-d3;
|
||||||
|
H(3, 4) = d1_d2 ;
|
||||||
|
H(4, 3) = conj(d1_d2);
|
||||||
|
end
|
@@ -0,0 +1,88 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5778
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import * # 引入pi, cos等
|
||||||
|
import cmath
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(kx, ky): # BHZ模型
|
||||||
|
A=0.3645/5
|
||||||
|
B=-0.686/25
|
||||||
|
C=0
|
||||||
|
D=-0.512/25
|
||||||
|
M=-0.01
|
||||||
|
matrix = np.zeros((4, 4))*(1+0j)
|
||||||
|
|
||||||
|
varepsilon = C-2*D*(2-cos(kx)-cos(ky))
|
||||||
|
d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky))
|
||||||
|
d1_d2 = A*(sin(kx)+1j*sin(ky))
|
||||||
|
matrix[0, 0] = varepsilon+d3
|
||||||
|
matrix[1, 1] = varepsilon-d3
|
||||||
|
matrix[0, 1] = np.conj(d1_d2)
|
||||||
|
matrix[1, 0] = d1_d2
|
||||||
|
|
||||||
|
varepsilon = C-2*D*(2-cos(-kx)-cos(-ky))
|
||||||
|
d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky))
|
||||||
|
d1_d2 = A*(sin(-kx)+1j*sin(-ky))
|
||||||
|
matrix[2, 2] = varepsilon+d3
|
||||||
|
matrix[3, 3] = varepsilon-d3
|
||||||
|
matrix[2, 3] = d1_d2
|
||||||
|
matrix[3, 2] = np.conj(d1_d2)
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_clock = time.perf_counter()
|
||||||
|
delta = 0.1
|
||||||
|
Z2 = 0 # Z2数
|
||||||
|
for kx in np.arange(-pi, 0, delta):
|
||||||
|
print(kx)
|
||||||
|
for ky in np.arange(-pi, pi, delta):
|
||||||
|
H = hamiltonian(kx, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数1
|
||||||
|
vector2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 价带波函数2
|
||||||
|
|
||||||
|
H_delta_kx = hamiltonian(kx+delta, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
|
||||||
|
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数1
|
||||||
|
vector_delta_kx2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离kx的波函数2
|
||||||
|
|
||||||
|
H_delta_ky = hamiltonian(kx, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
|
||||||
|
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数1
|
||||||
|
vector_delta_ky2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离ky的波函数2
|
||||||
|
|
||||||
|
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
|
||||||
|
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数1
|
||||||
|
vector_delta_kx_ky2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离kx和ky的波函数2
|
||||||
|
|
||||||
|
Ux = dot_and_det(vector, vector_delta_kx, vector2, vector_delta_kx2)
|
||||||
|
Uy = dot_and_det(vector, vector_delta_ky, vector2, vector_delta_ky2)
|
||||||
|
Ux_y = dot_and_det(vector_delta_ky, vector_delta_kx_ky, vector_delta_ky2, vector_delta_kx_ky2)
|
||||||
|
Uy_x = dot_and_det(vector_delta_kx, vector_delta_kx_ky, vector_delta_kx2, vector_delta_kx_ky2)
|
||||||
|
|
||||||
|
F = np.imag(cmath.log(Ux*Uy_x*np.conj(Ux_y)*np.conj(Uy)))
|
||||||
|
A = np.imag(cmath.log(Ux))+np.imag(cmath.log(Uy_x))+np.imag(cmath.log(np.conj(Ux_y)))+np.imag(cmath.log(np.conj(Uy)))
|
||||||
|
Z2 = Z2 + (A-F)/(2*pi)
|
||||||
|
print('Z2 = ', Z2) # Z2数
|
||||||
|
end_clock = time.perf_counter()
|
||||||
|
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
|
||||||
|
|
||||||
|
|
||||||
|
def dot_and_det(a1, b1, a2, b2): # 内积组成的矩阵对应的行列式
|
||||||
|
x1 = np.dot(np.conj(a1), b1)
|
||||||
|
x2 = np.dot(np.conj(a2), b2)
|
||||||
|
x3 = np.dot(np.conj(a1), b2)
|
||||||
|
x4 = np.dot(np.conj(a2), b1)
|
||||||
|
return x1*x2-x3*x4
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,98 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5778
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import * # 引入pi, cos等
|
||||||
|
import cmath
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian1(kx, ky): # Half BHZ for spin up
|
||||||
|
A=0.3645/5
|
||||||
|
B=-0.686/25
|
||||||
|
C=0
|
||||||
|
D=-0.512/25
|
||||||
|
M=-0.01
|
||||||
|
matrix = np.zeros((2, 2))*(1+0j)
|
||||||
|
varepsilon = C-2*D*(2-cos(kx)-cos(ky))
|
||||||
|
d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky))
|
||||||
|
d1_d2 = A*(sin(kx)+1j*sin(ky))
|
||||||
|
|
||||||
|
matrix[0, 0] = varepsilon+d3
|
||||||
|
matrix[1, 1] = varepsilon-d3
|
||||||
|
matrix[0, 1] = np.conj(d1_d2)
|
||||||
|
matrix[1, 0] = d1_d2
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
def hamiltonian2(kx, ky): # Half BHZ for spin down
|
||||||
|
A=0.3645/5
|
||||||
|
B=-0.686/25
|
||||||
|
C=0
|
||||||
|
D=-0.512/25
|
||||||
|
M=-0.01
|
||||||
|
matrix = np.zeros((2, 2))*(1+0j)
|
||||||
|
varepsilon = C-2*D*(2-cos(-kx)-cos(-ky))
|
||||||
|
d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky))
|
||||||
|
d1_d2 = A*(sin(-kx)+1j*sin(-ky))
|
||||||
|
|
||||||
|
matrix[0, 0] = varepsilon+d3
|
||||||
|
matrix[1, 1] = varepsilon-d3
|
||||||
|
matrix[0, 1] = d1_d2
|
||||||
|
matrix[1, 0] = np.conj(d1_d2)
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_clock = time.perf_counter()
|
||||||
|
delta = 0.1
|
||||||
|
for i0 in range(2):
|
||||||
|
if i0 == 0:
|
||||||
|
hamiltonian = hamiltonian1
|
||||||
|
else:
|
||||||
|
hamiltonian = hamiltonian2
|
||||||
|
chern_number = 0 # 陈数初始化
|
||||||
|
for kx in np.arange(-pi, pi, delta):
|
||||||
|
print(kx)
|
||||||
|
for ky in np.arange(-pi, pi, delta):
|
||||||
|
H = hamiltonian(kx, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
|
||||||
|
|
||||||
|
H_delta_kx = hamiltonian(kx+delta, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
|
||||||
|
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
|
||||||
|
|
||||||
|
H_delta_ky = hamiltonian(kx, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
|
||||||
|
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
|
||||||
|
|
||||||
|
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
|
||||||
|
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
|
||||||
|
|
||||||
|
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
|
||||||
|
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
|
||||||
|
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
|
||||||
|
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
|
||||||
|
|
||||||
|
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
|
||||||
|
# 陈数(chern number)
|
||||||
|
chern_number = chern_number + F
|
||||||
|
chern_number = chern_number/(2*pi*1j)
|
||||||
|
if i0 == 0:
|
||||||
|
chern_number_up = chern_number
|
||||||
|
else:
|
||||||
|
chern_number_down = chern_number
|
||||||
|
spin_chern_number = (chern_number_up-chern_number_down)/2
|
||||||
|
print('Chern number for spin up = ', chern_number_up)
|
||||||
|
print('Chern number for spin down = ', chern_number_down)
|
||||||
|
print('Spin chern number = ', spin_chern_number)
|
||||||
|
end_clock = time.perf_counter()
|
||||||
|
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,64 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6077
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
n = 0.5
|
||||||
|
k1 = np.arange(-n*pi, n*pi, n/50)
|
||||||
|
k2 = np.arange(-n*pi, n*pi, n/50)
|
||||||
|
plot_bands_two_dimension_direct(k1, k2, hamiltonian)
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(kx,kz,ky=0): # surface states of Weyl semimetal
|
||||||
|
A = 1
|
||||||
|
H = A*kx
|
||||||
|
return H
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_x():
|
||||||
|
return np.array([[0, 1],[1, 0]])
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_y():
|
||||||
|
return np.array([[0, -1j],[1j, 0]])
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_z():
|
||||||
|
return np.array([[1, 0],[0, -1]])
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_two_dimension_direct(k1, k2, hamiltonian):
|
||||||
|
from mpl_toolkits.mplot3d import Axes3D
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator, FormatStrFormatter
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.gca(projection='3d')
|
||||||
|
dim1 = k1.shape[0]
|
||||||
|
dim2 = k2.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim2, dim1))
|
||||||
|
i0 = 0
|
||||||
|
for k10 in k1:
|
||||||
|
j0 = 0
|
||||||
|
for k20 in k2:
|
||||||
|
if (k10**2+k20**2 <= 1):
|
||||||
|
eigenvalue_k[j0, i0] = hamiltonian(k10, k20)
|
||||||
|
else:
|
||||||
|
eigenvalue_k[j0, i0] = 'nan'
|
||||||
|
j0 += 1
|
||||||
|
i0 += 1
|
||||||
|
k1, k2 = np.meshgrid(k1, k2)
|
||||||
|
ax.scatter(k1, k2, eigenvalue_k)
|
||||||
|
plt.xlabel('kx')
|
||||||
|
plt.ylabel('kz')
|
||||||
|
ax.set_zlabel('E')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,67 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6077
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
n = 0.5
|
||||||
|
k1 = np.arange(-n*pi, n*pi, n/20)
|
||||||
|
k2 = np.arange(-n*pi, n*pi, n/20)
|
||||||
|
plot_bands_two_dimension(k1, k2, hamiltonian)
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(kx,kz,ky=0): # Weyl semimetal
|
||||||
|
A = 1
|
||||||
|
M0 = 1
|
||||||
|
M1 = 1
|
||||||
|
H = A*(kx*sigma_x()+ky*sigma_y())+(M0-M1*(kx**2+ky**2+kz**2))*sigma_z()
|
||||||
|
return H
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_x():
|
||||||
|
return np.array([[0, 1],[1, 0]])
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_y():
|
||||||
|
return np.array([[0, -1j],[1j, 0]])
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_z():
|
||||||
|
return np.array([[1, 0],[0, -1]])
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_two_dimension(k1, k2, hamiltonian):
|
||||||
|
from mpl_toolkits.mplot3d import Axes3D
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator, FormatStrFormatter
|
||||||
|
dim = hamiltonian(0, 0).shape[0]
|
||||||
|
dim1 = k1.shape[0]
|
||||||
|
dim2 = k2.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim2, dim1, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k10 in k1:
|
||||||
|
j0 = 0
|
||||||
|
for k20 in k2:
|
||||||
|
matrix0 = hamiltonian(k10, k20)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
j0 += 1
|
||||||
|
i0 += 1
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.gca(projection='3d')
|
||||||
|
k1, k2 = np.meshgrid(k1, k2)
|
||||||
|
for dim0 in range(dim):
|
||||||
|
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
plt.xlabel('kx')
|
||||||
|
plt.ylabel('kz')
|
||||||
|
ax.set_zlabel('E')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,77 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6260
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import * # 引入sqrt(), pi, exp等
|
||||||
|
import cmath # 要处理复数情况,用到cmath.exp()
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k1, k2, M=0, t1=1, a=1/sqrt(3)): # Haldane哈密顿量(a为原子间距,不赋值的话默认为1/sqrt(3))
|
||||||
|
h0 = np.zeros((2, 2))*(1+0j)
|
||||||
|
h1 = np.zeros((2, 2))*(1+0j)
|
||||||
|
h2 = np.zeros((2, 2))*(1+0j)
|
||||||
|
|
||||||
|
# 质量项(mass term), 用于打开带隙
|
||||||
|
h0[0, 0] = M
|
||||||
|
h0[1, 1] = -M
|
||||||
|
|
||||||
|
# 最近邻项
|
||||||
|
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
|
||||||
|
h1[0, 1] = h1[1, 0].conj()
|
||||||
|
|
||||||
|
# # 最近邻项也可写成这种形式
|
||||||
|
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
|
||||||
|
# h1[0, 1] = h1[1, 0].conj()
|
||||||
|
|
||||||
|
matrix = h0 + h1
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
a = 1/sqrt(3)
|
||||||
|
Gamma0 = np.array([0, 0])
|
||||||
|
M0 = np.array([0, 2*pi/3/a])
|
||||||
|
K0 = np.array([2*np.sqrt(3)*pi/9/a, 2*pi/3/a])
|
||||||
|
|
||||||
|
kn = 100 # 每个区域的取点数
|
||||||
|
n = 3 # n个区域(K-Gamma,Gamma-M, M-K)
|
||||||
|
k1_array = np.zeros(kn*n)
|
||||||
|
k2_array = np.zeros(kn*n)
|
||||||
|
|
||||||
|
# K-Gamma轴
|
||||||
|
k1_array[0:kn] = np.linspace(0, K0[0], kn)[::-1] # [::-1]表示反转数组
|
||||||
|
k2_array[0:kn] = np.linspace(0, K0[1], kn)[::-1]
|
||||||
|
|
||||||
|
# Gamma-M轴
|
||||||
|
k1_array[kn:2*kn] = np.zeros(kn)
|
||||||
|
k2_array[kn:2*kn] = np.linspace(0, M0[1], kn)
|
||||||
|
|
||||||
|
# M-K轴
|
||||||
|
k1_array[2*kn:3*kn] = np.linspace(0, K0[0], kn)
|
||||||
|
k2_array[2*kn:3*kn] = np.ones(kn)*M0[1]
|
||||||
|
|
||||||
|
i0 = 0
|
||||||
|
dim = hamiltonian(0, 0).shape[0]
|
||||||
|
eigenvalue_k = np.zeros((kn*n, dim))
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
for kn0 in range(kn*n):
|
||||||
|
k1 = k1_array[kn0]
|
||||||
|
k2 = k2_array[kn0]
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(hamiltonian(k1, k2))
|
||||||
|
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
i0 += 1
|
||||||
|
for dim0 in range(dim):
|
||||||
|
plt.plot(range(kn*n), eigenvalue_k[:, dim0], '-k')
|
||||||
|
plt.ylabel('E')
|
||||||
|
ax.set_xticks([0, kn, 2*kn, 3*kn])
|
||||||
|
ax.set_xticklabels(['K', 'Gamma', 'M', 'K'])
|
||||||
|
plt.xlim(0, n*kn)
|
||||||
|
plt.grid(axis='x',c='r',linestyle='--')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,240 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6352
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import copy
|
||||||
|
import time
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data')
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_time = time.time()
|
||||||
|
h00 = matrix_00() # 方格子模型
|
||||||
|
h01 = matrix_01() # 方格子模型
|
||||||
|
fermi_energy = 0.1
|
||||||
|
write_transmission_matrix(fermi_energy, h00, h01) # 输出无散射的散射矩阵
|
||||||
|
end_time = time.time()
|
||||||
|
print('运行时间=', end_time - start_time, '秒')
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_00(width=4):
|
||||||
|
h00 = np.zeros((width, width))
|
||||||
|
for width0 in range(width-1):
|
||||||
|
h00[width0, width0+1] = 1
|
||||||
|
h00[width0+1, width0] = 1
|
||||||
|
return h00
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_01(width=4):
|
||||||
|
h01 = np.identity(width)
|
||||||
|
return h01
|
||||||
|
|
||||||
|
|
||||||
|
def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵
|
||||||
|
transfer = np.zeros((2*dim, 2*dim))*(0+0j)
|
||||||
|
transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00)
|
||||||
|
transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj())
|
||||||
|
transfer[dim:2*dim, 0:dim] = np.identity(dim)
|
||||||
|
transfer[dim:2*dim, dim:2*dim] = 0
|
||||||
|
return transfer
|
||||||
|
|
||||||
|
|
||||||
|
def complex_wave_vector(fermi_energy, h00, h01, dim): # 获取通道的复数波矢,并按照波矢的实部Re(k)排序
|
||||||
|
transfer = transfer_matrix(fermi_energy, h00, h01, dim)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(transfer)
|
||||||
|
k_channel = np.log(eigenvalue)/1j
|
||||||
|
ind = np.argsort(np.real(k_channel))
|
||||||
|
k_channel = np.sort(k_channel)
|
||||||
|
temp = np.zeros((2*dim, 2*dim))*(1+0j)
|
||||||
|
temp2 = np.zeros((2*dim))*(1+0j)
|
||||||
|
i0 = 0
|
||||||
|
for ind0 in ind:
|
||||||
|
temp[:, i0] = eigenvector[:, ind0]
|
||||||
|
temp2[i0] = eigenvalue[ind0]
|
||||||
|
i0 += 1
|
||||||
|
eigenvalue = copy.deepcopy(temp2)
|
||||||
|
temp = normalization_of_eigenvector(temp[0:dim, :], dim)
|
||||||
|
velocity = np.zeros((2*dim))*(1+0j)
|
||||||
|
for dim0 in range(2*dim):
|
||||||
|
velocity[dim0] = eigenvalue[dim0]*np.dot(np.dot(temp[0:dim, :].transpose().conj(), h01),temp[0:dim, :])[dim0, dim0]
|
||||||
|
velocity = -2*np.imag(velocity)
|
||||||
|
eigenvector = copy.deepcopy(temp)
|
||||||
|
return k_channel, velocity, eigenvalue, eigenvector # 返回通道的对应的波矢、费米速度、本征值、本征态
|
||||||
|
|
||||||
|
|
||||||
|
def normalization_of_eigenvector(eigenvector, dim): # 波函数归一化
|
||||||
|
factor = np.zeros(2*dim)*(1+0j)
|
||||||
|
for dim0 in range(dim):
|
||||||
|
factor = factor+np.square(np.abs(eigenvector[dim0, :]))
|
||||||
|
for dim0 in range(2*dim):
|
||||||
|
eigenvector[:, dim0] = eigenvector[:, dim0]/np.sqrt(factor[dim0])
|
||||||
|
return eigenvector
|
||||||
|
|
||||||
|
|
||||||
|
def calculation_of_lambda_u_f(fermi_energy, h00, h01, dim): # 对所有通道(包括active和evanescent)进行分类,并计算F
|
||||||
|
k_channel, velocity, eigenvalue, eigenvector = complex_wave_vector(fermi_energy, h00, h01, dim)
|
||||||
|
ind_right_active = 0; ind_right_evanescent = 0; ind_left_active = 0; ind_left_evanescent = 0
|
||||||
|
k_right = np.zeros(dim)*(1+0j); k_left = np.zeros(dim)*(1+0j)
|
||||||
|
velocity_right = np.zeros(dim)*(1+0j); velocity_left = np.zeros(dim)*(1+0j)
|
||||||
|
lambda_right = np.zeros(dim)*(1+0j); lambda_left = np.zeros(dim)*(1+0j)
|
||||||
|
u_right = np.zeros((dim, dim))*(1+0j); u_left = np.zeros((dim, dim))*(1+0j)
|
||||||
|
for dim0 in range(2*dim):
|
||||||
|
if_active = if_active_channel(k_channel[dim0])
|
||||||
|
direction = direction_of_channel(velocity[dim0], k_channel[dim0])
|
||||||
|
if direction == 1: # 向右运动的通道
|
||||||
|
if if_active == 1: # 可传播通道(active channel)
|
||||||
|
k_right[ind_right_active] = k_channel[dim0]
|
||||||
|
velocity_right[ind_right_active] = velocity[dim0]
|
||||||
|
lambda_right[ind_right_active] = eigenvalue[dim0]
|
||||||
|
u_right[:, ind_right_active] = eigenvector[:, dim0]
|
||||||
|
ind_right_active += 1
|
||||||
|
else: # 衰减通道(evanescent channel)
|
||||||
|
k_right[dim-1-ind_right_evanescent] = k_channel[dim0]
|
||||||
|
velocity_right[dim-1-ind_right_evanescent] = velocity[dim0]
|
||||||
|
lambda_right[dim-1-ind_right_evanescent] = eigenvalue[dim0]
|
||||||
|
u_right[:, dim-1-ind_right_evanescent] = eigenvector[:, dim0]
|
||||||
|
ind_right_evanescent += 1
|
||||||
|
else: # 向左运动的通道
|
||||||
|
if if_active == 1: # 可传播通道(active channel)
|
||||||
|
k_left[ind_left_active] = k_channel[dim0]
|
||||||
|
velocity_left[ind_left_active] = velocity[dim0]
|
||||||
|
lambda_left[ind_left_active] = eigenvalue[dim0]
|
||||||
|
u_left[:, ind_left_active] = eigenvector[:, dim0]
|
||||||
|
ind_left_active += 1
|
||||||
|
else: # 衰减通道(evanescent channel)
|
||||||
|
k_left[dim-1-ind_left_evanescent] = k_channel[dim0]
|
||||||
|
velocity_left[dim-1-ind_left_evanescent] = velocity[dim0]
|
||||||
|
lambda_left[dim-1-ind_left_evanescent] = eigenvalue[dim0]
|
||||||
|
u_left[:, dim-1-ind_left_evanescent] = eigenvector[:, dim0]
|
||||||
|
ind_left_evanescent += 1
|
||||||
|
lambda_matrix_right = np.diag(lambda_right)
|
||||||
|
lambda_matrix_left = np.diag(lambda_left)
|
||||||
|
f_right = np.dot(np.dot(u_right, lambda_matrix_right), np.linalg.inv(u_right))
|
||||||
|
f_left = np.dot(np.dot(u_left, lambda_matrix_left), np.linalg.inv(u_left))
|
||||||
|
return k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active
|
||||||
|
# 分别返回向右和向左的运动的波矢k、费米速度velocity、F值、U值、可向右传播的通道数
|
||||||
|
|
||||||
|
|
||||||
|
def if_active_channel(k_channel): # 判断是可传播通道还是衰减通道
|
||||||
|
if np.abs(np.imag(k_channel)) < 1e-7:
|
||||||
|
if_active = 1
|
||||||
|
else:
|
||||||
|
if_active = 0
|
||||||
|
return if_active
|
||||||
|
|
||||||
|
|
||||||
|
def direction_of_channel(velocity, k_channel): # 判断通道对应的费米速度方向
|
||||||
|
if if_active_channel(k_channel) == 1:
|
||||||
|
direction = np.sign(velocity)
|
||||||
|
else:
|
||||||
|
direction = np.sign(np.imag(k_channel))
|
||||||
|
return direction
|
||||||
|
|
||||||
|
|
||||||
|
def calculation_of_green_function(fermi_energy, h00, h01, dim, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 计算格林函数
|
||||||
|
k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active = calculation_of_lambda_u_f(fermi_energy, h00, h01, dim)
|
||||||
|
right_self_energy = np.dot(h01, f_right)
|
||||||
|
left_self_energy = np.dot(h01.transpose().conj(), np.linalg.inv(f_left))
|
||||||
|
nx = 300
|
||||||
|
for nx0 in range(nx):
|
||||||
|
if nx0 == 0:
|
||||||
|
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-left_self_energy)
|
||||||
|
green_00_n = copy.deepcopy(green_nn_n)
|
||||||
|
green_0n_n = copy.deepcopy(green_nn_n)
|
||||||
|
green_n0_n = copy.deepcopy(green_nn_n)
|
||||||
|
elif nx0 != nx-1:
|
||||||
|
if scatter_type == 0: # 无散射
|
||||||
|
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
|
||||||
|
elif scatter_type == 1: # 势垒散射
|
||||||
|
h00_scatter = h00 + scatter_intensity * np.identity(dim)
|
||||||
|
if int(nx/2)-int(scatter_length/2) <= nx0 < int(nx/2)+int((scatter_length+1)/2):
|
||||||
|
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00_scatter - np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
|
||||||
|
else:
|
||||||
|
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
|
||||||
|
else:
|
||||||
|
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-right_self_energy-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
|
||||||
|
|
||||||
|
green_00_n = green_00_n+np.dot(np.dot(np.dot(np.dot(green_0n_n, h01), green_nn_n), h01.transpose().conj()), green_n0_n)
|
||||||
|
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
|
||||||
|
green_n0_n = np.dot(np.dot(green_nn_n, h01.transpose().conj()), green_n0_n)
|
||||||
|
return green_00_n, green_n0_n, k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active
|
||||||
|
|
||||||
|
|
||||||
|
def transmission_with_detailed_modes(fermi_energy, h00, h01, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 计算散射矩阵
|
||||||
|
dim = h00.shape[0]
|
||||||
|
green_00_n, green_n0_n, k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active = calculation_of_green_function(fermi_energy, h00, h01, dim, scatter_type, scatter_intensity, scatter_length)
|
||||||
|
temp = np.dot(h01.transpose().conj(), np.linalg.inv(f_right)-np.linalg.inv(f_left))
|
||||||
|
transmission_matrix = np.dot(np.dot(np.linalg.inv(u_right), np.dot(green_n0_n, temp)), u_right)
|
||||||
|
reflection_matrix = np.dot(np.dot(np.linalg.inv(u_left), np.dot(green_00_n, temp)-np.identity(dim)), u_right)
|
||||||
|
for dim0 in range(dim):
|
||||||
|
for dim1 in range(dim):
|
||||||
|
if_active = if_active_channel(k_right[dim0])*if_active_channel(k_right[dim1])
|
||||||
|
if if_active == 1:
|
||||||
|
transmission_matrix[dim0, dim1] = np.sqrt(np.abs(velocity_right[dim0]/velocity_right[dim1])) * transmission_matrix[dim0, dim1]
|
||||||
|
reflection_matrix[dim0, dim1] = np.sqrt(np.abs(velocity_left[dim0] / velocity_right[dim1]))*reflection_matrix[dim0, dim1]
|
||||||
|
else:
|
||||||
|
transmission_matrix[dim0, dim1] = 0
|
||||||
|
reflection_matrix[dim0, dim1] = 0
|
||||||
|
sum_of_tran_refl_array = np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)+np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)
|
||||||
|
for sum_of_tran_refl in sum_of_tran_refl_array:
|
||||||
|
if sum_of_tran_refl > 1.001:
|
||||||
|
print('错误警告:散射矩阵的计算结果不归一! Error Alert: scattering matrix is not normalized!')
|
||||||
|
return transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active
|
||||||
|
|
||||||
|
|
||||||
|
def write_transmission_matrix(fermi_energy, h00, h01, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 输出
|
||||||
|
transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active, \
|
||||||
|
= transmission_with_detailed_modes(fermi_energy, h00, h01, scatter_type, scatter_intensity, scatter_length)
|
||||||
|
dim = h00.shape[0]
|
||||||
|
np.set_printoptions(suppress=True) # 取消科学计数法输出
|
||||||
|
print('\n可传播的通道数(向右)active_channel (right) = ', ind_right_active)
|
||||||
|
print('衰减的通道数(向右) evanescent_channel (right) = ', dim-ind_right_active, '\n')
|
||||||
|
print('向右可传播的通道数对应的波矢 k_right:\n', np.real(k_right[0:ind_right_active]))
|
||||||
|
print('向左可传播的通道数对应的波矢 k_left:\n', np.real(k_left[0:ind_right_active]), '\n')
|
||||||
|
print('向右可传播的通道数对应的费米速度 velocity_right:\n', np.real(velocity_right[0:ind_right_active]))
|
||||||
|
print('向左可传播的通道数对应的费米速度 velocity_left:\n', np.real(velocity_left[0:ind_right_active]), '\n')
|
||||||
|
print('透射矩阵 transmission_matrix:\n', np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])))
|
||||||
|
print('反射矩阵 reflection_matrix:\n', np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), '\n')
|
||||||
|
print('透射矩阵列求和 total transmission of channels =\n', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))
|
||||||
|
print('反射矩阵列求和 total reflection of channels =\n',np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))
|
||||||
|
print('透射以及反射矩阵列求和 sum of transmission and reflection of channels =\n', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0) + np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))
|
||||||
|
print('总电导 total conductance = ', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active]))), '\n')
|
||||||
|
|
||||||
|
# 下面把以上信息写入文件中
|
||||||
|
with open('a.txt', 'w') as f:
|
||||||
|
f.write('Active_channel (right or left) = ' + str(ind_right_active) + '\n')
|
||||||
|
f.write('Evanescent_channel (right or left) = ' + str(dim - ind_right_active) + '\n\n')
|
||||||
|
f.write('Channel K Velocity\n')
|
||||||
|
for ind0 in range(ind_right_active):
|
||||||
|
f.write(' '+str(ind0 + 1) + ' | '+str(np.real(k_right[ind0]))+' ' + str(np.real(velocity_right[ind0]))+'\n')
|
||||||
|
f.write('\n')
|
||||||
|
for ind0 in range(ind_right_active):
|
||||||
|
f.write(' -' + str(ind0 + 1) + ' | ' + str(np.real(k_left[ind0])) + ' ' + str(np.real(velocity_left[ind0])) + '\n')
|
||||||
|
f.write('\n\nScattering_matrix:\n ')
|
||||||
|
for ind0 in range(ind_right_active):
|
||||||
|
f.write(str(ind0+1)+' ')
|
||||||
|
f.write('\n')
|
||||||
|
for ind1 in range(ind_right_active):
|
||||||
|
f.write(' '+str(ind1+1)+' ')
|
||||||
|
for ind2 in range(ind_right_active):
|
||||||
|
f.write('%f' % np.square(np.abs(transmission_matrix[ind1, ind2]))+' ')
|
||||||
|
f.write('\n')
|
||||||
|
f.write('\n')
|
||||||
|
for ind1 in range(ind_right_active):
|
||||||
|
f.write(' -'+str(ind1+1)+' ')
|
||||||
|
for ind2 in range(ind_right_active):
|
||||||
|
f.write('%f' % np.square(np.abs(reflection_matrix[ind1, ind2]))+' ')
|
||||||
|
f.write('\n')
|
||||||
|
f.write('\n')
|
||||||
|
f.write('Total transmission of channels:\n'+str(np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))+'\n')
|
||||||
|
f.write('Total conductance = '+str(np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active]))))+'\n')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,61 @@
|
|||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
time_1 = np.array([])
|
||||||
|
time_2 = np.array([])
|
||||||
|
time_3 = np.array([])
|
||||||
|
n_all = np.arange(2,5000,200) # 测试的范围
|
||||||
|
start_all = time.process_time()
|
||||||
|
for n in n_all:
|
||||||
|
print(n)
|
||||||
|
matrix_1 = np.zeros((n,n))
|
||||||
|
matrix_2 = np.zeros((n,n))
|
||||||
|
for i0 in range(n):
|
||||||
|
for j0 in range(n):
|
||||||
|
matrix_1[i0,j0] = np.random.uniform(-10, 10)
|
||||||
|
for i0 in range(n):
|
||||||
|
for j0 in range(n):
|
||||||
|
matrix_2[i0,j0] = np.random.uniform(-10, 10)
|
||||||
|
|
||||||
|
start = time.process_time()
|
||||||
|
matrix_3 = np.dot(matrix_1, matrix_2) # 矩阵乘积
|
||||||
|
end = time.process_time()
|
||||||
|
time_1 = np.append(time_1, [end-start], axis=0)
|
||||||
|
|
||||||
|
start = time.process_time()
|
||||||
|
matrix_4 = np.linalg.inv(matrix_1) # 矩阵求逆
|
||||||
|
end = time.process_time()
|
||||||
|
time_2 = np.append(time_2, [end-start], axis=0)
|
||||||
|
|
||||||
|
start = time.process_time()
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix_1) # 求矩阵本征值
|
||||||
|
end = time.process_time()
|
||||||
|
time_3 = np.append(time_3, [end-start], axis=0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end_all = time.process_time()
|
||||||
|
print('总共运行时间:', (end_all-start_all)/60, '分')
|
||||||
|
|
||||||
|
plt.subplot(131)
|
||||||
|
plt.xlabel('n^3/10^9')
|
||||||
|
plt.ylabel('时间(秒)')
|
||||||
|
plt.title('矩阵乘积')
|
||||||
|
plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_1, 'o-')
|
||||||
|
|
||||||
|
plt.subplot(132)
|
||||||
|
plt.xlabel('n^3/10^9')
|
||||||
|
plt.title('矩阵求逆')
|
||||||
|
plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_2, 'o-')
|
||||||
|
|
||||||
|
plt.subplot(133)
|
||||||
|
plt.xlabel('n^3/10^9')
|
||||||
|
plt.title('求矩阵本征值')
|
||||||
|
plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_3, 'o-')
|
||||||
|
|
||||||
|
plt.rcParams['font.sans-serif'] = ['SimHei'] # 在画图中正常显示中文
|
||||||
|
plt.rcParams['axes.unicode_minus'] = False # 中文化后,加上这个使正常显示负号
|
||||||
|
plt.show()
|
@@ -0,0 +1,83 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6896
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import time
|
||||||
|
import cmath
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(kx,ky,kz): # Weyl semimetal
|
||||||
|
A = 1
|
||||||
|
M0 = 1
|
||||||
|
M1 = 1
|
||||||
|
H = A*(sin(kx)*sigma_x()+sin(ky)*sigma_y())+(M0-M1*(2*(1-cos(kx))+2*(1-cos(ky))+2*(1-cos(kz))))*sigma_z()
|
||||||
|
return H
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_x():
|
||||||
|
return np.array([[0, 1],[1, 0]])
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_y():
|
||||||
|
return np.array([[0, -1j],[1j, 0]])
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_z():
|
||||||
|
return np.array([[1, 0],[0, -1]])
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_time = time.time()
|
||||||
|
n = 50
|
||||||
|
delta = 2*pi/n
|
||||||
|
kz_array = np.arange(-pi, pi, 0.1)
|
||||||
|
chern_number_array = np.zeros(kz_array.shape[0])
|
||||||
|
i0 = 0
|
||||||
|
for kz in kz_array:
|
||||||
|
print('kz=', kz)
|
||||||
|
chern_number = 0 # 陈数初始化
|
||||||
|
for kx in np.arange(-pi, pi, 2*pi/n):
|
||||||
|
for ky in np.arange(-pi, pi, 2*pi/n):
|
||||||
|
H = hamiltonian(kx, ky, kz)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
|
||||||
|
|
||||||
|
H_delta_kx = hamiltonian(kx+delta, ky, kz)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
|
||||||
|
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
|
||||||
|
|
||||||
|
H_delta_ky = hamiltonian(kx, ky+delta, kz)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
|
||||||
|
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
|
||||||
|
|
||||||
|
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta, kz)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
|
||||||
|
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
|
||||||
|
|
||||||
|
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
|
||||||
|
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
|
||||||
|
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
|
||||||
|
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
|
||||||
|
|
||||||
|
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
|
||||||
|
|
||||||
|
# 陈数(chern number)
|
||||||
|
chern_number = chern_number + F
|
||||||
|
chern_number = chern_number/(2*pi*1j)
|
||||||
|
print('Chern number = ', chern_number, '\n')
|
||||||
|
chern_number_array[i0] = np.real(chern_number)
|
||||||
|
i0 += 1
|
||||||
|
end_time = time.time()
|
||||||
|
print('运行时间(min)=', (end_time-start_time)/60)
|
||||||
|
plt.plot(kz_array, chern_number_array, 'o-')
|
||||||
|
plt.xlabel('kz')
|
||||||
|
plt.ylabel('Chern number')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,66 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6896
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
k1 = np.arange(-pi, pi, 0.05)
|
||||||
|
k2 = np.arange(-pi, pi, 0.05)
|
||||||
|
plot_bands_two_dimension(k1, k2, hamiltonian)
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(kx,kz,ky=0): # Weyl semimetal
|
||||||
|
A = 1
|
||||||
|
M0 = 1
|
||||||
|
M1 = 1
|
||||||
|
H = A*(sin(kx)*sigma_x()+sin(ky)*sigma_y())+(M0-M1*(2*(1-cos(kx))+2*(1-cos(ky))+2*(1-cos(kz))))*sigma_z()
|
||||||
|
return H
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_x():
|
||||||
|
return np.array([[0, 1],[1, 0]])
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_y():
|
||||||
|
return np.array([[0, -1j],[1j, 0]])
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_z():
|
||||||
|
return np.array([[1, 0],[0, -1]])
|
||||||
|
|
||||||
|
|
||||||
|
def plot_bands_two_dimension(k1, k2, hamiltonian):
|
||||||
|
from mpl_toolkits.mplot3d import Axes3D
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator, FormatStrFormatter
|
||||||
|
dim = hamiltonian(0, 0).shape[0]
|
||||||
|
dim1 = k1.shape[0]
|
||||||
|
dim2 = k2.shape[0]
|
||||||
|
eigenvalue_k = np.zeros((dim2, dim1, dim))
|
||||||
|
i0 = 0
|
||||||
|
for k10 in k1:
|
||||||
|
j0 = 0
|
||||||
|
for k20 in k2:
|
||||||
|
matrix0 = hamiltonian(k10, k20)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
j0 += 1
|
||||||
|
i0 += 1
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.gca(projection='3d')
|
||||||
|
k1, k2 = np.meshgrid(k1, k2)
|
||||||
|
for dim0 in range(dim):
|
||||||
|
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
plt.xlabel('kx')
|
||||||
|
plt.ylabel('kz')
|
||||||
|
ax.set_zlabel('E')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,114 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7516
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import * # 引入pi, cos等
|
||||||
|
import cmath
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(kx, ky): # 量子反常霍尔QAH模型(该参数对应的陈数为2)
|
||||||
|
t1 = 1.0
|
||||||
|
t2 = 1.0
|
||||||
|
t3 = 0.5
|
||||||
|
m = -1.0
|
||||||
|
matrix = np.zeros((2, 2))*(1+0j)
|
||||||
|
matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky)
|
||||||
|
matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky)
|
||||||
|
matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)
|
||||||
|
matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky))
|
||||||
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_time = time.time()
|
||||||
|
n = 100 # 积分密度
|
||||||
|
delta = 1e-9 # 求导的偏离量
|
||||||
|
chern_number = 0 # 陈数初始化
|
||||||
|
for kx in np.arange(-pi, pi, 2*pi/n):
|
||||||
|
for ky in np.arange(-pi, pi, 2*pi/n):
|
||||||
|
H = hamiltonian(kx, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
|
||||||
|
|
||||||
|
H_delta_kx = hamiltonian(kx+delta, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
|
||||||
|
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
|
||||||
|
|
||||||
|
H_delta_ky = hamiltonian(kx, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
|
||||||
|
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
|
||||||
|
|
||||||
|
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
|
||||||
|
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
|
||||||
|
|
||||||
|
# vector = vector*cmath.exp(-1j*1)
|
||||||
|
# vector_delta_kx = vector_delta_kx*cmath.exp(-1j*1)
|
||||||
|
# vector_delta_ky = vector_delta_ky*cmath.exp(-1j*1)
|
||||||
|
# vector_delta_kx_ky = vector_delta_kx_ky*cmath.exp(-1j*(1+1e-8))
|
||||||
|
|
||||||
|
|
||||||
|
rand = np.random.uniform(-pi, pi)
|
||||||
|
vector_delta_kx_ky = vector_delta_kx_ky*cmath.exp(-1j*rand)
|
||||||
|
|
||||||
|
# 寻找近似的同一的规范
|
||||||
|
phase_1_pre = 0
|
||||||
|
phase_2_pre = pi
|
||||||
|
n_test = 10001
|
||||||
|
for i0 in range(n_test):
|
||||||
|
test_1 = np.sum(np.abs(vector_delta_kx_ky*cmath.exp(1j*phase_1_pre) - vector))
|
||||||
|
test_2 = np.sum(np.abs(vector_delta_kx_ky*cmath.exp(1j*phase_2_pre) - vector))
|
||||||
|
if test_1 < 1e-6:
|
||||||
|
phase = phase_1_pre
|
||||||
|
print('Done with i0=', i0)
|
||||||
|
break
|
||||||
|
if i0 == n_test-1:
|
||||||
|
phase = phase_1_pre
|
||||||
|
print('Not Found with i0=', i0)
|
||||||
|
if test_1 < test_2:
|
||||||
|
if i0 == 0:
|
||||||
|
phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
phase_1 = phase_1_pre
|
||||||
|
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
if i0 == 0:
|
||||||
|
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_2_pre
|
||||||
|
phase_1_pre = phase_1
|
||||||
|
phase_2_pre = phase_2
|
||||||
|
|
||||||
|
vector_delta_kx_ky = vector_delta_kx_ky*cmath.exp(1j*phase)
|
||||||
|
print('随机的规范=', rand) # 可注释掉
|
||||||
|
print('二分查找找到的规范=', phase) # 可注释掉
|
||||||
|
print() # 可注释掉
|
||||||
|
|
||||||
|
|
||||||
|
# 价带的波函数的贝里联络(berry connection) # 求导后内积
|
||||||
|
A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Ax(x分量)
|
||||||
|
A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ay(y分量)
|
||||||
|
|
||||||
|
A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax
|
||||||
|
A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay
|
||||||
|
|
||||||
|
# 贝里曲率(berry curvature)
|
||||||
|
F = (A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta
|
||||||
|
|
||||||
|
# 陈数(chern number)
|
||||||
|
chern_number = chern_number + F*(2*pi/n)**2
|
||||||
|
chern_number = chern_number/(2*pi*1j)
|
||||||
|
print('Chern number = ', chern_number)
|
||||||
|
end_time = time.time()
|
||||||
|
print('运行时间(min)=', (end_time-start_time)/60)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,39 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7516
|
||||||
|
"""
|
||||||
|
|
||||||
|
def find_vector_with_the_same_gauge(vector_1, vector_0):
|
||||||
|
# 寻找近似的同一的规范
|
||||||
|
phase_1_pre = 0
|
||||||
|
phase_2_pre = pi
|
||||||
|
n_test = 10001
|
||||||
|
for i0 in range(n_test):
|
||||||
|
test_1 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_1_pre) - vector_0))
|
||||||
|
test_2 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_2_pre) - vector_0))
|
||||||
|
if test_1 < 1e-6:
|
||||||
|
phase = phase_1_pre
|
||||||
|
# print('Done with i0=', i0)
|
||||||
|
break
|
||||||
|
if i0 == n_test-1:
|
||||||
|
phase = phase_1_pre
|
||||||
|
print('Gauge Not Found with i0=', i0)
|
||||||
|
if test_1 < test_2:
|
||||||
|
if i0 == 0:
|
||||||
|
phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
phase_1 = phase_1_pre
|
||||||
|
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
if i0 == 0:
|
||||||
|
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_2_pre
|
||||||
|
phase_1_pre = phase_1
|
||||||
|
phase_2_pre = phase_2
|
||||||
|
vector_1 = vector_1*cmath.exp(1j*phase)
|
||||||
|
# print('二分查找找到的规范=', phase)
|
||||||
|
return vector_1
|
34
academic_codes/2020.12.23_plot_with_matplotlib/plot_2D_scatter.py
Executable file
34
academic_codes/2020.12.23_plot_with_matplotlib/plot_2D_scatter.py
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
import numpy as np
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置文件保存的位置
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
x = [4, 3, 5, 7]
|
||||||
|
y = [6, 1, 3, 2]
|
||||||
|
value = [3, 1, 10, 2]
|
||||||
|
Plot_2D_Scatter(x, y, value, title='Plot 2D Scatter')
|
||||||
|
|
||||||
|
|
||||||
|
def Plot_2D_Scatter(x, y, value, xlabel='x', ylabel='y', title='title', filename='a'):
|
||||||
|
from matplotlib.axes._axes import _log as matplotlib_axes_logger
|
||||||
|
matplotlib_axes_logger.setLevel('ERROR') # 只显示error级别的通知
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.add_subplot(111)
|
||||||
|
plt.subplots_adjust(bottom=0.2, right=0.8, left=0.2)
|
||||||
|
for i in range(np.array(x).shape[0]):
|
||||||
|
ax.scatter(x[i], y[i], marker='o', s=100*value[i], c=(1,0,0))
|
||||||
|
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.tick_params(labelsize=15) # 设置刻度值字体大小
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
|
||||||
|
# plt.savefig(filename+'.jpg', dpi=300)
|
||||||
|
plt.show()
|
||||||
|
plt.close('all')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
40
academic_codes/2020.12.23_plot_with_matplotlib/plot_3D_scatter.py
Executable file
40
academic_codes/2020.12.23_plot_with_matplotlib/plot_3D_scatter.py
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
import numpy as np
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置文件保存的位置
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
x = [1, 3, 5, 7]
|
||||||
|
y = [2, 4, 6, 8]
|
||||||
|
z = [2, 8, 6, 1]
|
||||||
|
value = [3, 1, 10, 2]
|
||||||
|
Plot_3D_Scatter(x, y, z, value, title='Plot 3D Scatter')
|
||||||
|
|
||||||
|
|
||||||
|
def Plot_3D_Scatter(x, y, z, value, xlabel='x', ylabel='y', zlabel='z', title='title', filename='a'):
|
||||||
|
from matplotlib.axes._axes import _log as matplotlib_axes_logger
|
||||||
|
matplotlib_axes_logger.setLevel('ERROR') # 只显示error级别的通知
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from matplotlib.ticker import LinearLocator
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.add_subplot(111, projection='3d')
|
||||||
|
plt.subplots_adjust(bottom=0.1, right=0.8)
|
||||||
|
for i in range(np.array(x).shape[0]):
|
||||||
|
ax.scatter(x[i], y[i], z[i], marker='o', s=int(100*value[i]), c=(1,0,0))
|
||||||
|
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_zlabel(zlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
# ax.set_zlim(0, 20)
|
||||||
|
# ax.zaxis.set_major_locator(LinearLocator(6)) # 设置z轴主刻度的个数
|
||||||
|
# ax.zaxis.set_major_formatter('{x:.0f}') # 设置z轴主刻度的格式
|
||||||
|
ax.tick_params(labelsize=15) # 设置刻度值字体大小
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
|
||||||
|
# plt.savefig(filename+'.jpg', dpi=300)
|
||||||
|
plt.show()
|
||||||
|
plt.close('all')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
44
academic_codes/2020.12.23_plot_with_matplotlib/plot_3D_surface.py
Executable file
44
academic_codes/2020.12.23_plot_with_matplotlib/plot_3D_surface.py
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
import numpy as np
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置文件保存的位置
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
x = np.arange(-5, 5, 0.25)
|
||||||
|
y = np.arange(-5, 5, 0.25)
|
||||||
|
X, Y = np.meshgrid(x, y)
|
||||||
|
R = np.sqrt(X**2 + Y**2)
|
||||||
|
Z = np.sin(R)
|
||||||
|
Plot_3D_Surface(x,y,Z)
|
||||||
|
|
||||||
|
|
||||||
|
def Plot_3D_Surface(x,y,matrix,filename='a.jpg', titlename='Plot 3D Surface'):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator
|
||||||
|
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
|
||||||
|
plt.subplots_adjust(bottom=0.1, right=0.65) # 调整位置
|
||||||
|
x, y = np.meshgrid(x, y)
|
||||||
|
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False) # Plot the surface.
|
||||||
|
ax.set_title(titlename, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel('x', fontsize=30, fontfamily='Times New Roman') # 坐标标签
|
||||||
|
ax.set_ylabel('y', fontsize=30, fontfamily='Times New Roman') # 坐标标签
|
||||||
|
ax.set_zlabel('z', fontsize=30, fontfamily='Times New Roman') # 坐标标签
|
||||||
|
# ax.set_zlim(-1, 1) # 设置z轴的范围
|
||||||
|
ax.zaxis.set_major_locator(LinearLocator(5)) # 设置z轴主刻度的个数
|
||||||
|
ax.zaxis.set_major_formatter('{x:.2f}') # 设置z轴主刻度的格式
|
||||||
|
ax.tick_params(labelsize=15) # 设置刻度值字体大小
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
|
||||||
|
cax = plt.axes([0.75, 0.15, 0.05, 0.75]) # color bar的位置 [左,下,宽度, 高度]
|
||||||
|
cbar = fig.colorbar(surf, cax=cax) # color bar
|
||||||
|
cbar.ax.tick_params(labelsize=15) # 设置color bar刻度的字体大小
|
||||||
|
for l in cbar.ax.yaxis.get_ticklabels(): # 设置color bar刻度的字体
|
||||||
|
l.set_family('Times New Roman')
|
||||||
|
# plt.savefig(filename, dpi=800) # 保存图片文件
|
||||||
|
plt.show()
|
||||||
|
plt.close('all') # 关闭所有plt,防止循环画图时占用内存
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
42
academic_codes/2020.12.23_plot_with_matplotlib/plot_contour.py
Executable file
42
academic_codes/2020.12.23_plot_with_matplotlib/plot_contour.py
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
import numpy as np
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置文件保存的位置
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
x = np.arange(-5, 5, 0.25)
|
||||||
|
y = np.arange(-5, 5, 0.25)
|
||||||
|
X, Y = np.meshgrid(x, y)
|
||||||
|
R = np.sqrt(X**2 + Y**2)
|
||||||
|
Z = np.sin(R)
|
||||||
|
Plot_Contour(x,y,Z)
|
||||||
|
|
||||||
|
|
||||||
|
def Plot_Contour(x,y,matrix,filename='a.jpg', titlename='Plot Contour'):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
plt.subplots_adjust(bottom=0.15, right=0.7) # 调整位置
|
||||||
|
x, y = np.meshgrid(x, y)
|
||||||
|
contour = ax.contourf(x,y,matrix,cmap='jet')
|
||||||
|
ax.set_title(titlename, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel('x', fontsize=30, fontfamily='Times New Roman') # 坐标标签
|
||||||
|
ax.set_ylabel('y', fontsize=30, fontfamily='Times New Roman') # 坐标标签
|
||||||
|
# plt.xlabel('x')
|
||||||
|
# plt.ylabel('y')
|
||||||
|
ax.tick_params(labelsize=15) # 设置刻度值字体大小
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
|
||||||
|
cax = plt.axes([0.75, 0.15, 0.08, 0.73]) # color bar的位置 [左,下,宽度, 高度]
|
||||||
|
cbar = fig.colorbar(contour, cax=cax) # color bar
|
||||||
|
cbar.ax.tick_params(labelsize=15) # 设置color bar刻度的字体大小
|
||||||
|
for l in cbar.ax.yaxis.get_ticklabels(): # 设置color bar刻度的字体
|
||||||
|
l.set_family('Times New Roman')
|
||||||
|
# plt.savefig(filename, dpi=800) # 保存图片文件
|
||||||
|
plt.show()
|
||||||
|
plt.close('all') # 关闭所有plt,防止循环画图时占用内存
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
30
academic_codes/2020.12.23_plot_with_matplotlib/plot_line.py
Executable file
30
academic_codes/2020.12.23_plot_with_matplotlib/plot_line.py
Executable file
@@ -0,0 +1,30 @@
|
|||||||
|
import numpy as np
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data') # 设置文件保存的位置
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
x = np.arange(0.0, 2.0, 0.01)
|
||||||
|
y = 1 + np.sin(2 * np.pi * x)
|
||||||
|
Plot_Line(x,y)
|
||||||
|
|
||||||
|
|
||||||
|
def Plot_Line(x,y,filename='a.jpg', titlename='Plot Line'):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
plt.subplots_adjust(bottom=0.20, left=0.16)
|
||||||
|
ax.plot(x, y, '-o')
|
||||||
|
ax.grid()
|
||||||
|
ax.set_title(titlename, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel('x', fontsize=30, fontfamily='Times New Roman') # 坐标标签
|
||||||
|
ax.set_ylabel('y', fontsize=30, fontfamily='Times New Roman') # 坐标标签
|
||||||
|
ax.tick_params(labelsize=20) # 设置刻度值字体大小
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
|
||||||
|
# plt.savefig(filename, dpi=800) # 保存图片文件
|
||||||
|
plt.show()
|
||||||
|
plt.close('all') # 关闭所有plt,防止循环画图时占用内存
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,102 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_00(width, length):
|
||||||
|
h00 = np.zeros((width*length, width*length))
|
||||||
|
for x in range(length):
|
||||||
|
for y in range(width-1):
|
||||||
|
h00[x*width+y, x*width+y+1] = 1
|
||||||
|
h00[x*width+y+1, x*width+y] = 1
|
||||||
|
for x in range(length-1):
|
||||||
|
for y in range(width):
|
||||||
|
h00[x*width+y, (x+1)*width+y] = 1
|
||||||
|
h00[(x+1)*width+y, x*width+y] = 1
|
||||||
|
return h00
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_01(width, length):
|
||||||
|
h01 = np.identity(width*length)
|
||||||
|
return h01
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
height = 2 # z
|
||||||
|
width = 3 # y
|
||||||
|
length = 4 # x
|
||||||
|
eta = 1e-2
|
||||||
|
E = 0
|
||||||
|
h00 = matrix_00(width, length)
|
||||||
|
h01 = matrix_01(width, length)
|
||||||
|
G_ii_n_array = G_ii_n_with_Dyson_equation(width, length, height, E, eta, h00, h01)
|
||||||
|
for i0 in range(height):
|
||||||
|
print('z=', i0+1, ':')
|
||||||
|
for j0 in range(width):
|
||||||
|
print(' y=', j0+1, ':')
|
||||||
|
for k0 in range(length):
|
||||||
|
print(' x=', k0+1, ' ', -np.imag(G_ii_n_array[i0, k0*width+j0, k0*width+j0])/pi) # 态密度
|
||||||
|
|
||||||
|
|
||||||
|
def G_ii_n_with_Dyson_equation(width, length, height, E, eta, h00, h01):
|
||||||
|
dim = length*width
|
||||||
|
G_ii_n_array = np.zeros((height, dim, dim), dtype=complex)
|
||||||
|
G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(dim)-h00)
|
||||||
|
for i in range(height): # i为格林函数的右下指标
|
||||||
|
# 初始化开始
|
||||||
|
G_nn_n_minus = G_11_1
|
||||||
|
G_in_n_minus = G_11_1
|
||||||
|
G_ni_n_minus = G_11_1
|
||||||
|
G_ii_n_minus = G_11_1
|
||||||
|
for i0 in range(i):
|
||||||
|
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
|
||||||
|
G_nn_n_minus = G_nn_n
|
||||||
|
if i!=0:
|
||||||
|
G_in_n_minus = G_nn_n
|
||||||
|
G_ni_n_minus = G_nn_n
|
||||||
|
G_ii_n_minus = G_nn_n
|
||||||
|
# 初始化结束
|
||||||
|
for j0 in range(height-1-i): # j0为格林函数的右上指标,表示当前体系大小,即G^{(j0)}
|
||||||
|
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
|
||||||
|
G_nn_n_minus = G_nn_n
|
||||||
|
|
||||||
|
G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵
|
||||||
|
G_ii_n_minus = G_ii_n
|
||||||
|
|
||||||
|
G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n)
|
||||||
|
G_in_n_minus = G_in_n
|
||||||
|
|
||||||
|
G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus)
|
||||||
|
G_ni_n_minus = G_ni_n
|
||||||
|
G_ii_n_array[i, :, :] = G_ii_n_minus
|
||||||
|
return G_ii_n_array
|
||||||
|
|
||||||
|
|
||||||
|
def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2
|
||||||
|
dim = H00.shape[0]
|
||||||
|
G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V))
|
||||||
|
return G_nn_n
|
||||||
|
|
||||||
|
|
||||||
|
def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2
|
||||||
|
G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n)
|
||||||
|
return G_in_n
|
||||||
|
|
||||||
|
|
||||||
|
def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2
|
||||||
|
G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus)
|
||||||
|
return G_ni_n
|
||||||
|
|
||||||
|
|
||||||
|
def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i
|
||||||
|
G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus)
|
||||||
|
return G_ii_n
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,99 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_00(width, length):
|
||||||
|
h00 = np.zeros((width*length, width*length))
|
||||||
|
for x in range(length):
|
||||||
|
for y in range(width-1):
|
||||||
|
h00[x*width+y, x*width+y+1] = 1
|
||||||
|
h00[x*width+y+1, x*width+y] = 1
|
||||||
|
for x in range(length-1):
|
||||||
|
for y in range(width):
|
||||||
|
h00[x*width+y, (x+1)*width+y] = 1
|
||||||
|
h00[(x+1)*width+y, x*width+y] = 1
|
||||||
|
return h00
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_01(width, length):
|
||||||
|
h01 = np.identity(width*length)
|
||||||
|
return h01
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
height = 2 # z
|
||||||
|
width = 3 # y
|
||||||
|
length = 4 # x
|
||||||
|
eta = 1e-2
|
||||||
|
E = 0
|
||||||
|
h00 = matrix_00(width, length)
|
||||||
|
h01 = matrix_01(width, length)
|
||||||
|
G_ii_n_with_Dyson_equation_version_II(width, length, height, E, eta, h00, h01)
|
||||||
|
|
||||||
|
|
||||||
|
def G_ii_n_with_Dyson_equation_version_II(width, length, height, E, eta, h00, h01):
|
||||||
|
dim = length*width
|
||||||
|
G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(dim)-h00)
|
||||||
|
for i in range(height): # i为格林函数的右下指标
|
||||||
|
# 初始化开始
|
||||||
|
G_nn_n_minus = G_11_1
|
||||||
|
G_in_n_minus = G_11_1
|
||||||
|
G_ni_n_minus = G_11_1
|
||||||
|
G_ii_n_minus = G_11_1
|
||||||
|
for i0 in range(i):
|
||||||
|
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
|
||||||
|
G_nn_n_minus = G_nn_n
|
||||||
|
if i!=0:
|
||||||
|
G_in_n_minus = G_nn_n
|
||||||
|
G_ni_n_minus = G_nn_n
|
||||||
|
G_ii_n_minus = G_nn_n
|
||||||
|
# 初始化结束
|
||||||
|
for j0 in range(height-1-i): # j0为格林函数的右上指标,表示当前体系大小,即G^{(j0)}
|
||||||
|
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
|
||||||
|
G_nn_n_minus = G_nn_n
|
||||||
|
|
||||||
|
G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵
|
||||||
|
G_ii_n_minus = G_ii_n
|
||||||
|
|
||||||
|
G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n)
|
||||||
|
G_in_n_minus = G_in_n
|
||||||
|
|
||||||
|
G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus)
|
||||||
|
G_ni_n_minus = G_ni_n
|
||||||
|
# 输出
|
||||||
|
print('z=', i+1, ':')
|
||||||
|
for j0 in range(width):
|
||||||
|
print(' y=', j0+1, ':')
|
||||||
|
for k0 in range(length):
|
||||||
|
print(' x=', k0+1, ' ', -np.imag(G_ii_n_minus[k0*width+j0, k0*width+j0])/pi) # 态密度
|
||||||
|
|
||||||
|
|
||||||
|
def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2
|
||||||
|
dim = H00.shape[0]
|
||||||
|
G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V))
|
||||||
|
return G_nn_n
|
||||||
|
|
||||||
|
|
||||||
|
def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2
|
||||||
|
G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n)
|
||||||
|
return G_in_n
|
||||||
|
|
||||||
|
|
||||||
|
def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2
|
||||||
|
G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus)
|
||||||
|
return G_ni_n
|
||||||
|
|
||||||
|
|
||||||
|
def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i
|
||||||
|
G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus)
|
||||||
|
return G_ii_n
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,49 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(width, length, height):
|
||||||
|
h = np.zeros((width*length*height, width*length*height))
|
||||||
|
for i0 in range(length):
|
||||||
|
for j0 in range(width):
|
||||||
|
for k0 in range(height-1):
|
||||||
|
h[k0*width*length+i0*width+j0, (k0+1)*width*length+i0*width+j0] = 1
|
||||||
|
h[(k0+1)*width*length+i0*width+j0, k0*width*length+i0*width+j0] = 1
|
||||||
|
for i0 in range(length):
|
||||||
|
for j0 in range(width-1):
|
||||||
|
for k0 in range(height):
|
||||||
|
h[k0*width*length+i0*width+j0, k0*width*length+i0*width+j0+1] = 1
|
||||||
|
h[k0*width*length+i0*width+j0+1, k0*width*length+i0*width+j0] = 1
|
||||||
|
for i0 in range(length-1):
|
||||||
|
for j0 in range(width):
|
||||||
|
for k0 in range(height):
|
||||||
|
h[k0*width*length+i0*width+j0, k0*width*length+(i0+1)*width+j0] = 1
|
||||||
|
h[k0*width*length+(i0+1)*width+j0, k0*width*length+i0*width+j0] = 1
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
height = 2 # z
|
||||||
|
width = 3 # y
|
||||||
|
length = 4 # x
|
||||||
|
h = hamiltonian(width, length, height)
|
||||||
|
E = 0
|
||||||
|
green = np.linalg.inv((E+1e-2j)*np.eye(width*length*height)-h)
|
||||||
|
for k0 in range(height):
|
||||||
|
print('z=', k0+1, ':')
|
||||||
|
for j0 in range(width):
|
||||||
|
print(' y=', j0+1, ':')
|
||||||
|
for i0 in range(length):
|
||||||
|
print(' x=', i0+1, ' ', -np.imag(green[k0*width*length+i0*width+j0, k0*width*length+i0*width+j0])/pi) # 态密度
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
@@ -0,0 +1,95 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_00(width):
|
||||||
|
h00 = np.zeros((width, width))
|
||||||
|
for width0 in range(width-1):
|
||||||
|
h00[width0, width0+1] = 1
|
||||||
|
h00[width0+1, width0] = 1
|
||||||
|
return h00
|
||||||
|
|
||||||
|
|
||||||
|
def matrix_01(width):
|
||||||
|
h01 = np.identity(width)
|
||||||
|
return h01
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
width = 2
|
||||||
|
length = 3
|
||||||
|
eta = 1e-2
|
||||||
|
E = 0
|
||||||
|
h00 = matrix_00(width)
|
||||||
|
h01 = matrix_01(width)
|
||||||
|
G_ii_n_array = G_ii_n_with_Dyson_equation(width, length, E, eta, h00, h01)
|
||||||
|
for i0 in range(length):
|
||||||
|
# print('G_{'+str(i0+1)+','+str(i0+1)+'}^{('+str(length)+')}:')
|
||||||
|
# print(G_ii_n_array[i0, :, :],'\n')
|
||||||
|
print('x=', i0+1, ':')
|
||||||
|
for j0 in range(width):
|
||||||
|
print(' y=', j0+1, ' ', -np.imag(G_ii_n_array[i0, j0, j0])/pi) # 态密度
|
||||||
|
|
||||||
|
|
||||||
|
def G_ii_n_with_Dyson_equation(width, length, E, eta, h00, h01):
|
||||||
|
G_ii_n_array = np.zeros((length, width, width), complex)
|
||||||
|
G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(width)-h00)
|
||||||
|
for i in range(length): # i为格林函数的右下指标
|
||||||
|
# 初始化开始
|
||||||
|
G_nn_n_minus = G_11_1
|
||||||
|
G_in_n_minus = G_11_1
|
||||||
|
G_ni_n_minus = G_11_1
|
||||||
|
G_ii_n_minus = G_11_1
|
||||||
|
for i0 in range(i):
|
||||||
|
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
|
||||||
|
G_nn_n_minus = G_nn_n
|
||||||
|
if i!=0:
|
||||||
|
G_in_n_minus = G_nn_n
|
||||||
|
G_ni_n_minus = G_nn_n
|
||||||
|
G_ii_n_minus = G_nn_n
|
||||||
|
# 初始化结束
|
||||||
|
for j0 in range(length-1-i): # j0为格林函数的右上指标,表示当前体系大小,即G^{(j0)}
|
||||||
|
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
|
||||||
|
G_nn_n_minus = G_nn_n
|
||||||
|
|
||||||
|
G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵
|
||||||
|
G_ii_n_minus = G_ii_n
|
||||||
|
|
||||||
|
G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n)
|
||||||
|
G_in_n_minus = G_in_n
|
||||||
|
|
||||||
|
G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus)
|
||||||
|
G_ni_n_minus = G_ni_n
|
||||||
|
G_ii_n_array[i, :, :] = G_ii_n_minus
|
||||||
|
return G_ii_n_array
|
||||||
|
|
||||||
|
|
||||||
|
def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2
|
||||||
|
dim = H00.shape[0]
|
||||||
|
G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V))
|
||||||
|
return G_nn_n
|
||||||
|
|
||||||
|
|
||||||
|
def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2
|
||||||
|
G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n)
|
||||||
|
return G_in_n
|
||||||
|
|
||||||
|
|
||||||
|
def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2
|
||||||
|
G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus)
|
||||||
|
return G_ni_n
|
||||||
|
|
||||||
|
|
||||||
|
def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i
|
||||||
|
G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus)
|
||||||
|
return G_ii_n
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,41 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(width, length):
|
||||||
|
h = np.zeros((width*length, width*length))
|
||||||
|
for i0 in range(length):
|
||||||
|
for j0 in range(width-1):
|
||||||
|
h[i0*width+j0, i0*width+j0+1] = 1
|
||||||
|
h[i0*width+j0+1, i0*width+j0] = 1
|
||||||
|
for i0 in range(length-1):
|
||||||
|
for j0 in range(width):
|
||||||
|
h[i0*width+j0, (i0+1)*width+j0] = 1
|
||||||
|
h[(i0+1)*width+j0, i0*width+j0] = 1
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
width = 2
|
||||||
|
length = 3
|
||||||
|
h = hamiltonian(width, length)
|
||||||
|
E = 0
|
||||||
|
green = np.linalg.inv((E+1e-2j)*np.eye(width*length)-h)
|
||||||
|
for i0 in range(length):
|
||||||
|
# print('G_{'+str(i0+1)+','+str(i0+1)+'}^{('+str(length)+')}:')
|
||||||
|
# print(green[i0*width+0: i0*width+width, i0*width+0: i0*width+width], '\n')
|
||||||
|
print('x=', i0+1, ':')
|
||||||
|
for j0 in range(width):
|
||||||
|
print(' y=', j0+1, ' ', -np.imag(green[i0*width+j0, i0*width+j0])/pi)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
@@ -0,0 +1,50 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8491
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import cmath
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
for n in np.arange(1, 11):
|
||||||
|
print('n=', n)
|
||||||
|
width = n
|
||||||
|
length = n
|
||||||
|
B_array = np.arange(0, 1, 0.001)
|
||||||
|
eigenvalue_all = np.zeros((B_array.shape[0], width*length))
|
||||||
|
i0 = 0
|
||||||
|
for B in B_array:
|
||||||
|
# print(B)
|
||||||
|
h = hamiltonian(width, length, B)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(h)
|
||||||
|
eigenvalue_all[i0, :] = np.real(eigenvalue)
|
||||||
|
i0 += 1
|
||||||
|
plt.plot(B_array, eigenvalue_all, '.r', markersize=0.5)
|
||||||
|
plt.title('width=length='+str(n))
|
||||||
|
plt.xlabel('B*a^2/phi_0')
|
||||||
|
plt.ylabel('E')
|
||||||
|
plt.savefig('width=length='+str(n)+'.jpg', dpi=300)
|
||||||
|
plt.close('all') # 关闭所有plt,防止循环画图时占用内存
|
||||||
|
# plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(width, length, B): # 方格子哈密顿量
|
||||||
|
h = np.zeros((width*length, width*length))*(1+0j)
|
||||||
|
# y方向的跃迁
|
||||||
|
for x in range(length):
|
||||||
|
for y in range(width-1):
|
||||||
|
h[x*width+y, x*width+y+1] = 1
|
||||||
|
h[x*width+y+1, x*width+y] = 1
|
||||||
|
# x方向的跃迁
|
||||||
|
for x in range(length-1):
|
||||||
|
for y in range(width):
|
||||||
|
h[x*width+y, (x+1)*width+y] = 1*cmath.exp(-2*np.pi*1j*B*y)
|
||||||
|
h[(x+1)*width+y, x*width+y] = 1*cmath.exp(2*np.pi*1j*B*y)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@@ -0,0 +1,151 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8536
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import cmath
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k1, k2, t1=2.82*sqrt(3)/2, a=1/sqrt(3)): # 石墨烯哈密顿量(a为原子间距,不赋值的话默认为1/sqrt(3))
|
||||||
|
h = np.zeros((2, 2))*(1+0j)
|
||||||
|
h[0, 0] = 0.28/2
|
||||||
|
h[1, 1] = -0.28/2
|
||||||
|
h[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
|
||||||
|
h[0, 1] = h[1, 0].conj()
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_time = time.time()
|
||||||
|
n = 400 # 取点密度
|
||||||
|
delta = 1e-10 # 求导的偏离量
|
||||||
|
kx_array = np.linspace(-2*pi, 2*pi, n)
|
||||||
|
ky_array = np.linspace(-2*pi, 2*pi, n)
|
||||||
|
for band in range(2):
|
||||||
|
F_all = np.zeros((ky_array.shape[0], ky_array.shape[0])) # 贝里曲率
|
||||||
|
j0 = 0
|
||||||
|
for kx in kx_array:
|
||||||
|
print(kx)
|
||||||
|
i0 = 0
|
||||||
|
for ky in ky_array:
|
||||||
|
H = hamiltonian(kx, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 价带波函数
|
||||||
|
# print(np.argsort(np.real(eigenvalue))[0]) # 排序索引(从小到大)
|
||||||
|
# print(eigenvalue) # 排序前的本征值
|
||||||
|
# print(np.sort(np.real(eigenvalue))) # 排序后的本征值(从小到大)
|
||||||
|
|
||||||
|
H_delta_kx = hamiltonian(kx+delta, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
|
||||||
|
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离kx的波函数
|
||||||
|
# vector_delta_kx = find_vector_with_the_same_gauge(vector_delta_kx, vector) # 如果波函数不连续需要使用这个
|
||||||
|
|
||||||
|
H_delta_ky = hamiltonian(kx, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
|
||||||
|
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离ky的波函数
|
||||||
|
# vector_delta_ky = find_vector_with_the_same_gauge(vector_delta_ky, vector) # 如果波函数不连续需要使用这个
|
||||||
|
|
||||||
|
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
|
||||||
|
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离kx和ky的波函数
|
||||||
|
# vector_delta_kx_ky = find_vector_with_the_same_gauge(vector_delta_kx_ky, vector) # 如果波函数不连续需要使用这个
|
||||||
|
|
||||||
|
# 价带的波函数的贝里联络(berry connection) # 求导后内积
|
||||||
|
A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Ax(x分量)
|
||||||
|
A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ay(y分量)
|
||||||
|
|
||||||
|
A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax
|
||||||
|
A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay
|
||||||
|
|
||||||
|
# 贝里曲率(berry curvature)
|
||||||
|
F = ((A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta)*1j
|
||||||
|
# print(F)
|
||||||
|
F_all[i0, j0] = np.real(F)
|
||||||
|
i0 += 1
|
||||||
|
j0 += 1
|
||||||
|
plot_matrix(kx_array/pi, ky_array/pi, F_all, band)
|
||||||
|
write_matrix(kx_array/pi, ky_array/pi, F_all, band)
|
||||||
|
end_time = time.time()
|
||||||
|
print('运行时间(min)=', (end_time-start_time)/60)
|
||||||
|
|
||||||
|
|
||||||
|
def find_vector_with_the_same_gauge(vector_1, vector_0):
|
||||||
|
# 寻找近似的同一的规范
|
||||||
|
phase_1_pre = 0
|
||||||
|
phase_2_pre = pi
|
||||||
|
n_test = 10001
|
||||||
|
for i0 in range(n_test):
|
||||||
|
test_1 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_1_pre) - vector_0))
|
||||||
|
test_2 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_2_pre) - vector_0))
|
||||||
|
if test_1 < 1e-9:
|
||||||
|
phase = phase_1_pre
|
||||||
|
# print('Done with i0=', i0)
|
||||||
|
break
|
||||||
|
if i0 == n_test-1:
|
||||||
|
phase = phase_1_pre
|
||||||
|
print('Gauge Not Found with i0=', i0)
|
||||||
|
if test_1 < test_2:
|
||||||
|
if i0 == 0:
|
||||||
|
phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
phase_1 = phase_1_pre
|
||||||
|
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
if i0 == 0:
|
||||||
|
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_2_pre
|
||||||
|
phase_1_pre = phase_1
|
||||||
|
phase_2_pre = phase_2
|
||||||
|
|
||||||
|
vector_1 = vector_1*cmath.exp(1j*phase)
|
||||||
|
# print('二分查找找到的规范=', phase)
|
||||||
|
return vector_1
|
||||||
|
|
||||||
|
|
||||||
|
def plot_matrix(k1, k2, matrix, band):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from mpl_toolkits.mplot3d import Axes3D
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator, FormatStrFormatter
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.gca(projection='3d')
|
||||||
|
k1, k2 = np.meshgrid(k1, k2)
|
||||||
|
ax.plot_surface(k1, k2, matrix, cmap="rainbow", linewidth=0, antialiased=False)
|
||||||
|
plt.xlabel('kx')
|
||||||
|
plt.ylabel('ky')
|
||||||
|
ax.set_zlabel('Berry curvature')
|
||||||
|
if band==0:
|
||||||
|
plt.title('Valence Band')
|
||||||
|
else:
|
||||||
|
plt.title('Conductance Band')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
def write_matrix(k1, k2, matrix, band):
|
||||||
|
import os
|
||||||
|
os.chdir('D:/data') # 设置路径
|
||||||
|
with open('band='+str(band)+'.txt', 'w') as f:
|
||||||
|
# np.set_printoptions(suppress=True) # 取消输出科学记数法
|
||||||
|
f.write('0 ')
|
||||||
|
for k10 in k1:
|
||||||
|
f.write(str(k10)+' ')
|
||||||
|
f.write('\n')
|
||||||
|
i0 = 0
|
||||||
|
for k20 in k2:
|
||||||
|
f.write(str(k20))
|
||||||
|
for j0 in range(k1.shape[0]):
|
||||||
|
f.write(' '+str(matrix[i0, j0])+' ')
|
||||||
|
f.write('\n')
|
||||||
|
i0 += 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,114 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8536
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
import cmath
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k1, k2, t1=2.82*sqrt(3)/2, a=1/sqrt(3)): # 石墨烯哈密顿量(a为原子间距,不赋值的话默认为1/sqrt(3))
|
||||||
|
h = np.zeros((2, 2))*(1+0j)
|
||||||
|
h[0, 0] = 0.28/2
|
||||||
|
h[1, 1] = -0.28/2
|
||||||
|
h[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
|
||||||
|
h[0, 1] = h[1, 0].conj()
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_time = time.time()
|
||||||
|
n = 2000 # 取点密度
|
||||||
|
delta = 1e-9 # 求导的偏离量
|
||||||
|
for band in range(2):
|
||||||
|
F_all = [] # 贝里曲率
|
||||||
|
for kx in np.linspace(-2*pi, 2*pi, n):
|
||||||
|
for ky in [0]: # 这里只考虑ky=0对称轴上的情况 # np.linspace(-pi, pi, n):
|
||||||
|
H = hamiltonian(kx, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 价带波函数
|
||||||
|
# print(np.argsort(np.real(eigenvalue))[0]) # 排序索引(从小到大)
|
||||||
|
# print(eigenvalue) # 排序前的本征值
|
||||||
|
# print(np.sort(np.real(eigenvalue))) # 排序后的本征值(从小到大)
|
||||||
|
|
||||||
|
H_delta_kx = hamiltonian(kx+delta, ky)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
|
||||||
|
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离kx的波函数
|
||||||
|
# vector_delta_kx = find_vector_with_the_same_gauge(vector_delta_kx, vector) # 如果波函数不连续需要使用这个
|
||||||
|
|
||||||
|
H_delta_ky = hamiltonian(kx, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
|
||||||
|
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离ky的波函数
|
||||||
|
# vector_delta_ky = find_vector_with_the_same_gauge(vector_delta_ky, vector) # 如果波函数不连续需要使用这个
|
||||||
|
|
||||||
|
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
|
||||||
|
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离kx和ky的波函数
|
||||||
|
# vector_delta_kx_ky = find_vector_with_the_same_gauge(vector_delta_kx_ky, vector) # 如果波函数不连续需要使用这个
|
||||||
|
|
||||||
|
# 价带的波函数的贝里联络(berry connection) # 求导后内积
|
||||||
|
A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Ax(x分量)
|
||||||
|
A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ay(y分量)
|
||||||
|
|
||||||
|
A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax
|
||||||
|
A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay
|
||||||
|
|
||||||
|
# 贝里曲率(berry curvature)
|
||||||
|
F = ((A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta)*1j
|
||||||
|
# print(F)
|
||||||
|
F_all = np.append(F_all,[F], axis=0)
|
||||||
|
plt.plot(np.linspace(-2*pi, 2*pi, n)/pi, np.real(F_all))
|
||||||
|
plt.xlabel('k_x (pi)')
|
||||||
|
plt.ylabel('Berry curvature')
|
||||||
|
if band==0:
|
||||||
|
plt.title('Valence Band')
|
||||||
|
else:
|
||||||
|
plt.title('Conductance Band')
|
||||||
|
plt.show()
|
||||||
|
end_time = time.time()
|
||||||
|
print('运行时间(min)=', (end_time-start_time)/60)
|
||||||
|
|
||||||
|
|
||||||
|
def find_vector_with_the_same_gauge(vector_1, vector_0):
|
||||||
|
# 寻找近似的同一的规范
|
||||||
|
phase_1_pre = 0
|
||||||
|
phase_2_pre = pi
|
||||||
|
n_test = 10001
|
||||||
|
for i0 in range(n_test):
|
||||||
|
test_1 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_1_pre) - vector_0))
|
||||||
|
test_2 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_2_pre) - vector_0))
|
||||||
|
if test_1 < 1e-9:
|
||||||
|
phase = phase_1_pre
|
||||||
|
# print('Done with i0=', i0)
|
||||||
|
break
|
||||||
|
if i0 == n_test-1:
|
||||||
|
phase = phase_1_pre
|
||||||
|
print('Gauge Not Found with i0=', i0)
|
||||||
|
if test_1 < test_2:
|
||||||
|
if i0 == 0:
|
||||||
|
phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
phase_1 = phase_1_pre
|
||||||
|
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
if i0 == 0:
|
||||||
|
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2
|
||||||
|
else:
|
||||||
|
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
|
||||||
|
phase_2 = phase_2_pre
|
||||||
|
phase_1_pre = phase_1
|
||||||
|
phase_2_pre = phase_2
|
||||||
|
|
||||||
|
vector_1 = vector_1*cmath.exp(1j*phase)
|
||||||
|
# print('二分查找找到的规范=', phase)
|
||||||
|
return vector_1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,322 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8734
|
||||||
|
|
||||||
|
函数调用目录:
|
||||||
|
1. x, y = read_one_dimensional_data(filename='a')
|
||||||
|
2. x, y, matrix = read_two_dimensional_data(filename='a')
|
||||||
|
3. write_one_dimensional_data(x, y, filename='a')
|
||||||
|
4. write_two_dimensional_data(x, y, matrix, filename='a')
|
||||||
|
5. plot(x, y, xlabel='x', ylabel='y', title='', filename='a')
|
||||||
|
6. plot_3d_surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a')
|
||||||
|
7. plot_contour(x, y, matrix, xlabel='x', ylabel='y', title='', filename='a')
|
||||||
|
8. plot_2d_scatter(x, y, value, xlabel='x', ylabel='y', title='', filename='a')
|
||||||
|
9. plot_3d_surface(x, y, z, value, xlabel='x', ylabel='y', zlabel='z', title='', filename='a')
|
||||||
|
10. creat_animation(image_names, duration_time=0.5, filename='a')
|
||||||
|
11. eigenvalue_array = calculate_eigenvalue_with_one_paramete(x, matrix)
|
||||||
|
12. eigenvalue_array = calculate_eigenvalue_with_two_parameters(x, y, matrix)
|
||||||
|
|
||||||
|
函数对应的功能:
|
||||||
|
1. 读取filename.txt文件中的一维数据y(x)
|
||||||
|
2. 读取filename.txt文件中的二维数据matrix(x,y)
|
||||||
|
3. 把一维数据y(x)写入filename.txt文件
|
||||||
|
4. 把二维数据matrix(x,y)写入filename.txt文件
|
||||||
|
5. 画y(x)图,并保存到filename.jpg文件。具体画图格式可在函数中修改!
|
||||||
|
6. 画3d_surface图,并保存到filename.jpg文件。具体画图格式可在函数中修改!
|
||||||
|
7. 画contour图,并保存到filename.jpg文件。具体画图格式可在函数中修改!
|
||||||
|
8. 画2d_scatter图,并保存到filename.jpg文件。具体画图格式可在函数中修改!
|
||||||
|
9. 画3d_scatter图,并保存到filename.jpg文件。具体画图格式可在函数中修改!
|
||||||
|
10. 制作动画
|
||||||
|
11. 在参数x下,计算matrix函数的本征值eigenvalue_array[:, index]
|
||||||
|
12. 在参数(x,y)下,计算matrix函数的本征值eigenvalue_array[:, :, index]
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
# import os
|
||||||
|
# os.chdir('D:/data')
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
pass # 读取数据 + 数据处理 + 保存新数据
|
||||||
|
|
||||||
|
|
||||||
|
# 1. 读取filename.txt文件中的一维数据y(x)
|
||||||
|
def read_one_dimensional_data(filename='a'):
|
||||||
|
f = open(filename+'.txt', 'r')
|
||||||
|
text = f.read()
|
||||||
|
f.close()
|
||||||
|
row_list = np.array(text.split('\n'))
|
||||||
|
dim_column = np.array(row_list[0].split()).shape[0]
|
||||||
|
x = np.array([])
|
||||||
|
y = np.array([])
|
||||||
|
for row in row_list:
|
||||||
|
column = np.array(row.split())
|
||||||
|
if column.shape[0] != 0:
|
||||||
|
x = np.append(x, [float(column[0])], axis=0)
|
||||||
|
y_row = np.zeros(dim_column-1)
|
||||||
|
for dim0 in range(dim_column-1):
|
||||||
|
y_row[dim0] = float(column[dim0+1])
|
||||||
|
if np.array(y).shape[0] == 0:
|
||||||
|
y = [y_row]
|
||||||
|
else:
|
||||||
|
y = np.append(y, [y_row], axis=0)
|
||||||
|
return x, y
|
||||||
|
|
||||||
|
|
||||||
|
# 2. 读取filename.txt文件中的二维数据matrix(x,y)
|
||||||
|
def read_two_dimensional_data(filename='a'):
|
||||||
|
f = open(filename+'.txt', 'r')
|
||||||
|
text = f.read()
|
||||||
|
f.close()
|
||||||
|
row_list = np.array(text.split('\n'))
|
||||||
|
dim_column = np.array(row_list[0].split()).shape[0]
|
||||||
|
x = np.array([])
|
||||||
|
y = np.array([])
|
||||||
|
matrix = np.array([])
|
||||||
|
for i0 in range(row_list.shape[0]):
|
||||||
|
column = np.array(row_list[i0].split())
|
||||||
|
if i0 == 0:
|
||||||
|
x_str = column[1::]
|
||||||
|
x = np.zeros(x_str.shape[0])
|
||||||
|
for i00 in range(x_str.shape[0]):
|
||||||
|
x[i00] = float(x_str[i00])
|
||||||
|
elif column.shape[0] != 0:
|
||||||
|
y = np.append(y, [float(column[0])], axis=0)
|
||||||
|
matrix_row = np.zeros(dim_column-1)
|
||||||
|
for dim0 in range(dim_column-1):
|
||||||
|
matrix_row[dim0] = float(column[dim0+1])
|
||||||
|
if np.array(matrix).shape[0] == 0:
|
||||||
|
matrix = [matrix_row]
|
||||||
|
else:
|
||||||
|
matrix = np.append(matrix, [matrix_row], axis=0)
|
||||||
|
return x, y, matrix
|
||||||
|
|
||||||
|
|
||||||
|
# 3. 把一维数据y(x)写入filename.txt文件
|
||||||
|
def write_one_dimensional_data(x, y, filename='a'):
|
||||||
|
with open(filename+'.txt', 'w') as f:
|
||||||
|
i0 = 0
|
||||||
|
for x0 in x:
|
||||||
|
f.write(str(x0)+' ')
|
||||||
|
if len(y.shape) == 1:
|
||||||
|
f.write(str(y[i0])+'\n')
|
||||||
|
elif len(y.shape) == 2:
|
||||||
|
for j0 in range(y.shape[1]):
|
||||||
|
f.write(str(y[i0, j0])+' ')
|
||||||
|
f.write('\n')
|
||||||
|
i0 += 1
|
||||||
|
|
||||||
|
|
||||||
|
# 4. 把二维数据matrix(x,y)写入filename.txt文件
|
||||||
|
def write_two_dimensional_data(x, y, matrix, filename='a'):
|
||||||
|
with open(filename+'.txt', 'w') as f:
|
||||||
|
f.write('0 ')
|
||||||
|
for x0 in x:
|
||||||
|
f.write(str(x0)+' ')
|
||||||
|
f.write('\n')
|
||||||
|
i0 = 0
|
||||||
|
for y0 in y:
|
||||||
|
f.write(str(y0))
|
||||||
|
j0 = 0
|
||||||
|
for x0 in x:
|
||||||
|
f.write(' '+str(matrix[i0, j0])+' ')
|
||||||
|
j0 += 1
|
||||||
|
f.write('\n')
|
||||||
|
i0 += 1
|
||||||
|
|
||||||
|
|
||||||
|
# 5. 画y(x)图,并保存到filename.jpg文件。具体画图格式可在函数中修改。
|
||||||
|
def plot(x, y, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
plt.subplots_adjust(bottom=0.20, left=0.18)
|
||||||
|
ax.plot(x, y, '-o')
|
||||||
|
ax.grid()
|
||||||
|
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.tick_params(labelsize=20)
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels]
|
||||||
|
if save == 1:
|
||||||
|
plt.savefig(filename+'.jpg', dpi=300)
|
||||||
|
if show == 1:
|
||||||
|
plt.show()
|
||||||
|
plt.close('all')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 6. 画3d_surface图,并保存到filename.jpg文件。具体画图格式可在函数中修改。
|
||||||
|
def plot_3d_surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator
|
||||||
|
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
|
||||||
|
plt.subplots_adjust(bottom=0.1, right=0.65)
|
||||||
|
x, y = np.meshgrid(x, y)
|
||||||
|
if len(matrix.shape) == 2:
|
||||||
|
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
elif len(matrix.shape) == 3:
|
||||||
|
for i0 in range(matrix.shape[2]):
|
||||||
|
surf = ax.plot_surface(x, y, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_zlabel(zlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.zaxis.set_major_locator(LinearLocator(5))
|
||||||
|
ax.zaxis.set_major_formatter('{x:.2f}')
|
||||||
|
ax.tick_params(labelsize=15)
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels]
|
||||||
|
cax = plt.axes([0.80, 0.15, 0.05, 0.75])
|
||||||
|
cbar = fig.colorbar(surf, cax=cax)
|
||||||
|
cbar.ax.tick_params(labelsize=15)
|
||||||
|
for l in cbar.ax.yaxis.get_ticklabels():
|
||||||
|
l.set_family('Times New Roman')
|
||||||
|
if save == 1:
|
||||||
|
plt.savefig(filename+'.jpg', dpi=300)
|
||||||
|
if show == 1:
|
||||||
|
plt.show()
|
||||||
|
plt.close('all')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 7. 画plot_contour图,并保存到filename.jpg文件。具体画图格式可在函数中修改。
|
||||||
|
def plot_contour(x, y, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
plt.subplots_adjust(bottom=0.2, right=0.75, left = 0.16)
|
||||||
|
x, y = np.meshgrid(x, y)
|
||||||
|
contour = ax.contourf(x,y,matrix,cmap='jet')
|
||||||
|
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.tick_params(labelsize=15)
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels]
|
||||||
|
cax = plt.axes([0.78, 0.17, 0.08, 0.71])
|
||||||
|
cbar = fig.colorbar(contour, cax=cax)
|
||||||
|
cbar.ax.tick_params(labelsize=15)
|
||||||
|
for l in cbar.ax.yaxis.get_ticklabels():
|
||||||
|
l.set_family('Times New Roman')
|
||||||
|
if save == 1:
|
||||||
|
plt.savefig(filename+'.jpg', dpi=300)
|
||||||
|
if show == 1:
|
||||||
|
plt.show()
|
||||||
|
plt.close('all')
|
||||||
|
|
||||||
|
|
||||||
|
# 8. 画2d_scatter图,并保存到filename.jpg文件。具体画图格式可在函数中修改!
|
||||||
|
def plot_2d_scatter(x, y, value, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from matplotlib.axes._axes import _log as matplotlib_axes_logger
|
||||||
|
matplotlib_axes_logger.setLevel('ERROR')
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.add_subplot(111)
|
||||||
|
plt.subplots_adjust(bottom=0.2, right=0.8, left=0.2)
|
||||||
|
for i in range(np.array(x).shape[0]):
|
||||||
|
ax.scatter(x[i], y[i], marker='o', s=100*value[i], c=(1,0,0))
|
||||||
|
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.tick_params(labelsize=15)
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels]
|
||||||
|
if save == 1:
|
||||||
|
plt.savefig(filename+'.jpg', dpi=300)
|
||||||
|
if show == 1:
|
||||||
|
plt.show()
|
||||||
|
plt.close('all')
|
||||||
|
|
||||||
|
|
||||||
|
# 9. 画3d_scatter图,并保存到filename.jpg文件。具体画图格式可在函数中修改!
|
||||||
|
def plot_3d_scatter(x, y, z, value, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from matplotlib.ticker import LinearLocator
|
||||||
|
from matplotlib.axes._axes import _log as matplotlib_axes_logger
|
||||||
|
matplotlib_axes_logger.setLevel('ERROR')
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.add_subplot(111, projection='3d')
|
||||||
|
plt.subplots_adjust(bottom=0.1, right=0.8)
|
||||||
|
for i in range(np.array(x).shape[0]):
|
||||||
|
ax.scatter(x[i], y[i], z[i], marker='o', s=int(100*value[i]), c=(1,0,0))
|
||||||
|
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_zlabel(zlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.tick_params(labelsize=15)
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels]
|
||||||
|
if save == 1:
|
||||||
|
plt.savefig(filename+'.jpg', dpi=300)
|
||||||
|
if show == 1:
|
||||||
|
plt.show()
|
||||||
|
plt.close('all')
|
||||||
|
|
||||||
|
|
||||||
|
# 10. 制作动画
|
||||||
|
def creat_animation(image_names, duration_time=0.5, filename='a'):
|
||||||
|
import imageio
|
||||||
|
images = []
|
||||||
|
for name in image_names:
|
||||||
|
image = name+'.jpg'
|
||||||
|
im = imageio.imread(image)
|
||||||
|
images.append(im)
|
||||||
|
imageio.mimsave(filename+'.gif', images, 'GIF', duration=duration_time) # durantion是延迟时间
|
||||||
|
|
||||||
|
|
||||||
|
# 11. 在参数x下,计算matrix函数的本征值eigenvalue_array[:, index]
|
||||||
|
def calculate_eigenvalue_with_one_parameter(x, matrix):
|
||||||
|
dim_x = np.array(x).shape[0]
|
||||||
|
i0 = 0
|
||||||
|
if np.array(matrix(0)).shape==():
|
||||||
|
eigenvalue_array = np.zeros((dim_x, 1))
|
||||||
|
for x0 in x:
|
||||||
|
matrix0 = matrix(x0)
|
||||||
|
eigenvalue_array[i0, 0] = np.real(matrix0)
|
||||||
|
i0 += 1
|
||||||
|
else:
|
||||||
|
dim = np.array(matrix(0)).shape[0]
|
||||||
|
eigenvalue_array = np.zeros((dim_x, dim))
|
||||||
|
for x0 in x:
|
||||||
|
matrix0 = matrix(x0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_array[i0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
i0 += 1
|
||||||
|
return eigenvalue_array
|
||||||
|
|
||||||
|
|
||||||
|
# 12. 在参数(x,y)下,计算matrix函数的本征值eigenvalue_array[:, :, index]
|
||||||
|
def calculate_eigenvalue_with_two_parameters(x, y, matrix):
|
||||||
|
dim_x = np.array(x).shape[0]
|
||||||
|
dim_y = np.array(y).shape[0]
|
||||||
|
if np.array(matrix(0,0)).shape==():
|
||||||
|
eigenvalue_array = np.zeros((dim_y, dim_x, 1))
|
||||||
|
i0 = 0
|
||||||
|
for y0 in y:
|
||||||
|
j0 = 0
|
||||||
|
for x0 in x:
|
||||||
|
matrix0 = matrix(x0, y0)
|
||||||
|
eigenvalue_array[i0, j0, 0] = np.real(matrix0)
|
||||||
|
j0 += 1
|
||||||
|
i0 += 1
|
||||||
|
else:
|
||||||
|
dim = np.array(matrix(0, 0)).shape[0]
|
||||||
|
eigenvalue_array = np.zeros((dim_y, dim_x, dim))
|
||||||
|
i0 = 0
|
||||||
|
for y0 in y:
|
||||||
|
j0 = 0
|
||||||
|
for x0 in x:
|
||||||
|
matrix0 = matrix(x0, y0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_array[i0, j0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
j0 += 1
|
||||||
|
i0 += 1
|
||||||
|
return eigenvalue_array
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@@ -0,0 +1,103 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8557
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(Nx, Ny):
|
||||||
|
delta = 1e-3
|
||||||
|
gamma = 1e-3
|
||||||
|
lambda0 = 1
|
||||||
|
h = np.zeros((4*Nx*Ny, 4*Nx*Ny))
|
||||||
|
# 元胞内部跃迁
|
||||||
|
for x in range(Nx):
|
||||||
|
for y in range(Ny):
|
||||||
|
h[x*Ny*4+y*4+0, x*Ny*4+y*4+0] = delta
|
||||||
|
h[x*Ny*4+y*4+1, x*Ny*4+y*4+1] = delta
|
||||||
|
h[x*Ny*4+y*4+2, x*Ny*4+y*4+2] = -delta
|
||||||
|
h[x*Ny*4+y*4+3, x*Ny*4+y*4+3] = -delta
|
||||||
|
|
||||||
|
h[x*Ny*4+y*4+0, x*Ny*4+y*4+2] = gamma
|
||||||
|
h[x*Ny*4+y*4+0, x*Ny*4+y*4+3] = gamma
|
||||||
|
h[x*Ny*4+y*4+1, x*Ny*4+y*4+2] = -gamma
|
||||||
|
h[x*Ny*4+y*4+1, x*Ny*4+y*4+3] = gamma
|
||||||
|
h[x*Ny*4+y*4+2, x*Ny*4+y*4+0] = gamma
|
||||||
|
h[x*Ny*4+y*4+2, x*Ny*4+y*4+1] = -gamma
|
||||||
|
h[x*Ny*4+y*4+3, x*Ny*4+y*4+0] = gamma
|
||||||
|
h[x*Ny*4+y*4+3, x*Ny*4+y*4+1] = gamma
|
||||||
|
|
||||||
|
# y方向上的元胞间跃迁
|
||||||
|
for x in range(Nx):
|
||||||
|
for y in range(Ny-1):
|
||||||
|
h[x*Ny*4+y*4+0, x*Ny*4+(y+1)*4+3] = lambda0
|
||||||
|
h[x*Ny*4+(y+1)*4+1, x*Ny*4+y*4+2] = -lambda0
|
||||||
|
h[x*Ny*4+y*4+2, x*Ny*4+(y+1)*4+1] = -lambda0
|
||||||
|
h[x*Ny*4+(y+1)*4+3, x*Ny*4+y*4+0] = lambda0
|
||||||
|
|
||||||
|
# x方向上的元胞间跃迁
|
||||||
|
for x in range(Nx-1):
|
||||||
|
for y in range(Ny):
|
||||||
|
h[x*Ny*4+y*4+0, (x+1)*Ny*4+y*4+2] = lambda0
|
||||||
|
h[(x+1)*Ny*4+y*4+1, x*Ny*4+y*4+3] = lambda0
|
||||||
|
h[(x+1)*Ny*4+y*4+2, x*Ny*4+y*4+0] = lambda0
|
||||||
|
h[x*Ny*4+y*4+3, (x+1)*Ny*4+y*4+1] = lambda0
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
Nx = 10
|
||||||
|
Ny = 10
|
||||||
|
fermi_energy = 0
|
||||||
|
h = hamiltonian(Nx, Ny)
|
||||||
|
green = np.linalg.inv((fermi_energy+1e-6j)*np.eye(h.shape[0])-h)
|
||||||
|
|
||||||
|
x_array = []
|
||||||
|
y_array = []
|
||||||
|
DOS = []
|
||||||
|
for x in range(Nx):
|
||||||
|
for y in range(Ny):
|
||||||
|
x_array.append(x*2+2)
|
||||||
|
y_array.append(y*2+2)
|
||||||
|
DOS.append(-np.imag(green[x*Ny*4+y*4+0, x*Ny*4+y*4+0])/pi)
|
||||||
|
|
||||||
|
x_array.append(x*2+1)
|
||||||
|
y_array.append(y*2+1)
|
||||||
|
DOS.append(-np.imag(green[x*Ny*4+y*4+1, x*Ny*4+y*4+1])/pi)
|
||||||
|
|
||||||
|
x_array.append(x*2+1)
|
||||||
|
y_array.append(y*2+2)
|
||||||
|
DOS.append(-np.imag(green[x*Ny*4+y*4+2, x*Ny*4+y*4+2])/pi)
|
||||||
|
|
||||||
|
x_array.append(x*2+2)
|
||||||
|
y_array.append(y*2+1)
|
||||||
|
DOS.append(-np.imag(green[x*Ny*4+y*4+3, x*Ny*4+y*4+3])/pi)
|
||||||
|
DOS = DOS/np.sum(DOS)
|
||||||
|
Plot_2D_Scatter(x_array, y_array, DOS, xlabel='x', ylabel='y', title='BBH Model', filename='BBH Model')
|
||||||
|
|
||||||
|
|
||||||
|
def Plot_2D_Scatter(x, y, value, xlabel='x', ylabel='y', title='title', filename='a'):
|
||||||
|
from matplotlib.axes._axes import _log as matplotlib_axes_logger
|
||||||
|
matplotlib_axes_logger.setLevel('ERROR') # 只显示error级别的通知
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from matplotlib.ticker import LinearLocator
|
||||||
|
fig = plt.figure()
|
||||||
|
ax = fig.add_subplot(111)
|
||||||
|
plt.subplots_adjust(bottom=0.2, right=0.8, left=0.2)
|
||||||
|
for i in range(np.array(x).shape[0]):
|
||||||
|
ax.scatter(x[i], y[i], marker='o', s=1000*value[i], c=(1,0,0))
|
||||||
|
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.tick_params(labelsize=15) # 设置刻度值字体大小
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
|
||||||
|
# plt.savefig(filename+'.jpg', dpi=300)
|
||||||
|
plt.show()
|
||||||
|
plt.close('all')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,100 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8557
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(Nx, Ny):
|
||||||
|
delta = 1e-3
|
||||||
|
gamma = 1e-3
|
||||||
|
lambda0 = 1
|
||||||
|
h = np.zeros((4*Nx*Ny, 4*Nx*Ny))
|
||||||
|
# 元胞内部跃迁
|
||||||
|
for x in range(Nx):
|
||||||
|
for y in range(Ny):
|
||||||
|
h[x*Ny*4+y*4+0, x*Ny*4+y*4+0] = delta
|
||||||
|
h[x*Ny*4+y*4+1, x*Ny*4+y*4+1] = delta
|
||||||
|
h[x*Ny*4+y*4+2, x*Ny*4+y*4+2] = -delta
|
||||||
|
h[x*Ny*4+y*4+3, x*Ny*4+y*4+3] = -delta
|
||||||
|
|
||||||
|
h[x*Ny*4+y*4+0, x*Ny*4+y*4+2] = gamma
|
||||||
|
h[x*Ny*4+y*4+0, x*Ny*4+y*4+3] = gamma
|
||||||
|
h[x*Ny*4+y*4+1, x*Ny*4+y*4+2] = -gamma
|
||||||
|
h[x*Ny*4+y*4+1, x*Ny*4+y*4+3] = gamma
|
||||||
|
h[x*Ny*4+y*4+2, x*Ny*4+y*4+0] = gamma
|
||||||
|
h[x*Ny*4+y*4+2, x*Ny*4+y*4+1] = -gamma
|
||||||
|
h[x*Ny*4+y*4+3, x*Ny*4+y*4+0] = gamma
|
||||||
|
h[x*Ny*4+y*4+3, x*Ny*4+y*4+1] = gamma
|
||||||
|
|
||||||
|
# y方向上的元胞间跃迁
|
||||||
|
for x in range(Nx):
|
||||||
|
for y in range(Ny-1):
|
||||||
|
h[x*Ny*4+y*4+0, x*Ny*4+(y+1)*4+3] = lambda0
|
||||||
|
h[x*Ny*4+(y+1)*4+1, x*Ny*4+y*4+2] = -lambda0
|
||||||
|
h[x*Ny*4+y*4+2, x*Ny*4+(y+1)*4+1] = -lambda0
|
||||||
|
h[x*Ny*4+(y+1)*4+3, x*Ny*4+y*4+0] = lambda0
|
||||||
|
|
||||||
|
# x方向上的元胞间跃迁
|
||||||
|
for x in range(Nx-1):
|
||||||
|
for y in range(Ny):
|
||||||
|
h[x*Ny*4+y*4+0, (x+1)*Ny*4+y*4+2] = lambda0
|
||||||
|
h[(x+1)*Ny*4+y*4+1, x*Ny*4+y*4+3] = lambda0
|
||||||
|
h[(x+1)*Ny*4+y*4+2, x*Ny*4+y*4+0] = lambda0
|
||||||
|
h[x*Ny*4+y*4+3, (x+1)*Ny*4+y*4+1] = lambda0
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
Nx = 10
|
||||||
|
Ny = 10
|
||||||
|
fermi_energy = 0
|
||||||
|
h = hamiltonian(Nx, Ny)
|
||||||
|
green = np.linalg.inv((fermi_energy+1e-6j)*np.eye(h.shape[0])-h)
|
||||||
|
DOS = np.zeros((Ny*2, Nx*2))
|
||||||
|
for x in range(Nx):
|
||||||
|
for y in range(Ny):
|
||||||
|
DOS[y*2+1, x*2+1] = -np.imag(green[x*Ny*4+y*4+0, x*Ny*4+y*4+0])/pi
|
||||||
|
DOS[y*2+0, x*2+0] = -np.imag(green[x*Ny*4+y*4+1, x*Ny*4+y*4+1])/pi
|
||||||
|
DOS[y*2+1, x*2+0] = -np.imag(green[x*Ny*4+y*4+2, x*Ny*4+y*4+2])/pi
|
||||||
|
DOS[y*2+0, x*2+1] = -np.imag(green[x*Ny*4+y*4+3, x*Ny*4+y*4+3])/pi
|
||||||
|
DOS = DOS/np.sum(DOS)
|
||||||
|
Plot_3D_Surface(np.arange(1, 2*Nx+0.001), np.arange(1, 2*Ny+0.001), DOS, xlabel='x', ylabel='y', zlabel='DOS', title='BBH Model', filename='BBH Model')
|
||||||
|
|
||||||
|
|
||||||
|
def Plot_3D_Surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='title', filename='a'):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator
|
||||||
|
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
|
||||||
|
plt.subplots_adjust(bottom=0.1, right=0.65)
|
||||||
|
x, y = np.meshgrid(x, y)
|
||||||
|
if len(matrix.shape) == 2:
|
||||||
|
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
elif len(matrix.shape) == 3:
|
||||||
|
for i0 in range(matrix.shape[2]):
|
||||||
|
surf = ax.plot_surface(x, y, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_zlabel(zlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
# ax.set_zlim(-1, 1) # 设置z轴的范围
|
||||||
|
ax.zaxis.set_major_locator(LinearLocator(2)) # 设置z轴主刻度的个数
|
||||||
|
ax.zaxis.set_major_formatter('{x:.2f}') # 设置z轴主刻度的格式
|
||||||
|
ax.tick_params(labelsize=15) # 设置刻度值字体大小
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
|
||||||
|
cax = plt.axes([0.80, 0.15, 0.05, 0.75]) # color bar的位置 [左,下,宽度, 高度]
|
||||||
|
cbar = fig.colorbar(surf, cax=cax) # color bar
|
||||||
|
cbar.ax.tick_params(labelsize=15) # 设置color bar刻度的字体大小
|
||||||
|
for l in cbar.ax.yaxis.get_ticklabels():
|
||||||
|
l.set_family('Times New Roman')
|
||||||
|
# plt.savefig(filename+'.jpg', dpi=300)
|
||||||
|
plt.show()
|
||||||
|
plt.close('all')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,179 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6075
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import copy
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def lead_matrix_00(y):
|
||||||
|
h00 = np.zeros((y, y))
|
||||||
|
for y0 in range(y-1):
|
||||||
|
h00[y0, y0+1] = 1
|
||||||
|
h00[y0+1, y0] = 1
|
||||||
|
return h00
|
||||||
|
|
||||||
|
|
||||||
|
def lead_matrix_01(y):
|
||||||
|
h01 = np.identity(y)
|
||||||
|
return h01
|
||||||
|
|
||||||
|
|
||||||
|
def scattering_region(x, y):
|
||||||
|
h = np.zeros((x*y, x*y))
|
||||||
|
for x0 in range(x-1):
|
||||||
|
for y0 in range(y):
|
||||||
|
h[x0*y+y0, (x0+1)*y+y0] = 1 # x方向的跃迁
|
||||||
|
h[(x0+1)*y+y0, x0*y+y0] = 1
|
||||||
|
for x0 in range(x):
|
||||||
|
for y0 in range(y-1):
|
||||||
|
h[x0*y+y0, x0*y+y0+1] = 1 # y方向的跃迁
|
||||||
|
h[x0*y+y0+1, x0*y+y0] = 1
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
start_time = time.time()
|
||||||
|
width = 5
|
||||||
|
length = 50
|
||||||
|
fermi_energy_array = np.arange(-4, 4, .01)
|
||||||
|
|
||||||
|
# 中心区的哈密顿量
|
||||||
|
H_scattering_region = scattering_region(x=length, y=width)
|
||||||
|
|
||||||
|
# 电极的h00和h01
|
||||||
|
lead_h00 = lead_matrix_00(width)
|
||||||
|
lead_h01 = lead_matrix_01(width)
|
||||||
|
|
||||||
|
transmission_12_array = []
|
||||||
|
transmission_13_array = []
|
||||||
|
transmission_14_array = []
|
||||||
|
transmission_15_array = []
|
||||||
|
transmission_16_array = []
|
||||||
|
transmission_1_all_array = []
|
||||||
|
|
||||||
|
for fermi_energy in fermi_energy_array:
|
||||||
|
print(fermi_energy)
|
||||||
|
# 表面格林函数
|
||||||
|
right_lead_surface, left_lead_surface = surface_green_function_lead(fermi_energy + 1e-9j, lead_h00, lead_h01, dim=width)
|
||||||
|
|
||||||
|
# 由于镜面对称以及xy各项同性,因此这里六个电极的表面格林函数具有相同的形式
|
||||||
|
lead_1 = copy.deepcopy(right_lead_surface) # 镜面对称使得lead_1=lead_4
|
||||||
|
lead_2 = copy.deepcopy(right_lead_surface) # xy各项同性使得lead_2=lead_4
|
||||||
|
lead_3 = copy.deepcopy(right_lead_surface)
|
||||||
|
lead_4 = copy.deepcopy(right_lead_surface)
|
||||||
|
lead_5 = copy.deepcopy(right_lead_surface)
|
||||||
|
lead_6 = copy.deepcopy(right_lead_surface)
|
||||||
|
|
||||||
|
# 几何形状如下所示:
|
||||||
|
# lead2 lead3
|
||||||
|
# lead1(L) lead4(R)
|
||||||
|
# lead6 lead5
|
||||||
|
|
||||||
|
# 电极到中心区的跃迁矩阵
|
||||||
|
H_from_lead_1_to_center = np.zeros((width, width*length), dtype=complex)
|
||||||
|
H_from_lead_2_to_center = np.zeros((width, width*length), dtype=complex)
|
||||||
|
H_from_lead_3_to_center = np.zeros((width, width*length), dtype=complex)
|
||||||
|
H_from_lead_4_to_center = np.zeros((width, width*length), dtype=complex)
|
||||||
|
H_from_lead_5_to_center = np.zeros((width, width*length), dtype=complex)
|
||||||
|
H_from_lead_6_to_center = np.zeros((width, width*length), dtype=complex)
|
||||||
|
for i0 in range(width):
|
||||||
|
H_from_lead_1_to_center[i0, i0] = 1
|
||||||
|
H_from_lead_2_to_center[i0, width*i0+(width-1)] = 1
|
||||||
|
H_from_lead_3_to_center[i0, width*(length-1-i0)+(width-1)] = 1
|
||||||
|
H_from_lead_4_to_center[i0, width*(length-1)+i0] = 1
|
||||||
|
H_from_lead_5_to_center[i0, width*(length-1-i0)+0] = 1
|
||||||
|
H_from_lead_6_to_center[i0, width*i0+0] = 1
|
||||||
|
|
||||||
|
# 自能
|
||||||
|
self_energy_1 = np.dot(np.dot(H_from_lead_1_to_center.transpose().conj(), lead_1), H_from_lead_1_to_center)
|
||||||
|
self_energy_2 = np.dot(np.dot(H_from_lead_2_to_center.transpose().conj(), lead_2), H_from_lead_2_to_center)
|
||||||
|
self_energy_3 = np.dot(np.dot(H_from_lead_3_to_center.transpose().conj(), lead_3), H_from_lead_3_to_center)
|
||||||
|
self_energy_4 = np.dot(np.dot(H_from_lead_4_to_center.transpose().conj(), lead_4), H_from_lead_4_to_center)
|
||||||
|
self_energy_5 = np.dot(np.dot(H_from_lead_5_to_center.transpose().conj(), lead_5), H_from_lead_5_to_center)
|
||||||
|
self_energy_6 = np.dot(np.dot(H_from_lead_6_to_center.transpose().conj(), lead_6), H_from_lead_6_to_center)
|
||||||
|
|
||||||
|
# 整体格林函数
|
||||||
|
green = np.linalg.inv(fermi_energy*np.eye(width*length)-H_scattering_region-self_energy_1-self_energy_2-self_energy_3-self_energy_4-self_energy_5-self_energy_6)
|
||||||
|
|
||||||
|
# Gamma矩阵
|
||||||
|
self_energy_1 = 1j*(self_energy_1-self_energy_1.transpose().conj())
|
||||||
|
self_energy_2 = 1j*(self_energy_2-self_energy_2.transpose().conj())
|
||||||
|
self_energy_3 = 1j*(self_energy_3-self_energy_3.transpose().conj())
|
||||||
|
self_energy_4 = 1j*(self_energy_4-self_energy_4.transpose().conj())
|
||||||
|
self_energy_5 = 1j*(self_energy_5-self_energy_5.transpose().conj())
|
||||||
|
self_energy_6 = 1j*(self_energy_6-self_energy_6.transpose().conj())
|
||||||
|
|
||||||
|
# Transmission
|
||||||
|
transmission_12 = np.trace(np.dot(np.dot(np.dot(self_energy_1, green), self_energy_2), green.transpose().conj()))
|
||||||
|
transmission_13 = np.trace(np.dot(np.dot(np.dot(self_energy_1, green), self_energy_3), green.transpose().conj()))
|
||||||
|
transmission_14 = np.trace(np.dot(np.dot(np.dot(self_energy_1, green), self_energy_4), green.transpose().conj()))
|
||||||
|
transmission_15 = np.trace(np.dot(np.dot(np.dot(self_energy_1, green), self_energy_5), green.transpose().conj()))
|
||||||
|
transmission_16 = np.trace(np.dot(np.dot(np.dot(self_energy_1, green), self_energy_6), green.transpose().conj()))
|
||||||
|
|
||||||
|
transmission_12_array.append(np.real(transmission_12))
|
||||||
|
transmission_13_array.append(np.real(transmission_13))
|
||||||
|
transmission_14_array.append(np.real(transmission_14))
|
||||||
|
transmission_15_array.append(np.real(transmission_15))
|
||||||
|
transmission_16_array.append(np.real(transmission_16))
|
||||||
|
transmission_1_all_array.append(np.real(transmission_12+transmission_13+transmission_14+transmission_15+transmission_16))
|
||||||
|
|
||||||
|
Plot_Line(fermi_energy_array, transmission_12_array, xlabel='Fermi energy', ylabel='Transmission_12', title='', filename='a')
|
||||||
|
Plot_Line(fermi_energy_array, transmission_13_array, xlabel='Fermi energy', ylabel='Transmission_13', title='', filename='a')
|
||||||
|
Plot_Line(fermi_energy_array, transmission_14_array, xlabel='Fermi energy', ylabel='Transmission_14', title='', filename='a')
|
||||||
|
Plot_Line(fermi_energy_array, transmission_15_array, xlabel='Fermi energy', ylabel='Transmission_15', title='', filename='a')
|
||||||
|
Plot_Line(fermi_energy_array, transmission_16_array, xlabel='Fermi energy', ylabel='Transmission_16', title='', filename='a')
|
||||||
|
Plot_Line(fermi_energy_array, transmission_1_all_array, xlabel='Fermi energy', ylabel='Transmission_1_all', title='', filename='a')
|
||||||
|
end_time = time.time()
|
||||||
|
print('运行时间=', end_time-start_time)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def Plot_Line(x, y, xlabel='x', ylabel='y', title='', filename='a'):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
plt.subplots_adjust(bottom=0.20, left=0.18)
|
||||||
|
ax.plot(x, y, '-')
|
||||||
|
ax.grid()
|
||||||
|
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.tick_params(labelsize=20)
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels]
|
||||||
|
# plt.savefig(filename+'.jpg', dpi=300)
|
||||||
|
plt.show()
|
||||||
|
plt.close('all')
|
||||||
|
|
||||||
|
def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵T
|
||||||
|
transfer = np.zeros((2*dim, 2*dim))*(0+0j)
|
||||||
|
transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00)
|
||||||
|
transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj())
|
||||||
|
transfer[dim:2*dim, 0:dim] = np.identity(dim)
|
||||||
|
transfer[dim:2*dim, dim:2*dim] = 0
|
||||||
|
return transfer # 返回转移矩阵
|
||||||
|
|
||||||
|
|
||||||
|
def surface_green_function_lead(fermi_energy, h00, h01, dim): # 电极的表面格林函数
|
||||||
|
transfer = transfer_matrix(fermi_energy, h00, h01, dim)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(transfer)
|
||||||
|
ind = np.argsort(np.abs(eigenvalue))
|
||||||
|
temp = np.zeros((2*dim, 2*dim))*(1+0j)
|
||||||
|
i0 = 0
|
||||||
|
for ind0 in ind:
|
||||||
|
temp[:, i0] = eigenvector[:, ind0]
|
||||||
|
i0 += 1
|
||||||
|
s1 = temp[dim:2*dim, 0:dim]
|
||||||
|
s2 = temp[0:dim, 0:dim]
|
||||||
|
s3 = temp[dim:2*dim, dim:2*dim]
|
||||||
|
s4 = temp[0:dim, dim:2*dim]
|
||||||
|
right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1)))
|
||||||
|
left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4)))
|
||||||
|
return right_lead_surface, left_lead_surface # 返回右电极的表面格林函数和左电极的表面格林函数
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,68 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10064
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import cmath
|
||||||
|
from math import *
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k):
|
||||||
|
gamma = 0.5
|
||||||
|
lambda0 = 1
|
||||||
|
delta = 0
|
||||||
|
h = np.zeros((2, 2))*(1+0j)
|
||||||
|
h[0,0] = delta
|
||||||
|
h[1,1] = -delta
|
||||||
|
h[0,1] = gamma+lambda0*cmath.exp(-1j*k)
|
||||||
|
h[1,0] = gamma+lambda0*cmath.exp(1j*k)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
Num_k = 100
|
||||||
|
k_array = np.linspace(-pi, pi, Num_k)
|
||||||
|
vector_array = []
|
||||||
|
for k in k_array:
|
||||||
|
vector = get_occupied_bands_vectors(k, hamiltonian)
|
||||||
|
vector_array.append(vector)
|
||||||
|
|
||||||
|
# 波函数固定一个规范
|
||||||
|
index = np.argmax(np.abs(vector_array[0]))
|
||||||
|
for i0 in range(Num_k):
|
||||||
|
vector_array[i0] = find_vector_with_fixed_gauge(vector_array[i0], index)
|
||||||
|
|
||||||
|
# 计算Wilson loop
|
||||||
|
W_k = 1
|
||||||
|
for i0 in range(Num_k-1):
|
||||||
|
F = np.dot(vector_array[i0+1].transpose().conj(), vector_array[i0])
|
||||||
|
W_k = np.dot(F, W_k)
|
||||||
|
nu = np.log(W_k)/2/pi/1j
|
||||||
|
# if np.real(nu) < 0:
|
||||||
|
# nu += 1
|
||||||
|
print('p=', nu, '\n')
|
||||||
|
|
||||||
|
|
||||||
|
def get_occupied_bands_vectors(x, matrix):
|
||||||
|
matrix0 = matrix(x)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]]
|
||||||
|
return vector
|
||||||
|
|
||||||
|
|
||||||
|
def find_vector_with_fixed_gauge(vector, index):
|
||||||
|
sign_pre = np.sign(np.imag(vector[index]))
|
||||||
|
for phase in np.arange(0, 2*pi, 0.01):
|
||||||
|
sign = np.sign(np.imag(vector[index]*cmath.exp(1j*phase)))
|
||||||
|
if np.abs(np.imag(vector[index]*cmath.exp(1j*phase))) < 1e-9 or sign == -sign_pre:
|
||||||
|
break
|
||||||
|
sign_pre = sign
|
||||||
|
vector = vector*cmath.exp(1j*phase)
|
||||||
|
if np.real(vector[index]) < 0:
|
||||||
|
vector = -vector
|
||||||
|
return vector
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,53 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10064
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import cmath
|
||||||
|
from math import *
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(k):
|
||||||
|
gamma = 0.5
|
||||||
|
lambda0 = 1
|
||||||
|
delta = 0
|
||||||
|
h = np.zeros((2, 2))*(1+0j)
|
||||||
|
h[0,0] = delta
|
||||||
|
h[1,1] = -delta
|
||||||
|
h[0,1] = gamma+lambda0*cmath.exp(-1j*k)
|
||||||
|
h[1,0] = gamma+lambda0*cmath.exp(1j*k)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
Num_k = 100
|
||||||
|
k_array = np.linspace(-pi, pi, Num_k)
|
||||||
|
vector_array = []
|
||||||
|
for k in k_array:
|
||||||
|
vector = get_occupied_bands_vectors(k, hamiltonian)
|
||||||
|
if k != pi:
|
||||||
|
vector_array.append(vector)
|
||||||
|
else:
|
||||||
|
vector_array.append(vector_array[0])
|
||||||
|
|
||||||
|
# 计算Wilson loop
|
||||||
|
W_k = 1
|
||||||
|
for i0 in range(Num_k-1):
|
||||||
|
F = np.dot(vector_array[i0+1].transpose().conj(), vector_array[i0])
|
||||||
|
W_k = np.dot(F, W_k)
|
||||||
|
nu = np.log(W_k)/2/pi/1j
|
||||||
|
# if np.real(nu) < 0:
|
||||||
|
# nu += 1
|
||||||
|
print('p=', nu, '\n')
|
||||||
|
|
||||||
|
|
||||||
|
def get_occupied_bands_vectors(x, matrix):
|
||||||
|
matrix0 = matrix(x)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]]
|
||||||
|
return vector
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,81 @@
|
|||||||
|
(* Content-type: application/vnd.wolfram.mathematica *)
|
||||||
|
|
||||||
|
(*** Wolfram Notebook File ***)
|
||||||
|
(* http://www.wolfram.com/nb *)
|
||||||
|
|
||||||
|
(* CreatedBy='Mathematica 12.0' *)
|
||||||
|
|
||||||
|
(*CacheID: 234*)
|
||||||
|
(* Internal cache information:
|
||||||
|
NotebookFileLineBreakTest
|
||||||
|
NotebookFileLineBreakTest
|
||||||
|
NotebookDataPosition[ 158, 7]
|
||||||
|
NotebookDataLength[ 2039, 71]
|
||||||
|
NotebookOptionsPosition[ 1730, 57]
|
||||||
|
NotebookOutlinePosition[ 2086, 73]
|
||||||
|
CellTagsIndexPosition[ 2043, 70]
|
||||||
|
WindowFrame->Normal*)
|
||||||
|
|
||||||
|
(* Beginning of Notebook Content *)
|
||||||
|
Notebook[{
|
||||||
|
Cell[BoxData[{
|
||||||
|
RowBox[{"Clear", "[", "\"\<`*\>\"", "]"}], "\n",
|
||||||
|
RowBox[{
|
||||||
|
RowBox[{"H", "=",
|
||||||
|
RowBox[{
|
||||||
|
RowBox[{"(",
|
||||||
|
RowBox[{"{",
|
||||||
|
RowBox[{
|
||||||
|
RowBox[{"{",
|
||||||
|
RowBox[{"a0", ",", "0"}], "}"}], ",",
|
||||||
|
RowBox[{"{",
|
||||||
|
RowBox[{"0", ",", "a0"}], "}"}]}], "}"}], ")"}], "+",
|
||||||
|
RowBox[{"(",
|
||||||
|
RowBox[{"{",
|
||||||
|
RowBox[{
|
||||||
|
RowBox[{"{",
|
||||||
|
RowBox[{"a3", ",",
|
||||||
|
RowBox[{"a1", "-",
|
||||||
|
RowBox[{"I", "*", "a2"}]}]}], "}"}], ",",
|
||||||
|
RowBox[{"{",
|
||||||
|
RowBox[{
|
||||||
|
RowBox[{"a1", "+",
|
||||||
|
RowBox[{"I", "*", "a2"}]}], ",",
|
||||||
|
RowBox[{"-", "a3"}]}], "}"}]}], "}"}], ")"}]}]}], ";"}], "\n",
|
||||||
|
RowBox[{"MatrixForm", "[", "H", "]"}], "\n",
|
||||||
|
RowBox[{"eigenvalue", "=",
|
||||||
|
RowBox[{"MatrixForm", "[",
|
||||||
|
RowBox[{"Simplify", "[",
|
||||||
|
RowBox[{"Eigenvalues", "[", "H", "]"}], "]"}], "]"}]}], "\n",
|
||||||
|
RowBox[{"eigenvector", "=",
|
||||||
|
RowBox[{"MatrixForm", "[",
|
||||||
|
RowBox[{"Simplify", "[",
|
||||||
|
RowBox[{"Eigenvectors", "[", "H", "]"}], "]"}], "]"}]}]}], "Input",
|
||||||
|
CellChangeTimes->{{3.830338636045154*^9,
|
||||||
|
3.830338636046383*^9}},ExpressionUUID->"6b5e0acb-1938-4b1e-bd73-\
|
||||||
|
d3f6bb8905fc"]
|
||||||
|
},
|
||||||
|
WindowSize->{759, 670},
|
||||||
|
WindowMargins->{{Automatic, 572}, {64, Automatic}},
|
||||||
|
FrontEndVersion->"12.0 for Microsoft Windows (64-bit) (2019\:5e744\:67088\
|
||||||
|
\:65e5)",
|
||||||
|
StyleDefinitions->"Default.nb"
|
||||||
|
]
|
||||||
|
(* End of Notebook Content *)
|
||||||
|
|
||||||
|
(* Internal cache information *)
|
||||||
|
(*CellTagsOutline
|
||||||
|
CellTagsIndex->{}
|
||||||
|
*)
|
||||||
|
(*CellTagsIndex
|
||||||
|
CellTagsIndex->{}
|
||||||
|
*)
|
||||||
|
(*NotebookFileOutline
|
||||||
|
Notebook[{
|
||||||
|
Cell[558, 20, 1168, 35, 193, "Input",ExpressionUUID->"6b5e0acb-1938-4b1e-bd73-d3f6bb8905fc"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
*)
|
||||||
|
|
||||||
|
(* End of internal cache information *)
|
||||||
|
|
@@ -0,0 +1,89 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10385
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from math import *
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
k1 = np.linspace(-pi, pi, 100)
|
||||||
|
k2 = np.linspace(-pi, pi, 100)
|
||||||
|
|
||||||
|
eigenvalue_array = Calculate_Eigenvalue_with_Two_Parameters(k1, k2, hamiltonian)
|
||||||
|
Plot_3D_Surface(k1, k2, eigenvalue_array, xlabel='kx', ylabel='ky', zlabel='E', title='', filename='a')
|
||||||
|
|
||||||
|
|
||||||
|
def hamiltonian(kx,ky,kz=0):
|
||||||
|
w0x = 2
|
||||||
|
w0y = 0
|
||||||
|
w0z = 0
|
||||||
|
vx = 1
|
||||||
|
vy = 1
|
||||||
|
vz = 1
|
||||||
|
H = (w0x*kx+w0y*ky+w0z*kz)*sigma_0() + vx*kx*sigma_x()+vy*ky*sigma_y()+vz*kz*sigma_z()
|
||||||
|
return H
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_0():
|
||||||
|
return np.eye(2)
|
||||||
|
|
||||||
|
def sigma_x():
|
||||||
|
return np.array([[0, 1],[1, 0]])
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_y():
|
||||||
|
return np.array([[0, -1j],[1j, 0]])
|
||||||
|
|
||||||
|
|
||||||
|
def sigma_z():
|
||||||
|
return np.array([[1, 0],[0, -1]])
|
||||||
|
|
||||||
|
|
||||||
|
def Calculate_Eigenvalue_with_Two_Parameters(x, y, matrix):
|
||||||
|
dim = np.array(matrix(0, 0)).shape[0]
|
||||||
|
dim_x = np.array(x).shape[0]
|
||||||
|
dim_y = np.array(y).shape[0]
|
||||||
|
eigenvalue_array = np.zeros((dim_y, dim_x, dim))
|
||||||
|
i0 = 0
|
||||||
|
for y0 in y:
|
||||||
|
j0 = 0
|
||||||
|
for x0 in x:
|
||||||
|
matrix0 = matrix(x0, y0)
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(matrix0)
|
||||||
|
eigenvalue_array[i0, j0, :] = np.sort(np.real(eigenvalue[:]))
|
||||||
|
j0 += 1
|
||||||
|
i0 += 1
|
||||||
|
return eigenvalue_array
|
||||||
|
|
||||||
|
|
||||||
|
def Plot_3D_Surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a'):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from matplotlib import cm
|
||||||
|
from matplotlib.ticker import LinearLocator
|
||||||
|
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
|
||||||
|
plt.subplots_adjust(bottom=0.1, right=0.8)
|
||||||
|
x, y = np.meshgrid(x, y)
|
||||||
|
if len(matrix.shape) == 2:
|
||||||
|
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
elif len(matrix.shape) == 3:
|
||||||
|
for i0 in range(matrix.shape[2]):
|
||||||
|
surf = ax.plot_surface(x, y, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
|
||||||
|
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
ax.set_zlabel(zlabel, fontsize=20, fontfamily='Times New Roman')
|
||||||
|
# ax.set_zlim(-1, 1) # 设置z轴的范围
|
||||||
|
ax.zaxis.set_major_locator(LinearLocator(5)) # 设置z轴主刻度的个数
|
||||||
|
ax.zaxis.set_major_formatter('{x:.2f}') # 设置z轴主刻度的格式
|
||||||
|
ax.tick_params(labelsize=15) # 设置刻度值字体大小
|
||||||
|
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
|
||||||
|
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
|
||||||
|
# plt.savefig(filename+'.jpg', dpi=300)
|
||||||
|
plt.show()
|
||||||
|
plt.close('all')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,73 @@
|
|||||||
|
(* Content-type: application/vnd.wolfram.mathematica *)
|
||||||
|
|
||||||
|
(*** Wolfram Notebook File ***)
|
||||||
|
(* http://www.wolfram.com/nb *)
|
||||||
|
|
||||||
|
(* CreatedBy='Mathematica 12.0' *)
|
||||||
|
|
||||||
|
(*CacheID: 234*)
|
||||||
|
(* Internal cache information:
|
||||||
|
NotebookFileLineBreakTest
|
||||||
|
NotebookFileLineBreakTest
|
||||||
|
NotebookDataPosition[ 158, 7]
|
||||||
|
NotebookDataLength[ 2028, 65]
|
||||||
|
NotebookOptionsPosition[ 1687, 50]
|
||||||
|
NotebookOutlinePosition[ 2075, 67]
|
||||||
|
CellTagsIndexPosition[ 2032, 64]
|
||||||
|
WindowFrame->Normal*)
|
||||||
|
|
||||||
|
(* Beginning of Notebook Content *)
|
||||||
|
Notebook[{
|
||||||
|
Cell[BoxData[
|
||||||
|
RowBox[{"\[IndentingNewLine]",
|
||||||
|
RowBox[{
|
||||||
|
RowBox[{"Clear", "[", "\"\<`*\>\"", "]"}], "\[IndentingNewLine]",
|
||||||
|
RowBox[{
|
||||||
|
RowBox[{"A", "=",
|
||||||
|
RowBox[{"{",
|
||||||
|
RowBox[{
|
||||||
|
RowBox[{"{",
|
||||||
|
RowBox[{"3", ",", "2", ",",
|
||||||
|
RowBox[{"-", "1"}]}], "}"}], ",",
|
||||||
|
RowBox[{"{",
|
||||||
|
RowBox[{
|
||||||
|
RowBox[{"-", "2"}], ",",
|
||||||
|
RowBox[{"-", "2"}], ",", "2"}], "}"}], ",", " ",
|
||||||
|
RowBox[{"{",
|
||||||
|
RowBox[{"3", ",", "6", ",",
|
||||||
|
RowBox[{"-", "1"}]}], "}"}]}], "}"}]}], ";"}], "\[IndentingNewLine]",
|
||||||
|
RowBox[{"MatrixForm", "[", "A", "]"}], "\n",
|
||||||
|
RowBox[{"eigenvalue", "=",
|
||||||
|
RowBox[{"MatrixForm", "[",
|
||||||
|
RowBox[{"Eigenvalues", "[", "A", "]"}], "]"}]}], "\n",
|
||||||
|
RowBox[{"eigenvector", "=",
|
||||||
|
RowBox[{"MatrixForm", "[",
|
||||||
|
RowBox[{"Eigenvectors", "[", "A", "]"}], "]"}]}]}]}]], "Input",
|
||||||
|
CellChangeTimes->{{3.8249089321894894`*^9, 3.8249090194456663`*^9}, {
|
||||||
|
3.8249090545199647`*^9, 3.824909158471919*^9}, {3.8249092372038407`*^9,
|
||||||
|
3.824909243121014*^9}},
|
||||||
|
CellLabel->"In[24]:=",ExpressionUUID->"54dc89aa-0cf7-4c91-9e21-ea7b96cf97e8"]
|
||||||
|
},
|
||||||
|
WindowSize->{1128, 568},
|
||||||
|
WindowMargins->{{Automatic, 375}, {Automatic, 189}},
|
||||||
|
Magnification:>1.2 Inherited,
|
||||||
|
FrontEndVersion->"12.0 for Microsoft Windows (64-bit) (2019\:5e744\:67088\
|
||||||
|
\:65e5)",
|
||||||
|
StyleDefinitions->"Default.nb"
|
||||||
|
]
|
||||||
|
(* End of Notebook Content *)
|
||||||
|
|
||||||
|
(* Internal cache information *)
|
||||||
|
(*CellTagsOutline
|
||||||
|
CellTagsIndex->{}
|
||||||
|
*)
|
||||||
|
(*CellTagsIndex
|
||||||
|
CellTagsIndex->{}
|
||||||
|
*)
|
||||||
|
(*NotebookFileOutline
|
||||||
|
Notebook[{
|
||||||
|
Cell[558, 20, 1125, 28, 238, "Input",ExpressionUUID->"54dc89aa-0cf7-4c91-9e21-ea7b96cf97e8"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
*)
|
||||||
|
|
@@ -0,0 +1,3 @@
|
|||||||
|
clc;clear all;
|
||||||
|
A = [3, 2, -1; -2, -2, 2; 3, 6, -1]
|
||||||
|
[V,D] = eig(A)
|
@@ -0,0 +1,40 @@
|
|||||||
|
program main
|
||||||
|
use lapack95
|
||||||
|
implicit none
|
||||||
|
integer i,j,info
|
||||||
|
complex*16 A(3,3), eigenvalues(3), eigenvectors(3,3)
|
||||||
|
|
||||||
|
A(1,1)=(3.d0, 0.d0)
|
||||||
|
A(1,2)=(2.d0, 0.d0)
|
||||||
|
A(1,3)=(-1.d0, 0.d0)
|
||||||
|
A(2,1)=(-2.d0, 0.d0)
|
||||||
|
A(2,2)=(-2.d0, 0.d0)
|
||||||
|
A(2,3)=(2.d0, 0.d0)
|
||||||
|
A(3,1)=(3.d0, 0.d0)
|
||||||
|
A(3,2)=(6.d0, 0.d0)
|
||||||
|
A(3,3)=(-1.d0, 0.d0)
|
||||||
|
|
||||||
|
write(*,*) 'matrix:'
|
||||||
|
do i=1,3
|
||||||
|
do j=1,3
|
||||||
|
write(*,"(f10.4, '+1i*',f7.4)",advance='no') A(i,j) ! <20><>ѭ<EFBFBD><D1AD>Ϊ<EFBFBD>е<EFBFBD>ָ<EFBFBD><D6B8>
|
||||||
|
enddo
|
||||||
|
write(*,*) ''
|
||||||
|
enddo
|
||||||
|
|
||||||
|
call geev(A=A, W=eigenvalues, VR=eigenvectors, INFO=info)
|
||||||
|
|
||||||
|
write(*,*) 'eigenvectors:'
|
||||||
|
do i=1,3
|
||||||
|
do j=1,3
|
||||||
|
write(*,"(f10.4, '+1i*',f7.4)",advance='no') eigenvectors(i,j) ! <20><>ѭ<EFBFBD><D1AD>Ϊ<EFBFBD>е<EFBFBD>ָ<EFBFBD>ꡣ<EFBFBD><EAA1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
enddo
|
||||||
|
write(*,*) ''
|
||||||
|
enddo
|
||||||
|
write(*,*) 'eigenvalues:'
|
||||||
|
do i=1,3
|
||||||
|
write(*,"(f10.4, '+1i*',f7.4)",advance='no') eigenvalues(i)
|
||||||
|
enddo
|
||||||
|
write(*,*) ''
|
||||||
|
write(*,*) ''
|
||||||
|
end program
|
@@ -0,0 +1,21 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
A = np.array([[3, 2+1j, -1], [2-1j, -2, 6], [-1, 6, 1]])
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(A)
|
||||||
|
print('矩阵:\n', A)
|
||||||
|
print('特征值:\n', eigenvalue)
|
||||||
|
print('特征向量:\n', eigenvector)
|
||||||
|
|
||||||
|
print('\n判断是否正交:\n', np.dot(eigenvector.transpose().conj(), eigenvector))
|
||||||
|
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose().conj()))
|
||||||
|
|
||||||
|
print('特征向量矩阵的列向量模方和:')
|
||||||
|
for i in range(3):
|
||||||
|
print(np.abs(eigenvector[0, i])**2+np.abs(eigenvector[1, i])**2+np.abs(eigenvector[2, i])**2)
|
||||||
|
print('特征向量矩阵的行向量模方和:')
|
||||||
|
for i in range(3):
|
||||||
|
print(np.abs(eigenvector[i, 0])**2+np.abs(eigenvector[i, 1])**2+np.abs(eigenvector[i, 2])**2)
|
||||||
|
|
||||||
|
print('\n对角化验证:')
|
||||||
|
print(np.dot(np.dot(eigenvector.transpose().conj(), A), eigenvector))
|
||||||
|
print(np.dot(np.dot(eigenvector, A), eigenvector.transpose().conj()))
|
@@ -0,0 +1,18 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
A = np.array([[3, 2, -1], [-2, -2, 2], [3, 6, -1]])
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(A)
|
||||||
|
print('矩阵:\n', A)
|
||||||
|
print('特征值:\n', eigenvalue)
|
||||||
|
print('特征向量:\n', eigenvector)
|
||||||
|
print('特征值为-4对应的特征向量理论值:\n', np.array([1/3, -2/3, 1])/np.sqrt((1/3)**2+(-2/3)**2+1**2))
|
||||||
|
|
||||||
|
print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
|
||||||
|
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
|
||||||
|
|
||||||
|
print('特征向量矩阵的列向量模方和:')
|
||||||
|
for i in range(3):
|
||||||
|
print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2)
|
||||||
|
print('特征向量矩阵的行向量模方和:')
|
||||||
|
for i in range(3):
|
||||||
|
print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2)
|
@@ -0,0 +1,21 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
A = np.array([[3, 2, -1], [2, -2, 6], [-1, 6, 1]])
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(A)
|
||||||
|
print('矩阵:\n', A)
|
||||||
|
print('特征值:\n', eigenvalue)
|
||||||
|
print('特征向量:\n', eigenvector)
|
||||||
|
|
||||||
|
print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
|
||||||
|
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
|
||||||
|
|
||||||
|
print('特征向量矩阵的列向量模方和:')
|
||||||
|
for i in range(3):
|
||||||
|
print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2)
|
||||||
|
print('特征向量矩阵的行向量模方和:')
|
||||||
|
for i in range(3):
|
||||||
|
print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2)
|
||||||
|
|
||||||
|
print('\n对角化验证:')
|
||||||
|
print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector))
|
||||||
|
print(np.dot(np.dot(eigenvector, A), eigenvector.transpose()))
|
@@ -0,0 +1,32 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
A = np.array([[0, 1, 1, -1], [1, 0, -1, 1], [1, -1, 0, 1], [-1, 1, 1, 0]])
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(A)
|
||||||
|
print('矩阵:\n', A)
|
||||||
|
print('特征值:\n', eigenvalue)
|
||||||
|
print('特征向量:\n', eigenvector)
|
||||||
|
|
||||||
|
print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
|
||||||
|
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
|
||||||
|
|
||||||
|
print('特征向量矩阵的列向量模方和:')
|
||||||
|
for i in range(4):
|
||||||
|
print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2+eigenvector[3, i]**2)
|
||||||
|
print('特征向量矩阵的行向量模方和:')
|
||||||
|
for i in range(4):
|
||||||
|
print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2+eigenvector[i, 3]**2)
|
||||||
|
|
||||||
|
print('\n对角化验证:')
|
||||||
|
print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector))
|
||||||
|
print(np.dot(np.dot(eigenvector, A), eigenvector.transpose()))
|
||||||
|
|
||||||
|
print('\n特征向量理论值:')
|
||||||
|
T = np.array([[1/np.sqrt(2), 1/np.sqrt(6), -1/np.sqrt(12), 1/2], [1/np.sqrt(2), -1/np.sqrt(6), 1/np.sqrt(12), -1/2], [0, 2/np.sqrt(6), 1/np.sqrt(12), -1/2], [0, 0, 3/np.sqrt(12), 1/2]])
|
||||||
|
print(T)
|
||||||
|
|
||||||
|
print('\n判断是否正交:\n', np.dot(T.transpose(), T))
|
||||||
|
print('判断是否正交:\n', np.dot(T, T.transpose()))
|
||||||
|
|
||||||
|
print('\n对角化验证:')
|
||||||
|
print(np.dot(np.dot(T.transpose(), A), T))
|
||||||
|
print(np.dot(np.dot(T, A), T.transpose()))
|
@@ -0,0 +1,44 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10890
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
A = np.array([[0, 1, 1, -1], [1, 0, -1, 1], [1, -1, 0, 1], [-1, 1, 1, 0]])
|
||||||
|
eigenvalue, eigenvector = np.linalg.eig(A)
|
||||||
|
print('矩阵:\n', A)
|
||||||
|
print('特征值:\n', eigenvalue)
|
||||||
|
print('特征向量:\n', eigenvector)
|
||||||
|
|
||||||
|
print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
|
||||||
|
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
|
||||||
|
|
||||||
|
print('对角化验证:')
|
||||||
|
print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector))
|
||||||
|
|
||||||
|
# 施密斯正交化
|
||||||
|
eigenvector = Schmidt_orthogonalization(eigenvector)
|
||||||
|
|
||||||
|
print('\n施密斯正交化后,特征向量:\n', eigenvector)
|
||||||
|
|
||||||
|
print('施密斯正交化后,判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
|
||||||
|
print('施密斯正交化后,判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
|
||||||
|
|
||||||
|
print('施密斯正交化后,对角化验证:')
|
||||||
|
print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector))
|
||||||
|
|
||||||
|
|
||||||
|
def Schmidt_orthogonalization(eigenvector):
|
||||||
|
num = eigenvector.shape[1]
|
||||||
|
for i in range(num):
|
||||||
|
for i0 in range(i):
|
||||||
|
eigenvector[:, i] = eigenvector[:, i] - eigenvector[:, i0]*np.dot(eigenvector[:, i].transpose().conj(), eigenvector[:, i0])/(np.dot(eigenvector[:, i0].transpose().conj(),eigenvector[:, i0]))
|
||||||
|
eigenvector[:, i] = eigenvector[:, i]/np.linalg.norm(eigenvector[:, i])
|
||||||
|
return eigenvector
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
40
academic_codes/2021.03.19_plot_twist_graphene_with_python/graphene.py
Executable file
40
academic_codes/2021.03.19_plot_twist_graphene_with_python/graphene.py
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
x_array = np.arange(-5, 5.1)
|
||||||
|
y_array = np.arange(-5, 5.1)
|
||||||
|
coordinates = []
|
||||||
|
for x in x_array:
|
||||||
|
for y in y_array:
|
||||||
|
coordinates.append([0+x*3, 0+y*np.sqrt(3)])
|
||||||
|
coordinates.append([1+x*3, 0+y*np.sqrt(3)])
|
||||||
|
coordinates.append([-1/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
|
||||||
|
coordinates.append([-3/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
|
||||||
|
plot_dots(coordinates)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_dots(coordinates):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
x_range = max(np.array(coordinates)[:, 0])-min(np.array(coordinates)[:, 0])
|
||||||
|
y_range = max(np.array(coordinates)[:, 1])-min(np.array(coordinates)[:, 1])
|
||||||
|
fig, ax = plt.subplots(figsize=(9*x_range/y_range,9))
|
||||||
|
plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
|
||||||
|
plt.axis('off')
|
||||||
|
for i1 in range(len(coordinates)):
|
||||||
|
for i2 in range(len(coordinates)):
|
||||||
|
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
|
||||||
|
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=1)
|
||||||
|
for i in range(len(coordinates)):
|
||||||
|
ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=8)
|
||||||
|
# plt.savefig('graphene.eps')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
35
academic_codes/2021.03.19_plot_twist_graphene_with_python/square.py
Executable file
35
academic_codes/2021.03.19_plot_twist_graphene_with_python/square.py
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
x_array = np.arange(-5, 5.1)
|
||||||
|
y_array = np.arange(-5, 5.1)
|
||||||
|
coordinates = []
|
||||||
|
for x in x_array:
|
||||||
|
for y in y_array:
|
||||||
|
coordinates.append([x, y])
|
||||||
|
plot_dots(coordinates)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_dots(coordinates):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
fig, ax = plt.subplots(figsize=(9,9))
|
||||||
|
plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
|
||||||
|
plt.axis('off')
|
||||||
|
for i1 in range(len(coordinates)):
|
||||||
|
for i2 in range(len(coordinates)):
|
||||||
|
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
|
||||||
|
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=1)
|
||||||
|
for i in range(len(coordinates)):
|
||||||
|
ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=10)
|
||||||
|
# plt.savefig('square.eps')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
73
academic_codes/2021.03.19_plot_twist_graphene_with_python/twist_graphene.py
Executable file
73
academic_codes/2021.03.19_plot_twist_graphene_with_python/twist_graphene.py
Executable file
@@ -0,0 +1,73 @@
|
|||||||
|
"""
|
||||||
|
This code is supported by the website: https://www.guanjihuan.com
|
||||||
|
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
|
||||||
|
"""
|
||||||
|
|
||||||
|
from types import coroutine
|
||||||
|
import numpy as np
|
||||||
|
import copy
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from math import *
|
||||||
|
|
||||||
|
def main():
|
||||||
|
x_array = np.arange(-20, 20.1)
|
||||||
|
y_array = np.arange(-20, 20.1)
|
||||||
|
coordinates = []
|
||||||
|
for x in x_array:
|
||||||
|
for y in y_array:
|
||||||
|
coordinates.append([0+x*3, 0+y*np.sqrt(3)])
|
||||||
|
coordinates.append([1+x*3, 0+y*np.sqrt(3)])
|
||||||
|
coordinates.append([-1/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
|
||||||
|
coordinates.append([-3/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
|
||||||
|
x_range1 = max(np.array(coordinates)[:, 0])-min(np.array(coordinates)[:, 0])
|
||||||
|
y_range1 = max(np.array(coordinates)[:, 1])-min(np.array(coordinates)[:, 1])
|
||||||
|
|
||||||
|
theta = -1.1/180*pi
|
||||||
|
rotation_matrix = np.zeros((2, 2))
|
||||||
|
rotation_matrix[0, 0] = np.cos(theta)
|
||||||
|
rotation_matrix[1, 1] = np.cos(theta)
|
||||||
|
rotation_matrix[0, 1] = -np.sin(theta)
|
||||||
|
rotation_matrix[1, 0] = np.sin(theta)
|
||||||
|
coordinates2 = copy.deepcopy(coordinates)
|
||||||
|
for i in range(len(coordinates)):
|
||||||
|
coordinates2[i] = np.dot(rotation_matrix, coordinates[i])
|
||||||
|
x_range2 = max(np.array(coordinates2)[:, 0])-min(np.array(coordinates2)[:, 0])
|
||||||
|
y_range2 = max(np.array(coordinates2)[:, 1])-min(np.array(coordinates2)[:, 1])
|
||||||
|
|
||||||
|
x_range = max([x_range1, x_range2])
|
||||||
|
y_range = max([y_range1, y_range2])
|
||||||
|
fig, ax = plt.subplots(figsize=(9*x_range/y_range,9))
|
||||||
|
plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
|
||||||
|
plt.axis('off')
|
||||||
|
plot_dots_1(ax, coordinates)
|
||||||
|
plot_dots_2(ax, coordinates2)
|
||||||
|
plot_dots_0(ax, [[0, 0]])
|
||||||
|
plt.savefig('twist_graphene.eps')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
def plot_dots_0(ax, coordinates):
|
||||||
|
for i in range(len(coordinates)):
|
||||||
|
ax.plot(coordinates[i][0], coordinates[i][1], 'ko', markersize=0.5)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_dots_1(ax, coordinates):
|
||||||
|
for i1 in range(len(coordinates)):
|
||||||
|
for i2 in range(len(coordinates)):
|
||||||
|
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
|
||||||
|
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=0.2)
|
||||||
|
for i in range(len(coordinates)):
|
||||||
|
ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=0.5)
|
||||||
|
|
||||||
|
|
||||||
|
def plot_dots_2(ax, coordinates):
|
||||||
|
for i1 in range(len(coordinates)):
|
||||||
|
for i2 in range(len(coordinates)):
|
||||||
|
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
|
||||||
|
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '--k', linewidth=0.2)
|
||||||
|
for i in range(len(coordinates)):
|
||||||
|
ax.plot(coordinates[i][0], coordinates[i][1], 'bo', markersize=0.5)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@@ -0,0 +1,48 @@
|
|||||||
|
import numpy as np
|
||||||
|
import gjh
|
||||||
|
|
||||||
|
a_00 = np.random.uniform(-1, 1)
|
||||||
|
a_0x = np.random.uniform(-1, 1)
|
||||||
|
a_0y = np.random.uniform(-1, 1)
|
||||||
|
a_0z = np.random.uniform(-1, 1)
|
||||||
|
|
||||||
|
a_x0 = np.random.uniform(-1, 1)
|
||||||
|
a_xx = np.random.uniform(-1, 1)
|
||||||
|
a_xy = np.random.uniform(-1, 1)
|
||||||
|
a_xz = np.random.uniform(-1, 1)
|
||||||
|
|
||||||
|
a_y0 = np.random.uniform(-1, 1)
|
||||||
|
a_yx = np.random.uniform(-1, 1)
|
||||||
|
a_yy = np.random.uniform(-1, 1)
|
||||||
|
a_yz = np.random.uniform(-1, 1)
|
||||||
|
|
||||||
|
a_z0 = np.random.uniform(-1, 1)
|
||||||
|
a_zx = np.random.uniform(-1, 1)
|
||||||
|
a_zy = np.random.uniform(-1, 1)
|
||||||
|
a_zz = np.random.uniform(-1, 1)
|
||||||
|
|
||||||
|
hamiltonian_1 = \
|
||||||
|
a_00*gjh.sigma_00()+a_0x*gjh.sigma_0x()+a_0y*gjh.sigma_0y()+a_0z*gjh.sigma_0z()+ \
|
||||||
|
a_x0*gjh.sigma_x0()+a_xx*gjh.sigma_xx()+a_xy*gjh.sigma_xy()+a_xz*gjh.sigma_xz()+ \
|
||||||
|
a_y0*gjh.sigma_y0()+a_yx*gjh.sigma_yx()+a_yy*gjh.sigma_yy()+a_yz*gjh.sigma_yz()+ \
|
||||||
|
a_z0*gjh.sigma_z0()+a_zx*gjh.sigma_zx()+a_zy*gjh.sigma_zy()+a_zz*gjh.sigma_zz()
|
||||||
|
eigenvalue_1 = gjh.calculate_eigenvalue(hamiltonian_1)
|
||||||
|
|
||||||
|
hamiltonian_2 = \
|
||||||
|
a_00*gjh.sigma_00()+a_0x*gjh.sigma_x0()+a_0y*gjh.sigma_y0()+a_0z*gjh.sigma_z0()+ \
|
||||||
|
a_x0*gjh.sigma_0x()+a_xx*gjh.sigma_xx()+a_xy*gjh.sigma_yx()+a_xz*gjh.sigma_zx()+ \
|
||||||
|
a_y0*gjh.sigma_0y()+a_yx*gjh.sigma_xy()+a_yy*gjh.sigma_yy()+a_yz*gjh.sigma_zy()+ \
|
||||||
|
a_z0*gjh.sigma_0z()+a_zx*gjh.sigma_xz()+a_zy*gjh.sigma_yz()+a_zz*gjh.sigma_zz()
|
||||||
|
eigenvalue_2 = gjh.calculate_eigenvalue(hamiltonian_2)
|
||||||
|
|
||||||
|
|
||||||
|
print()
|
||||||
|
print('Eigenvalue:')
|
||||||
|
print(eigenvalue_1)
|
||||||
|
print(eigenvalue_2)
|
||||||
|
print()
|
||||||
|
print('Difference of matrices:')
|
||||||
|
print(hamiltonian_1-hamiltonian_2)
|
||||||
|
print()
|
||||||
|
# print(hamiltonian_1)
|
||||||
|
# print(hamiltonian_2)
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user