vmatgen.f90 8.89 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
MODULE m_vmatgen
  USE m_juDFT
  !**********************************************************************
  !     This subroutine prepares the spin dependent 2x2 matrix potential
  !     for the Hamiltonian setup. This is done in 4 steps.
  !
  !    i) The spin up and down potential and the direction of the
  !     magentic field, theta and phi, are reloaded from files nrp,
  !     dirofmag.
  !    ii) The spin up and down potential is Fouriertransformed to real
  !     space (theta and phi are stored in real space).
  !    iii) The four components of the matrix potential are calculated on
  !     the real space mesh.
  !    iv) The matrix potential is Fouriertransformed, stored in terms of
  !     stars and written to file potmat.
  !
  !     Philipp Kurz 99/11/01
Alexander Neukirchen's avatar
Alexander Neukirchen committed
24
  !   
25 26 27 28 29
  !     Extended for the investigation of the exch-corr B-field, which is 
  !     analogously saved as a potden type with 3 integers (i.e. in com-
  !     ponent space.
  !     
  !     A.Neukirchen 05.09.2019
30 31
  !**********************************************************************
CONTAINS
32
  SUBROUTINE vmatgen(stars,atoms,vacuum,sym,input,den,vTot)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

    !******** ABBREVIATIONS ***********************************************
    !     ifft3    : size of the 3d real space mesh
    !     ifft2    : size of the 2d real space mesh
    !     vpw      : first interstitial spin up and down potential
    !                later four components of matrix potential
    !                all stored in terms of 3d-stars
    !     vis      : first interstitial spin up and down potential and
    !                direction of magnetic field (theta and phi)
    !                later four components of matrix potential
    !                all stored on real space mesh
    !**********************************************************************

    USE m_fft2d
    USE m_fft3d
    USE m_types
    IMPLICIT NONE
50
!    TYPE(t_oneD),INTENT(IN)   :: oneD
51 52 53 54 55
    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_atoms),INTENT(IN)  :: atoms
56
    TYPE(t_potden),INTENT(IN) :: den
57
    TYPE(t_potden),INTENT(INOUT):: vTot
58
 
59 60
    !     ..
    !     .. Local Scalars ..
61
    INTEGER imeshpt,ipot,jspin,ig2 ,ig3,ivac,ifft2,ifft3,imz,iter,i
62
    REAL    vup,vdown,veff,beff,vziw,theta,phi
63 64
    !     ..
    !     .. Local Arrays ..
65
    REAL,    ALLOCATABLE :: vvacxy(:,:,:,:),vis(:,:),fftwork(:)
66

67
    ifft3 = 27*stars%mx1*stars%mx2*stars%mx3
68 69 70 71 72
    IF (ifft3.NE.SIZE(den%theta_pw)) CALL judft_error("Wrong size of angles")
    ifft2 = SIZE(den%phi_vacxy,1) 
    
    ALLOCATE ( vis(ifft3,4),fftwork(ifft3))
    
73 74 75
    !---> fouriertransform the spin up and down potential
    !---> in the interstitial, vpw, to real space (vis)
    DO jspin = 1,input%jspins
76
       CALL fft3d(vis(:,jspin),fftwork, vTot%pw(:,jspin), stars,+1)
77 78 79 80
    ENDDO

    !---> calculate the four components of the matrix potential on
    !---> real space mesh
81
    DO imeshpt = 1,ifft3
82 83
       vup   = vis(imeshpt,1)
       vdown = vis(imeshpt,2)
84 85
       theta = den%theta_pw(imeshpt)
       phi   = den%phi_pw(imeshpt)
Alexander Neukirchen's avatar
Alexander Neukirchen committed
86
       !--->    at first determine the effective potential and magnetic fields
87 88 89 90 91
       veff  = (vup + vdown)/2.0
       beff  = (vup - vdown)/2.0
       !--->    now calculate the matrix potential, which is hermitian.
       !--->    thus calculate the diagonal elements:
       !--->    V_11
92
       vis(imeshpt,1) = veff + beff*COS(theta)
93
       !--->    V_22
94
       vis(imeshpt,2) = veff - beff*COS(theta)
95
       !--->    the real part of V_21
96
       vis(imeshpt,3) = beff*SIN(theta)*COS(phi)
97
       !--->    and the imaginary part of V_21
98
       vis(imeshpt,4) = beff*SIN(theta)*SIN(phi)
99 100 101 102

       DO ipot = 1,4
          vis(imeshpt,ipot) =  vis(imeshpt,ipot) * stars%ufft(imeshpt-1)
       ENDDO
103

104 105 106 107 108
    ENDDO

    !---> Fouriertransform the matrix potential back to reciprocal space
    DO ipot = 1,2
       fftwork=0.0
109
       CALL fft3d(vis(:,ipot),fftwork, vTot%pw_w(1,ipot), stars,-1)
110
    ENDDO
Alexander Neukirchen's avatar
Alexander Neukirchen committed
111
    
112
    CALL fft3d(vis(:,3),vis(:,4), vTot%pw_w(1,3), stars,-1)
113 114 115 116

    IF (.NOT. input%film) RETURN

    !Now the vacuum part starts
117

118
 
119
    ALLOCATE(vvacxy(ifft2,vacuum%nmzxyd,2,4))
120
    
121 122 123 124 125 126
       !--->    fouriertransform the spin up and down potential
       !--->    in the vacuum, vz & vxy, to real space (vvacxy)
       DO jspin = 1,input%jspins
          DO ivac = 1,vacuum%nvac
             DO imz = 1,vacuum%nmzxyd
                vziw = 0.0
127 128
                !IF (oneD%odi%d1) THEN
                IF (.FALSE.) THEN
129 130 131 132 133 134 135 136
                   CALL judft_error("oneD not implemented",calledby="vmatgen")
                   !                  CALL fft2d(&
                   !     &                 oneD%k3,odi%M,odi%n2d,&
                   !     &                 vvacxy(0,imz,ivac,jspin),fftwork,&
                   !     &                 vz(imz,ivac,jspin),vziw,vxy(imz,1,ivac,jspin),&
                   !     &                 vacuum,odi%nq2,odi%kimax2,1,&
                   !     &                  %igf,odl%pgf,odi%nst2)
                ELSE
137
                   CALL fft2d(stars, vvacxy(:,imz,ivac,jspin),fftwork,&
138
                        vTot%vacz(imz,ivac,jspin),vziw,vTot%vacxy(imz,1,ivac,jspin), vacuum%nmzxyd,1)
139 140 141 142 143 144 145 146 147
                ENDIF
             ENDDO
          ENDDO
       ENDDO

       !--->    calculate the four components of the matrix potential on
       !--->    real space mesh
       DO ivac = 1,vacuum%nvac
          DO imz = 1,vacuum%nmzxyd
148
             DO imeshpt = 1,ifft2
149 150
                vup   = vvacxy(imeshpt,imz,ivac,1)
                vdown = vvacxy(imeshpt,imz,ivac,2)
151 152
                theta = den%theta_vacxy(imeshpt,imz,ivac)
                phi   = den%phi_vacxy(imeshpt,imz,ivac)
153 154
                veff  = (vup + vdown)/2.0
                beff  = (vup - vdown)/2.0
155 156 157 158
                vvacxy(imeshpt,imz,ivac,1) = veff + beff*COS(theta)
                vvacxy(imeshpt,imz,ivac,2) = veff - beff*COS(theta)
                vvacxy(imeshpt,imz,ivac,3) = beff*SIN(theta)*COS(phi)
                vvacxy(imeshpt,imz,ivac,4) = beff*SIN(theta)*SIN(phi)
159 160 161
             ENDDO
          ENDDO
          DO imz = vacuum%nmzxyd+1,vacuum%nmzd
162 163
             vup   = vTot%vacz(imz,ivac,1)
             vdown = vTot%vacz(imz,ivac,2)
164 165
             theta = den%theta_vacz(imz,ivac)
             phi   = den%phi_vacz(imz,ivac)
166 167
             veff  = (vup + vdown)/2.0
             beff  = (vup - vdown)/2.0
168 169 170 171
             vTot%vacz(imz,ivac,1) = veff + beff*COS(theta)
             vTot%vacz(imz,ivac,2) = veff - beff*COS(theta)
             vTot%vacz(imz,ivac,3) = beff*SIN(theta)*COS(phi)
             vTot%vacz(imz,ivac,4) = beff*SIN(theta)*SIN(phi)
172 173 174 175 176 177 178 179
          ENDDO
       ENDDO

       !--->    Fouriertransform the matrix potential back to reciprocal space
       DO ipot = 1,2
          DO ivac = 1,vacuum%nvac
             DO imz = 1,vacuum%nmzxyd
                fftwork=0.0
180 181
                !IF (oneD%odi%d1) THEN
                IF (.FALSE.) THEN
182 183 184 185 186 187 188 189
                   CALL judft_error("oneD not implemented",calledby="vmatgen")
                   !                CALL fft2d(&
                   !     &                 oneD%k3,odi%M,odi%n2d,&
                   !     &                 vvacxy(0,imz,ivac,ipot),fftwork,&
                   !     &                 vz(imz,ivac,ipot),vziw,vxy(imz,1,ivac,ipot),&
                   !     &                 vacuum,odi%nq2,odi%kimax2,-1,&
                   !     &                  %igf,odl%pgf,odi%nst2)
                ELSE
190
                   CALL fft2d(stars, vvacxy(:,imz,ivac,ipot),fftwork,&
191
                        vTot%vacz(imz,ivac,ipot),vziw,vTot%vacxy(imz,1,ivac,ipot), vacuum%nmzxyd,-1)
192 193 194 195 196 197 198 199
                END IF
             ENDDO
          ENDDO
       ENDDO

       DO ivac = 1,vacuum%nvac
          DO imz = 1,vacuum%nmzxyd
             fftwork=0.0
200 201 202
             !IF (oneD%odi%d1) THEN
             IF (.FALSE.) THEN
             CALL judft_error("oneD not implemented",calledby="vmatgen")
203 204 205 206 207 208 209
                !              CALL fft2d(&
                !   &              oneD%k3,odi%M,odi%n2d,&
                !   &              vvacxy(0,imz,ivac,3),vvacxy(0,imz,ivac,4),&
                !   &              vz(imz,ivac,3),vz(imz,ivac,4),vxy(imz,1,ivac,3),&
                !   &              vacuum,odi%nq2,odi%kimax2,-1,&
                !   &               %igf,odl%pgf,odi%nst2)
             ELSE
210
                CALL fft2d(stars, vvacxy(:,imz,ivac,3),vvacxy(:,imz,ivac,4),&
211
                     vTot%vacz(imz,ivac,3),vTot%vacz(imz,ivac,4),vTot%vacxy(imz,1,ivac,3), vacuum%nmzxyd,-1)
212 213 214 215 216 217 218
             END IF
          ENDDO
       ENDDO

    RETURN
  END SUBROUTINE vmatgen
END MODULE m_vmatgen