The Elk Code
 
Loading...
Searching...
No Matches
timestep.f90
Go to the documentation of this file.
1
2! Copyright (C) 2014 K. Krieger, J. K. Dewhurst, S. Sharma and E. K. U. Gross.
3! This file is distributed under the terms of the GNU General Public License.
4! See the file COPYING for license details.
5
6subroutine timestep
7use modmain
8use modtddft
9use modmpi
10use modomp
11implicit none
12! local variables
13integer ik,i,nthd
14real(8) ca,dt,t1
15complex(8) z1,z2
16! automatic arrays
17real(8) w(nstsv)
18! allocatable arrays
19real(8), allocatable :: vmt(:,:),vir(:),bmt(:,:,:),bir(:,:)
20complex(8), allocatable :: evecsv(:,:),evectv(:,:),evecsvt(:,:)
21complex(8), allocatable :: kmat(:,:),pmat(:,:,:)
22complex(8), allocatable :: a(:,:),b(:,:),c(:,:)
23if (itimes >= ntimes) then
24 write(*,*)
25 write(*,'("Error(timestep): itimes >= ntimes : ",2I8)') itimes,ntimes
26 write(*,*)
27 stop
28end if
29allocate(vmt(npcmtmax,natmtot),vir(ngtc))
30if (spinpol) then
31 allocate(bmt(npcmtmax,natmtot,ndmag),bir(ngtc,ndmag))
32end if
33! generate the Kohn-Sham potential and magnetic field in spherical coordinates
34! and multiply by the radial integration weights; also multiply the interstitial
35! potential with the characteristic function
36call vblocal(vmt,vir,bmt,bir)
37! time step length
39! zero the kinetic energy
40engykn=0.d0
41! zero the total current
42jtot(1:3)=0.d0
43! loop over k-points
44call holdthd(nkpt/np_mpi,nthd)
45!$OMP PARALLEL DEFAULT(SHARED) &
46!$OMP PRIVATE(evecsv,evectv,evecsvt) &
47!$OMP PRIVATE(kmat,pmat,w,a,b,c) &
48!$OMP PRIVATE(i,t1,z1,z2) &
49!$OMP NUM_THREADS(nthd)
50allocate(evecsv(nstsv,nstsv),evectv(nstsv,nstsv),evecsvt(nstsv,nstsv))
51allocate(kmat(nstsv,nstsv),pmat(nstsv,nstsv,3))
52allocate(a(nstsv,nstsv),b(nstsv,nstsv),c(nstsv,nstsv))
53!$OMP DO SCHEDULE(DYNAMIC)
54do ik=1,nkpt
55! distribute among MPI processes
56 if (mod(ik-1,np_mpi) /= lp_mpi) cycle
57! get the kinetic matrix elements from file
58 call getkmat(ik,kmat)
59! get the momentum matrix elements from file
60 call getpmat(vkl(:,ik),pmat)
61! generate the Hamiltonian matrix in the ground-state second-variational basis
62 call genhmlt(ik,vmt,vir,bmt,bir,kmat,pmat,evectv)
63! diagonalise the Hamiltonian to get third-variational eigenvectors
64 if (spinpol.and.(.not.ncmag)) then
65! collinear case requires block diagonalisation
66 call eveqnzh(nstfv,nstsv,evectv,w)
67 evectv(nstfv+1:nstsv,1:nstfv)=0.d0
68 evectv(1:nstfv,nstfv+1:nstsv)=0.d0
69 i=nstfv+1
70 call eveqnzh(nstfv,nstsv,evectv(i,i),w(i))
71 else
72! non-collinear or spin-unpolarised: full diagonalisation
73 call eveqnzh(nstsv,nstsv,evectv,w)
74 end if
75! read in ground-state eigenvectors
76 call getevecsv('.OUT',ik,vkl(:,ik),evecsv)
77! convert third-variational eigenvectors to first-variational basis
78 call zgemm('N','N',nstsv,nstsv,nstsv,zone,evecsv,nstsv,evectv,nstsv,zzero,a, &
79 nstsv)
80! time propagate instantaneous eigenvectors across one time step
81 if (tdphi == 0.d0) then
82! real time evolution
83 do i=1,nstsv
84 t1=-w(i)*dt
85 z1=cmplx(cos(t1),sin(t1),8)
86 b(1:nstsv,i)=z1*a(1:nstsv,i)
87 end do
88 else
89! complex time evolution
90 z2=cmplx(sin(tdphi),cos(tdphi),8)
91 do i=1,nstsv
92 t1=-w(i)*dt
93 z1=exp(t1*z2)
94 b(1:nstsv,i)=z1*a(1:nstsv,i)
95 end do
96 end if
97! read in time-dependent Kohn-Sham eigenvectors (first-variational basis)
98 call getevecsv(filext,ik,vkl(:,ik),evecsvt)
99! apply time evolution operator
100 call zgemm('C','N',nstsv,nstsv,nstsv,zone,a,nstsv,evecsvt,nstsv,zzero,c,nstsv)
101 call zgemm('N','N',nstsv,nstsv,nstsv,zone,b,nstsv,c,nstsv,zzero,evecsvt,nstsv)
102! orthonormalise the eigenvectors if required
103 if (ntsorth > 0) then
104 if (mod(itimes-1,ntsorth) == 0) call unitary(nstsv,evecsvt)
105 end if
106! add to the kinetic energy
107 call engyknk(ik,kmat,evecsv,evecsvt)
108! add to the total current
109 call jtotk(ik,pmat,evecsv,evecsvt)
110! write the new eigenvectors to file
111 call putevecsv(filext,ik,evecsvt)
112end do
113!$OMP END DO
114deallocate(evecsv,evectv,evecsvt)
115deallocate(kmat,pmat,a,b,c)
116!$OMP END PARALLEL
117call freethd(nthd)
118deallocate(vmt,vir)
119if (spinpol) deallocate(bmt,bir)
120! add the kinetic energy and total current from each process and redistribute
121if (np_mpi > 1) then
122 call mpi_allreduce(mpi_in_place,engykn,1,mpi_double_precision,mpi_sum,mpicom,&
123 ierror)
124 call mpi_allreduce(mpi_in_place,jtot,3,mpi_double_precision,mpi_sum,mpicom, &
125 ierror)
126end if
127! add the core kinetic energy
129! coupling constant of the external A-field (-1/c)
130ca=-1.d0/solsc
131! add the diamagnetic current to total
132jtot(1:3)=jtot(1:3)+ca*afieldt(1:3,itimes)*(chgtot-chgstot(1:3))
133! symmetrise the vector
134call symvec(jtot)
135! total current magnitude
136jtotm=norm2(jtot(1:3))
137! write the time step to file
138if (mp_mpi) call writetimes
139! backup existing time-dependent Kohn-Sham eigenvectors if required
140call tdbackup
141! synchronise MPI processes
142call mpi_barrier(mpicom,ierror)
143end subroutine
144
subroutine engyknk(ik, kmat, evecsv, evecsvt)
Definition engyknk.f90:7
subroutine eveqnzh(n, ld, a, w)
Definition eveqnzh.f90:7
subroutine genhmlt(ik, vmt, vir, bmt, bir, kmat, pmat, h)
Definition genhmlt.f90:7
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition getevecsv.f90:7
subroutine getkmat(ik, kmat)
Definition getkmat.f90:7
subroutine getpmat(vpl, pmat)
Definition getpmat.f90:7
subroutine jtotk(ik, pmat, evecsv, evecsvt)
Definition jtotk.f90:7
real(8), dimension(3) jtot
Definition modmain.f90:748
complex(8), parameter zzero
Definition modmain.f90:1238
logical ncmag
Definition modmain.f90:240
character(256) filext
Definition modmain.f90:1300
real(8) engykn
Definition modmain.f90:950
real(8) engykncr
Definition modmain.f90:952
logical spinpol
Definition modmain.f90:228
complex(8), parameter zone
Definition modmain.f90:1238
real(8) jtotm
Definition modmain.f90:748
real(8) chgtot
Definition modmain.f90:726
integer ngtc
Definition modmain.f90:392
integer nkpt
Definition modmain.f90:461
integer natmtot
Definition modmain.f90:40
integer npcmtmax
Definition modmain.f90:216
real(8) solsc
Definition modmain.f90:1252
real(8), dimension(:,:), allocatable vkl
Definition modmain.f90:471
integer nstfv
Definition modmain.f90:884
integer ndmag
Definition modmain.f90:238
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) tdphi
Definition modtddft.f90:52
integer ntsorth
Definition modtddft.f90:105
real(8), dimension(:), allocatable times
Definition modtddft.f90:48
real(8), dimension(:,:), allocatable afieldt
Definition modtddft.f90:58
integer itimes
Definition modtddft.f90:46
real(8), dimension(3) chgstot
Definition modtddft.f90:84
integer ntimes
Definition modtddft.f90:42
subroutine putevecsv(fext, ik, evecsv)
Definition putevecsv.f90:7
subroutine symvec(vc)
Definition symvec.f90:7
subroutine tdbackup
Definition tdbackup.f90:7
subroutine timestep
Definition timestep.f90:7
subroutine unitary(n, a)
Definition unitary.f90:10
subroutine vblocal(vmt, vir, bmt, bir)
Definition vblocal.f90:7
subroutine writetimes
Definition writetimes.f90:7