The Elk Code
 
Loading...
Searching...
No Matches
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
6subroutine energyafsp
7use modmain
8use modmpi
9use modomp
10implicit none
11! local variables
12integer ik,ist,i,l,nthd
13real(8) ca,sm,v(3),wo,t1
14complex(8) z11,z12,z21,z22
15! automatic arrays
16complex(8) y(nstsv)
17! allocatable arrays
18complex(8), allocatable :: apwalm(:,:,:,:),evecfv(:,:),evecsv(:,:)
19complex(8), allocatable :: wfmt(:,:,:,:),wfgk(:,:,:),pmat(:,:,:)
20! external functions
21complex(8), external :: zdotc
22! coupling constant of the external spin-polarised A-field (-1/c)
23ca=-1.d0/solsc
24sm=0.d0
25! begin parallel loop over k-points
26call 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)
33allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot))
34allocate(evecfv(nmatmax,nstfv),evecsv(nstsv,nstsv))
35allocate(wfmt(npcmtmax,natmtot,nspinor,nstsv),wfgk(ngkmax,nspinor,nstsv))
36allocate(pmat(nstsv,nstsv,3))
37!$OMP DO SCHEDULE(DYNAMIC)
38do 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
72end do
73!$OMP END DO
74deallocate(apwalm,evecfv,evecsv)
75deallocate(wfmt,wfgk,pmat)
76!$OMP END PARALLEL
77call freethd(nthd)
78! add sums from each process and redistribute
79if (np_mpi > 1) then
80 call mpi_allreduce(mpi_in_place,sm,1,mpi_double_precision,mpi_sum,mpicom, &
81 ierror)
82end if
83! subtract from kinetic energy
84engykn=engykn-0.5d0*sm
85end subroutine
86
subroutine energyafsp
Definition energyafsp.f90:7
subroutine genpmatk(ngp, igpig, vgpc, wfmt, wfgp, pmat)
Definition genpmatk.f90:10
subroutine genwfsv(tsh, tgp, nst, idx, ngridg_, igfft_, ngp, igpig, apwalm, evecfv, evecsv, wfmt, ld, wfir)
Definition genwfsv.f90:11
subroutine getevecfv(fext, ikp, vpl, vgpl, evecfv)
Definition getevecfv.f90:10
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition getevecsv.f90:7
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition match.f90:10
real(8), dimension(:,:,:,:), allocatable vgkc
Definition modmain.f90:505
real(8), dimension(:), allocatable wkpt
Definition modmain.f90:475
complex(8), parameter zzero
Definition modmain.f90:1238
integer, dimension(3) ngridg
Definition modmain.f90:386
real(8), dimension(:,:,:), allocatable gkc
Definition modmain.f90:507
integer nspinor
Definition modmain.f90:267
character(256) filext
Definition modmain.f90:1300
real(8) engykn
Definition modmain.f90:950
integer, dimension(:,:), allocatable ngk
Definition modmain.f90:497
integer, dimension(:,:,:), allocatable igkig
Definition modmain.f90:501
complex(8), parameter zone
Definition modmain.f90:1238
integer lmmaxapw
Definition modmain.f90:199
integer apwordmax
Definition modmain.f90:760
real(8), dimension(3, 3) afspc
Definition modmain.f90:331
integer nkpt
Definition modmain.f90:461
integer natmtot
Definition modmain.f90:40
real(8), dimension(:,:,:,:), allocatable vgkl
Definition modmain.f90:503
integer npcmtmax
Definition modmain.f90:216
integer, dimension(:), allocatable igfft
Definition modmain.f90:406
integer nmatmax
Definition modmain.f90:848
real(8) solsc
Definition modmain.f90:1252
real(8) epsocc
Definition modmain.f90:900
real(8), dimension(:,:), allocatable vkl
Definition modmain.f90:471
integer ngkmax
Definition modmain.f90:499
integer nstfv
Definition modmain.f90:884
complex(8), dimension(:,:,:,:), allocatable sfacgk
Definition modmain.f90:509
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
subroutine holdthd(nloop, nthd)
Definition modomp.f90:78
subroutine freethd(nthd)
Definition modomp.f90:106