The Elk Code
 
Loading...
Searching...
No Matches
rhomagk.f90
Go to the documentation of this file.
1
2! Copyright (C) 2002-2010 J. K. Dewhurst, S. Sharma and C. Ambrosch-Draxl.
3! This file is distributed under the terms of the GNU General Public License.
4! See the file COPYING for license details.
5
6!BOP
7! !ROUTINE: rhomagk
8! !INTERFACE:
9subroutine rhomagk(ngp,igpig,wppt,occsvp,apwalm,evecfv,evecsv,rhomt_,rhoir_, &
10 magmt_,magir_)
11! !USES:
12use modmain
13use modomp
14! !INPUT/OUTPUT PARAMETERS:
15! ngp : number of G+p-vectors (in,integer(nspnfv))
16! igpig : index from G+p-vectors to G-vectors (in,integer(ngkmax,nspnfv))
17! wppt : weight of input p-point (in,real)
18! occsvp : occupation number for each state (in,real(nstsv))
19! apwalm : APW matching coefficients
20! (in,complex(ngkmax,apwordmax,lmmaxapw,natmtot,nspnfv))
21! evecfv : first-variational eigenvectors (in,complex(nmatmax,nstfv,nspnfv))
22! evecsv : second-variational eigenvectors (in,complex(nstsv,nstsv))
23! rhomt_ : muffin-tin density (inout,real(npcmtmax,natmtot))
24! rhoir_ : interstitial density (inout,real(ngtc))
25! magmt_ : muffin-tin magnetisation (inout,real(npcmtmax,natmtot,ndmag))
26! magir_ : interstitial magnetisation (inout,real(ngtc,ndmag))
27! !DESCRIPTION:
28! Generates the partial valence charge density and magnetisation from the
29! eigenvectors at a particular $k$-point. In the muffin-tin region, the
30! wavefunction is obtained in terms of its $(l,m)$-components from both the
31! APW and local-orbital functions. Using a backward spherical harmonic
32! transform (SHT), the wavefunction is converted to real-space and the density
33! obtained from its modulus squared. A similar process is used for the
34! interstitial density in which the wavefunction in real-space is obtained
35! from a Fourier transform of the APW functions. See routines {\tt wfmtsv},
36! {\tt genshtmat} and {\tt eveqn}.
37!
38! !REVISION HISTORY:
39! Created April 2003 (JKD)
40! Removed conversion to spherical harmonics, January 2009 (JKD)
41! Partially de-phased the muffin-tin magnetisation for spin-spirals,
42! February 2009 (FC, FB & LN)
43! Optimisations, July 2010 (JKD)
44!EOP
45!BOC
46implicit none
47! arguments
48integer, intent(in) :: ngp(nspnfv),igpig(ngkmax,nspnfv)
49real(8), intent(in) :: wppt,occsvp(nstsv)
50complex(8), intent(in) :: apwalm(ngkmax,apwordmax,lmmaxapw,natmtot,nspnfv)
51complex(8), intent(in) :: evecfv(nmatmax,nstfv,nspnfv),evecsv(nstsv,nstsv)
52real(8), intent(inout) :: rhomt_(npcmtmax,natmtot),rhoir_(ngtc)
53real(8), intent(inout) :: magmt_(npcmtmax,natmtot,ndmag),magir_(ngtc,ndmag)
54! local variables
55integer ispn,jspn,nst,ist
56integer is,ias,npc,i,j,k
57integer n,igp,nthd
58real(8) wo,ts0,ts1
59complex(8) z1
60! automatic arrays
61integer idx(nstsv)
62complex(8) wfir(ngtc,nspinor),wfgp(ngkmax)
63! allocatable arrays
64complex(8), allocatable :: wfmt(:,:,:)
65call timesec(ts0)
66! number of and index to occupied states
67nst=0
68do ist=1,nstsv
69 if (abs(occsvp(ist)) < epsocc) cycle
70 nst=nst+1
71 idx(nst)=ist
72end do
73!----------------------------------------------!
74! muffin-tin density and magnetisation !
75!----------------------------------------------!
76call holdthd(max(natmtot,nst),nthd)
77!$OMP PARALLEL DEFAULT(SHARED) &
78!$OMP PRIVATE(wfmt,wfir,wfgp) &
79!$OMP PRIVATE(ias,is,npc,i,j,k,wo) &
80!$OMP PRIVATE(ispn,jspn,n,ist,z1,igp) &
81!$OMP NUM_THREADS(nthd)
82allocate(wfmt(npcmtmax,nspinor,nst))
83!$OMP DO SCHEDULE(DYNAMIC)
84do ias=1,natmtot
85 is=idxis(ias)
86 npc=npcmt(is)
87 call wfmtsv(.false.,lradstp,is,ias,nst,idx,ngp,apwalm,evecfv,evecsv,npcmtmax,&
88 wfmt)
89 do j=1,nst
90 k=idx(j)
91 wo=occsvp(k)*wppt
92! add to density and magnetisation
93 if (spinpol) then
94! spin-polarised
95 if (ncmag) then
96! non-collinear
97 call rmk1(npc,wo,wfmt(:,1,j),wfmt(:,2,j),rhomt_(:,ias),magmt_(:,ias,1),&
98 magmt_(:,ias,2),magmt_(:,ias,3))
99 else
100! collinear
101 call rmk2(npc,wo,wfmt(:,1,j),wfmt(:,2,j),rhomt_(:,ias),magmt_(:,ias,1))
102 end if
103 else
104! spin-unpolarised
105 call rmk3(npc,wo,wfmt(:,1,j),rhomt_(:,ias))
106 end if
107 end do
108end do
109!$OMP END DO NOWAIT
110deallocate(wfmt)
111!------------------------------------------------!
112! interstitial density and magnetisation !
113!------------------------------------------------!
114!$OMP DO ORDERED SCHEDULE(DYNAMIC)
115do j=1,nst
116 k=idx(j)
117 wo=occsvp(k)*wppt/omega
118 if (tevecsv) then
119! generate spinor wavefunction from second-variational eigenvectors
120 do ispn=1,nspinor
121 jspn=jspnfv(ispn)
122 n=ngp(jspn)
123 wfgp(1:n)=0.d0
124 do ist=1,nstfv
125 i=(ispn-1)*nstfv+ist
126 z1=evecsv(i,k)
127 if (abs(z1%re)+abs(z1%im) > 1.d-10) then
128 wfgp(1:n)=wfgp(1:n)+z1*evecfv(1:n,ist,jspn)
129 end if
130 end do
131 wfir(1:ngtc,ispn)=0.d0
132 do igp=1,n
133 wfir(igfc(igpig(igp,jspn)),ispn)=wfgp(igp)
134 end do
135! Fourier transform wavefunction to real-space
136 call zfftifc(3,ngdgc,1,wfir(:,ispn))
137 end do
138 else
139! spin-unpolarised wavefunction
140 wfir(1:ngtc,1)=0.d0
141 do igp=1,ngp(1)
142 wfir(igfc(igpig(igp,1)),1)=evecfv(igp,k,1)
143 end do
144 call zfftifc(3,ngdgc,1,wfir)
145 end if
146! add to density and magnetisation
147!$OMP ORDERED
148 if (spinpol) then
149! spin-polarised
150 if (ncmag) then
151! non-collinear
152 call rmk1(ngtc,wo,wfir,wfir(:,2),rhoir_,magir_,magir_(:,2),magir_(:,3))
153 else
154! collinear
155 call rmk2(ngtc,wo,wfir,wfir(:,2),rhoir_,magir_)
156 end if
157 else
158! spin-unpolarised
159 call rmk3(ngtc,wo,wfir,rhoir_)
160 end if
161!$OMP END ORDERED
162end do
163!$OMP END DO
164!$OMP END PARALLEL
165call freethd(nthd)
166call timesec(ts1)
167!$OMP ATOMIC
168timerho=timerho+ts1-ts0
169return
170
171contains
172
173pure subroutine rmk1(n,wo,wf1,wf2,rho,mag1,mag2,mag3)
174implicit none
175! arguments
176integer, intent(in) :: n
177real(8), intent(in) :: wo
178complex(8), intent(in) :: wf1(n),wf2(n)
179real(8), intent(inout) :: rho(n),mag1(n),mag2(n),mag3(n)
180! local variables
181integer i
182real(8) wo2,t1,t2
183real(8) a1,b1,a2,b2
184wo2=2.d0*wo
185!$OMP SIMD PRIVATE(a1,b1,a2,b2,t1,t2) SIMDLEN(8)
186do i=1,n
187 a1=dble(wf1(i)); b1=aimag(wf1(i))
188 a2=dble(wf2(i)); b2=aimag(wf2(i))
189 t1=a1**2+b1**2; t2=a2**2+b2**2
190 mag1(i)=mag1(i)+wo2*(a1*a2+b1*b2)
191 mag2(i)=mag2(i)+wo2*(a1*b2-b1*a2)
192 mag3(i)=mag3(i)+wo*(t1-t2)
193 rho(i)=rho(i)+wo*(t1+t2)
194end do
195end subroutine
196
197pure subroutine rmk2(n,wo,wf1,wf2,rho,mag)
198implicit none
199! arguments
200integer, intent(in) :: n
201real(8), intent(in) :: wo
202complex(8), intent(in) :: wf1(n),wf2(n)
203real(8), intent(inout) :: rho(n),mag(n)
204! local variables
205integer i
206real(8) t1,t2
207!$OMP SIMD PRIVATE(t1,t2) SIMDLEN(8)
208do i=1,n
209 t1=dble(wf1(i))**2+aimag(wf1(i))**2
210 t2=dble(wf2(i))**2+aimag(wf2(i))**2
211 mag(i)=mag(i)+wo*(t1-t2)
212 rho(i)=rho(i)+wo*(t1+t2)
213end do
214end subroutine
215
216pure subroutine rmk3(n,wo,wf,rho)
217implicit none
218! arguments
219integer, intent(in) :: n
220real(8), intent(in) :: wo
221complex(8), intent(in) :: wf(n)
222real(8), intent(inout) :: rho(n)
223rho(1:n)=rho(1:n)+wo*(dble(wf(1:n))**2+aimag(wf(1:n))**2)
224end subroutine
225
226end subroutine
227!EOC
228
logical ncmag
Definition modmain.f90:240
integer, dimension(3) ngdgc
Definition modmain.f90:388
logical spinpol
Definition modmain.f90:228
real(8) omega
Definition modmain.f90:20
integer, dimension(:), allocatable igfc
Definition modmain.f90:410
integer, dimension(maxatoms *maxspecies) idxis
Definition modmain.f90:44
integer lradstp
Definition modmain.f90:171
real(8) timerho
Definition modmain.f90:1220
integer, dimension(maxspecies) npcmt
Definition modmain.f90:214
integer, dimension(2) jspnfv
Definition modmain.f90:291
real(8) epsocc
Definition modmain.f90:900
logical tevecsv
Definition modmain.f90:920
subroutine holdthd(nloop, nthd)
Definition modomp.f90:78
subroutine freethd(nthd)
Definition modomp.f90:106
pure subroutine rmk2(n, wo, wf1, wf2, rho, mag)
Definition rhomagk.f90:198
subroutine rhomagk(ngp, igpig, wppt, occsvp, apwalm, evecfv, evecsv, rhomt_, rhoir_, magmt_, magir_)
Definition rhomagk.f90:11
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 timesec(ts)
Definition timesec.f90:10
subroutine wfmtsv(tsh, lrstp, is, ias, nst, idx, ngp, apwalm, evecfv, evecsv, ld, wfmt)
Definition wfmtsv.f90:7
subroutine zfftifc(nd, n, sgn, z)