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): ",I6," of ",I6," κ-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 gencore
65  call linengy
66  call genapwlofr
67  call gensocfr
68  call genevfsv
69  call occupy
70  call initulr
71 ! read in the potential STATE_ULR.OUT
72  call readstulr
73 ! initialise the external Coulomb potential
74  call vclqinit
75 ! apply required local operations to the potential and magnetic field
76  call vblocalu
77 ! loop over original k-points
78  call holdthd(nkpt0/np_mpi,nthd)
79 !$OMP PARALLEL DEFAULT(SHARED) &
80 !$OMP PRIVATE(evecu) &
81 !$OMP NUM_THREADS(nthd)
82  allocate(evecu(nstulr,nstulr))
83 !$OMP DO SCHEDULE(DYNAMIC)
84  do ik0=1,nkpt0
85 ! distribute among MPI processes
86  if (mod(ik0-1,np_mpi) /= lp_mpi) cycle
87 !$OMP CRITICAL(bandstrulr_)
88  write(*,'("Info(bandstrulr): ",I6," of ",I6," k-points")') ik0,nkpt0
89 !$OMP END CRITICAL(bandstrulr_)
90 ! solve the ultra long-range eigenvalue equation
91  call eveqnulr(ik0,evecu)
92 ! determine the current κ-point characteristic for each ULR state
93  call charkpa(ikpa,evecu,chkpa(:,ik0))
94 ! add to the ULR spectral function
95  call sfuadd(ik0,w,chkpa(:,ik0),sfu(:,ik0))
96  end do
97 !$OMP END DO
98  deallocate(evecu)
99 !$OMP END PARALLEL
100  call freethd(nthd)
101 ! broadcast arrays to every process
102  if (np_mpi > 1) then
103  do ik0=1,nkpt0
104  lp=mod(ik0-1,np_mpi)
105  call mpi_bcast(evalu(:,ik0),nstulr,mpi_double_precision,lp,mpicom,ierror)
106  call mpi_bcast(chkpa(:,ik0),nstulr,mpi_double_precision,lp,mpicom,ierror)
107  end do
108  end if
109 ! subtract the Fermi energy
110  evalu(:,:)=evalu(:,:)-efermi
111  if (mp_mpi) then
112 ! output the band structure
113  open(50,file='BANDULR.OUT',form='FORMATTED',action='WRITE', &
114  position='APPEND')
115  do ist=1,nstulr
116  do ik0=1,nkpt0
117  write(50,'(3G18.10)') dpp1d(ik0),evalu(ist,ik0),chkpa(ist,ik0)
118  end do
119  write(50,*)
120  end do
121  close(50)
122 ! output the vertex location lines
123  if (ikpa == 1) then
124 ! find the minimum and maximum eigenvalues
125  emin=minval(evalu(:,:))
126  emax=maxval(evalu(:,:))
127  open(50,file='BANDLINES.OUT',form='FORMATTED',action='WRITE')
128  do iv=1,nvp1d
129  write(50,'(2G18.10)') dvp1d(iv),emin
130  write(50,'(2G18.10)') dvp1d(iv),emax
131  write(50,*)
132  end do
133  close(50)
134  end if
135  end if
136 ! synchronise MPI processes
137  call mpi_barrier(mpicom,ierror)
138 end do
139 ! add the spectral function from each process and redistribute
140 call mpi_allreduce(mpi_in_place,sfu,nwplot*nkpt0,mpi_double_precision,mpi_sum, &
141  mpicom,ierror)
142 ! normalise
143 t1=1.d0/nkpa0
144 sfu(1:nwplot,1:nkpt0)=t1*sfu(1:nwplot,1:nkpt0)
145 ! write spectral function band structure
146 if (mp_mpi) then
147  open(50,file='BANDSFU.OUT',form='FORMATTED')
148  write(50,'(2I6," : grid size")') nkpt0,nwplot
149  do iw=1,nwplot
150  do ik0=1,nkpt0
151  write(50,'(3G18.10)') dpp1d(ik0),w(iw),sfu(iw,ik0)
152  end do
153  end do
154  close(50)
155  write(*,*)
156  write(*,'("Info(bandstrulr):")')
157  write(*,'(" Ultra long-range band structure plot written to BANDULR.OUT")')
158  write(*,'(" Plotted k-point character written in third column")')
159  write(*,*)
160  write(*,'(" Vertex location lines written to BANDLINES.OUT")')
161  write(*,*)
162  write(*,'(" Ultra long-range spectral function band structure written to &
163  &BANDSFU.OUT")')
164 end if
165 deallocate(vvlp1d0,vql0,w,chkpa,sfu)
166 end subroutine
167 
subroutine readstulr
Definition: readstulr.f90:7
subroutine genevfsv
Definition: genevfsv.f90:7
real(8) efermi
Definition: modmain.f90:907
integer task
Definition: modmain.f90:1299
logical mp_mpi
Definition: modmpi.f90:17
subroutine occupy
Definition: occupy.f90:10
integer nstulr
Definition: modulr.f90:95
real(8), dimension(:), allocatable dpp1d
Definition: modmain.f90:1126
subroutine gencore
Definition: gencore.f90:10
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:7
integer np_mpi
Definition: modmpi.f90:13
subroutine linengy
Definition: linengy.f90:10
integer nstsv
Definition: modmain.f90:889
real(8), dimension(2) wplot
Definition: modmain.f90:1079
real(8), dimension(:), allocatable dvp1d
Definition: modmain.f90:1122
subroutine vclqinit
Definition: vclqinit.f90:7
real(8), dimension(:,:), allocatable vql
Definition: modmain.f90:545
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:106
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:1073
subroutine eveqnulr(ik0, evecu)
Definition: eveqnulr.f90:7
integer nvp1d
Definition: modmain.f90:1114
integer nkpa
Definition: modulr.f90:24
real(8), dimension(:,:), allocatable evalu
Definition: modulr.f90:97
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