2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! Copyright (C) 2001 PWSCF group
|
|
|
|
! 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 .
|
|
|
|
!
|
|
|
|
!
|
|
|
|
!----------------------------------------------------------------------
|
2003-02-08 00:04:36 +08:00
|
|
|
subroutine addusddens (drhoscf, dbecsum, irr, mode0, npe, iflag)
|
2003-01-20 05:58:50 +08:00
|
|
|
!----------------------------------------------------------------------
|
|
|
|
!
|
2007-02-08 21:07:07 +08:00
|
|
|
! This routine adds to the change of the charge and of the
|
|
|
|
! magnetization densities the part due to the US augmentation.
|
2003-01-20 05:58:50 +08:00
|
|
|
! It assumes that the array dbecsum has already accumulated the
|
|
|
|
! change of the becsum term.
|
|
|
|
!
|
2004-06-26 01:25:37 +08:00
|
|
|
#include "f_defs.h"
|
2004-06-12 21:44:18 +08:00
|
|
|
!
|
2008-08-24 01:55:06 +08:00
|
|
|
USE kinds, only : DP
|
|
|
|
USE becmod, ONLY : calbec
|
|
|
|
USE gvect, ONLY : gg, ngm, nrxx, nr1, nr2, nr3, nrx1, nrx2, nrx3, &
|
|
|
|
nl, g, eigts1, eigts2, eigts3, ig1, ig2, ig3
|
|
|
|
USE lsda_mod, ONLY : nspin
|
|
|
|
USE spin_orb, ONLY : domag
|
|
|
|
USE uspp, ONLY : okvan, becsum
|
|
|
|
USE cell_base, ONLY : tpiba
|
2004-06-12 21:44:18 +08:00
|
|
|
USE ions_base, ONLY : nat, ityp, ntyp => nsp
|
2003-11-09 18:42:50 +08:00
|
|
|
USE wavefunctions_module, ONLY: psic
|
2003-02-08 00:04:36 +08:00
|
|
|
use phcom
|
2007-11-10 17:16:00 +08:00
|
|
|
USE uspp_param, ONLY: upf, lmaxq, nh, nhm
|
2004-06-01 01:55:33 +08:00
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
implicit none
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! the dummy variables
|
|
|
|
!
|
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
integer :: iflag, npe
|
2003-01-20 05:58:50 +08:00
|
|
|
! input: if zero does not compute drho
|
|
|
|
! input: the number of perturbations
|
|
|
|
|
2005-08-28 22:09:42 +08:00
|
|
|
complex(DP) :: drhoscf (nrxx, nspin, npe), &
|
2003-04-29 19:20:28 +08:00
|
|
|
dbecsum (nhm*(nhm+1)/2, nat, nspin, npe)
|
2003-01-20 05:58:50 +08:00
|
|
|
! inp/out: change of the charge density
|
|
|
|
!input: sum over kv of bec
|
2003-02-08 00:04:36 +08:00
|
|
|
integer :: irr, mode0
|
2003-01-20 05:58:50 +08:00
|
|
|
! input:the index of the irreducible repr.
|
|
|
|
! input:the mode of the representation
|
|
|
|
!
|
|
|
|
! here the local variables
|
|
|
|
!
|
|
|
|
|
2007-02-08 21:07:07 +08:00
|
|
|
integer :: ig, na, nt, ih, jh, ir, mu, mode, ipert, is, ijh, nspin0
|
2003-01-20 05:58:50 +08:00
|
|
|
! counter on G vectors
|
|
|
|
! counter on atoms
|
|
|
|
! counter on atomic type
|
|
|
|
! counter on beta functions
|
|
|
|
! counter on beta functions
|
|
|
|
! counter on r vectors
|
|
|
|
! pointer on modes
|
|
|
|
! pointer on the mode
|
|
|
|
! counter on perturbations
|
|
|
|
! counter on spin
|
|
|
|
! counter on combined beta functions
|
2003-02-08 00:04:36 +08:00
|
|
|
|
2005-08-28 22:09:42 +08:00
|
|
|
real(DP), allocatable :: qmod (:), qpg (:,:), ylmk0 (:,:)
|
2003-01-20 05:58:50 +08:00
|
|
|
! the modulus of q+G
|
|
|
|
! the values of q+G
|
|
|
|
! the spherical harmonics
|
|
|
|
|
2005-08-28 22:09:42 +08:00
|
|
|
complex(DP) :: fact, zsum, bb, alpha, alpha_0, u1, u2, u3
|
2003-01-20 05:58:50 +08:00
|
|
|
! auxiliary variables
|
2005-08-28 22:09:42 +08:00
|
|
|
complex(DP), allocatable :: sk (:), qgm(:), drhous (:,:), aux (:,:,:)
|
2003-01-20 05:58:50 +08:00
|
|
|
! the structure factor
|
2004-05-08 18:24:24 +08:00
|
|
|
! q_lm(G)
|
2003-01-20 05:58:50 +08:00
|
|
|
! contain the charge of drho
|
|
|
|
! auxiliary variable for drho(G)
|
2003-02-08 00:04:36 +08:00
|
|
|
|
|
|
|
if (.not.okvan) return
|
2007-02-08 21:07:07 +08:00
|
|
|
nspin0=nspin
|
|
|
|
if (nspin==4.and..not.domag) nspin0=1
|
2003-02-08 00:04:36 +08:00
|
|
|
call start_clock ('addusddens')
|
2004-05-08 18:24:24 +08:00
|
|
|
allocate (aux( ngm , nspin , npertx))
|
2003-02-08 00:04:36 +08:00
|
|
|
allocate (sk ( ngm))
|
2004-06-01 01:55:33 +08:00
|
|
|
allocate (ylmk0(ngm , lmaxq * lmaxq))
|
2004-05-08 18:24:24 +08:00
|
|
|
allocate (qgm( ngm))
|
|
|
|
allocate (qmod( ngm))
|
2003-02-08 00:04:36 +08:00
|
|
|
if (.not.lgamma) allocate (qpg( 3 , ngm))
|
2003-11-06 03:01:20 +08:00
|
|
|
! WRITE( stdout,*) aux, ylmk0, qmod
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! And then we compute the additional charge in reciprocal space
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
if (.not.lgamma) then
|
|
|
|
call setqmod (ngm, xq, g, qmod, qpg)
|
2004-06-01 01:55:33 +08:00
|
|
|
call ylmr2 (lmaxq * lmaxq, ngm, qpg, qmod, ylmk0)
|
2003-02-08 00:04:36 +08:00
|
|
|
do ig = 1, ngm
|
|
|
|
qmod (ig) = sqrt (qmod (ig) )
|
2003-01-20 05:58:50 +08:00
|
|
|
enddo
|
2003-02-08 00:04:36 +08:00
|
|
|
else
|
2004-06-01 01:55:33 +08:00
|
|
|
call ylmr2 (lmaxq * lmaxq, ngm, g, gg, ylmk0)
|
2003-02-08 00:04:36 +08:00
|
|
|
do ig = 1, ngm
|
|
|
|
qmod (ig) = sqrt (gg (ig) )
|
2003-01-20 05:58:50 +08:00
|
|
|
enddo
|
|
|
|
endif
|
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
|
|
|
fact = 0.5d0 * CMPLX (0.d0, - tpiba)
|
2004-01-09 23:56:24 +08:00
|
|
|
aux(:,:,:) = (0.d0, 0.d0)
|
2003-02-08 00:04:36 +08:00
|
|
|
do nt = 1, ntyp
|
2007-11-10 17:16:00 +08:00
|
|
|
if (upf(nt)%tvanp ) then
|
2003-02-08 00:04:36 +08:00
|
|
|
ijh = 0
|
|
|
|
do ih = 1, nh (nt)
|
|
|
|
do jh = ih, nh (nt)
|
|
|
|
call qvan2 (ngm, ih, jh, nt, qmod, qgm, ylmk0)
|
|
|
|
ijh = ijh + 1
|
|
|
|
do na = 1, nat
|
|
|
|
if (ityp (na) .eq.nt) then
|
|
|
|
mu = 3 * (na - 1)
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! calculate the structure factor
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
do ig = 1, ngm
|
2003-04-29 19:20:28 +08:00
|
|
|
sk (ig) = eigts1 (ig1 (ig), na) * &
|
|
|
|
eigts2 (ig2 (ig), na) * &
|
|
|
|
eigts3 (ig3 (ig), na) * &
|
|
|
|
eigqts (na) * qgm (ig)
|
2003-01-20 05:58:50 +08:00
|
|
|
enddo
|
|
|
|
!
|
|
|
|
! And qgmq and becp and dbecq
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
do ipert = 1, npert (irr)
|
2007-02-08 21:07:07 +08:00
|
|
|
do is = 1, nspin0
|
2003-02-08 00:04:36 +08:00
|
|
|
mode = mode0 + ipert
|
|
|
|
zsum = dbecsum (ijh, na, is, ipert)
|
|
|
|
u1 = u (mu + 1, mode)
|
|
|
|
u2 = u (mu + 2, mode)
|
|
|
|
u3 = u (mu + 3, mode)
|
2003-04-29 19:20:28 +08:00
|
|
|
if (abs(u1) + abs(u2) + abs(u3) .gt.1d-12 .and. &
|
|
|
|
iflag.eq.1) then
|
2003-02-08 00:04:36 +08:00
|
|
|
bb = becsum (ijh, na, is)
|
2003-04-29 19:20:28 +08:00
|
|
|
zsum = zsum + 0.5d0 * &
|
|
|
|
( alphasum (ijh, 1, na, is) * u1 &
|
|
|
|
+ alphasum (ijh, 2, na, is) * u2 &
|
|
|
|
+ alphasum (ijh, 3, na, is) * u3)
|
2003-02-08 00:04:36 +08:00
|
|
|
u1 = u1 * fact
|
|
|
|
u2 = u2 * fact
|
|
|
|
u3 = u3 * fact
|
2003-04-29 19:20:28 +08:00
|
|
|
alpha_0 = xq(1)*u1 + xq(2)*u2 + xq(3)*u3
|
2003-02-08 00:04:36 +08:00
|
|
|
do ig = 1, ngm
|
2003-04-29 19:20:28 +08:00
|
|
|
alpha = alpha_0 + &
|
|
|
|
g(1,ig)*u1 + g(2,ig)*u2 + g(3,ig)*u3
|
|
|
|
aux(ig,is,ipert) = aux(ig,is,ipert) + &
|
|
|
|
(zsum + alpha*bb) * sk(ig)
|
2003-01-20 05:58:50 +08:00
|
|
|
enddo
|
2003-02-08 00:04:36 +08:00
|
|
|
else
|
2003-04-29 19:20:28 +08:00
|
|
|
call ZAXPY (ngm, zsum, sk, 1, aux(1,is,ipert), 1)
|
2003-01-20 05:58:50 +08:00
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
!
|
|
|
|
! convert aux to real space
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
do ipert = 1, npert (irr)
|
|
|
|
mu = mode0 + ipert
|
2007-02-08 21:07:07 +08:00
|
|
|
do is = 1, nspin0
|
2004-01-09 23:56:24 +08:00
|
|
|
psic(:) = (0.d0, 0.d0)
|
2003-02-08 00:04:36 +08:00
|
|
|
do ig = 1, ngm
|
2003-04-29 19:20:28 +08:00
|
|
|
psic (nl (ig) ) = aux (ig, is, ipert)
|
2003-01-20 05:58:50 +08:00
|
|
|
enddo
|
2003-04-29 19:20:28 +08:00
|
|
|
call cft3 (psic, nr1, nr2, nr3, nrx1, nrx2, nrx3, 1)
|
|
|
|
call DAXPY (2*nrxx, 2.d0, psic, 1, drhoscf(1,is,ipert), 1)
|
2003-01-20 05:58:50 +08:00
|
|
|
enddo
|
|
|
|
enddo
|
2003-02-08 00:04:36 +08:00
|
|
|
if (.not.lgamma) deallocate (qpg)
|
|
|
|
deallocate (qmod)
|
2004-05-08 18:24:24 +08:00
|
|
|
deallocate (qgm)
|
|
|
|
deallocate (ylmk0)
|
2003-02-08 00:04:36 +08:00
|
|
|
deallocate (sk)
|
|
|
|
deallocate (aux)
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2004-01-09 23:56:24 +08:00
|
|
|
if (iflag == 0) then
|
2003-04-29 19:20:28 +08:00
|
|
|
allocate (drhous( nrxx, nspin))
|
|
|
|
do ipert = 1, npert (irr)
|
|
|
|
mu = mode0 + ipert
|
|
|
|
call davcio (drhous, lrdrhous, iudrhous, mu, -1)
|
|
|
|
call DAXPY (2*nrxx*nspin, 1.d0, drhous, 1, drhoscf(1,1,ipert), 1)
|
|
|
|
end do
|
|
|
|
deallocate (drhous)
|
|
|
|
end if
|
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
call stop_clock ('addusddens')
|
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
end subroutine addusddens
|