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