Skip to content

Commit 06ecb8c

Browse files
committed
Initial commit
0 parents  commit 06ecb8c

13 files changed

+2325
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# slgc

analyse.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin python3
2+
# _*_ coding: utf-8 _*_
3+
import cmath as cm
4+
import numpy as np
5+
from matplotlib import pyplot as plt
6+
7+
# define useful constant.
8+
ev = 1.6e-19 # electron volt
9+
U0 = 0.5 * ev # barrier height
10+
m = 9e-31 # mass of electron
11+
h = 6.626e-34 # Plank constant
12+
h_ = h / (2 * np.pi)# h bar
13+
# a = 0.16 # barrier width
14+
15+
16+
def K1(ratio):
17+
ratio = 0.01 if ratio < 0.01 else ratio if ratio != 1 else ratio + 1e-10
18+
scale = 0.5e-8 / cm.sqrt(ratio)
19+
return scale * cm.sqrt(2 * m * ratio*U0 / np.square(h_))
20+
21+
22+
def K2(ratio):
23+
ratio = 0.01 if ratio < 0.01 else ratio if ratio != 1 else ratio + 1e-10
24+
scale = 0.5e-8 / cm.sqrt(ratio)
25+
return scale * cm.sqrt(2 * m * (ratio * U0 - U0) / np.square(h_))
26+
27+
28+
def D(k1, k2, a):
29+
return 4 * np.square(k1 * k2) / (
30+
np.square((np.square(k1) - np.square(k2)) * np.sin(k2 * a)) + 4 * np.square(k1 * k2))
31+
32+
33+
def R(d):
34+
return 1 - d
35+
36+
# a = 0.16
37+
# ratio = np.linspace(0, 10, 100)
38+
# d = [D(K1(r), K2(r), a) for r in ratio]
39+
# plt.title('Relationship With Energy of Wave')
40+
# plt.hold(True)
41+
# plt.plot(ratio, np.real(d), 'r', label='translation ratio')
42+
# plt.plot(ratio, np.real([R(d_) for d_ in d]), 'b', label='reflection ratio')
43+
# plt.legend()
44+
# plt.show()
45+
46+
ratio = 1
47+
a = np.linspace(1e-10, 1, 100)
48+
d = [D(K1(ratio), K2(ratio), a_) for a_ in a]
49+
plt.title('Relationship With Barrier Width')
50+
plt.hold(True)
51+
plt.plot(a, np.real(d), 'r', label='translation ratio')
52+
plt.plot(a, np.real([R(d_) for d_ in d]), 'b', label='reflection ratio')
53+
plt.legend()
54+
plt.show()

analysed.py

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import os
2+
import im2gif
3+
import cmath as cm
4+
import numpy as np
5+
from io import BytesIO
6+
from PIL import Image as im
7+
from matplotlib import pyplot as plt
8+
9+
def font(family='serif', color='black', weight='normal', size='16'):
10+
return {'family': family, 'color': color, 'weight': weight, 'size': size}
11+
12+
# relationship with ratio
13+
# ratio = np.linspace(0,5,1e4)
14+
# ratio[ratio==1]=1+1e-10
15+
# k0 = 1e-10
16+
# k1 = np.array([k0*cm.sqrt(r) for r in ratio])
17+
# k2 = np.array([k0*cm.sqrt(r-1) for r in ratio])
18+
# D = 4*np.square(k1)*np.square(k2)/(np.square(np.square(k1)-np.square(k2))*np.square(np.sin(k2))+4*np.square(k1)*np.square(k2))
19+
# R = 1-D
20+
# flg = plt.figure(figsize=(10,45/8))
21+
# plt.xlabel('$E/U_0$', fontdict=font())
22+
# plt.ylabel('$Intensity$', fontdict=font())
23+
# plt.title('Relationship With $E/U_0$')
24+
# plt.hold(True)
25+
# hd, = plt.plot(ratio, np.real(D), color='blue', label='transmission coefficient')
26+
# hr, = plt.plot(ratio, np.real(R), color='red', label='reflection coefficient')
27+
# plt.legend(fontsize=14, frameon=True, fancybox=True, framealpha=0.3)
28+
# plt.hold(False)
29+
# ht= plt.text(2.1,.5,'$k_0=%.2f$' % k0, fontdict=font(size=20))
30+
# # plt.show()
31+
# gif_root = './gif'
32+
# # check gif root dir
33+
# if not os.path.isdir(gif_root):
34+
# os.makedirs(gif_root)
35+
# FN = 50
36+
# images = []
37+
# for k0 in np.linspace(0,50,FN):
38+
# k1 = np.array([k0*cm.sqrt(r) for r in ratio])
39+
# k2 = np.array([k0*cm.sqrt(r-1) for r in ratio])
40+
41+
# D = 4*np.square(k1)*np.square(k2)/(np.square(np.square(k1)-np.square(k2))*np.square(np.sin(k2))+4*np.square(k1)*np.square(k2))
42+
# R = 1-D
43+
44+
# hd.set_ydata(np.real(D))
45+
# hr.set_ydata(np.real(R))
46+
# ht.set_text('$k_0=%.2f$' % k0)
47+
# buf = BytesIO()
48+
# plt.savefig(buf, format='png')
49+
# images.append(im.open(buf))
50+
# gif_path = os.path.join(gif_root, 'analyse_r2e.gif' % ratio)
51+
# im2gif.writeGif(filename=gif_path, images=images, duration=2 / FN)
52+
# print('gif file created at path: %s.' % os.path.abspath(gif_path))
53+
54+
# relationship with k0
55+
ratio = 0.01
56+
ratio = 0.01 if ratio < 0.01 else ratio if ratio != 1 else ratio + 1e-10
57+
k0 = np.linspace(0,20,1e3)
58+
59+
k1 = k0*cm.sqrt(ratio)
60+
k2 = k0*cm.sqrt(ratio-1)
61+
62+
D = 4*np.square(k1)*np.square(k2)/(np.square(np.square(k1)-np.square(k2))*np.square(np.sin(k2))+4*np.square(k1)*np.square(k2))
63+
R = 1-D
64+
65+
flg = plt.figure(figsize=(10,45/8))
66+
plt.xlabel('$k_0$', fontdict=font())
67+
plt.ylabel('$Intensity$', fontdict=font())
68+
plt.title('Relationship With $K0$')
69+
plt.hold(True)
70+
hd, = plt.plot(k0, np.real(D), color='blue', label='transmission coefficient')
71+
hr, = plt.plot(k0, np.real(R), color='red', label='reflection coefficient')
72+
plt.legend(fontsize=14, frameon=True, fancybox=True, framealpha=0.3)
73+
plt.hold(False)
74+
ht = plt.text(8,.5,'$E/U_0=%.2f$' % ratio, fontdict=font(size=20))
75+
# plt.show()
76+
gif_root = './gif'
77+
# check gif root dir
78+
if not os.path.isdir(gif_root):
79+
os.makedirs(gif_root)
80+
FN = 40
81+
images = []
82+
for ratio in np.linspace(0,5,FN):
83+
k1 = k0*cm.sqrt(ratio)
84+
k2 = k0*cm.sqrt(ratio-1)
85+
86+
D = 4*np.square(k1)*np.square(k2)/(np.square(np.square(k1)-np.square(k2))*np.square(np.sin(k2))+4*np.square(k1)*np.square(k2))
87+
R = 1-D
88+
89+
hd.set_ydata(np.real(D))
90+
hr.set_ydata(np.real(R))
91+
ht.set_text('$E/U_0=%.2f$' % ratio)
92+
buf = BytesIO()
93+
plt.savefig(buf, format='png')
94+
images.append(im.open(buf))
95+
gif_path = os.path.join(gif_root, 'analyse_e2r.gif' % ratio)
96+
im2gif.writeGif(filename=gif_path, images=images, duration=2 / FN)
97+
print('gif file created at path: %s.' % os.path.abspath(gif_path))

analysem.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import cmath as cm
2+
import numpy as np
3+
from matplotlib import pyplot as plt
4+
5+
def font(family='serif', color='black', weight='normal', size='16'):
6+
return {'family': family, 'color': color, 'weight': weight, 'size': size}
7+
8+
# ratio = np.linspace(0,5,1e4)
9+
# ratio[ratio==1]=1+1e-10
10+
11+
# k0 = 10
12+
# k1 = np.array([k0*cm.sqrt(r) for r in ratio])
13+
# k2 = np.array([k0*cm.sqrt(r-1) for r in ratio])
14+
15+
# D = 4*np.square(k1)*np.square(k2)/(np.square(np.square(k1)-np.square(k2))*np.square(np.sin(k2))+4*np.square(k1)*np.square(k2))
16+
# R = 1-D
17+
18+
# flg = plt.figure(figsize=(10,45/8))
19+
# plt.xlabel('$E/U_0$', fontdict=font())
20+
# plt.ylabel('$Intensity$', fontdict=font())
21+
# plt.title('Relationship With $E/U_0$')
22+
# plt.hold(True)
23+
# plt.plot(ratio, np.real(D), color='blue', label='transmission coefficient')
24+
# plt.plot(ratio, np.real(R), color='red', label='reflection coefficient')
25+
# plt.legend(fontsize=14, frameon=True, fancybox=True, framealpha=0.3)
26+
# plt.hold(False)
27+
# plt.text(2.1,.5,'$k_0=%.2f$' % k0, fontdict=font(size=20))
28+
# plt.show()
29+
30+
ratio = 0.01
31+
ratio = 0.01 if ratio < 0.01 else ratio if ratio != 1 else ratio + 1e-10
32+
k0 = np.linspace(0,20,1e3)
33+
34+
k1 = k0*cm.sqrt(ratio)
35+
k2 = k0*cm.sqrt(ratio-1)
36+
37+
D = 4*np.square(k1)*np.square(k2)/(np.square(np.square(k1)-np.square(k2))*np.square(np.sin(k2))+4*np.square(k1)*np.square(k2))
38+
R = 1-D
39+
40+
flg = plt.figure(figsize=(10,45/8))
41+
plt.xlabel('$k_0$', fontdict=font())
42+
plt.ylabel('$Intensity$', fontdict=font())
43+
plt.title('Relationship With $K0$')
44+
plt.hold(True)
45+
plt.plot(k0, np.real(D), color='blue', label='transmission coefficient')
46+
plt.plot(k0, np.real(R), color='red', label='reflection coefficient')
47+
plt.legend(fontsize=14, frameon=True, fancybox=True, framealpha=0.3)
48+
# plt.hold(False)
49+
plt.text(8,.5,'$E/U_0=%.2f$' % ratio, fontdict=font(size=20))
50+
plt.show()

0 commit comments

Comments
 (0)