@@ -681,6 +681,13 @@ void LCAO_Hamilt::calculate_HSR_sparse(const int ¤t_spin, const double &sp
681681 }
682682 }
683683
684+ if (GlobalC::exx_global.info .hybrid_type ==Exx_Global::Hybrid_Type::HF
685+ || GlobalC::exx_global.info .hybrid_type ==Exx_Global::Hybrid_Type::PBE0
686+ || GlobalC::exx_global.info .hybrid_type ==Exx_Global::Hybrid_Type::HSE)
687+ {
688+ calculate_HR_exx_sparse (current_spin, sparse_threshold);
689+ }
690+
684691 clear_zero_elements (current_spin, sparse_threshold);
685692
686693}
@@ -910,6 +917,80 @@ void LCAO_Hamilt::calculat_HR_dftu_soc_sparse(const int ¤t_spin, const dou
910917
911918}
912919
920+ // Peize Lin add 2021.11.16
921+ void LCAO_Hamilt::calculate_HR_exx_sparse (const int ¤t_spin, const double &sparse_threshold)
922+ {
923+ ModuleBase::TITLE (" LCAO_Hamilt" ," calculate_HR_exx_sparse" );
924+ ModuleBase::timer::tick (" LCAO_Hamilt" ," calculate_HR_exx_sparse" );
925+
926+ const Abfs::Vector3_Order<int > Rs_period (GlobalC::kv.nmp [0 ], GlobalC::kv.nmp [1 ], GlobalC::kv.nmp [2 ]);
927+ if (Rs_period.x <=0 || Rs_period.y <=0 || Rs_period.z <=0 )
928+ throw std::invalid_argument (" Rs_period = (" +ModuleBase::GlobalFunc::TO_STRING (Rs_period.x )+" ," +ModuleBase::GlobalFunc::TO_STRING (Rs_period.y )+" ," +ModuleBase::GlobalFunc::TO_STRING (Rs_period.z )+" ).\n "
929+ +ModuleBase::GlobalFunc::TO_STRING (__FILE__)+" line " +ModuleBase::GlobalFunc::TO_STRING (__LINE__));
930+ const std::vector<Abfs::Vector3_Order<int >> Rs = Abfs::get_Born_von_Karmen_boxes ( Rs_period );
931+
932+
933+ const int ik_begin = (GlobalV::NSPIN==2 ) ? (current_spin*GlobalC::kv.nks /2 ) : 0 ;
934+ const int ik_end = (GlobalV::NSPIN==2 ) ? ((current_spin+1 )*GlobalC::kv.nks /2 ) : GlobalC::kv.nks ;
935+ for (const Abfs::Vector3_Order<int > &R : Rs)
936+ {
937+ ModuleBase::matrix HexxR;
938+ for (int ik=ik_begin; ik<ik_end; ++ik)
939+ {
940+ ModuleBase::matrix HexxR_tmp;
941+ if (GlobalV::GAMMA_ONLY_LOCAL)
942+ HexxR_tmp = GlobalC::exx_global.info .hybrid_alpha
943+ * GlobalC::exx_lcao.Hexx_para .HK_Gamma_m2D [ik];
944+ else
945+ HexxR_tmp = GlobalC::exx_global.info .hybrid_alpha
946+ * (GlobalC::exx_lcao.Hexx_para .HK_K_m2D [ik]
947+ * std::exp ( ModuleBase::TWO_PI*ModuleBase::IMAG_UNIT * (GlobalC::kv.kvec_c [ik] * (R*GlobalC::ucell.latvec )) )).real ();
948+
949+ if (HexxR.c )
950+ HexxR += HexxR_tmp;
951+ else
952+ HexxR = std::move (HexxR_tmp);
953+ }
954+
955+ for (int iwt1_local=0 ; iwt1_local<HexxR.nr ; ++iwt1_local)
956+ {
957+ const int iwt1_global = (GlobalV::KS_SOLVER==" genelpa" || GlobalV::KS_SOLVER==" scalapack_gvx" )
958+ ? GlobalC::ParaO.MatrixInfo .col_set [iwt1_local]
959+ : GlobalC::ParaO.MatrixInfo .row_set [iwt1_local];
960+ for (int iwt2_local=0 ; iwt2_local<HexxR.nc ; ++iwt2_local)
961+ {
962+ const int iwt2_global = (GlobalV::KS_SOLVER==" genelpa" || GlobalV::KS_SOLVER==" scalapack_gvx" )
963+ ? GlobalC::ParaO.MatrixInfo .row_set [iwt2_local]
964+ : GlobalC::ParaO.MatrixInfo .col_set [iwt2_local];
965+ if (std::abs (HexxR (iwt1_local,iwt2_local)) > sparse_threshold)
966+ {
967+ if (GlobalV::NSPIN==1 || GlobalV::NSPIN==2 )
968+ {
969+ auto &HR_sparse_ptr = GlobalC::LM.HR_sparse [current_spin][R][iwt1_global];
970+ auto &HR_sparse = HR_sparse_ptr[iwt2_global];
971+ HR_sparse += HexxR (iwt1_local,iwt2_local);
972+ if (std::abs (HR_sparse) < sparse_threshold)
973+ HR_sparse_ptr.erase (iwt2_global);
974+ }
975+ else
976+ {
977+ auto &HR_sparse_ptr = GlobalC::LM.HR_soc_sparse [R][iwt1_global];
978+ auto &HR_sparse = HR_sparse_ptr[iwt2_global];
979+ HR_sparse += HexxR (iwt1_local,iwt2_local);
980+ if (std::abs (HR_sparse) < sparse_threshold)
981+ HR_sparse_ptr.erase (iwt2_global);
982+ }
983+ }
984+ }
985+ }
986+ }
987+
988+ // In the future it should be changed to mpi communication, since some Hexx(R) of R in Rs may be zeros
989+ GlobalC::LM.all_R_coor .insert (Rs.begin (),Rs.end ());
990+
991+ ModuleBase::timer::tick (" LCAO_Hamilt" ," calculate_HR_exx_sparse" );
992+ }
993+
913994// in case there are elements smaller than the threshold
914995void LCAO_Hamilt::clear_zero_elements (const int ¤t_spin, const double &sparse_threshold)
915996{
0 commit comments