flipcdn.f90 8.1 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
      MODULE m_flipcdn
!     *******************************************************
!     this subroutine reads the charge density and flips the 
!     magnetic moment within the m.t.sphere for each atom 
!     according to the variable nflip. This variable is read in
!     the main program
!             nflip = -1 : flip spin in sphere
!             nflip = -2 : scale spin by bmu(n)
!             nflip = any: no spin flip
!                            r.pentcheva,kfa,Feb'96
!     *******************************************************
      CONTAINS
        SUBROUTINE flipcdn(&
             &                   atoms,input,vacuum,sphhar,&
21
             &                   stars,sym,oneD,cell,&
22
             &                   l_noco)
23
          USE m_cdn_io
24 25 26 27 28 29 30 31
          USE m_types
          IMPLICIT NONE
          TYPE(t_stars),INTENT(IN)  :: stars
          TYPE(t_vacuum),INTENT(IN) :: vacuum
          TYPE(t_atoms),INTENT(IN)  :: atoms
          TYPE(t_sphhar),INTENT(IN) :: sphhar
          TYPE(t_input),INTENT(IN)  :: input
          TYPE(t_sym),INTENT(IN)    :: sym
32
          TYPE(t_oneD),INTENT(IN)     :: oneD
33 34 35 36
          TYPE(t_cell),INTENT(IN)   :: cell
          LOGICAL,INTENT(IN)        :: l_noco

          !     .. Local Scalars ..
37
          REAL    rhodummy,rhodumms,fermiEnergyTemp
38
          INTEGER i,iter,n,nt,j,lh,na ,mp,ispin,n_ldau,urec,itype,m
39
          INTEGER archiveType
40 41
            
          CHARACTER(len=8) iop,dop
42
          LOGICAL n_exist,l_qfix
43 44 45 46 47 48 49 50 51 52 53 54
          !     ..
          !     .. Local Arrays ..
          COMPLEX, ALLOCATABLE :: n_mmp(:,:,:,:),qpw(:,:),rhtxy(:,:,:,:)
          REAL   , ALLOCATABLE :: rho(:,:,:,:),rht(:,:,:)
          COMPLEX, ALLOCATABLE :: cdom(:),cdomvz(:,:),cdomvxy(:,:,:)
          CHARACTER(len=80), ALLOCATABLE :: clines(:)
          CHARACTER(len=8) name(10)
          !     ..
          !atoms%jmtd = MAXVAL(atoms%jri(:))
          !sphhar%nlhd = MAXVAL(sphhar%nlh(:))
          ALLOCATE ( rho(atoms%jmtd,0:sphhar%nlhd,atoms%ntype,input%jspins),qpw(stars%ng3,input%jspins) )
          ALLOCATE ( rhtxy(vacuum%nmzxy,stars%ng2-1,2,input%jspins),rht(vacuum%nmz,2,input%jspins) )
55
          archiveType = CDN_ARCHIVE_TYPE_CDN1_const
56 57 58
          IF (l_noco) THEN
             ALLOCATE( cdom(stars%ng3) )
             ALLOCATE( cdomvz(vacuum%nmz,2),cdomvxy(vacuum%nmzxy,stars%ng2-1,2) )
59
             archiveType = CDN_ARCHIVE_TYPE_NOCO_const
60 61 62
          ENDIF

          !     ---> read the charge density 
63
          CALL readDensity(stars,vacuum,atoms,cell,sphhar,input,sym,oneD,archiveType,&
64
                     CDN_INPUT_DEN_const,0,fermiEnergyTemp,l_qfix,iter,rho,qpw,rht,rhtxy,cdom,cdomvz,cdomvxy)
65

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
          !     ---> flip cdn for each atom with nflip=-1
          !
          na = 1
          DO n = 1, atoms%ntype
             IF (atoms%nflip(n).EQ.-1) THEN
                !     ---> spherical and non-spherical m.t. charge density
                DO lh = 0,sphhar%nlh(atoms%ntypsy(na))
                   DO j = 1,atoms%jri(n)
                      rhodummy = rho(j,lh,n,1)
                      rho(j,lh,n,1) = rho(j,lh,n,input%jspins)
                      rho(j,lh,n,input%jspins) = rhodummy
                   ENDDO
                ENDDO
             ELSEIF (atoms%nflip(n).EQ.-2) THEN
                DO lh = 0,sphhar%nlh(atoms%ntypsy(na))
                   DO j = 1,atoms%jri(n)
                      rhodummy = rho(j,lh,n,1) + rho(j,lh,n,input%jspins)
                      rhodumms = rho(j,lh,n,1) - rho(j,lh,n,input%jspins)
                      rho(j,lh,n,1) = 0.5 * ( rhodummy + atoms%bmu(n) * rhodumms )
                      rho(j,lh,n,input%jspins) = 0.5*(rhodummy - atoms%bmu(n)*rhodumms )
                   ENDDO
                ENDDO
             END IF
             na = na + atoms%neq(n)
          ENDDO
91
          !     ----> write the spin-polarized density
92
          CALL writeDensity(stars,vacuum,atoms,cell,sphhar,input,sym,oneD,archiveType,CDN_INPUT_DEN_const,&
93
                            0,-1.0,0.0,.FALSE.,iter,rho,qpw,rht,rhtxy,cdom,cdomvz,cdomvxy)
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
          !
          ! for lda+U: flip n-matrix 
          !
          IF (atoms%n_u.GT.0) THEN
             INQUIRE (file='n_mmp_mat',exist=n_exist)
             IF (n_exist) THEN
                OPEN (69,file='n_mmp_mat',status='old',form='formatted')
                ALLOCATE (  n_mmp(-3:3,-3:3,atoms%n_u,2) )

                READ (69,9000) n_mmp
                !   flip    ...
                n_ldau = 0
                DO n = 1,atoms%ntype
                   IF (atoms%lda_u(n)%l.GE.0) THEN
                      n_ldau = n_ldau + 1
                      IF (atoms%nflip(n).EQ.-1) THEN
                         DO m = -3,3
                            DO mp = -3,3
                               rhodummy = n_mmp(m,mp,n_ldau,1)
                               n_mmp(m,mp,n_ldau,1) = n_mmp(m,mp,n_ldau,input%jspins)
                               n_mmp(m,mp,n_ldau,input%jspins) = rhodummy
                            ENDDO
                         ENDDO
                      ELSEIF (atoms%nflip(n).EQ.-2) THEN
                         DO m = -3,3
                            DO mp = -3,3
                               rhodummy = n_mmp(m,mp,n_ldau,1) + &
                                    &                           n_mmp(m,mp,n_ldau,input%jspins)
                               rhodumms = n_mmp(m,mp,n_ldau,1) - &
                                    &                           n_mmp(m,mp,n_ldau,input%jspins)
                               n_mmp(m,mp,n_ldau,1) = 0.5 * ( rhodummy + &
                                    &                                      atoms%bmu(n) * rhodumms )
                               n_mmp(m,mp,n_ldau,input%jspins) = 0.5*( rhodummy - &
                                    &                                         atoms%bmu(n) * rhodumms )
                            ENDDO
                         ENDDO
                      ENDIF
                   ENDIF
                ENDDO
                !   flip    ...
                REWIND (69)
                WRITE (69,9000) n_mmp
9000            FORMAT(7f20.13)
                !
                DEALLOCATE ( n_mmp )
             ENDIF
          ENDIF
          !-lda+U
          !
          !--->   read enpara and  flip lines
          !
          INQUIRE(file='enpara',exist=n_exist)
          IF (n_exist) THEN
             OPEN(40,file ='enpara',status='old',form='formatted')

             n = 2
             DO itype = 1 , atoms%ntype
                n         = n + 1
                IF (atoms%nlo(itype)>0) n = n + 2
             ENDDO
             IF (input%film) n = n + 1
             ALLOCATE (clines(2*n))
             DO i = 1,2*n
                READ (40,'(a)') clines(i)
             ENDDO

             REWIND 40
             i = 0 
             DO ispin = 1,input%jspins
                i         = i + 2
                WRITE (40,'(a)') TRIM(clines(i-1))
                WRITE (40,'(a)') TRIM(clines(i))
                DO itype = 1 , atoms%ntype
                   i          = i + 1
                   m               = i
                   IF (atoms%nflip(itype)==-1) m = MOD(i+n,2*n)
                   IF (m==0) m        = 2*n
                   WRITE (40,'(a)') TRIM(clines(m))
                   IF (atoms%nlo(itype)>0) THEN
                      WRITE (40,'(a)') TRIM(clines(m+1))
                      WRITE (40,'(a)') TRIM(clines(m+2))
                      i = i + 2
                   ENDIF
                ENDDO
                IF (input%film) THEN
                   i = i + 1
                   WRITE (40,'(a)') TRIM(clines(i))
                ENDIF
             ENDDO

             DEALLOCATE (clines,rho,qpw,rhtxy,rht)
             IF (l_noco) THEN
                DEALLOCATE (cdom,cdomvz,cdomvxy)
             ENDIF
             CLOSE(40)
          ENDIF
        END SUBROUTINE flipcdn
      END MODULE m_flipcdn