The Elk Code
bandstrulr.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2024 Wenhan Chen, J. K. Dewhurst and S. Sharma.
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 bandstrulr
7 use modmain
8 use modulr
9 use modmpi
10 use modomp
11 use moddelf
12 implicit none
13 ! local variables
14 integer nkpa0,ikpa,nthd
15 integer ik0,ist,iv,iw,lp
16 real(8) dw,emin,emax,t1
17 ! allocatable arrays
18 real(8), allocatable :: vvlp1d0(:,:),vql0(:,:)
19 real(8), allocatable :: w(:),chkpa(:,:),sfu(:,:)
20 complex(8), allocatable :: evecu(:,:)
21 ! store the 1D plot vertices
22 allocate(vvlp1d0(3,nvp1d))
23 vvlp1d0(1:3,1:nvp1d)=vvlp1d(1:3,1:nvp1d)
24 ! initialise global variables
25 call init0
26 call init1
27 if (task == 720) then
28 ! use only κ = 0
29  nkpa0=1
30 else
31 ! use all κ-points
32  nkpa0=nkpa
33 end if
34 ! store the κ-points
35 allocate(vql0(3,nkpa0))
36 vql0(1:3,1:nkpa0)=vql(1:3,1:nkpa0)
37 ! generate frequency grid
38 allocate(w(nwplot))
39 dw=(wplot(2)-wplot(1))/dble(nwplot)
40 do iw=1,nwplot
41  w(iw)=dw*dble(iw-1)+wplot(1)
42 end do
43 allocate(chkpa(nstsv*nkpa,nkpt0))
44 ! allocate and zero the ULR spectral function
45 allocate(sfu(nwplot,nkpt0))
46 sfu(1:nwplot,1:nkpt0)=0.d0
47 ! delete the BANDULR.OUT file
48 call delfile('BANDULR.OUT')
49 ! loop over the κ-points
50 do ikpa=1,nkpa0
51  if (mp_mpi) then
52  write(*,*)
53  write(*,'("Info(bandstrulr): ",I0," of ",I0," κ-points")') ikpa,nkpa0
54  write(*,*)
55  end if
56 ! subtract current κ-point from 1D plot vertices
57  do iv=1,nvp1d
58  vvlp1d(1:3,iv)=vvlp1d0(1:3,iv)-vql0(1:3,ikpa)
59  end do
60  call init0
61  call init1
62  call readstate
63  call genvsig
64  call linengy
65  call genapwlofr
66  call gensocfr
67  call genevfsv
68  call occupy
69  call initulr
70 ! read in the potential STATE_ULR.OUT
71  call readstulr
72 ! initialise the external Coulomb potential
73  call vclqinit
74 ! apply required local operations to the potential and magnetic field
75  call vblocalu
76 ! loop over original k-points
77  call holdthd(nkpt0/np_mpi,nthd)
78 !$OMP PARALLEL DEFAULT(SHARED) &
79 !$OMP PRIVATE(evecu) &
80 !$OMP NUM_THREADS(nthd)
81  allocate(evecu(nstulr,nstulr))
82 !$OMP DO SCHEDULE(DYNAMIC)
83  do ik0=1,nkpt0
84 ! distribute among MPI processes
85  if (mod(ik0-1,np_mpi) /= lp_mpi) cycle
86 !$OMP CRITICAL(bandstrulr_)
87  write(*,'("Info(bandstrulr): ",I0," of ",I0," k-points")') ik0,nkpt0
88 !$OMP END CRITICAL(bandstrulr_)
89 ! solve the ultra long-range eigenvalue equation
90  call eveqnulr(ik0,evecu)
91 ! determine the current κ-point characteristic for each ULR state
92  call charkpa(ikpa,evecu,chkpa(:,ik0))
93 ! add to the ULR spectral function
94  call sfuadd(ik0,w,chkpa(:,ik0),sfu(:,ik0))
95  end do
96 !$OMP END DO
97  deallocate(evecu)
98 !$OMP END PARALLEL
99  call freethd(nthd)
100 ! broadcast arrays to every process
101  if (np_mpi > 1) then
102  do ik0=1,nkpt0
103  lp=mod(ik0-1,np_mpi)
104  call mpi_bcast(evalu(:,ik0),nstulr,mpi_double_precision,lp,mpicom,ierror)
105  call mpi_bcast(chkpa(:,ik0),nstulr,mpi_double_precision,lp,mpicom,ierror)
106  end do
107  end if
108 ! subtract the Fermi energy
109  evalu(:,:)=evalu(:,:)-efermi
110  if (mp_mpi) then
111 ! output the band structure
112  open(50,file='BANDULR.OUT',form='FORMATTED',action='WRITE', &
113  position='APPEND')
114  do ist=1,nstulr
115  do ik0=1,nkpt0
116  write(50,'(3G18.10)') dpp1d(ik0),evalu(ist,ik0),chkpa(ist,ik0)
117  end do
118  write(50,*)
119  end do
120  close(50)
121 ! output the vertex location lines
122  if (ikpa == 1) then
123 ! find the minimum and maximum eigenvalues
124  emin=minval(evalu(:,:))
125  emax=maxval(evalu(:,:))
126  open(50,file='BANDLINES.OUT',form='FORMATTED',action='WRITE')
127  do iv=1,nvp1d
128  write(50,'(2G18.10)') dvp1d(iv),emin
129  write(50,'(2G18.10)') dvp1d(iv),emax
130  write(50,*)
131  end do
132  close(50)
133  end if
134  end if
135 ! synchronise MPI processes
136  call mpi_barrier(mpicom,ierror)
137 end do
138 ! add the spectral function from each process and redistribute
139 call mpi_allreduce(mpi_in_place,sfu,nwplot*nkpt0,mpi_double_precision,mpi_sum, &
140  mpicom,ierror)
141 ! normalise
142 t1=1.d0/nkpa0
143 sfu(1:nwplot,1:nkpt0)=t1*sfu(1:nwplot,1:nkpt0)
144 ! write spectral function band structure
145 if (mp_mpi) then
146  open(50,file='BANDSFU.OUT',form='FORMATTED')
147  write(50,'(2I6," : grid size")') nkpt0,nwplot
148  do iw=1,nwplot
149  do ik0=1,nkpt0
150  write(50,'(3G18.10)') dpp1d(ik0),w(iw),sfu(iw,ik0)
151  end do
152  end do
153  close(50)
154  write(*,*)
155  write(*,'("Info(bandstrulr):")')
156  write(*,'(" Ultra long-range band structure plot written to BANDULR.OUT")')
157  write(*,'(" Plotted k-point character written in third column")')
158  write(*,*)
159  write(*,'(" Vertex location lines written to BANDLINES.OUT")')
160  write(*,*)
161  write(*,'(" Ultra long-range spectral function band structure written to &
162  &BANDSFU.OUT")')
163 end if
164 deallocate(vvlp1d0,vql0,w,chkpa,sfu)
165 end subroutine
166 
subroutine readstulr
Definition: readstulr.f90:7
subroutine genevfsv
Definition: genevfsv.f90:7
real(8) efermi
Definition: modmain.f90:903
integer task
Definition: modmain.f90:1299
logical mp_mpi
Definition: modmpi.f90:17
subroutine occupy
Definition: occupy.f90:10
integer nstulr
Definition: modulr.f90:97
real(8), dimension(:), allocatable dpp1d
Definition: modmain.f90:1126
Definition: modomp.f90:6
integer nkpt0
Definition: modulr.f90:18
subroutine genvsig
Definition: genvsig.f90:10
subroutine genapwlofr
Definition: genapwlofr.f90:7
subroutine gensocfr
Definition: gensocfr.f90:10
integer np_mpi
Definition: modmpi.f90:13
subroutine linengy
Definition: linengy.f90:10
integer nstsv
Definition: modmain.f90:885
real(8), dimension(2) wplot
Definition: modmain.f90:1081
real(8), dimension(:), allocatable dvp1d
Definition: modmain.f90:1122
subroutine vclqinit
Definition: vclqinit.f90:7
real(8), dimension(:,:), allocatable vql
Definition: modmain.f90:548
subroutine bandstrulr
Definition: bandstrulr.f90:7
subroutine init1
Definition: init1.f90:10
subroutine delfile(fname)
Definition: moddelf.f90:15
Definition: modmpi.f90:6
subroutine readstate
Definition: readstate.f90:10
real(8), dimension(:,:), allocatable vvlp1d
Definition: modmain.f90:1120
integer lp_mpi
Definition: modmpi.f90:15
pure subroutine charkpa(ikpa, evecu, chkpa)
Definition: charkpa.f90:7
subroutine freethd(nthd)
Definition: modomp.f90:112
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
subroutine vblocalu
Definition: vblocalu.f90:7
subroutine init0
Definition: init0.f90:10
Definition: modulr.f90:6
integer nwplot
Definition: modmain.f90:1075
subroutine eveqnulr(ik0, evecu)
Definition: eveqnulr.f90:7
integer nvp1d
Definition: modmain.f90:1116
integer nkpa
Definition: modulr.f90:24
real(8), dimension(:,:), allocatable evalu
Definition: modulr.f90:99
subroutine sfuadd(ik0, w, chkpa, sfu)
Definition: sfuadd.f90:7
integer mpicom
Definition: modmpi.f90:11
subroutine initulr
Definition: initulr.f90:7
integer ierror
Definition: modmpi.f90:19