The Elk Code
 
Loading...
Searching...
No Matches
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
6subroutine writetdjtk
7use modmain
8use modtddft
9use modmpi
10use modomp
11implicit none
12! local variables
13integer ik,ist,l,lp,nthd
14real(8) ca,t1,t2
15complex(8) z1
16character(32) fext
17! allocatable arrays
18real(8), allocatable :: jtk(:,:)
19complex(8), allocatable :: evecsv(:,:),evecsvt(:,:)
20complex(8), allocatable :: pmat(:,:,:),a(:,:),b(:,:)
21! external functions
22complex(8), external :: zdotc
23! coupling constant of the external A-field (-1/c)
24ca=-1.d0/solsc
25allocate(jtk(3,nkpt))
26jtk(:,:)=0.d0
27call 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)
32allocate(evecsv(nstsv,nstsv),evecsvt(nstsv,nstsv))
33allocate(pmat(nstsv,nstsv,3),a(nstsv,nstsv),b(nstsv,nstsv))
34!$OMP DO SCHEDULE(DYNAMIC)
35do 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
62end do
63!$OMP END DO
64deallocate(evecsv,evecsvt,pmat,a,b)
65!$OMP END PARALLEL
66call freethd(nthd)
67! broadcast current array to every MPI process
68if (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
73end if
74! write k-point dependent total current to file
75if (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)
83end if
84deallocate(jtk)
85! synchronise MPI processes
86call mpi_barrier(mpicom,ierror)
87end subroutine
88
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition getevecsv.f90:7
subroutine getpmat(vpl, pmat)
Definition getpmat.f90:7
complex(8), parameter zzero
Definition modmain.f90:1238
character(256) filext
Definition modmain.f90:1300
complex(8), parameter zone
Definition modmain.f90:1238
integer nkpt
Definition modmain.f90:461
integer nstsv
Definition modmain.f90:886
real(8) solsc
Definition modmain.f90:1252
real(8) epsocc
Definition modmain.f90:900
real(8), dimension(:,:), allocatable vkl
Definition modmain.f90:471
real(8), dimension(:,:), allocatable occsv
Definition modmain.f90:902
integer lp_mpi
Definition modmpi.f90:15
integer ierror
Definition modmpi.f90:19
integer mpicom
Definition modmpi.f90:11
integer np_mpi
Definition modmpi.f90:13
logical mp_mpi
Definition modmpi.f90:17
subroutine holdthd(nloop, nthd)
Definition modomp.f90:78
subroutine freethd(nthd)
Definition modomp.f90:106
real(8), dimension(:,:), allocatable afieldt
Definition modtddft.f90:58
integer itimes
Definition modtddft.f90:46
subroutine writetdjtk
Definition writetdjtk.f90:7