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
#ifdef CPP_MPI
INCLUDE 'mpif.h'
#endif
! ..
! .. Scalar Arguments ..
! Scalar Arguments
INTEGER,INTENT(IN) :: iter
INTEGER,INTENT(IN) :: eig_id
! ..
!-odim
!+odim
! ..
! .. Local Scalars ..
! Local Scalars
INTEGER jsp,nk,nred,ne_all,ne_found
INTEGER ne,lh0
INTEGER isp,i,j,err
LOGICAL l_wu,l_file,l_real,l_zref
! ..
! .. Local Arrays ..
INTEGER, PARAMETER :: lmaxb=3
! Local Arrays
INTEGER :: ierr(3)
INTEGER :: neigBuffer(kpts%nkpt,input%jspins)
INTEGER, PARAMETER :: lmaxb = 3
REAL, ALLOCATABLE :: bkpt(:)
REAL, ALLOCATABLE :: eig(:)
COMPLEX, ALLOCATABLE :: vs_mmp(:,:,:,:)
TYPE(t_tlmplm) :: td
TYPE(t_usdus) :: ud
TYPE(t_lapw) :: lapw
CLASS(t_Mat),ALLOCATABLE :: zMat
CLASS(t_mat),ALLOCATABLE :: hmat,smat
TYPE(T_mat) :: olap
!
INTEGER nn,n
INTEGER ierr(3)
INTEGER :: neigBuffer(kpts%nkpt,input%jspins)
! .. variables for HF or hybrid functional calculation ..
INTEGER :: comm(kpts%nkpt),irank2(kpts%nkpt),isize2(kpts%nkpt)
TYPE(t_tlmplm) :: td
TYPE(t_usdus) :: ud
TYPE(t_lapw) :: lapw
CLASS(t_mat), ALLOCATABLE :: zMat
CLASS(t_mat), ALLOCATABLE :: hmat,smat
! Variables for HF or hybrid functional calculation
INTEGER :: comm(kpts%nkpt),irank2(kpts%nkpt),isize2(kpts%nkpt)
call ud%init(atoms,DIMENSION%jspd)
ALLOCATE (eig(DIMENSION%neigd),bkpt(3))
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)
IF (mpi%n_size > 1) l_zref = .FALSE.
#ifdef CPP_MPI
CALL mpi_bc_potden(mpi,stars,sphhar,atoms,input,vacuum,oneD,noco,v)
#endif
!IF (mpi%irank.EQ.0) CALL openXMLElementFormPoly('iteration',(/'numberForCurrentRun','overallNumber '/),(/iter,v%iter/),&
! RESHAPE((/19,13,5,5/),(/2,2/)))
!---> set up and solve the eigenvalue problem
!---> loop over spins
!---> set up k-point independent t(l'm',lm) matrices
! Set up and solve the eigenvalue problem
! loop over spins
! 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)
neigBuffer = 0
......@@ -127,43 +121,38 @@ CONTAINS
DO jsp = 1,MERGE(1,input%jspins,noco%l_noco)
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 timestart("Setup of H&S matrices")
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")
IF( hybrid%l_hybrid ) THEN
!write overlap matrix b to direct access file olap
IF(hybrid%l_hybrid) THEN
! Write overlap matrix smat to direct access file olap
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"
! STOP "TODO"
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_subvxc ) THEN
PRINT *,"BASIS:", lapw%nv(jsp), atoms%nlotot
IF (hybrid%l_addhf) CALL add_Vnonlocal(nk,hybrid,dimension,kpts,jsp,results,xcpot,hmat)
IF(hybrid%l_subvxc) THEN
!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,&
! oneD, hamovlp,vx)
! sym,atoms%nlotot,kveclo,cell,sphhar,stars,xcpot,mpi,oneD,hamovlp,vx)
END IF
END IF ! hybrid%l_hybrid
l_wu=.FALSE.
ne_all=DIMENSION%neigd
if (allocated(zmat)) deallocate(zmat)
CALL eigen_diag(hmat,smat,nk,jsp,iter,ne_all,eig,zMat)
DEALLOCATE(hmat,smat)
!
!---> output results
!
! Output results
CALL timestart("EV output")
#if defined(CPP_MPI)
!Collect number of all eigenvalues
! Collect number of all eigenvalues
ne_found=ne_all
CALL MPI_ALLREDUCE(ne_found,ne_all,1,MPI_INTEGER,MPI_SUM, mpi%sub_comm,ierr)
ne_all=MIN(DIMENSION%neigd,ne_all)
......@@ -172,12 +161,12 @@ CONTAINS
#endif
IF (.NOT.l_real) THEN
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,&
eig(:ne_found),n_start=mpi%n_size,n_end=mpi%n_rank,zmat=zMat)
neigBuffer(nk,jsp) = ne_found
#if defined(CPP_MPI)
!RMA synchronization
! RMA synchronization
CALL MPI_BARRIER(mpi%MPI_COMM,ierr)
#endif
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
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
! This module is the driver routine for the calculation of the Hartree c
! Fock exchange term by using the mixed basis set. c
......@@ -34,108 +40,95 @@ MODULE m_add_vnonlocal
! 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
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_util ,ONLY: intgrf,intgrf_init
USE m_symm_hf, ONLY: symm_hf
USE m_util, ONLY: intgrf,intgrf_init
USE m_exchange_valence_hf
USE m_exchange_core
USE m_symmetrizeh
USE m_wrapper
USE m_hsefunctional ,ONLY: exchange_vccvHSE,exchange_ccccHSE
USE m_hsefunctional, ONLY: exchange_vccvHSE,exchange_ccccHSE
USE m_types
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
! - local scalars -
INTEGER :: ic,n,nn
INTEGER :: iband
IMPLICIT NONE
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
COMPLEX :: exch(dimension%neigd,dimension%neigd)
!
COMPLEX :: exch(dimension%neigd,dimension%neigd)
! 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
CALL read_v_x(v_x,kpts%nkpt*(jsp-1) + nk)
! add non-local x-potential to the hamiltonian a (in packed storage)
ic=1
DO n=1,v_x%matsize1
DO nn=1,n
IF (hamovlp%l_real) THEN
hamovlp%a_r(ic) = hamovlp%a_r(ic) - a_ex*v_x%data_r(n,nn)
ELSE
hamovlp%a_c(ic) = hamovlp%a_c(ic) - a_ex*v_x%data_c(n,nn)
ENDIF
ic=ic+1
ENDDO
END DO
! calculate HF energy
IF( hybrid%l_calhf ) THEN
WRITE(6,'(A)') new_line('n')//new_line('n')//' ### '// ' diagonal HF exchange elements (eV) ###'
CALL read_v_x(v_x,kpts%nkpt*(jsp-1) + nk)
! add non-local x-potential to the hamiltonian hmat
DO n=1,v_x%matsize1
DO nn=1,n
IF (hmat%l_real) THEN
hmat%data_r(n,nn) = hmat%data_r(n,nn) - a_ex*v_x%data_r(n,nn)
ELSE
hmat%data_c(n,nn) = hmat%data_c(n,nn) - a_ex*v_x%data_c(n,nn)
ENDIF
END DO
END DO
! calculate HF energy
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)'
END IF
WRITE(6,'(A)') new_line('n') // ' k-point '// 'band tail pole total(valence+core)'
END IF
! read in lower triangle part of overlap matrix from direct acces file olap
call olap%alloc(hamovlp%l_real,dimension%nbasfcn)
call read_olap(olap, kpts%nkpt*(jsp-1) + nk)
if (.not.olap%l_real) olap%data_c=conjg(olap%data_c)
call z%alloc(olap%l_real,dimension%nbasfcn,dimension%neigd)
! read in lower triangle part of overlap matrix from direct acces file olap
CALL olap%alloc(hmat%l_real,dimension%nbasfcn)
CALL read_olap(olap,kpts%nkpt*(jsp-1) + nk)
IF (.NOT.olap%l_real) olap%data_c=conjg(olap%data_c)
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)
! 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)
exch = 0
z%matsize1=MIN(z%matsize1,v_x%matsize2)
call v_x%multiply(z,tmp)
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))
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
! 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
IF (.NOT.v_x%l_real) v_x%data_c=conjg(v_x%data_c)
exch = 0
z%matsize1=MIN(z%matsize1,v_x%matsize2)
CALL v_x%multiply(z,tmp)
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 @@
IF (l_hyb) THEN
! Changes for hybrid functionals
input%isec1 = 999
namex = 'hse '
input%frcor = .true. ; input%ctail = .false. ; atoms%l_geo = .false.
namex = 'pbe0'
input%ctail = .false. ; atoms%l_geo = .false.! ; input%frcor = .true.
input%itmax = 15 ; input%maxiter = 25!; input%imix = 17
IF (ANY(kpts%nkpt3(:).EQ.0)) kpts%nkpt3(:) = 4
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
use m_io_matrix
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
USE m_types
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