The Elk Code
writehmlbse.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2010 S. Sharma, J. K. Dewhurst and E. K. U. Gross.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 subroutine writehmlbse
7 use modmain
8 use modmpi
9 ! sets up the BSE matrix and writes it to file
10 implicit none
11 ! local variables
12 integer ik,jk,ist,jst
13 integer a,b,i,j,m,n
14 real(8) t1
15 ! initialise global variables
16 call init0
17 call init1
18 call init2
19 call init3
20 ! read density and potentials from file
21 call readstate
22 ! find the new linearisation energies
23 call linengy
24 ! generate the APW radial functions
25 call genapwfr
26 ! generate the local-orbital radial functions
27 call genlofr
28 ! get the eigenvalues and occupation numbers from file
29 do ik=1,nkpt
30  call getevalsv(filext,ik,vkl(:,ik),evalsv(:,ik))
31  call getoccsv(filext,ik,vkl(:,ik),occsv(:,ik))
32 end do
33 ! check if system is metallic
34 t1=minval(abs(0.5d0-occsv(:,:)/occmax))
35 if (abs(t1-0.5d0) > 0.01d0) then
36  write(*,*)
37  write(*,'("Warning(writehmlbse): system is metallic, the BSE may fail")')
38  write(*,'("Try using a different vkloff or reducing swidth")')
39 end if
40 ! generate the BSE state index arrays
41 call genidxbse
42 if (allocated(hmlbse)) deallocate(hmlbse)
43 allocate(hmlbse(nmbse,nmbse))
44 ! synchronise MPI processes
45 call mpi_barrier(mpicom,ierror)
46 if (mp_mpi) then
47  write(*,*)
48  write(*,'("Info(writehmlbse): setting up BSE Hamiltonian matrix")')
49 end if
50 ! zero the BSE Hamiltonian
51 hmlbse(:,:)=0.d0
52 ! compute diagonal matrix elements
53 do ik=1,nkptnr
54 ! distribute among MPI processes
55  if (mod(ik-1,np_mpi) /= lp_mpi) cycle
56  jk=ivkik(ivk(1,ik),ivk(2,ik),ivk(3,ik))
57  do i=1,nvbse
58  ist=istbse(i,ik)
59  do j=1,ncbse
60  jst=jstbse(j,ik)
61  a=ijkbse(i,j,ik)
62  hmlbse(a,a)=evalsv(jst,jk)-evalsv(ist,jk)
63  if (bsefull) then
64  b=a+nbbse
65  hmlbse(b,b)=-hmlbse(a,a)
66  end if
67  end do
68  end do
69 end do
70 ! add the exchange matrix elements
71 if (hxbse) call hmlxbse
72 ! add the direct matrix elements
73 if (hdbse) call hmldbse
74 ! add matrices from all processes and redistribute
75 if (np_mpi > 1) then
76 ! ensure that the number of elements transmitted by MPI is not larger than the
77 ! maximum packet size (assumed to be 1024³ bytes)
78  m=67108864/nmbse
79  do b=1,nmbse,m
80  n=min(nmbse-b+1,m)
81  n=nmbse*n
82  call mpi_allreduce(mpi_in_place,hmlbse(1,b),n,mpi_double_complex,mpi_sum, &
83  mpicom,ierror)
84  end do
85 end if
86 ! write the BSE matrix to HMLBSE.OUT
87 if (mp_mpi) then
88  open(140,file='HMLBSE.OUT',form='UNFORMATTED',action='WRITE')
89  write(140) nmbse
90  write(140) hmlbse
91  close(140)
92  write(*,*)
93  write(*,'("Info(writehmlbse): BSE Hamiltonian matrix written to HMLBSE.OUT")')
94 end if
95 ! deallocate global BSE arrays
96 deallocate(istbse,jstbse,ijkbse,hmlbse)
97 end subroutine
98 
character(256) filext
Definition: modmain.f90:1301
real(8), dimension(:,:), allocatable evalsv
Definition: modmain.f90:921
logical mp_mpi
Definition: modmpi.f90:17
integer nkpt
Definition: modmain.f90:461
subroutine genlofr
Definition: genlofr.f90:10
subroutine getevalsv(fext, ikp, vpl, evalsv_)
Definition: getevalsv.f90:7
integer, dimension(:,:,:), allocatable ijkbse
Definition: modmain.f90:1199
subroutine hmlxbse
Definition: hmlxbse.f90:7
integer nbbse
Definition: modmain.f90:1191
integer, dimension(:,:,:), allocatable ivkik
Definition: modmain.f90:467
integer nkptnr
Definition: modmain.f90:463
integer, dimension(:,:), allocatable jstbse
Definition: modmain.f90:1197
integer np_mpi
Definition: modmpi.f90:13
subroutine linengy
Definition: linengy.f90:10
subroutine writehmlbse
Definition: writehmlbse.f90:7
real(8) occmax
Definition: modmain.f90:901
subroutine init3
Definition: init3.f90:7
subroutine init2
Definition: init2.f90:7
real(8), dimension(:,:), allocatable occsv
Definition: modmain.f90:905
integer nmbse
Definition: modmain.f90:1193
subroutine init1
Definition: init1.f90:10
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
subroutine genapwfr
Definition: genapwfr.f90:10
logical hxbse
Definition: modmain.f90:1209
Definition: modmpi.f90:6
subroutine getoccsv(fext, ikp, vpl, occsvp)
Definition: getoccsv.f90:7
subroutine readstate
Definition: readstate.f90:10
integer lp_mpi
Definition: modmpi.f90:15
subroutine genidxbse
Definition: genidxbse.f90:7
complex(8), dimension(:,:), allocatable hmlbse
Definition: modmain.f90:1201
logical bsefull
Definition: modmain.f90:1206
subroutine init0
Definition: init0.f90:10
subroutine hmldbse
Definition: hmldbse.f90:7
logical hdbse
Definition: modmain.f90:1209
integer nvbse
Definition: modmain.f90:1179
integer ncbse
Definition: modmain.f90:1179
integer, dimension(:,:), allocatable ivk
Definition: modmain.f90:465
integer mpicom
Definition: modmpi.f90:11
integer ierror
Definition: modmpi.f90:19
integer, dimension(:,:), allocatable istbse
Definition: modmain.f90:1195