The Elk Code
 
Loading...
Searching...
No Matches
rhomaguk.f90
Go to the documentation of this file.
1
2! Copyright (C) 2017 T. Mueller, 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 rhomaguk(ik0,lock,evecu)
7use modmain
8use modulr
9use modomp
10implicit none
11! arguments
12integer, intent(in) :: ik0
13integer(omp_lock_kind), intent(inout) :: lock(nqpt)
14complex(8), intent(in) :: evecu(nstulr,nstulr)
15! local variables
16integer ik,ikpa,jkpa
17integer nst,ist,jst,i,j
18integer ngk0,is,ias
19integer npc,ir,nthd
20real(8) ts0,ts1
21real(4) wo
22! automatic arrays
23integer idx(nstsv)
24complex(8) zfft(nqpt)
25! allocatable arrays
26complex(8), allocatable :: apwalm(:,:,:,:),evecfv(:,:),evecsv(:,:)
27complex(8), allocatable :: evectv(:,:,:),evecsvt(:,:)
28complex(4), allocatable :: wfmt(:,:,:,:),wfir(:,:,:)
29call timesec(ts0)
30! central k-point
31ik=(ik0-1)*nkpa+1
32! number of G+k-vectors for central k-point
33ngk0=ngk(1,ik)
34! get the eigenvectors from file
35allocate(evecfv(nmatmax,nstfv),evecsv(nstsv,nstsv))
36call getevecfv(filext,ik,vkl(:,ik),vgkl(:,:,:,ik),evecfv)
37call getevecsv(filext,ik,vkl(:,ik),evecsv)
38! find the matching coefficients
39allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot))
40call match(ngk0,vgkc(:,:,1,ik),gkc(:,1,ik),sfacgk(:,:,1,ik),apwalm)
41allocate(evectv(nstsv,nstsv,nqpt))
42call holdthd(nqpt,nthd)
43!$OMP PARALLEL DEFAULT(SHARED) &
44!$OMP PRIVATE(zfft,evecsvt,wfmt,wfir) &
45!$OMP PRIVATE(ikpa,jkpa,ist,jst,i,j) &
46!$OMP PRIVATE(ir,wo,ias,is,npc) &
47!$OMP NUM_THREADS(nthd)
48allocate(evecsvt(nstsv,nstsv))
49allocate(wfmt(npcmtmax,natmtot,nspinor,nstsv),wfir(ngtc,nspinor,nstsv))
50! loop over long-range states in subsets of size nstsv
51do jkpa=1,nkpa
52! number of and index to occupied states in subset
53!$OMP SINGLE
54 nst=0
55 do jst=1,nstsv
56 j=(jkpa-1)*nstsv+jst
57 if (abs(occulr(j,ik0)) < epsocc) cycle
58 nst=nst+1
59 idx(nst)=jst
60 end do
61!$OMP END SINGLE
62 if (nst == 0) cycle
63!$OMP DO SCHEDULE(DYNAMIC)
64 do jst=1,nst
65 j=(jkpa-1)*nstsv+idx(jst)
66 do ist=1,nstsv
67 zfft(1:nqpt)=0.d0
68 do ikpa=1,nkpa
69 i=(ikpa-1)*nstsv+ist
70! store the long-range state in FFT Q-space
71 zfft(iqfft(ikpa))=evecu(i,j)
72 end do
73! Fourier transform to R-space
74 call zfftifc(3,ngridq,1,zfft)
75 evectv(ist,jst,1:nqpt)=zfft(1:nqpt)
76 end do
77 end do
78!$OMP END DO
79! parallel loop over R-points
80!$OMP DO SCHEDULE(DYNAMIC)
81 do ir=1,nqpt
82! convert third-variational states to second-variational states
83 call zgemm('N','N',nstsv,nst,nstsv,zone,evecsv,nstsv,evectv(:,:,ir), &
84 nstsv,zzero,evecsvt,nstsv)
85! generate the wavefunctions in single-precision
86 call genwfsv_sp(.false.,.false.,nst,[0],ngdgc,igfc,ngk0,igkig(:,1,ik), &
87 apwalm,evecfv,evecsvt,wfmt,ngtc,wfir)
88! loop over second-variational states
89 do jst=1,nst
90 j=(jkpa-1)*nstsv+idx(jst)
91 wo=occulr(j,ik0)*wkpt(ik)
92! add to the density and magnetisation
93 call omp_set_lock(lock(ir))
94! muffin-tin part
95 do ias=1,natmtot
96 is=idxis(ias)
97 npc=npcmt(is)
98 if (spinpol) then
99 if (ncmag) then
100 call rmk1(npc,wo,wfmt(:,ias,1,jst),wfmt(:,ias,2,jst), &
101 rhormt(:,ias,ir),magrmt(:,ias,1,ir),magrmt(:,ias,2,ir), &
102 magrmt(:,ias,3,ir))
103 else
104 call rmk2(npc,wo,wfmt(:,ias,1,jst),wfmt(:,ias,2,jst), &
105 rhormt(:,ias,ir),magrmt(:,ias,1,ir))
106 end if
107 else
108 call rmk3(npc,wo,wfmt(:,ias,1,jst),rhormt(:,ias,ir))
109 end if
110 end do
111! interstitial part
112 if (spinpol) then
113 if (ncmag) then
114 call rmk1(ngtc,wo,wfir(:,1,jst),wfir(:,2,jst),rhorir(:,ir), &
115 magrir(:,1,ir),magrir(:,2,ir),magrir(:,3,ir))
116 else
117 call rmk2(ngtc,wo,wfir(:,1,jst),wfir(:,2,jst),rhorir(:,ir), &
118 magrir(:,1,ir))
119 end if
120 else
121 call rmk3(ngtc,wo,wfir(:,1,jst),rhorir(:,ir))
122 end if
123 call omp_unset_lock(lock(ir))
124 end do
125! end parallel loop over R-points
126 end do
127!$OMP END DO
128end do
129deallocate(evecsvt,wfmt,wfir)
130!$OMP END PARALLEL
131call freethd(nthd)
132deallocate(apwalm,evecfv,evecsv,evectv)
133call timesec(ts1)
134!$OMP ATOMIC
135timerho=timerho+ts1-ts0
136return
137
138contains
139
140pure subroutine rmk1(n,wo,wf1,wf2,rho,mag1,mag2,mag3)
141implicit none
142! arguments
143integer, intent(in) :: n
144real(4), intent(in) :: wo
145complex(4), intent(in) :: wf1(n),wf2(n)
146real(8), intent(inout) :: rho(n),mag1(n),mag2(n),mag3(n)
147! local variables
148integer i
149real(4) wo2,t1,t2
150real(4) a1,b1,a2,b2
151wo2=2.e0*wo
152!$OMP SIMD PRIVATE(a1,b1,a2,b2,t1,t2) SIMDLEN(8)
153do i=1,n
154 a1=real(wf1(i)); b1=aimag(wf1(i))
155 a2=real(wf2(i)); b2=aimag(wf2(i))
156 t1=a1**2+b1**2; t2=a2**2+b2**2
157 mag1(i)=mag1(i)+wo2*(a1*a2+b1*b2)
158 mag2(i)=mag2(i)+wo2*(a1*b2-b1*a2)
159 mag3(i)=mag3(i)+wo*(t1-t2)
160 rho(i)=rho(i)+wo*(t1+t2)
161end do
162end subroutine
163
164pure subroutine rmk2(n,wo,wf1,wf2,rho,mag)
165implicit none
166! arguments
167integer, intent(in) :: n
168real(4), intent(in) :: wo
169complex(4), intent(in) :: wf1(n),wf2(n)
170real(8), intent(inout) :: rho(n),mag(n)
171! local variables
172integer i
173real(4) t1,t2
174!$OMP SIMD PRIVATE(t1,t2) SIMDLEN(8)
175do i=1,n
176 t1=real(wf1(i))**2+aimag(wf1(i))**2
177 t2=real(wf2(i))**2+aimag(wf2(i))**2
178 mag(i)=mag(i)+wo*(t1-t2)
179 rho(i)=rho(i)+wo*(t1+t2)
180end do
181end subroutine
182
183pure subroutine rmk3(n,wo,wf,rho)
184implicit none
185! arguments
186integer, intent(in) :: n
187real(4), intent(in) :: wo
188complex(4), intent(in) :: wf(n)
189real(8), intent(inout) :: rho(n)
190rho(1:n)=rho(1:n)+wo*(real(wf(1:n))**2+aimag(wf(1:n))**2)
191end subroutine
192
193end subroutine
194
subroutine genwfsv_sp(tsh, tgp, nst, idx, ngridg_, igfft_, ngp, igpig, apwalm, evecfv, evecsv, wfmt, ld, wfir)
Definition genwfsv_sp.f90:8
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
logical ncmag
Definition modmain.f90:240
real(8), dimension(:,:,:), allocatable gkc
Definition modmain.f90:507
integer nspinor
Definition modmain.f90:267
integer, dimension(3) ngdgc
Definition modmain.f90:388
character(256) filext
Definition modmain.f90:1300
logical spinpol
Definition modmain.f90:228
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, dimension(:), allocatable igfc
Definition modmain.f90:410
integer, dimension(maxatoms *maxspecies) idxis
Definition modmain.f90:44
integer lmmaxapw
Definition modmain.f90:199
real(8) timerho
Definition modmain.f90:1220
integer apwordmax
Definition modmain.f90:760
integer ngtc
Definition modmain.f90:392
integer natmtot
Definition modmain.f90:40
real(8), dimension(:,:,:,:), allocatable vgkl
Definition modmain.f90:503
integer npcmtmax
Definition modmain.f90:216
integer, dimension(maxspecies) npcmt
Definition modmain.f90:214
integer nmatmax
Definition modmain.f90:848
real(8) epsocc
Definition modmain.f90:900
real(8), dimension(:,:), allocatable vkl
Definition modmain.f90:471
integer, dimension(:), allocatable iqfft
Definition modmain.f90:537
integer ngkmax
Definition modmain.f90:499
integer nstfv
Definition modmain.f90:884
complex(8), dimension(:,:,:,:), allocatable sfacgk
Definition modmain.f90:509
integer, dimension(3) ngridq
Definition modmain.f90:515
subroutine holdthd(nloop, nthd)
Definition modomp.f90:78
subroutine freethd(nthd)
Definition modomp.f90:106
real(8), dimension(:,:,:), allocatable rhormt
Definition modulr.f90:52
real(8), dimension(:,:,:,:), allocatable magrmt
Definition modulr.f90:53
integer nkpa
Definition modulr.f90:24
real(8), dimension(:,:), allocatable occulr
Definition modulr.f90:98
real(8), dimension(:,:,:), allocatable magrir
Definition modulr.f90:53
real(8), dimension(:,:), allocatable rhorir
Definition modulr.f90:52
pure subroutine rmk2(n, wo, wf1, wf2, rho, mag)
Definition rhomagk.f90:198
pure subroutine rmk3(n, wo, wf, rho)
Definition rhomagk.f90:217
pure subroutine rmk1(n, wo, wf1, wf2, rho, mag1, mag2, mag3)
Definition rhomagk.f90:174
subroutine rhomaguk(ik0, lock, evecu)
Definition rhomaguk.f90:7
subroutine timesec(ts)
Definition timesec.f90:10
subroutine zfftifc(nd, n, sgn, z)