Skip to content

Commit

Permalink
complete HContainer with non-adjcent atom pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
maki49 committed Aug 31, 2024
1 parent 69e3487 commit 2037ae3
Showing 1 changed file with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ namespace hamilt
inline void reallocate_hcontainer(const std::vector<std::map<int, std::map<TAC, RI::Tensor<Tdata>>>>& Hexxs,
HContainer<TR>* hR)
{
auto* pv = hR->get_paraV();
bool need_allocate = false;
for (auto& Htmp1 : Hexxs[0])
{
const int& iat0 = Htmp1.first;
for (auto& Htmp2 : Htmp1.second)
{
const int& iat1 = Htmp2.first.first;
if (hR->find_pair(iat0, iat1))
if (pv->get_row_size(iat0) > 0 && pv->get_col_size(iat1) > 0)
{
const Abfs::Vector3_Order<int>& R = RI_Util::array3_to_Vector3(Htmp2.first.second);
BaseMatrix<TR>* HlocR = hR->find_matrix(iat0, iat1, R.x, R.y, R.z);
if (HlocR == nullptr)
{ // add R to HContainer
need_allocate = true;
AtomPair<TR> tmp(iat0, iat1, R.x, R.y, R.z, hR->get_paraV());
AtomPair<TR> tmp(iat0, iat1, R.x, R.y, R.z, pv);
hR->insert_pair(tmp);
}
}
Expand All @@ -45,29 +46,36 @@ namespace hamilt
const std::array<int, 3>& Rs_period,
const RI::Cell_Nearest<int, int, 3, double, 3>* const cell_nearest = nullptr)
{
auto* pv = hR->get_paraV();
auto Rs = RI_Util::get_Born_von_Karmen_cells(Rs_period);
bool need_allocate = false;
for (int iap = 0;iap < hR->size_atom_pairs();++iap)
for (int iat0 = 0;iat0 < GlobalC::ucell.nat;++iat0)
{
hamilt::AtomPair<TR>& ap = hR->get_atom_pair(iap);
const int iat0 = ap.get_atom_i();
const int iat1 = ap.get_atom_j();
for (auto& cell : Rs)
for (int iat1 = 0;iat1 < GlobalC::ucell.nat;++iat1)
{
const Abfs::Vector3_Order<int>& R = RI_Util::array3_to_Vector3(
(cell_nearest ?
cell_nearest->get_cell_nearest_discrete(iat0, iat1, cell)
: cell));
BaseMatrix<TR>* HlocR = hR->find_matrix(iat0, iat1, R.x, R.y, R.z);
if (HlocR == nullptr)
{ // add R to HContainer
need_allocate = true;
AtomPair<TR> tmp(iat0, iat1, R.x, R.y, R.z, hR->get_paraV());
hR->insert_pair(tmp);
// complete the atom pairs that has orbitals in this processor but not in hR due to the adj_list
// but adj_list is not enought for EXX, which is more nonlocal than Nonlocal
if(pv->get_row_size(iat0) > 0 && pv->get_col_size(iat1) > 0)
{
for (auto& cell : Rs)
{
const Abfs::Vector3_Order<int>& R = RI_Util::array3_to_Vector3(
(cell_nearest ?
cell_nearest->get_cell_nearest_discrete(iat0, iat1, cell)
: cell));
BaseMatrix<TR>* HlocR = hR->find_matrix(iat0, iat1, R.x, R.y, R.z);

if (HlocR == nullptr)
{ // add R to HContainer
need_allocate = true;
AtomPair<TR> tmp(iat0, iat1, R.x, R.y, R.z, pv);
hR->insert_pair(tmp);
}
}
}
}
}
if (need_allocate) { hR->allocate(nullptr, true); }
if (need_allocate) { hR->allocate(nullptr, true);}
}

template <typename TK, typename TR>
Expand Down

0 comments on commit 2037ae3

Please sign in to comment.