diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.hpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.hpp index e3d52324ef..42317c2df7 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.hpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.hpp @@ -1,8 +1,4 @@ -//======================= -// AUTHOR : Peize Lin #include "module_parameter/parameter.h" -// DATE : 2022-09-13 -//======================= #ifndef LCAO_HAMILT_HPP #define LCAO_HAMILT_HPP @@ -23,6 +19,7 @@ #ifdef __EXX // Peize Lin add 2022.09.13 + template void sparse_format::cal_HR_exx( const Parallel_Orbitals& pv, @@ -31,8 +28,8 @@ void sparse_format::cal_HR_exx( const double& sparse_threshold, const int (&nmp)[3], const std::vector>, - RI::Tensor>>>& Hexxs) { + std::map>, + RI::Tensor>>>& Hexxs) { ModuleBase::TITLE("sparse_format", "cal_HR_exx"); ModuleBase::timer::tick("sparse_format", "cal_HR_exx"); @@ -45,7 +42,7 @@ void sparse_format::cal_HR_exx( .tau[GlobalC::ucell.iat2ia[iat]]); } const std::array, 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)}; @@ -58,18 +55,22 @@ void sparse_format::cal_HR_exx( ? std::vector{current_spin} : std::vector{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 R = RI_Util::array3_to_Vector3( @@ -81,47 +82,60 @@ void sparse_format::cal_HR_exx( const RI::Tensor& 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( 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& HR_sparse = HR_sparse_ptr[iwt1]; + HR_sparse += RI::Global_Func::convert< - std::complex>(frac - * Hexx(iw0, iw1)); - if (std::abs(HR_sparse) <= sparse_threshold) { + std::complex>(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__)); } }