2 ! Copyright (C) 2002-2007 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.
13 ! Computes the self-consistent Kohn-Sham ground-state. General information is
14 ! written to the file {\tt INFO.OUT}. First- and second-variational
15 ! eigenvalues, eigenvectors and occupancies are written to the unformatted
16 ! files {\tt EVALFV.OUT}, {\tt EVALSV.OUT}, {\tt EVECFV.OUT}, {\tt EVECSV.OUT}
17 ! and {\tt OCCSV.OUT}.
20 ! Created October 2002 (JKD)
26 integer ik
,is
,ia
,idm
,n
29 real(8), allocatable
:: nu(:)
30 real(8), allocatable
:: mu(:)
31 real(8), allocatable
:: beta(:)
32 real(8), allocatable
:: f(:)
33 real(8), allocatable
:: evalfv(:,:)
34 complex(8), allocatable
:: evecfv(:,:,:)
35 complex(8), allocatable
:: evecsv(:,:)
36 ! require forces for structural optimisation
37 if ((task
.eq
.2).or
.(task
.eq
.3)) tforce
=.true
.
38 ! initialise global variables
41 ! initialise OEP variables if required
42 if (xctype
.lt
.0) call init2
43 ! write the real and reciprocal lattice vectors to file
45 ! write inter-atomic distances to file
47 ! write symmetry matrices to file
49 ! output the k-point set to file
51 ! write lattice vectors and atomic positions to file
52 call writegeom(.false
.)
54 open(60,file
='INFO'//trim(filext
),action
='WRITE',form
='FORMATTED')
56 open(61,file
='TOTENERGY'//trim(filext
),action
='WRITE',form
='FORMATTED')
58 open(62,file
='FERMIDOS'//trim(filext
),action
='WRITE',form
='FORMATTED')
59 ! open MOMENT.OUT if required
60 if (spinpol
) open(63,file
='MOMENT'//trim(filext
),action
='WRITE', &
62 ! open FORCEMAX.OUT if required
63 if (tforce
) open(64,file
='FORCEMAX'//trim(filext
),action
='WRITE', &
66 open(65,file
='RMSDVEFF'//trim(filext
),action
='WRITE',form
='FORMATTED')
67 ! write out general information to INFO.OUT
69 ! initialise or read the charge density and potentials from file
72 if ((task
.eq
.1).or
.(task
.eq
.3)) then
74 write(60,'("Density and potential read in from STATE.OUT")')
79 write(60,'("Density and potential initialised from atomic data")')
82 ! size of mixing vector
83 n
=lmmaxvr
*nrmtmax
*natmtot
+ngrtot
84 if (spinpol
) n
=n
*(1+ndmag
)
85 if (ldapu
.ne
.0) n
=n
+2*lmmaxlu
*lmmaxlu
*nspinor
*nspinor
*natmtot
86 ! allocate mixing arrays
94 ! set last iteration flag
96 ! initialise the mixer
97 call packeff(.true
.,n
,nu
)
98 call mixer(.true
.,beta0
,betamax
,n
,nu
,mu
,beta
,f
,dv
)
99 call packeff(.false
.,n
,nu
)
100 ! delete any existing eigenvector files
102 ! begin the self-consistent loop
104 write(60,'("+------------------------------+")')
105 write(60,'("| Self-consistent loop started |")')
106 write(60,'("+------------------------------+")')
109 write(60,'("+-------------------------+")')
110 write(60,'("| Iteration number : ",I4," |")') iscl
111 write(60,'("+-------------------------+")')
113 if (iscl
.ge
.maxscl
) then
115 write(60,'("Reached self-consistent loops maximum")')
119 ! generate the core wavefunctions and densities
121 ! find the new linearisation energies
123 ! write out the linearisation energies
125 ! generate the APW radial functions
127 ! generate the local-orbital radial functions
129 ! compute the overlap radial integrals
131 ! compute the Hamiltonian radial integrals
133 ! begin parallel loop over k-points
134 !$OMP PARALLEL DEFAULT(SHARED) &
135 !$OMP PRIVATE(evalfv,evecfv,evecsv)
138 ! every thread should allocate its own arrays
139 allocate(evalfv(nstfv
,nspnfv
))
140 allocate(evecfv(nmatmax
,nstfv
,nspnfv
))
141 allocate(evecsv(nstsv
,nstsv
))
142 ! solve the first- and second-variational secular equations
143 call seceqn(ik
,evalfv
,evecfv
,evecsv
)
144 ! write the eigenvalues/vectors to file
145 call putevalfv(ik
,evalfv
)
146 call putevalsv(ik
,evalsv(1,ik
))
147 call putevecfv(ik
,evecfv
)
148 call putevecsv(ik
,evecsv
)
149 deallocate(evalfv
,evecfv
,evecsv
)
153 ! find the occupation numbers and Fermi energy
155 ! write out the eigenvalues and occupation numbers
157 ! write the Fermi energy to file
159 ! set the charge density and magnetisation to zero
166 !$OMP PARALLEL DEFAULT(SHARED) &
167 !$OMP PRIVATE(evecfv,evecsv)
170 allocate(evecfv(nmatmax
,nstfv
,nspnfv
))
171 allocate(evecsv(nstsv
,nstsv
))
172 ! write the occupancies to file
173 call putoccsv(ik
,occsv(1,ik
))
174 ! get the eigenvectors from file
175 call getevecfv(vkl(1,ik
),vgkl(1,1,ik
,1),evecfv
)
176 call getevecsv(vkl(1,ik
),evecsv
)
177 ! add to the density and magnetisation
178 call rhovalk(ik
,evecfv
,evecsv
)
179 deallocate(evecfv
,evecsv
)
183 ! symmetrise the density
184 call symrf(lradstp
,rhomt
,rhoir
)
185 ! symmetrise the magnetisation
186 if (spinpol
) call symrvf(lradstp
,magmt
,magir
)
187 ! convert the density from a coarse to a fine radial mesh
189 ! convert the magnetisation from a coarse to a fine radial mesh
191 call rfmtctof(magmt(1,1,1,idm
))
193 ! add the core density to the total density
195 ! calculate the charges
197 ! calculate the moments
198 if (spinpol
) call moment
199 ! normalise the density
203 ! generate the LDA+U density matrix
205 ! generate the LDA+U potential matrix
207 ! write the LDA+U matrices to file
210 ! compute the effective potential
212 ! pack interstitial and muffin-tin effective potential and field into one array
213 call packeff(.true
.,n
,nu
)
214 ! mix in the old potential and field with the new
215 call mixer(.false
.,beta0
,betamax
,n
,nu
,mu
,beta
,f
,dv
)
216 ! unpack potential and field
217 call packeff(.false
.,n
,nu
)
218 ! add the fixed spin moment effect field
219 if (fixspin
.ne
.0) call fsmfield
220 ! Fourier transform effective potential to G-space
222 ! reduce the external magnetic fields if required
223 if (reducebf
.lt
.1.d0
) then
224 bfieldc(:)=bfieldc(:)*reducebf
225 bfcmt(:,:,:)=bfcmt(:,:,:)*reducebf
227 ! compute the energy components
229 ! output energy components
232 write(60,'("Density of states at Fermi energy : ",G18.10)') fermidos
233 write(60,'(" (states/Hartree/spin/unit cell)")')
234 ! write total energy to TOTENERGY.OUT and flush
235 write(61,'(G18.10)') engytot
237 ! write DOS at Fermi energy to FERMIDOS.OUT and flush
238 write(62,'(G18.10)') fermidos
240 ! output charges and moments
242 ! write total moment to MOMENT.OUT and flush
244 write(63,'(3G18.10)') momtot(1:ndmag
)
247 ! output effective fields for fixed spin moment calculations
248 if (fixspin
.ne
.0) call writefsm(60)
249 ! check for WRITE file
250 inquire(file
='WRITE',exist
=exist
)
253 write(60,'("WRITE file exists - writing STATE.OUT")')
255 open(50,file
='WRITE')
256 close(50,status
='DELETE')
258 ! write STATE.OUT file if required
259 if (nwrite
.ge
.1) then
260 if (mod(iscl
,nwrite
).eq
.0) then
263 write(60,'("Wrote STATE.OUT")')
266 ! exit self-consistent loop if last iteration is complete
268 ! check for convergence
271 write(60,'("RMS change in effective potential (target) : ",G18.10,&
272 &" (",G18.10,")")') dv
,epspot
273 if (dv
.lt
.epspot
) then
275 write(60,'("Potential convergence target achieved")')
278 write(65,'(G18.10)') dv
281 if (xctype
.lt
.0) then
283 write(60,'("Magnitude of OEP residue : ",G18.10)') resoep
285 ! check for STOP file
286 inquire(file
='STOP',exist
=exist
)
289 write(60,'("STOP file exists - stopping self-consistent loop")')
293 close(50,status
='DELETE')
295 ! output the current total CPU time
296 timetot
=timeinit
+timemat
+timefv
+timesv
+timerho
+timepot
+timefor
298 write(60,'("Time (CPU seconds) : ",F12.2)') timetot
299 ! end the self-consistent loop
303 write(60,'("+------------------------------+")')
304 write(60,'("| Self-consistent loop stopped |")')
305 write(60,'("+------------------------------+")')
306 ! write density and potentials to file only if maxscl > 1
307 if (maxscl
.gt
.1) then
310 write(60,'("Wrote STATE.OUT")')
312 !-----------------------!
314 !-----------------------!
315 if ((.not
.tstop
).and
.(tforce
)) then
317 ! output forces to INFO.OUT
319 ! write maximum force magnitude to FORCEMAX.OUT
320 write(64,'(G18.10)') forcemax
323 !---------------------------------------!
324 ! perform structural relaxation !
325 !---------------------------------------!
326 if ((.not
.tstop
).and
.((task
.eq
.2).or
.(task
.eq
.3))) then
328 write(60,'("Maximum force magnitude (target) : ",G18.10," (",G18.10,")")') &
331 ! check force convergence
332 if (forcemax
.le
.epsforce
) then
334 write(60,'("Force convergence target achieved")')
337 ! update the atomic positions if forces are not converged
340 write(60,'("+--------------------------+")')
341 write(60,'("| Updated atomic positions |")')
342 write(60,'("+--------------------------+")')
345 write(60,'("Species : ",I4," (",A,")")') is
,trim(spsymb(is
))
346 write(60,'(" atomic positions (lattice) :")')
348 write(60,'(I4," : ",3F14.8)') ia
,atposl(:,ia
,is
)
351 ! add blank line to TOTENERGY.OUT, FERMIDOS.OUT and MOMENT.OUT
354 if (spinpol
) write (63,*)
355 ! begin new self-consistent loop with updated positions
359 ! output timing information
361 write(60,'("Timings (CPU seconds) :")')
362 write(60,'(" initialisation",T40,": ",F12.2)') timeinit
363 write(60,'(" Hamiltonian and overlap matrix set up",T40,": ",F12.2)') timemat
364 write(60,'(" first-variational secular equation",T40,": ",F12.2)') timefv
366 write(60,'(" second-variational calculation",T40,": ",F12.2)') timesv
368 write(60,'(" charge density calculation",T40,": ",F12.2)') timerho
369 write(60,'(" potential calculation",T40,": ",F12.2)') timepot
371 write(60,'(" force calculation",T40,": ",F12.2)') timefor
373 timetot
=timeinit
+timemat
+timefv
+timesv
+timerho
+timepot
+timefor
374 write(60,'(" total",T40,": ",F12.2)') timetot
376 write(60,'("+----------------------------------+")')
377 write(60,'("| EXCITING version ",I1.1,".",I1.1,".",I3.3," stopped |")') version
378 write(60,'("+----------------------------------+")')
379 ! close the INFO.OUT file
381 ! close the TOTENERGY.OUT file
383 ! close the FERMIDOS.OUT file
385 ! close the MOMENT.OUT file
386 if (spinpol
) close(63)
387 ! close the FORCEMAX.OUT file
388 if (tforce
) close(64)
389 ! close the RMSDVEFF.OUT file
391 deallocate(nu
,mu
,beta
,f
)