Skip to content

Commit b56961f

Browse files
committed
optimize ELF calculations
1 parent a57707d commit b56961f

File tree

3 files changed

+80
-34
lines changed

3 files changed

+80
-34
lines changed

src/lib/ELF/Lindhard.m

+28-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function eps=Lindhard(q,omega,gamma,omega0)
1+
function [eps,epsimag]=Lindhard(q,omega,gamma,omega0)
22

33
% sq = numel(q);
44
% sw = numel(omega);
@@ -14,18 +14,35 @@
1414
chi = sqrt(1.0 / (pi*v_f));
1515

1616
z1_1 = omega./(q*v_f);
17+
z1_1(isnan(z1_1)) = 0;
1718

18-
z1 = bsxfun(@plus,bsxfun(@plus,z1_1,z),1j*gamma./(q*v_f));
19-
d1 = vos_g(z1);
20-
z2 = bsxfun(@plus,bsxfun(@minus,z1_1,z),1j*gamma./(q*v_f));
21-
d2 = vos_g(z2);
19+
% z1 = bsxfun(@plus,bsxfun(@plus,z1_1,z),1j*gamma./(q*v_f));
20+
% d1 = vos_g(z1);
21+
% z2 = bsxfun(@plus,bsxfun(@minus,z1_1,z),1j*gamma./(q*v_f));
22+
% d2 = vos_g(z2);
23+
gq = gamma./(q*v_f); gq(isnan(gq)) = 0;
24+
[reD1, imD1] = vos_g(z1_1 + z, gq);
25+
[reD2, imD2] = vos_g(z1_1 - z, gq);
26+
27+
% [reD1, imD1] = vos_g(complex(z1_1 + z, gamma./(q*v_f)));
28+
% [reD2, imD2] = vos_g(complex(z1_1 - z, gamma./(q*v_f)));
29+
30+
% d1 = vos_g(complex(z1_1 + z, gamma./(q*v_f)));
31+
% d2 = vos_g(complex(z1_1 - z, gamma./(q*v_f)));
32+
% reD1 = real(d1); imD1 = imag(d1);
33+
% reD2 = real(d2); imD2 = imag(d2);
2234

23-
zzz = z.^3;
24-
red1_d2 = real(d1) - real(d2);
25-
imd1_d2 = imag(d1) - imag(d2);
35+
red1_d2 = reD1 - reD2;
36+
imd1_d2 = imD1 - imD2;
2637

27-
epsreal = bsxfun(@plus,1,bsxfun(@times,red1_d2 ,chi^2./(4 * zzz)));
28-
epsimag = bsxfun(@times,imd1_d2 ,chi^2./(4 * zzz));
29-
eps = complex(epsreal,epsimag);
38+
chizzz = chi^2./(z.*z.*z * 4);
39+
epsreal = 1 + red1_d2 .* chizzz;
40+
epsimag = imd1_d2 .* chizzz;
41+
if nargout == 1
42+
eps = complex(epsreal,epsimag);
43+
else
44+
eps = epsreal;
45+
% epsimag = epsimag
46+
end
3047

3148
end

src/lib/ELF/Mermin.m

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
g_over_w = gamma ./ omega;
88
z1 = complex(1,g_over_w); % omega should be unequal 0
9-
z2 = bsxfun(@minus,Lindhard(q, omega, gamma, om_at_q),1);
10-
z3 = bsxfun(@minus,Lindhard(q, zeros(size(omega)), 0.0, om_at_q),1);
119

12-
top = bsxfun(@times,z1,z2);
13-
bottom = bsxfun(@plus,1,bsxfun(@times,complex(0,g_over_w),z2)./z3);
14-
eps = bsxfun(@plus,1,top./bottom);
10+
z2 = Lindhard(q, omega, gamma, om_at_q) - 1;
11+
z3 = Lindhard(q, zeros(size(omega)), 0.0, om_at_q) - 1;
12+
13+
top = z1 .* z2;
14+
bottom = complex(0,g_over_w).*z2./z3 + 1;
15+
eps = 1 + top./bottom;
1516

1617
end

src/lib/ELF/vos_g.m

+46-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,52 @@
1-
function eps=vos_g(z)
1+
function [out, outim]=vos_g(z, img_z)
22

3-
zplus1 = z + ones(size(z));
4-
zminus1 = z - ones(size(z));
5-
6-
dummy1 = log( abs(zplus1) ./ abs(zminus1) );
7-
dummy2 = angle(zplus1) - angle(zminus1);
8-
9-
real_sq = (real(z)).^2;
10-
imag_sq = (imag(z)).^2;
11-
12-
reim1 = bsxfun(@minus,1,real_sq - imag_sq);
13-
14-
outreal_1 = real(z) + 0.5*bsxfun(@times,reim1,dummy1);
15-
outreal = outreal_1 + bsxfun(@times,bsxfun(@times,real(z),imag(z)),dummy2);
3+
if nargin < 2
4+
reZ = real(z);
5+
imgZ = imag(z);
6+
else
7+
reZ = z;
8+
imgZ = img_z;
9+
end
10+
11+
zplus1 = z + 1;
12+
zminus1 = z - 1;
1613

17-
outimag_1 = imag(z) + 0.5*bsxfun(@times,reim1,dummy2);
18-
outimag = outimag_1 - bsxfun(@times,bsxfun(@times,real(z),imag(z)),dummy1);
14+
if any(any(imgZ ~= 0))
15+
imgZ2 = imgZ.*imgZ;
16+
% dummy1 = log( abs(zplus1) ./ abs(zminus1) );
17+
dummy1 = log( sqrt((zplus1.*zplus1+imgZ2) ./ (zminus1.*zminus1+imgZ2)) );
18+
% dummy2 = angle(zplus1) - angle(zminus1);
19+
dummy2 = atan2(imgZ, zplus1) - atan2(imgZ, zminus1);
20+
21+
reim1 = 1 - (reZ.^2 - imgZ2);
22+
23+
outreal_1 = reZ + 0.5*reim1.*dummy1;
24+
outreal = outreal_1 + reZ.*imgZ.*dummy2;
25+
26+
outimag_1 = imgZ + 0.5*reim1.*dummy2;
27+
outimag = outimag_1 - reZ.*imgZ.*dummy1;
28+
else
29+
% imgZ2 = imgZ.*imgZ;
30+
dummy1 = log( abs(zplus1) ./ abs(zminus1) );
31+
% dummy2 = angle(zplus1) - angle(zminus1);
32+
dummy2 = atan2(0, zplus1) - atan2(0, zminus1);
33+
34+
reim1 = 1 - reZ.^2;
35+
36+
outreal_1 = reZ + 0.5*reim1.*dummy1;
37+
outreal = outreal_1;%; + reZ.*imgZ.*dummy2;
38+
39+
outimag_1 = 0.5*reim1.*dummy2;% + imgZ
40+
outimag = outimag_1;% - reZ.*imgZ.*dummy1;
41+
end
1942

2043
% outreal = real(z) + 0.5* (1.0 - (real(z)*real(z) - imag(z)*imag(z))) *dummy1 + real(z)*imag(z)*dummy2;
21-
% outimag = imag(z) + 0.5*(1.0 - (real(z)*real(z) - imag(z)*imag(z)))*dummy2 - real(z)*imag(z)*dummy1;
44+
% outimag = imag(z) + 0.5* (1.0 - (real(z)*real(z) - imag(z)*imag(z))) *dummy2 - real(z)*imag(z)*dummy1;
2245

23-
eps=complex(outreal,outimag);
46+
if nargout == 1
47+
out = complex(outreal,outimag);
48+
else
49+
out = outreal;
50+
outim = outimag;
51+
end
2452
end

0 commit comments

Comments
 (0)