The Elk Code
writexrmk.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2024 Peter Elliott, 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 writexrmk
7 use modmain
8 use modtddft
9 use modmpi
10 use modomp
11 use moddelf
12 implicit none
13 ! local variables
14 integer ik,jk,ist,jst
15 integer i1,i2,i3,i,lp,nthd
16 real(8) xchg,t1,t2
17 complex(8) z1
18 ! automatic arrays
19 real(8) xrk(nkptnr),xmk(ndmag,nkptnr)
20 complex(8) zv(nstsv)
21 character(32) fext
22 ! allocatable arrays
23 complex(8), allocatable :: evecsv(:,:),evecsvt(:,:)
24 ! external functions
25 complex(8), external :: zdotc
26 ! zero the excited density and magnetisation
27 xrk(:)=0.d0
28 if (spinpol) xmk(:,:)=0.d0
29 call holdthd(nkptnr/np_mpi,nthd)
30 !$OMP PARALLEL DEFAULT(SHARED) &
31 !$OMP PRIVATE(evecsv,evecsvt,zv) &
32 !$OMP PRIVATE(jk,ist,jst,z1,i,t1,t2) &
33 !$OMP NUM_THREADS(nthd)
34 allocate(evecsv(nstsv,nstsv),evecsvt(nstsv,nstsv))
35 !$OMP DO SCHEDULE(DYNAMIC)
36 do ik=1,nkptnr
37 ! distribute among MPI processes
38  if (mod(ik-1,np_mpi) /= lp_mpi) cycle
39 ! equivalent reduced k-point
40  jk=ivkik(ivk(1,ik),ivk(2,ik),ivk(3,ik))
41 ! read in ground-state eigenvectors
42  call getevecsv('.OUT',0,vkl(:,ik),evecsv)
43 ! read in time-dependent Kohn-Sham eigenvectors (first-variational basis)
44  call getevecsv(filext,0,vkl(:,ik),evecsvt)
45  do ist=1,nstsv
46  if (evalsv(ist,jk) > efermi) cycle
47 ! project time-dependent Kohn-Sham state onto ground-state conduction bands
48  zv(1:nstsv)=0.d0
49  do jst=1,nstsv
50  if (evalsv(jst,jk) < efermi) cycle
51  z1=zdotc(nstsv,evecsv(:,jst),1,evecsvt(:,ist),1)
52  zv(1:nstsv)=zv(1:nstsv)+z1*evecsv(1:nstsv,jst)
53  end do
54 ! calculate the excited density and magnetisation
55  if (spinpol) then
56  i=nstfv+1
57  t1=dble(zdotc(nstfv,zv,1,zv,1))
58  t2=dble(zdotc(nstfv,zv(i),1,zv(i),1))
59  xrk(ik)=xrk(ik)+t1+t2
60  xmk(ndmag,ik)=xmk(ndmag,ik)+t1-t2
61  if (ncmag) then
62  z1=zdotc(nstfv,zv,1,zv(i),1)
63  xmk(1,ik)=xmk(1,ik)+2.d0*z1%re
64  xmk(2,ik)=xmk(2,ik)+2.d0*z1%im
65  end if
66  else
67  xrk(ik)=xrk(ik)+occmax*dble(zdotc(nstsv,zv,1,zv,1))
68  end if
69  end do
70 end do
71 !$OMP END DO
72 deallocate(evecsv,evecsvt)
73 !$OMP END PARALLEL
74 call freethd(nthd)
75 ! broadcast arrays to every MPI process
76 if (np_mpi > 1) then
77  do ik=1,nkptnr
78  lp=mod(ik-1,np_mpi)
79  call mpi_bcast(xrk(ik),1,mpi_double_precision,lp,mpicom,ierror)
80  call mpi_bcast(xmk(:,ik),3,mpi_double_precision,lp,mpicom,ierror)
81  end do
82 end if
83 ! compute the excited charge
84 xchg=sum(wkpt(1:nkptnr)*xrk(1:nkptnr))
85 if (mp_mpi) then
86 ! file extension
87  write(fext,'("_TS",I8.8,".OUT")') itimes
88 ! write k-point dependent excited density and magnetisation to file
89  open(50,file='XRHOK'//trim(fext),form='FORMATTED',action='WRITE')
90  if (spinpol) then
91  open(51,file='XMAGK'//trim(fext),form='FORMATTED',action='WRITE')
92  end if
93  do i3=0,ngridk(3)-1
94  do i2=0,ngridk(2)-1
95  do i1=0,ngridk(1)-1
96  ik=ivkiknr(i1,i2,i3)
97  write(50,'(I6,4G18.10)') ik,vkl(:,ik),xrk(ik)
98  if (spinpol) then
99  write(51,'(I6,6G18.10)') ik,vkl(:,ik),xmk(:,ik)
100  end if
101  end do
102  end do
103  end do
104  close(50)
105  if (spinpol) close(51)
106 ! write the excited charge to file
107  if (itimes <= 1) call delfile('XCHARGE_TD.OUT')
108  open(50,file='XCHARGE_TD.OUT',form='FORMATTED',position='APPEND')
109  write(50,'(2G18.10)') times(itimes),xchg
110  close(50)
111 end if
112 ! synchronise MPI processes
113 call mpi_barrier(mpicom,ierror)
114 end subroutine
115 
real(8) efermi
Definition: modmain.f90:903
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition: getevecsv.f90:7
character(256) filext
Definition: modmain.f90:1295
real(8), dimension(:,:), allocatable evalsv
Definition: modmain.f90:915
logical mp_mpi
Definition: modmpi.f90:17
logical spinpol
Definition: modmain.f90:228
Definition: modomp.f90:6
integer, dimension(:,:,:), allocatable ivkik
Definition: modmain.f90:467
integer np_mpi
Definition: modmpi.f90:13
subroutine writexrmk
Definition: writexrmk.f90:7
real(8), dimension(:), allocatable wkpt
Definition: modmain.f90:475
real(8) occmax
Definition: modmain.f90:897
integer, dimension(3) ngridk
Definition: modmain.f90:448
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
subroutine delfile(fname)
Definition: moddelf.f90:15
Definition: modmpi.f90:6
real(8), dimension(:), allocatable times
Definition: modtddft.f90:48
integer itimes
Definition: modtddft.f90:46
integer lp_mpi
Definition: modmpi.f90:15
subroutine freethd(nthd)
Definition: modomp.f90:112
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
logical ncmag
Definition: modmain.f90:240
integer nstfv
Definition: modmain.f90:883
integer, dimension(:,:), allocatable ivk
Definition: modmain.f90:465
integer mpicom
Definition: modmpi.f90:11
integer ierror
Definition: modmpi.f90:19
integer, dimension(:,:,:), allocatable ivkiknr
Definition: modmain.f90:469