The Elk Code
writetdjtk.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2023 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 writetdjtk
7 use modmain
8 use modtddft
9 use modmpi
10 use modomp
11 implicit none
12 ! local variables
13 integer ik,ist,l,lp,nthd
14 real(8) ca,t1,t2
15 complex(8) z1
16 character(32) fext
17 ! allocatable arrays
18 real(8), allocatable :: jtk(:,:)
19 complex(8), allocatable :: evecsv(:,:),evecsvt(:,:)
20 complex(8), allocatable :: pmat(:,:,:),a(:,:),b(:,:)
21 ! external functions
22 complex(8), external :: zdotc
23 ! coupling constant of the external A-field (-1/c)
24 ca=-1.d0/solsc
25 allocate(jtk(3,nkpt))
26 jtk(:,:)=0.d0
27 call holdthd(nkpt/np_mpi,nthd)
28 !$OMP PARALLEL DEFAULT(SHARED) &
29 !$OMP PRIVATE(evecsv,evecsvt,pmat) &
30 !$OMP PRIVATE(a,b,l,t1,t2,ist,z1) &
31 !$OMP NUM_THREADS(nthd)
32 allocate(evecsv(nstsv,nstsv),evecsvt(nstsv,nstsv))
33 allocate(pmat(nstsv,nstsv,3),a(nstsv,nstsv),b(nstsv,nstsv))
34 !$OMP DO SCHEDULE(DYNAMIC)
35 do ik=1,nkpt
36 ! distribute among MPI processes
37  if (mod(ik-1,np_mpi) /= lp_mpi) cycle
38 ! get the momentum matrix elements from file
39  call getpmat(vkl(:,ik),pmat)
40 ! read in ground-state eigenvectors
41  call getevecsv('.OUT',ik,vkl(:,ik),evecsv)
42 ! read in time-dependent Kohn-Sham eigenvectors (first-variational basis)
43  call getevecsv(filext,ik,vkl(:,ik),evecsvt)
44  do l=1,3
45 ! form the momentum operator matrix elements in the first-variational basis
46  call zgemm('N','C',nstsv,nstsv,nstsv,zone,pmat(:,:,l),nstsv,evecsv,nstsv, &
47  zzero,a,nstsv)
48  call zgemm('N','N',nstsv,nstsv,nstsv,zone,evecsv,nstsv,a,nstsv,zzero,b, &
49  nstsv)
50  call zgemm('N','N',nstsv,nstsv,nstsv,zone,b,nstsv,evecsvt,nstsv,zzero,a, &
51  nstsv)
52 ! add to the total current for this k-point (including diamagnetic contribution)
53  t1=ca*afieldt(l,itimes)
54  do ist=1,nstsv
55  t2=occsv(ist,ik)
56  if (abs(t2) > epsocc) then
57  z1=zdotc(nstsv,evecsvt(:,ist),1,a(:,ist),1)
58  jtk(l,ik)=jtk(l,ik)+t2*(z1%re+t1)
59  end if
60  end do
61  end do
62 end do
63 !$OMP END DO
64 deallocate(evecsv,evecsvt,pmat,a,b)
65 !$OMP END PARALLEL
66 call freethd(nthd)
67 ! broadcast current array to every MPI process
68 if (np_mpi > 1) then
69  do ik=1,nkpt
70  lp=mod(ik-1,np_mpi)
71  call mpi_bcast(jtk(:,ik),3,mpi_double_precision,lp,mpicom,ierror)
72  end do
73 end if
74 ! write k-point dependent total current to file
75 if (mp_mpi) then
76 ! file extension
77  write(fext,'("_TS",I8.8,".OUT")') itimes
78  open(50,file='JTOTK'//trim(fext),form='FORMATTED',action='WRITE')
79  do ik=1,nkpt
80  write(50,'(I6,6G18.10)') ik,vkl(:,ik),jtk(:,ik)
81  end do
82  close(50)
83 end if
84 deallocate(jtk)
85 ! synchronise MPI processes
86 call mpi_barrier(mpicom,ierror)
87 end subroutine
88 
subroutine writetdjtk
Definition: writetdjtk.f90:7
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition: getevecsv.f90:7
character(256) filext
Definition: modmain.f90:1301
logical mp_mpi
Definition: modmpi.f90:17
integer nkpt
Definition: modmain.f90:461
subroutine getpmat(vpl, pmat)
Definition: getpmat.f90:7
Definition: modomp.f90:6
real(8) epsocc
Definition: modmain.f90:903
complex(8), parameter zone
Definition: modmain.f90:1240
integer np_mpi
Definition: modmpi.f90:13
integer nstsv
Definition: modmain.f90:889
real(8), dimension(:,:), allocatable occsv
Definition: modmain.f90:905
real(8) solsc
Definition: modmain.f90:1253
complex(8), parameter zzero
Definition: modmain.f90:1240
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
Definition: modmpi.f90:6
real(8), dimension(:,:), allocatable afieldt
Definition: modtddft.f90:58
integer itimes
Definition: modtddft.f90:46
integer lp_mpi
Definition: modmpi.f90:15
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
integer mpicom
Definition: modmpi.f90:11
integer ierror
Definition: modmpi.f90:19