coulombmatrix.F90 95.5 KB
 Daniel Wortmann committed Jun 21, 2017 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ``````! ! Calculates the Coulomb matrix ! ! v = < M | v | M > ! k,IJ k,I k,J ! ! with the mixed-basis functions M (indices I and J). ! ! Note that ! * ! v = v . ! k,JI k,IJ ! ! In the code: coulomb(IJ,k) = v where only the upper triangle (I<=J) is stored. `````` Matthias Redies committed Jun 17, 2019 15 ``````! k,IJ `````` Daniel Wortmann committed Jun 21, 2017 16 17 18 19 20 21 22 23 24 25 26 27 28 ``````! ! The Coulomb matrix v(IJ,k) diverges at the Gamma-point. Here, we apply the decomposition ! ! (0) (1) * 2-l (0)* (0) (1)* m (1) ! v = v + SUM v * Y (k) / k with v = v , v = (-1) v ! k,IJ IJ lm IJ lm JI IJ JI,lm IJ,l,-m ! ! where a = atom index, R = position vector, T = Wigner-Seitz radius (scalar). ! a 0 ! (0) ! In the code: coulomb(IJ,1) = v where only the upper triangle (I<=J) is stored, ! IJ ! (1) `````` Daniel Wortmann committed Jul 14, 2017 29 ``````! coulfac(IJ,lm) = v IJ,lm `````` Daniel Wortmann committed Jun 21, 2017 30 31 32 33 ``````! ! For the PW contribution we have to construct plane waves within the MT spheres with the help ! of spherical Bessel functions. The value lexp (LEXP in gwinp) is the corresponding cutoff. ! `````` Daniel Wortmann committed Jul 18, 2017 34 ``````MODULE m_coulombmatrix `````` Daniel Wortmann committed Jun 21, 2017 35 `````` `````` Daniel Wortmann committed Jul 14, 2017 36 ``````CONTAINS `````` Daniel Wortmann committed Jun 21, 2017 37 `````` `````` Matthias Redies committed Jun 17, 2019 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 89 90 91 92 93 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 `````` SUBROUTINE coulombmatrix(mpi, atoms, kpts, cell, sym, hybrid, xcpot, l_restart) USE m_types USE m_juDFT USE m_constants, ONLY: pi_const USE m_olap, ONLY: olap_pw, gptnorm USE m_trafo, ONLY: symmetrize, bramat_trafo USE m_util, ONLY: sphbessel, intgrf, intgrf_init, harmonicsr, primitivef USE m_hsefunctional, ONLY: change_coulombmatrix USE m_wrapper USE m_io_hybrid IMPLICIT NONE TYPE(t_xcpot_inbuild), INTENT(IN) :: xcpot TYPE(t_mpi), INTENT(IN) :: mpi TYPE(t_hybrid), INTENT(INOUT) :: hybrid TYPE(t_sym), INTENT(IN) :: sym TYPE(t_cell), INTENT(IN) :: cell TYPE(t_kpts), INTENT(IN) :: kpts TYPE(t_atoms), INTENT(IN) :: atoms ! - scalars - LOGICAL, INTENT(IN) :: l_restart ! - local scalars - INTEGER :: inviop INTEGER :: nqnrm, iqnrm, iqnrm1, iqnrm2, iqnrmstart, iqnrmstep INTEGER :: itype, l, ix, iy, iy0, i, j, lm, l1, l2, m1, m2, ineq, idum, ikpt, ikpt0, ikpt1 INTEGER :: lm1, lm2, itype1, itype2, ineq1, ineq2, n, n1, n2, ng INTEGER :: ic, ic1, ic2, ic3, ic4, ic5, ic6, ic7, ic8 INTEGER :: igpt, igpt1, igpt2, igptp, igptp1, igptp2 INTEGER :: isym, isym1, isym2, igpt0 INTEGER :: ok INTEGER :: m INTEGER :: ikptmin, ikptmax, nkminmax INTEGER :: maxfac LOGICAL :: lsym REAL :: rdum, rdum1, rdum2 REAL :: svol, qnorm, qnorm1, qnorm2, gnorm REAL :: fcoulfac REAL :: time1, time2 COMPLEX :: cdum, cdum1, cexp, csum ! - local arrays - INTEGER :: g(3) INTEGER :: nbasm1(kpts%nkptf) INTEGER, ALLOCATABLE :: pqnrm(:, :) INTEGER :: rrot(3, 3, sym%nsym), invrrot(3, 3, sym%nsym) INTEGER, ALLOCATABLE :: iarr(:), POINTER(:, :, :, :)!,pointer(:,:,:) INTEGER :: igptmin(kpts%nkpt), igptmax(kpts%nkpt) INTEGER, ALLOCATABLE :: nsym_gpt(:, :), sym_gpt(:, :, :) INTEGER :: nsym1(kpts%nkpt + 1), sym1(sym%nsym, kpts%nkpt + 1) LOGICAL :: calc_mt(kpts%nkpt) REAL :: q(3), q1(3), q2(3) REAL :: integrand(atoms%jmtd), primf1(atoms%jmtd), primf2(atoms%jmtd) REAL :: mat(hybrid%maxindxm1*(hybrid%maxindxm1 + 1)/2) REAL :: moment(hybrid%maxindxm1, 0:hybrid%maxlcutm1, atoms%ntype), & moment2(hybrid%maxindxm1, atoms%ntype) REAL :: sphbes(atoms%jmtd, 0:hybrid%maxlcutm1) REAL :: sphbesmoment1(atoms%jmtd, 0:hybrid%maxlcutm1) REAL :: rarr(0:hybrid%lexp + 1), rarr1(0:hybrid%maxlcutm1) REAL, ALLOCATABLE :: gmat(:, :), qnrm(:) REAL, ALLOCATABLE :: sphbesmoment(:, :, :) REAL, ALLOCATABLE :: sphbes0(:, :, :) REAL, ALLOCATABLE :: olap(:, :, :, :), integral(:, :, :, :) REAL, ALLOCATABLE :: gridf(:, :) REAL :: facA(0:MAX(2*atoms%lmaxd + hybrid%maxlcutm1 + 1, 4*MAX(hybrid%maxlcutm1, hybrid%lexp) + 1)) REAL :: facB(0:MAX(2*atoms%lmaxd + hybrid%maxlcutm1 + 1, 4*MAX(hybrid%maxlcutm1, hybrid%lexp) + 1)) REAL :: facC(-1:MAX(2*atoms%lmaxd + hybrid%maxlcutm1 + 1, 4*MAX(hybrid%maxlcutm1, hybrid%lexp) + 1)) COMPLEX :: cexp1(atoms%ntype), csumf(9) COMPLEX :: structconst((2*hybrid%lexp + 1)**2, atoms%nat, atoms%nat, kpts%nkpt) ! nw = 1 COMPLEX :: y((hybrid%lexp + 1)**2), y1((hybrid%lexp + 1)**2), y2((hybrid%lexp + 1)**2) COMPLEX :: dwgn(-hybrid%maxlcutm1:hybrid%maxlcutm1, -hybrid%maxlcutm1:hybrid%maxlcutm1, 0:hybrid%maxlcutm1, sym%nsym) COMPLEX, ALLOCATABLE :: smat(:, :) COMPLEX, ALLOCATABLE :: coulmat(:, :) COMPLEX, ALLOCATABLE :: carr2(:, :), carr2a(:, :), carr2b(:, :) COMPLEX, ALLOCATABLE :: structconst1(:, :) REAL, ALLOCATABLE :: coulomb_mt1(:, :, :, :, :) !REAL , ALLOCATABLE :: coulomb(:,:) !At the moment we always calculate a complex coulomb matrix REAL, ALLOCATABLE :: coulomb_mt2_r(:, :, :, :, :), coulomb_mt3_r(:, :, :, :) REAL, ALLOCATABLE :: coulomb_mtir_r(:, :, :), coulombp_mtir_r(:, :) COMPLEX, ALLOCATABLE :: coulomb(:, :) COMPLEX, ALLOCATABLE :: coulomb_mt2_c(:, :, :, :, :), coulomb_mt3_c(:, :, :, :) COMPLEX, ALLOCATABLE :: coulomb_mtir_c(:, :, :), coulombp_mtir_c(:, :) INTEGER :: ishift, ishift1 INTEGER :: iatom, iatom1 INTEGER :: indx1, indx2, indx3, indx4 LOGICAL :: l_found, l_warn, l_warned, l_plot = .FALSE.!.true.!.false. TYPE(t_mat) :: olapm, coulhlp CALL timestart("Coulomb matrix setup") svol = SQRT(cell%vol) fcoulfac = 4*pi_const/cell%vol maxfac = MAX(2*atoms%lmaxd + hybrid%maxlcutm1 + 1, 4*MAX(hybrid%maxlcutm1, hybrid%lexp) + 1) facA(0) = 1 ! facB(0) = 1 ! Define: facC(-1:0) = 1 ! facA(i) = i! DO i = 1, maxfac ! facB(i) = sqrt(i!) facA(i) = facA(i - 1)*i ! facC(i) = (2i+1)!! facB(i) = facB(i - 1)*SQRT(i*1d0) ! facC(i) = facC(i - 1)*(2*i + 1) ! END DO CALL intgrf_init(atoms%ntype, atoms%jmtd, atoms%jri, atoms%dx, atoms%rmsh, gridf) nbasm1 = hybrid%nbasp + hybrid%ngptm(:) `````` Matthias Redies committed Jun 18, 2019 156 `````` `````` Matthias Redies committed Jun 17, 2019 157 158 159 160 161 162 163 164 165 `````` ! Calculate the structure constant CALL structureconstant(structconst, cell, hybrid, atoms, kpts, mpi) IF (mpi%irank == 0) WRITE (6, '(//A)') '### subroutine: coulombmatrix ###' ! ! Matrix allocation ! `````` Matthias Redies committed Jun 18, 2019 166 `````` call timestart("coulomb allocation") `````` Matthias Redies committed Jun 17, 2019 167 168 169 170 171 `````` IF (ALLOCATED(coulomb)) DEALLOCATE (coulomb) ALLOCATE (coulomb(hybrid%maxbasm1*(hybrid%maxbasm1 + 1)/2, kpts%nkpt), stat=ok) IF (ok .NE. 0) STOP 'coulombmatrix: failure allocation coulomb matrix' coulomb = 0 `````` Matthias Redies committed Jun 18, 2019 172 `````` call timestop("coulomb allocation") `````` Matthias Redies committed Jun 17, 2019 173 174 175 176 177 `````` IF (mpi%irank == 0) WRITE (6, '(/A,F6.1," MB")') 'Size of coulomb matrix:', 16d0/1048576*SIZE(coulomb) ! Generate Symmetry: ! Reduce list of g-Points so that only one of each symm-equivalent is calculated `````` Daniel Wortmann committed Jun 21, 2017 178 `````` `````` Gregor Michalicek committed Aug 29, 2018 179 ``````#ifndef CPP_NOCOULSYM `````` Matthias Redies committed Jun 17, 2019 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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 `````` IF (mpi%irank == 0) WRITE (6, '(/A)', advance='no') 'Setup for symmetry...' CALL cpu_TIME(time1) ! calculate rotations in reciprocal space DO isym = 1, sym%nsym IF (isym .LE. sym%nop) THEN inviop = sym%invtab(isym) rrot(:, :, isym) = TRANSPOSE(sym%mrot(:, :, inviop)) DO l = 0, hybrid%maxlcutm1 dwgn(:, :, l, isym) = TRANSPOSE(hybrid%d_wgn2(-hybrid%maxlcutm1:hybrid%maxlcutm1, & -hybrid%maxlcutm1:hybrid%maxlcutm1, l, isym)) END DO ELSE inviop = isym - sym%nop rrot(:, :, isym) = -rrot(:, :, inviop) dwgn(:, :, :, isym) = dwgn(:, :, :, inviop) DO l = 0, hybrid%maxlcutm1 DO m1 = -l, l DO m2 = -l, -1 cdum = dwgn(m1, m2, l, isym) dwgn(m1, m2, l, isym) = dwgn(m1, -m2, l, isym)*(-1)**m2 dwgn(m1, -m2, l, isym) = cdum*(-1)**m2 END DO END DO END DO END IF END DO invrrot(:, :, :sym%nop) = rrot(:, :, sym%invtab) IF (sym%nsym > sym%nop) THEN invrrot(:, :, sym%nop + 1:) = rrot(:, :, sym%invtab + sym%nop) END IF ! Get symmetry operations that leave bk(:,ikpt) invariant -> sym1 nsym1 = 0 DO ikpt = 1, kpts%nkpt isym1 = 0 DO isym = 1, sym%nsym ! temporary fix until bramat_trafo is correct ! for systems with symmetries including translations IF (isym > sym%nop) THEN isym2 = isym - sym%nop ELSE isym2 = isym END IF IF (ANY(sym%tau(:, isym2) /= 0)) CYCLE IF (ALL(ABS(MATMUL(rrot(:, :, isym), kpts%bk(:, ikpt)) - kpts%bk(:, ikpt)) .LT. 1d-12)) THEN isym1 = isym1 + 1 sym1(isym1, ikpt) = isym END IF END DO nsym1(ikpt) = isym1 END DO ! Define reduced lists of G points -> pgptm1(:,ikpt), ikpt=1,..,nkpt !ALLOCATE ( hybrid%pgptm1(hybrid%maxgptm,kpts%nkpt)) !in mixedbasis ALLOCATE (iarr(hybrid%maxgptm), POINTER(kpts%nkpt, & MINVAL(hybrid%gptm(1, :)) - 1:MAXVAL(hybrid%gptm(1, :)) + 1, & MINVAL(hybrid%gptm(2, :)) - 1:MAXVAL(hybrid%gptm(2, :)) + 1, & MINVAL(hybrid%gptm(3, :)) - 1:MAXVAL(hybrid%gptm(3, :)) + 1)) hybrid%pgptm1 = 0; iarr = 0; POINTER = 0 DO ikpt = 1, kpts%nkpt DO igpt = 1, hybrid%ngptm(ikpt) g = hybrid%gptm(:, hybrid%pgptm(igpt, ikpt)) POINTER(ikpt, g(1), g(2), g(3)) = igpt END DO iarr = 0 j = 0 DO igpt = hybrid%ngptm(ikpt), 1, -1 IF (iarr(igpt) .EQ. 0) THEN j = j + 1 hybrid%pgptm1(j, ikpt) = igpt DO isym1 = 1, nsym1(ikpt) g = MATMUL(rrot(:, :, sym1(isym1, ikpt)), hybrid%gptm(:, hybrid%pgptm(igpt, ikpt))) i = POINTER(ikpt, g(1), g(2), g(3)) IF (i .EQ. 0) STOP 'coulombmatrix: zero pointer (bug?)' iarr(i) = 1 END DO END IF END DO hybrid%ngptm1(ikpt) = j END DO DEALLOCATE (iarr) IF (mpi%irank == 0) WRITE (6, '(12X,A)', advance='no') 'done' CALL cpu_TIME(time2) IF (mpi%irank == 0) WRITE (6, '(2X,A,F8.2,A)') '( Timing:', time2 - time1, ' )' ! no symmetry used #else ALLOCATE (hybrid%pgptm1(hybrid%maxgptm, kpts%nkpt)) DO ikpt = 1, kpts%nkpt hybrid%pgptm1(:, ikpt) = (/(igpt0, igpt0=1, hybrid%maxgptm)/) hybrid%ngptm1(ikpt) = hybrid%ngptm(ikpt) END DO `````` Gregor Michalicek committed Aug 29, 2018 273 ``````#endif `````` Daniel Wortmann committed Jun 21, 2017 274 `````` `````` Matthias Redies committed Jun 17, 2019 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 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 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 `````` ! Distribute the work as equally as possible over the processes ikptmin = 1 ikptmax = kpts%nkpt igptmin = 1 igptmax = hybrid%ngptm1(:kpts%nkpt) calc_mt = .TRUE. nkminmax = kpts%nkpt IF (mpi%irank == 0) WRITE (6, '(A)', advance='no') 'Preparations...' CALL cpu_TIME(time1) call timestart("define gmat") ! Define gmat (symmetric) i = (hybrid%lexp + 1)**2 ALLOCATE (gmat(i, i)) gmat = 0 lm1 = 0 DO l1 = 0, hybrid%lexp DO m1 = -l1, l1 lm1 = lm1 + 1 lm2 = 0 lp1: DO l2 = 0, l1 DO m2 = -l2, l2 lm2 = lm2 + 1 IF (lm2 .GT. lm1) EXIT lp1 ! Don't cross the diagonal! gmat(lm1, lm2) = facB(l1 + l2 + m2 - m1)*facB(l1 + l2 + m1 - m2)/ & (facB(l1 + m1)*facB(l1 - m1)*facB(l2 + m2)*facB(l2 - m2))/ & SQRT(1d0*(2*l1 + 1)*(2*l2 + 1)*(2*(l1 + l2) + 1))*(4*pi_const)**1.5d0 gmat(lm2, lm1) = gmat(lm1, lm2) END DO END DO LP1 END DO END DO call timestop("define gmat") ! Calculate moments of MT functions call timestart("calc moments of MT") DO itype = 1, atoms%ntype DO l = 0, hybrid%lcutm1(itype) DO i = 1, hybrid%nindxm1(l, itype) ! note that hybrid%basm1 already contains the factor rgrid moment(i, l, itype) = intgrf(atoms%rmsh(:, itype)**(l + 1)*hybrid%basm1(:, i, l, itype), & atoms%jri, atoms%jmtd, atoms%rmsh, atoms%dx, atoms%ntype, itype, gridf) END DO END DO DO i = 1, hybrid%nindxm1(0, itype) moment2(i, itype) = intgrf(atoms%rmsh(:, itype)**3*hybrid%basm1(:, i, 0, itype), & atoms%jri, atoms%jmtd, atoms%rmsh, atoms%dx, atoms%ntype, itype, gridf) END DO END DO call timestop("calc moments of MT") call timestart("getnorm") ! Look for different qnorm = |k+G|, definition of qnrm and pqnrm. CALL getnorm(kpts, hybrid%gptm, hybrid%ngptm, hybrid%pgptm, qnrm, nqnrm, pqnrm, cell) ALLOCATE (sphbesmoment(0:hybrid%lexp, atoms%ntype, nqnrm), & olap(hybrid%maxindxm1, 0:hybrid%maxlcutm1, atoms%ntype, nqnrm), & integral(hybrid%maxindxm1, 0:hybrid%maxlcutm1, atoms%ntype, nqnrm)) sphbes = 0 sphbesmoment = 0 sphbesmoment1 = 0 olap = 0 integral = 0 ! Calculate moments of spherical Bessel functions (for (2) and (3)) (->sphbesmoment) ! Calculate overlap of spherical Bessel functions with basis functions (for (2)) (->olap) ! Calculate overlap of sphbesmoment1(r,l) with basis functions (for (2)) (->integral) ! We use sphbes(r,l) = j_l(qr) ! and sphbesmoment1(r,l) = 1/r**(l-1) * INT(0..r) r'**(l+2) * j_l(qr') dr' ! + r**(l+2) * INT(r..S) r'**(1-l) * j_l(qr') dr' . iqnrmstart = mpi%irank + 1 iqnrmstep = mpi%isize call timestop("getnorm") `````` Matthias Redies committed Jun 18, 2019 350 `````` `````` Matthias Redies committed Jun 17, 2019 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 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 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 `````` call timestart("Bessel calculation") DO iqnrm = iqnrmstart, nqnrm, iqnrmstep qnorm = qnrm(iqnrm) DO itype = 1, atoms%ntype ng = atoms%jri(itype) rdum = atoms%rmt(itype) sphbes = 0 sphbesmoment1 = 0 IF (qnorm .EQ. 0) THEN sphbesmoment(0, itype, iqnrm) = rdum**3/3 DO i = 1, ng sphbes(i, 0) = 1 sphbesmoment1(i, 0) = atoms%rmsh(i, itype)**2/3 + (rdum**2 - atoms%rmsh(i, itype)**2)/2 END DO ELSE CALL sphbessel(rarr, qnorm*rdum, hybrid%lexp + 1) DO l = 0, hybrid%lexp sphbesmoment(l, itype, iqnrm) = rdum**(l + 2)*rarr(l + 1)/qnorm END DO DO i = ng, 1, -1 rdum = atoms%rmsh(i, itype) CALL sphbessel(rarr, qnorm*rdum, hybrid%lcutm1(itype) + 1) DO l = 0, hybrid%lcutm1(itype) sphbes(i, l) = rarr(l) IF (l .NE. 0) THEN; rdum1 = -rdum**(1 - l)*rarr(l - 1) ELSE; rdum1 = -COS(qnorm*rdum)/qnorm ENDIF IF (i .EQ. ng) rarr1(l) = rdum1 sphbesmoment1(i, l) = (rdum**(l + 2)*rarr(l + 1)/rdum**(l + 1) & + (rarr1(l) - rdum1)*rdum**l)/qnorm END DO END DO END IF DO l = 0, hybrid%lcutm1(itype) DO n = 1, hybrid%nindxm1(l, itype) ! note that hybrid%basm1 already contains one factor rgrid olap(n, l, itype, iqnrm) = & intgrf(atoms%rmsh(:, itype)*hybrid%basm1(:, n, l, itype)*sphbes(:, l), & atoms%jri, atoms%jmtd, atoms%rmsh, atoms%dx, atoms%ntype, itype, gridf) integral(n, l, itype, iqnrm) = & intgrf(atoms%rmsh(:, itype)*hybrid%basm1(:, n, l, itype)*sphbesmoment1(:, l), & atoms%jri, atoms%jmtd, atoms%rmsh, atoms%dx, atoms%ntype, itype, gridf) END DO END DO END DO END DO call timestop("Bessel calculation") IF (mpi%irank == 0) THEN WRITE (6, '(18X,A)', advance='no') 'done' CALL cpu_TIME(time2) WRITE (6, '(2X,A,F8.2,A)', advance='no') '( Timing:', time2 - time1, ' )' WRITE (6, *) END IF ! ! (1) Case < MT | v | MT > ! IF (mpi%irank == 0) WRITE (6, '(A)', advance='no') '< MT | v | MT > contribution...' CALL cpu_TIME(time1) IF (ANY(calc_mt)) THEN ! (1a) r,r' in same MT call timestart("loop 1") ix = 0 iy = 0 iy0 = 0 DO itype = 1, atoms%ntype DO ineq = 1, atoms%neq(itype) ! Here the diagonal block matrices do not depend on ineq. In (1b) they do depend on ineq, though, DO l = 0, hybrid%lcutm1(itype) DO n2 = 1, hybrid%nindxm1(l, itype) ! note that hybrid%basm1 already contains the factor rgrid CALL primitivef(primf1, hybrid%basm1(:, n2, l, itype) & *atoms%rmsh(:, itype)**(l + 1), atoms%rmsh, atoms%dx, & atoms%jri, atoms%jmtd, itype, atoms%ntype) ! -itype is to enforce inward integration CALL primitivef(primf2, hybrid%basm1(:atoms%jri(itype), n2, l, itype) & /atoms%rmsh(:atoms%jri(itype), itype)**l, atoms%rmsh, atoms%dx, & atoms%jri, atoms%jmtd, -itype, atoms%ntype) primf1(:atoms%jri(itype)) = primf1(:atoms%jri(itype))/atoms%rmsh(:atoms%jri(itype), itype)**l primf2 = primf2*atoms%rmsh(:, itype)**(l + 1) DO n1 = 1, n2 integrand = hybrid%basm1(:, n1, l, itype)*(primf1 + primf2) ! call intgr0( (4*pimach())/(2*l+1)*integrand,rmsh(1,itype),dx(itype),jri(itype),mat(n2*(n2-1)/2+n1) ) mat(n2*(n2 - 1)/2 + n1) = (4*pi_const)/(2*l + 1) & *intgrf(integrand, atoms%jri, atoms%jmtd, atoms%rmsh, atoms%dx, & atoms%ntype, itype, gridf) END DO END DO ! distribute mat for m=-l,l on coulomb in block-matrix form DO M = -l, l DO n2 = 1, hybrid%nindxm1(l, itype) ix = ix + 1 iy = iy0 DO n1 = 1, n2 iy = iy + 1 i = ix*(ix - 1)/2 + iy j = n2*(n2 - 1)/2 + n1 coulomb(i, kpts%nkpt) = mat(j) END DO END DO iy0 = ix END DO END DO END DO END DO call timestop("loop 1") ! (1b) r,r' in different MT ALLOCATE (coulmat(hybrid%nbasp, hybrid%nbasp), stat=ok) IF (ok .NE. 0) STOP 'coulombmatrix: failure allocation coulmat' coulmat = 0 END IF DO ikpt = ikptmin, ikptmax ! only the first rank handles the MT-MT part call timestart("MT-MT part") IF (calc_mt(ikpt)) THEN ix = 0 ic2 = 0 DO itype2 = 1, atoms%ntype DO ineq2 = 1, atoms%neq(itype2) ic2 = ic2 + 1 lm2 = 0 DO l2 = 0, hybrid%lcutm1(itype2) DO m2 = -l2, l2 lm2 = lm2 + 1 DO n2 = 1, hybrid%nindxm1(l2, itype2) ix = ix + 1 iy = 0 ic1 = 0 lp2: DO itype1 = 1, itype2 DO ineq1 = 1, atoms%neq(itype1) ic1 = ic1 + 1 lm1 = 0 DO l1 = 0, hybrid%lcutm1(itype1) DO m1 = -l1, l1 lm1 = lm1 + 1 DO n1 = 1, hybrid%nindxm1(l1, itype1) iy = iy + 1 IF (iy .GT. ix) EXIT lp2 ! Don't cross the diagonal! rdum = (-1)**(l2 + m2)*moment(n1, l1, itype1)*moment(n2, l2, itype2)*gmat(lm1, lm2) l = l1 + l2 lm = l**2 + l + m1 - m2 + 1 idum = ix*(ix - 1)/2 + iy coulmat(iy, ix) = coulomb(idum, kpts%nkpt) & + EXP(CMPLX(0.0, 1.0)*2*pi_const* & dot_PRODUCT(kpts%bk(:, ikpt), & atoms%taual(:, ic2) - atoms%taual(:, ic1))) & *rdum*structconst(lm, ic1, ic2, ikpt) coulmat(ix, iy) = CONJG(coulmat(iy, ix)) END DO END DO END DO END DO END DO lp2 END DO END DO END DO END DO END DO IF (sym%invs) THEN !symmetrize makes the Coulomb matrix real symmetric CALL symmetrize(coulmat, hybrid%nbasp, hybrid%nbasp, 3, .FALSE., & atoms, hybrid%lcutm1, hybrid%maxlcutm1, & hybrid%nindxm1, sym) ENDIF coulomb(:hybrid%nbasp*(hybrid%nbasp + 1)/2, ikpt) = packmat(coulmat) END IF call timestop("MT-MT part") END DO IF (ANY(calc_mt)) DEALLOCATE (coulmat) IF (mpi%irank == 0) THEN WRITE (6, '(2X,A)', advance='no') 'done' CALL cpu_TIME(time2) WRITE (6, '(2X,A,F8.2,A)', advance='no') '( Timing:', time2 - time1, ' )' WRITE (6, *) END IF IF (hybrid%maxgptm .EQ. 0) GOTO 1 ! skip calculation of plane-wave contribution if mixed basis does not contain plane waves ! ! (2) Case < MT | v | PW > ! IF (mpi%irank == 0) WRITE (6, '(A)', advance='no') '< MT | v | PW > contribution...' CALL cpu_TIME(time1) ! (2a) r in MT, r' everywhere ! (2b) r,r' in same MT ! (2c) r,r' in different MT ALLOCATE (coulmat(hybrid%nbasp, hybrid%maxgptm), stat=ok) IF (ok .NE. 0) STOP 'coulombmatrix: failure allocation coulmat' coulmat = 0 `````` Matthias Redies committed Jun 18, 2019 568 `````` `````` Matthias Redies committed Jun 17, 2019 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 `````` call timestart("loop over interst.") DO ikpt = ikptmin, ikptmax !1,kpts%nkpt coulmat = 0 ! start to loop over interstitial plane waves DO igpt0 = igptmin(ikpt), igptmax(ikpt) !1,hybrid%ngptm1(ikpt) igpt = hybrid%pgptm1(igpt0, ikpt) igptp = hybrid%pgptm(igpt, ikpt) ix = hybrid%nbasp + igpt q = MATMUL(kpts%bk(:, ikpt) + hybrid%gptm(:, igptp), cell%bmat) qnorm = SQRT(SUM(q**2)) iqnrm = pqnrm(igpt, ikpt) IF (ABS(qnrm(iqnrm) - qnorm) .GT. 1d-12) then STOP 'coulombmatrix: qnorm does not equal corresponding & element in qnrm (bug?)' ! We shouldn't stop here! endif CALL harmonicsr(y1, MATMUL(kpts%bk(:, kpts%nkpt), cell%bmat), 2) CALL harmonicsr(y2, MATMUL(hybrid%gptm(:, igptp), cell%bmat), 2) CALL harmonicsr(y, q, hybrid%lexp) y1 = CONJG(y1); y2 = CONJG(y2); y = CONJG(y) iy = 0 ic = 0 DO itype = 1, atoms%ntype DO ineq = 1, atoms%neq(itype) ic = ic + 1 lm = 0 DO l = 0, hybrid%lcutm1(itype) DO M = -l, l lm = lm + 1 ! calculate sum over lm and centers for (2c) -> csum, csumf csum = 0 csumf = 0 ic1 = 0 DO itype1 = 1, atoms%ntype DO ineq1 = 1, atoms%neq(itype1) ic1 = ic1 + 1 cexp = 4*pi_const*EXP(CMPLX(0.0, 1.0)*2*pi_const & *(dot_PRODUCT(kpts%bk(:, ikpt) + hybrid%gptm(:, igptp), atoms%taual(:, ic1)) & - dot_PRODUCT(kpts%bk(:, ikpt), atoms%taual(:, ic)))) lm1 = 0 DO l1 = 0, hybrid%lexp l2 = l + l1 ! for structconst idum = 1 cdum = sphbesmoment(l1, itype1, iqnrm)*CMPLX(0.0, 1.0)**(l1)*cexp DO m1 = -l1, l1 lm1 = lm1 + 1 m2 = M - m1 ! for structconst lm2 = l2**2 + l2 + m2 + 1 ! csum = csum - idum*gmat(lm1, lm)*y(lm1)*cdum*structconst(lm2, ic, ic1, ikpt) idum = -idum ! factor (-1)*(l1+m1) END DO END DO ! add contribution of (2c) to csum and csumf coming from linear and quadratic orders of Y_lm*(G) / G * j_(l+1)(GS) IF (ikpt .EQ. 1 .AND. l .LE. 2) THEN cexp = EXP(CMPLX(0.0, 1.0)*2*pi_const*dot_PRODUCT(hybrid%gptm(:, igptp), atoms%taual(:, ic1))) & *gmat(lm, 1)*4*pi_const/cell%vol csumf(lm) = csumf(lm) - cexp*SQRT(4*pi_const)* & CMPLX(0.0, 1.0)**l*sphbesmoment(0, itype1, iqnrm)/facC(l - 1) IF (l .EQ. 0) THEN IF (igpt .NE. 1) THEN csum = csum - cexp*(sphbesmoment(0, itype1, iqnrm)*atoms%rmt(itype1)**2 - & sphbesmoment(2, itype1, iqnrm)*2.0/3)/10 ELSE csum = csum - cexp*atoms%rmt(itype1)**5/30 END IF ELSE IF (l .EQ. 1) THEN csum = csum + cexp*CMPLX(0.0, 1.0)*SQRT(4*pi_const) & *sphbesmoment(1, itype1, iqnrm)*y(lm)/3 END IF END IF END DO END DO ! add contribution of (2a) to csumf IF (ikpt .EQ. 1 .AND. igpt .EQ. 1 .AND. l .LE. 2) THEN csumf(lm) = csumf(lm) + (4*pi_const)**2*CMPLX(0.0, 1.0)**l/facC(l) END IF ! finally define coulomb idum = ix*(ix - 1)/2 cdum = (4*pi_const)**2*CMPLX(0.0, 1.0)**(l)*y(lm) & *EXP(CMPLX(0.0, 1.0)*2*pi_const & *dot_PRODUCT(hybrid%gptm(:, igptp), atoms%taual(:, ic))) DO n = 1, hybrid%nindxm1(l, itype) iy = iy + 1 IF (ikpt .EQ. 1 .AND. igpt .EQ. 1) THEN IF (l .EQ. 0) coulmat(iy, ix - hybrid%nbasp) = & -cdum*moment2(n, itype)/6/svol ! (2a) coulmat(iy, ix - hybrid%nbasp) = coulmat(iy, ix - hybrid%nbasp) & + (-cdum/(2*l + 1)*integral(n, l, itype, iqnrm) & ! (2b)& + csum*moment(n, l, itype))/svol ! (2c) ELSE coulmat(iy, ix - hybrid%nbasp) = & (cdum*olap(n, l, itype, iqnrm)/qnorm**2 & ! (2a)& - cdum/(2*l + 1)*integral(n, l, itype, iqnrm) & ! (2b)& + csum*moment(n, l, itype))/svol ! (2c) END IF END DO END DO END DO END DO END DO END DO IF (sym%invs) THEN CALL symmetrize(coulmat, hybrid%nbasp, hybrid%ngptm(ikpt), 1, .FALSE., & atoms, hybrid%lcutm1, hybrid%maxlcutm1, hybrid%nindxm1, sym) ENDIF M = hybrid%nbasp*(hybrid%nbasp + 1)/2 DO i = 1, hybrid%ngptm(ikpt) DO j = 1, hybrid%nbasp + i M = M + 1 IF (j .LE. hybrid%nbasp) coulomb(M, ikpt) = coulmat(j, i) END DO END DO END DO call timestop("loop over interst.") DEALLOCATE (coulmat, olap, integral) IF (mpi%irank == 0) THEN WRITE (6, '(2X,A)', advance='no') 'done' CALL cpu_TIME(time2) WRITE (6, '(2X,A,F8.2,A)') '( Timing:', time2 - time1, ' )' END IF ! ! (3) Case < PW | v | PW > ! IF (mpi%irank == 0) WRITE (6, '(A)', advance='no') '< PW | v | PW > contribution...' CALL cpu_TIME(time1) ! (3a) r,r' everywhere; r everywhere, r' in MT; r in MT, r' everywhere CALL cpu_TIME(time1) ! Calculate the hermitian matrix smat(i,j) = sum(a) integral(MT(a)) exp[i(Gj-Gi)r] dr call timestart("calc smat") ALLOCATE (smat(hybrid%gptmd, hybrid%gptmd)) smat = 0 DO igpt2 = 1, hybrid%gptmd DO igpt1 = 1, igpt2 g = hybrid%gptm(:, igpt2) - hybrid%gptm(:, igpt1) gnorm = gptnorm(g, cell%bmat) IF (gnorm .EQ. 0) THEN DO itype = 1, atoms%ntype smat(igpt1, igpt2) = smat(igpt1, igpt2) + atoms%neq(itype)*4*pi_const*atoms%rmt(itype)**3/3 END DO ELSE ic = 0 DO itype = 1, atoms%ntype rdum = atoms%rmt(itype)*gnorm rdum = 4*pi_const*(SIN(rdum) - rdum*COS(rdum))/gnorm**3 DO ineq = 1, atoms%neq(itype) ic = ic + 1 smat(igpt1, igpt2) = smat(igpt1, igpt2) & + rdum*EXP(CMPLX(0.0, 1.0)*2*pi_const*dot_PRODUCT(atoms%taual(:, ic), g)) END DO END DO END IF smat(igpt2, igpt1) = CONJG(smat(igpt1, igpt2)) END DO END DO call timestop("calc smat") ! Coulomb matrix, contribution (3a) call timestart("coulomb matrix") DO ikpt = ikptmin, ikptmax DO igpt0 = igptmin(ikpt), igptmax(ikpt) igpt2 = hybrid%pgptm1(igpt0, ikpt) igptp2 = hybrid%pgptm(igpt2, ikpt) ix = hybrid%nbasp + igpt2 iy = hybrid%nbasp q2 = MATMUL(kpts%bk(:, ikpt) + hybrid%gptm(:, igptp2), cell%bmat) rdum2 = SUM(q2**2) IF (rdum2 .NE. 0) rdum2 = 4*pi_const/rdum2 DO igpt1 = 1, igpt2 igptp1 = hybrid%pgptm(igpt1, ikpt) iy = iy + 1 q1 = MATMUL(kpts%bk(:, ikpt) + hybrid%gptm(:, igptp1), cell%bmat) idum = ix*(ix - 1)/2 + iy rdum1 = SUM(q1**2) IF (rdum1 .NE. 0) rdum1 = 4*pi_const/rdum1 IF (ikpt .EQ. 1) THEN IF (igpt1 .NE. 1) THEN coulomb(idum, 1) = -smat(igptp1, igptp2)*rdum1/cell%vol END IF IF (igpt2 .NE. 1) THEN coulomb(idum, 1) = coulomb(idum, 1) - smat(igptp1, igptp2)*rdum2/cell%vol END IF ELSE coulomb(idum, ikpt) = -smat(igptp1, igptp2)*(rdum1 + rdum2)/cell%vol END IF END DO IF (ikpt .NE. 1 .OR. igpt2 .NE. 1) THEN ! coulomb(idum, ikpt) = coulomb(idum, ikpt) + rdum2 ! diagonal term END IF ! END DO END DO call timestop("coulomb matrix") ! (3b) r,r' in different MT call timestart("loop 4:") DO ikpt = ikptmin, ikptmax!1,kpts%nkpt ! group together quantities which depend only on l,m and igpt -> carr2a ALLOCATE (carr2a((hybrid%lexp + 1)**2, hybrid%maxgptm), carr2b(atoms%nat, hybrid%maxgptm)) carr2a = 0; carr2b = 0 DO igpt = 1, hybrid%ngptm(ikpt) igptp = hybrid%pgptm(igpt, ikpt) iqnrm = pqnrm(igpt, ikpt) q = MATMUL(kpts%bk(:, ikpt) + hybrid%gptm(:, igptp), cell%bmat) CALL harmonicsr(y, q, hybrid%lexp) y = CONJG(y) lm = 0 DO l = 0, hybrid%lexp DO M = -l, l lm = lm + 1 carr2a(lm, igpt) = 4*pi_const*CMPLX(0.0, 1.0)**(l)*y(lm) END DO END DO DO ic = 1, atoms%nat carr2b(ic, igpt) = EXP(-CMPLX(0.0, 1.0)*2*pi_const* & dot_PRODUCT(kpts%bk(:, ikpt) + hybrid%gptm(:, igptp), atoms%taual(:, ic))) END DO END DO !finally we can loop over the plane waves (G: igpt1,igpt2) call timestart("loop over plane waves") ALLOCATE (carr2(atoms%nat, (hybrid%lexp + 1)**2), & structconst1(atoms%nat, (2*hybrid%lexp + 1)**2)) carr2 = 0; structconst1 = 0 DO igpt0 = igptmin(ikpt), igptmax(ikpt)!1,hybrid%ngptm1(ikpt) igpt2 = hybrid%pgptm1(igpt0, ikpt) ix = hybrid%nbasp + igpt2 igptp2 = hybrid%pgptm(igpt2, ikpt) iqnrm2 = pqnrm(igpt2, ikpt) ic2 = 0 carr2 = 0 DO itype2 = 1, atoms%ntype DO ineq2 = 1, atoms%neq(itype2) ic2 = ic2 + 1 cexp = CONJG(carr2b(ic2, igpt2)) lm2 = 0 DO ic1 = 1, atoms%nat structconst1(ic1, :) = structconst(:, ic1, ic2, ikpt) END DO DO l2 = 0, hybrid%lexp idum = 1 DO m2 = -l2, l2 lm2 = lm2 + 1 cdum = idum*sphbesmoment(l2, itype2, iqnrm2)*cexp*carr2a(lm2, igpt2) IF (cdum .NE. 0) THEN lm1 = 0 DO l1 = 0, hybrid%lexp l = l1 + l2 M = -l1 - m2 !first loop of m1 lm = l**2 + l + M DO m1 = -l1, l1 lm1 = lm1 + 1 lm = lm + 1 cdum1 = cdum*gmat(lm1, lm2) DO ic1 = 1, atoms%nat carr2(ic1, lm1) = carr2(ic1, lm1) + cdum1*structconst1(ic1, lm) END DO END DO END DO END IF idum = -idum !factor (-1)**(l+M) END DO END DO END DO END DO iy = hybrid%nbasp DO igpt1 = 1, igpt2 iy = iy + 1 igptp1 = hybrid%pgptm(igpt1, ikpt) iqnrm1 = pqnrm(igpt1, ikpt) csum = 0 ic = 0 DO itype = 1, atoms%ntype DO ineq = 1, atoms%neq(itype) ic = ic + 1 cexp = carr2b(ic, igpt1) lm = 0 DO l = 0, hybrid%lexp cdum = cexp*sphbesmoment(l, itype, iqnrm1) DO M = -l, l lm = lm + 1 csum = csum + cdum*carr2(ic, lm)*CONJG(carr2a(lm, igpt1)) ! for coulomb END DO END DO END DO END DO idum = ix*(ix - 1)/2 + iy coulomb(idum, ikpt) = coulomb(idum, ikpt) + csum/cell%vol END DO END DO DEALLOCATE (carr2, carr2a, carr2b, structconst1) call timestop("loop over plane waves") END DO !ikpt call timestop("loop 4:") ! Add corrections from higher orders in (3b) to coulomb(:,1) ! (1) igpt1 > 1 , igpt2 > 1 (finite G vectors) call timestart("add corrections from higher orders") rdum = (4*pi_const)**(1.5d0)/cell%vol**2*gmat(1, 1) DO igpt0 = 1, hybrid%ngptm1(1) igpt2 = hybrid%pgptm1(igpt0, 1); IF (igpt2 == 1) CYCLE ix = hybrid%nbasp + igpt2 iqnrm2 = pqnrm(igpt2, 1) igptp2 = hybrid%pgptm(igpt2, 1) q2 = MATMUL(hybrid%gptm(:, igptp2), cell%bmat) qnorm2 = SQRT(SUM(q2**2)) iy = hybrid%nbasp + 1 DO igpt1 = 2, igpt2 iy = iy + 1 idum = ix*(ix - 1)/2 + iy iqnrm1 = pqnrm(igpt1, 1) igptp1 = hybrid%pgptm(igpt1, 1) q1 = MATMUL(hybrid%gptm(:, igptp1), cell%bmat) qnorm1 = SQRT(SUM(q1**2)) rdum1 = dot_PRODUCT(q1, q2)/(qnorm1*qnorm2) ic1 = 0 DO itype1 = 1, atoms%ntype DO ineq1 = 1, atoms%neq(itype1) ic1 = ic1 + 1 ic2 = 0 DO itype2 = 1, atoms%ntype DO ineq2 = 1, atoms%neq(itype2) ic2 = ic2 + 1 cdum = EXP(CMPLX(0.0, 1.0)*2*pi_const* & (-dot_PRODUCT(hybrid%gptm(:, igptp1), atoms%taual(:, ic1)) & + dot_PRODUCT(hybrid%gptm(:, igptp2), atoms%taual(:, ic2)))) coulomb(idum, 1) = coulomb(idum, 1) + rdum*cdum*( & -sphbesmoment(1, itype1, iqnrm1) & *sphbesmoment(1, itype2, iqnrm2)*rdum1/3 & - sphbesmoment(0, itype1, iqnrm1) & *sphbesmoment(2, itype2, iqnrm2)/6 & - sphbesmoment(2, itype1, iqnrm1) & *sphbesmoment(0, itype2, iqnrm2)/6 & + sphbesmoment(0, itype1, iqnrm1) & *sphbesmoment(1, itype2, iqnrm2)/qnorm2/2 & + sphbesmoment(1, itype1, iqnrm1) & *sphbesmoment(0, itype2, iqnrm2)/qnorm1/2) END DO END DO END DO END DO END DO END DO ! (2) igpt1 = 1 , igpt2 > 1 (first G vector vanishes, second finite) iy = hybrid%nbasp + 1 DO igpt0 = 1, hybrid%ngptm1(1) igpt2 = hybrid%pgptm1(igpt0, 1); IF (igpt2 == 1) CYCLE ix = hybrid%nbasp + igpt2 iqnrm2 = pqnrm(igpt2, 1) igptp2 = hybrid%pgptm(igpt2, 1) qnorm2 = qnrm(iqnrm2) idum = ix*(ix - 1)/2 + iy DO itype1 = 1, atoms%ntype DO ineq1 = 1, atoms%neq(itype1) ic2 = 0 DO itype2 = 1, atoms%ntype DO ineq2 = 1, atoms%neq(itype2) ic2 = ic2 + 1 cdum = EXP(CMPLX(0.0, 1.0)*2*pi_const*dot_PRODUCT(hybrid%gptm(:, igptp2), atoms%taual(:, ic2))) coulomb(idum, 1) = coulomb(idum, 1) & + rdum*cdum*atoms%rmt(itype1)**3*( & +sphbesmoment(0, itype2, iqnrm2)/30*atoms%rmt(itype1)**2 & - sphbesmoment(2, itype2, iqnrm2)/18 & + sphbesmoment(1, itype2, iqnrm2)/6/qnorm2) END DO END DO END DO END DO END DO ! (2) igpt1 = 1 , igpt2 = 1 (vanishing G vectors) iy = hybrid%nbasp + 1 ix = hybrid%nbasp + 1 idum = ix*(ix - 1)/2 + iy DO itype1 = 1, atoms%ntype DO ineq1 = 1, atoms%neq(itype1) DO itype2 = 1, atoms%ntype DO ineq2 = 1, atoms%neq(itype2) coulomb(idum, 1) = coulomb(idum, 1) & + rdum*atoms%rmt(itype1)**3*atoms%rmt(itype2)**3* & (atoms%rmt(itype1)**2 + atoms%rmt(itype2)**2)/90 END DO END DO END DO END DO call timestop("add corrections from higher orders") ! (3c) r,r' in same MT ! Calculate sphbesintegral call timestart("sphbesintegral") ALLOCATE (sphbes0(-1:hybrid%lexp + 2, atoms%ntype, nqnrm),& & carr2((hybrid%lexp + 1)**2, hybrid%maxgptm)) sphbes0 = 0; carr2 = 0 DO iqnrm = 1, nqnrm DO itype = 1, atoms%ntype rdum = qnrm(iqnrm)*atoms%rmt(itype) CALL sphbessel(sphbes0(0, itype, iqnrm), rdum, hybrid%lexp + 2) IF (rdum .NE. 0) sphbes0(-1, itype, iqnrm) = COS(rdum)/rdum END DO END DO call timestop("sphbesintegral") l_warn = (mpi%irank == 0) call timestart("loop 2") DO ikpt = ikptmin, ikptmax!1,nkpt DO igpt = 1, hybrid%ngptm(ikpt) igptp = hybrid%pgptm(igpt, ikpt) q = MATMUL(kpts%bk(:, ikpt) + hybrid%gptm(:, igptp), cell%bmat) CALL harmonicsr(carr2(:, igpt), q, hybrid%lexp) END DO DO igpt0 = igptmin(ikpt), igptmax(ikpt)!1,hybrid%ngptm1(ikpt) igpt2 = hybrid%pgptm1(igpt0, ikpt) ix = hybrid%nbasp + igpt2 igptp2 = hybrid%pgptm(igpt2, ikpt) iqnrm2 = pqnrm(igpt2, ikpt) q2 = MATMUL(kpts%bk(:, ikpt) + hybrid%gptm(:, igptp2), cell%bmat) y2 = CONJG(carr2(:, igpt2)) iy = hybrid%nbasp DO igpt1 = 1, igpt2 iy = iy + 1 igptp1 = hybrid%pgptm(igpt1, ikpt) iqnrm1 = pqnrm(igpt1, ikpt) q1 = MATMUL(kpts%bk(:, ikpt) + hybrid%gptm(:, igptp1), cell%bmat) y1 = carr2(:, igpt1) cexp1 = 0 ic = 0 DO itype = 1, atoms%ntype DO ineq = 1, atoms%neq(itype) ic = ic + 1 cexp1(itype) = cexp1(itype) + & EXP(CMPLX(0.0, 1.0)*2*pi_const*dot_PRODUCT( & (hybrid%gptm(:, igptp2) - hybrid%gptm(:, igptp1)), atoms%taual(:, ic))) ENDDO ENDDO lm = 0 cdum = 0 DO l = 0, hybrid%lexp cdum1 = 0 DO itype = 1, atoms%ntype cdum1 = cdum1 + cexp1(itype)*sphbessel_integral( & atoms, itype, qnrm, nqnrm, & iqnrm1, iqnrm2, l, hybrid, & sphbes0, l_warn, l_warned) & /(2*l + 1) l_warn = l_warn .AND. .NOT. l_warned ! only warn once END DO DO M = -l, l lm = lm + 1 cdum = cdum + cdum1*y1(lm)*y2(lm) ENDDO ENDDO idum = ix*(ix - 1)/2 + iy coulomb(idum, ikpt) = coulomb(idum, ikpt) + (4*pi_const)**3*cdum/cell%vol END DO END DO END DO call timestop("loop 2") DEALLOCATE (carr2) IF (mpi%irank == 0) THEN WRITE (6, '(2X,A)', advance='no') 'done' CALL cpu_TIME(time2) WRITE (6, '(2X,A,F8.2,A)') '( Timing:', time2 - time1, ' )' END IF ! ! Symmetry-equivalent G vectors ! `````` Gregor Michalicek committed Jun 25, 2018 1065 ``````#ifndef CPP_NOCOULSYM `````` Daniel Wortmann committed Jun 21, 2017 1066 `````` `````` Matthias Redies committed Jun 17, 2019 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 `````` IF (mpi%irank == 0) WRITE (6, '(A)', advance='no') 'Symm.-equiv. matrix elements...' CALL cpu_TIME(time1) ! All elements are needed so send all data to all processes treating the ! respective k-points ALLOCATE (carr2(hybrid%maxbasm1, 2), iarr(hybrid%maxgptm)) ALLOCATE (nsym_gpt(hybrid%gptmd, kpts%nkpt), & sym_gpt(MAXVAL(nsym1), hybrid%gptmd, kpts%nkpt)) nsym_gpt = 0; sym_gpt = 0 call timestart("loop 3") DO ikpt = ikptmin, ikptmax carr2 = 0; iarr = 0 iarr(hybrid%pgptm1(:hybrid%ngptm1(ikpt), ikpt)) = 1 DO igpt0 = 1, hybrid%ngptm1(ikpt) !igptmin(ikpt),igptmax(ikpt) lsym = ((igptmin(ikpt) <= igpt0) .AND. & (igptmax(ikpt) >= igpt0)) igpt2 = hybrid%pgptm1(igpt0, ikpt) j = (hybrid%nbasp + igpt2 - 1)*(hybrid%nbasp + igpt2)/2 i = hybrid%nbasp + igpt2 carr2(1:i, 2) = coulomb(j + 1:j + i, ikpt) j = j + i DO i = hybrid%nbasp + igpt2 + 1, nbasm1(ikpt) j = j + i - 1 IF (sym%invs) THEN carr2(i, 2) = coulomb(j, ikpt) ELSE carr2(i, 2) = CONJG(coulomb(j, ikpt)) ENDIF END DO IF (lsym) THEN ic = 1 sym_gpt(ic, igpt0, ikpt) = igpt2 END IF DO isym1 = 2, nsym1(ikpt) isym = sym1(isym1, ikpt) CALL bramat_trafo( & carr2(:, 1), igpt1, & carr2(:, 2), igpt2, ikpt, isym, .FALSE., POINTER(ikpt, :, :, :), & sym, rrot(:, :, isym), invrrot(:, :, isym), hybrid, & kpts, hybrid%maxlcutm1, atoms, hybrid%lcutm1, & hybrid%nindxm1, hybrid%maxindxm1, dwgn(:, :, :, isym), & hybrid%nbasp, nbasm1) IF (iarr(igpt1) .EQ. 0) THEN CALL bramat_trafo( & carr2(:, 1), igpt1, & carr2(:, 2), igpt2, ikpt, isym, .TRUE., POINTER(ikpt, :, :, :), & sym, rrot(:, :, isym), invrrot(:, :, isym), hybrid, & kpts, hybrid%maxlcutm1, atoms, hybrid%lcutm1, & hybrid%nindxm1, hybrid%maxindxm1, & dwgn(:, :, :, isym), hybrid%nbasp, nbasm1) l = (hybrid%nbasp + igpt1 - 1)*(hybrid%nbasp + igpt1)/2 coulomb(l + 1:l + hybrid%nbasp + igpt1, ikpt) = carr2(:hybrid%nbasp + igpt1, 1) iarr(igpt1) = 1 IF (lsym) THEN ic = ic + 1 sym_gpt(ic, igpt0, ikpt) = igpt1 END IF END IF END DO nsym_gpt(igpt0, ikpt) = ic END DO ! igpt0 END DO ! ikpt call timestop("loop 3") call timestart("gap 1:") DEALLOCATE (carr2, iarr, hybrid%pgptm1) IF (mpi%irank == 0) THEN WRITE (6, '(2X,A)', advance='no') 'done' CALL cpu_TIME(time2) WRITE (6, '(2X,A,F8.2,A)') '( Timing:', time2 - time1, ' )' END IF ! no symmetry used `````` Gregor Michalicek committed Jun 25, 2018 1139 ``````#else `````` Daniel Wortmann committed Jun 21, 2017 1140 `````` `````` Matthias Redies committed Jun 17, 2019 1141 1142 1143 1144 1145 `````` ALLOCATE (nsym_gpt(hybrid%gptmd, kpts%nkpt), sym_gpt(1, hybrid%gptmd, kpts%nkpt)) nsym_gpt = 1 DO ikpt = 1, kpts%nkpt sym_gpt(1, :, ikpt) = (/(igpt0, igpt0=1, hybrid%gptmd)/) END DO `````` Daniel Wortmann committed Jun 21, 2017 1146 `````` `````` Gregor Michalicek committed Jun 25, 2018 1147 ``````#endif `````` Daniel Wortmann committed Jun 21, 2017 1148 `````` `````` Matthias Redies committed Jun 17, 2019 1149 1150 1151 1152 1153 1154 1155 1156 ``````1 DEALLOCATE (qnrm, pqnrm) CALL cpu_TIME(time1) IF (xcpot%is_name("hse") .OR. xcpot%is_name("vhse")) THEN ! ! The HSE functional is realized subtracting erf/r from ! the normal Coulomb matrix ! `````` Daniel Wortmann committed Jun 21, 2017 1157 ``````#ifdef CPP_NOSPMVEC `````` Matthias Redies committed Jun 17, 2019 1158 1159 1160 1161 1162 `````` CALL change_coulombmatrix( & atoms, kpts, kpts, kpts%nkpt, & cell, cell, hybrid%lcutm1, hybrid%maxlcutm1, & hybrid%nindxm1, hybrid%maxindxm1, hybrid, & hybrid%basm1, hybrid%maxbasm1, nbasm1, sym, mpi, & `````` Daniel Wortmann committed Jul 14, 2017 1163 `````` coulomb) `````` Daniel Wortmann committed Jun 21, 2017 1164 ``````#endif `````` Matthias Redies committed Jun 17, 2019 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 `````` ELSE IF (ikptmin == 1) CALL subtract_sphaverage(sym, cell, atoms, kpts, hybrid, nbasm1, gridf, coulomb) END IF ! transform Coulomb matrix to the biorthogonal set IF (mpi%irank == 0) WRITE (6, '(A)', advance='no') 'Transform to biorthogonal set...' CALL cpu_TIME(time1) call timestop("gap 1:") call timestart("calc eigenvalues olap_pw") DO ikpt = ikptmin, ikptmax !calculate IR overlap-matrix CALL olapm%alloc(sym%invs, hybrid%ngptm(ikpt), hybrid%ngptm(ikpt), 0.0) CALL olap_pw(olapm, hybrid%gptm(:, hybrid%pgptm(:hybrid%ngptm(ikpt), ikpt)), hybrid%ngptm(ikpt), atoms, cell) ! !calculate eigenvalues of olapm ! ALLOCATE( eval(ngptm(ikpt)),evec(ngptm(ikpt),ngptm(ikpt)) ) ! CALL diagonalize(evec,eval,olapm) ! ! ! ! ! small eigenvalues lead to inaccuries in the inversion ! ! however it seems that these do not play an important role ! ! for the HF exchange ! ! thus we do not do a SingularValueDecomposition ! ! ! ! IF( any(eval .le. 1E-06 ) ) THEN ! ! WRITE(*,*) count( eval .le. 1E-06 ) ! ! WRITE(*,*) 'eval .le. 1E-06' ! ! ALLOCATE( involapm(ngptm(ikpt),ngptm(ikpt)) ) ! olapm = 0 ! DO i = 1,ngptm(ikpt) ! IF( eval(i) .le. 1E-06) CYCLE ! olapm(i,i) = 1/eval(i) ! END DO ! ! ALLOCATE( invevec(ngptm(ikpt),ngptm(ikpt)) ) ! if (sym%invs) then ! invevec = transpose(evec) ! else ! invevec = conjg( transpose(evec) ) ! endif ! ! olapm = matmul(evec,matmul(olapm,invevec) ) ! ! DEALLOCATE(invevec)!,involapm) ! ELSE !calculate inverse overlap-matrix CALL olapm%inverse() ! END IF !unpack matrix coulomb CALL coulhlp%from_packed(sym%invs, nbasm1(ikpt), REAL(coulomb(:, ikpt)), coulomb(:, ikpt)) if (olapm%l_real) THEN !multiply with inverse olap from right hand side coulhlp%data_r(:, hybrid%nbasp + 1:) = MATMUL(coulhlp%data_r(:, hybrid%nbasp + 1:), olapm%data_r) !multiply with inverse olap from left side coulhlp%data_r(hybrid%nbasp + 1:, :) = MATMUL(olapm%data_r, coulhlp%data_r(hybrid%nbasp + 1:, :)) else !multiply with inverse olap from right hand side coulhlp%data_c(:, hybrid%nbasp + 1:) = MATMUL(coulhlp%data_c(:, hybrid%nbasp + 1:), olapm%data_c) !multiply with inverse olap from left side coulhlp%data_c(hybrid%nbasp + 1:, :) = MATMUL(olapm%data_c, coulhlp%data_c(hybrid%nbasp + 1:, :)) end if coulomb(:(nbasm1(ikpt)*(nbasm1(ikpt) + 1))/2, ikpt) = coulhlp%to_packed() END DO call timestop("calc eigenvalues olap_pw") IF (mpi%irank == 0) THEN WRITE (6, '(1X,A)', advance='no') 'done' CALL cpu_TIME(time2) WRITE (6, '(2X,A,F8.2,A)') '( Timing:', time2 - time1, ' )' END IF !call plot_coulombmatrix() -> code was shifted to plot_coulombmatrix.F90 IF (mpi%irank == 0) WRITE (6, '(A)', advance='no') 'Writing of data to file...' CALL cpu_TIME(time1) `````` Daniel Wortmann committed Jun 21, 2017 1246 ``````#if( !defined CPP_NOSPMVEC && !defined CPP_IRAPPROX ) `````` Matthias Redies committed Jun 17, 2019 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 `````` ! ! rearrange coulomb matrix ! ALLOCATE (coulomb_mt1(hybrid%maxindxm1 - 1, hybrid%maxindxm1 - 1, 0:hybrid%maxlcutm1, atoms%ntype, 1)) ic = (hybrid%maxlcutm1 + 1)**2*atoms%nat idum = ic + hybrid%maxgptm idum = (idum*(idum + 1))/2 if (sym%invs) THEN ALLOCATE (coulomb_mt2_r(hybrid%maxindxm1 - 1, -hybrid%maxlcutm1:hybrid%maxlcutm1, 0:hybrid%maxlcutm1 + 1, atoms%nat, 1)) ALLOCATE (coulomb_mt3_r(hybrid%maxindxm1 - 1, atoms%nat, atoms%nat, 1)) `````` Gregor Michalicek committed Jun 25, 2018 1258 ``````#ifdef CPP_IRCOULOMBAPPROX `````` Matthias Redies committed Jun 17, 2019 1259 1260 1261 `````` ALLOCATE (coulomb_mtir_r(ic, ic + hybrid%maxgptm, 1)) coulomb_mtir_r = 0 ALLOCATE (coulombp_mtir_r(0, 0)) `````` Gregor Michalicek committed Jun 25, 2018 1262 ``````#else `````` Matthias Redies committed Jun 17, 2019 1263 1264 `````` ALLOCATE (coulomb_mtir_r(ic + hybrid%maxgptm, ic + hybrid%maxgptm, 1)) ALLOCATE (coulombp_mtir_r(idum, 1)) `````` Gregor Michalicek committed Jun 25, 2018 1265 ``````#endif `````` Matthias Redies committed Jun 17, 2019 1266 1267 1268 `````` else ALLOCATE (coulomb_mt2_c(hybrid%maxindxm1 - 1, -hybrid%maxlcutm1:hybrid%maxlcutm1, 0:hybrid%maxlcutm1 + 1, atoms%nat, 1)) ALLOCATE (coulomb_mt3_c(hybrid%maxindxm1 - 1, atoms%nat, atoms%nat, 1)) `````` Gregor Michalicek committed Jun 25, 2018 1269 ``````#ifdef CPP_IRCOULOMBAPPROX `````` Matthias Redies committed Jun 17, 2019 1270 1271 `````` ALLOCATE (coulomb_mtir_c(ic, ic + hybrid%maxgptm, 1)) ALLOCATE (coulombp_mtir_c(0, 0)) `````` Gregor Michalicek committed Jun 25, 2018 1272 ``````#else `````` Matthias Redies committed Jun 17, 2019 1273 1274 `````` ALLOCATE (coulomb_mtir_c(ic + hybrid%maxgptm, ic + hybrid%maxgptm, 1)) ALLOCATE (coulombp_mtir_c(idum, 1)) `````` Gregor Michalicek committed Jun 25, 2018 1275 ``````#endif `````` Matthias Redies committed Jun 17, 2019 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 `````` endif call timestart("loop bla") DO ikpt = ikptmin, ikptmax ikpt0 = 1 ikpt1 = 1 ! initialize arrays if (sym%invs) THEN coulomb_mt1 = 0; coulomb_mt2_r = 0 coulomb_mt3_r = 0; coulombp_mtir_r = 0 else coulomb_mt1 = 0; coulomb_mt2_c = 0 coulomb_mt3_c = 0; coulombp_mtir_c = 0 endif ! unpack coulomb into coulhlp call coulhlp%from_packed(sym%invs, nbasm1(ikpt), real(coulomb(:, ikpt)), coulomb(:, ikpt)) ! only one processor per k-point calculates MT convolution IF (calc_mt(ikpt)) THEN ! ! store m-independent part of Coulomb matrix in MT spheres ! in coulomb_mt1(:hybrid%nindxm1(l,itype)-1,:hybrid%nindxm1(l,itype)-1,l,itype) ! call timestart("m-indep. part of coulomb mtx") indx1 = 0 DO itype = 1, atoms%ntype DO ineq = 1, atoms%neq(itype) DO l = 0, hybrid%lcutm1(itype) IF (ineq == 1) THEN DO n = 1, hybrid%nindxm1(l, itype) - 1 if (coulhlp%l_real) THEN coulomb_mt1(n, 1:hybrid%nindxm1(l, itype) - 1, l, itype, ikpt0) & = coulhlp%data_r(indx1 + n, indx1 + 1:indx1 + hybrid%nindxm1(l, itype) - 1) else coulomb_mt1(n, 1:hybrid%nindxm1(l, itype) - 1, l, itype, ikpt0) & = coulhlp%data_c(indx1 + n, indx1 + 1:indx1 + hybrid%nindxm1(l, itype) - 1) end if END DO END IF indx1 = indx1 + (2*l + 1)*hybrid%nindxm1(l, itype) END DO END DO END DO call timestop("m-indep. part of coulomb mtx") ! ! store m-dependent and atom-dependent part of Coulomb matrix in MT spheres ! in coulomb_mt2(:hybrid%nindxm1(l,itype)-1,-l:l,l,iatom) ! call timestart("m-dep. part of coulomb mtx") indx1 = 0 iatom = 0 DO itype = 1, atoms%ntype DO ineq = 1, atoms%neq(itype) iatom = iatom + 1 DO l = 0, hybrid%lcutm1(itype) DO M = -l, l if (coulhlp%l_real) THEN coulomb_mt2_r(:hybrid%nindxm1(l, itype) - 1, M, l, iatom, ikpt0) & = coulhlp%data_r(indx1 + 1:indx1 + hybrid%nindxm1(l, itype) - 1, indx1 + hybrid%nindxm1(l, itype)) else coulomb_mt2_c(:hybrid%nindxm1(l, itype) - 1, M, l, iatom, ikpt0) & = coulhlp%data_c(indx1 + 1:indx1 + hybrid%nindxm1(l, itype) - 1, indx1 + hybrid%nindxm1(l, itype)) endif indx1 = indx1 + hybrid%nindxm1(l, itype) END DO END DO END DO END DO call timestop("m-dep. part of coulomb mtx") ! ! due to the subtraction of the divergent part at the Gamma point ! additional contributions occur ! call timestart("gamma point treatment") IF (ikpt .EQ. 1) THEN ! ! store the contribution of the G=0 plane wave with the MT l=0 functions in ! coulomb_mt2(:hybrid%nindxm1(l=0,itype),0,hybrid%maxlcutm1+1,iatom) ! ic = 0 iatom = 0 DO itype = 1, atoms%ntype DO ineq = 1, atoms%neq(itype) iatom = iatom + 1 DO n = 1, hybrid%nindxm1(0, itype) - 1 if (coulhlp%l_real) THEN coulomb_mt2_r(n, 0, hybrid%maxlcutm1 + 1, iatom, ikpt0) = coulhlp%data_r(ic + n, hybrid%nbasp + 1) else coulomb_mt2_c(n, 0, hybrid%maxlcutm1 + 1, iatom, ikpt0) = coulhlp%data_c(ic + n, hybrid%nbasp + 1) endif END DO ic = ic + SUM((/((2*l + 1)*hybrid%nindxm1(l, itype), l=0, hybrid%lcutm1(itype))/)) END DO END DO ! ! store the contributions between the MT s-like functions at atom1 and ! and the constant function at a different atom2 ! iatom = 0 ic = 0 DO itype = 1, atoms%ntype ishift = SUM((/((2*l + 1)*hybrid%nindxm1(l, itype), l=0, hybrid%lcutm1(itype))/)) DO ineq = 1, atoms%neq(itype) iatom = iatom + 1 ic1 = ic + hybrid%nindxm1(0, itype) iatom1 = 0 ic2 = 0 DO itype1 = 1, atoms%ntype ishift1 = SUM((/((2*l1 + 1)*hybrid%nindxm1(l1, itype1), l1=0, hybrid%lcutm1(itype1))/)) DO ineq1 = 1, atoms%neq(itype1) iatom1 = iatom1 + 1 ic3 = ic2 + 1 ic4 = ic3 + hybrid%nindxm1(0, itype1) - 2 IF (sym%invs) THEN coulomb_mt3_r(:hybrid%nindxm1(0, itype1) - 1, iatom, iatom1, ikpt0) = coulhlp%data_r(ic1, ic3:ic4) ELSE coulomb_mt3_c(:hybrid%nindxm1(0, itype1) - 1, iatom, iatom1, ikpt0) & = CONJG(coulhlp%data_c(ic1, ic3:ic4)) ENDIF ic2 = ic2 + ishift1 END DO END DO ic = ic + ishift END DO END DO !test iatom = 0 DO itype = 1, atoms%ntype DO ineq = 1, atoms%neq(itype) iatom = iatom + 1 if (sym%invs) THEN IF (MAXVAL(ABS(coulomb_mt2_r(:hybrid%nindxm1(0, itype) - 1, 0, 0, & iatom, ikpt0) & - coulomb_mt3_r(:hybrid%nindxm1(0, itype) - 1, iatom, & iatom, ikpt0))) & .GT. 1E-08) & call judft_error('coulombmatrix: coulomb_mt2 and coulomb_mt3 are inconsistent') else IF (MAXVAL(ABS(coulomb_mt2_c(:hybrid%nindxm1(0, itype) - 1, 0, 0, & iatom, ikpt0) & - coulomb_mt3_c(:hybrid%nindxm1(0, itype) - 1, iatom, & iatom, ikpt0))) & .GT. 1E-08) & `````` Daniel Wortmann committed Jul 14, 2017 1432 `````` call judft_error('coulombmatrix: coulomb_mt2 and coulomb_mt3 are inconsistent') `````` Matthias Redies committed Jun 17, 2019 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 `````` endif END DO END DO END IF call timestop("gamma point treatment") END IF ! calc_mt ! ! add the residual MT contributions, i.e. those functions with an moment, ! to the matrix coulomb_mtir, which is fully occupied ! call timestart("residual MT contributions") ic = 0 DO itype = 1, atoms%ntype DO ineq = 1, atoms%neq(itype) DO l = 0, hybrid%lcutm1(itype) DO M = -l, l ic = ic + 1 END DO END DO END DO END DO indx1 = 0; indx2 = 0; indx3 = 0; indx4 = 0 DO itype = 1, atoms%ntype DO ineq = 1, atoms%neq(itype) DO l = 0, hybrid%lcutm1(itype) DO M = -l, l indx1 = indx1 + 1 indx3 = indx3 + hybrid%nindxm1(l, itype) indx2 = 0 indx4 = 0 DO itype1 = 1, atoms%ntype DO ineq1 = 1, atoms%neq(itype1) DO l1 = 0, hybrid%lcutm1(itype1) DO m1 = -l1, l1 indx2 = indx2 + 1 indx4 = indx4 + hybrid%nindxm1(l1, itype1) IF (indx4 .LT. indx3) CYCLE IF (calc_mt(ikpt)) THEN IF (sym%invs) THEN coulomb_mtir_r(indx1, indx2, ikpt1) = coulhlp%data_r(indx3, indx4) coulomb_mtir_r(indx2, indx1, ikpt1) = coulomb_mtir_r(indx1, indx2, ikpt1) ELSE coulomb_mtir_c(indx1, indx2, ikpt1) = coulhlp%data_c(indx3, indx4) coulomb_mtir_c(indx2, indx1, ikpt1) = CONJG(coulomb_mtir_c(indx1, indx2, ikpt1)) ENDIF END IF END DO END DO END DO END DO DO igpt = 1, hybrid%ngptm(ikpt) indx2 = indx2 + 1 IF (sym%invs) THEN coulomb_mtir_r(indx1, indx2, ikpt1) = coulhlp%data_r(indx3, hybrid%nbasp + igpt) `````` Daniel Wortmann committed Jun 21, 2017 1492 ``````#if !defined CPP_IRCOULOMBAPPROX `````` Matthias Redies committed Jun 17, 2019 1493 `````` coulomb_mtir_r(indx2, indx1, ikpt1) = coulomb_mtir_r(indx1, indx2, ikpt1) `````` Daniel Wortmann committed Jun 21, 2017 1494 ``````#endif `````` Matthias Redies committed Jun 17, 2019 1495 1496 `````` ELSE coulomb_mtir_c(indx1, indx2, ikpt1) = coulhlp%data_c(indx3, hybrid%nbasp + igpt) `````` Daniel Wortmann committed Jul 14, 2017 1497 ``````#if !defined CPP_IRCOULOMBAPPROX `````` Matthias Redies committed Jun 17, 2019 1498 `````` coulomb_mtir_c(indx2, indx1, ikpt1) = CONJG(coulomb_mtir_c(indx1, indx2, ikpt1)) `````` Daniel Wortmann committed Jun 21, 2017 1499 ``````#endif `````` Matthias Redies committed Jun 17, 2019 1500 `````` ENDIF `````` Daniel Wortmann committed Jun 21, 2017 1501 `````` `````` Matthias Redies committed Jun 17, 2019 1502 `````` END DO `````` Daniel Wortmann committed Jul 14, 2017 1503 `````` `````` Matthias Redies committed Jun 17, 2019 1504 1505 1506 1507 1508 `````` END DO END DO END DO END DO call timestop("residual MT contributions") `````` Daniel Wortmann committed Jun 21, 2017 1509 `````` `````` Matthias Redies committed Jun 17, 2019 1510 `````` IF (indx1 .NE. ic) STOP 'coulombmatrix: error index counting' `````` Daniel Wortmann committed Jun 21, 2017 1511 `````` `````` Matthias Redies committed Jun 17, 2019 1512 1513 1514 `````` ! ! add ir part to the matrix coulomb_mtir ! `````` Gregor Michalicek committed Jun 25, 2018 1515 ``````#ifndef CPP_IRCOULOMBAPPROX `````` Matthias Redies committed Jun 17, 2019 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 `````` if (sym%invs) THEN coulomb_mtir_r(ic + 1:ic + hybrid%ngptm(ikpt), ic + 1:ic + hybrid%ngptm(ikpt), ikpt1) & = coulhlp%data_r(hybrid%nbasp + 1:nbasm1(ikpt), hybrid%nbasp + 1:nbasm1(ikpt)) ic2 = indx1 + hybrid%ngptm(ikpt) coulombp_mtir_r(:ic2*(ic2 + 1)/2, ikpt0) = packmat(coulomb_mtir_r(:ic2, :ic2, ikpt1)) else coulomb_mtir_c(ic + 1:ic + hybrid%ngptm(ikpt), ic + 1:ic + hybrid%ngptm(ikpt), ikpt1) & = coulhlp%data_c(hybrid%nbasp + 1:nbasm1(ikpt), hybrid%nbasp + 1:nbasm1(ikpt)) ic2 = indx1 + hybrid%ngptm(ikpt) coulombp_mtir_c(:ic2*(ic2 + 1)/2, ikpt0) = packmat(coulomb_mtir_c(:ic2, :ic2, ikpt1)) end if `````` Gregor Michalicek committed Jun 25, 2018 1527 ``````#endif `````` Matthias Redies committed Jun 17, 2019 1528 1529 `````` call timestart("write coulomb_spm") if (sym%invs) THEN `````` Gregor Michalicek committed Jun 25, 2018 1530 ``````#ifdef CPP_IRCOULOMBAPPROX `````` Matthias Redies committed Jun 17, 2019 1531 1532 `````` call write_coulomb_spm_r(ikpt, coulomb_mt1(:, :, :, :, 1), coulomb_mt2_r(:, :, :, :, 1), & coulomb_mt3_r(:, :, :, 1), coulomb_mtir_r(:, 1)) `````` Gregor Michalicek committed Jun 25, 2018 1533 ``````#else `````` Matthias Redies committed Jun 17, 2019 1534 1535 `````` CALL write_coulomb_spm_r(ikpt, coulomb_mt1(:, :, :, :, 1), coulomb_mt2_r(:, :, :, :, 1), & coulomb_mt3_r(:, :, :, 1), coulombp_mtir_r(:, 1)) `````` 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 ``````!!\$ print *,"DEBUG" !!\$ DO n1=1,SIZE(coulomb_mt1,1) !!\$ DO n2=1,SIZE(coulomb_mt1,2) !!\$ DO i=1,SIZE(coulomb_mt1,3) !!\$ DO j=1,SIZE(coulomb_mt1,4) !!\$ WRITE(732,*) n1,n2,i-1,j,coulomb_mt2_r(n1,n2,i-1,j,1) !!\$ ENDDO !!\$ ENDDO !!\$ ENDDO !!\$ ENDDO `````` Gregor Michalicek committed Jun 25, 2018 1546 ``````#endif `````` Matthias Redies committed Jun 17, 2019 1547 `````` else `````` Gregor Michalicek committed Jun 25, 2018 1548 ``````#ifdef CPP_IRCOULOMBAPPROX `````` Matthias Redies committed Jun 17, 2019 1549 1550 `````` call write_coulomb_spm_c(ikpt, coulomb_mt1(:, :, :, :, 1), coulomb_mt2_c(:, :, :, :, 1), & coulomb_mt3_c(:, :, :, 1), coulomb_mtir_c(:, 1)) `````` Gregor Michalicek committed Jun 25, 2018 1551 ``````#else `````` Matthias Redies committed Jun 17, 2019 1552 1553 `````` call write_coulomb_spm_c(ikpt, coulomb_mt1(:, :, :, :, 1), coulomb_mt2_c(:, :, :, :, 1), & coulomb_mt3_c(:, :, :, 1), coulombp_mtir_c(:, 1)) `````` Gregor Michalicek committed Jun 25, 2018 1554 ``````#endif `````` Matthias Redies committed Jun 17, 2019 1555 1556 `````` endif call timestop("write coulomb_spm") `````` Daniel Wortmann committed Jun 21, 2017 1557 `````` `````` Matthias Redies committed Jun 17, 2019 1558 1559 `````` END DO ! ikpt call timestop("loop bla") `````` Daniel Wortmann committed Jun 21, 2017 1560 `````` `````` Matthias Redies committed Jun 17, 2019 1561 1562 1563 1564 1565 `````` if (sym%invs) THEN DEALLOCATE (coulomb_mt1, coulomb_mt2_r, coulomb_mt3_r, coulomb_mtir_r, coulombp_mtir_r) else DEALLOCATE (coulomb_mt1, coulomb_mt2_c, coulomb_mt3_c, coulomb_mtir_c, coulombp_mtir_c) end if `````` Daniel Wortmann committed Jun 21, 2017 1566 ``````#else `````` Matthias Redies committed Jun 17, 2019 1567 1568 1569 1570 `````` !write coulomb matrix to direct access file coulomb DO i = 1, kpts%nkpt call write_coulomb(i, sym%invs, coulomb(:, i)) END DO `````` Daniel Wortmann committed Jun 21, 2017 1571 1572 ``````#endif `````` Matthias Redies committed Jun 17, 2019 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 `````` IF (mpi%irank == 0) THEN WRITE (6, '(7X,A)', advance='no') 'done' CALL cpu_TIME(time2) WRITE (6, '(2X,A,F8.2,A)') '( Timing:', time2 - time1, ' )' END IF CALL timestop("Coulomb matrix setup") END SUBROUTINE coulombmatrix ! Calculate body of Coulomb matrix at Gamma point: v_IJ = SUM(G) c^*_IG c_JG 4*pi/G**2 . ! For this we must subtract from coulomb(:,1) the spherical average of a term that comes ! from the fact that MT functions have k-dependent Fourier coefficients (see script). SUBROUTINE subtract_sphaverage(sym, cell, atoms, kpts, hybrid, nbasm1, gridf, coulomb) USE m_types USE m_constants USE m_wrapper USE m_trafo USE m_util USE m_olap IMPLICIT NONE TYPE(t_sym), INTENT(IN) :: sym TYPE(t_cell), INTENT(IN) :: cell TYPE(t_atoms), INTENT(IN) :: atoms TYPE(t_kpts), INTENT(IN) :: kpts TYPE(t_hybrid), INTENT(IN) :: hybrid INTEGER, INTENT(IN) :: nbasm1(kpts%nkptf) REAL, INTENT(IN) :: gridf(:, :) COMPLEX, INTENT(INOUT) :: coulomb(hybrid%maxbasm1*(hybrid%maxbasm1 + 1)/2, kpts%nkpt) ! - local scalars - INTEGER :: l, i, j, n, nn, itype, ieq, M ! - local arrays - TYPE(t_mat) :: olap !COMPLEX , ALLOCATABLE :: constfunc(:) !can also be real in inversion case COMPLEX :: coeff(nbasm1(1)), cderiv(nbasm1(1), -1:1), claplace(nbasm1(1)) CALL olap%alloc(sym%invs, hybrid%ngptm(1), hybrid%ngptm(1), 0.) n = nbasm1(1) nn = n*(n + 1)/2 CALL olap_pw(olap, hybrid%gptm(:, hybrid%pgptm(:hybrid%ngptm(1), 1)), hybrid%ngptm(1), atoms, cell) ! Define coefficients (coeff) and their derivatives (cderiv,claplace) coeff = 0 cderiv = 0 claplace = 0 j = 0 DO itype = 1, atoms%ntype DO ieq = 1, atoms%neq(itype) DO l = 0, hybrid%lcutm1(itype) DO M = -l, l DO i = 1, hybrid%nindxm1(l, itype) j = j + 1 IF (l .EQ. 0) THEN coeff(j) = SQRT(4*pi_const) & *intgrf(atoms%rmsh(:, itype)*hybrid%basm1(:, i, 0, itype), & atoms%jri, atoms%jmtd, atoms%rmsh, atoms%dx, atoms%ntype, itype, gridf) & /SQRT(cell%vol) claplace(j) = -SQRT(4*pi_const) & *intgrf(atoms%rmsh(:, itype)**3*hybrid%basm1(:, i, 0, itype), & atoms%jri, atoms%jmtd, atoms%rmsh, atoms%dx, atoms%ntype, itype, gridf) & /SQRT(cell%vol) ELSE IF (l .EQ. 1) THEN cderiv(j, M) = -SQRT(4*pi_const/3)*CMPLX(0.0, 1.0) & *intgrf(atoms%rmsh(:, itype)**2*hybrid%basm1(:, i, 1, itype), & atoms%jri, atoms%jmtd, atoms%rmsh, atoms%dx, atoms%ntype, itype, gridf) & /SQRT(cell%vol) END IF END DO END DO END DO END DO END DO IF (olap%l_real) THEN coeff(hybrid%nbasp + 1:n) = olap%data_r(1, 1:n - hybrid%nbasp) else coeff(hybrid%nbasp + 1:n) = olap%data_c(1, 1:n - hybrid%nbasp) END IF IF (sym%invs) THEN CALL symmetrize(coeff, 1, nbasm1(1), 2, .FALSE., & atoms, hybrid%lcutm1, hybrid%maxlcutm1, & hybrid%nindxm1, sym) CALL symmetrize(claplace, 1, nbasm1(1), 2, .FALSE., & atoms, hybrid%lcutm1, hybrid%maxlcutm1, & hybrid%nindxm1, sym) CALL symmetrize(cderiv(:, -1), 1, nbasm1(1), 2, .FALSE., & atoms, hybrid%lcutm1, hybrid%maxlcutm1, & hybrid%nindxm1, sym) CALL symmetrize(cderiv(:, 0), 1, nbasm1(1), 2, .FALSE., & atoms, hybrid%lcutm1, hybrid%maxlcutm1, & hybrid%nindxm1, sym) CALL symmetrize(cderiv(:, 1), 1, nbasm1(1), 2, .FALSE., & atoms, hybrid%lcutm1, hybrid%maxlcutm1, & hybrid%nindxm1, sym) ENDIF ! Subtract head contributions from coulomb(:nn,1) to obtain the body l = 0 DO j = 1, n DO i = 1, j l = l + 1 coulomb(l, 1) = coulomb(l, 1) - 4*pi_const/3 & *(dot_PRODUCT(cderiv(i, :), cderiv(j, :)) & + (CONJG(coeff(i))*claplace(j) & + CONJG(claplace(i))*coeff(j))/2) END DO END DO coeff(hybrid%nbasp + 1) = 1d0 coeff(hybrid%nbasp + 2:) = 0d0 IF (sym%invs) THEN CALL desymmetrize(coeff, 1, nbasm1(1), 2, & atoms, hybrid%lcutm1, hybrid%maxlcutm1, & hybrid%nindxm1, sym) CALL symmetrize(coeff, nbasm1(1), 1, 1, .FALSE., & atoms, hybrid%lcutm1, hybrid%maxlcutm1, & hybrid%nindxm1, sym) ENDIF ! Explicit normalization here in order to prevent failure of the diagonalization in diagonalize_coulomb ! due to inaccuracies in the overlap matrix (which can make it singular). !constfunc = coeff / SQRT ( ( SUM(ABS(coeff(:hybrid%nbasp))**2) + dotprod ( coeff(hybrid%nbasp+1:), MATMUL(olap,coeff(hybrid%nbasp+1:)) ) ) ) END SUBROUTINE subtract_sphaverage ! ----------------------------------------------------------------------------------------------- ! Calculates the structure constant ! 1 * ^ ! structconst(lm,ic1,ic2,k) = SUM exp(ikT) ----------------------- Y ( T + R(ic) ) ! T | T + R(ic1) - R(ic2) | lm ! ! with T = lattice vectors ! ! An Ewald summation method devised by O.K. Andersen is used for l<5 ! (see e.g. H.L. Skriver, "The LMTO method", Springer 1984). ! (The real-space function G can be calculated with gfunction.f) ! ! Convergence parameter `````` Daniel Wortmann committed Jun 21, 2017 1718 ``````#define CONVPARAM 1d-18 `````` Matthias Redies committed Jun 17, 2019 1719 `````` ! Do some additional shells ( real-space and Fourier-space sum ) `````` Daniel Wortmann committed Jun 21, 2017 1720 1721 1722 ``````#define ADDSHELL1 40 #define ADDSHELL2 0 `````` Matthias Redies committed Jun 17, 2019 1723 1724 1725 1726 1727 `````` SUBROUTINE structureconstant(structconst, cell, hybrid, atoms, kpts, mpi) USE m_constants, ONLY: pi_const USE m_util, ONLY: harmonicsr, rorderp, rorderpf USE m_types `````` Matthias Redies committed Jun 18, 2019 1728 `````` USE m_juDFT `````` Matthias Redies committed Jun 24, 2019 1729 `````` use m_ylm `````` Matthias Redies committed Jun 17, 2019 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 `````` IMPLICIT NONE TYPE(t_mpi), INTENT(IN) :: mpi TYPE(t_hybrid), INTENT(INOUT) :: hybrid TYPE(t_cell), INTENT(IN) :: cell TYPE(t_atoms), INTENT(IN) :: atoms TYPE(t_kpts), INTENT(IN) :: kpts ! - scalars - ! - arrays - COMPLEX, INTENT(INOUT) :: structconst((2*hybrid%lexp + 1)**2, atoms%nat, atoms%nat, kpts%nkpt) ! - local scalars - INTEGER :: i, ic1, ic2, lm, ikpt, l, ishell, nshell INTEGER :: m INTEGER :: nptsh, maxl REAL :: rad, rrad, rdum REAL :: a, a1, aa REAL :: pref, rexp REAL :: time1, time2 REAL :: scale COMPLEX :: cdum, cexp LOGICAL, SAVE :: first = .TRUE. ! - local arrays - INTEGER :: conv(0:2*hybrid%lexp) INTEGER, ALLOCATABLE :: pnt(:), ptsh(:, :) REAL :: rc(3), ra(3), k(3), ki(3), ka(3) REAL :: convpar(0:2*hybrid%lexp), g(0:2*hybrid%lexp) REAL, ALLOCATABLE :: radsh(:) COMPLEX :: y((2*hybrid%lexp + 1)**2) COMPLEX :: shlp((2*hybrid%lexp + 1)**2, kpts%nkpt) `````` Matthias Redies committed Jun 18, 2019 1770 1771 `````` call timestart("calc struc_const.") `````` Matthias Redies committed Jun 17, 2019 1772 1773 1774