The Elk Code
ephcouple.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2008 J. K. Dewhurst, S. Sharma and C. Ambrosch-Draxl.
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 ephcouple
7 use modmain
8 use modphonon
9 use modmpi
10 use modomp
11 implicit none
12 ! local variables
13 integer iq,ik,jk,jkq
14 integer ist,jst,isym,ip
15 integer is,ia,ias,js,jas
16 integer nr,nri,np,i,n,nthd
17 real(8) vl(3),de,x
18 real(8) t1,t2,t3,t4
19 ! allocatable arrays
20 real(8), allocatable :: gq(:,:),y(:)
21 complex(8), allocatable :: ev(:,:),a(:,:)
22 complex(8), allocatable :: dvmt(:,:,:),dvir(:,:)
23 complex(8), allocatable :: zfmt(:),gzfmt(:,:,:)
24 complex(8), allocatable :: ephmat(:,:,:)
25 ! external functions
26 real(8), external :: sdelta
27 ! increase the angular momentum cut-off on the inner part of the muffin-tin
29 lmaxi=max(lmaxi,4)
30 ! initialise universal variables
31 call init0
32 call init1
33 call init2
34 call initph
35 ! allocate global arrays
36 if (allocated(dvsbs)) deallocate(dvsbs)
38 allocate(dvsbs(n))
39 dvsmt(1:npmtmax,1:natmtot) => dvsbs(1:)
40 if (allocated(dvsir)) deallocate(dvsir)
41 allocate(dvsir(ngtot))
42 ! allocate local arrays
43 allocate(gq(nbph,nqpt),y(nbph))
44 allocate(ev(nbph,nbph),a(nbph,nbph))
45 allocate(dvmt(npcmtmax,natmtot,nbph),dvir(ngtc,nbph))
46 allocate(zfmt(npmtmax),gzfmt(npmtmax,3,natmtot))
47 ! read in the density and potentials from file
48 call readstate
49 ! Fourier transform Kohn-Sham potential to G-space
50 call genvsig
51 ! set the speed of light >> 1 (non-relativistic approximation)
52 solsc=sol*100.d0
53 ! new file extension for eigenvector files with c >> 1
54 filext='_EPH.OUT'
55 ! generate the first- and second-variational eigenvectors and eigenvalues
56 call linengy
57 call genapwlofr
58 call gensocfr
59 call genevfsv
60 ! precise determination of the Fermi energy
62 swidth=1.d-5
63 call occupy
65 ! restore the speed of light
66 solsc=sol
67 ! compute the gradients of the Kohn-Sham potential for the rigid-ion term
68 do ias=1,natmtot
69  is=idxis(ias)
70  nr=nrmt(is)
71  nri=nrmti(is)
72  call rtozfmt(nr,nri,vsmt(:,ias),zfmt)
73  call gradzfmt(nr,nri,rlmt(:,-1,is),wcrmt(:,:,is),zfmt,npmtmax,gzfmt(:,:,ias))
74 end do
75 ! energy window for calculating the electron-phonon matrix elements
76 if (task == 240) then
77  de=4.d0*swidth
78 else
79  de=1.d6
80 end if
81 ! loop over phonon q-points
82 do iq=1,nqpt
83  if (mp_mpi) write(*,'("Info(ephcouple): ",I6," of ",I6," q-points")') iq,nqpt
84 ! diagonalise the dynamical matrix
85  call dynev(dynq(:,:,iq),wphq(:,iq),ev)
86 ! generate the matrix for converting between Cartesian and phonon coordinates
87  call genmcph(wphq(:,iq),ev,a)
88  i=0
89  do is=1,nspecies
90  nr=nrmt(is)
91  nri=nrmti(is)
92  np=npmt(is)
93  do ia=1,natoms(is)
94  ias=idxas(ia,is)
95  do ip=1,3
96  i=i+1
97 ! read in the Cartesian change in Kohn-Sham potential
98  call readdvs(iq,is,ia,ip,dvsmt,dvsir)
99 ! add the rigid-ion term
100  dvsmt(1:np,ias)=dvsmt(1:np,ias)-gzfmt(1:np,ip,ias)
101  do jas=1,natmtot
102  js=idxis(jas)
103 ! convert to coarse radial mesh
104  call zfmtftoc(nrcmt(js),nrcmti(js),dvsmt(:,jas),dvmt(:,jas,i))
105 ! apply the radial integration weights
106  call zfmtwr(nrcmt(js),nrcmti(js),wr2cmt(:,js),dvmt(:,jas,i))
107  end do
108 ! multiply the interstitial potential with the characteristic function and
109 ! convert to coarse grid
110  call zfirftoc(dvsir,dvir(:,i))
111  end do
112  end do
113  end do
114  y(1:nbph)=0.d0
115  call holdthd(nkptnr/np_mpi,nthd)
116 !$OMP PARALLEL DEFAULT(SHARED) &
117 !$OMP PRIVATE(ephmat,jk,vl,isym,jkq) &
118 !$OMP PRIVATE(t1,t2,t3,t4,ist,jst,x,i) &
119 !$OMP REDUCTION(+:y) &
120 !$OMP NUM_THREADS(nthd)
121  allocate(ephmat(nstsv,nstsv,nbph))
122 !$OMP DO SCHEDULE(DYNAMIC)
123  do ik=1,nkptnr
124 ! distribute among MPI processes
125  if (mod(ik-1,np_mpi) /= lp_mpi) cycle
126 ! equivalent reduced k-point
127  jk=ivkik(ivk(1,ik),ivk(2,ik),ivk(3,ik))
128 ! compute the electron-phonon coupling matrix elements
129  call genephmat(iq,ik,de,a,dvmt,dvir,ephmat)
130 ! write the matrix elements to file if required
131  if (task == 241) call putephmat(iq,ik,ephmat)
132 ! k+q-vector in lattice coordinates
133  vl(1:3)=vkl(1:3,ik)+vql(1:3,iq)
134 ! index to k+q-vector
135  call findkpt(vl,isym,jkq)
136  t1=pi*wkptnr*occmax
137 ! loop over second-variational states
138  do ist=1,nstsv
139  x=(evalsv(ist,jkq)-efermi)/swidth
140  t2=t1*sdelta(stype,x)/swidth
141  do jst=1,nstsv
142 ! loop over phonon branches
143  do i=1,nbph
144  x=(wphq(i,iq)+evalsv(jst,jk)-evalsv(ist,jkq))/swidth
145  t3=t2*sdelta(stype,x)/swidth
146  t4=dble(ephmat(ist,jst,i))**2+aimag(ephmat(ist,jst,i))**2
147  y(i)=y(i)+wphq(i,iq)*t3*t4
148  end do
149  end do
150  end do
151 ! end loop over k-points
152  end do
153 !$OMP END DO
154  deallocate(ephmat)
155 !$OMP END PARALLEL
156  call freethd(nthd)
157 ! store in phonon linewidths array
158  gq(1:nbph,iq)=y(1:nbph)
159 ! end loop over phonon q-points
160 end do
161 ! add gq from each MPI process
162 if (np_mpi > 1) then
163  n=nbph*nqpt
164  call mpi_allreduce(mpi_in_place,gq,n,mpi_double_precision,mpi_sum,mpicom, &
165  ierror)
166 end if
167 ! restore the default file extension
168 filext='.OUT'
169 if (mp_mpi) then
170 ! write the phonon linewidths to file
171  call writegamma(gq)
172 ! write electron-phonon coupling constants to file
173  call writelambda(gq)
174  if (task == 241) then
175  write(*,*)
176  write(*,'("Info(ephcouple):")')
177  write(*,'(" wrote electron-phonon matrix elements to EPHMAT.OUT")')
178  end if
179 end if
180 ! deallocate global arrays
181 deallocate(dvsbs)
182 ! deallocate local arrays
183 deallocate(gq,y,ev,a,dvmt,dvir,zfmt,gzfmt)
184 ! restore original input parameters
186 end subroutine
187 
subroutine genevfsv
Definition: genevfsv.f90:7
real(8) efermi
Definition: modmain.f90:907
integer npcmtmax
Definition: modmain.f90:216
character(256) filext
Definition: modmain.f90:1301
subroutine zfirftoc(zfir, zfirc)
Definition: zfirftoc.f90:7
real(8), dimension(:,:), allocatable evalsv
Definition: modmain.f90:921
integer task
Definition: modmain.f90:1299
logical mp_mpi
Definition: modmpi.f90:17
integer ngtot
Definition: modmain.f90:390
subroutine occupy
Definition: occupy.f90:10
integer ngtc
Definition: modmain.f90:392
pure subroutine zfmtwr(nr, nri, wr, zfmt)
Definition: zfmtwr.f90:7
integer nqpt
Definition: modmain.f90:525
integer, dimension(maxatoms, maxspecies) idxas
Definition: modmain.f90:42
complex(8), dimension(:), allocatable dvsir
Definition: modphonon.f90:112
real(8), dimension(:,:,:), allocatable rlmt
Definition: modmain.f90:179
integer, dimension(maxspecies) npmt
Definition: modmain.f90:213
subroutine writelambda(gq)
Definition: writelambda.f90:7
Definition: modomp.f90:6
subroutine gradzfmt(nr, nri, ri, wcr, zfmt, ld, gzfmt)
Definition: gradzfmt.f90:10
real(8) swidth
Definition: modmain.f90:895
subroutine ephcouple
Definition: ephcouple.f90:7
integer, dimension(:,:,:), allocatable ivkik
Definition: modmain.f90:467
subroutine genephmat(iq, ik, de, a, dvmt, dvir, ephmat)
Definition: genephmat.f90:7
pure subroutine rtozfmt(nr, nri, rfmt, zfmt)
Definition: rtozfmt.f90:7
integer lmaxi0
Definition: modmain.f90:205
subroutine genvsig
Definition: genvsig.f90:10
integer nkptnr
Definition: modmain.f90:463
real(8), parameter pi
Definition: modmain.f90:1232
subroutine genapwlofr
Definition: genapwlofr.f90:7
subroutine gensocfr
Definition: gensocfr.f90:7
integer np_mpi
Definition: modmpi.f90:13
subroutine linengy
Definition: linengy.f90:10
real(8) swidth0
Definition: modmain.f90:895
integer nstsv
Definition: modmain.f90:889
subroutine writegamma(gq)
Definition: writegamma.f90:7
pure subroutine zfmtftoc(nrc, nrci, zfmt, zfcmt)
Definition: zfmtftoc.f90:7
real(8) occmax
Definition: modmain.f90:901
subroutine dynev(dq, wq, ev)
Definition: dynev.f90:7
complex(8), dimension(:,:,:), allocatable dynq
Definition: modphonon.f90:27
integer nbph
Definition: modphonon.f90:13
complex(8), dimension(:,:), pointer, contiguous dvsmt
Definition: modphonon.f90:110
subroutine readdvs(iq, is, ia, ip, dvsmt, dvsir)
Definition: readdvs.f90:7
subroutine init2
Definition: init2.f90:7
real(8), dimension(:,:), allocatable vql
Definition: modmain.f90:545
real(8), parameter sol
Definition: modmain.f90:1251
subroutine initph
Definition: initph.f90:7
real(8) solsc
Definition: modmain.f90:1253
subroutine init1
Definition: init1.f90:10
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
integer, dimension(maxspecies) natoms
Definition: modmain.f90:36
real(8), dimension(:,:), allocatable wr2cmt
Definition: modmain.f90:189
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
integer stype
Definition: modmain.f90:891
Definition: modmpi.f90:6
complex(8), dimension(:), allocatable, target dvsbs
Definition: modphonon.f90:108
subroutine readstate
Definition: readstate.f90:10
integer lp_mpi
Definition: modmpi.f90:15
pure subroutine genmcph(wq, ev, a)
Definition: genmcph.f90:7
integer nspecies
Definition: modmain.f90:34
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
subroutine putephmat(iq, ik, ephmat)
Definition: putephmat.f90:7
real(8) wkptnr
Definition: modmain.f90:477
integer npmtmax
Definition: modmain.f90:216
subroutine init0
Definition: init0.f90:10
integer natmtot
Definition: modmain.f90:40
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
subroutine findkpt(vpl, isym, ik)
Definition: findkpt.f90:7
real(8), dimension(:,:,:), allocatable wcrmt
Definition: modmain.f90:187
real(8), dimension(:,:), pointer, contiguous vsmt
Definition: modmain.f90:649
integer, dimension(maxspecies) nrmti
Definition: modmain.f90:211
real(8), dimension(:,:), allocatable wphq
Definition: modphonon.f90:31
integer, dimension(:,:), allocatable ivk
Definition: modmain.f90:465
integer mpicom
Definition: modmpi.f90:11
integer ierror
Definition: modmpi.f90:19
integer, dimension(maxspecies) nrmt
Definition: modmain.f90:150
integer lmaxi
Definition: modmain.f90:205