summaryrefslogtreecommitdiff
path: root/src/labat/ggaexc.f
diff options
context:
space:
mode:
Diffstat (limited to 'src/labat/ggaexc.f')
-rw-r--r--src/labat/ggaexc.f76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/labat/ggaexc.f b/src/labat/ggaexc.f
new file mode 100644
index 0000000..135b42e
--- /dev/null
+++ b/src/labat/ggaexc.f
@@ -0,0 +1,76 @@
1 subroutine ggaexc(r,db,i,imin,imax,doned,exc)
2c ggaexc calculates the exchange-correlation energy
3c input r : position coordinate (array)
4c input db : spin up and down density. (array)
5c input i : counter, i.e. present position = r(i)
6c input imin : min value of i
7c input imax : max value of i
8c in/output doned : true if density is splined
9c output exc : exchange-correlation energy
10 implicit logical (a-z)
11 logical doned
12 double precision r,db,gradd,gradup,graddn,fk,fkup,fkdn,sk,g
13 double precision sup,sdn,t,exc,ec
14 double precision onethi,twothi,pi,conkf,d,zet,rs,exup,exdn
15 double precision ex,eclda,ecgga
16 integer i,imin,imax
17 dimension r(561),db(2,561)
18 dimension gradd(561),gradup(561),graddn(561),fk(561),fkup(561)
19 dimension fkdn(561),sk(561),g(561),sup(561),sdn(561),t(561)
20 common/gga/gradd,gradup,graddn,fkup,fkdn,sk,g,sup,sdn,t
21 onethi = 1.d0/3.d0
22 twothi = 2.d0/3.d0
23 pi = 4.d0*datan(1.d0)
24 conkf = (3.d0*pi**2)**onethi
25 d = db(1,i) + db(2,i)
26 call grad(r,db,i,imin,imax,doned,gradd(i),gradup(i),graddn(i))
27
28c calculate the exchange energy, first spin up, then spin down
29
30 if (db(1,i).gt.1.d-100) then
31 fkup(i) = conkf*(2.d0*db(1,i))**onethi
32 sup(i) = dabs(gradup(i))/(2.d0*fkup(i)*db(1,i))
33 call exchen(2.d0*db(1,i),sup(i),exup)
34 else
35 fkup(i) = 0.d0
36 sup(i) = 0.d0
37 exup = 0.d0
38 endif
39 if (db(2,i).gt.1.d-100) then
40 fkdn(i) = conkf*(2.d0*db(2,i))**onethi
41 sdn(i) = dabs(graddn(i))/(2.d0*fkdn(i)*db(2,i))
42 call exchen(2.d0*db(2,i),sdn(i),exdn)
43 else
44 fkdn(i) = 0.d0
45 sdn(i) = 0.d0
46 exdn = 0.d0
47 endif
48 if (d.gt.1d-100) then
49 ex = (exup*db(1,i) + exdn*db(2,i))/d
50 else
51 ex = 0.d0
52 endif
53
54c exchange energy done, now calculate the correlation energy
55
56 fk(i) = conkf*d**onethi
57 sk(i) = dsqrt(4.d0*fk(i)/pi)
58 if (d.gt.1.d-100) then
59 zet = (db(1,i) - db(2,i))/d
60 else
61 zet = 0.d0
62 endif
63 g(i) = ((1.d0+zet)**twothi+(1.d0-zet)**twothi)/2.d0
64 if (d.gt.1.d-18) then
65 rs = (3.d0/(4.d0*pi*d))**onethi
66 t(i) = dabs(gradd(i))/(d*2*sk(i)*g(i))
67 call ldaec(rs,zet,eclda)
68 call ggaec(rs,zet,t(i),eclda,ecgga)
69 ec = eclda + ecgga
70 else
71 ec = 0.d0
72 endif
73 exc = ex + ec
74
75 return
76 end