The Elk Code
phonon.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2010 J. K. Dewhurst, S. Sharma 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 phonon
7 use modmain
8 use modphonon
9 use modpw
10 use modmpi
11 use modomp
12 use moddelf
13 implicit none
14 ! local variables
15 integer ik,jk,iv(3),jspn,idm
16 integer is,ia,ias,ip,nthd
17 integer nmix,nwork,n,lp
18 ! use Broyden mixing only
19 integer, parameter :: mtype=3
20 real(8) ddv,a,b
21 character(256) fext
22 ! allocatable arrays
23 real(8), allocatable :: evalfv(:,:),work(:)
24 complex(8), allocatable :: dyn(:,:)
25 complex(8), allocatable :: apwalm(:,:,:,:,:),apwalmq(:,:,:,:,:)
26 complex(8), allocatable :: dapwalm(:,:,:,:),dapwalmq(:,:,:,:)
27 complex(8), allocatable :: evecfv(:,:,:),devecfv(:,:,:)
28 complex(8), allocatable :: evecsv(:,:),devecsv(:,:)
29 ! initialise universal variables
30 call init0
31 call init1
32 call init2
33 call init4
34 ! check k-point grid is commensurate with q-point grid
35 iv(:)=mod(ngridk(:),ngridq(:))
36 if ((iv(1) /= 0).or.(iv(2) /= 0).or.(iv(3) /= 0)) then
37  write(*,*)
38  write(*,'("Error(phonon): k-point grid incommensurate with q-point grid")')
39  write(*,'(" ngridk : ",3I6)') ngridk
40  write(*,'(" ngridq : ",3I6)') ngridq
41  write(*,*)
42  stop
43 end if
44 if (lmaxi < 2) then
45  write(*,*)
46  write(*,'("Error(phonon): lmaxi too small for calculating DFPT phonons : ",&
47  &I4)') lmaxi
48  write(*,'(" Run the ground-state calculation again with lmaxi >= 2")')
49  write(*,*)
50  stop
51 end if
52 if (spinpol) then
53  write(*,*)
54  write(*,'("Error(phonon): spin-polarised phonons not yet available")')
55  write(*,*)
56  stop
57 end if
58 ! check spin-spiral de-phasing is not used
59 if (ssdph) then
60  write(*,*)
61  write(*,'("Error(phonon): ssdph should be .false. for DFPT phonons")')
62  write(*,*)
63  stop
64 end if
65 ! check for zero atoms
66 if (natmtot == 0) return
67 ! read in the density and potentials
68 call readstate
69 ! Fourier transform Kohn-Sham potential to G-space
70 call genvsig
71 ! find the new linearisation energies
72 call linengy
73 ! generate the APW and local-orbital radial functions and integrals
74 call genapwlofr
75 ! generate the spin-orbit coupling radial functions
76 call gensocfr
77 ! get the eigenvalues and occupation numbers from file
78 do ik=1,nkpt
79  call getevalsv(filext,ik,vkl(:,ik),evalsv(:,ik))
80  call getoccsv(filext,ik,vkl(:,ik),occsv(:,ik))
81 end do
82 ! size of mixing vector (complex array)
83 nmix=2*size(dvsbs)
84 ! determine the size of the mixer work array
85 nwork=-1
86 call mixerifc(mtype,nmix,dvsbs,ddv,nwork,work)
87 allocate(work(nwork))
88 ! allocate dynamical matrix column
89 allocate(dyn(3,natmtot))
90 ! begin new dynamical matrix task
91 10 continue
92 call dyntask(80,fext)
93 ! if nothing more to do then return
94 if (iqph == 0) return
95 if (mp_mpi) then
96  write(*,'("Info(phonon): working on ",A)') 'DYN'//trim(fext)
97 ! open RMSDDVS.OUT
98  open(65,file='RMSDDVS'//trim(fext),form='FORMATTED')
99 end if
100 ! zero the dynamical matrix row
101 dyn(:,:)=0.d0
102 ! check to see if mass is considered infinite
103 if (spmass(isph) <= 0.d0) goto 20
104 ! generate the G+k+q-vectors and related quantities
105 call gengkqvec(iqph)
106 ! generate the G+q-vectors and related quantities
107 call gengqvec(iqph)
108 ! generate the Coulomb Green's function in G+q-space
109 call gengclgq(.false.,iqph,ngvec,gqc,gclgq)
110 ! generate the characteristic function derivative
111 call gendcfun
112 ! generate the gradient of the Kohn-Sham potential
113 call gengvsmt
114 ! zero the density derivative
115 drhmg(:)=0.d0
116 ! initialise the potential derivative
117 call dpotks
118 call gendvsig
119 ! initialise the mixer
120 iscl=0
121 call mixerifc(mtype,nmix,dvsbs,ddv,nwork,work)
122 ! initialise the Fermi energy and occupancy derivatives
123 defermi=0.d0
124 doccsv(:,:)=0.d0
125 ! set last self-consistent loop flag
126 tlast=.false.
127 ! begin the self-consistent loop
128 do iscl=1,maxscl
129 ! compute the Hamiltonian radial integral derivatives
130  call dhmlrad
131 ! zero the density and magnetisation derivatives
132  drhomt(:,:)=0.d0
133  drhoir(:)=0.d0
134  if (spinpol) then
135  dmagmt(:,:,:)=0.d0
136  dmagir(:,:)=0.d0
137  end if
138 ! parallel loop over k-points
139  call holdthd(nkptnr/np_mpi,nthd)
140 !$OMP PARALLEL DEFAULT(SHARED) &
141 !$OMP PRIVATE(evalfv,apwalm,apwalmq,dapwalm,dapwalmq) &
142 !$OMP PRIVATE(evecfv,devecfv,evecsv,devecsv,jk,jspn) &
143 !$OMP NUM_THREADS(nthd)
144  allocate(evalfv(nstfv,nspnfv))
145  allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot,nspnfv))
146  allocate(apwalmq(ngkmax,apwordmax,lmmaxapw,natmtot,nspnfv))
147  allocate(dapwalm(ngkmax,apwordmax,lmmaxapw,nspnfv))
148  allocate(dapwalmq(ngkmax,apwordmax,lmmaxapw,nspnfv))
149  allocate(evecfv(nmatmax,nstfv,nspnfv),devecfv(nmatmax,nstfv,nspnfv))
150  allocate(evecsv(nstsv,nstsv),devecsv(nstsv,nstsv))
151 !$OMP DO SCHEDULE(DYNAMIC)
152  do ik=1,nkptnr
153 ! distribute among MPI processes
154  if (mod(ik-1,np_mpi) /= lp_mpi) cycle
155 ! equivalent reduced k-point
156  jk=ivkik(ivk(1,ik),ivk(2,ik),ivk(3,ik))
157 ! compute the matching coefficients and derivatives
158  do jspn=1,nspnfv
159  call match(ngk(jspn,ik),vgkc(:,:,jspn,ik),gkc(:,jspn,ik), &
160  sfacgk(:,:,jspn,ik),apwalm(:,:,:,:,jspn))
161  call dmatch(iasph,ipph,ngk(jspn,ik),vgkc(:,:,jspn,ik), &
162  apwalm(:,:,:,:,jspn),dapwalm(:,:,:,jspn))
163  call match(ngkq(jspn,ik),vgkqc(:,:,jspn,ik),gkqc(:,jspn,ik), &
164  sfacgkq(:,:,jspn,ik),apwalmq(:,:,:,:,jspn))
165  call dmatch(iasph,ipph,ngkq(jspn,ik),vgkqc(:,:,jspn,ik), &
166  apwalmq(:,:,:,:,jspn),dapwalmq(:,:,:,jspn))
167  end do
168 ! get the first- and second-variational eigenvalues and eigenvectors from file
169  call getevalfv(filext,jk,vkl(:,ik),evalfv)
170  call getevecfv(filext,0,vkl(:,ik),vgkl(:,:,:,ik),evecfv)
171  call getevecsv(filext,0,vkl(:,ik),evecsv)
172 ! solve the first-variational eigenvalue equation derivative
173  do jspn=1,nspnfv
174  call deveqnfv(ngk(jspn,ik),ngkq(jspn,ik),igkig(:,jspn,ik), &
175  igkqig(:,jspn,ik),vgkc(:,:,jspn,ik),vgkqc(:,:,jspn,ik),evalfv(:,jspn), &
176  apwalm(:,:,:,:,jspn),apwalmq(:,:,:,:,jspn),dapwalm(:,:,:,jspn), &
177  dapwalmq(:,:,:,jspn),evecfv(:,:,jspn),devalfv(:,jspn,ik), &
178  devecfv(:,:,jspn))
179  end do
180  if (spinsprl) then
181 ! solve the spin-spiral second-variational eigenvalue equation derivative
182 ! call deveqnss(ngk(:,ik),ngkq(:,ik),igkig(:,:,ik),igkqig(:,:,ik),apwalm, &
183 ! dapwalm,devalfv,evecfv,evecfvq,devecfv,evalsv(:,jk),evecsv,devecsv)
184  else
185 ! solve the second-variational eigenvalue equation derivative
186 ! call deveqnsv(ngk(1,ik),ngkq(1,ik),igkig(:,1,ik),igkqig(:,1,ik), &
187 ! vgkqc(:,:,1,ik),apwalm,dapwalm,devalfv,evecfv,evecfvq,devecfv, &
188 ! evalsv(:,jk),evecsv,devecsv)
189  end if
190 
191 !*******
192 devalsv(:,ik)=devalfv(:,1,ik)
193 !*******
194 
195 ! write the eigenvalue/vector derivatives to file
196  call putdevecfv(ik,devecfv)
197  if (tevecsv) call putdevecsv(ik,devecsv)
198 ! add to the density and magnetisation derivatives
199  call drhomagk(ngk(:,ik),ngkq(:,ik),igkig(:,:,ik),igkqig(:,:,ik), &
200  occsv(:,jk),doccsv(:,ik),apwalm,apwalmq,dapwalm,evecfv,devecfv,evecsv, &
201  devecsv)
202  end do
203 !$OMP END DO
204  deallocate(evalfv,apwalm,apwalmq,dapwalm,dapwalmq)
205  deallocate(evecfv,devecfv,evecsv,devecsv)
206 !$OMP END PARALLEL
207  call freethd(nthd)
208 ! broadcast eigenvalue derivative arrays to every process
209  n=nstfv*nspnfv
210  do ik=1,nkptnr
211  lp=mod(ik-1,np_mpi)
212  call mpi_bcast(devalfv(:,:,ik),n,mpi_double_precision,lp,mpicom,ierror)
213  call mpi_bcast(devalsv(:,ik),nstsv,mpi_double_precision,lp,mpicom,ierror)
214  end do
215 ! convert muffin-tin density/magnetisation derivatives to spherical harmonics
216  call drhomagsh
217 ! convert from a coarse to a fine radial mesh
218  call zfmtctof(drhomt)
219  do idm=1,ndmag
220  call zfmtctof(dmagmt(:,:,idm))
221  end do
222 ! convert interstitial density/magnetisation derivatives to fine grid
223  call zfirctof(drhoir,drhoir)
224  do idm=1,ndmag
225  call zfirctof(dmagir(:,idm),dmagir(:,idm))
226  end do
227 ! add densities from each process and redistribute
228  if (np_mpi > 1) then
229  n=size(drhmg)
230  call mpi_allreduce(mpi_in_place,drhmg,n,mpi_double_complex,mpi_sum,mpicom, &
231  ierror)
232  end if
233 ! synchronise MPI processes
234  call mpi_barrier(mpicom,ierror)
235 ! add gradient contribution to density derivative
236  call gradrhomt
237 ! compute the Kohn-Sham potential derivative
238  call dpotks
239 ! Fourier transform Kohn-Sham potential derivative to G+q-space
240  call gendvsig
241 ! mix the old potential and field with the new
242  call mixerifc(mtype,nmix,dvsbs,ddv,nwork,work)
243  if (mp_mpi) then
244  write(65,'(G18.10)') ddv
245  flush(65)
246  end if
247 ! exit self-consistent loop if required
248  if (tlast) goto 20
249 ! check for convergence
250  if (iscl >= 2) then
251  if (ddv < epspot) tlast=.true.
252  end if
253 ! broadcast tlast from master process to all other processes
254  call mpi_bcast(tlast,1,mpi_logical,0,mpicom,ierror)
255 ! compute the occupation number derivatives
256  call doccupy
257 ! end the self-consistent loop
258 end do
259 write(*,*)
260 write(*,'("Warning(phonon): failed to reach self-consistency after ",I4,&
261  &" loops")') maxscl
262 20 continue
263 ! close the RMSDDVS.OUT file
264 if (mp_mpi) close(65)
265 ! synchronise MPI processes
266 call mpi_barrier(mpicom,ierror)
267 ! generate the dynamical matrix row from force derivatives
268 call dforce(dyn)
269 ! synchronise MPI processes
270 call mpi_barrier(mpicom,ierror)
271 ! write dynamical matrix row to file
272 if (mp_mpi) then
273  do ias=1,natmtot
274  is=idxis(ias)
275  ia=idxia(ias)
276  do ip=1,3
277  a=dble(dyn(ip,ias))
278  b=aimag(dyn(ip,ias))
279  if (abs(a) < 1.d-12) a=0.d0
280  if (abs(b) < 1.d-12) b=0.d0
281  write(80,'(2G18.10," : is = ",I4,", ia = ",I4,", ip = ",I4)') a,b,is,ia,ip
282  end do
283  end do
284  close(80)
285 ! write the complex Kohn-Sham potential derivative to file
286  call writedvs(fext)
287 end if
288 ! delete the non-essential files
289 call delfiles(devec=.true.)
290 ! synchronise MPI processes
291 call mpi_barrier(mpicom,ierror)
292 goto 10
293 end subroutine
294 
integer nmatmax
Definition: modmain.f90:853
subroutine doccupy
Definition: doccupy.f90:7
subroutine zfmtctof(zfmt)
Definition: zfmtctof.f90:7
subroutine dpotks
Definition: dpotks.f90:7
subroutine drhomagk(ngp, ngpq, igpig, igpqig, occsvp, doccsvp, apwalm, apwalmq, dapwalm, evecfv, devecfv, evecsv, devecsv)
Definition: drhomagk.f90:8
complex(8), dimension(:,:), pointer, contiguous dmagir
Definition: modphonon.f90:102
subroutine dforce(dyn)
Definition: dforce.f90:7
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition: getevecsv.f90:7
character(256) filext
Definition: modmain.f90:1301
subroutine dhmlrad
Definition: dhmlrad.f90:7
real(8), dimension(:,:), allocatable evalsv
Definition: modmain.f90:921
logical mp_mpi
Definition: modmpi.f90:17
logical spinpol
Definition: modmain.f90:228
complex(8), dimension(:,:), pointer, contiguous drhomt
Definition: modphonon.f90:100
integer lmmaxapw
Definition: modmain.f90:199
integer nkpt
Definition: modmain.f90:461
real(8), dimension(:,:,:), allocatable gkqc
Definition: modphonon.f90:90
integer ndmag
Definition: modmain.f90:238
integer ngkmax
Definition: modmain.f90:499
subroutine getevecfv(fext, ikp, vpl, vgpl, evecfv)
Definition: getevecfv.f90:10
logical tevecsv
Definition: modmain.f90:923
subroutine getevalsv(fext, ikp, vpl, evalsv_)
Definition: getevalsv.f90:7
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition: match.f90:10
subroutine gendvsig
Definition: gendvsig.f90:7
integer iscl
Definition: modmain.f90:1051
logical spinsprl
Definition: modmain.f90:283
Definition: modomp.f90:6
integer iasph
Definition: modphonon.f90:15
integer, dimension(:,:,:), allocatable ivkik
Definition: modmain.f90:467
subroutine dyntask(fnum, fext)
Definition: dyntask.f90:7
real(8), dimension(:,:), allocatable devalsv
Definition: modphonon.f90:134
subroutine genvsig
Definition: genvsig.f90:10
integer nkptnr
Definition: modmain.f90:463
subroutine phonon
Definition: phonon.f90:7
subroutine genapwlofr
Definition: genapwlofr.f90:7
subroutine gensocfr
Definition: gensocfr.f90:7
integer np_mpi
Definition: modmpi.f90:13
subroutine gengkqvec(iq)
Definition: gengkqvec.f90:7
complex(8), dimension(:,:,:,:), allocatable sfacgk
Definition: modmain.f90:509
subroutine linengy
Definition: linengy.f90:10
subroutine mixerifc(mtype, n, v, dv, nwork, work)
Definition: mixerifc.f90:7
subroutine putdevecfv(ik, devecfv)
Definition: putdevecfv.f90:7
pure subroutine gengclgq(treg, iq, ngq, gqc, gclgq)
Definition: gengclgq.f90:7
integer nstsv
Definition: modmain.f90:889
complex(8), dimension(:,:,:), pointer, contiguous dmagmt
Definition: modphonon.f90:102
integer, dimension(:,:), allocatable ngk
Definition: modmain.f90:497
logical tlast
Definition: modmain.f90:1053
complex(8), dimension(:,:,:,:), allocatable sfacgkq
Definition: modphonon.f90:92
subroutine putdevecsv(ik, devecsv)
Definition: putdevecsv.f90:7
real(8), dimension(:,:), allocatable doccsv
Definition: modphonon.f90:136
real(8), dimension(:,:,:,:), allocatable vgkl
Definition: modmain.f90:503
complex(8), dimension(:), allocatable, target drhmg
Definition: modphonon.f90:98
real(8), dimension(:,:,:), allocatable devalfv
Definition: modphonon.f90:132
integer ipph
Definition: modphonon.f90:15
real(8), dimension(maxspecies) spmass
Definition: modmain.f90:101
subroutine init2
Definition: init2.f90:7
integer, dimension(3) ngridk
Definition: modmain.f90:448
integer ngvec
Definition: modmain.f90:396
real(8), dimension(:,:), allocatable occsv
Definition: modmain.f90:905
subroutine getevalfv(fext, ikp, vpl, evalfv)
Definition: getevalfv.f90:7
integer isph
Definition: modphonon.f90:15
real(8), dimension(:,:,:,:), allocatable vgkc
Definition: modmain.f90:505
subroutine init1
Definition: init1.f90:10
integer, dimension(3) ngridq
Definition: modmain.f90:515
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
integer apwordmax
Definition: modmain.f90:760
subroutine delfiles(evec, devec, eval, occ, pmat, epsi)
Definition: moddelf.f90:25
subroutine drhomagsh
Definition: drhomagsh.f90:7
logical ssdph
Definition: modmain.f90:285
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
Definition: modmpi.f90:6
subroutine getoccsv(fext, ikp, vpl, occsvp)
Definition: getoccsv.f90:7
real(8) epspot
Definition: modmain.f90:1061
real(8), dimension(:,:,:), allocatable gkc
Definition: modmain.f90:507
subroutine init4
Definition: init4.f90:7
subroutine deveqnfv(ngp, ngpq, igpig, igpqig, vgpc, vgpqc, evalfv, apwalm, apwalmq, dapwalm, dapwalmq, evecfv, devalfvp, devecfv)
Definition: deveqnfv.f90:8
complex(8), dimension(:), pointer, contiguous drhoir
Definition: modphonon.f90:100
subroutine zfirctof(zfirc, zfir)
Definition: zfirctof.f90:7
Definition: modpw.f90:6
complex(8), dimension(:), allocatable, target dvsbs
Definition: modphonon.f90:108
subroutine readstate
Definition: readstate.f90:10
integer iqph
Definition: modphonon.f90:15
subroutine gradrhomt
Definition: gradrhomt.f90:7
integer lp_mpi
Definition: modmpi.f90:15
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
integer, dimension(:,:), allocatable ngkq
Definition: modphonon.f90:84
integer, dimension(maxatoms *maxspecies) idxia
Definition: modmain.f90:45
subroutine gengvsmt
Definition: gengvsmt.f90:7
real(8), dimension(:,:,:,:), allocatable vgkqc
Definition: modphonon.f90:88
subroutine gendcfun
Definition: gendcfun.f90:7
subroutine init0
Definition: init0.f90:10
integer natmtot
Definition: modmain.f90:40
real(8), dimension(:), allocatable gqc
Definition: modphonon.f90:64
pure subroutine dmatch(ias, ip, ngp, vgpc, apwalm, dapwalm)
Definition: dmatch.f90:7
integer, dimension(:,:,:), allocatable igkig
Definition: modmain.f90:501
real(8) defermi
Definition: modphonon.f90:130
integer nstfv
Definition: modmain.f90:887
subroutine writedvs(fext)
Definition: writedvs.f90:7
integer maxscl
Definition: modmain.f90:1049
integer, dimension(:,:), allocatable ivk
Definition: modmain.f90:465
integer mpicom
Definition: modmpi.f90:11
integer nspnfv
Definition: modmain.f90:289
subroutine gengqvec(iq)
Definition: gengqvec.f90:7
integer, dimension(:,:,:), allocatable igkqig
Definition: modphonon.f90:86
real(8), dimension(:), allocatable gclgq
Definition: modphonon.f90:66
integer ierror
Definition: modmpi.f90:19
integer lmaxi
Definition: modmain.f90:205