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 .
|
|
|
|
!
|
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 init_us_2 (npw_, igk_, q_, vkb_)
|
2003-01-20 05:58:50 +08:00
|
|
|
!----------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
! Calculates beta functions (Kleinman-Bylander projectors), with
|
2003-02-08 00:04:36 +08:00
|
|
|
! structure factor, for all atoms, in reciprocal space
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
2004-06-12 21:44:18 +08:00
|
|
|
USE kinds, ONLY : DP
|
|
|
|
USE ions_base, ONLY : nat, ntyp => nsp, ityp, tau
|
|
|
|
USE cell_base, ONLY : tpiba
|
|
|
|
USE constants, ONLY : tpi
|
|
|
|
USE gvect, ONLY : eigts1, eigts2, eigts3, ig1, ig2, ig3, g
|
|
|
|
USE wvfct, ONLY : npw, npwx, igk
|
|
|
|
USE us, ONLY : dq, tab
|
|
|
|
USE uspp, ONLY : nkb, vkb, nhtol, nhtolm, indv
|
|
|
|
USE uspp_param, ONLY : lmaxkb, nbeta, nhm, nh
|
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
implicit none
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
integer :: npw_, igk_ (npw_)
|
2003-01-20 05:58:50 +08:00
|
|
|
! input: number of PW's
|
|
|
|
! input: indices of q+G
|
2005-08-28 22:09:42 +08:00
|
|
|
real(DP) :: q_(3)
|
2003-01-20 05:58:50 +08:00
|
|
|
! input: q vector
|
2005-08-28 22:09:42 +08:00
|
|
|
complex(DP) :: vkb_ (npwx, nkb)
|
2003-01-20 05:58:50 +08:00
|
|
|
! output: beta functions
|
|
|
|
!
|
|
|
|
! Local variables
|
|
|
|
!
|
|
|
|
integer :: i0,i1,i2,i3, ig, l, lm, na, nt, nb, ih, jkb
|
|
|
|
|
2005-08-28 22:09:42 +08:00
|
|
|
real(DP) :: px, ux, vx, wx, arg
|
|
|
|
real(DP), allocatable :: gk (:,:), qg (:), vq (:), ylm (:,:), vkb1(:,:)
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2005-08-28 22:09:42 +08:00
|
|
|
complex(DP) :: phase, pref
|
|
|
|
complex(DP), allocatable :: sk(:)
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
!
|
|
|
|
if (lmaxkb.lt.0) return
|
2003-02-08 00:04:36 +08:00
|
|
|
call start_clock ('init_us_2')
|
|
|
|
allocate (vkb1( npw_,nhm))
|
|
|
|
allocate ( sk( npw_))
|
|
|
|
allocate ( qg( npw_))
|
|
|
|
allocate ( vq( npw_))
|
|
|
|
allocate ( ylm( npw_, (lmaxkb + 1) **2))
|
|
|
|
allocate ( gk( 3, npw_))
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
do ig = 1, npw_
|
2003-01-20 05:58:50 +08:00
|
|
|
gk (1,ig) = q_(1) + g(1, igk_(ig) )
|
|
|
|
gk (2,ig) = q_(2) + g(2, igk_(ig) )
|
|
|
|
gk (3,ig) = q_(3) + g(3, igk_(ig) )
|
|
|
|
qg (ig) = gk(1, ig)**2 + gk(2, ig)**2 + gk(3, ig)**2
|
|
|
|
enddo
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
call ylmr2 ((lmaxkb+1)**2, npw_, gk, qg, ylm)
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! set now qg=|q+G| in atomic units
|
2003-02-08 00:04:36 +08:00
|
|
|
!
|
|
|
|
do ig = 1, npw_
|
2003-01-20 05:58:50 +08:00
|
|
|
qg(ig) = sqrt(qg(ig))*tpiba
|
|
|
|
enddo
|
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
jkb = 0
|
|
|
|
do nt = 1, ntyp
|
2003-01-20 05:58:50 +08:00
|
|
|
! calculate beta in G-space using an interpolation table
|
2003-02-08 00:04:36 +08:00
|
|
|
do nb = 1, nbeta (nt)
|
|
|
|
do ig = 1, npw_
|
|
|
|
px = qg (ig) / dq - int (qg (ig) / dq)
|
|
|
|
ux = 1.d0 - px
|
|
|
|
vx = 2.d0 - px
|
|
|
|
wx = 3.d0 - px
|
2005-08-31 17:19:39 +08:00
|
|
|
i0 = INT( qg (ig) / dq ) + 1
|
2003-02-08 00:04:36 +08:00
|
|
|
i1 = i0 + 1
|
|
|
|
i2 = i0 + 2
|
|
|
|
i3 = i0 + 3
|
2003-01-20 05:58:50 +08:00
|
|
|
vq (ig) = tab (i0, nb, nt) * ux * vx * wx / 6.d0 + &
|
|
|
|
tab (i1, nb, nt) * px * vx * wx / 2.d0 - &
|
|
|
|
tab (i2, nb, nt) * px * ux * wx / 2.d0 + &
|
|
|
|
tab (i3, nb, nt) * px * ux * vx / 6.d0
|
|
|
|
enddo
|
|
|
|
! add spherical harmonic part
|
2003-02-08 00:04:36 +08:00
|
|
|
do ih = 1, nh (nt)
|
|
|
|
if (nb.eq.indv (ih, nt) ) then
|
|
|
|
l = nhtol (ih, nt)
|
2004-04-28 18:25:36 +08:00
|
|
|
lm =nhtolm (ih, nt)
|
2003-02-08 00:04:36 +08:00
|
|
|
do ig = 1, npw_
|
|
|
|
vkb1 (ig,ih) = ylm (ig, lm) * vq (ig)
|
2003-01-20 05:58:50 +08:00
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
!
|
|
|
|
! vkb1 contains all betas including angular part for type nt
|
|
|
|
! now add the structure factor and factor (-i)^l
|
|
|
|
!
|
2003-02-08 00:04:36 +08:00
|
|
|
do na = 1, nat
|
2003-01-20 05:58:50 +08:00
|
|
|
! ordering: first all betas for atoms of type 1
|
|
|
|
! then all betas for atoms of type 2 and so on
|
2003-02-08 00:04:36 +08:00
|
|
|
if (ityp (na) .eq.nt) then
|
2003-01-20 05:58:50 +08:00
|
|
|
arg = (q_(1) * tau (1, na) + &
|
|
|
|
q_(2) * tau (2, na) + &
|
|
|
|
q_(3) * tau (3, na) ) * tpi
|
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
|
|
|
phase = CMPLX (cos (arg), - sin (arg) )
|
2003-01-20 05:58:50 +08:00
|
|
|
do ig = 1, npw_
|
|
|
|
sk (ig) = eigts1 (ig1(igk_(ig)), na) * &
|
|
|
|
eigts2 (ig2(igk_(ig)), na) * &
|
|
|
|
eigts3 (ig3(igk_(ig)), na)
|
|
|
|
enddo
|
2003-02-08 00:04:36 +08:00
|
|
|
do ih = 1, nh (nt)
|
2003-01-20 05:58:50 +08:00
|
|
|
jkb = jkb + 1
|
2004-05-06 21:06:16 +08:00
|
|
|
pref = (0.d0, -1.d0) **nhtol (ih, nt) * phase
|
2003-02-08 00:04:36 +08:00
|
|
|
do ig = 1, npw_
|
2003-01-20 05:58:50 +08:00
|
|
|
vkb_(ig, jkb) = vkb1 (ig,ih) * sk (ig) * pref
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
enddo
|
2003-02-08 00:04:36 +08:00
|
|
|
deallocate (gk)
|
|
|
|
deallocate (ylm)
|
|
|
|
deallocate (vq)
|
|
|
|
deallocate (qg)
|
|
|
|
deallocate (sk)
|
|
|
|
deallocate (vkb1)
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2003-02-08 00:04:36 +08:00
|
|
|
call stop_clock ('init_us_2')
|
|
|
|
return
|
2003-01-20 05:58:50 +08:00
|
|
|
end subroutine init_us_2
|
|
|
|
|