2003-01-20 05:58:50 +08:00
|
|
|
!
|
2007-10-24 03:47:26 +08:00
|
|
|
! Copyright (C) 2001-2007 Quantum-Espresso 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"
|
2004-06-12 21:44:18 +08:00
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
!-----------------------------------------------------------------------
|
2007-11-10 23:07:51 +08:00
|
|
|
SUBROUTINE new_ns(ns)
|
2003-01-20 05:58:50 +08:00
|
|
|
!-----------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
! This routine computes the new value for ns (the occupation numbers of
|
|
|
|
! ortogonalized atomic wfcs).
|
|
|
|
! These quantities are defined as follows: ns_{I,s,m1,m2} = \sum_{k,v}
|
|
|
|
! f_{kv} <\fi^{at}_{I,m1}|\psi_{k,v,s}><\psi_{k,v,s}|\fi^{at}_{I,m2}>
|
|
|
|
!
|
2004-06-12 21:44:18 +08:00
|
|
|
USE io_global, ONLY : stdout
|
|
|
|
USE kinds, ONLY : DP
|
|
|
|
USE ions_base, ONLY : nat, ityp
|
|
|
|
USE basis, ONLY : natomwfc
|
2007-01-23 00:38:47 +08:00
|
|
|
USE klist, ONLY : nks, ngk
|
2007-11-10 23:07:51 +08:00
|
|
|
USE ldaU, ONLY : Hubbard_lmax, Hubbard_l, &
|
|
|
|
Hubbard_U, Hubbard_alpha, swfcatom
|
2007-11-06 20:54:17 +08:00
|
|
|
USE symme, ONLY : d1, d2, d3
|
2004-06-12 21:44:18 +08:00
|
|
|
USE lsda_mod, ONLY : lsda, current_spin, nspin, isk
|
|
|
|
USE symme, ONLY : nsym, irt
|
2007-11-22 22:23:04 +08:00
|
|
|
USE wvfct, ONLY : nbnd, npw, npwx, igk, wg
|
|
|
|
USE control_flags, ONLY : gamma_only
|
2004-06-12 21:44:18 +08:00
|
|
|
USE wavefunctions_module, ONLY : evc
|
|
|
|
USE gvect, ONLY : gstart
|
2006-11-05 10:47:07 +08:00
|
|
|
USE io_files, ONLY : iunigk, nwordwfc, iunwfc, nwordatwfc, iunsat
|
2007-02-21 21:01:31 +08:00
|
|
|
USE buffers, ONLY : get_buffer
|
2007-10-24 03:47:26 +08:00
|
|
|
USE uspp_param, ONLY : upf
|
2008-01-24 00:53:17 +08:00
|
|
|
USE mp_global, ONLY : intra_pool_comm, inter_pool_comm
|
|
|
|
USE mp, ONLY : mp_sum
|
|
|
|
|
2004-09-27 17:11:56 +08:00
|
|
|
|
|
|
|
IMPLICIT NONE
|
2004-06-12 21:44:18 +08:00
|
|
|
!
|
2007-11-10 23:07:51 +08:00
|
|
|
! I/O variables
|
|
|
|
!
|
|
|
|
REAL(DP) :: ns(2*Hubbard_lmax+1,2*Hubbard_lmax+1,nspin,nat)
|
|
|
|
|
2004-09-27 17:11:56 +08:00
|
|
|
INTEGER :: ik, ibnd, is, i, na, nb, nt, isym, n, counter, m1, m2, &
|
2003-02-10 16:58:33 +08:00
|
|
|
m0, m00, l, ldim
|
2004-09-27 17:11:56 +08:00
|
|
|
INTEGER, ALLOCATABLE :: offset (:)
|
2003-01-20 05:58:50 +08:00
|
|
|
! counter on k points
|
|
|
|
! " " bands
|
|
|
|
! " " spins
|
|
|
|
! offset of d electrons of atom d
|
|
|
|
! in the natomwfc ordering
|
2005-08-28 22:09:42 +08:00
|
|
|
REAL(DP) , ALLOCATABLE :: nr (:,:,:,:)
|
|
|
|
REAL(DP) :: t0, scnds
|
2003-01-20 05:58:50 +08:00
|
|
|
! cpu time spent
|
|
|
|
|
2005-08-28 22:09:42 +08:00
|
|
|
REAL(DP), EXTERNAL :: DDOT
|
|
|
|
COMPLEX(DP) :: ZDOTC
|
|
|
|
COMPLEX(DP) , ALLOCATABLE :: proj(:,:)
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2005-08-28 22:09:42 +08:00
|
|
|
REAL(DP) :: psum
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2003-02-10 16:58:33 +08:00
|
|
|
t0 = scnds ()
|
|
|
|
ldim = 2 * Hubbard_lmax + 1
|
2004-09-27 17:11:56 +08:00
|
|
|
ALLOCATE( offset(nat), proj(natomwfc,nbnd), nr(ldim,ldim,nspin,nat) )
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
2003-02-10 16:58:33 +08:00
|
|
|
! D_Sl for l=1, l=2 and l=3 are already initialized, for l=0 D_S0 is 1
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
2003-02-10 16:58:33 +08:00
|
|
|
counter = 0
|
2004-09-27 17:11:56 +08:00
|
|
|
DO na = 1, nat
|
2003-02-10 16:58:33 +08:00
|
|
|
nt = ityp (na)
|
2007-10-24 03:47:26 +08:00
|
|
|
DO n = 1, upf(nt)%nwfc
|
|
|
|
IF (upf(nt)%oc (n) >= 0.d0) THEN
|
|
|
|
l = upf(nt)%lchi (n)
|
2004-09-27 17:11:56 +08:00
|
|
|
IF (l == Hubbard_l(nt)) offset (na) = counter
|
2003-02-10 16:58:33 +08:00
|
|
|
counter = counter + 2 * l + 1
|
2004-09-27 17:11:56 +08:00
|
|
|
ENDIF
|
|
|
|
ENDDO
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2004-09-27 17:11:56 +08:00
|
|
|
ENDDO
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2004-09-27 17:11:56 +08:00
|
|
|
IF (counter.NE.natomwfc) CALL errore ('new_ns', 'nstart<>counter', 1)
|
2007-11-10 23:07:51 +08:00
|
|
|
nr (:,:,:,:) = 0.d0
|
|
|
|
ns (:,:,:,:) = 0.d0
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! we start a loop on k points
|
|
|
|
!
|
|
|
|
|
2007-02-21 21:01:31 +08:00
|
|
|
IF (nks > 1) REWIND (iunigk)
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2004-09-27 17:11:56 +08:00
|
|
|
DO ik = 1, nks
|
|
|
|
IF (lsda) current_spin = isk(ik)
|
2007-01-23 00:38:47 +08:00
|
|
|
npw = ngk (ik)
|
|
|
|
IF (nks > 1) THEN
|
|
|
|
READ (iunigk) igk
|
2007-02-21 21:01:31 +08:00
|
|
|
CALL get_buffer (evc, nwordwfc, iunwfc, ik)
|
2007-01-23 00:38:47 +08:00
|
|
|
END IF
|
2006-11-05 10:47:07 +08:00
|
|
|
CALL davcio (swfcatom, nwordatwfc, iunsat, ik, - 1)
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! make the projection
|
|
|
|
!
|
2004-09-27 17:11:56 +08:00
|
|
|
DO ibnd = 1, nbnd
|
|
|
|
DO i = 1, natomwfc
|
|
|
|
IF ( gamma_only ) THEN
|
2004-02-12 20:32:06 +08:00
|
|
|
proj (i, ibnd) = 2.d0 * &
|
|
|
|
DDOT(2*npw, swfcatom (1, i), 1, evc (1, ibnd), 1)
|
2004-09-27 17:11:56 +08:00
|
|
|
IF (gstart.EQ.2) proj (i, ibnd) = proj (i, ibnd) - &
|
2004-02-12 20:32:06 +08:00
|
|
|
swfcatom (1, i) * evc (1, ibnd)
|
2004-09-27 17:11:56 +08:00
|
|
|
ELSE
|
2004-02-12 20:32:06 +08:00
|
|
|
proj (i, ibnd) = ZDOTC (npw, swfcatom (1, i), 1, evc (1, ibnd), 1)
|
2004-09-27 17:11:56 +08:00
|
|
|
ENDIF
|
|
|
|
ENDDO
|
|
|
|
ENDDO
|
2004-02-12 20:32:06 +08:00
|
|
|
|
2003-02-21 22:57:00 +08:00
|
|
|
#ifdef __PARA
|
2008-04-21 05:23:37 +08:00
|
|
|
CALL mp_sum ( proj, intra_pool_comm )
|
2003-01-20 05:58:50 +08:00
|
|
|
#endif
|
2004-02-12 20:32:06 +08:00
|
|
|
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! compute the occupation numbers (the quantities n(m1,m2)) of the
|
|
|
|
! atomic orbitals
|
|
|
|
!
|
2004-09-27 17:11:56 +08:00
|
|
|
DO na = 1, nat
|
2003-02-10 16:58:33 +08:00
|
|
|
nt = ityp (na)
|
2004-09-27 17:11:56 +08:00
|
|
|
IF (Hubbard_U(nt).NE.0.d0 .OR. Hubbard_alpha(nt).NE.0.d0) THEN
|
|
|
|
DO m1 = 1, 2 * Hubbard_l(nt) + 1
|
|
|
|
DO m2 = m1, 2 * Hubbard_l(nt) + 1
|
|
|
|
DO ibnd = 1, nbnd
|
2003-07-31 20:54:09 +08:00
|
|
|
nr(m1,m2,current_spin,na) = nr(m1,m2,current_spin,na) + &
|
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
|
|
|
wg(ibnd,ik) * DBLE( proj(offset(na)+m2,ibnd) * &
|
2004-09-27 17:11:56 +08:00
|
|
|
CONJG(proj(offset(na)+m1,ibnd)) )
|
|
|
|
ENDDO
|
|
|
|
ENDDO
|
|
|
|
ENDDO
|
|
|
|
ENDIF
|
|
|
|
ENDDO
|
2004-02-12 20:32:06 +08:00
|
|
|
! on k-points
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2004-09-27 17:11:56 +08:00
|
|
|
ENDDO
|
2003-02-21 22:57:00 +08:00
|
|
|
#ifdef __PARA
|
2008-01-24 00:53:17 +08:00
|
|
|
CALL mp_sum( nr, inter_pool_comm )
|
2003-01-20 05:58:50 +08:00
|
|
|
#endif
|
2004-09-27 17:11:56 +08:00
|
|
|
IF (nspin.EQ.1) nr = 0.5d0 * nr
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
! impose hermiticity of n_{m1,m2}
|
|
|
|
!
|
2004-09-27 17:11:56 +08:00
|
|
|
DO na = 1, nat
|
2003-02-10 16:58:33 +08:00
|
|
|
nt = ityp(na)
|
2004-09-27 17:11:56 +08:00
|
|
|
DO is = 1, nspin
|
|
|
|
DO m1 = 1, 2 * Hubbard_l(nt) + 1
|
|
|
|
DO m2 = m1 + 1, 2 * Hubbard_l(nt) + 1
|
2003-07-31 20:54:09 +08:00
|
|
|
nr (m2, m1, is, na) = nr (m1, m2, is, na)
|
2004-09-27 17:11:56 +08:00
|
|
|
ENDDO
|
|
|
|
ENDDO
|
|
|
|
ENDDO
|
|
|
|
ENDDO
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2007-11-10 23:07:51 +08:00
|
|
|
! symmetryze the quantities nr -> ns
|
2004-09-27 17:11:56 +08:00
|
|
|
DO na = 1, nat
|
2003-02-10 16:58:33 +08:00
|
|
|
nt = ityp (na)
|
2004-09-27 17:11:56 +08:00
|
|
|
IF (Hubbard_U(nt).NE.0.d0 .OR. Hubbard_alpha(nt).NE.0.d0) THEN
|
|
|
|
DO is = 1, nspin
|
|
|
|
DO m1 = 1, 2 * Hubbard_l(nt) + 1
|
|
|
|
DO m2 = 1, 2 * Hubbard_l(nt) + 1
|
|
|
|
DO isym = 1, nsym
|
2003-02-10 16:58:33 +08:00
|
|
|
nb = irt (isym, na)
|
2004-09-27 17:11:56 +08:00
|
|
|
DO m0 = 1, 2 * Hubbard_l(nt) + 1
|
|
|
|
DO m00 = 1, 2 * Hubbard_l(nt) + 1
|
|
|
|
IF (Hubbard_l(nt).EQ.0) THEN
|
2007-11-10 23:07:51 +08:00
|
|
|
ns(m1,m2,is,na) = ns(m1,m2,is,na) + &
|
2003-07-31 20:54:09 +08:00
|
|
|
nr(m0,m00,is,nb) / nsym
|
2004-09-27 17:11:56 +08:00
|
|
|
ELSE IF (Hubbard_l(nt).EQ.1) THEN
|
2007-11-10 23:07:51 +08:00
|
|
|
ns(m1,m2,is,na) = ns(m1,m2,is,na) + &
|
2003-07-31 20:54:09 +08:00
|
|
|
d1(m0 ,m1,isym) * nr(m0,m00,is,nb) * &
|
2003-02-27 18:00:00 +08:00
|
|
|
d1(m00,m2,isym) / nsym
|
2004-09-27 17:11:56 +08:00
|
|
|
ELSE IF (Hubbard_l(nt).EQ.2) THEN
|
2007-11-10 23:07:51 +08:00
|
|
|
ns(m1,m2,is,na) = ns(m1,m2,is,na) + &
|
2003-07-31 20:54:09 +08:00
|
|
|
d2(m0 ,m1,isym) * nr(m0,m00,is,nb) * &
|
2003-02-27 18:00:00 +08:00
|
|
|
d2(m00,m2,isym) / nsym
|
2004-09-27 17:11:56 +08:00
|
|
|
ELSE IF (Hubbard_l(nt).EQ.3) THEN
|
2007-11-10 23:07:51 +08:00
|
|
|
ns(m1,m2,is,na) = ns(m1,m2,is,na) + &
|
2003-07-31 20:54:09 +08:00
|
|
|
d3(m0 ,m1,isym) * nr(m0,m00,is,nb) * &
|
2003-02-27 18:00:00 +08:00
|
|
|
d3(m00,m2,isym) / nsym
|
2004-09-27 17:11:56 +08:00
|
|
|
ELSE
|
|
|
|
CALL errore ('new_ns', &
|
2003-02-10 16:58:33 +08:00
|
|
|
'angular momentum not implemented', &
|
2004-09-27 17:11:56 +08:00
|
|
|
ABS(Hubbard_l(nt)) )
|
|
|
|
END IF
|
|
|
|
ENDDO
|
|
|
|
ENDDO
|
|
|
|
ENDDO
|
|
|
|
ENDDO
|
|
|
|
ENDDO
|
|
|
|
ENDDO
|
|
|
|
ENDIF
|
|
|
|
ENDDO
|
2003-01-20 05:58:50 +08:00
|
|
|
|
|
|
|
! Now we make the matrix ns(m1,m2) strictly hermitean
|
2004-09-27 17:11:56 +08:00
|
|
|
DO na = 1, nat
|
2003-02-10 16:58:33 +08:00
|
|
|
nt = ityp (na)
|
2004-09-27 17:11:56 +08:00
|
|
|
IF (Hubbard_U(nt).NE.0.d0 .OR. Hubbard_alpha(nt).NE.0.d0) THEN
|
|
|
|
DO is = 1, nspin
|
|
|
|
DO m1 = 1, 2 * Hubbard_l(nt) + 1
|
|
|
|
DO m2 = m1, 2 * Hubbard_l(nt) + 1
|
2007-11-10 23:07:51 +08:00
|
|
|
psum = ABS ( ns(m1,m2,is,na) - ns(m2,m1,is,na) )
|
2004-09-27 17:11:56 +08:00
|
|
|
IF (psum.GT.1.d-10) THEN
|
2003-11-04 18:53:05 +08:00
|
|
|
WRITE( stdout, * ) na, is, m1, m2
|
2007-11-10 23:07:51 +08:00
|
|
|
WRITE( stdout, * ) ns (m1, m2, is, na)
|
|
|
|
WRITE( stdout, * ) ns (m2, m1, is, na)
|
2004-09-27 17:11:56 +08:00
|
|
|
CALL errore ('new_ns', 'non hermitean matrix', 1)
|
|
|
|
ELSE
|
2007-11-10 23:07:51 +08:00
|
|
|
ns(m1,m2,is,na) = 0.5d0 * (ns(m1,m2,is,na) + &
|
|
|
|
ns(m2,m1,is,na) )
|
|
|
|
ns(m2,m1,is,na) = ns(m1,m2,is,na)
|
2004-09-27 17:11:56 +08:00
|
|
|
ENDIF
|
|
|
|
ENDDO
|
|
|
|
ENDDO
|
|
|
|
ENDDO
|
|
|
|
ENDIF
|
|
|
|
ENDDO
|
2004-02-12 20:32:06 +08:00
|
|
|
|
2004-09-27 17:11:56 +08:00
|
|
|
DEALLOCATE ( offset, proj, nr )
|
2003-03-20 19:21:34 +08:00
|
|
|
|
2004-09-27 17:11:56 +08:00
|
|
|
RETURN
|
2003-01-20 05:58:50 +08:00
|
|
|
|
2004-09-27 17:11:56 +08:00
|
|
|
END SUBROUTINE new_ns
|