2003-01-20 05:58:50 +08:00
|
|
|
!
|
2003-04-04 22:36:00 +08:00
|
|
|
! Copyright (C) 2001-2003 PWSCF group
|
2003-01-20 05:58:50 +08:00
|
|
|
! This file is distributed under the terms of the
|
|
|
|
! GNU General Public License. See the file `License'
|
|
|
|
! in the root directory of the present distribution,
|
|
|
|
! or http://www.gnu.org/copyleft/gpl.txt .
|
|
|
|
!
|
2004-06-26 01:25:37 +08:00
|
|
|
#include "f_defs.h"
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
!----------------------------------------------------------------------
|
2003-02-08 00:04:36 +08:00
|
|
|
subroutine addusforce (forcenl)
|
2003-01-20 05:58:50 +08:00
|
|
|
!----------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
! This routine computes the contribution to atomic forces due
|
|
|
|
! to the dependence of the Q function on the atomic position.
|
|
|
|
! On output: the contribution is added to forcenl
|
|
|
|
!
|
2004-06-12 21:44:18 +08:00
|
|
|
USE kinds, ONLY : DP
|
|
|
|
USE ions_base, ONLY : nat, ntyp => nsp, ityp
|
|
|
|
USE cell_base, ONLY : omega, tpiba
|
|
|
|
USE gvect, ONLY : nr1, nr2, nr3, nrx1, nrx2, nrx3, nrxx, ngm, &
|
|
|
|
nl, nlm, gg, g, eigts1, eigts2, eigts3, ig1, ig2, ig3
|
|
|
|
USE lsda_mod, ONLY : nspin
|
|
|
|
USE scf, ONLY : vr, vltot
|
2005-03-28 21:55:19 +08:00
|
|
|
USE uspp, ONLY : becsum, okvan
|
2004-06-01 01:55:33 +08:00
|
|
|
USE uspp_param, ONLY : lmaxq, tvanp, nh, nhm
|
2004-06-12 21:44:18 +08:00
|
|
|
USE wvfct, ONLY : gamma_only
|
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
implicit none
|
2004-06-12 21:44:18 +08:00
|
|
|
!
|
2005-08-28 22:09:42 +08:00
|
|
|
real(DP) :: forcenl (3, nat)
|
2003-01-20 05:58:50 +08:00
|
|
|
! local variables
|
2003-02-08 00:04:36 +08:00
|
|
|
integer :: ig, ir, dim, nt, ih, jh, ijh, ipol, is, na
|
2005-08-28 22:09:42 +08:00
|
|
|
complex(DP):: cfac
|
|
|
|
real(DP) :: fact, DDOT
|
2003-01-20 05:58:50 +08:00
|
|
|
! work space
|
2005-08-28 22:09:42 +08:00
|
|
|
complex(DP), allocatable :: aux(:,:), aux1(:,:), vg(:), qgm(:)
|
|
|
|
real(DP) , allocatable :: ddeeq(:,:,:,:), qmod(:), ylmk0(:,:)
|
2003-11-07 00:39:22 +08:00
|
|
|
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
if (.not.okvan) return
|
|
|
|
!
|
|
|
|
if (gamma_only) then
|
|
|
|
fact = 2.d0
|
|
|
|
else
|
|
|
|
fact = 1.d0
|
|
|
|
end if
|
2003-02-08 00:04:36 +08:00
|
|
|
allocate (aux(ngm,nspin))
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! fourier transform of the total effective potential
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
allocate (vg(nrxx))
|
|
|
|
do is = 1, nspin
|
2003-11-07 00:39:22 +08:00
|
|
|
if (nspin.eq.4.and.is.ne.1) then
|
|
|
|
vg (:) = vr(:,is)
|
|
|
|
else
|
|
|
|
vg (:) = vltot (:) + vr (:, is)
|
|
|
|
endif
|
2003-02-08 00:04:36 +08:00
|
|
|
call cft3 (vg, nr1, nr2, nr3, nrx1, nrx2, nrx3, - 1)
|
2004-05-06 21:06:16 +08:00
|
|
|
aux (:, is) = vg (nl (:) ) * tpiba * (0.d0, -1.d0)
|
2003-01-20 05:58:50 +08:00
|
|
|
enddo
|
2003-02-08 00:04:36 +08:00
|
|
|
deallocate (vg)
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
2003-04-04 22:36:00 +08:00
|
|
|
allocate (aux1(ngm,3))
|
|
|
|
allocate (ddeeq( 3, (nhm*(nhm+1))/2,nat,nspin))
|
2004-05-08 18:24:24 +08:00
|
|
|
allocate (qgm( ngm))
|
2003-04-04 22:36:00 +08:00
|
|
|
allocate (qmod( ngm))
|
2004-06-01 01:55:33 +08:00
|
|
|
allocate (ylmk0(ngm,lmaxq*lmaxq))
|
2003-04-04 22:36:00 +08:00
|
|
|
!
|
|
|
|
ddeeq(:,:,:,:) = 0.d0
|
|
|
|
!
|
2004-06-01 01:55:33 +08:00
|
|
|
call ylmr2 (lmaxq * lmaxq, ngm, g, gg, ylmk0)
|
2003-04-04 22:36:00 +08:00
|
|
|
!
|
|
|
|
qmod (:) = sqrt (gg (:) )
|
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
! here we compute the integral Q*V for each atom,
|
|
|
|
! I = sum_G i G_a exp(-iR.G) Q_nm v^*
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
do nt = 1, ntyp
|
|
|
|
if (tvanp (nt) ) then
|
|
|
|
ijh = 1
|
|
|
|
do ih = 1, nh (nt)
|
|
|
|
do jh = ih, nh (nt)
|
|
|
|
call qvan2 (ngm, ih, jh, nt, qmod, qgm, ylmk0)
|
|
|
|
do na = 1, nat
|
|
|
|
if (ityp (na) .eq.nt) then
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! The product of potential, structure factor and iG
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
do is = 1, nspin
|
|
|
|
do ig = 1, ngm
|
General cleanup of intrinsic functions:
conversion to real => DBLE
(including real part of a complex number)
conversion to complex => CMPLX
complex conjugate => CONJG
imaginary part => AIMAG
All functions are uppercase.
CMPLX is preprocessed by f_defs.h and performs an explicit cast:
#define CMPLX(a,b) cmplx(a,b,kind=DP)
This implies that 1) f_defs.h must be included whenever a CMPLX is present,
2) CMPLX should stay in a single line, 3) DP must be defined.
All occurrences of real, float, dreal, dfloat, dconjg, dimag, dcmplx
removed - please do not reintroduce any of them.
Tested only with ifc7 and g95 - beware unintended side effects
Maybe not the best solution (explicit casts everywhere would be better)
but it can be easily changed with a script if the need arises.
The following code might be used to test for possible trouble:
program test_intrinsic
implicit none
integer, parameter :: dp = selected_real_kind(14,200)
real (kind=dp) :: a = 0.123456789012345_dp
real (kind=dp) :: b = 0.987654321098765_dp
complex (kind=dp) :: c = ( 0.123456789012345_dp, 0.987654321098765_dp)
print *, ' A = ', a
print *, ' DBLE(A)= ', DBLE(a)
print *, ' C = ', c
print *, 'CONJG(C)= ', CONJG(c)
print *, 'DBLE(c),AIMAG(C) = ', DBLE(c), AIMAG(c)
print *, 'CMPLX(A,B,kind=dp)= ', CMPLX( a, b, kind=dp)
end program test_intrinsic
Note that CMPLX and REAL without a cast yield single precision numbers on
ifc7 and g95 !!!
git-svn-id: http://qeforge.qe-forge.org/svn/q-e/trunk/espresso@2133 c92efa57-630b-4861-b058-cf58834340f0
2005-08-27 01:44:42 +08:00
|
|
|
cfac = aux (ig, is) * CONJG(eigts1 (ig1 (ig), na) *&
|
2003-01-20 05:58:50 +08:00
|
|
|
eigts2 (ig2 (ig), na) *&
|
|
|
|
eigts3 (ig3 (ig), na) )
|
2003-02-08 00:04:36 +08:00
|
|
|
aux1 (ig, 1) = g (1, ig) * cfac
|
|
|
|
aux1 (ig, 2) = g (2, ig) * cfac
|
|
|
|
aux1 (ig, 3) = g (3, ig) * cfac
|
2003-01-20 05:58:50 +08:00
|
|
|
enddo
|
|
|
|
!
|
|
|
|
! and the product with the Q functions
|
|
|
|
! G=0 term gives no contribution
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
do ipol = 1, 3
|
2003-01-20 05:58:50 +08:00
|
|
|
ddeeq (ipol, ijh, na, is) = omega * fact * &
|
|
|
|
DDOT (2 * ngm, aux1 (1, ipol), 1, qgm, 1)
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
enddo
|
2003-02-08 00:04:36 +08:00
|
|
|
ijh = ijh + 1
|
2003-01-20 05:58:50 +08:00
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
|
|
|
|
enddo
|
2003-02-21 22:57:00 +08:00
|
|
|
#ifdef __PARA
|
2003-02-08 00:04:36 +08:00
|
|
|
call reduce (3 * nhm * (nhm + 1) * nat * nspin / 2, ddeeq)
|
2003-01-20 05:58:50 +08:00
|
|
|
#endif
|
2003-11-04 18:53:05 +08:00
|
|
|
! WRITE( stdout,'( "dmatrix atom ",i4)') na
|
2003-01-20 05:58:50 +08:00
|
|
|
! do ih = 1, nh(nt)
|
2003-11-04 18:53:05 +08:00
|
|
|
! WRITE( stdout,'(8f9.4)') (ddeeq(ipol,ih,jh,na),jh=1,nh(nt))
|
2003-01-20 05:58:50 +08:00
|
|
|
! end do
|
2003-11-04 18:53:05 +08:00
|
|
|
! WRITE( stdout,'( "dion pseudo ",i4)') nt
|
2003-01-20 05:58:50 +08:00
|
|
|
! do ih = 1, nh(nt)
|
2004-06-22 16:03:59 +08:00
|
|
|
! WRITE( stdout,'(8f9.4)') (dvan(ih,jh,nt),jh=1,nh(nt))
|
2003-01-20 05:58:50 +08:00
|
|
|
! end do
|
2003-02-08 00:04:36 +08:00
|
|
|
do is = 1, nspin
|
|
|
|
do na = 1, nat
|
|
|
|
nt = ityp (na)
|
|
|
|
dim = (nh (nt) * (nh (nt) + 1) ) / 2
|
|
|
|
do ipol = 1, 3
|
|
|
|
do ir = 1, dim
|
2003-01-20 05:58:50 +08:00
|
|
|
forcenl (ipol, na) = forcenl (ipol, na) + &
|
|
|
|
ddeeq (ipol, ir, na, is) * becsum (ir, na, is)
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
enddo
|
2003-02-08 00:04:36 +08:00
|
|
|
deallocate (ylmk0)
|
2004-05-08 18:24:24 +08:00
|
|
|
deallocate (qgm)
|
2003-02-08 00:04:36 +08:00
|
|
|
deallocate (qmod)
|
|
|
|
deallocate (ddeeq)
|
|
|
|
deallocate (aux1)
|
|
|
|
deallocate (aux)
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
end subroutine addusforce
|
|
|
|
|