39 SUBROUTINE libtetrabz_initialize(ltetra,nge,ngw,bvec,linterpol,wlsm,nk_local,nt_local,nkBZ,ik_global,ik_local,kvec,comm)
43 INTEGER,
INTENT(IN) :: ltetra, nge(3), ngw(3)
44 REAL(8),
INTENT(IN) :: bvec(3,3)
45 LOGICAL,
INTENT(OUT) :: linterpol
46 REAL(8),
INTENT(OUT) :: wlsm(4,20)
47 INTEGER,
INTENT(OUT) :: nk_local, nt_local, nkbz
48 INTEGER,
INTENT(OUT),
ALLOCATABLE :: ik_global(:,:), ik_local(:,:)
49 REAL(8),
INTENT(OUT),
ALLOCATABLE :: kvec(:,:)
50 INTEGER,
INTENT(IN),
OPTIONAL :: comm
52 INTEGER :: itype, i1, i2, i3, it, divvec(4,4), ivvec0(4), ivvec(3,20,6)
53 REAL(8) :: l(4), bvec2(3,3), bvec3(3,4)
55 nkbz = product(nge(1:3))
56 linterpol = .NOT. all(nge(1:3) == ngw(1:3))
59 bvec2(1:3,i1) = bvec(1:3,i1) / dble(nge(i1))
62 bvec3(1:3,1) = -bvec2(1:3,1) + bvec2(1:3,2) + bvec2(1:3,3)
63 bvec3(1:3,2) = bvec2(1:3,1) - bvec2(1:3,2) + bvec2(1:3,3)
64 bvec3(1:3,3) = bvec2(1:3,1) + bvec2(1:3,2) - bvec2(1:3,3)
65 bvec3(1:3,4) = bvec2(1:3,1) + bvec2(1:3,2) + bvec2(1:3,3)
70 l(i1) = dot_product(bvec3(1:3,i1),bvec3(1:3,i1))
73 itype = minloc(l(1:4),1)
77 ivvec0(1:4) = (/ 0, 0, 0, 0 /)
79 divvec(1:4,1) = (/ 1, 0, 0, 0 /)
80 divvec(1:4,2) = (/ 0, 1, 0, 0 /)
81 divvec(1:4,3) = (/ 0, 0, 1, 0 /)
82 divvec(1:4,4) = (/ 0, 0, 0, 1 /)
85 divvec(itype, itype) = - 1
94 IF(i3 == i1 .OR. i3 == i2) cycle
98 ivvec(1:3,1,it) = ivvec0(1:3)
99 ivvec(1:3,2,it) = ivvec(1:3,1,it) + divvec(1:3,i1)
100 ivvec(1:3,3,it) = ivvec(1:3,2,it) + divvec(1:3,i2)
101 ivvec(1:3,4,it) = ivvec(1:3,3,it) + divvec(1:3,i3)
109 ivvec(1:3, 5,1:6) = 2 * ivvec(1:3,1,1:6) - ivvec(1:3,2,1:6)
110 ivvec(1:3, 6,1:6) = 2 * ivvec(1:3,2,1:6) - ivvec(1:3,3,1:6)
111 ivvec(1:3, 7,1:6) = 2 * ivvec(1:3,3,1:6) - ivvec(1:3,4,1:6)
112 ivvec(1:3, 8,1:6) = 2 * ivvec(1:3,4,1:6) - ivvec(1:3,1,1:6)
114 ivvec(1:3, 9,1:6) = 2 * ivvec(1:3,1,1:6) - ivvec(1:3,3,1:6)
115 ivvec(1:3,10,1:6) = 2 * ivvec(1:3,2,1:6) - ivvec(1:3,4,1:6)
116 ivvec(1:3,11,1:6) = 2 * ivvec(1:3,3,1:6) - ivvec(1:3,1,1:6)
117 ivvec(1:3,12,1:6) = 2 * ivvec(1:3,4,1:6) - ivvec(1:3,2,1:6)
119 ivvec(1:3,13,1:6) = 2 * ivvec(1:3,1,1:6) - ivvec(1:3,4,1:6)
120 ivvec(1:3,14,1:6) = 2 * ivvec(1:3,2,1:6) - ivvec(1:3,1,1:6)
121 ivvec(1:3,15,1:6) = 2 * ivvec(1:3,3,1:6) - ivvec(1:3,2,1:6)
122 ivvec(1:3,16,1:6) = 2 * ivvec(1:3,4,1:6) - ivvec(1:3,3,1:6)
124 ivvec(1:3,17,1:6) = ivvec(1:3,4,1:6) - ivvec(1:3,1,1:6) + ivvec(1:3,2,1:6)
125 ivvec(1:3,18,1:6) = ivvec(1:3,1,1:6) - ivvec(1:3,2,1:6) + ivvec(1:3,3,1:6)
126 ivvec(1:3,19,1:6) = ivvec(1:3,2,1:6) - ivvec(1:3,3,1:6) + ivvec(1:3,4,1:6)
127 ivvec(1:3,20,1:6) = ivvec(1:3,3,1:6) - ivvec(1:3,4,1:6) + ivvec(1:3,1,1:6)
133 wlsm(1:4,1:20) = 0.0d0
139 ELSE IF(ltetra == 2)
THEN
143 wlsm(1, 1: 4) = dble((/1440, 0, 30, 0/))
144 wlsm(2, 1: 4) = dble((/ 0, 1440, 0, 30/))
145 wlsm(3, 1: 4) = dble((/ 30, 0, 1440, 0/))
146 wlsm(4, 1: 4) = dble((/ 0, 30, 0, 1440/))
148 wlsm(1, 5: 8) = dble((/ -38, 7, 17, -28/))
149 wlsm(2, 5: 8) = dble((/ -28, -38, 7, 17/))
150 wlsm(3, 5: 8) = dble((/ 17, -28, -38, 7/))
151 wlsm(4, 5: 8) = dble((/ 7, 17, -28, -38/))
153 wlsm(1, 9:12) = dble((/ -56, 9, -46, 9/))
154 wlsm(2, 9:12) = dble((/ 9, -56, 9, -46/))
155 wlsm(3, 9:12) = dble((/ -46, 9, -56, 9/))
156 wlsm(4, 9:12) = dble((/ 9, -46, 9, -56/))
158 wlsm(1,13:16) = dble((/ -38, -28, 17, 7/))
159 wlsm(2,13:16) = dble((/ 7, -38, -28, 17/))
160 wlsm(3,13:16) = dble((/ 17, 7, -38, -28/))
161 wlsm(4,13:16) = dble((/ -28, 17, 7, -38/))
163 wlsm(1,17:20) = dble((/ -18, -18, 12, -18/))
164 wlsm(2,17:20) = dble((/ -18, -18, -18, 12/))
165 wlsm(3,17:20) = dble((/ 12, -18, -18, -18/))
166 wlsm(4,17:20) = dble((/ -18, 12, -18, -18/))
168 wlsm(1:4,1:20) = wlsm(1:4,1:20) / 1260d0
172 WRITE(*,*)
"[libtetrabz] STOP! ltetrta is invalid."
177 IF (
PRESENT(comm))
THEN
178 CALL libtetrabz_kgrid(linterpol,ivvec,nge,nkbz,nk_local,nt_local,ik_global,ik_local,kvec,comm)
180 CALL libtetrabz_kgrid(linterpol,ivvec,nge,nkbz,nk_local,nt_local,ik_global,ik_local,kvec)
187 SUBROUTINE libtetrabz_kgrid(linterpol,ivvec,ng,nkBZ,nk_local,nt_local,ik_global,ik_local,kvec,comm)
191 LOGICAL,
INTENT(INOUT) :: linterpol
192 INTEGER,
INTENT(IN) :: ivvec(3,20,6), ng(3), nkbz
193 INTEGER,
INTENT(OUT) :: nk_local, nt_local
194 INTEGER,
INTENT(OUT),
ALLOCATABLE :: ik_global(:,:), ik_local(:,:)
195 REAL(8),
INTENT(OUT),
ALLOCATABLE :: kvec(:,:)
196 INTEGER,
INTENT(IN),
OPTIONAL :: comm
198 INTEGER :: it, i1, i2, i3, ii, ikv(3), nt, ik, nt_front, loc2glob(nkbz), glob2loc(nkbz)
200 IF(
PRESENT(comm))
THEN
201 CALL libtetrabz_dividempi(comm,6 * nkbz,nt_front,nt_local)
202 linterpol = linterpol .OR. (6*nkbz /= nt_local)
207 ALLOCATE(ik_global(20, nt_local), ik_local(20, nt_local))
219 IF(nt <= nt_front .OR. nt_front + nt_local < nt) cycle
223 ikv(1:3) = (/i1, i2, i3/) + ivvec(1:3,ii,it) - 1
224 ikv(1:3) = modulo(ikv(1:3), ng(1:3))
226 ik_global(ii,nt - nt_front) = 1 + ikv(1) + ng(1) * ikv(2) + ng(1) * ng(2) * ikv(3)
238 IF(.NOT. linterpol)
THEN
240 ik_local(1:20,1:nt_local) = ik_global(1:20,1:nt_local)
249 IF(glob2loc(ik_global(ii,nt)) /= 0)
THEN
250 ik_local(ii,nt) = glob2loc(ik_global(ii,nt))
253 nk_local = nk_local + 1
254 loc2glob(nk_local) = ik_global(ii,nt)
255 glob2loc(ik_global(ii,nt)) = nk_local
256 ik_local(ii,nt) = nk_local
265 ALLOCATE(kvec(3,nk_local))
268 i1 = mod(loc2glob(ik) - 1, ng(1))
269 i2 = mod((loc2glob(ik) - 1) / ng(1), ng(2))
270 i3 = (loc2glob(ik) - 1) / (ng(1) * ng(2))
271 kvec(1:3,ik) = dble((/i1, i2, i3/)) / dble(ng(1:3))
274 END SUBROUTINE libtetrabz_kgrid
278 SUBROUTINE libtetrabz_dividempi(comm,nt,nt_front,nt_local)
281 USE mpi,
ONLY : mpi_comm_size, mpi_comm_rank
285 INTEGER,
INTENT(IN) :: comm, nt
286 INTEGER,
INTENT(OUT) :: nt_front, nt_local
288 INTEGER :: petot = 1, my_rank = 0
291 CALL mpi_comm_size(comm, petot, ierr)
292 CALL mpi_comm_rank(comm, my_rank, ierr)
295 IF(my_rank < mod(nt, petot))
THEN
296 nt_local = nt / petot + 1
297 nt_front = my_rank * nt_local
299 nt_local = nt / petot
300 nt_front = my_rank * nt_local + mod(nt, petot)
303 END SUBROUTINE libtetrabz_dividempi
311 integer,
INTENT(IN) :: n
312 REAL(8),
INTENT(inout) :: key(n)
313 INTEGER,
INTENT(OUT) :: indx(n)
315 INTEGER :: i, i0, indx0
323 key0 = minval(key(i+1:n))
324 i0 = minloc(key(i+1:n),1) + i
325 IF(key(i) > key0)
THEN
343 INTEGER,
INTENT(in) :: ng(3)
344 REAL(8),
INTENT(in) :: kvec(3)
345 INTEGER,
INTENT(out) :: kintp(8)
346 REAL(8),
INTENT(out) :: wintp(8)
350 integer :: ikv0(3), ikv1(3), i1, i2, i3
352 xv(1:3) = kvec(1:3) * dble(ng(1:3))
353 ikv0(1:3) = floor(xv(1:3))
354 xv(1:3) = xv(1:3) - dble(ikv0(1:3))
363 ikv1(1:3) = ikv0(1:3) + (/i1, i2, i3/)
364 ikv1(1:3) = modulo(ikv1(1:3), ng(1:3))
365 kintp(ii) = 1 + ikv1(1) + ng(1) * ikv1(2) + ng(1) * ng(2) * ikv1(3)
367 wintp(ii) = xv(1)**i1 * (1.0d0 - xv(1))**(1 - i1) &
368 & * xv(2)**i2 * (1.0d0 - xv(2))**(1 - i2) &
369 & * xv(3)**i3 * (1.0d0 - xv(3))**(1 - i3)
383 REAL(8),
INTENT(IN) :: e(4)
384 REAL(8),
INTENT(OUT) :: v
385 REAL(8),
INTENT(OUT) :: tsmall(4,4)
391 a(1:4,ii) = (0d0 - e(ii)) / (e(1:4) - e(ii))
394 v = a(2,1) * a(3,1) * a(4,1)
396 tsmall(1, 1:4) = (/ 1d0, 0d0, 0d0, 0d0/)
397 tsmall(2, 1:4) = (/a(1,2), a(2,1), 0d0, 0d0/)
398 tsmall(3, 1:4) = (/a(1,3), 0d0, a(3,1), 0d0/)
399 tsmall(4, 1:4) = (/a(1,4), 0d0, 0d0, a(4,1)/)
409 REAL(8),
INTENT(IN) :: e(4)
410 REAL(8),
INTENT(OUT) :: v
411 REAL(8),
INTENT(OUT) :: tsmall(4,4)
417 a(1:4,ii) = (0d0 - e(ii)) / (e(1:4) - e(ii))
420 v = a(3,1) * a(4,1) * a(2,4)
422 tsmall(1, 1:4) = (/ 1d0, 0d0, 0d0, 0d0/)
423 tsmall(2, 1:4) = (/a(1,3), 0d0, a(3,1), 0d0/)
424 tsmall(3, 1:4) = (/a(1,4), 0d0, 0d0, a(4,1)/)
425 tsmall(4, 1:4) = (/ 0d0, a(2,4), 0d0, a(4,2)/)
435 REAL(8),
INTENT(IN) :: e(4)
436 REAL(8),
INTENT(OUT) :: v
437 REAL(8),
INTENT(OUT) :: tsmall(4,4)
443 a(1:4,ii) = (0d0 - e(ii)) / (e(1:4) - e(ii))
448 tsmall(1, 1:4) = (/1d0, 0d0, 0d0, 0d0/)
449 tsmall(2, 1:4) = (/0d0, 1d0, 0d0, 0d0/)
450 tsmall(3, 1:4) = (/0d0, a(2,3), a(3,2), 0d0/)
451 tsmall(4, 1:4) = (/0d0, a(2,4), 0d0, a(4,2)/)
461 REAL(8),
INTENT(IN) :: e(4)
462 REAL(8),
INTENT(OUT) :: v
463 REAL(8),
INTENT(OUT) :: tsmall(4,4)
469 a(1:4,ii) = (0d0 - e(ii)) / (e(1:4) - e(ii))
472 v = a(2,3) * a(3,1) * a(4,2)
474 tsmall(1, 1:4) = (/ 1d0, 0d0, 0d0, 0d0/)
475 tsmall(2, 1:4) = (/a(1,3), 0d0, a(3,1), 0d0/)
476 tsmall(3, 1:4) = (/ 0d0, a(2,3), a(3,2), 0d0/)
477 tsmall(4, 1:4) = (/ 0d0, a(2,4), 0d0, a(4,2)/)
487 REAL(8),
INTENT(IN) :: e(4)
488 REAL(8),
INTENT(OUT) :: v
489 REAL(8),
INTENT(OUT) :: tsmall(4,4)
495 a(1:4,ii) = (0d0 - e(ii)) / (e(1:4) - e(ii))
500 tsmall(1, 1:4) = (/1d0, 0d0, 0d0, 0d0/)
501 tsmall(2, 1:4) = (/0d0, 1d0, 0d0, 0d0/)
502 tsmall(3, 1:4) = (/0d0, 0d0, 1d0, 0d0/)
503 tsmall(4, 1:4) = (/0d0, 0d0, a(3,4), a(4,3)/)
513 REAL(8),
INTENT(IN) :: e(4)
514 REAL(8),
INTENT(OUT) :: v
515 REAL(8),
INTENT(OUT) :: tsmall(4,4)
521 a(1:4,ii) = (0d0 - e(ii)) / (e(1:4) - e(ii))
526 tsmall(1, 1:4) = (/1d0, 0d0, 0d0, 0d0/)
527 tsmall(2, 1:4) = (/0d0, 1d0, 0d0, 0d0/)
528 tsmall(3, 1:4) = (/0d0, a(2,4), 0d0, a(4,2)/)
529 tsmall(4, 1:4) = (/0d0, 0d0, a(3,4), a(4,3)/)
539 REAL(8),
INTENT(IN) :: e(4)
540 REAL(8),
INTENT(OUT) :: v
541 REAL(8),
INTENT(OUT) :: tsmall(4,4)
547 a(1:4,ii) = (0d0 - e(ii)) / (e(1:4) - e(ii))
550 v = a(3,4) * a(2,4) * a(4,1)
552 tsmall(1, 1:4) = (/ 1d0, 0d0, 0d0, 0d0/)
553 tsmall(2, 1:4) = (/a(1,4), 0d0, 0d0, a(4,1)/)
554 tsmall(3, 1:4) = (/ 0d0, a(2,4), 0d0, a(4,2)/)
555 tsmall(4, 1:4) = (/ 0d0, 0d0, a(3,4), a(4,3)/)
565 REAL(8),
INTENT(IN) :: e(4)
566 REAL(8),
INTENT(OUT) :: v
567 REAL(8),
INTENT(OUT) :: tsmall(3,4)
573 a(1:4,ii) = (0d0 - e(ii)) / (e(1:4) - e(ii))
577 v = 3d0 * a(2,1) * a(3,1) / (e(4) - e(1))
579 tsmall(1,1:4) = (/a(1,2), a(2,1), 0d0, 0d0/)
580 tsmall(2,1:4) = (/a(1,3), 0d0, a(3,1), 0d0/)
581 tsmall(3,1:4) = (/a(1,4), 0d0, 0d0, a(4,1)/)
591 REAL(8),
INTENT(IN) :: e(4)
592 REAL(8),
INTENT(OUT) :: v
593 REAL(8),
INTENT(OUT) :: tsmall(3,4)
599 a(1:4,ii) = (0d0 - e(ii)) / (e(1:4) - e(ii))
603 v = 3d0 * a(4,1) * a(2,4) / (e(3) - e(1))
605 tsmall(1,1:4) = (/a(1,3), 0d0, a(3,1), 0d0/)
606 tsmall(2,1:4) = (/a(1,4), 0d0, 0d0, a(4,1)/)
607 tsmall(3,1:4) = (/ 0d0, a(2,4), 0d0, a(4,2)/)
617 REAL(8),
INTENT(IN) :: e(4)
618 REAL(8),
INTENT(OUT) :: v
619 REAL(8),
INTENT(OUT) :: tsmall(3,4)
625 a(1:4,ii) = (0d0 - e(ii)) / (e(1:4) - e(ii))
629 v = 3d0 * a(2,3) * a(4,2) / (e(3) - e(1))
631 tsmall(1,1:4) = (/a(1,3), 0d0, a(3,1), 0d0/)
632 tsmall(2,1:4) = (/ 0d0, a(2,3), a(3,2), 0d0/)
633 tsmall(3,1:4) = (/ 0d0, a(2,4), 0d0, a(4,2)/)
643 REAL(8),
INTENT(IN) :: e(4)
644 REAL(8),
INTENT(OUT) :: v
645 REAL(8),
INTENT(OUT) :: tsmall(3,4)
651 a(1:4,ii) = (0d0 - e(ii)) / (e(1:4) - e(ii))
655 v = 3d0 * a(1,4) * a(2,4) / (e(4) - e(3))
657 tsmall(1,1:4) = (/a(1,4), 0d0, 0d0, a(4,1)/)
658 tsmall(2,1:4) = (/ 0d0, a(2,4), 0d0, a(4,2)/)
659 tsmall(3,1:4) = (/ 0d0, 0d0, a(3,4), a(4,3)/)
668 USE mpi,
ONLY : mpi_double_precision, mpi_in_place, mpi_sum
678 CALL mpi_allreduce(mpi_in_place, scaler, 1, &
679 & mpi_double_precision, mpi_sum, comm, ierr)
689 USE mpi,
ONLY : mpi_double_precision, mpi_in_place, mpi_sum
693 INTEGER :: comm, ndim
694 REAL(8) :: vector(ndim)
699 CALL mpi_allreduce(mpi_in_place, vector, ndim, &
700 & mpi_double_precision, mpi_sum, comm, ierr)
710 USE mpi,
ONLY : mpi_double_complex, mpi_in_place, mpi_sum
714 INTEGER :: comm, ndim
715 COMPLEX(8) :: vector(ndim)
720 CALL mpi_allreduce(mpi_in_place, vector, ndim, &
721 & mpi_double_complex, mpi_sum, comm, ierr)