pwint.f90 7.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
      MODULE m_pwint
!     ******************************************************************
!     calculate the integral of a star function over the interstial    *
!     region              c.l.fu                                       *
!     ******************************************************************
      CONTAINS
      SUBROUTINE pwint(&
     &                 stars,atoms,sym,oneD,&
     &                 cell,ng,&
     &                 x)

      USE m_spgrot
      USE m_od_cylbes
      use m_juDFT
      USE m_types 
      USE m_constants
      IMPLICIT NONE
!     ..
!     .. Scalar Arguments ..
      TYPE(t_stars),INTENT(IN) :: stars
      TYPE(t_atoms),INTENT(IN) :: atoms
      TYPE(t_sym),INTENT(IN)   :: sym
      TYPE(t_oneD),INTENT(IN)  :: oneD
      TYPE(t_cell),INTENT(IN)  :: cell
      INTEGER,INTENT(IN)       :: ng
      COMPLEX, INTENT (OUT):: x
!     ..
!     .. Array Arguments ..
!-odim
!+odim
!     ..
!     .. Local Scalars ..
      COMPLEX s1,sfs
      REAL arg,g,s,srmt,gr,fJ
      INTEGER ig2d,ig3d,n,nn,na,ii
!     ..
!     .. Local Arrays ..
      COMPLEX ph(sym%nop)
      INTEGER kr(3,sym%nop)
!     ..
!     .. Intrinsic Functions ..
      INTRINSIC cmplx,cos,exp,sin
!     ..
      ig3d = stars%ig(stars%kv3(1,ng),stars%kv3(2,ng),stars%kv3(3,ng))
      IF (ig3d.EQ.0) THEN
         x = (0.,0.)
         RETURN
      END IF
      IF (ig3d.EQ.1) THEN
         x = cmplx(cell%volint,0.0)
         RETURN
      ELSE

         IF (oneD%odi%d1) THEN
            IF (stars%kv3(3,ng).EQ.0) THEN
               g = (stars%kv3(1,ng)*cell%bmat(1,1) + stars%kv3(2,ng)*cell%bmat(2,1))**2 +&
     &             (stars%kv3(1,ng)*cell%bmat(1,2) + stars%kv3(2,ng)*cell%bmat(2,2))**2
               gr = sqrt(g)
               g  = gr*cell%z1
               CALL od_cylbes(1,g,fJ)
               x = cmplx(2*cell%vol*fJ/g,0.0)
            ELSE
               x = (0.0,0.0)
            END IF
          ELSE
             ig2d = stars%ig2(ig3d)
             IF (ig2d.EQ.1) THEN
                g = stars%kv3(3,ng)*cell%bmat(3,3)*cell%z1
                x = cmplx(cell%vol*sin(g)/g,0.0)
             ELSE
                x = (0.0,0.0)
             END IF
          END IF

      END IF
!     -----> sphere contributions
      s = stars%sk3(ig3d)
      na = 1

      IF (.NOT.oneD%odi%d1) THEN
         CALL spgrot(&
     &           sym%nop,sym%symor,sym%mrot,sym%tau,sym%invtab,&
     &           stars%kv3,&
     &           kr,ph)
          DO  n = 1,atoms%ntype
            srmt = s*atoms%rmt(n)
            sfs = (0.0,0.0)
            DO  nn = 1,sym%nop
89 90
               arg = tpi_const * dot_product(real(kr(:,nn)),atoms%taual(:,na))
               sfs = sfs + cmplx(cos(arg),sin(arg))*ph(nn)
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
            ENDDO
            sfs = sfs/sym%nop
!     -----3*ji(gr)/gr term
            s1 = 3.* (sin(srmt)/srmt-cos(srmt))/ (srmt*srmt)
            x = x - atoms%volmts(n)*atoms%neq(n)*s1*sfs
            na = na + atoms%neq(n)
         ENDDO
      ELSE
!-odim
         DO 21 n = 1,atoms%ntype
            DO ii = 1,atoms%neq(n)
               srmt = s*atoms%rmt(n)
               CALL spgrot(&
     &              sym%nop,sym%symor,sym%mrot,sym%tau,sym%invtab,&
     &              stars%kv3,&
     &              kr,ph)
               sfs = (0.0,0.0)
108 109 110 111
               DO nn = 1,sym%nop
                 arg = tpi_const * dot_product(real(kr(:,nn)),atoms%taual(:,na))
                 sfs = sfs + cmplx(cos(arg),sin(arg))*ph(nn)
               ENDDO
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 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
               sfs = sfs/sym%nop
!     -----3*ji(gr)/gr term
               s1 = 3.* (sin(srmt)/srmt-cos(srmt))/ (srmt*srmt)
               x = x - atoms%volmts(n)*s1*sfs
               na = na + 1
            END DO
 21      CONTINUE
!+odim
      ENDIF

      END SUBROUTINE pwint
      SUBROUTINE pwint_all(&
     &                 stars,atoms,sym,oneD,&
     &                 cell,&
     &                 x)

      USE m_spgrot
      USE m_od_cylbes
      use m_juDFT
      USE m_types 
      USE m_constants
      IMPLICIT NONE
!     ..

      TYPE(t_stars),INTENT(IN) :: stars
      TYPE(t_atoms),INTENT(IN) :: atoms
      TYPE(t_sym),INTENT(IN)   :: sym
      TYPE(t_oneD),INTENT(IN)  :: oneD
      TYPE(t_cell),INTENT(IN)  :: cell
      COMPLEX, INTENT (OUT):: x(:)
!     ..
!-odim
!+odim
!     ..
!     .. Local Scalars ..
      COMPLEX s1,sfs
      REAL arg,g,s,srmt,gr,fJ
      INTEGER ig2d,ig3d,n,nn,na,ii,ng
!     ..
!     .. Local Arrays ..
      COMPLEX ph(sym%nop)
      INTEGER kr(3,sym%nop)
!     ..
!     .. Intrinsic Functions ..
      INTRINSIC cmplx,cos,exp,sin
!     ..
      
!$OMP PARALLEL DO default(shared)  &
!$OMP PRIVATE(ng,ig3d,g,gr,fj,ig2d,s,na,kr,ph,n)&
!$OMP PRIVATE(srmt,nn,sfs,arg,s1,ii)
      starloop:DO ng=1,size(x)
      ig3d = stars%ig(stars%kv3(1,ng),stars%kv3(2,ng),stars%kv3(3,ng))
      IF (ig3d.EQ.0) THEN
         x(ng) = (0.,0.)
         cycle starloop
      END IF

      IF (ig3d.EQ.1) THEN
         x(ng) = cmplx(cell%volint,0.0)
         cycle starloop
      ELSE

         IF (oneD%odi%d1) THEN
            IF (stars%kv3(3,ng).EQ.0) THEN
               g = (stars%kv3(1,ng)*cell%bmat(1,1) + stars%kv3(2,ng)*cell%bmat(2,1))**2 +&
     &             (stars%kv3(1,ng)*cell%bmat(1,2) + stars%kv3(2,ng)*cell%bmat(2,2))**2
               gr = sqrt(g)
               g  = gr*cell%z1
               CALL od_cylbes(1,g,fJ)
               x(ng) = cmplx(2*cell%vol*fJ/g,0.0)
            ELSE
               x(ng) = (0.0,0.0)
            END IF
          ELSE
             ig2d = stars%ig2(ig3d)
             IF (ig2d.EQ.1) THEN
                g = stars%kv3(3,ng)*cell%bmat(3,3)*cell%z1
                x(ng) = cmplx(cell%vol*sin(g)/g,0.0)
             ELSE
                x(ng) = (0.0,0.0)
             END IF
          END IF

      END IF
!     -----> sphere contributions
      s = stars%sk3(ig3d)
      na = 1

      IF (.NOT.oneD%odi%d1) THEN
         CALL spgrot(&
     &           sym%nop,sym%symor,sym%mrot,sym%tau,sym%invtab,&
     &           stars%kv3(:,ng),&
     &           kr,ph)
          DO  n = 1,atoms%ntype
            srmt = s*atoms%rmt(n)
            sfs = (0.0,0.0)
            DO  nn = 1,sym%nop
             arg = tpi_const* (kr(1,nn)*atoms%taual(1,na)+kr(2,nn)*atoms%taual(2,na)+&
     &              kr(3,nn)*atoms%taual(3,na))
               sfs = sfs + exp(cmplx(0.0,arg))*ph(nn)
            ENDDO
            sfs = sfs/sym%nop
!     -----3*ji(gr)/gr term
            s1 = 3.* (sin(srmt)/srmt-cos(srmt))/ (srmt*srmt)
            x(ng) = x(ng) - atoms%volmts(n)*atoms%neq(n)*s1*sfs
            na = na + atoms%neq(n)
         ENDDO
      ELSE
!-odim
         DO 21 n = 1,atoms%ntype
            DO ii = 1,atoms%neq(n)
               srmt = s*atoms%rmt(n)
               CALL spgrot(&
     &              sym%nop,sym%symor,sym%mrot,sym%tau,sym%invtab,&
     &              stars%kv3(:,ng),&
     &              kr,ph)
               sfs = (0.0,0.0)
               DO 11 nn = 1,sym%nop
                  arg = tpi_const* (kr(1,nn)*atoms%taual(1,na)+&
     &                 kr(2,nn)*atoms%taual(2,na)+&
     &                 kr(3,nn)*atoms%taual(3,na))
                  sfs = sfs + exp(cmplx(0.0,arg))*ph(nn)
 11            CONTINUE
               sfs = sfs/sym%nop
!     -----3*ji(gr)/gr term
               s1 = 3.* (sin(srmt)/srmt-cos(srmt))/ (srmt*srmt)
               x(ng) = x(ng) - atoms%volmts(n)*s1*sfs
               na = na + 1
            END DO
 21      CONTINUE
!+odim
      ENDIF
      ENDDO starloop
!$OMP end parallel do

      END SUBROUTINE pwint_all
      END MODULE m_pwint