subroutine update_coherence_check(ilut, nI, i, signedCache, unsignedCache, connections)
use SystemData, only: tHPHF
use Determinants, only: get_helement
use hphf_integrals, only: hphf_off_diag_helement
use guga_matrixElements, only: calc_guga_matrix_element
use guga_bitRepOps, only: CSF_Info_t
use guga_data, only: ExcitationInformation_t
implicit none
integer, intent(in) :: nI(nel), i
integer(n_int), intent(in) :: ilut(0:NIfTot)
HElement_t(dp), intent(inout) :: signedCache
real(dp), intent(inout) :: unsignedCache
integer, intent(out) :: connections
real(dp) :: i_sgn(lenof_sign)
integer :: run
HElement_t(dp) :: h_el, tmp
type(ExcitationInformation_t) :: excitInfo
! TODO: Only if ilutRefAdi(:,i) is a SI on this run
! We require cached data here
if (.not. tUseCaches) call fill_adi_caches
! First, get the matrix element
if (tHPHF) then
h_el = hphf_off_diag_helement(nI, nIRef(:, i), ilut, ilutRefAdi(:, i))
else if (tGUGA) then
call calc_guga_matrix_element(&
ilut, CSF_Info_t(ilut), ilutRefAdi(:, i), CSF_Info_t(ilutRefAdi(:, i)), &
excitInfo, h_el, .true.)
else
h_el = get_helement(nI, nIRef(:, i), ilut, ilutRefAdi(:, i))
end if
! Only proceed if the determinants are coupled
if (abs(h_el) < eps) return
! Add tmp = Hij cj to the caches
tmp = h_cast(0.0_dp)
do run = 1, inum_runs
#ifdef CMPLX_
tmp = tmp + h_el * cmplx(signsRef(min_part_type(run), i), &
signsRef(max_part_type(run), i), dp)
#else
tmp = h_el * signsRef(run, i)
#endif
end do
signedCache = signedCache + tmp
unsignedCache = unsignedCache + abs(tmp)
if (tWeightedConnections) then
! there is the option to have the connections weighted with
! the population
i_sgn = signsRef(:, i)
do run = 1, inum_runs
connections = int(connections + mag_of_run(i_sgn, run) / inum_runs)
end do
else
connections = connections + 1
end if
end subroutine update_coherence_check