10
1
mirror of https://github.com/pfloos/quack synced 2025-01-07 03:43:13 +01:00
QuAcK/src/GW/ccRG0W0.f90

246 lines
6.6 KiB
Fortran
Raw Normal View History

2024-09-30 23:06:00 +02:00
subroutine ccRG0W0(maxSCF,thresh,max_diis,nBas,nOrb,nC,nO,nV,nR,nS,ERI,ENuc,ERHF,eHF)
2024-09-16 22:30:23 +02:00
! CC-based GW module
implicit none
include 'parameters.h'
! Input variables
integer,intent(in) :: maxSCF
double precision,intent(in) :: thresh
2024-09-17 16:39:38 +02:00
integer,intent(in) :: max_diis
2024-09-16 22:30:23 +02:00
integer,intent(in) :: nBas
integer,intent(in) :: nOrb
integer,intent(in) :: nC
integer,intent(in) :: nO
integer,intent(in) :: nV
integer,intent(in) :: nR
2024-09-30 23:06:00 +02:00
integer,intent(in) :: nS
2024-09-16 22:30:23 +02:00
double precision,intent(in) :: ENuc
double precision,intent(in) :: ERHF
double precision,intent(in) :: eHF(nOrb)
double precision,intent(in) :: ERI(nOrb,nOrb,nOrb,nOrb)
! Local variables
2024-09-17 16:39:38 +02:00
integer :: p,q,r,s
2024-09-16 22:30:23 +02:00
integer :: i,j,k,l
integer :: a,b,c,d
2024-09-30 23:06:00 +02:00
integer :: m
2024-09-16 22:30:23 +02:00
2024-09-30 23:06:00 +02:00
integer :: isp_W
logical :: TDA_W
logical :: dRPA
2024-09-16 22:30:23 +02:00
integer :: nSCF
double precision :: Conv
2024-09-30 23:06:00 +02:00
double precision :: EcRPA
2024-09-16 22:30:23 +02:00
2024-09-17 20:13:18 +02:00
double precision,allocatable :: Sig(:)
2024-09-16 22:30:23 +02:00
double precision,allocatable :: Z(:)
2024-09-30 23:06:00 +02:00
double precision,allocatable :: del(:,:)
double precision,allocatable :: vec(:,:)
double precision,allocatable :: res(:,:)
double precision,allocatable :: amp(:,:)
double precision,allocatable :: Aph(:,:)
double precision,allocatable :: Bph(:,:)
double precision,allocatable :: Om(:)
double precision,allocatable :: XpY(:,:)
double precision,allocatable :: XmY(:,:)
double precision,allocatable :: rho(:,:,:)
2024-09-17 16:39:38 +02:00
integer :: n_diis
double precision :: rcond
double precision,allocatable :: r_diis(:,:)
double precision,allocatable :: t_diis(:,:)
2024-09-16 22:30:23 +02:00
! Hello world
write(*,*)
write(*,*)'*****************************'
write(*,*)'* CC-based G0W0 Calculation *'
write(*,*)'*****************************'
write(*,*)
2024-09-17 20:13:18 +02:00
! Memory allocation
2024-09-16 22:30:23 +02:00
2024-09-30 23:06:00 +02:00
allocate(del(nS,nOrb))
allocate(vec(nS,nOrb))
allocate(res(nS,nOrb))
allocate(amp(nS,nOrb))
2024-09-17 16:39:38 +02:00
2024-09-17 20:13:18 +02:00
allocate(Sig(nOrb))
allocate(Z(nOrb))
2024-09-16 22:30:23 +02:00
2024-09-30 23:06:00 +02:00
allocate(r_diis(nS*nOrb,max_diis))
allocate(t_diis(nS*nOrb,max_diis))
!-------------------!
! Compute screening !
!-------------------!
! Spin manifold
isp_W = 1
TDA_W = .false.
dRPA = .true.
! Memory allocation
allocate(Om(nS),Aph(nS,nS),Bph(nS,nS),XpY(nS,nS),XmY(nS,nS),rho(nOrb,nOrb,nS))
call phLR_A(isp_W,dRPA,nOrb,nC,nO,nV,nR,nS,1d0,eHF,ERI,Aph)
call phLR_B(isp_W,dRPA,nOrb,nC,nO,nV,nR,nS,1d0,ERI,Bph)
call phLR(TDA_W,nS,Aph,Bph,EcRPA,Om,XpY,XmY)
call RGW_excitation_density(nOrb,nC,nO,nR,nS,ERI,XpY,rho)
deallocate(Aph,Bph,XpY,XmY)
2024-09-17 16:39:38 +02:00
2024-09-16 22:30:23 +02:00
! Initialization
2024-09-17 20:13:18 +02:00
Sig(:) = 0d0
2024-09-17 19:12:45 +02:00
Z(:) = 1d0
2024-09-16 22:30:23 +02:00
!-------------------------!
! Main loop over orbitals !
!-------------------------!
2024-09-17 20:13:18 +02:00
do p=nO,nO+1
2024-09-16 22:30:23 +02:00
! Initialization
Conv = 1d0
nSCF = 0
2024-09-17 16:39:38 +02:00
n_diis = 0
t_diis(:,:) = 0d0
r_diis(:,:) = 0d0
rcond = 0d0
2024-09-30 23:06:00 +02:00
amp(:,:) = 0d0
res(:,:) = 0d0
2024-09-17 16:39:38 +02:00
2024-10-01 09:42:25 +02:00
! Compute approximate hessians and coupling blocks
2024-09-17 20:13:18 +02:00
2024-09-30 23:06:00 +02:00
do m=1,nS
2024-09-17 20:13:18 +02:00
do j=nC+1,nO
2024-09-30 23:06:00 +02:00
del(m,j) = Om(m) + eHF(j) - eHF(p)
vec(m,j) = sqrt(2d0)*rho(p,j,m)
2024-09-17 20:13:18 +02:00
end do
end do
2024-09-30 23:06:00 +02:00
do m=1,nS
do b=1,nV-nR
del(m,nO+b) = Om(m) + eHF(nO+b) - eHF(p)
vec(m,nO+b) = sqrt(2d0)*rho(p,nO+b,m)
2024-09-17 09:10:16 +02:00
end do
end do
2024-09-16 22:30:23 +02:00
!----------------------!
! Loop over amplitudes !
!----------------------!
write(*,*)
2024-09-17 16:39:38 +02:00
write(*,*)'-------------------------------------------------------------'
write(*,*)'| CC-based G0W0 calculation |'
write(*,*)'-------------------------------------------------------------'
write(*,'(1X,A1,1X,A3,1X,A1,1X,A15,1X,A1,1X,A15,1X,A1,1X,A15,1X,A1,1X)') &
2024-09-17 20:13:18 +02:00
'|','#','|','Sig_c (eV)','|','e_GW (eV)','|','Conv','|'
2024-09-17 16:39:38 +02:00
write(*,*)'-------------------------------------------------------------'
2024-09-16 22:30:23 +02:00
do while(Conv > thresh .and. nSCF < maxSCF)
! Increment
nSCF = nSCF + 1
! Compute residual for 2h1p sector
2024-10-01 09:42:25 +02:00
! res(:,:) = vec(:,:) + (del(:,:) - Sig(p))*amp(:,:)
2024-09-16 22:30:23 +02:00
2024-09-30 23:06:00 +02:00
do m=1,nS
do j=nC+1,nO
2024-10-01 09:42:25 +02:00
res(m,j) = vec(m,j) + (eHF(j) - Om(m) - eHF(p) - Sig(p))*amp(m,j)
2024-09-16 22:30:23 +02:00
end do
end do
! Compute residual for 2p1h sector
2024-09-30 23:06:00 +02:00
do m=nC+1,nO
do b=1,nV-nR
2024-10-01 09:42:25 +02:00
res(m,nO+b) = vec(m,nO+b) + (eHF(nO+b) + Om(m) - eHF(p) - Sig(p))*amp(m,nO+b)
2024-09-16 22:30:23 +02:00
end do
end do
2024-09-17 19:12:45 +02:00
! Check convergence
2024-09-16 22:30:23 +02:00
2024-09-17 16:39:38 +02:00
Conv = maxval(abs(res))
2024-09-16 22:30:23 +02:00
! Update amplitudes
2024-09-17 16:39:38 +02:00
2024-09-30 23:06:00 +02:00
amp(:,:) = amp(:,:) - res(:,:)/del(:,:)
2024-09-16 22:30:23 +02:00
2024-09-17 16:39:38 +02:00
! DIIS extrapolation
if(max_diis > 1) then
n_diis = min(n_diis+1,max_diis)
2024-09-30 23:06:00 +02:00
call DIIS_extrapolation(rcond,nS*nOrb,nS*nOrb,n_diis,r_diis,t_diis,res,amp)
2024-09-17 16:39:38 +02:00
end if
! Compute quasiparticle energy
2024-09-16 22:30:23 +02:00
2024-09-17 20:13:18 +02:00
Sig(p) = 0d0
2024-09-17 16:39:38 +02:00
2024-09-30 23:06:00 +02:00
do m=1,nS
do q=nC+1,nOrb-nR
Sig(p) = Sig(p) + vec(m,q)*amp(m,q)
2024-09-16 22:30:23 +02:00
end do
end do
2024-09-17 16:39:38 +02:00
2024-09-16 22:30:23 +02:00
! Dump results
2024-09-17 16:39:38 +02:00
write(*,'(1X,A1,1X,I3,1X,A1,1X,F15.10,1X,A1,1X,F15.10,1X,A1,1X,F15.10,1X,A1,1X)') &
2024-09-17 20:13:18 +02:00
'|',nSCF,'|',Sig(p)*HaToeV,'|',(eHF(p)+Sig(p))*HaToeV,'|',Conv,'|'
2024-09-16 22:30:23 +02:00
end do
2024-09-17 16:39:38 +02:00
write(*,*)'-------------------------------------------------------------'
2024-09-17 20:13:18 +02:00
write(*,*)
2024-09-16 22:30:23 +02:00
!------------------------------------------------------------------------
! End of SCF loop
!------------------------------------------------------------------------
! Did it actually converge?
if(nSCF == maxSCF) then
write(*,*)
write(*,*)'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
write(*,*)' Convergence failed '
write(*,*)'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
write(*,*)
end if
write(*,*)'-------------------------------------------------------------------------------'
2024-09-17 20:13:18 +02:00
write(*,*)'| CC-based G0W0 calculation |'
2024-09-16 22:30:23 +02:00
write(*,*)'-------------------------------------------------------------------------------'
write(*,'(1X,A1,1X,A3,1X,A1,1X,A15,1X,A1,1X,A15,1X,A1,1X,A15,1X,A1,1X,A15,1X,A1,1X)') &
2024-09-17 20:13:18 +02:00
'|','Orb','|','e_HF (eV)','|','Sig_c (eV)','|','Z','|','e_QP (eV)','|'
2024-09-16 22:30:23 +02:00
write(*,*)'-------------------------------------------------------------------------------'
2024-09-17 16:39:38 +02:00
write(*,'(1X,A1,1X,I3,1X,A1,1X,F15.10,1X,A1,1X,F15.10,1X,A1,1X,F15.10,1X,A1,1X,F15.10,1X,A1,1X)') &
2024-09-17 20:13:18 +02:00
'|',p,'|',eHF(p)*HaToeV,'|',Sig(p)*HaToeV,'|',Z(p),'|',(eHF(p)+Sig(p))*HaToeV,'|'
2024-09-16 22:30:23 +02:00
write(*,*)'-------------------------------------------------------------------------------'
2024-09-17 20:15:06 +02:00
write(*,*)
2024-09-16 22:30:23 +02:00
end do
end subroutine