quantum-espresso/D3/set_efsh.f90

91 lines
2.5 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 set_efsh (drhoscf, imode0, irr, npe)
!-----------------------------------------------------------------------
! This routine calculates the FermiEnergy shift
! and stores it in the variable ef_sh
!
#include "f_defs.h"
USE kinds, only : DP
USE io_global, ONLY : stdout
use pwcom
use phcom
use d3com
implicit none
integer :: npe, imode0, irr
! input: the number of perturbation
! input: the position of the current mode
! input: index of the current irr. rep.
complex (DP) :: drhoscf (nrxx, npe)
! input: variation of the charge density
integer :: ipert, ik, ikk, ibnd
! counters
complex (DP) :: delta_n, def (npertx)
! the change in electron number
! the change of the Fermi energy for each perturbation
real (DP) :: weight, wdelta
! kpoint weight
! delta function weight
real (DP), save :: dos_ef
! density of states at Ef
real (DP), external :: w0gauss
logical, save :: first = .true.
! Used for initialization
!
! first call: calculates density of states at Ef
!
if (first) then
first = .false.
dos_ef = 0.d0
do ik = 1, nksq
if (lgamma) then
ikk = ik
else
ikk = 2 * ik - 1
endif
weight = wk (ikk)
do ibnd = 1, nbnd
wdelta = w0gauss ( (ef - et (ibnd, ikk) ) / degauss, ngauss) &
/ degauss
dos_ef = dos_ef + weight * wdelta
enddo
enddo
#ifdef __PARA
call poolreduce (1, dos_ef)
#endif
endif
!
! determines Fermi energy shift (such that each pertubation is neutral)
!
WRITE( stdout, * )
do ipert = 1, npe
call cft3 (drhoscf (1, ipert), nr1, nr2, nr3, nrx1, nrx2, nrx3, - 1)
#ifdef __PARA
delta_n = (0.d0, 0.d0)
if (gg (1) < 1.0d-8) delta_n = omega * drhoscf (nl (1), ipert)
call reduce (2, delta_n)
#else
delta_n = omega * drhoscf (nl (1), ipert)
#endif
def (ipert) = - delta_n / dos_ef
enddo
!
! symmetrizes the Fermi energy shift
!
call sym_def1 (def, irr)
do ipert = 1, npe
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
ef_sh (imode0 + ipert) = DBLE (def (ipert) )
enddo
WRITE( stdout, '(5x,"Pert. #",i3,": Fermi energy shift (Ryd) =", &
& 2f10.4)') (ipert, def (ipert) , ipert = 1, npe)
return
end subroutine set_efsh