-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.jl~
163 lines (141 loc) · 4.28 KB
/
script.jl~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using Pkg; Pkg.activate("/Users/mbabar/Desktop/PhD/Analysis/Gerischer/")
loc = "/Users/mbabar/Desktop/PhD/Analysis/Gerischer/ElectrochemicalKinetics.jl/src/"
push!(LOAD_PATH, loc)
# Load libs
using MAT
using CSV
using DelimitedFiles
using Glob
using Interpolations
using QuadGK
using Plots
using ElectrochemicalKinetics
import ElectrochemicalKinetics.compute_k_cq
# Load functions
function integrand(
mhcd::MarcusHushChidseyDOS,
ox::Bool;
kT::Real = 0.026,
η::Real = 0.0,
V_q::Real = 0.0,
)
function marcus_term(E)
local exp_arg
if ox
exp_arg = -(( E .+ mhcd.λ) .^ 2) ./ (4 * mhcd.λ * kT)
else
exp_arg = -(( E .- mhcd.λ) .^ 2) ./ (4 * mhcd.λ * kT)
end
exp.(exp_arg)
end
fd(E) = ox ? 1 .- fermi_dirac(E; kT = kT) : fermi_dirac(E; kT = kT)
E -> mhcd.A .* ((mhcd.dos.interp_func.(E .+ V_q)).^ 1) .* marcus_term(E .+ η) .* fd(E)
end
function compute_k_cq(
η,
model::MarcusHushChidseyDOS,
ox::Bool;
Eo = -0.07, # E_f,red (solvent) - E_f,vac (bilayer)
C_dl = 10.0,
Vq_min = -0.5,
Vq_max = 0.5,
kT = 0.026,
E_min = model.dos.E_min,
E_max = model.dos.E_max,
)
V_dl_interp = calculate_Vdl_interp(model.dos.interp_func, Vq_min, Vq_max, C_dl)
#Vappl_data, Vdl_data = calculate_Vdl_interp(model.dos.interp_func, Vq_min, Vq_max, C_dl)
#v_interp = LinearInterpolation(Vappl_data, Vdl_data)
V_t = (Eo + η)
V_dl = V_dl_interp(V_t)
#V_dl = v_interp(V_t)
V_q = V_t - V_dl
if V_q < 0
E_max = E_max .- 0.05
E_min = E_min .- V_q .+ 0.05
elseif V_q > 0
E_min = E_min .+ 0.05
E_max = E_max .- V_q .- 0.05
end
#print(E_min, E_max)
k_rate = quadgk(integrand(model, ox; kT = kT, η = η, V_q = V_q), E_min, E_max)[1]
return k_rate, V_q
end
#Prefactor
function prefactor(
mhcd::MarcusHushChidseyDOS;
kT::Real = 0.026,
V_q = 0.0,
)
#fd(E) = ox ? 1 .- fermi_dirac(E; kT = kT) : fermi_dirac(E; kT = kT)
Ft(E) = (1/4kT).*((sech.(E./2kT)).^2) # Thermal broadening function
E -> ((mhcd.dos.interp_func.(E .+ V_q)).^ 1) .* Ft(E)
end
# Modify string
function chop_str(str::String)
while str[length(str)] == '0'
str = chop(str)
end
if str[length(str)] == '.'
str = chop(str)
end
return str
end
# Get rate k
#dos = [transpose(Elist) transpose(dos_tot)]
## Define model
Vq_max = 0.6
Vq_min = -0.6
C_dl = 10.0
λ = 0.82
Eo = -0.07
A = 1.0
η = 0.0
kT = 0.026 #eV
ef = 0.0 # Fermi level eV
#η_list = LinRange(-0.3, 0.3, 13)
#kox_data = zeros(Float64, length(flist));
#kred_data = zeros(Float64, length(flist));
#q_list = zeros(Float64, length(flist));
#mhcd = MarcusHushChidseyDOS(A, λ, dos)
#k_ox = compute_k_cq(0.4, mhcd, true; Vq_min=Vq_min, Vq_max=Vq_max)
#k_red = compute_k_cq(0.4, mhcd, false; Vq_min=Vq_min, Vq_max=Vq_max)
# ABA
file = matopen("aba_dos.mat")
Elist = transpose(read(file, "E_list"));
dos_tot = read(file, "dos");
dos_data = [Elist dos_tot]
mhcd = MarcusHushChidseyDOS(A, λ, dos_data, Ef=ef)
kox,V_q = compute_k_cq(η, mhcd, true; Eo=Eo, Vq_min=Vq_min, Vq_max=Vq_max);
kred,V_q = compute_k_cq(η, mhcd, false; Eo=Eo, Vq_min=Vq_min, Vq_max=Vq_max);
print("ABA ","k_ox ",k_ox," k_red ",k_red,"\n")
# ABC
file = matopen("abc_dos.mat")
Elist = transpose(read(file, "E_list"));
dos_tot = read(file, "dos");
dos_data = [Elist dos_tot]
mhcd = MarcusHushChidseyDOS(A, λ, dos_data, Ef=ef)
kox,V_q = compute_k_cq(η, mhcd, true; Eo=Eo, Vq_min=Vq_min, Vq_max=Vq_max);
kred,V_q = compute_k_cq(η, mhcd, false; Eo=Eo, Vq_min=Vq_min, Vq_max=Vq_max);
print("ABC ","k_ox ",kox," k_red ",kred,"\n")
#q_list = q_list[sortperm(q_list)]
#kox_data = kox_data[sortperm(q_list)]
#kred_data = kred_data[sortperm(q_list)]
# Write
#file = matopen("krate_tmblg.mat","w")
#write(file,"theta_list",q_list)
#write(file, "kox_data",kox_data)
#write(file, "kred_data",kred_data)
# Plots
#plot(η_list, abs.(kox_data- kred_data), label="AAA")
#xlabel!("η (eV)")
#ylabel!("kox - kred")
# Compute prefactor
#factor[i] = quadgk(prefactor(mhcd; kT = kT, V_q = V_q), -0.45, 0.45)[1]
#print(i,",",V_q,",",factor[i],"\n")
#print(k)
##
#@time begin
# mhcd = MarcusHushChidseyDOS(20.0, 0.82, dos)
# k = compute_k(0.4, mhcd; calc_cq=true, Vq_min=-0.45, Vq_max=0.45)
#end