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