Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LCAO_hamilt.hpp #5580

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 39 additions & 25 deletions source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
//=======================
// AUTHOR : Peize Lin
#include "module_parameter/parameter.h"
// DATE : 2022-09-13
//=======================

#ifndef LCAO_HAMILT_HPP
#define LCAO_HAMILT_HPP
Expand All @@ -23,6 +19,7 @@

#ifdef __EXX
// Peize Lin add 2022.09.13

template <typename Tdata>
void sparse_format::cal_HR_exx(
const Parallel_Orbitals& pv,
Expand All @@ -31,8 +28,8 @@ void sparse_format::cal_HR_exx(
const double& sparse_threshold,
const int (&nmp)[3],
const std::vector<std::map<int,
std::map<std::pair<int, std::array<int, 3>>,
RI::Tensor<Tdata>>>>& Hexxs) {
std::map<std::pair<int, std::array<int, 3>>,
RI::Tensor<Tdata>>>>& Hexxs) {
ModuleBase::TITLE("sparse_format", "cal_HR_exx");
ModuleBase::timer::tick("sparse_format", "cal_HR_exx");

Expand All @@ -45,7 +42,7 @@ void sparse_format::cal_HR_exx(
.tau[GlobalC::ucell.iat2ia[iat]]);
}
const std::array<std::array<double, 3>, 3> latvec
= {RI_Util::Vector3_to_array3(GlobalC::ucell.a1),
= {RI_Util::Vector3_to_array3(GlobalC::ucell.a1), // too bad to use GlobalC here,
RI_Util::Vector3_to_array3(GlobalC::ucell.a2),
RI_Util::Vector3_to_array3(GlobalC::ucell.a3)};

Expand All @@ -58,18 +55,22 @@ void sparse_format::cal_HR_exx(
? std::vector<int>{current_spin}
: std::vector<int>{0, 1, 2, 3};

for (const int is: is_list) {
for (const int is: is_list)
{
int is0_b = 0;
int is1_b = 0;
std::tie(is0_b, is1_b) = RI_2D_Comm::split_is_block(is);

if (Hexxs.empty()) {
if (Hexxs.empty())
{
break;
}

for (const auto& HexxA: Hexxs[is]) {
for (const auto& HexxA: Hexxs[is])
{
const int iat0 = HexxA.first;
for (const auto& HexxB: HexxA.second) {
for (const auto& HexxB: HexxA.second)
{
const int iat1 = HexxB.first.first;

const Abfs::Vector3_Order<int> R = RI_Util::array3_to_Vector3(
Expand All @@ -81,47 +82,60 @@ void sparse_format::cal_HR_exx(

const RI::Tensor<Tdata>& Hexx = HexxB.second;

for (size_t iw0 = 0; iw0 < Hexx.shape[0]; ++iw0) {
for (size_t iw0 = 0; iw0 < Hexx.shape[0]; ++iw0)
{
const int iwt0 = RI_2D_Comm::get_iwt(iat0, iw0, is0_b);
const int iwt0_local = pv.global2local_row(iwt0);

if (iwt0_local < 0) {
if (iwt0_local < 0)
{
continue;
}

for (size_t iw1 = 0; iw1 < Hexx.shape[1]; ++iw1) {
for (size_t iw1 = 0; iw1 < Hexx.shape[1]; ++iw1)
{
const int iwt1 = RI_2D_Comm::get_iwt(iat1, iw1, is1_b);
const int iwt1_local = pv.global2local_col(iwt1);

if (iwt1_local < 0) {
if (iwt1_local < 0)
{
continue;
}

if (std::abs(Hexx(iw0, iw1)) > sparse_threshold) {
if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) {
if (std::abs(Hexx(iw0, iw1)) > sparse_threshold)
{
if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2)
{
auto& HR_sparse_ptr
= HS_Arrays
.HR_sparse[current_spin][R][iwt0];
double& HR_sparse = HR_sparse_ptr[iwt1];
HR_sparse += RI::Global_Func::convert<double>(
frac * Hexx(iw0, iw1));
if (std::abs(HR_sparse) <= sparse_threshold) {
if (std::abs(HR_sparse) <= sparse_threshold)
{
HR_sparse_ptr.erase(iwt1);
}
} else if (PARAM.inp.nspin == 4) {
}
else if (PARAM.inp.nspin == 4)
{
auto& HR_sparse_ptr
= HS_Arrays.HR_soc_sparse[R][iwt0];

std::complex<double>& HR_sparse
= HR_sparse_ptr[iwt1];

HR_sparse += RI::Global_Func::convert<
std::complex<double>>(frac
* Hexx(iw0, iw1));
if (std::abs(HR_sparse) <= sparse_threshold) {
std::complex<double>>(frac * Hexx(iw0, iw1));

if (std::abs(HR_sparse) <= sparse_threshold)
{
HR_sparse_ptr.erase(iwt1);
}
} else {
throw std::invalid_argument(
std::string(__FILE__) + " line "
}
else
{
throw std::invalid_argument(std::string(__FILE__) + " line "
+ std::to_string(__LINE__));
}
}
Expand Down
Loading