quantum-espresso/PH/dv_of_drho.f90

119 lines
3.2 KiB
Fortran
Raw Normal View History

!
! 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 .
!
!
!-----------------------------------------------------------------------
subroutine dv_of_drho (mode, dvscf, flag)
!-----------------------------------------------------------------------
!
! This routine computes the change of the self consistent potential
! due to the perturbation.
!
#include "f_defs.h"
use funct
use pwcom
USE kinds, only : DP
use phcom
implicit none
integer :: mode
! input: the mode to do
complex(DP) :: dvscf (nrxx, nspin)
! input: the change of the charge,
! output: change of the potential
logical :: flag
! input: if true add core charge
integer :: ir, is, is1, ig
! counter on r vectors
! counter on spin polarizations
! counter on g vectors
real(DP) :: qg2, fac
! the modulus of (q+G)^2
! the structure factor
complex(DP), allocatable :: dvaux (:,:), drhoc (:)
! auxiliary variable for potential
! the change of the core charge
call start_clock ('dv_of_drho')
allocate (dvaux( nrxx, nspin))
allocate (drhoc( nrxx))
!
! the exchange-correlation contribution is computed in real space
!
dvaux (:,:) = (0.d0, 0.d0)
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
fac = 1.d0 / DBLE (nspin)
if (nlcc_any.and.flag) then
call addcore (mode, drhoc)
do is = 1, nspin
rho(:, is) = rho(:, is) + fac * rho_core (:)
dvscf(:, is) = dvscf(:, is) + fac * drhoc (:)
enddo
endif
do is = 1, nspin
do is1 = 1, nspin
do ir = 1, nrxx
dvaux(ir,is) = dvaux(ir,is) + dmuxc(ir,is,is1) * dvscf(ir,is1)
enddo
enddo
enddo
!
! add gradient correction to xc, NB: if nlcc is true we need to add here
! its contribution. grho contains already the core charge
!
if (igcx /= 0 .or. igcc /= 0) call dgradcorr &
(rho, grho, dvxc_rr, dvxc_sr, dvxc_ss, dvxc_s, xq, &
dvscf, nr1, nr2, nr3, nrx1, nrx2, nrx3, nrxx, nspin, nl, ngm, g, &
alat, omega, dvaux)
if (nlcc_any.and.flag) then
do is = 1, nspin
rho(:, is) = rho(:, is) - fac * rho_core (:)
dvscf(:, is) = dvscf(:, is) - fac * drhoc (:)
enddo
endif
!
! copy the total (up+down) delta rho in dvscf(*,1) and go to G-space
!
if (nspin == 2) then
dvscf(:,1) = dvscf(:,1) + dvscf(:,2)
end if
!
call cft3 (dvscf, nr1, nr2, nr3, nrx1, nrx2, nrx3, -1)
!
! hartree contribution is computed in reciprocal space
!
do is = 1, nspin
call cft3 (dvaux (1, is), nr1, nr2, nr3, nrx1, nrx2, nrx3, - 1)
do ig = 1, ngm
qg2 = (g(1,ig)+xq(1))**2 + (g(2,ig)+xq(2))**2 + (g(3,ig)+xq(3))**2
if (qg2 > 1.d-8) then
dvaux(nl(ig),is) = dvaux(nl(ig),is) + &
e2 * fpi * dvscf(nl(ig),1) / (tpiba2 * qg2)
endif
enddo
!
! and transformed back to real space
!
call cft3 (dvaux (1, is), nr1, nr2, nr3, nrx1, nrx2, nrx3, +1)
enddo
!
! at the end the two contributes are added
!
dvscf (:,:) = dvaux (:,:)
!
deallocate (drhoc)
deallocate (dvaux)
call stop_clock ('dv_of_drho')
return
end subroutine dv_of_drho