Skip to content

Commit

Permalink
Fix R-index mismatch in lr_util_hcontainer (#5456)
Browse files Browse the repository at this point in the history
* fix the R-index mismatch in lr_util_hcontainer

* change the test ref

* [pre-commit.ci lite] apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
maki49 and pre-commit-ci-lite[bot] authored Nov 12, 2024
1 parent 2f15c55 commit 8d6e593
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions source/module_lr/utils/lr_util_hcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ namespace LR_Util
auto dr_real = DMR_real.get_DMR_vector()[is];
assert(dr != nullptr);
assert(dr_real != nullptr);
for (int ia = 0;ia < nat;ia++)
for (int ia = 0;ia < nat;ia++) {
for (int ja = 0;ja < nat;ja++)
{
auto ap = dr->find_pair(ia, ja);
auto ap_real = dr_real->find_pair(ia, ja);
for (int iR = 0;iR < ap->get_R_size();++iR)
{
// R index may be different between the two HContainers, find by R value instead of R-index
auto dR = ap->get_R_index(iR);
auto ptr = ap->get_HR_values(iR).get_pointer();
auto ptr_real = ap_real->get_HR_values(iR).get_pointer();
for (int i = 0;i < ap->get_size();++i) ptr_real[i] = (get_imag ? ptr[i].imag() : ptr[i].real());
auto ptr_real = ap_real->get_HR_values(dR.x, dR.y, dR.z).get_pointer();
for (int i = 0;i < ap->get_size();++i) { ptr_real[i] = (get_imag ? ptr[i].imag() : ptr[i].real()); }
}
}
}
}
}

Expand All @@ -35,17 +38,20 @@ namespace LR_Util
const char& type)
{
bool get_imag = (type == 'I' || type == 'i');
for (int ia = 0;ia < nat;ia++)
for (int ia = 0;ia < nat;ia++) {
for (int ja = 0;ja < nat;ja++)
{
auto ap = HR.find_pair(ia, ja);
auto ap_real = HR_real.find_pair(ia, ja);
for (int iR = 0;iR < ap->get_R_size();++iR)
{
// R index may be different between the two HContainers, find by R value instead of R-index
auto dR = ap->get_R_index(iR);
auto ptr = ap->get_HR_values(iR).get_pointer();
auto ptr_real = ap_real->get_HR_values(iR).get_pointer();
for (int i = 0;i < ap->get_size();++i) get_imag ? ptr[i].imag(ptr_real[i]) : ptr[i].real(ptr_real[i]);
auto ptr_real = ap_real->get_HR_values(dR.x, dR.y, dR.z).get_pointer();
for (int i = 0;i < ap->get_size();++i) { get_imag ? ptr[i].imag(ptr_real[i]) : ptr[i].real(ptr_real[i]); }
}
}
}
}
}
2 changes: 1 addition & 1 deletion tests/integrate/291_NO_KP_LR/result.ref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
totexcitationenergyref 0.784963
totexcitationenergyref 0.784471

0 comments on commit 8d6e593

Please sign in to comment.