The Elk Code
 
Loading...
Searching...
No Matches
force.f90
Go to the documentation of this file.
1
2! Copyright (C) 2002-2005 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!BOP
7! !ROUTINE: force
8! !INTERFACE:
9subroutine force
10! !USES:
11use modmain
12use modtddft
13use modtest
14use modmpi
15use modomp
16! !DESCRIPTION:
17! Computes the various contributions to the atomic forces. In principle, the
18! force acting on a nucleus is simply the gradient at that site of the
19! classical electrostatic potential from the other nuclei and the electronic
20! density. This is a result of the Hellmann-Feynman theorem. However because
21! the basis set is dependent on the nuclear coordinates and is not complete,
22! the Hellman-Feynman force is inaccurate and corrections to it are required.
23! The first is the core correction which arises because the core wavefunctions
24! were determined by neglecting the non-spherical parts of the Kohn-Sham
25! potential $v_s$. Explicitly this is given by
26! $$ {\bf F}_{\rm core}^{\alpha}=\int_{\rm MT_{\alpha}} v_s({\bf r})
27! \nabla\rho_{\rm core}^{\alpha}({\bf r})\,d{\bf r} $$
28! for atom $\alpha$. The second, which is the incomplete basis set (IBS)
29! correction, is due to the position dependence of the APW functions, and is
30! derived by considering the change in total energy if the eigenvector
31! coefficients were fixed and the APW functions themselves were changed. This
32! would result in changes to the first-variational Hamiltonian and overlap
33! matrices given by
34! \begin{align*}
35! \delta H_{\bf G,G'}^{\alpha}&=i({\bf G-G'})
36! \left(H^{\alpha}_{\bf G+k,G'+k}-\frac{1}{2}({\bf G+k})\cdot({\bf G'+k})
37! \tilde{\Theta}_{\alpha}({\bf G-G'})e^{-i({\bf G-G'})\cdot{\bf r}_{\alpha}}
38! \right)\\
39! \delta O_{\bf G,G'}^{\alpha}&=i({\bf G-G'})\left(O^{\alpha}_{\bf G+k,G'+k}
40! -\tilde{\Theta}_{\alpha}({\bf G-G'})e^{-i({\bf G-G'})\cdot{\bf r}_{\alpha}}
41! \right)
42! \end{align*}
43! where both ${\bf G}$ and ${\bf G'}$ run over the APW indices;
44! $\tilde{\Theta}_{\alpha}$ is the form factor of the smooth step function for
45! muffin-tin $\alpha$; and $H^{\alpha}$ and $O^{\alpha}$ are the muffin-tin
46! Hamiltonian and overlap matrices, respectively. The APW-local-orbital part
47! is given by
48! \begin{align*}
49! \delta H_{\bf G,G'}^{\alpha}&=i({\bf G+k})H^{\alpha}_{\bf G+k,G'+k}\\
50! \delta O_{\bf G,G'}^{\alpha}&=i({\bf G+k})O^{\alpha}_{\bf G+k,G'+k}
51! \end{align*}
52! where ${\bf G}$ runs over the APW indices and ${\bf G'}$ runs over the
53! local-orbital indices. There is no contribution from the
54! local-orbital-local-orbital part of the matrices. We can now write the IBS
55! correction in terms of the basis of first-variational states as
56! \begin{align*}
57! {\bf F}_{ij}^{\alpha{\bf k}}=\sum_{\bf G,G'}
58! b^{i{\bf k}*}_{\bf G}b^{j{\bf k}}_{\bf G'}\left(
59! \delta H_{\bf G,G'}^{\alpha}-\epsilon_j\delta O_{\bf G,G'}^{\alpha}\right),
60! \end{align*}
61! where $b^{i{\bf k}}$ is the first-variational eigenvector.
62! Finally, the ${\bf F}_{ij}^{\alpha{\bf k}}$ matrix elements can be
63! multiplied by the second-variational coefficients, and contracted over all
64! indices to obtain the IBS force:
65! \begin{align*}
66! {\bf F}_{\rm IBS}^{\alpha}=\sum_{\bf k}w_{\bf k}\sum_{l\sigma}n_{l{\bf k}}
67! \sum_{ij}c_{\sigma i}^{l{\bf k}*}c_{\sigma j}^{l{\bf k}}
68! {\bf F}_{ij}^{\alpha{\bf k}}
69! +\int_{\rm MT_{\alpha}}v_s({\bf r})\nabla\left[\rho({\bf r})
70! -\rho^{\alpha}_{\rm core}({\bf r})\right]\,d{\bf r},
71! \end{align*}
72! where $c^{l{\bf k}}$ are the second-variational coefficients, $w_{\bf k}$
73! are the $k$-point weights, $n_{l{\bf k}}$ are the occupation numbers.
74!
75! !REVISION HISTORY:
76! Created January 2004 (JKD)
77! Fixed problem with second-variational forces, May 2008 (JKD)
78!EOP
79!BOC
80implicit none
81! local variables
82integer ik,idm,is,ias
83integer nr,nri,i,j,nthd
84real(8) fav(3),ca,t1,t2
85real(8) ts0,ts1
86! automatic arrays
87real(8) forceibs(3,natmtot),grfmt(npmtmax,3)
88! allocatable arrays
89real(8), allocatable :: rfmt(:,:)
90! external functions
91real(8), external :: rfmtinp,rfmtint
92call timesec(ts0)
93! coupling constant of the external A-field (-1/c)
94ca=-1.d0/solsc
95!---------------------------------!
96! Hellmann-Feynman forces !
97!---------------------------------!
98do ias=1,natmtot
99 is=idxis(ias)
100 nr=nrmt(is)
101 nri=nrmti(is)
102 call gradrfmt(nr,nri,rlmt(:,-1,is),wcrmt(:,:,is),vclmt(:,ias),npmtmax,grfmt)
103! force from Coulomb potential
104 forcehf(1:3,ias)=-spzn(is)*grfmt(1,1:3)*y00
105! force on nuclei from time-dependent E-field
106 if (tafieldt) then
107 do i=1,3
108 t1=(chgsmt(ias,i)+spzn(is))*efieldt(i)
109 forcehf(i,ias)=forcehf(i,ias)+t1
110 end do
111 end if
112end do
113! symmetrise Hellmann-Feynman forces
114call symveca(forcehf)
115!----------------------------------!
116! IBS correction to forces !
117!----------------------------------!
118! set the IBS forces to zero
119forceibs(:,:)=0.d0
120! compute k-point dependent contribution to the IBS forces
121call holdthd(nkpt/np_mpi,nthd)
122!$OMP PARALLEL DO DEFAULT(SHARED) &
123!$OMP REDUCTION(+:forceibs) &
124!$OMP SCHEDULE(DYNAMIC) &
125!$OMP NUM_THREADS(nthd)
126do ik=1,nkpt
127! distribute among MPI processes
128 if (mod(ik-1,np_mpi) /= lp_mpi) cycle
129 call forcek(ik,forceibs)
130end do
131!$OMP END PARALLEL DO
132call freethd(nthd)
133! add IBS forces from each process and redistribute
134if (np_mpi > 1) then
135 call mpi_allreduce(mpi_in_place,forceibs,3*natmtot,mpi_double_precision, &
136 mpi_sum,mpicom,ierror)
137end if
138if (tafieldt) then
139 t2=afieldt(1,itimes)**2+afieldt(2,itimes)**2+afieldt(3,itimes)**2
140 t2=t2*ca**2
141end if
142! integral of Kohn-Sham potential with gradient of density
143do ias=1,natmtot
144 is=idxis(ias)
145 nr=nrmt(is)
146 nri=nrmti(is)
147 call gradrfmt(nr,nri,rlmt(:,-1,is),wcrmt(:,:,is),rhomt(:,ias),npmtmax,grfmt)
148 do i=1,3
149 t1=rfmtinp(nr,nri,wr2mt(:,is),vsmt(:,ias),grfmt(:,i))
150! remove contribution from gauge correction to the current density
151 if (tafieldt) then
152 t1=t1-t2*rfmtint(nr,nri,wr2mt(:,is),grfmt(:,i))
153 end if
154 forceibs(i,ias)=forceibs(i,ias)+t1
155 end do
156end do
157! integral of Kohn-Sham magnetic field with magnetisation gradient
158if (spinpol) then
159 allocate(rfmt(npmtmax,natmtot))
160 do idm=1,ndmag
161 do ias=1,natmtot
162 is=idxis(ias)
163 call rfsht(nrcmt(is),nrcmti(is),bsmt(:,ias,idm),rfmt(:,ias))
164 end do
165 call rfmtctof(rfmt)
166 do ias=1,natmtot
167 is=idxis(ias)
168 nr=nrmt(is)
169 nri=nrmti(is)
170 call gradrfmt(nr,nri,rlmt(:,-1,is),wcrmt(:,:,is),magmt(:,ias,idm), &
171 npmtmax,grfmt)
172 do i=1,3
173 t1=rfmtinp(nr,nri,wr2mt(:,is),rfmt(:,ias),grfmt(:,i))
174 forceibs(i,ias)=forceibs(i,ias)+t1
175 end do
176 end do
177 end do
178 deallocate(rfmt)
179end if
180! time-dependent vector potential times integral of the gradient of the current
181! density over the muffin-tin
182if (tafieldt.and.tjr) then
183 do j=1,3
184 t1=ca*afieldt(j,itimes)
185 do ias=1,natmtot
186 is=idxis(ias)
187 nr=nrmt(is)
188 nri=nrmti(is)
189 call gradrfmt(nr,nri,rlmt(:,-1,is),wcrmt(:,:,is),jrmt(:,ias,j),npmtmax, &
190 grfmt)
191 do i=1,3
192 t2=rfmtint(nr,nri,wr2mt(:,is),grfmt(:,i))
193 forceibs(i,ias)=forceibs(i,ias)+t1*t2
194 end do
195 end do
196 end do
197end if
198! symmetrise IBS forces
199call symveca(forceibs)
200! total force on each atom
201do ias=1,natmtot
202 forcetot(1:3,ias)=forcehf(1:3,ias)+forceibs(1:3,ias)
203end do
204! symmetrise total forces
205call symveca(forcetot)
206! remove the average force, if required, to prevent translation of atomic basis
207if (tfav0) then
208 fav(1:3)=0.d0
209 do ias=1,natmtot
210 fav(1:3)=fav(1:3)+forcetot(1:3,ias)
211 end do
212 fav(1:3)=fav(1:3)/dble(natmtot)
213 do ias=1,natmtot
214 forcetot(1:3,ias)=forcetot(1:3,ias)-fav(1:3)
215 end do
216end if
217! zero force on atoms with negative mass
218do ias=1,natmtot
219 is=idxis(ias)
220 if (spmass(is) <= 0.d0) forcetot(1:3,ias)=0.d0
221end do
222! compute maximum force magnitude over all atoms
223forcemax=0.d0
224do ias=1,natmtot
225 t1=norm2(forcetot(1:3,ias))
226 if (t1 > forcemax) forcemax=t1
227end do
228! restrict maximum force magnitude if required
229if (maxforce >= 0.d0) then
230 if (forcemax > maxforce) then
232 forcetot(1:3,1:natmtot)=t1*forcetot(1:3,1:natmtot)
233 end if
234end if
235call timesec(ts1)
236timefor=timefor+ts1-ts0
237! write total forces to test file
238call writetest(750,'total forces',nv=3*natmtot,tol=1.d-3,rva=forcetot)
239end subroutine
240!EOC
241
subroutine force
Definition force.f90:10
subroutine forcek(ik, forceibs)
Definition forcek.f90:10
subroutine gradrfmt(nr, nri, ri, wcr, rfmt, ld, grfmt)
Definition gradrfmt.f90:10
integer, dimension(maxspecies) nrmti
Definition modmain.f90:211
real(8), parameter y00
Definition modmain.f90:1233
real(8), dimension(:,:,:), allocatable wcrmt
Definition modmain.f90:187
real(8) forcemax
Definition modmain.f90:994
real(8), dimension(:,:,:), pointer, contiguous magmt
Definition modmain.f90:616
integer, dimension(maxspecies) nrmt
Definition modmain.f90:150
logical spinpol
Definition modmain.f90:228
real(8) timefor
Definition modmain.f90:1224
integer, dimension(maxspecies) nrcmt
Definition modmain.f90:173
integer, dimension(maxatoms *maxspecies) idxis
Definition modmain.f90:44
real(8) maxforce
Definition modmain.f90:997
logical tjr
Definition modmain.f90:620
integer nkpt
Definition modmain.f90:461
logical tfav0
Definition modmain.f90:1000
real(8), dimension(:,:), allocatable forcetot
Definition modmain.f90:990
real(8), dimension(:,:,:), allocatable jrmt
Definition modmain.f90:622
real(8), dimension(:,:), pointer, contiguous vsmt
Definition modmain.f90:649
real(8) solsc
Definition modmain.f90:1252
real(8), dimension(:,:), allocatable vclmt
Definition modmain.f90:624
real(8), dimension(:,:), allocatable wr2mt
Definition modmain.f90:183
real(8), dimension(:,:), allocatable forcehf
Definition modmain.f90:988
real(8), dimension(:,:,:), pointer, contiguous bsmt
Definition modmain.f90:656
real(8), dimension(:,:), pointer, contiguous rhomt
Definition modmain.f90:614
integer, dimension(maxspecies) nrcmti
Definition modmain.f90:211
real(8), dimension(:,:,:), allocatable rlmt
Definition modmain.f90:179
integer ndmag
Definition modmain.f90:238
real(8), dimension(maxspecies) spmass
Definition modmain.f90:101
real(8), dimension(maxspecies) spzn
Definition modmain.f90:80
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
subroutine holdthd(nloop, nthd)
Definition modomp.f90:78
subroutine freethd(nthd)
Definition modomp.f90:106
logical tafieldt
Definition modtddft.f90:56
real(8), dimension(:,:), allocatable afieldt
Definition modtddft.f90:58
real(8), dimension(:,:), allocatable chgsmt
Definition modtddft.f90:86
integer itimes
Definition modtddft.f90:46
real(8), dimension(3) efieldt
Definition modtddft.f90:74
subroutine writetest(id, descr, nv, iv, iva, tol, rv, rva, zv, zva)
Definition modtest.f90:16
subroutine rfmtctof(rfmt)
Definition rfmtctof.f90:10
pure real(8) function rfmtinp(nr, nri, wr, rfmt1, rfmt2)
Definition rfmtinp.f90:10
pure real(8) function rfmtint(nr, nri, wr, rfmt)
Definition rfmtint.f90:7
subroutine rfsht(nr, nri, rfmt1, rfmt2)
Definition rfsht.f90:7
subroutine symveca(vca)
Definition symveca.f90:10
subroutine timesec(ts)
Definition timesec.f90:10