Commit 1dd2bbda authored by Gregor Michalicek's avatar Gregor Michalicek

First steps to re-implement the hybrid functionals

parent 0ab711bf
...@@ -65,59 +65,53 @@ CONTAINS ...@@ -65,59 +65,53 @@ CONTAINS
#ifdef CPP_MPI #ifdef CPP_MPI
INCLUDE 'mpif.h' INCLUDE 'mpif.h'
#endif #endif
! ..
! .. Scalar Arguments .. ! Scalar Arguments
INTEGER,INTENT(IN) :: iter INTEGER,INTENT(IN) :: iter
INTEGER,INTENT(IN) :: eig_id INTEGER,INTENT(IN) :: eig_id
! ..
!-odim ! Local Scalars
!+odim
! ..
! .. Local Scalars ..
INTEGER jsp,nk,nred,ne_all,ne_found INTEGER jsp,nk,nred,ne_all,ne_found
INTEGER ne,lh0 INTEGER ne,lh0
INTEGER isp,i,j,err INTEGER isp,i,j,err
LOGICAL l_wu,l_file,l_real,l_zref LOGICAL l_wu,l_file,l_real,l_zref
! .. ! Local Arrays
! .. Local Arrays .. INTEGER :: ierr(3)
INTEGER, PARAMETER :: lmaxb=3 INTEGER :: neigBuffer(kpts%nkpt,input%jspins)
INTEGER, PARAMETER :: lmaxb = 3
REAL, ALLOCATABLE :: bkpt(:) REAL, ALLOCATABLE :: bkpt(:)
REAL, ALLOCATABLE :: eig(:) REAL, ALLOCATABLE :: eig(:)
COMPLEX, ALLOCATABLE :: vs_mmp(:,:,:,:) COMPLEX, ALLOCATABLE :: vs_mmp(:,:,:,:)
TYPE(t_tlmplm) :: td
TYPE(t_usdus) :: ud TYPE(t_tlmplm) :: td
TYPE(t_lapw) :: lapw TYPE(t_usdus) :: ud
CLASS(t_Mat),ALLOCATABLE :: zMat TYPE(t_lapw) :: lapw
CLASS(t_mat),ALLOCATABLE :: hmat,smat CLASS(t_mat), ALLOCATABLE :: zMat
TYPE(T_mat) :: olap CLASS(t_mat), ALLOCATABLE :: hmat,smat
!
INTEGER nn,n ! Variables for HF or hybrid functional calculation
INTEGER ierr(3) INTEGER :: comm(kpts%nkpt),irank2(kpts%nkpt),isize2(kpts%nkpt)
INTEGER :: neigBuffer(kpts%nkpt,input%jspins)
! .. variables for HF or hybrid functional calculation ..
INTEGER :: comm(kpts%nkpt),irank2(kpts%nkpt),isize2(kpts%nkpt)
call ud%init(atoms,DIMENSION%jspd) call ud%init(atoms,DIMENSION%jspd)
ALLOCATE (eig(DIMENSION%neigd),bkpt(3)) ALLOCATE (eig(DIMENSION%neigd),bkpt(3))
l_real=sym%invs.AND..NOT.noco%l_noco l_real=sym%invs.AND..NOT.noco%l_noco
!check if z-reflection trick can be used
! check if z-reflection trick can be used
l_zref=(sym%zrfs.AND.(SUM(ABS(kpts%bk(3,:kpts%nkpt))).LT.1e-9).AND..NOT.noco%l_noco) l_zref=(sym%zrfs.AND.(SUM(ABS(kpts%bk(3,:kpts%nkpt))).LT.1e-9).AND..NOT.noco%l_noco)
IF (mpi%n_size > 1) l_zref = .FALSE. IF (mpi%n_size > 1) l_zref = .FALSE.
#ifdef CPP_MPI #ifdef CPP_MPI
CALL mpi_bc_potden(mpi,stars,sphhar,atoms,input,vacuum,oneD,noco,v) CALL mpi_bc_potden(mpi,stars,sphhar,atoms,input,vacuum,oneD,noco,v)
#endif #endif
!IF (mpi%irank.EQ.0) CALL openXMLElementFormPoly('iteration',(/'numberForCurrentRun','overallNumber '/),(/iter,v%iter/),& !IF (mpi%irank.EQ.0) CALL openXMLElementFormPoly('iteration',(/'numberForCurrentRun','overallNumber '/),(/iter,v%iter/),&
! RESHAPE((/19,13,5,5/),(/2,2/))) ! RESHAPE((/19,13,5,5/),(/2,2/)))
!---> set up and solve the eigenvalue problem ! Set up and solve the eigenvalue problem
!---> loop over spins ! loop over spins
!---> set up k-point independent t(l'm',lm) matrices ! set up k-point independent t(l'm',lm) matrices
CALL mt_setup(atoms,sym,sphhar,input,noco,enpara,inden,v,mpi,results,DIMENSION,td,ud) CALL mt_setup(atoms,sym,sphhar,input,noco,enpara,inden,v,mpi,results,DIMENSION,td,ud)
neigBuffer = 0 neigBuffer = 0
...@@ -127,43 +121,38 @@ CONTAINS ...@@ -127,43 +121,38 @@ CONTAINS
DO jsp = 1,MERGE(1,input%jspins,noco%l_noco) DO jsp = 1,MERGE(1,input%jspins,noco%l_noco)
k_loop:DO nk = mpi%n_start,kpts%nkpt,mpi%n_stride k_loop:DO nk = mpi%n_start,kpts%nkpt,mpi%n_stride
! ! Set up lapw list
!---> set up lapw list
CALL lapw%init(input,noco, kpts,atoms,sym,nk,cell,l_zref, mpi) CALL lapw%init(input,noco, kpts,atoms,sym,nk,cell,l_zref, mpi)
call timestart("Setup of H&S matrices") call timestart("Setup of H&S matrices")
CALL eigen_hssetup(jsp,mpi,DIMENSION,hybrid,enpara,input,vacuum,noco,sym,& CALL eigen_hssetup(jsp,mpi,DIMENSION,hybrid,enpara,input,vacuum,noco,sym,&
stars,cell,sphhar,atoms,ud,td,v,lapw,l_real,smat,hmat) stars,cell,sphhar,atoms,ud,td,v,lapw,l_real,smat,hmat)
CALL timestop("Setup of H&S matrices") CALL timestop("Setup of H&S matrices")
IF( hybrid%l_hybrid ) THEN IF(hybrid%l_hybrid) THEN
!write overlap matrix b to direct access file olap ! Write overlap matrix smat to direct access file olap
print *,"Wrong overlap matrix used, fix this later" print *,"Wrong overlap matrix used, fix this later"
!call write_olap(smat,nrec) CALL write_olap(smat,(jsp-1)*kpts%nkpt+nk) ! Note: At this moment this only works without MPI parallelization
PRINT *,"TODO" PRINT *,"TODO"
! STOP "TODO" ! STOP "TODO"
PRINT *,"BASIS:",lapw%nv(jsp),atoms%nlotot PRINT *,"BASIS:", lapw%nv(jsp), atoms%nlotot
!if (hybrid%l_addhf) CALL add_Vnonlocal(nk,hybrid,dimension, kpts,jsp,results,xcpot,hamovlp) IF (hybrid%l_addhf) CALL add_Vnonlocal(nk,hybrid,dimension,kpts,jsp,results,xcpot,hmat)
IF(hybrid%l_subvxc) THEN
IF( hybrid%l_subvxc ) THEN
!CALL subvxc(lapw,kpts%bk(:,nk),DIMENSION,input,jsp,v%mt(:,0,:,:),atoms,ud,hybrid,enpara%el0,enpara%ello0,& !CALL subvxc(lapw,kpts%bk(:,nk),DIMENSION,input,jsp,v%mt(:,0,:,:),atoms,ud,hybrid,enpara%el0,enpara%ello0,&
! sym, atoms%nlotot,kveclo, cell,sphhar, stars, xcpot,mpi,& ! sym,atoms%nlotot,kveclo,cell,sphhar,stars,xcpot,mpi,oneD,hamovlp,vx)
! oneD, hamovlp,vx)
END IF END IF
END IF ! hybrid%l_hybrid END IF ! hybrid%l_hybrid
l_wu=.FALSE. l_wu=.FALSE.
ne_all=DIMENSION%neigd ne_all=DIMENSION%neigd
if (allocated(zmat)) deallocate(zmat) if (allocated(zmat)) deallocate(zmat)
CALL eigen_diag(hmat,smat,nk,jsp,iter,ne_all,eig,zMat) CALL eigen_diag(hmat,smat,nk,jsp,iter,ne_all,eig,zMat)
DEALLOCATE(hmat,smat) DEALLOCATE(hmat,smat)
!
!---> output results ! Output results
!
CALL timestart("EV output") CALL timestart("EV output")
#if defined(CPP_MPI) #if defined(CPP_MPI)
!Collect number of all eigenvalues ! Collect number of all eigenvalues
ne_found=ne_all ne_found=ne_all
CALL MPI_ALLREDUCE(ne_found,ne_all,1,MPI_INTEGER,MPI_SUM, mpi%sub_comm,ierr) CALL MPI_ALLREDUCE(ne_found,ne_all,1,MPI_INTEGER,MPI_SUM, mpi%sub_comm,ierr)
ne_all=MIN(DIMENSION%neigd,ne_all) ne_all=MIN(DIMENSION%neigd,ne_all)
...@@ -172,12 +161,12 @@ CONTAINS ...@@ -172,12 +161,12 @@ CONTAINS
#endif #endif
IF (.NOT.l_real) THEN IF (.NOT.l_real) THEN
zMat%data_c(:lapw%nmat,:ne_found) = CONJG(zMat%data_c(:lapw%nmat,:ne_found)) zMat%data_c(:lapw%nmat,:ne_found) = CONJG(zMat%data_c(:lapw%nmat,:ne_found))
ENDIF END IF
CALL write_eig(eig_id, nk,jsp,ne_found,ne_all,& CALL write_eig(eig_id, nk,jsp,ne_found,ne_all,&
eig(:ne_found),n_start=mpi%n_size,n_end=mpi%n_rank,zmat=zMat) eig(:ne_found),n_start=mpi%n_size,n_end=mpi%n_rank,zmat=zMat)
neigBuffer(nk,jsp) = ne_found neigBuffer(nk,jsp) = ne_found
#if defined(CPP_MPI) #if defined(CPP_MPI)
!RMA synchronization ! RMA synchronization
CALL MPI_BARRIER(mpi%MPI_COMM,ierr) CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
#endif #endif
CALL timestop("EV output") CALL timestop("EV output")
......
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------
MODULE m_add_vnonlocal MODULE m_add_vnonlocal
USE m_judft USE m_judft
! c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c ! c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c
! This module is the driver routine for the calculation of the Hartree c ! This module is the driver routine for the calculation of the Hartree c
! Fock exchange term by using the mixed basis set. c ! Fock exchange term by using the mixed basis set. c
...@@ -34,108 +40,95 @@ MODULE m_add_vnonlocal ...@@ -34,108 +40,95 @@ MODULE m_add_vnonlocal
! c ! c
! M.Betzinger (09/07) c ! M.Betzinger (09/07) c
! c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c ! c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c
CONTAINS CONTAINS
SUBROUTINE add_vnonlocal(nk,hybrid,dimension, kpts,jsp,results,xcpot,hamovlp) SUBROUTINE add_vnonlocal(nk,hybrid,dimension,kpts,jsp,results,xcpot,hmat)
USE m_symm_hf ,ONLY: symm_hf USE m_symm_hf, ONLY: symm_hf
USE m_util ,ONLY: intgrf,intgrf_init USE m_util, ONLY: intgrf,intgrf_init
USE m_exchange_valence_hf USE m_exchange_valence_hf
USE m_exchange_core USE m_exchange_core
USE m_symmetrizeh USE m_symmetrizeh
USE m_wrapper USE m_wrapper
USE m_hsefunctional ,ONLY: exchange_vccvHSE,exchange_ccccHSE USE m_hsefunctional, ONLY: exchange_vccvHSE,exchange_ccccHSE
USE m_types USE m_types
USE m_io_hybrid USE m_io_hybrid
IMPLICIT NONE
TYPE(t_results),INTENT(INOUT) :: results
TYPE(t_xcpot_inbuild),INTENT(IN) :: xcpot
TYPE(t_dimension),INTENT(IN) :: dimension
TYPE(t_hybrid),INTENT(INOUT) :: hybrid
TYPE(t_kpts),INTENT(IN) :: kpts
INTEGER,INTENT(IN) :: jsp
INTEGER,INTENT(IN) :: nk
TYPE(t_hamovlp),INTENT(INOUT)::hamovlp
IMPLICIT NONE
! - local scalars -
INTEGER :: ic,n,nn
INTEGER :: iband
REAL :: a_ex TYPE(t_results), INTENT(INOUT) :: results
CLASS(t_xcpot), INTENT(IN) :: xcpot
TYPE(t_dimension), INTENT(IN) :: dimension
TYPE(t_hybrid), INTENT(INOUT) :: hybrid
TYPE(t_kpts), INTENT(IN) :: kpts
TYPE(t_mat), INTENT(INOUT) :: hmat
INTEGER, INTENT(IN) :: jsp
INTEGER, INTENT(IN) :: nk
! local scalars
INTEGER :: n,nn,iband
REAL :: a_ex
TYPE(t_mat) :: olap,tmp,v_x,z TYPE(t_mat) :: olap,tmp,v_x,z
COMPLEX :: exch(dimension%neigd,dimension%neigd) COMPLEX :: exch(dimension%neigd,dimension%neigd)
!
! initialize weighting factor for HF exchange part ! initialize weighting factor for HF exchange part
! a_ex=xcpot%get_exchange_weight()
a_ex=xcpot%get_exchange_weight()
v_x%l_real=hamovlp%l_real v_x%l_real=hmat%l_real
v_x%matsize1=dimension%nbasfcn v_x%matsize1=dimension%nbasfcn
CALL read_v_x(v_x,kpts%nkpt*(jsp-1) + nk) CALL read_v_x(v_x,kpts%nkpt*(jsp-1) + nk)
! add non-local x-potential to the hamiltonian a (in packed storage) ! add non-local x-potential to the hamiltonian hmat
ic=1 DO n=1,v_x%matsize1
DO n=1,v_x%matsize1 DO nn=1,n
DO nn=1,n IF (hmat%l_real) THEN
IF (hamovlp%l_real) THEN hmat%data_r(n,nn) = hmat%data_r(n,nn) - a_ex*v_x%data_r(n,nn)
hamovlp%a_r(ic) = hamovlp%a_r(ic) - a_ex*v_x%data_r(n,nn) ELSE
ELSE hmat%data_c(n,nn) = hmat%data_c(n,nn) - a_ex*v_x%data_c(n,nn)
hamovlp%a_c(ic) = hamovlp%a_c(ic) - a_ex*v_x%data_c(n,nn) ENDIF
ENDIF END DO
ic=ic+1 END DO
ENDDO ! calculate HF energy
END DO IF(hybrid%l_calhf) THEN
! calculate HF energy WRITE(6,'(A)') new_line('n')//new_line('n')//' ### '// ' diagonal HF exchange elements (eV) ###'
IF( hybrid%l_calhf ) THEN
WRITE(6,'(A)') new_line('n')//new_line('n')//' ### '// ' diagonal HF exchange elements (eV) ###'
WRITE(6,'(A)') new_line('n') // ' k-point '// 'band tail pole total(valence+core)' WRITE(6,'(A)') new_line('n') // ' k-point '// 'band tail pole total(valence+core)'
END IF
END IF
! read in lower triangle part of overlap matrix from direct acces file olap ! read in lower triangle part of overlap matrix from direct acces file olap
call olap%alloc(hamovlp%l_real,dimension%nbasfcn) CALL olap%alloc(hmat%l_real,dimension%nbasfcn)
call read_olap(olap, kpts%nkpt*(jsp-1) + nk) CALL read_olap(olap,kpts%nkpt*(jsp-1) + nk)
if (.not.olap%l_real) olap%data_c=conjg(olap%data_c) IF (.NOT.olap%l_real) olap%data_c=conjg(olap%data_c)
call z%alloc(olap%l_real,dimension%nbasfcn,dimension%neigd)
call read_z(z,nk) !what about spin? CALL z%alloc(olap%l_real,dimension%nbasfcn,dimension%neigd)
CALL read_z(z,nk) !what about spin?
WRITE(*,*) 'What about spin (in add_Vnonlocal)?'
! calculate exchange contribution of current k-point nk to total energy (te_hfex) ! calculate exchange contribution of current k-point nk to total energy (te_hfex)
! in the case of a spin-unpolarized calculation the factor 2 is added in eigen.F90 ! in the case of a spin-unpolarized calculation the factor 2 is added in eigen.F90
if (.not.v_x%l_real) v_x%data_c=conjg(v_x%data_c) IF (.NOT.v_x%l_real) v_x%data_c=conjg(v_x%data_c)
exch = 0 exch = 0
z%matsize1=MIN(z%matsize1,v_x%matsize2) z%matsize1=MIN(z%matsize1,v_x%matsize2)
call v_x%multiply(z,tmp)
DO iband = 1,hybrid%nbands(nk) CALL v_x%multiply(z,tmp)
if (z%l_real) THEN
exch(iband,iband) = dot_product(z%data_r(:z%matsize1,iband),tmp%data_r(:,iband))
else
exch(iband,iband) = dot_product(z%data_r(:z%matsize1,iband),tmp%data_r(:,iband))
endif
IF( iband .le. hybrid%nobd(nk) ) THEN
results%te_hfex%valence = results%te_hfex%valence -a_ex*results%w_iks(iband,nk,jsp)*exch(iband,iband)
END IF
IF(hybrid%l_calhf) THEN
WRITE(6, '( '' ('',F5.3,'','',F5.3,'','',F5.3,'')'',I4,4X,3F15.5)')&
& kpts%bkf(:,nk),iband, (REAL(exch(iband,iband))-hybrid%div_vv(iband,nk,jsp))*(-27.211608),&
& hybrid%div_vv(iband,nk,jsp)*(-27.211608),REAL(exch(iband,iband))*(-27.211608)
END IF
END DO
END SUBROUTINE add_vnonlocal
DO iband = 1, hybrid%nbands(nk)
IF (z%l_real) THEN
exch(iband,iband) = dot_product(z%data_r(:z%matsize1,iband),tmp%data_r(:,iband))
ELSE
exch(iband,iband) = dot_product(z%data_r(:z%matsize1,iband),tmp%data_r(:,iband))
END IF
IF(iband.LE.hybrid%nobd(nk)) THEN
results%te_hfex%valence = results%te_hfex%valence -a_ex*results%w_iks(iband,nk,jsp)*exch(iband,iband)
END IF
IF(hybrid%l_calhf) THEN
WRITE(6, '( '' ('',F5.3,'','',F5.3,'','',F5.3,'')'',I4,4X,3F15.5)')&
kpts%bkf(:,nk),iband, (REAL(exch(iband,iband))-hybrid%div_vv(iband,nk,jsp))*(-27.211608),&
hybrid%div_vv(iband,nk,jsp)*(-27.211608),REAL(exch(iband,iband))*(-27.211608)
END IF
END DO
END SUBROUTINE add_vnonlocal
END MODULE m_add_vnonlocal END MODULE m_add_vnonlocal
This diff is collapsed.
...@@ -427,8 +427,8 @@ ...@@ -427,8 +427,8 @@
IF (l_hyb) THEN IF (l_hyb) THEN
! Changes for hybrid functionals ! Changes for hybrid functionals
input%isec1 = 999 input%isec1 = 999
namex = 'hse ' namex = 'pbe0'
input%frcor = .true. ; input%ctail = .false. ; atoms%l_geo = .false. input%ctail = .false. ; atoms%l_geo = .false.! ; input%frcor = .true.
input%itmax = 15 ; input%maxiter = 25!; input%imix = 17 input%itmax = 15 ; input%maxiter = 25!; input%imix = 17
IF (ANY(kpts%nkpt3(:).EQ.0)) kpts%nkpt3(:) = 4 IF (ANY(kpts%nkpt3(:).EQ.0)) kpts%nkpt3(:) = 4
div(:) = kpts%nkpt3(:) div(:) = kpts%nkpt3(:)
......
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------
module m_io_hybrid module m_io_hybrid
use m_io_matrix use m_io_matrix
use m_judft use m_judft
......
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------
MODULE m_io_matrix MODULE m_io_matrix
USE m_types USE m_types
IMPLICIT NONE IMPLICIT NONE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment