This commit is contained in:
2023-11-07 03:38:46 +08:00
parent 1e7c4c0e68
commit bc3890c25b
212 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
(* 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[ 2422, 82]
NotebookOptionsPosition[ 2082, 67]
NotebookOutlinePosition[ 2469, 84]
CellTagsIndexPosition[ 2426, 81]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[{
RowBox[{"Clear", "[", "\"\<`*\>\"", "]"}], "\n",
RowBox[{
RowBox[{"k1a1", "=", "kx"}], ";"}], "\n",
RowBox[{
RowBox[{"k2a2", "=",
RowBox[{
RowBox[{"kx", "/", "2"}], "+",
RowBox[{"ky", "*",
RowBox[{
RowBox[{"Sqrt", "[", "3", "]"}], "/", "2"}]}]}]}], ";"}], "\n",
RowBox[{
RowBox[{"k3a3", "=",
RowBox[{
RowBox[{
RowBox[{"-", "kx"}], "/", "2"}], "+",
RowBox[{"ky", "*",
RowBox[{
RowBox[{"Sqrt", "[", "3", "]"}], "/", "2"}]}]}]}], ";"}], "\n",
RowBox[{
RowBox[{"H", "=",
RowBox[{
RowBox[{"-", "2"}], "*", "t", "*",
RowBox[{"(",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"0", ",",
RowBox[{"Cos", "[", "k1a1", "]"}], ",",
RowBox[{"Cos", "[", "k2a2", "]"}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"Cos", "[", "k1a1", "]"}], ",", "0", ",",
RowBox[{"Cos", "[", "k3a3", "]"}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"Cos", "[", "k2a2", "]"}], ",",
RowBox[{"Cos", "[", "k3a3", "]"}], ",", "0"}], "}"}]}], "}"}],
")"}]}]}], ";"}], "\n",
RowBox[{"MatrixForm", "[", "H", "]"}], "\n",
RowBox[{"eigenvalue", "=",
RowBox[{"MatrixForm", "[",
RowBox[{"Eigenvalues", "[", "H", "]"}], "]"}]}]}], "Input",
CellChangeTimes->{{3.837485198864452*^9, 3.837485198867505*^9}, {
3.837497369979506*^9, 3.8374974574378343`*^9}},
CellLabel->"",ExpressionUUID->"a7abdb4e-e7ef-4556-9d32-d94836d031ca"]
},
WindowSize->{1147, 812},
WindowMargins->{{Automatic, 228}, {22, Automatic}},
Magnification:>1.7 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, 1520, 45, 514, "Input",ExpressionUUID->"a7abdb4e-e7ef-4556-9d32-d94836d031ca"]
}
]
*)

View File

@@ -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/16730
"""
import numpy as np
from math import *
def hamiltonian(kx, ky): # kagome lattice
k1_dot_a1 = kx
k2_dot_a2 = kx/2+ky*sqrt(3)/2
k3_dot_a3 = -kx/2+ky*sqrt(3)/2
h = np.zeros((3, 3), dtype=complex)
h[0, 1] = 2*cos(k1_dot_a1)
h[0, 2] = 2*cos(k2_dot_a2)
h[1, 2] = 2*cos(k3_dot_a3)
h = h + h.transpose().conj()
t = 1
h = -t*h
return h
def main():
kx_array = np.linspace(-pi ,pi, 500)
ky_array = np.linspace(-pi ,pi, 500)
eigenvalue_array = calculate_eigenvalue_with_two_parameters(kx_array, ky_array, hamiltonian)
plot_3d_surface(kx_array, ky_array, eigenvalue_array, xlabel='kx', ylabel='ky', zlabel='E', rcount=200, ccount=200)
# import guan
# eigenvalue_array = guan.calculate_eigenvalue_with_two_parameters(kx_array, ky_array, hamiltonian)
# guan.plot_3d_surface(kx_array, ky_array, eigenvalue_array, xlabel='kx', ylabel='ky', zlabel='E', rcount=200, ccount=200)
def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_function, print_show=0, print_show_more=0):
dim_x = np.array(x_array).shape[0]
dim_y = np.array(y_array).shape[0]
if np.array(hamiltonian_function(0,0)).shape==():
eigenvalue_array = np.zeros((dim_y, dim_x, 1))
i0 = 0
for y0 in y_array:
j0 = 0
for x0 in x_array:
hamiltonian = hamiltonian_function(x0, y0)
eigenvalue_array[i0, j0, 0] = np.real(hamiltonian)
j0 += 1
i0 += 1
else:
dim = np.array(hamiltonian_function(0, 0)).shape[0]
eigenvalue_array = np.zeros((dim_y, dim_x, dim))
i0 = 0
for y0 in y_array:
j0 = 0
if print_show==1:
print(y0)
for x0 in x_array:
if print_show_more==1:
print(x0)
hamiltonian = hamiltonian_function(x0, y0)
eigenvalue, eigenvector = np.linalg.eigh(hamiltonian)
eigenvalue_array[i0, j0, :] = eigenvalue
j0 += 1
i0 += 1
return eigenvalue_array
def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', fontsize=20, labelsize=15, show=1, save=0, filename='a', file_format='.jpg', dpi=300, z_min=None, z_max=None, rcount=100, ccount=100):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
matrix = np.array(matrix)
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plt.subplots_adjust(bottom=0.1, right=0.65)
x_array, y_array = np.meshgrid(x_array, y_array)
if len(matrix.shape) == 2:
surf = ax.plot_surface(x_array, y_array, matrix, rcount=rcount, ccount=ccount, cmap=cm.coolwarm, linewidth=0, antialiased=False)
elif len(matrix.shape) == 3:
for i0 in range(matrix.shape[2]):
surf = ax.plot_surface(x_array, y_array, matrix[:,:,i0], rcount=rcount, ccount=ccount, cmap=cm.coolwarm, linewidth=0, antialiased=False)
ax.set_title(title, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_zlabel(zlabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.zaxis.set_major_locator(LinearLocator(5))
ax.zaxis.set_major_formatter('{x:.2f}')
if z_min!=None or z_max!=None:
if z_min==None:
z_min=matrix.min()
if z_max==None:
z_max=matrix.max()
ax.set_zlim(z_min, z_max)
ax.tick_params(labelsize=labelsize)
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
[label.set_fontname('Times New Roman') for label in labels]
cax = plt.axes([0.8, 0.1, 0.05, 0.8])
cbar = fig.colorbar(surf, cax=cax)
cbar.ax.tick_params(labelsize=labelsize)
for l in cbar.ax.yaxis.get_ticklabels():
l.set_family('Times New Roman')
if save == 1:
plt.savefig(filename+file_format, dpi=dpi)
if show == 1:
plt.show()
plt.close('all')
if __name__ == '__main__':
main()