BB_a(R)=<0n|H(r-R)|Rm> is the Fourier transform of BB_a(k) = i (a=x,y,z)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(pw90_berry_mod_type), | intent(in) | :: | pw90_berry | |||
| type(dis_manifold_type), | intent(in) | :: | dis_manifold | |||
| type(kmesh_info_type), | intent(in) | :: | kmesh_info | |||
| real(kind=dp), | intent(in) | :: | kpt_latt(:,:) | |||
| type(print_output_type), | intent(in) | :: | print_output | |||
| complex(kind=dp), | intent(inout), | allocatable | :: | HH_R(:,:,:) | ||
| complex(kind=dp), | intent(inout), | allocatable | :: | BB_R(:,:,:,:) | ||
| complex(kind=dp), | intent(in) | :: | v_matrix(:,:,:) | |||
| real(kind=dp), | intent(in) | :: | eigval(:,:) | |||
| real(kind=dp), | intent(in) | :: | scissors_shift | |||
| type(wigner_seitz_type), | intent(in) | :: | wigner_seitz | |||
| type(ws_distance_type), | intent(in) | :: | ws_distance | |||
| type(ws_region_type), | intent(in) | :: | ws_region | |||
| integer, | intent(in) | :: | num_bands | |||
| integer, | intent(in) | :: | num_kpts | |||
| integer, | intent(in) | :: | num_wann | |||
| logical, | intent(in) | :: | have_disentangled | |||
| character(len=50), | intent(in) | :: | seedname | |||
| integer, | intent(in) | :: | stdout | |||
| type(timer_list_type), | intent(inout) | :: | timer | |||
| type(w90_error_type), | intent(out), | allocatable | :: | error | ||
| type(w90_comm_type), | intent(in) | :: | comm |
subroutine get_BB_R(pw90_berry, dis_manifold, kmesh_info, kpt_latt, print_output, HH_R, BB_R, v_matrix, eigval, & scissors_shift, wigner_seitz, ws_distance, ws_region, num_bands, num_kpts, num_wann, & have_disentangled, seedname, stdout, timer, error, comm) !================================================ ! !! BB_a(R)=<0n|H(r-R)|Rm> is the Fourier transform of !! BB_a(k) = i<u|H|del_a u> (a=x,y,z) ! !================================================ use w90_postw90_types, only: pw90_berry_mod_type, wigner_seitz_type use w90_types, only: dis_manifold_type, kmesh_info_type, ws_distance_type, ws_region_type, & print_output_type, timer_list_type implicit none ! arguments type(pw90_berry_mod_type), intent(in) :: pw90_berry type(dis_manifold_type), intent(in) :: dis_manifold type(kmesh_info_type), intent(in) :: kmesh_info type(wigner_seitz_type), intent(in) :: wigner_seitz type(ws_distance_type), intent(in) :: ws_distance type(ws_region_type), intent(in) :: ws_region type(print_output_type), intent(in) :: print_output type(timer_list_type), intent(inout) :: timer type(w90_comm_type), intent(in) :: comm type(w90_error_type), allocatable, intent(out) :: error integer, intent(in) :: num_bands, num_kpts, num_wann, stdout real(kind=dp), intent(in) :: eigval(:, :) real(kind=dp), intent(in) :: scissors_shift real(kind=dp), intent(in) :: kpt_latt(:, :) complex(kind=dp), intent(in) :: v_matrix(:, :, :) complex(kind=dp), allocatable, intent(inout) :: HH_R(:, :, :) complex(kind=dp), allocatable, intent(inout) :: BB_R(:, :, :, :) ! <0|H(r-R)|R> complex(kind=dp), allocatable :: BB_R_temp(:, :, :) complex(kind=dp), allocatable :: BB_R_b(:, :, :, :) logical, intent(in) :: have_disentangled character(len=50), intent(in) :: seedname ! local variables integer :: idir, n, m, nn, i, j, ir, & ik, ik2, inn, nnl, nnm, nnn, & winmin_q, winmin_qb, ncount, & nb_tmp, nkp_tmp, nntot_tmp, mmn_in, w complex(kind=dp), allocatable :: S_o(:, :) complex(kind=dp), allocatable :: BB_q(:, :, :, :) complex(kind=dp), allocatable :: BB_q_loc(:, :, :) complex(kind=dp), allocatable :: BB_q_b(:, :, :, :, :) complex(kind=dp), allocatable :: H_q_qb(:, :) real(kind=dp), allocatable :: r0(:, :, :) complex(kind=dp), allocatable :: phase1(:, :), phase2(:) integer, allocatable :: num_states(:) integer, allocatable :: counts(:), displs(:) real(kind=dp) :: m_real, m_imag logical :: nn_found character(len=60) :: header logical :: on_root = .false. if (mpirank(comm) == 0) on_root = .true. if (print_output%timing_level > 1 .and. print_output%iprint > 0) & call io_stopwatch_start('get_oper: get_BB_R', timer) if (.not. allocated(BB_R)) then allocate (BB_R(num_wann, num_wann, wigner_seitz%nrpts_pw90, 3)) else if (print_output%timing_level > 1 .and. print_output%iprint > 0) & call io_stopwatch_stop('get_oper: get_BB_R', timer) return end if if (on_root) then allocate (BB_q_b(num_wann, num_wann, num_kpts, kmesh_info%nntot, 3)) BB_R = cmplx_0 else allocate (BB_q_b(1, 1, 1, kmesh_info%nntot, 3)) end if if (on_root) then if (abs(scissors_shift) > 1.0e-7_dp) then call set_error_fatal(error, 'Error: scissors correction not yet implemented for BB_R', comm) return end if allocate (S_o(num_bands, num_bands)) allocate (H_q_qb(num_wann, num_wann)) allocate (num_states(num_kpts)) allocate (phase1(num_wann, num_wann)) if (pw90_berry%transl_inv_full) then allocate (r0(num_wann, num_wann, 3)) do j = 1, num_wann do i = 1, num_wann r0(i, j, :) = (wigner_seitz%wannier_centres_from_AA_R(:, i) + & wigner_seitz%wannier_centres_from_AA_R(:, j))/2.0_dp end do end do end if do ik = 1, num_kpts if (have_disentangled) then num_states(ik) = dis_manifold%ndimwin(ik) else num_states(ik) = num_wann end if end do open (newunit=mmn_in, file=trim(seedname)//'.mmn', & form='formatted', status='old', action='read', err=103) write (stdout, '(/a)', advance='no') & ' Reading overlaps from '//trim(seedname)//'.mmn in get_BB_R : ' ! Read the comment line (header) read (mmn_in, '(a)', err=104, end=104) header write (stdout, '(a)') trim(header) ! Read the number of bands, k-points and nearest neighbours read (mmn_in, *, err=104, end=104) nb_tmp, nkp_tmp, nntot_tmp ! Checks if (nb_tmp .ne. num_bands) then call set_error_fatal(error, trim(seedname)//'.mmn has wrong number of bands', comm) return end if if (nkp_tmp .ne. num_kpts) then call set_error_fatal(error, trim(seedname)//'.mmn has wrong number of k-points', comm) return end if if (nntot_tmp .ne. kmesh_info%nntot) then call set_error_fatal(error, trim(seedname)//'.mmn has wrong number of nearest neighbours', comm) return end if BB_q_b = cmplx_0 do ncount = 1, num_kpts*kmesh_info%nntot ! !Read from .mmn file the original overlap matrix ! S_o=<u_ik|u_ik2> between ab initio eigenstates ! read (mmn_in, *, err=104, end=104) ik, ik2, nnl, nnm, nnn do n = 1, num_bands do m = 1, num_bands read (mmn_in, *, err=104, end=104) m_real, m_imag S_o(m, n) = cmplx(m_real, m_imag, kind=dp) end do end do nn = 0 nn_found = .false. do inn = 1, kmesh_info%nntot if ((ik2 .eq. kmesh_info%nnlist(ik, inn)) .and. & (nnl .eq. kmesh_info%nncell(1, ik, inn)) .and. & (nnm .eq. kmesh_info%nncell(2, ik, inn)) .and. & (nnn .eq. kmesh_info%nncell(3, ik, inn))) then if (.not. nn_found) then nn_found = .true. nn = inn else call set_error_fatal(error, 'Error reading '//trim(seedname)//'.mmn.& & More than one matching nearest neighbour found', comm) return end if end if end do if (nn .eq. 0) then write (stdout, '(/a,i8,2i5,i4,2x,3i3)') ' Error reading '//trim(seedname)//'.mmn:', & ncount, ik, ik2, nn, nnl, nnm, nnn call set_error_fatal(error, 'Neighbour not found', comm) return end if call get_win_min(num_bands, dis_manifold, ik, winmin_q, have_disentangled) call get_win_min(num_bands, dis_manifold, kmesh_info%nnlist(ik, nn), winmin_qb, & have_disentangled) call get_gauge_overlap_matrix(num_bands, num_wann, eigval, v_matrix, dis_manifold, & ik, num_states(ik), kmesh_info%nnlist(ik, nn), & num_states(kmesh_info%nnlist(ik, nn)), S_o, & have_disentangled, H=H_q_qb) if (pw90_berry%transl_inv_full) then phase1 = (r0(:, :, 1)*kmesh_info%bk(1, nn, ik) + & r0(:, :, 2)*kmesh_info%bk(2, nn, ik) + & r0(:, :, 3)*kmesh_info%bk(3, nn, ik)) phase1 = exp(cmplx_i*phase1) else phase1 = cmplx_1 end if do idir = 1, 3 nno = kmesh_info%nninv(nn, ik) BB_q_b(:, :, ik, nno, idir) = BB_q_b(:, :, ik, nno, idir) & + cmplx_i*phase1(:, :)*kmesh_info%wb(nn)*kmesh_info%bk(idir, nn, ik) & *H_q_qb(:, :) end do end do !ncount close (mmn_in) deallocate (phase1) end if !on_root if (pw90_berry%transl_inv_full) then allocate (counts(0:mpisize(comm) - 1)) allocate (displs(0:mpisize(comm) - 1)) w = num_wann*num_wann call comms_array_split(num_kpts, counts, displs, comm) allocate (BB_q_loc(num_wann, num_wann, counts(mpirank(comm)))) allocate (BB_R_temp(num_wann, num_wann, wigner_seitz%nrpts)) if (on_root) then allocate (BB_R_b(num_wann, num_wann, wigner_seitz%nrpts_pw90, 3)) allocate (phase2(wigner_seitz%nrpts_pw90)) end if do idir = 1, 3 do nn = 1, kmesh_info%nntot call comms_scatterv(BB_q_loc, w*counts(mpirank(comm)), BB_q_b(:, :, :, nn, idir), w*counts, w*displs, error, comm) call fourier_loc_q_to_R(num_kpts, counts, displs, mpirank(comm), wigner_seitz%nrpts, wigner_seitz%irvec, & kpt_latt, BB_q_loc, BB_R_temp) call comms_reduce(BB_R_temp(1, 1, 1), num_wann*num_wann*wigner_seitz%nrpts, 'SUM', error, comm) if (on_root) then ! Apply degeneracy factor and reorder according to the wigner-seitz vectors call operator_wigner_setup(ws_distance, ws_region, wigner_seitz, num_wann, BB_R_temp, BB_R_b(:, :, :, idir)) phase2 = -0.5_dp*(wigner_seitz%crvec_pw90(1, :)*kmesh_info%bk(1, nn, 1) + & wigner_seitz%crvec_pw90(2, :)*kmesh_info%bk(2, nn, 1) + & wigner_seitz%crvec_pw90(3, :)*kmesh_info%bk(3, nn, 1)) phase2 = exp(cmplx_i*phase2) BB_R(:, :, :, idir) = BB_R(:, :, :, idir) + BB_R_b(:, :, :, idir)*spread(spread(phase2, 1, num_wann), 1, num_wann) end if end do end do deallocate (BB_q_loc) deallocate (BB_R_temp) if (on_root) then deallocate (phase2) deallocate (BB_q_b) deallocate (BB_R_b) do idir = 1, 3 do ir = 1, wigner_seitz%nrpts_pw90 BB_R(:, :, ir, idir) = BB_R(:, :, ir, idir) + & (r0(:, :, idir) - 0.5_dp*wigner_seitz%crvec_pw90(idir, ir))*HH_R(:, :, ir) end do end do end if else allocate (BB_q(num_wann, num_wann, num_kpts, 3)) if (on_root) then BB_q = sum(BB_q_b, 4) deallocate (BB_q_b) end if ! allocate (counts(0:mpisize(comm) - 1)) allocate (displs(0:mpisize(comm) - 1)) w = num_wann*num_wann call comms_array_split(num_kpts, counts, displs, comm) allocate (BB_q_loc(num_wann, num_wann, counts(mpirank(comm)))) allocate (BB_R_temp(num_wann, num_wann, wigner_seitz%nrpts)) do idir = 1, 3 call comms_scatterv(BB_q_loc, w*counts(mpirank(comm)), BB_q(:, :, :, idir), w*counts, w*displs, error, comm) call fourier_loc_q_to_R(num_kpts, counts, displs, mpirank(comm), wigner_seitz%nrpts, wigner_seitz%irvec, & kpt_latt, BB_q_loc, BB_R_temp) call comms_reduce(BB_R_temp(1, 1, 1), num_wann*num_wann*wigner_seitz%nrpts, 'SUM', error, comm) if (on_root) then ! Apply degeneracy factor and reorder according to the wigner-seitz vectors call operator_wigner_setup(ws_distance, ws_region, wigner_seitz, num_wann, BB_R_temp, BB_R(:, :, :, idir)) end if end do deallocate (BB_q_loc) deallocate (BB_q) deallocate (BB_R_temp) end if call comms_bcast(BB_R(1, 1, 1, 1), num_wann*num_wann*wigner_seitz%nrpts_pw90*3, error, comm) if (allocated(error)) return if (print_output%timing_level > 1 .and. print_output%iprint > 0) & call io_stopwatch_stop('get_oper: get_BB_R', timer) return 103 call set_error_file(error, 'Error: Problem opening input file '//trim(seedname)//'.mmn', comm) return 104 call set_error_file(error, 'Error: Problem reading input file '//trim(seedname)//'.mmn', comm) return end subroutine get_BB_R