1- // =======================
2- // AUTHOR : Peize Lin
31#include " module_parameter/parameter.h"
4- // DATE : 2022-09-13
5- // =======================
62
73#ifndef LCAO_HAMILT_HPP
84#define LCAO_HAMILT_HPP
2319
2420#ifdef __EXX
2521// Peize Lin add 2022.09.13
22+
2623template <typename Tdata>
2724void sparse_format::cal_HR_exx (
2825 const Parallel_Orbitals& pv,
@@ -31,8 +28,8 @@ void sparse_format::cal_HR_exx(
3128 const double & sparse_threshold,
3229 const int (&nmp)[3],
3330 const std::vector<std::map<int,
34- std::map<std::pair<int, std::array<int, 3>>,
35- RI::Tensor<Tdata>>>>& Hexxs) {
31+ std::map<std::pair<int, std::array<int, 3>>,
32+ RI::Tensor<Tdata>>>>& Hexxs) {
3633 ModuleBase::TITLE (" sparse_format" , " cal_HR_exx" );
3734 ModuleBase::timer::tick (" sparse_format" , " cal_HR_exx" );
3835
@@ -45,7 +42,7 @@ void sparse_format::cal_HR_exx(
4542 .tau [GlobalC::ucell.iat2ia [iat]]);
4643 }
4744 const std::array<std::array<double , 3 >, 3 > latvec
48- = {RI_Util::Vector3_to_array3 (GlobalC::ucell.a1 ),
45+ = {RI_Util::Vector3_to_array3 (GlobalC::ucell.a1 ), // too bad to use GlobalC here,
4946 RI_Util::Vector3_to_array3 (GlobalC::ucell.a2 ),
5047 RI_Util::Vector3_to_array3 (GlobalC::ucell.a3 )};
5148
@@ -58,18 +55,22 @@ void sparse_format::cal_HR_exx(
5855 ? std::vector<int >{current_spin}
5956 : std::vector<int >{0 , 1 , 2 , 3 };
6057
61- for (const int is: is_list) {
58+ for (const int is: is_list)
59+ {
6260 int is0_b = 0 ;
6361 int is1_b = 0 ;
6462 std::tie (is0_b, is1_b) = RI_2D_Comm::split_is_block (is);
6563
66- if (Hexxs.empty ()) {
64+ if (Hexxs.empty ())
65+ {
6766 break ;
6867 }
6968
70- for (const auto & HexxA: Hexxs[is]) {
69+ for (const auto & HexxA: Hexxs[is])
70+ {
7171 const int iat0 = HexxA.first ;
72- for (const auto & HexxB: HexxA.second ) {
72+ for (const auto & HexxB: HexxA.second )
73+ {
7374 const int iat1 = HexxB.first .first ;
7475
7576 const Abfs::Vector3_Order<int > R = RI_Util::array3_to_Vector3 (
@@ -81,47 +82,60 @@ void sparse_format::cal_HR_exx(
8182
8283 const RI::Tensor<Tdata>& Hexx = HexxB.second ;
8384
84- for (size_t iw0 = 0 ; iw0 < Hexx.shape [0 ]; ++iw0) {
85+ for (size_t iw0 = 0 ; iw0 < Hexx.shape [0 ]; ++iw0)
86+ {
8587 const int iwt0 = RI_2D_Comm::get_iwt (iat0, iw0, is0_b);
8688 const int iwt0_local = pv.global2local_row (iwt0);
8789
88- if (iwt0_local < 0 ) {
90+ if (iwt0_local < 0 )
91+ {
8992 continue ;
9093 }
9194
92- for (size_t iw1 = 0 ; iw1 < Hexx.shape [1 ]; ++iw1) {
95+ for (size_t iw1 = 0 ; iw1 < Hexx.shape [1 ]; ++iw1)
96+ {
9397 const int iwt1 = RI_2D_Comm::get_iwt (iat1, iw1, is1_b);
9498 const int iwt1_local = pv.global2local_col (iwt1);
9599
96- if (iwt1_local < 0 ) {
100+ if (iwt1_local < 0 )
101+ {
97102 continue ;
98103 }
99104
100- if (std::abs (Hexx (iw0, iw1)) > sparse_threshold) {
101- if (PARAM.inp .nspin == 1 || PARAM.inp .nspin == 2 ) {
105+ if (std::abs (Hexx (iw0, iw1)) > sparse_threshold)
106+ {
107+ if (PARAM.inp .nspin == 1 || PARAM.inp .nspin == 2 )
108+ {
102109 auto & HR_sparse_ptr
103110 = HS_Arrays
104111 .HR_sparse [current_spin][R][iwt0];
105112 double & HR_sparse = HR_sparse_ptr[iwt1];
106113 HR_sparse += RI::Global_Func::convert<double >(
107114 frac * Hexx (iw0, iw1));
108- if (std::abs (HR_sparse) <= sparse_threshold) {
115+ if (std::abs (HR_sparse) <= sparse_threshold)
116+ {
109117 HR_sparse_ptr.erase (iwt1);
110118 }
111- } else if (PARAM.inp .nspin == 4 ) {
119+ }
120+ else if (PARAM.inp .nspin == 4 )
121+ {
112122 auto & HR_sparse_ptr
113123 = HS_Arrays.HR_soc_sparse [R][iwt0];
124+
114125 std::complex <double >& HR_sparse
115126 = HR_sparse_ptr[iwt1];
127+
116128 HR_sparse += RI::Global_Func::convert<
117- std::complex <double >>(frac
118- * Hexx (iw0, iw1));
119- if (std::abs (HR_sparse) <= sparse_threshold) {
129+ std::complex <double >>(frac * Hexx (iw0, iw1));
130+
131+ if (std::abs (HR_sparse) <= sparse_threshold)
132+ {
120133 HR_sparse_ptr.erase (iwt1);
121134 }
122- } else {
123- throw std::invalid_argument (
124- std::string (__FILE__) + " line "
135+ }
136+ else
137+ {
138+ throw std::invalid_argument (std::string (__FILE__) + " line "
125139 + std::to_string (__LINE__));
126140 }
127141 }
0 commit comments