-
Notifications
You must be signed in to change notification settings - Fork 2
/
find_Ef_f.m
57 lines (45 loc) · 1.61 KB
/
find_Ef_f.m
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
function[Ef,NN,roEf]=find_Ef_f(Ec,E,ro,Ntot,T)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Constants %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
e=1.602176487E-19; %% electron charge [C]
kB = 1.3806488E-23; %% Boltzmann's constant [J/K]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%% Computes the Fermi level at any T %%%%%%%%%%%%%%%%%%%%%%%%%%
if T==0
T=1e-10;
end
Ef=Ec(1);
Fermi= 1./(1+exp((E-Ef)/(kB*T/e))) ;
NtotX=0;
roEf=[];
for i=1:length(Ec)
roEf(:,i)=ro(:,i).*Fermi';
NN(i)= trapz(E,roEf(:,i),1) ;
NtotX = NtotX + NN(i) ;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Now, it will try to get as close as posible to the real Ef with an
% error of 0.1% by dichotomy
ddE=0.01; % eV
Ef1=Ef;
Ef2=Ef1+ddE;
while abs(NtotX - Ntot)/Ntot > 0.001 % find the Fermi level at any temperature
NN(length(Ec))=0;
if NtotX > Ntot
Ef = Ef - abs(Ef1-Ef2)/2 ;
Ef1 = Ef ;
else
Ef = Ef + abs(Ef1-Ef2)/2 ;
Ef2 = Ef ;
end
Fermi = 1./(1+exp((E-Ef)/(kB*T/e))) ; % Fermi Dirac distribution function
NtotX=0;
for i=1:length(Ec)
roEf(:,i) = ro(:,i).*Fermi';
NN(i)= trapz(E,roEf(:,i),1) ;
NtotX = NtotX + NN(i) ;
end
end
end