rhodirgen.f90 11.7 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
MODULE m_rhodirgen
  USE m_juDFT
  !**********************************************************************
  !     This subroutine calculates the spin-up and -down density, which
  !     are needed to calculate the potential and writes them to the file
  !     cdn. The local angle of the magnetization is kept in real space
  !     and written to the file dirofmag. This is done in four steps.
  !
  !    i) The components of the hermitian density matrix (rho_11, rho_22,
  !     rho_21) are reloaded from the file rhomat_inp.
  !    ii) The density matrix in fouriertransformed to real space.
  !    iii) The spin-up and -down densities and the local angle of the
  !     magnetization are calculated on the real space mesh.    
  !    iv) The spin-up and -down densities are Fouriertransformed, stored
  !     in terms of stars and written to the file cdn. The local angle of
  !     magnetization is kept on the real space mesh and written to the
  !     file dirofmag.
  !
  !     Philipp Kurz 99/11/01
  !**********************************************************************
CONTAINS
28
  SUBROUTINE rhodirgen(DIMENSION,sym,stars,atoms,sphhar,vacuum,&
29
       cell,input,noco,oneD,den)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

    !******** ABBREVIATIONS ***********************************************
    !     ifft3    : size of the 3d real space mesh
    !     ifft2    : size of the 2d real space mesh
    !     rpw      : diagonal components of the density matrix (rho_11 ,
    !                rho_22)
    !                later interstitial spin-up and -down density
    !                all stored in terms of 3d-stars
    !     ris      : first components of the density matrix
    !                later interstitial spin-up and -down density and
    !                direction of magnetic field (theta and phi)
    !                all stored on real space mesh
    !**********************************************************************

    USE m_constants
    USE m_fft2d
    USE m_fft3d
    USE m_types
    IMPLICIT NONE

    TYPE(t_dimension),INTENT(IN)   :: DIMENSION
51
    TYPE(t_noco),INTENT(IN)        :: noco
52 53 54 55 56 57 58 59
    TYPE(t_oneD),INTENT(IN)        :: oneD
    TYPE(t_input),INTENT(IN)       :: input
    TYPE(t_vacuum),INTENT(IN)      :: vacuum
    TYPE(t_sym),INTENT(IN)         :: sym
    TYPE(t_stars),INTENT(IN)       :: stars
    TYPE(t_cell),INTENT(IN)        :: cell
    TYPE(t_sphhar),INTENT(IN)      :: sphhar
    TYPE(t_atoms),INTENT(IN)       :: atoms
60
    TYPE(t_potden),INTENT(INOUT)   :: den
61

62 63
    !     .. Local Scalars ..
    INTEGER iden,jspin,ivac,ifft2,ifft3
64
    INTEGER imz,ityp,iri,ilh,imesh,iq2,iq3
65 66
    REAL   rho_11,rho_22,rho_21r,rho_21i,rhotot,magmom,phi
    REAL rho_up,rho_down,mx,my,mz,eps,vz_r,vz_i,rziw,theta
67 68
    !     ..
    !     .. Local Arrays ..
69
    REAL,    ALLOCATABLE :: rz(:,:,:)
70 71 72
    REAL,    ALLOCATABLE :: rvacxy(:,:,:,:),ris(:,:),fftwork(:)
    !     ..
    eps = 1.0e-20
73

74 75


76 77 78 79
    !
    !---> initialize arrays for the density matrix
    !

80
    ifft3 = 27*stars%mx1*stars%mx2*stars%mx3
81 82 83 84 85 86
    IF (input%film) THEN
       ifft2 = 9*stars%mx1*stars%mx2
       IF (oneD%odi%d1) ifft2 = 9*stars%mx3*oneD%odi%M
    ELSE
       ifft2=0
    END IF
87

88 89 90
    IF (ALLOCATED(den%phi_pw)) THEN
       DEALLOCATE(den%phi_pw,den%phi_vacz,den%phi_vacxy)
       DEALLOCATE(den%theta_pw,den%theta_vacz,den%theta_vacxy)
91
    ENDIF
92 93 94
    ALLOCATE(den%phi_pw(ifft3),den%theta_pw(ifft3))
    ALLOCATE(den%phi_vacz(vacuum%nmzd,2),den%theta_vacz(vacuum%nmzd,2))
    ALLOCATE(den%phi_vacxy(ifft2,vacuum%nmzxyd,2),den%theta_vacxy(ifft2,vacuum%nmzxyd,2))
95

96 97
     
    ALLOCATE (ris(ifft3,4),fftwork(ifft3))
98
    !---> fouriertransform the diagonal part of the density matrix
99
    !---> in the interstitial, den%pw, to real space (ris)
100
    DO iden = 1,2
101
       CALL fft3d(ris(:,iden),fftwork,den%pw(:,iden),stars,+1)
102 103
    ENDDO
    !---> fouriertransform the off-diagonal part of the density matrix
Gregor Michalicek's avatar
Gregor Michalicek committed
104
    CALL fft3d(ris(:,3),ris(:,4),den%pw(:,3),stars,+1)
105 106 107 108 109 110 111 112 113

    !test
    !      DO iden=1,4
    !         write(*,*)'iden=',iden
    !         write(*,8500)(ris(imesh,iden),imesh=0,ifft3-1)
    !      enddo
    !test
    !---> calculate the charge and magnetization density on the
    !---> real space mesh
114
    DO imesh = 1,ifft3
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
       rho_11  = ris(imesh,1)
       rho_22  = ris(imesh,2)
       rho_21r = ris(imesh,3)
       rho_21i = ris(imesh,4)
       mx      =  2*rho_21r
       my      = -2*rho_21i
       mz      = (rho_11-rho_22)
       magmom  = SQRT(mx**2 + my**2 + mz**2)
       rhotot  = rho_11 + rho_22
       rho_up  = (rhotot + magmom)/2
       rho_down= (rhotot - magmom)/2

       IF (ABS(mz) .LE. eps) THEN
          theta = pi_const/2
       ELSEIF (mz .GE. 0.0) THEN
          theta = ATAN(SQRT(mx**2 + my**2)/mz)
       ELSE
          theta = ATAN(SQRT(mx**2 + my**2)/mz) + pi_const
       ENDIF

       IF (ABS(mx) .LE. eps) THEN
          IF (ABS(my) .LE. eps) THEN
             phi = 0.0
          ELSEIF (my .GE. 0.0) THEN
             phi = pi_const/2
          ELSE
             phi = -pi_const/2
          ENDIF
       ELSEIF (mx .GE. 0.0) THEN
          phi = ATAN(my/mx)
       ELSE
          IF (my .GE. 0.0) THEN
             phi = ATAN(my/mx) + pi_const
          ELSE
             phi = ATAN(my/mx) - pi_const
          ENDIF
       ENDIF

       !         write(36,'(i4,2f12.6)') mod(imesh,33),rho_11,rho_22
       ris(imesh,1) = rho_up
       ris(imesh,2) = rho_down
156 157
       den%theta_pw(imesh) = theta
       den%phi_pw(imesh) = phi
158
    ENDDO
159

160 161
    DO jspin = 1,input%jspins
       fftwork=0.0
162
       CALL fft3d(ris(:,jspin),fftwork,den%pw(:,jspin),stars,-1)
163 164
    ENDDO

165 166 167 168 169 170 171 172
    IF (.NOT.input%film) RETURN


     !Now the vacuum part starts

   
    ALLOCATE(rvacxy(ifft2,vacuum%nmzxyd,2,4))
    ALLOCATE (rz(vacuum%nmzd,2,2))
173 174
    !---> fouriertransform the diagonal part of the density matrix
    !---> in the vacuum, rz & rxy, to real space (rvacxy)
175
    DO iden = 1,2
176 177 178 179
       DO ivac = 1,vacuum%nvac
          DO imz = 1,vacuum%nmzxyd
             rziw = 0.0
             IF (oneD%odi%d1) THEN
180 181 182
                CALL judft_error("oneD not implemented",calledby="rhodirgen")
                !CALL fft2d(oneD%k3,odi%M,odi%n2d,rvacxy(0,imz,ivac,iden),fftwork,&
                !           den%vacz(imz,ivac,iden),rziw,den%vacxy(imz,1,ivac,iden),&
183
                !           vacuum,odi%nq2,odi%kimax2,1,&
184
                !     &                  %igf,odl%pgf,odi%nst2)
185
             ELSE
186 187 188
                CALL fft2d(stars,rvacxy(:,imz,ivac,iden),fftwork,&
                     den%vacz(imz,ivac,iden),rziw,den%vacxy(imz,1,ivac,iden),&
                     vacuum%nmzxyd,1)
189 190 191
             ENDIF
          ENDDO
       ENDDO
192 193 194 195 196
    ENDDO
    !--->    fouriertransform the off-diagonal part of the density matrix
    DO ivac = 1,vacuum%nvac
       DO imz = 1,vacuum%nmzxyd
          rziw = 0.0
Gregor Michalicek's avatar
Gregor Michalicek committed
197 198
          vz_r = den%vacz(imz,ivac,3)
          vz_i = den%vacz(imz,ivac,4)
199 200 201 202
          IF (oneD%odi%d1) THEN
             CALL judft_error("oneD not implemented",calledby="rhodirgen")
             !CALL fft2d(oneD%k3,odi%M,odi%n2d,&
             !           rvacxy(0,imz,ivac,3),rvacxy(0,imz,ivac,4),&
Gregor Michalicek's avatar
Gregor Michalicek committed
203
             !           vz_r,vz_i,den%vacxy(imz,1,ivac,3),&
204 205 206 207
             !           vacuum,odi%nq2,odi%kimax2,1,&
             !     &               %igf,odl%pgf,odi%nst2)
          ELSE
             CALL fft2d(stars,rvacxy(:,imz,ivac,3),rvacxy(:,imz,ivac,4),&
Gregor Michalicek's avatar
Gregor Michalicek committed
208
                  vz_r,vz_i,den%vacxy(imz,1,ivac,3),vacuum%nmzxyd,1)
209 210 211
          ENDIF
       ENDDO
    ENDDO
212

213 214 215 216 217 218 219 220 221
    !--->    calculate the four components of the matrix potential on
    !--->    real space mesh
    DO ivac = 1,vacuum%nvac
       DO imz = 1,vacuum%nmzxyd
          DO imesh = 1,ifft2
             rho_11  = rvacxy(imesh,imz,ivac,1)
             rho_22  = rvacxy(imesh,imz,ivac,2)
             rho_21r = rvacxy(imesh,imz,ivac,3)
             rho_21i = rvacxy(imesh,imz,ivac,4)
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
             mx      =  2*rho_21r
             my      = -2*rho_21i
             mz      = (rho_11-rho_22)
             magmom  = SQRT(mx**2 + my**2 + mz**2)
             rhotot  = rho_11 + rho_22
             rho_up  = (rhotot + magmom)/2
             rho_down= (rhotot - magmom)/2

             IF (ABS(mz) .LE. eps) THEN
                theta = pi_const/2
             ELSEIF (mz .GE. 0.0) THEN
                theta = ATAN(SQRT(mx**2 + my**2)/mz)
             ELSE
                theta = ATAN(SQRT(mx**2 + my**2)/mz) + pi_const
             ENDIF

             IF (ABS(mx) .LE. eps) THEN
                IF (ABS(my) .LE. eps) THEN
                   phi = 0.0
                ELSEIF (my .GE. 0.0) THEN
                   phi = pi_const/2
                ELSE
                   phi = -pi_const/2
                ENDIF
             ELSEIF (mx .GE. 0.0) THEN
                phi = ATAN(my/mx)
             ELSE
                IF (my .GE. 0.0) THEN
                   phi = ATAN(my/mx) + pi_const
                ELSE
                   phi = ATAN(my/mx) - pi_const
                ENDIF
             ENDIF

256 257 258 259
             rvacxy(imesh,imz,ivac,1) = rho_up
             rvacxy(imesh,imz,ivac,2) = rho_down
             den%theta_vacxy(imesh,imz,ivac) = theta
             den%phi_vacxy(imesh,imz,ivac) = phi
260 261
          ENDDO
       ENDDO
262 263 264
       DO imz = vacuum%nmzxyd+1,vacuum%nmzd
          rho_11  = den%vacz(imz,ivac,1)
          rho_22  = den%vacz(imz,ivac,2)
Gregor Michalicek's avatar
Gregor Michalicek committed
265 266
          rho_21r = den%vacz(imz,ivac,3)
          rho_21i = den%vacz(imz,ivac,4)
267 268 269 270 271 272 273
          mx      =  2*rho_21r
          my      = -2*rho_21i
          mz      = (rho_11-rho_22)
          magmom  = SQRT(mx**2 + my**2 + mz**2)
          rhotot  = rho_11 + rho_22
          rho_up  = (rhotot + magmom)/2
          rho_down= (rhotot - magmom)/2
274

275 276 277 278 279 280 281
          IF (ABS(mz) .LE. eps) THEN
             theta = pi_const/2
          ELSEIF (mz .GE. 0.0) THEN
             theta = ATAN(SQRT(mx**2 + my**2)/mz)
          ELSE
             theta = ATAN(SQRT(mx**2 + my**2)/mz) + pi_const
          ENDIF
282

283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
          IF (ABS(mx) .LE. eps) THEN
             IF (ABS(my) .LE. eps) THEN
                phi = 0.0
             ELSEIF (my .GE. 0.0) THEN
                phi = pi_const/2
             ELSE
                phi = -pi_const/2
             ENDIF
          ELSEIF (mx .GE. 0.0) THEN
             phi = ATAN(my/mx)
          ELSE
             IF (my .GE. 0.0) THEN
                phi = ATAN(my/mx) + pi_const
             ELSE
                phi = ATAN(my/mx) - pi_const
             ENDIF
          ENDIF
300

301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
          den%vacz(imz,ivac,1) = rho_up
          den%vacz(imz,ivac,2) = rho_down
          den%theta_vacz(imz,ivac) = theta
          den%phi_vacz(imz,ivac) = phi
       ENDDO
    ENDDO
    !--->    Fouriertransform the matrix potential back to reciprocal space
    DO jspin = 1,input%jspins
       DO ivac = 1,vacuum%nvac
          DO imz = 1,vacuum%nmzxyd
             fftwork=0.0
             IF (oneD%odi%d1) THEN
                call judft_error("oneD not implemented",calledby="rhodirgen")
                !CALL fft2d(oneD%k3,odi%M,odi%n2d,&
                !           rvacxy(0,imz,ivac,jspin),fftwork,&
                !           den%vacz(imz,ivac,jspin),rziw,den%vacxy(imz,1,ivac,jspin),&
                !           vacuum,odi%nq2,odi%kimax2,-1,&
                !     &                  %igf,odl%pgf,odi%nst2)
             ELSE
                CALL fft2d(stars,rvacxy(:,imz,ivac,jspin),fftwork,&
                     den%vacz(imz,ivac,jspin),rziw,den%vacxy(imz,1,ivac,jspin),&
                     vacuum%nmzxyd,-1)
             END IF
          ENDDO
       ENDDO
    ENDDO
    
328 329 330
    RETURN
  END SUBROUTINE rhodirgen
END MODULE m_rhodirgen