subroutine sitesym_symmetrize_u_matrix(sitesym, umat, num_bands, ndim, num_kpts, num_wann, &
stdout, error, comm, lwindow_in)
!================================================!
!
! calculate U(Rk)=d(R,k)*U(k)*D^{\dagger}(R,k) in the following two cases:
!
! 1. "disentanglement" phase (present(lwindow))
! ndim=num_bands
!
! 2. Minimization of Omega_{D+OD} (.not.present(lwindow))
! ndim=num_wann, d=sym%d_matrix_band
!
!================================================!
use w90_wannier90_types, only: sitesym_type
implicit none
! arguments
type(sitesym_type), intent(in) :: sitesym
type(w90_error_type), allocatable, intent(out) :: error
type(w90_comm_type), intent(in) :: comm
integer, intent(in) :: num_bands
integer, intent(in) :: stdout
integer, intent(in) :: num_wann
integer, intent(in) :: num_kpts
integer, intent(in) :: ndim
complex(kind=dp), intent(inout) :: umat(:, :, :) !(ndim, num_wann, num_kpts)
logical, optional, intent(in) :: lwindow_in(:, :) !(num_bands, num_kpts)
! local variables
integer :: ik, ir, isym, irk, n
logical :: ldone(num_kpts)
complex(kind=dp) :: cmat(ndim, num_wann)
if (present(lwindow_in) .and. (ndim .ne. num_bands)) then
call set_error_fatal(error, 'ndim!=num_bands', comm)
return
end if
if (.not. present(lwindow_in)) then
if (ndim .ne. num_wann) then
call set_error_fatal(error, 'ndim!=num_wann', comm)
return
end if
end if
ldone = .false.
do ir = 1, sitesym%nkptirr
ik = sitesym%ir2ik(ir)
ldone(ik) = .true.
if (present(lwindow_in)) then
n = count(lwindow_in(:, ik))
else
n = ndim
end if
if (present(lwindow_in)) then
call symmetrize_ukirr(num_wann, num_bands, ir, ndim, umat(:, :, ik), sitesym, stdout, &
error, comm, n)
else
call symmetrize_ukirr(num_wann, num_bands, ir, ndim, umat(:, :, ik), sitesym, stdout, &
error, comm)
end if
if (allocated(error)) return
do isym = 2, sitesym%nsymmetry
irk = sitesym%kptsym(isym, ir)
if (ldone(irk)) cycle
ldone(irk) = .true.
! cmat = d(R,k) * U(k)
call zgemm('N', 'N', n, num_wann, n, cmplx_1, &
sitesym%d_matrix_band(:, :, isym, ir), ndim, &
umat(:, :, ik), ndim, cmplx_0, cmat, ndim)
! umat(Rk) = cmat*D^{+}(R,k) = d(R,k) * U(k) * D^{+}(R,k)
call zgemm('N', 'C', n, num_wann, num_wann, cmplx_1, cmat, ndim, &
sitesym%d_matrix_wann(:, :, isym, ir), num_wann, cmplx_0, umat(:, :, irk), ndim)
end do
end do
if (any(.not. ldone)) then
call set_error_fatal(error, 'error in sitesym_symmetrize_u_matrix', comm)
return
end if
return
end subroutine sitesym_symmetrize_u_matrix