40 INTEGER(C_INT),
INTENT(IN) :: ltetra, nb, nge(3), ngw(3)
41 REAL(c_double),
INTENT(IN) :: bvec(9), eig1(nb,product(nge(1:3))), eig2(nb,product(nge(1:3)))
42 REAL(c_double),
INTENT(OUT) :: wght(nb*nb,product(ngw(1:3)))
43 INTEGER(C_INT),
INTENT(IN),
OPTIONAL :: comm
46 INTEGER :: nt_local, nk_local, nkbz, ik, kintp(8)
47 INTEGER,
ALLOCATABLE :: ik_global(:,:), ik_local(:,:)
48 REAL(8) :: wlsm(4,20), wintp(1,8)
49 REAL(8),
ALLOCATABLE :: wghtd(:,:,:), kvec(:,:)
51 IF(
PRESENT(comm))
THEN
53 & nt_local,nkbz,ik_global,ik_local,kvec,comm)
56 & nt_local,nkbz,ik_global,ik_local,kvec)
61 ALLOCATE(wghtd(nb*nb,1,nk_local))
66 wght(1:nb*nb,1:product(ngw(1:3))) = 0d0
69 wght(1:nb*nb,kintp(1:8)) = wght(1:nb*nb, kintp(1:8)) &
70 & + matmul(wghtd(1:nb*nb,1:1,ik), wintp(1:1,1:8))
72 DEALLOCATE(wghtd, kvec)
80 DEALLOCATE(ik_global, ik_local)
95 INTEGER,
INTENT(IN) :: nt_local, nb, nkBZ, nk_local, &
96 & ik_global(20,nt_local), ik_local(20,nt_local)
97 REAL(8),
INTENT(IN) :: wlsm(4,20), eig1(nb,nkBZ), eig2(nb,nkBZ)
98 REAL(8),
INTENT(OUT) :: polstat(nb,nb,nk_local)
100 INTEGER :: ib, it, indx(4)
101 REAL(8) :: e(4), ei1(4,nb), ei2(4), ej1(4,nb), ej2(4,nb), thr = 1d-10, tsmall(4,4), v, w1(nb,4), w2(nb,4)
103 polstat(1:nb,1:nb,1:nk_local) = 0d0
112 ei1(1:4, ib) = matmul(wlsm(1:4,1:20), eig1(ib, ik_global(1:20,it)))
113 ej1(1:4, ib) = matmul(wlsm(1:4,1:20), eig2(ib, ik_global(1:20,it)))
120 e(1:4) = ei1(1:4, ib)
123 IF(e(1) <= 0d0 .AND. 0d0 < e(2))
THEN
129 ei2(1:4 ) = matmul(tsmall(1:4,1:4), ei1(indx(1:4), ib))
130 ej2(1:4,1:nb) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),1:nb))
132 w1(1:nb,indx(1:4)) = w1(1:nb, indx(1:4)) &
133 & + v * matmul(w2(1:nb,1:4), tsmall(1:4,1:4))
137 ELSE IF(e(2) <= 0d0 .AND. 0d0 < e(3))
THEN
143 ei2(1:4 ) = matmul(tsmall(1:4,1:4), ei1(indx(1:4), ib))
144 ej2(1:4,1:nb) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),1:nb))
146 w1(1:nb,indx(1:4)) = w1(1:nb, indx(1:4)) &
147 & + v * matmul(w2(1:nb,1:4), tsmall(1:4,1:4))
155 ei2(1:4 ) = matmul(tsmall(1:4,1:4), ei1(indx(1:4), ib))
156 ej2(1:4,1:nb) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),1:nb))
158 w1(1:nb,indx(1:4)) = w1(1:nb, indx(1:4)) &
159 & + v * matmul(w2(1:nb,1:4), tsmall(1:4,1:4))
167 ei2(1:4 ) = matmul(tsmall(1:4,1:4), ei1(indx(1:4), ib))
168 ej2(1:4,1:nb) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),1:nb))
170 w1(1:nb,indx(1:4)) = w1(1:nb, indx(1:4)) &
171 & + v * matmul(w2(1:nb,1:4), tsmall(1:4,1:4))
175 ELSE IF(e(3) <= 0d0 .AND. 0d0 < e(4))
THEN
181 ei2(1:4 ) = matmul(tsmall(1:4,1:4), ei1(indx(1:4), ib))
182 ej2(1:4,1:nb) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),1:nb))
184 w1(1:nb,indx(1:4)) = w1(1:nb, indx(1:4)) &
185 & + v * matmul(w2(1:nb,1:4), tsmall(1:4,1:4))
193 ei2(1:4 ) = matmul(tsmall(1:4,1:4), ei1(indx(1:4), ib))
194 ej2(1:4,1:nb) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),1:nb))
196 w1(1:nb,indx(1:4)) = w1(1:nb, indx(1:4)) &
197 & + v * matmul(w2(1:nb,1:4), tsmall(1:4,1:4))
205 ei2(1:4 ) = matmul(tsmall(1:4,1:4), ei1(indx(1:4), ib))
206 ej2(1:4,1:nb) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),1:nb))
208 w1(1:nb,indx(1:4)) = w1(1:nb, indx(1:4)) &
209 & + v * matmul(w2(1:nb,1:4), tsmall(1:4,1:4))
213 ELSE IF(e(4) <= 0d0)
THEN
215 ei2(1:4 ) = ei1(1:4, ib)
216 ej2(1:4,1:nb) = ej1(1:4,1:nb)
218 w1(1:nb,1:4) = w1(1:nb,1:4) + w2(1:nb,1:4)
226 polstat(1:nb,ib,ik_local(1:20,it)) = polstat(1:nb,ib, ik_local(1:20,it)) &
227 & + matmul(w1(1:nb,1:4), wlsm(1:4,1:20))
236 polstat(1:nb,1:nb,1:nk_local) = polstat(1:nb,1:nb,1:nk_local) / dble(6 * nkbz)
251 INTEGER,
INTENT(IN) :: nb
252 REAL(8),
INTENT(IN) :: ei1(4), ej1(4,nb)
253 REAL(8),
INTENT(INOUT) :: w1(nb,4)
255 INTEGER :: ib, indx(4)
256 REAL(8) :: de(4), e(4), thr = 1d-8, tsmall(4,4), v, w2(4)
261 e(1:4) = - ej1(1:4, ib)
264 IF((e(1) <= 0d0 .AND. 0d0 < e(2)) .OR. (e(1) < 0d0 .AND. 0d0 <= e(2)))
THEN
270 de(1:4) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),ib) - ei1(indx(1:4)))
272 w1(ib,indx(1:4)) = w1(ib, indx(1:4)) &
273 & + v * matmul(w2(1:4), tsmall(1:4,1:4))
277 ELSE IF((e(2) <= 0d0 .AND. 0d0 < e(3)) .OR. (e(2) < 0d0 .AND. 0d0 <= e(3)))
THEN
283 de(1:4) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),ib) - ei1(indx(1:4)))
285 w1(ib,indx(1:4)) = w1(ib,indx(1:4)) &
286 & + v * matmul(w2( 1:4 ), tsmall(1:4,1:4))
294 de(1:4) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),ib) - ei1(indx(1:4)))
296 w1(ib,indx(1:4)) = w1(ib, indx(1:4)) &
297 & + v * matmul(w2(1:4), tsmall(1:4,1:4))
305 de(1:4) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),ib) - ei1(indx(1:4)))
307 w1(ib,indx(1:4)) = w1(ib, indx(1:4)) &
308 & + v * matmul(w2(1:4), tsmall(1:4,1:4))
312 ELSE IF((e(3) <= 0d0 .AND. 0d0 < e(4)) .OR. (e(3) < 0d0 .AND. 0d0 <= e(4)))
THEN
318 de(1:4) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),ib) - ei1(indx(1:4)))
320 w1(ib,indx(1:4)) = w1(ib, indx(1:4)) &
321 & + v * matmul(w2(1:4), tsmall(1:4,1:4))
329 de(1:4) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),ib) - ei1(indx(1:4)))
331 w1(ib,indx(1:4)) = w1(ib, indx(1:4)) &
332 & + v * matmul(w2(1:4), tsmall(1:4,1:4))
340 de(1:4) = matmul(tsmall(1:4,1:4), ej1(indx(1:4),ib) - ei1(indx(1:4)))
342 w1(ib,indx(1:4)) = w1(ib, indx(1:4)) &
343 & + v * matmul(w2(1:4), tsmall(1:4,1:4))
347 ELSE IF( e(4) <= 0d0 )
THEN
349 de(1:4) = ej1(1:4,ib) - ei1(1:4)
351 w1(ib,1:4) = w1(ib,1:4) + w2(1:4)
366 REAL(8),
INTENT(IN) :: de(4)
367 REAL(8),
INTENT(INOUT) :: w1(4)
369 INTEGER :: ii, indx(4)
370 REAL(8) :: e(4), ln(4), thr, thr2
375 thr = maxval(e(1:4)) * 1d-3
379 IF(e(ii) < thr2)
THEN
390 IF(abs(e(4) - e(3)) < thr )
THEN
391 IF(abs(e(4) - e(2)) < thr )
THEN
392 IF(abs(e(4) - e(1)) < thr )
THEN
396 w1(indx(4)) = 0.25d0 / e(4)
397 w1(indx(3)) = w1(indx(4))
398 w1(indx(2)) = w1(indx(4))
399 w1(indx(1)) = w1(indx(4))
405 w1(indx(4)) = libtetrabz_polstat_1211(e(4),e(1),ln(4),ln(1))
406 w1(indx(3)) = w1(indx(4))
407 w1(indx(2)) = w1(indx(4))
408 w1(indx(1)) = libtetrabz_polstat_1222(e(1),e(4),ln(1),ln(4))
410 IF(any(w1(1:4) < 0d0))
THEN
411 WRITE(*,
'(100e15.5)') e(1:4)
412 WRITE(*,
'(100e15.5)') w1(indx(1:4))
413 stop
"weighting 4=3=2"
417 ELSE IF(abs(e(2) - e(1)) < thr)
THEN
421 w1(indx(4)) = libtetrabz_polstat_1221(e(4),e(2), ln(4),ln(2))
422 w1(indx(3)) = w1(indx(4))
423 w1(indx(2)) = libtetrabz_polstat_1221(e(2),e(4), ln(2),ln(4))
424 w1(indx(1)) = w1(indx(2))
426 IF(any(w1(1:4) < 0d0))
THEN
427 WRITE(*,
'(100e15.5)') e(1:4)
428 WRITE(*,
'(100e15.5)') w1(indx(1:4))
429 stop
"weighting 4=3 2=1"
436 w1(indx(4)) = libtetrabz_polstat_1231(e(4),e(1),e(2),ln(4),ln(1),ln(2))
437 w1(indx(3)) = w1(indx(4))
438 w1(indx(2)) = libtetrabz_polstat_1233(e(2),e(1),e(4),ln(2),ln(1),ln(4))
439 w1(indx(1)) = libtetrabz_polstat_1233(e(1),e(2),e(4),ln(1),ln(2),ln(4))
441 IF(any(w1(1:4) < 0d0))
THEN
442 WRITE(*,
'(100e15.5)') e(1:4)
443 WRITE(*,
'(100e15.5)') w1(indx(1:4))
448 ELSE IF(abs(e(3) - e(2)) < thr)
THEN
449 IF(abs(e(3) - e(1)) < thr)
THEN
453 w1(indx(4)) = libtetrabz_polstat_1222(e(4),e(3), ln(4),ln(3))
454 w1(indx(3)) = libtetrabz_polstat_1211(e(3),e(4), ln(3),ln(4))
455 w1(indx(2)) = w1(indx(3))
456 w1(indx(1)) = w1(indx(3))
458 IF(any(w1(1:4) < 0d0))
THEN
459 WRITE(*,
'(100e15.5)') e(1:4)
460 WRITE(*,
'(100e15.5)') w1(indx(1:4))
461 stop
"weighting 3=2=1"
468 w1(indx(4)) = libtetrabz_polstat_1233(e(4),e(1),e(3),ln(4),ln(1),ln(3))
469 w1(indx(3)) = libtetrabz_polstat_1231(e(3),e(1),e(4),ln(3),ln(1),ln(4))
470 w1(indx(2)) = w1(indx(3))
471 w1(indx(1)) = libtetrabz_polstat_1233(e(1),e(4),e(3),ln(1),ln(4),ln(3))
473 IF(any(w1(1:4) < 0d0))
THEN
474 WRITE(*,
'(100e15.5)') e(1:4)
475 WRITE(*,
'(100e15.5)') w1(indx(1:4))
480 ELSE IF(abs(e(2) - e(1)) < thr)
THEN
484 w1(indx(4)) = libtetrabz_polstat_1233(e(4),e(3),e(2),ln(4),ln(3),ln(2))
485 w1(indx(3)) = libtetrabz_polstat_1233(e(3),e(4),e(2),ln(3),ln(4),ln(2))
486 w1(indx(2)) = libtetrabz_polstat_1231(e(2),e(3),e(4),ln(2),ln(3),ln(4))
487 w1(indx(1)) = w1(indx(2))
489 IF(any(w1(1:4) < 0d0))
THEN
490 WRITE(*,
'(100e15.5)') e(1:4)
491 WRITE(*,
'(100e15.5)') w1(indx(1:4))
504 IF(any(w1(1:4) < 0d0))
THEN
505 WRITE(*,
'(100e15.5)') e(1:4)
506 WRITE(*,
'(100e15.5)') w1(indx(1:4))
523 REAL(8),
INTENT(IN) :: g1,g2,g3,g4,lng1,lng2,lng3,lng4
526 REAL(8) :: w2, w3, w4
528 w2 = ((lng2 - lng1)/(g2 - g1)*g2 - 1d0)*g2/(g2 - g1)
529 w3 = ((lng3 - lng1)/(g3 - g1)*g3 - 1d0)*g3/(g3 - g1)
530 w4 = ((lng4 - lng1)/(g4 - g1)*g4 - 1d0)*g4/(g4 - g1)
531 w2 = ((w2 - w3)*g2)/(g2 - g3)
532 w4 = ((w4 - w3)*g4)/(g4 - g3)
533 w = (w4 - w2)/(g4 - g2)
539 FUNCTION libtetrabz_polstat_1231(g1,g2,g3,lng1,lng2,lng3)
RESULT(w)
543 REAL(8),
INTENT(IN) :: g1,g2,g3,lng1,lng2,lng3
548 w2 = ((lng2 - lng1)/(g2 - g1)*g2 - 1d0)*g2**2/(g2 - g1) - g1/( &
551 w3 = ((lng3 - lng1)/(g3 - g1)*g3 - 1d0)*g3**2/(g3 - g1) - g1/( &
554 w = (w3 - w2)/(g3 - g2)
556 END FUNCTION libtetrabz_polstat_1231
560 FUNCTION libtetrabz_polstat_1233(g1,g2,g3,lng1,lng2,lng3)
RESULT(w)
564 REAL(8),
INTENT(IN) :: g1,g2,g3,lng1,lng2,lng3
569 w2 = (lng2 - lng1)/(g2 - g1)*g2 - 1d0
570 w2 = (g2*w2)/(g2 - g1)
571 w3 = (lng3 - lng1)/(g3 - g1)*g3 - 1d0
572 w3 = (g3*w3)/(g3 - g1)
573 w2 = (w3 - w2)/(g3 - g2)
574 w3 = (lng3 - lng1)/(g3 - g1)*g3 - 1d0
575 w3 = 1d0 - (2d0*w3*g1)/(g3 - g1)
577 w = (g3*w3 - g2*w2)/(g3 - g2)
579 END FUNCTION libtetrabz_polstat_1233
583 FUNCTION libtetrabz_polstat_1221(g1,g2,lng1,lng2)
RESULT(w)
587 REAL(8),
INTENT(IN) :: g1, g2, lng1, lng2
590 w = 1d0 - (lng2 - lng1)/(g2 - g1)*g1
591 w = -1d0 + (2d0*g2*w)/(g2 - g1)
592 w = -1d0 + (3d0*g2*w)/(g2 - g1)
593 w = w/(2d0*(g2 - g1))
595 END FUNCTION libtetrabz_polstat_1221
599 FUNCTION libtetrabz_polstat_1222(g1,g2,lng1,lng2)
RESULT(w)
603 REAL(8),
INTENT(IN) :: g1, g2, lng1, lng2
606 w = (lng2 - lng1)/(g2 - g1)*g2 - 1d0
607 w = (2d0*g1*w)/(g2 - g1) - 1d0
608 w = (3d0*g1*w)/(g2 - g1) + 1d0
609 w = w/(2d0*(g2 - g1))
611 END FUNCTION libtetrabz_polstat_1222
615 FUNCTION libtetrabz_polstat_1211(g1,g2,lng1,lng2)
RESULT(w)
619 REAL(8),
INTENT(IN) :: g1,g2,lng1,lng2
622 w = -1d0 + (lng2 - lng1)/(g2 - g1)*g2
623 w = -1d0 + (2d0*g2*w)/(g2 - g1)
624 w = -1d0 + (3d0*g2*w)/(2d0*(g2 - g1))
625 w = w/(3d0*(g2 - g1))
627 END FUNCTION libtetrabz_polstat_1211