The Elk Code
energyafsp.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2024 Eddie Harris-Lee, 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 energyafsp
7 use modmain
8 use modmpi
9 use modomp
10 implicit none
11 ! local variables
12 integer ik,ist,i,l,nthd
13 real(8) ca,sm,v(3),wo,t1
14 complex(8) z11,z12,z21,z22
15 ! automatic arrays
16 complex(8) y(nstsv)
17 ! allocatable arrays
18 complex(8), allocatable :: apwalm(:,:,:,:),evecfv(:,:),evecsv(:,:)
19 complex(8), allocatable :: wfmt(:,:,:,:),wfgk(:,:,:),pmat(:,:,:)
20 ! external functions
21 complex(8), external :: zdotc
22 ! coupling constant of the external spin-polarised A-field (-1/c)
23 ca=-1.d0/solsc
24 sm=0.d0
25 ! begin parallel loop over k-points
26 call holdthd(nkpt/np_mpi,nthd)
27 !$OMP PARALLEL DEFAULT(SHARED) &
28 !$OMP PRIVATE(apwalm,evecfv,evecsv) &
29 !$OMP PRIVATE(wfmt,wfgk,pmat,y) &
30 !$OMP PRIVATE(ist,wo,l,v,z11,z12,z21,z22,i,t1) &
31 !$OMP REDUCTION(+:sm) &
32 !$OMP NUM_THREADS(nthd)
33 allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot))
34 allocate(evecfv(nmatmax,nstfv),evecsv(nstsv,nstsv))
35 allocate(wfmt(npcmtmax,natmtot,nspinor,nstsv),wfgk(ngkmax,nspinor,nstsv))
36 allocate(pmat(nstsv,nstsv,3))
37 !$OMP DO SCHEDULE(DYNAMIC)
38 do ik=1,nkpt
39 ! distribute among MPI processes
40  if (mod(ik-1,np_mpi) /= lp_mpi) cycle
41 ! get the eigenvectors from file
42  call getevecfv(filext,ik,vkl(:,ik),vgkl(:,:,:,ik),evecfv)
43  call getevecsv(filext,ik,vkl(:,ik),evecsv)
44 ! find the matching coefficients
45  call match(ngk(1,ik),vgkc(:,:,1,ik),gkc(:,1,ik),sfacgk(:,:,1,ik),apwalm)
46 ! calculate the wavefunctions for all states
47  call genwfsv(.true.,.true.,nstsv,[0],ngridg,igfft,ngk(:,ik),igkig(:,:,ik), &
48  apwalm,evecfv,evecsv,wfmt,ngkmax,wfgk)
49 ! calculate the momentum matrix elements in the second-variational basis
50  call genpmatk(ngk(:,ik),igkig(:,:,ik),vgkc(:,:,:,ik),wfmt,wfgk,pmat)
51  do ist=1,nstsv
52  wo=occsv(ist,ik)
53  if (abs(wo) < epsocc) cycle
54  wo=wo*wkpt(ik)
55  do l=1,3
56  v(1:3)=ca*afspc(l,1:3)
57  z11=v(3)
58  z12=cmplx(v(1),-v(2),8)
59  z21=cmplx(v(1),v(2),8)
60  z22=-v(3)
61 ! convert momentum matrix elements to first-variational basis
62  call zgemv('N',nstsv,nstsv,zone,evecsv,nstsv,pmat(:,ist,l),1,zzero,y,1)
63  i=nstfv+1
64  t1=dble(z11*zdotc(nstfv,evecsv(1,ist),1,y,1)) &
65  +dble(z12*zdotc(nstfv,evecsv(1,ist),1,y(i),1)) &
66  +dble(z21*zdotc(nstfv,evecsv(i,ist),1,y,1)) &
67  +dble(z22*zdotc(nstfv,evecsv(i,ist),1,y(i),1))
68 ! add to the expectation value
69  sm=sm+wo*t1
70  end do
71  end do
72 end do
73 !$OMP END DO
74 deallocate(apwalm,evecfv,evecsv)
75 deallocate(wfmt,wfgk,pmat)
76 !$OMP END PARALLEL
77 call freethd(nthd)
78 ! add sums from each process and redistribute
79 if (np_mpi > 1) then
80  call mpi_allreduce(mpi_in_place,sm,1,mpi_double_precision,mpi_sum,mpicom, &
81  ierror)
82 end if
83 ! subtract from kinetic energy
84 engykn=engykn-0.5d0*sm
85 end subroutine
86 
integer nmatmax
Definition: modmain.f90:853
real(8), dimension(3, 3) afspc
Definition: modmain.f90:331
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition: getevecsv.f90:7
integer npcmtmax
Definition: modmain.f90:216
integer, dimension(3) ngridg
Definition: modmain.f90:386
character(256) filext
Definition: modmain.f90:1301
subroutine genwfsv(tsh, tgp, nst, idx, ngridg_, igfft_, ngp, igpig, apwalm, evecfv, evecsv, wfmt, ld, wfir)
Definition: genwfsv.f90:11
subroutine energyafsp
Definition: energyafsp.f90:7
integer lmmaxapw
Definition: modmain.f90:199
integer nkpt
Definition: modmain.f90:461
real(8) engykn
Definition: modmain.f90:953
integer ngkmax
Definition: modmain.f90:499
subroutine getevecfv(fext, ikp, vpl, vgpl, evecfv)
Definition: getevecfv.f90:10
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition: match.f90:10
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
complex(8), dimension(:,:,:,:), allocatable sfacgk
Definition: modmain.f90:509
subroutine genpmatk(ngp, igpig, vgpc, wfmt, wfgp, pmat)
Definition: genpmatk.f90:10
integer, dimension(:,:), allocatable ngk
Definition: modmain.f90:497
real(8), dimension(:), allocatable wkpt
Definition: modmain.f90:475
integer, dimension(:), allocatable igfft
Definition: modmain.f90:406
real(8), dimension(:,:,:,:), allocatable vgkl
Definition: modmain.f90:503
real(8), dimension(:,:), allocatable occsv
Definition: modmain.f90:905
integer nspinor
Definition: modmain.f90:267
real(8), dimension(:,:,:,:), allocatable vgkc
Definition: modmain.f90:505
real(8) solsc
Definition: modmain.f90:1253
complex(8), parameter zzero
Definition: modmain.f90:1240
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
integer apwordmax
Definition: modmain.f90:760
Definition: modmpi.f90:6
real(8), dimension(:,:,:), allocatable gkc
Definition: modmain.f90:507
integer lp_mpi
Definition: modmpi.f90:15
subroutine freethd(nthd)
Definition: modomp.f90:106
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
integer natmtot
Definition: modmain.f90:40
integer, dimension(:,:,:), allocatable igkig
Definition: modmain.f90:501
integer nstfv
Definition: modmain.f90:887
integer mpicom
Definition: modmpi.f90:11
integer ierror
Definition: modmpi.f90:19