hlomat.F90 21.6 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
MODULE m_hlomat
!***********************************************************************
! updates the hamiltonian  matrix with the contributions from the local
! orbitals.
! p.kurz sept. 1996
!***********************************************************************
CONTAINS
14
  SUBROUTINE hlomat(input,atoms,usp,tsp,&
15 16 17 18 19 20
       n_size,n_rank, ntyp,na,lapw,ar,br,ai,bi, el,alo,blo,clo,ud,&
       noco,iintsp,jintsp,chi11,chi22,chi21, iilo,locol,nkvecprevat,tlmplm,aa)
#include"cpp_double.h"
    !
    USE m_types
    IMPLICIT NONE
21
    TYPE(t_input),INTENT(IN)  :: input
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
    TYPE(t_noco),INTENT(IN)   :: noco
    TYPE(t_atoms),INTENT(IN)  :: atoms
    TYPE(t_lapw),INTENT(IN)   :: lapw
    !     ..
    !     .. Scalar Arguments ..
    INTEGER, INTENT (IN) :: n_size,n_rank
    INTEGER, INTENT (IN) :: na,ntyp  
    INTEGER, INTENT (IN) :: usp,tsp !spin for usdus and tlmplm
    INTEGER, INTENT (IN) :: iintsp,jintsp
    COMPLEX, INTENT (IN) :: chi11,chi22,chi21
    INTEGER, INTENT (INOUT) :: iilo,nkvecprevat,locol
    !     ..
    !     .. Array Arguments ..
    COMPLEX, INTENT (IN) :: alo(-atoms%llod:,:,:,:)
    COMPLEX, INTENT (IN) :: blo(-atoms%llod:,:,:,:)
    COMPLEX, INTENT (IN) :: clo(-atoms%llod:,:,:,:)
    REAL,    INTENT (IN) :: ar(:,0:),br(:,0:) !(nvd,0:lmd)
    REAL,    INTENT (IN) :: ai(:,0:),bi(:,0:)
    REAL,    INTENT (IN) :: el(0:)!(0:atoms%lmax)
    TYPE(t_usdus),INTENT(IN)     ::ud
    TYPE(t_tlmplm),INTENT(INOUT) :: tlmplm
#ifdef CPP_INVERSION
    REAL,    INTENT (INOUT) :: aa(:)!(matsize)
#else
    COMPLEX, INTENT (INOUT) :: aa(:)
#endif
    !     ..
    !     .. Local Scalars ..
    COMPLEX axx,bxx,cxx,dtd,dtu,dtulo,ulotd,ulotu,ulotulo,utd,utu, utulo,chihlp
    INTEGER im,in,invsfct ,l,lm,lmp,lo,lolo,lolop,lop,lp ,matel0 
    INTEGER locol0,mp,nkvec,nkvecp,nkvecprevlo,lmplm , loplo,kp,m
    INTEGER iilo_s,locol_s,nkvecprevat_s,ic,ii,ij,n,k,mlo,mlolo
    !     ..
    !     .. Local Arrays ..
56
    COMPLEX ax(SIZE(ar,1)),bx(SIZE(ar,1)),cx(SIZE(ar,1))
57
    COMPLEX, ALLOCATABLE :: ahelp(:)
58
    INTEGER indt(0:SIZE(ar,2)-1)
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 89 90 91 92 93
    !     .. External Subroutines ..
    EXTERNAL CPP_BLAS_caxpy
    !     ..

    mlo=0;mlolo=0
    DO m=1,ntyp-1
       mlo=mlo+atoms%nlo(m)
       mlolo=mlolo+atoms%nlo(m)*(atoms%nlo(m)+1)/2
    ENDDO


    !$OMP MASTER
    IF ((atoms%invsat(na).EQ.0) .OR. (atoms%invsat(na).EQ.1)) THEN
       !--->    if this atom is the first of two atoms related by inversion,
       !--->    the contributions to the overlap matrix of both atoms are added
       !--->    at once. where it is made use of the fact, that the sum of
       !--->    these contributions is twice the real part of the contribution
       !--->    of each atom. note, that in this case there are twice as many
       !--->    (2*(2*l+1)) k-vectors (compare abccoflo and comments there).
       IF (atoms%invsat(na).EQ.0) invsfct = 1
       IF (atoms%invsat(na).EQ.1) invsfct = 2
       nkvecprevlo = 0
       !-noco
       IF (noco%l_ss) THEN
          iilo_s = iilo
          locol_s = locol
          nkvecprevat_s = nkvecprevat ! save for other interstitial spin loops
          ic = 0                                        ! update b-matrix
          DO lo = 1,atoms%nlo(ntyp)
             ic = ic + invsfct* (2*atoms%llo(lo,ntyp)+1)
          ENDDO
          k = ic*(lapw%nv(jintsp)+nkvecprevat) + (ic+1)*ic/2
          ALLOCATE ( ahelp(k) )       ! initialize help-array
94
          ahelp=CMPLX(0.,0.)
95 96 97 98 99 100
          iilo = 0
       ENDIF
       !-noco
       !
       ! temporarily update the diagonal elements
       !
101
       DO l = 0,atoms%lnonsph(ntyp)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
          DO  m = -l,l
             lm = l* (l+1) + m
             lmplm = (lm* (lm+3))/2
             tlmplm%tuu(lmplm,ntyp,tsp)=tlmplm%tuu(lmplm,ntyp,tsp) + el(l)
             tlmplm%tdd(lmplm,ntyp,tsp)=tlmplm%tdd(lmplm,ntyp,tsp) + el(l)*ud%ddn(l,ntyp,usp)
             tlmplm%tud(lmplm,ntyp,tsp)=tlmplm%tud(lmplm,ntyp,tsp) + 0.5
             tlmplm%tdu(lmplm,ntyp,tsp)=tlmplm%tdu(lmplm,ntyp,tsp) + 0.5
             indt(lm) = tlmplm%ind(lm,lm,ntyp,tsp)
             tlmplm%ind(lm,lm,ntyp,tsp) = lmplm
          ENDDO
       ENDDO
       !
       DO lo = 1,atoms%nlo(ntyp)
          l = atoms%llo(lo,ntyp)
          matel0 = iilo
          locol0 = locol
          !--->       calculate the hamiltonian matrix elements with the regular
          !--->       flapw basis-functions
          DO m = -l,l
             lm = l* (l+1) + m
             iilo = matel0
             locol = locol0
             DO kp = 1,lapw%nv(jintsp)
125 126 127
                ax(kp) = CMPLX(0.0,0.0)
                bx(kp) = CMPLX(0.0,0.0)
                cx(kp) = CMPLX(0.0,0.0)
128
             END DO
129
             DO lp = 0,atoms%lnonsph(ntyp)
130 131 132 133 134 135 136 137 138 139 140
                DO mp = -lp,lp
                   lmp = lp* (lp+1) + mp
                   in = tlmplm%ind(lmp,lm,ntyp,tsp)
                   IF (in.NE.-9999) THEN
                      IF (in.GE.0) THEN
                         utu = tlmplm%tuu(in,ntyp,tsp)
                         dtu = tlmplm%tdu(in,ntyp,tsp)
                         utd = tlmplm%tud(in,ntyp,tsp)
                         dtd = tlmplm%tdd(in,ntyp,tsp)
                      ELSE
                         im = -in
141 142 143 144
                         utu = CONJG(tlmplm%tuu(im,ntyp,tsp))
                         dtu = CONJG(tlmplm%tud(im,ntyp,tsp))
                         utd = CONJG(tlmplm%tdu(im,ntyp,tsp))
                         dtd = CONJG(tlmplm%tdd(im,ntyp,tsp))
145 146 147 148 149 150 151 152 153
                      END IF
                      utulo = tlmplm%tuulo(lmp,m,lo+mlo,tsp)
                      dtulo = tlmplm%tdulo(lmp,m,lo+mlo,tsp)
                      !--->                   note, that utu,dtu... are the t-matrices and
                      !--->                   not their complex conjugates as in hssphn
                      !--->                   and that a,b,alo... are the complex
                      !--->                   conjugates of the a,b...-coefficients
                      DO kp = 1,lapw%nv(jintsp)
                         ax(kp) = ax(kp) + &
154 155
                              CMPLX(ar(kp,lmp),ai(kp,lmp))*utu +&
                              CMPLX(br(kp,lmp),bi(kp,lmp))*dtu
156
                         bx(kp) = bx(kp) + &
157 158
                              CMPLX(ar(kp,lmp),ai(kp,lmp))*utd +&
                              CMPLX(br(kp,lmp),bi(kp,lmp))*dtd
159
                         cx(kp) = cx(kp) + &
160 161
                              CMPLX(ar(kp,lmp),ai(kp,lmp))*utulo +&
                              CMPLX(br(kp,lmp),bi(kp,lmp))*dtulo
162 163 164 165 166 167 168
                      END DO
                   END IF
                END DO
             END DO
             !+t3e
             DO nkvec = 1,invsfct* (2*l+1)
                locol = locol + 1
169
                IF (MOD(locol-1,n_size).EQ.n_rank) THEN
170 171 172 173 174
                   !-t3e
                   DO kp = 1,lapw%nv(jintsp)
                      iilo = iilo + 1
#ifdef CPP_INVERSION
                      aa(iilo) = aa(iilo) + invsfct * (&
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
                           REAL(alo(m,nkvec,lo,iintsp))* REAL(ax(kp)) +&
                           AIMAG(alo(m,nkvec,lo,iintsp))*AIMAG(ax(kp)) +&
                           REAL(blo(m,nkvec,lo,iintsp))* REAL(bx(kp)) +&
                           AIMAG(blo(m,nkvec,lo,iintsp))*AIMAG(bx(kp)) +&
                           REAL(clo(m,nkvec,lo,iintsp))* REAL(cx(kp)) +&
                           AIMAG(clo(m,nkvec,lo,iintsp))*AIMAG(cx(kp)) )
                      IF (input%l_useapw) THEN
                         !---> APWlo
                         aa(iilo) = aa(iilo) + 0.25 * atoms%rmt(ntyp)**2 * invsfct * (&
                              (ar(kp,lm)*ud%us(l,ntyp,usp)+&
                              br(kp,lm)*ud%uds(l,ntyp,usp))*&
                              REAL( alo(m,nkvec,lo,iintsp)*  ud%dus(l,ntyp,usp) +&
                              blo(m,nkvec,lo,iintsp)* ud%duds(l,ntyp,usp)  +&
                              clo(m,nkvec,lo,iintsp)*ud%dulos(lo,ntyp,usp) ) +&
                              (ai(kp,lm)*ud%us(l,ntyp,usp)+bi(kp,lm)*ud%uds(l,ntyp,usp))*&
                              AIMAG( alo(m,nkvec,lo,iintsp)*  ud%dus(l,ntyp,usp) +&
                              blo(m,nkvec,lo,iintsp)* ud%duds(l,ntyp,usp) +&
                              clo(m,nkvec,lo,iintsp)*ud%dulos(lo,ntyp,usp) ) )
                      ENDIF
194
#else
195
                      IF (.NOT.noco%l_ss) THEN
196
                         aa(iilo) = aa(iilo) + invsfct * (&
197 198 199 200 201 202 203 204 205 206 207 208
                              alo(m,nkvec,lo,iintsp) * CONJG( ax(kp) ) +&
                              blo(m,nkvec,lo,iintsp) * CONJG( bx(kp) ) +&
                              clo(m,nkvec,lo,iintsp) * CONJG( cx(kp) ) )
                         IF (input%l_useapw) THEN
                            !---> APWlo
                            aa(iilo)=aa(iilo) + 0.25 * atoms%rmt(ntyp)**2 * invsfct*(&
                                 (CMPLX(ar(kp,lm),-ai(kp,lm))* ud%us(l,ntyp,usp)+&
                                 CMPLX(br(kp,lm),-bi(kp,lm))*ud%uds(l,ntyp,usp))*&
                                 (alo(m,nkvec,lo,iintsp)*  ud%dus(l,ntyp,usp)&
                                 +blo(m,nkvec,lo,iintsp)* ud%duds(l,ntyp,usp)&
                                 +clo(m,nkvec,lo,iintsp)*ud%dulos(lo,ntyp,usp) ))
                         ENDIF
209 210
                      ELSE
                         ahelp(iilo) = ahelp(iilo) + invsfct * (&
211 212 213 214 215 216 217 218 219 220 221 222 223
                              alo(m,nkvec,lo,iintsp) * CONJG( ax(kp) ) +&
                              blo(m,nkvec,lo,iintsp) * CONJG( bx(kp) ) +&
                              clo(m,nkvec,lo,iintsp) * CONJG( cx(kp) ) )
                         IF (input%l_useapw) THEN

                            !---> APWlo
                            ahelp(iilo)=ahelp(iilo) + 0.25 * atoms%rmt(ntyp)**2 * invsfct*(&
                                 (CMPLX(ar(kp,lm),-ai(kp,lm))* ud%us(l,ntyp,usp)+&
                                 CMPLX(br(kp,lm),-bi(kp,lm))*ud%uds(l,ntyp,usp))*&
                                 (alo(m,nkvec,lo,iintsp)*  ud%dus(l,ntyp,usp)&
                                 +blo(m,nkvec,lo,iintsp)* ud%duds(l,ntyp,usp)&
                                 +clo(m,nkvec,lo,iintsp)*ud%dulos(lo,ntyp,usp) ))
                         ENDIF
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
                      ENDIF
#endif
                   END DO
                   !--->             jump to the last matrixelement of the current row
                   iilo = iilo + nkvecprevat + nkvecprevlo + nkvec
                ENDIF
             END DO
          END DO
          !--->       calculate the hamiltonian matrix elements with other
          !--->       local orbitals at the same atom and with itself
          iilo = matel0
          !+t3e
          locol = locol0
          DO nkvec = 1,invsfct* (2*l+1)
             locol = locol + 1
239
             IF (MOD(locol-1,n_size).EQ.n_rank) THEN
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
                !-t3e
                !--->          skip the matrixelements with regular flapw-fcn. and
                !--->          with local orbitals at other atoms
                iilo = iilo + lapw%nv(jintsp) + nkvecprevat
                !--->          calculate the hamiltonian matrix elements with other
                !--->          local orbitals at the same atom, if they have the same l
                DO lop = 1, (lo-1)
                   lp = atoms%llo(lop,ntyp)
                   DO nkvecp = 1,invsfct* (2*lp+1)
                      iilo = iilo + 1
                      DO m = -l,l
                         lm = l* (l+1) + m
                         DO mp = -lp,lp
                            lmp = lp* (lp+1) + mp
                            in = tlmplm%ind(lmp,lm,ntyp,tsp)
                            IF (in.NE.-9999) THEN
                               IF (in.GE.0) THEN
                                  utu = tlmplm%tuu(in,ntyp,tsp)
                                  dtu = tlmplm%tdu(in,ntyp,tsp)
                                  utd = tlmplm%tud(in,ntyp,tsp)
                                  dtd = tlmplm%tdd(in,ntyp,tsp)
                               ELSE
                                  im = -in
263 264 265 266
                                  utu = CONJG(tlmplm%tuu(im,ntyp,tsp))
                                  dtu = CONJG(tlmplm%tud(im,ntyp,tsp))
                                  utd = CONJG(tlmplm%tdu(im,ntyp,tsp))
                                  dtd = CONJG(tlmplm%tdd(im,ntyp,tsp))
267 268 269
                               END IF
                               utulo = tlmplm%tuulo(lmp,m,lo+mlo,tsp)
                               dtulo = tlmplm%tdulo(lmp,m,lo+mlo,tsp)
270 271
                               ulotu=CONJG(tlmplm%tuulo(lm,mp,lop+mlo,tsp))
                               ulotd=CONJG(tlmplm%tdulo(lm,mp,lop+mlo,tsp))
272 273
                               !--->                         note that lo > lop
                               lolop = ((lo-1)*lo)/2 + lop
274 275 276 277 278 279 280
                               ulotulo = CONJG(tlmplm%tuloulo (m,mp,lolop+mlolo,tsp))
                               axx=CONJG(alo(m,nkvec,lo,iintsp))*utu +&
                                    CONJG(blo(m,nkvec,lo,iintsp))*utd +&
                                    CONJG(clo(m,nkvec,lo,iintsp))*utulo
                               bxx=CONJG(alo(m,nkvec,lo,iintsp))*dtu +&
                                    CONJG(blo(m,nkvec,lo,iintsp))*dtd +&
                                    CONJG(clo(m,nkvec,lo,iintsp))*dtulo
281
                               cxx = &
282 283 284
                                    CONJG(alo(m,nkvec,lo,iintsp))*ulotu +&
                                    CONJG(blo(m,nkvec,lo,iintsp))*ulotd +&
                                    CONJG(clo(m,nkvec,lo,iintsp))*ulotulo
285 286
#ifdef CPP_INVERSION
                               aa(iilo) = aa(iilo) + invsfct * (&
287 288 289 290 291 292
                                    REAL(alo(mp,nkvecp,lop,jintsp))* REAL(axx) -&
                                    AIMAG(alo(mp,nkvecp,lop,jintsp))*AIMAG(axx) +&
                                    REAL(blo(mp,nkvecp,lop,jintsp))* REAL(bxx) -&
                                    AIMAG(blo(mp,nkvecp,lop,jintsp))*AIMAG(bxx) +&
                                    REAL(clo(mp,nkvecp,lop,jintsp))* REAL(cxx) -&
                                    AIMAG(clo(mp,nkvecp,lop,jintsp))*AIMAG(cxx) )
293
#else
294 295
                               IF (.NOT.noco%l_ss) THEN
                                  aa(iilo) = aa(iilo) + invsfct * CONJG(&
296 297 298 299
                                       alo(mp,nkvecp,lop,jintsp) * axx +&
                                       blo(mp,nkvecp,lop,jintsp) * bxx +&
                                       clo(mp,nkvecp,lop,jintsp) * cxx )
                               ELSE
300
                                  ahelp(iilo)=ahelp(iilo)+invsfct*CONJG(&
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
                                       alo(mp,nkvecp,lop,jintsp) * axx +&
                                       blo(mp,nkvecp,lop,jintsp) * bxx +&
                                       clo(mp,nkvecp,lop,jintsp) * cxx )
                               ENDIF
#endif
                            END IF
                         END DO
                      END DO
                   END DO
                END DO
                !--->          calculate the hamiltonian matrix elements of one local
                !--->          orbital with itself
                DO nkvecp = 1,nkvec
                   iilo = iilo + 1
                   DO m = -l,l
                      lm = l* (l+1) + m
                      DO mp = -l,l
                         lmp = l* (l+1) + mp
                         in = tlmplm%ind(lmp,lm,ntyp,tsp)
                         IF (in.NE.-9999) THEN
                            IF (in.GE.0) THEN
                               utu = tlmplm%tuu(in,ntyp,tsp)
                               dtu = tlmplm%tdu(in,ntyp,tsp)
                               utd = tlmplm%tud(in,ntyp,tsp)
                               dtd = tlmplm%tdd(in,ntyp,tsp)
                            ELSE
                               im = -in
328 329 330 331
                               utu = CONJG(tlmplm%tuu(im,ntyp,tsp))
                               dtu = CONJG(tlmplm%tud(im,ntyp,tsp))
                               utd = CONJG(tlmplm%tdu(im,ntyp,tsp))
                               dtd = CONJG(tlmplm%tdd(im,ntyp,tsp))
332 333 334
                            END IF
                            utulo = tlmplm%tuulo(lmp,m,lo+mlo,tsp)
                            dtulo = tlmplm%tdulo(lmp,m,lo+mlo,tsp)
335 336
                            ulotu = CONJG(tlmplm%tuulo(lm,mp,lo+mlo,tsp))
                            ulotd = CONJG(tlmplm%tdulo(lm,mp,lo+mlo,tsp))
337
                            lolo = ((lo-1)*lo)/2 + lo
338 339 340 341 342 343 344 345 346 347
                            ulotulo =CONJG(tlmplm%tuloulo(m,mp,lolo+mlolo,tsp))
                            axx = CONJG(alo(m,nkvec,lo,iintsp))*utu +&
                                 CONJG(blo(m,nkvec,lo,iintsp))*utd +&
                                 CONJG(clo(m,nkvec,lo,iintsp))*utulo
                            bxx = CONJG(alo(m,nkvec,lo,iintsp))*dtu +&
                                 CONJG(blo(m,nkvec,lo,iintsp))*dtd +&
                                 CONJG(clo(m,nkvec,lo,iintsp))*dtulo
                            cxx = CONJG(alo(m,nkvec,lo,iintsp))*ulotu +&
                                 CONJG(blo(m,nkvec,lo,iintsp))*ulotd +&
                                 CONJG(clo(m,nkvec,lo,iintsp))*ulotulo
348 349
#ifdef CPP_INVERSION
                            aa(iilo) = aa(iilo) + invsfct* (&
350 351 352 353 354 355
                                 REAL(alo(mp,nkvecp,lo,jintsp))* REAL(axx) -&
                                 AIMAG(alo(mp,nkvecp,lo,jintsp))*AIMAG(axx) +&
                                 REAL(blo(mp,nkvecp,lo,jintsp))* REAL(bxx) -&
                                 AIMAG(blo(mp,nkvecp,lo,jintsp))*AIMAG(bxx) +&
                                 REAL(clo(mp,nkvecp,lo,jintsp))* REAL(cxx) -&
                                 AIMAG(clo(mp,nkvecp,lo,jintsp))*AIMAG(cxx) )
356
#else
357 358
                            IF (.NOT.noco%l_ss) THEN
                               aa(iilo) = aa(iilo) + invsfct* CONJG(&
359 360 361 362
                                    alo(mp,nkvecp,lo,jintsp)*axx +&
                                    blo(mp,nkvecp,lo,jintsp)*bxx +&
                                    clo(mp,nkvecp,lo,jintsp)*cxx )
                            ELSE
363
                               ahelp(iilo) = ahelp(iilo) + invsfct* CONJG(&
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
                                    alo(mp,nkvecp,lo,jintsp)*axx +&
                                    blo(mp,nkvecp,lo,jintsp)*bxx +&
                                    clo(mp,nkvecp,lo,jintsp)*cxx )
                            ENDIF
#endif
                         END IF
                      END DO
                   END DO
                END DO
             ENDIF
             !-t3e
          END DO
          nkvecprevlo = nkvecprevlo + invsfct* (2*l+1)
       END DO ! end of lo = 1,atoms%nlo loop
       !
       ! remove the temporary update of the diagonal elements
       !
381
       DO l = 0,atoms%lnonsph(ntyp)
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
          DO  m = -l,l
             lm = l* (l+1) + m
             lmplm = (lm* (lm+3))/2
             tlmplm%tuu(lmplm,ntyp,tsp)=tlmplm%tuu(lmplm,ntyp,tsp) - el(l)
             tlmplm%tdd(lmplm,ntyp,tsp)=tlmplm%tdd(lmplm,ntyp,tsp) - el(l)*ud%ddn(l,ntyp,usp)
             tlmplm%tud(lmplm,ntyp,tsp)=tlmplm%tud(lmplm,ntyp,tsp) - 0.5
             tlmplm%tdu(lmplm,ntyp,tsp)=tlmplm%tdu(lmplm,ntyp,tsp) - 0.5
             tlmplm%ind(lm,lm,ntyp,tsp) = indt(lm)
          ENDDO
       ENDDO
       !
       nkvecprevat = nkvecprevat + nkvecprevlo
       !+noco
       IF (noco%l_ss) THEN
          IF ( iintsp.EQ.1 .AND. jintsp.EQ.1 ) THEN     !---> spin-up spin-up part
             chihlp = chi11
             n = lapw%nv(1) + nkvecprevat_s
             ij = (n+1)*n/2
          ELSEIF ( iintsp.EQ.2 .AND. jintsp.EQ.2 ) THEN !---> spin-down spin-down part
             chihlp = chi22
             n = lapw%nv(1) + lapw%nv(iintsp) + atoms%nlotot + nkvecprevat_s
             ij = (n+1)*n/2 + lapw%nv(1) + atoms%nlotot
          ELSE                                          !---> spin-down spin-up part
             chihlp = chi21
             n = lapw%nv(1) + lapw%nv(iintsp) + atoms%nlotot + nkvecprevat_s
             ij = (n+1)*n/2
          ENDIF

          ic = 0                                        ! update b-matrix
          DO lo = 1,atoms%nlo(ntyp)
             ic = ic + invsfct* (2*atoms%llo(lo,ntyp)+1)
          ENDDO
414
          IF (.NOT.( iintsp.EQ.1 .AND. jintsp.EQ.2 )) THEN
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
             ii = 0
             DO k = 1, ic
                n = k + lapw%nv(jintsp) + nkvecprevat_s
#ifndef CPP_INVERSION
                IF (iintsp.EQ.2 .AND. jintsp.EQ.1 ) THEN
                   CALL CPP_BLAS_caxpy(n-1,chihlp,ahelp(ii+1),1,aa(ij+1),1)
                ELSE
                   CALL CPP_BLAS_caxpy(n,chihlp,ahelp(ii+1),1,aa(ij+1),1)
                ENDIF
#endif
                ii = ii + n
                ij = ij + n + (lapw%nv(3-jintsp)+atoms%nlotot)*(iintsp-1)
             ENDDO
          ELSE                                         ! special treatment for up-down:
             n = lapw%nv(1) + atoms%nlotot
             ii = 0
             DO k = 1, ic
                ij = (n+1)*n/2 + lapw%nv(1) + k + nkvecprevat_s
                DO kp = 1, k + lapw%nv(jintsp) + nkvecprevat_s
                   ii = ii + 1
435
                   aa(ij) = aa(ij) + chihlp * CONJG( ahelp(ii) )
436 437 438 439 440
                   ij = ij + lapw%nv(1) + kp + atoms%nlotot
                ENDDO
             ENDDO
          ENDIF
          DEALLOCATE ( ahelp )
441
          IF (.NOT.( iintsp.EQ.2 .AND. jintsp.EQ.2 )) THEN
442 443 444 445 446 447 448 449 450 451 452 453 454
             iilo = iilo_s
             locol = locol_s             ! restore for other loops
             nkvecprevat = nkvecprevat_s
          ENDIF
       ELSE
          k = lapw%nv(1) * ( lapw%nv(1) + 1 ) / 2
       ENDIF
       !-noco
    END IF
    !$OMP END MASTER
    !$OMP barrier
  END SUBROUTINE hlomat
      END MODULE m_hlomat