The Elk Code
dielectric_bse.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2010 S. Sharma, J. K. Dewhurst and E. K. U. Gross.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 subroutine dielectric_bse
7 use modmain
8 use modomp
9 use modtest
10 implicit none
11 ! local variables
12 integer a1,a2,ik1,jk1
13 integer i1,j1,ist1,jst1
14 integer iw,ioc,i,j,nthd
15 integer ios,nmbse_
16 real(8) e,eji,t1,t2
17 complex(8) eta,z1
18 character(256) fname
19 ! allocatable arrays
20 real(8), allocatable :: w(:)
21 complex(8), allocatable :: pmat(:,:,:),sigma(:,:,:),zv(:,:)
22 ! initialise global variables
23 call init0
24 call init1
25 ! read Fermi energy from a file
26 call readefm
27 ! get the eigenvalues from file
28 do ik1=1,nkpt
29  call getevalsv(filext,ik1,vkl(:,ik1),evalsv(:,ik1))
30 end do
31 ! generate the BSE state index arrays
32 call genidxbse
33 ! allocate global BSE arrays
34 if (allocated(evalbse)) deallocate(evalbse)
35 allocate(evalbse(nmbse))
36 if (allocated(hmlbse)) deallocate(hmlbse)
37 allocate(hmlbse(nmbse,nmbse))
38 ! read in the BSE eigenvectors and eigenvalues
39 open(140,file='EVBSE.OUT',form='UNFORMATTED',action='READ',status='OLD', &
40  iostat=ios)
41 if (ios /= 0) then
42  write(*,*)
43  write(*,'("Error(dielectric_bse): error opening EVBSE.OUT")')
44  write(*,*)
45  stop
46 end if
47 read(140) nmbse_
48 if (nmbse /= nmbse_) then
49  write(*,*)
50  write(*,'("Error(dielectric_bse): differing nmbse")')
51  write(*,'(" current : ",I6)') nmbse
52  write(*,'(" EVBSE.OUT : ",I6)') nmbse_
53  stop
54 end if
55 read(140) evalbse
56 read(140) hmlbse
57 close(140)
58 ! set up the frequency grid (starting from zero)
59 allocate(w(nwplot))
60 t1=wplot(2)/dble(nwplot)
61 do iw=1,nwplot
62  w(iw)=t1*dble(iw-1)
63 end do
64 ! i divided by the complex relaxation time
65 eta=cmplx(0.d0,swidth,8)
66 allocate(pmat(nstsv,nstsv,3))
67 allocate(sigma(3,3,nwplot))
68 allocate(zv(3,nmbse))
69 sigma(:,:,:)=0.d0
70 zv(:,:)=0.d0
71 call holdthd(nmbse,nthd)
72 !$OMP PARALLEL DEFAULT(SHARED) &
73 !$OMP PRIVATE(ik1,jk1,a1,a2,e,i1,j1) &
74 !$OMP PRIVATE(ist1,jst1,eji,z1,i,j) &
75 !$OMP REDUCTION(+:sigma) &
76 !$OMP NUM_THREADS(nthd)
77 ! loop over non-reduced k-points
78 do ik1=1,nkptnr
79 ! equivalent reduced k-point
80  jk1=ivkik(ivk(1,ik1),ivk(2,ik1),ivk(3,ik1))
81 ! read the momentum matrix elements from file
82 !$OMP SINGLE
83  call getpmat(vkl(:,ik1),pmat)
84 !$OMP END SINGLE
85 !$OMP DO SCHEDULE(DYNAMIC)
86  do a2=1,nmbse
87  e=evalbse(a2)
88  do i1=1,nvbse
89  ist1=istbse(i1,ik1)
90  do j1=1,ncbse
91  jst1=jstbse(j1,ik1)
92  a1=ijkbse(i1,j1,ik1)
93  eji=evalsv(jst1,jk1)-evalsv(ist1,jk1)
94  z1=(e/eji)*hmlbse(a1,a2)
95  zv(1:3,a2)=zv(1:3,a2)+z1*pmat(ist1,jst1,1:3)
96  end do
97  end do
98  end do
99 !$OMP END DO
100 end do
101 !$OMP DO SCHEDULE(DYNAMIC)
102 do a2=1,nmbse
103  e=evalbse(a2)
104  if (abs(e) > 1.d-8) then
105  do i=1,3
106  do j=1,3
107  z1=zv(i,a2)*conjg(zv(j,a2))/e
108  sigma(i,j,:)=sigma(i,j,:)+z1/(w(:)-e+eta)+conjg(z1)/(w(:)+e+eta)
109  end do
110  end do
111  end if
112 end do
113 !$OMP END DO
114 !$OMP END PARALLEL
115 call freethd(nthd)
117 sigma(:,:,:)=z1*sigma(:,:,:)
118 ! loop over tensor components
119 do ioc=1,noptcomp
120  i=optcomp(1,ioc)
121  j=optcomp(2,ioc)
122  t1=0.d0
123  if (i == j) t1=1.d0
124  write(fname,'("EPSILON_BSE_",2I1,".OUT")') i,j
125  open(50,file=trim(fname),form='FORMATTED')
126  do iw=1,nwplot
127  t2=t1-fourpi*aimag(sigma(i,j,iw)/(w(iw)+eta))
128  write(50,'(2G18.10)') w(iw),t2
129  end do
130  write(50,*)
131  do iw=1,nwplot
132  t2=fourpi*dble(sigma(i,j,iw)/(w(iw)+eta))
133  write(50,'(2G18.10)') w(iw),t2
134  end do
135  close(50)
136 end do
137 write(*,*)
138 write(*,'("Info(dielectric_bse):")')
139 write(*,'(" dielectric tensor written to EPSILON_BSE_ij.OUT")')
140 write(*,'(" for components")')
141 do ioc=1,noptcomp
142  write(*,'(" i = ",I1,", j = ",I1)') optcomp(1:2,ioc)
143 end do
144 ! write sigma to test file
145 call writetest(187,'BSE optical conductivity',nv=nwplot,tol=1.d-2,zva=sigma)
146 deallocate(w,pmat,sigma,zv)
147 ! deallocate global BSE arrays
148 deallocate(evalbse,hmlbse)
149 end subroutine
150 
subroutine writetest(id, descr, nv, iv, iva, tol, rv, rva, zv, zva)
Definition: modtest.f90:16
character(256) filext
Definition: modmain.f90:1301
real(8), dimension(:,:), allocatable evalsv
Definition: modmain.f90:921
integer nkpt
Definition: modmain.f90:461
real(8) omega
Definition: modmain.f90:20
subroutine getevalsv(fext, ikp, vpl, evalsv_)
Definition: getevalsv.f90:7
subroutine getpmat(vpl, pmat)
Definition: getpmat.f90:7
integer, dimension(:,:,:), allocatable ijkbse
Definition: modmain.f90:1199
Definition: modomp.f90:6
real(8) swidth
Definition: modmain.f90:895
integer, dimension(:,:,:), allocatable ivkik
Definition: modmain.f90:467
integer nkptnr
Definition: modmain.f90:463
integer, dimension(:,:), allocatable jstbse
Definition: modmain.f90:1197
integer nstsv
Definition: modmain.f90:889
real(8), dimension(2) wplot
Definition: modmain.f90:1079
subroutine readefm
Definition: readefm.f90:10
real(8) occmax
Definition: modmain.f90:901
integer, dimension(3, 27) optcomp
Definition: modmain.f90:1093
integer nmbse
Definition: modmain.f90:1193
subroutine init1
Definition: init1.f90:10
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
integer noptcomp
Definition: modmain.f90:1091
subroutine dielectric_bse
subroutine genidxbse
Definition: genidxbse.f90:7
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
complex(8), dimension(:,:), allocatable hmlbse
Definition: modmain.f90:1201
complex(8), parameter zi
Definition: modmain.f90:1240
real(8) wkptnr
Definition: modmain.f90:477
subroutine init0
Definition: init0.f90:10
real(8), parameter fourpi
Definition: modmain.f90:1234
real(8), dimension(:), allocatable evalbse
Definition: modmain.f90:1203
integer nwplot
Definition: modmain.f90:1073
integer nvbse
Definition: modmain.f90:1179
integer ncbse
Definition: modmain.f90:1179
integer, dimension(:,:), allocatable ivk
Definition: modmain.f90:465
integer, dimension(:,:), allocatable istbse
Definition: modmain.f90:1195