From 6c05d88c35d728f067de89d875954f168289f914 Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Mon, 13 Jul 2026 22:11:46 +0800 Subject: [PATCH 01/13] replace C++17 code with C++11 code --- source/source_lcao/module_hcontainer/test/test_add_value.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/source_lcao/module_hcontainer/test/test_add_value.cpp b/source/source_lcao/module_hcontainer/test/test_add_value.cpp index 2bdd1529f49..201df363a35 100644 --- a/source/source_lcao/module_hcontainer/test/test_add_value.cpp +++ b/source/source_lcao/module_hcontainer/test/test_add_value.cpp @@ -41,8 +41,11 @@ class AddValueTest : public ::testing::Test { auto* hc = new hamilt::HContainer(¶V); insert_all_pairs(hc); - for (auto& [i, j, vals] : fill) + for (auto& item : fill) { + int i = std::get<0>(item); + int j = std::get<1>(item); + const std::vector& vals = std::get<2>(item); double* ptr = hc->find_matrix(i, j, 0, 0, 0)->get_pointer(); for (int k = 0; k < (int)vals.size(); k++) ptr[k] = vals[k]; From 72eed53c11cbec36e977bd81463fc66978d99159 Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Mon, 13 Jul 2026 22:17:17 +0800 Subject: [PATCH 02/13] Phase 2: Change reference to value copy and add member variables for exx_info removal Change Exx_LRI and RPA_LRI's info_ri from const reference to value copy to eliminate lifetime dependencies on GlobalC::exx_info. Add abfs_Lmax_ member to Exx_LRI, hybrid_step_ member to Exx_LRI_interface, and p_info_ri pointer to LRI_CV for subsequent phases. All changes are backward-compatible. --- source/source_lcao/module_ri/Exx_LRI.h | 7 ++++--- source/source_lcao/module_ri/Exx_LRI_interface.h | 5 +++++ source/source_lcao/module_ri/LRI_CV.h | 4 ++++ source/source_lcao/module_ri/RPA_LRI.h | 4 +--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/source/source_lcao/module_ri/Exx_LRI.h b/source/source_lcao/module_ri/Exx_LRI.h index 2b97552c478..d4332cf9683 100644 --- a/source/source_lcao/module_ri/Exx_LRI.h +++ b/source/source_lcao/module_ri/Exx_LRI.h @@ -107,11 +107,12 @@ class Exx_LRI ModuleBase::matrix force_exx; ModuleBase::matrix stress_exx; + int abfs_Lmax() const { return abfs_Lmax_; } + const Exx_Info_RI& get_info_ri() const { return info; } private: - // WARNING: reference to Exx_Info_RI, which holds references into Exx_Info_Global. - // Must not outlive GlobalC::exx_info. See exx_info.h for details. - const Exx_Info_RI &info; + Exx_Info_RI info; + int abfs_Lmax_ = 0; MPI_Comm mpi_comm; const K_Vectors *p_kv = nullptr; std::shared_ptr MGT; diff --git a/source/source_lcao/module_ri/Exx_LRI_interface.h b/source/source_lcao/module_ri/Exx_LRI_interface.h index 66fe9cab06f..c9f66b4e333 100644 --- a/source/source_lcao/module_ri/Exx_LRI_interface.h +++ b/source/source_lcao/module_ri/Exx_LRI_interface.h @@ -138,12 +138,17 @@ class Exx_LRI_Interface double etot_last_outer_loop = 0.0; elecstate::DensityMatrix* dm_last_step; + size_t hybrid_step() const { return hybrid_step_; } + void set_hybrid_step(size_t s) { hybrid_step_ = s; } + std::shared_ptr> exx_ptr; private: Mix_DMk_2D mix_DMk_2D; + size_t hybrid_step_ = 1; + bool exx_spacegroup_symmetry = false; ModuleSymmetry::Symmetry_rotation symrot_; diff --git a/source/source_lcao/module_ri/LRI_CV.h b/source/source_lcao/module_ri/LRI_CV.h index c23f1e5c614..7e64961fdd3 100644 --- a/source/source_lcao/module_ri/LRI_CV.h +++ b/source/source_lcao/module_ri/LRI_CV.h @@ -11,6 +11,7 @@ #include "source_basis/module_ao/ORB_atomic_lm.h" #include "abfs-vector3_order.h" #include "source_base/element_basis_index.h" +#include "source_hamilt/module_xc/exx_info_ri.h" #include #include @@ -33,6 +34,8 @@ class LRI_CV LRI_CV(); ~LRI_CV(); + void set_info_ri(const Exx_Info_RI* p) { p_info_ri = p; } + void set_orbitals( const UnitCell &ucell, const LCAO_Orbitals& orb, @@ -72,6 +75,7 @@ class LRI_CV ModuleBase::Element_Basis_Index::IndexLNM index_abfs; std::vector lcaos_rcut; std::vector abfs_ccp_rcut; + const Exx_Info_RI* p_info_ri = nullptr; public: std::map,RI::Tensor>>> Vws; diff --git a/source/source_lcao/module_ri/RPA_LRI.h b/source/source_lcao/module_ri/RPA_LRI.h index ccadf8d0387..36548003448 100644 --- a/source/source_lcao/module_ri/RPA_LRI.h +++ b/source/source_lcao/module_ri/RPA_LRI.h @@ -83,9 +83,7 @@ template class RPA_LRI Tdata Erpa; private: - // WARNING: reference to Exx_Info_RI, which holds references into Exx_Info_Global. - // Must not outlive GlobalC::exx_info. See exx_info.h for details. - const Exx_Info_RI &info; + Exx_Info_RI info; const K_Vectors *p_kv=nullptr; MPI_Comm mpi_comm; std::vector orb_cutoff_; From 5b10c43c8c15be685da382012a6a56c0fd45dcec Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Mon, 13 Jul 2026 22:21:46 +0800 Subject: [PATCH 03/13] Phase 3: Switch abfs_Lmax write from global to member with dual-write Change abfs_Lmax writing in Exx_LRI::init() and init_spencer() to write to member variable abfs_Lmax_ first, then sync to GlobalC::exx_info (dual-write) for backward compatibility. --- source/source_lcao/module_ri/Exx_LRI.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/source_lcao/module_ri/Exx_LRI.hpp b/source/source_lcao/module_ri/Exx_LRI.hpp index e4f8a6dbd02..2ccea309f7e 100644 --- a/source/source_lcao/module_ri/Exx_LRI.hpp +++ b/source/source_lcao/module_ri/Exx_LRI.hpp @@ -65,7 +65,10 @@ void Exx_LRI::init(const MPI_Comm &mpi_comm_in, Exx_Abfs::Construct_Orbs::print_orbs_size(ucell, this->abfs, GlobalV::ofs_running); for( size_t T=0; T!=this->abfs.size(); ++T ) - { GlobalC::exx_info.info_ri.abfs_Lmax = std::max( GlobalC::exx_info.info_ri.abfs_Lmax, static_cast(this->abfs[T].size())-1 ); } + { + this->abfs_Lmax_ = std::max(this->abfs_Lmax_, static_cast(this->abfs[T].size())-1); + GlobalC::exx_info.info_ri.abfs_Lmax = this->abfs_Lmax_; + } this->exx_objs.clear(); this->coulomb_settings = RI_Util::update_coulomb_settings(this->info.coulomb_param, ucell, this->p_kv); @@ -125,8 +128,8 @@ void Exx_LRI::init_spencer( for (size_t T = 0; T != this->abfs.size(); ++T) { - GlobalC::exx_info.info_ri.abfs_Lmax - = std::max(GlobalC::exx_info.info_ri.abfs_Lmax, static_cast(this->abfs[T].size()) - 1); + this->abfs_Lmax_ = std::max(this->abfs_Lmax_, static_cast(this->abfs[T].size()) - 1); + GlobalC::exx_info.info_ri.abfs_Lmax = this->abfs_Lmax_; } this->exx_objs.clear(); From 69e6f51a402879e985b93d269582d3843baa2e3c Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Mon, 13 Jul 2026 22:27:07 +0800 Subject: [PATCH 04/13] Phase 4: Set info_ri pointer for LRI_CV and fix exx_rotate_abfs read Call cv.set_info_ri(&this->info) after cv.set_orbitals() in both Exx_LRI::init() and init_spencer(). Change LRI_CV::Cs_inv_thr reads to dual-read (pointer first, global fallback). Fix exx_rotate_abfs to read rotate_abfs from member reference instead of GlobalC. --- source/source_lcao/module_ri/Exx_LRI.hpp | 2 ++ source/source_lcao/module_ri/LRI_CV.hpp | 10 ++++++---- source/source_lcao/module_ri/exx_rotate_abfs.hpp | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/source/source_lcao/module_ri/Exx_LRI.hpp b/source/source_lcao/module_ri/Exx_LRI.hpp index 2ccea309f7e..acd926cc824 100644 --- a/source/source_lcao/module_ri/Exx_LRI.hpp +++ b/source/source_lcao/module_ri/Exx_LRI.hpp @@ -80,6 +80,7 @@ void Exx_LRI::init(const MPI_Comm &mpi_comm_in, this->exx_objs[settings_list.first].cv.set_orbitals(ucell, orb, this->lcaos, this->abfs, this->exx_objs[settings_list.first].abfs_ccp, this->info.kmesh_times, this->MGT, settings_list.second.first ); + this->exx_objs[settings_list.first].cv.set_info_ri(&this->info); if (settings_list.first == Conv_Coulomb_Pot_K::Coulomb_Method::Ewald) { this->exx_objs[settings_list.first].evq.init(ucell, orb, @@ -155,6 +156,7 @@ void Exx_LRI::init_spencer( this->info.kmesh_times, this->MGT, center2_settings->second.first); + this->exx_objs[Conv_Coulomb_Pot_K::Coulomb_Method::Center2].cv.set_info_ri(&this->info); ModuleBase::timer::end("Exx_LRI", "init_spencer"); } diff --git a/source/source_lcao/module_ri/LRI_CV.hpp b/source/source_lcao/module_ri/LRI_CV.hpp index d429904f14a..53212a7b149 100644 --- a/source/source_lcao/module_ri/LRI_CV.hpp +++ b/source/source_lcao/module_ri/LRI_CV.hpp @@ -353,8 +353,9 @@ LRI_CV::DPcal_C_dC( Matrix_Orbs21::Matrix_Order::A1A2B); const RI::Tensor V = this->DPcal_V(it0, it0, {0, 0, 0}, {{"writable_Vws", true}}); RI::Tensor L; - if (GlobalC::exx_info.info_ri.Cs_inv_thr > 0) - L = LRI_CV_Tools::cal_I(V, Inverse_Matrix::Method::syev, GlobalC::exx_info.info_ri.Cs_inv_thr); + const double cs_inv_thr = this->p_info_ri != nullptr ? this->p_info_ri->Cs_inv_thr : GlobalC::exx_info.info_ri.Cs_inv_thr; + if (cs_inv_thr > 0) + L = LRI_CV_Tools::cal_I(V, Inverse_Matrix::Method::syev, cs_inv_thr); else L = LRI_CV_Tools::cal_I(V); @@ -405,8 +406,9 @@ LRI_CV::DPcal_C_dC( DPcal_V(it1, it1, {0,0,0}, {{"writable_Vws",true}})}}; std::vector>> L; - if (GlobalC::exx_info.info_ri.Cs_inv_thr > 0) - L = LRI_CV_Tools::cal_I(V, Inverse_Matrix::Method::syev, GlobalC::exx_info.info_ri.Cs_inv_thr); + const double cs_inv_thr = this->p_info_ri != nullptr ? this->p_info_ri->Cs_inv_thr : GlobalC::exx_info.info_ri.Cs_inv_thr; + if (cs_inv_thr > 0) + L = LRI_CV_Tools::cal_I(V, Inverse_Matrix::Method::syev, cs_inv_thr); else L = LRI_CV_Tools::cal_I(V); diff --git a/source/source_lcao/module_ri/exx_rotate_abfs.hpp b/source/source_lcao/module_ri/exx_rotate_abfs.hpp index ec5650f4981..b324394d782 100644 --- a/source/source_lcao/module_ri/exx_rotate_abfs.hpp +++ b/source/source_lcao/module_ri/exx_rotate_abfs.hpp @@ -269,8 +269,8 @@ void Moment_abfs::cal_VR( // Determine N1 and N2 loop ranges based on rotate_abfs // When rotate_abfs=true: only N=0 has non-zero moment, calculate only N1=0 and N2=0 // When rotate_abfs=false: all moments are non-zero, calculate all N1, N2 - const int N1_max = GlobalC::exx_info.info_ri.rotate_abfs ? 1 : orb_in[T1][L1].size(); - const int N2_max = GlobalC::exx_info.info_ri.rotate_abfs ? 1 : orb_in[T2][L2].size(); + const int N1_max = this->info.rotate_abfs ? 1 : orb_in[T1][L1].size(); + const int N2_max = this->info.rotate_abfs ? 1 : orb_in[T2][L2].size(); for (int N1 = 0; N1 != N1_max; ++N1) { From 2e28e0de61b6289a3291e5691bd6de5733373ed7 Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Mon, 13 Jul 2026 22:32:53 +0800 Subject: [PATCH 05/13] Phase 5: Replace info_ri reads from GlobalC to member access Change 5 shrink_abfs_pca_thr reads in RPA_LRI and 2 exx_symmetry_realspace reads in Exx_LRI_interface from GlobalC::exx_info.info_ri to this->info or this->exx_ptr->info. --- source/source_lcao/module_ri/Exx_LRI_interface.hpp | 4 ++-- source/source_lcao/module_ri/RPA_LRI.hpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/source_lcao/module_ri/Exx_LRI_interface.hpp b/source/source_lcao/module_ri/Exx_LRI_interface.hpp index 0172fb4d56c..47a9f7579f1 100644 --- a/source/source_lcao/module_ri/Exx_LRI_interface.hpp +++ b/source/source_lcao/module_ri/Exx_LRI_interface.hpp @@ -207,7 +207,7 @@ void Exx_LRI_Interface::exx_eachiterinit(const int istep, *dm_in.get_paraV_pointer(), PARAM.inp.nspin, this->exx_spacegroup_symmetry); - if(this->exx_spacegroup_symmetry && GlobalC::exx_info.info_ri.exx_symmetry_realspace) + if(this->exx_spacegroup_symmetry && this->exx_ptr->info.exx_symmetry_realspace) { this->cal_exx_elec(Ds, ucell,*dm_in.get_paraV_pointer(), &this->symrot_); } else { this->cal_exx_elec(Ds, ucell,*dm_in.get_paraV_pointer()); } @@ -403,7 +403,7 @@ bool Exx_LRI_Interface::exx_after_converge( *dm.get_paraV_pointer(), nspin, this->exx_spacegroup_symmetry); - if(this->exx_spacegroup_symmetry && GlobalC::exx_info.info_ri.exx_symmetry_realspace) + if(this->exx_spacegroup_symmetry && this->exx_ptr->info.exx_symmetry_realspace) { this->cal_exx_elec(Ds, ucell, *dm.get_paraV_pointer(), &this->symrot_); } else { this->cal_exx_elec(Ds, ucell, *dm.get_paraV_pointer()); } // restore DM but not Hexx diff --git a/source/source_lcao/module_ri/RPA_LRI.hpp b/source/source_lcao/module_ri/RPA_LRI.hpp index 31b6181850b..5abbc17073d 100644 --- a/source/source_lcao/module_ri/RPA_LRI.hpp +++ b/source/source_lcao/module_ri/RPA_LRI.hpp @@ -64,7 +64,7 @@ void RPA_LRI::postSCF(const UnitCell& ucell, exx_cut_coulomb = nullptr; RpaLriDetail::trim_malloc_cache(); - if (GlobalC::exx_info.info_ri.shrink_abfs_pca_thr >= 0.0) + if (this->info.shrink_abfs_pca_thr >= 0.0) { cal_large_Cs(ucell, orb, kv); cal_abfs_overlap(ucell, orb, kv); @@ -86,7 +86,7 @@ void RPA_LRI::init(const MPI_Comm& mpi_comm_in, const K_Vectors& kv_in this->p_kv = &kv_in; this->MGT = exx_cut_coulomb->MGT; - if (GlobalC::exx_info.info_ri.shrink_abfs_pca_thr >= 0.0) + if (this->info.shrink_abfs_pca_thr >= 0.0) { this->abfs_shrink = exx_cut_coulomb->abfs; } @@ -157,7 +157,7 @@ void RPA_LRI::cal_postSCF_exx(const elecstate::DensityMatrix if (!exx_cut_coulomb) exx_cut_coulomb = new Exx_LRI(GlobalC::exx_info.info_ri); - if (GlobalC::exx_info.info_ri.shrink_abfs_pca_thr >= 0.0) + if (this->info.shrink_abfs_pca_thr >= 0.0) { this->lcaos = Exx_Abfs::Construct_Orbs::change_orbs(orb, this->info.kmesh_times); const std::vector>> abfs_same_atom @@ -243,7 +243,7 @@ void RPA_LRI::output_cut_coulomb_cs(const UnitCell& ucell, Exx_LRICs_period = RI::RI_Tools::cal_period(Cs, period); this->Cs_period = exx_lri_rpa->exx_lri.post_2D.set_tensors_map2(this->Cs_period); - if (GlobalC::exx_info.info_ri.shrink_abfs_pca_thr >= 0.0) + if (this->info.shrink_abfs_pca_thr >= 0.0) this->out_Cs(ucell, this->Cs_period, "Cs_shrinked_data_"); else this->out_Cs(ucell, this->Cs_period, "Cs_data_"); @@ -263,7 +263,7 @@ void RPA_LRI::output_ewald_coulomb(const UnitCell& ucell, const K_Vect if (!exx_full_coulomb) exx_full_coulomb = new Exx_LRI(GlobalC::exx_info.info_ri); - if (GlobalC::exx_info.info_ri.shrink_abfs_pca_thr >= 0.0) + if (this->info.shrink_abfs_pca_thr >= 0.0) exx_full_coulomb->init(mpi_comm, ucell, kv, orb, this->abfs_shrink); else exx_full_coulomb->init(mpi_comm, ucell, kv, orb, this->abfs); From 018bf907fc0459d35c6dd4fb03b72e672ecd53be Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Mon, 13 Jul 2026 22:40:53 +0800 Subject: [PATCH 06/13] Phase 6: Eliminate abfs_Lmax global dependency in ewald_Vq Add abfs_Lmax parameter to Ewald_Vq::init(), store as member, and use in init_ions(). Pass abfs_Lmax_ from Exx_LRI to Ewald_Vq. Update RPA_LRI to read from exx_cut_coulomb->abfs_Lmax(). Remove dual-write to GlobalC for abfs_Lmax. --- source/source_lcao/module_ri/Exx_LRI.hpp | 5 ++--- source/source_lcao/module_ri/RPA_LRI.hpp | 2 +- source/source_lcao/module_ri/ewald_Vq.h | 4 +++- source/source_lcao/module_ri/ewald_Vq.hpp | 6 ++++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/source/source_lcao/module_ri/Exx_LRI.hpp b/source/source_lcao/module_ri/Exx_LRI.hpp index acd926cc824..98551878662 100644 --- a/source/source_lcao/module_ri/Exx_LRI.hpp +++ b/source/source_lcao/module_ri/Exx_LRI.hpp @@ -67,7 +67,6 @@ void Exx_LRI::init(const MPI_Comm &mpi_comm_in, for( size_t T=0; T!=this->abfs.size(); ++T ) { this->abfs_Lmax_ = std::max(this->abfs_Lmax_, static_cast(this->abfs[T].size())-1); - GlobalC::exx_info.info_ri.abfs_Lmax = this->abfs_Lmax_; } this->exx_objs.clear(); @@ -85,7 +84,8 @@ void Exx_LRI::init(const MPI_Comm &mpi_comm_in, { this->exx_objs[settings_list.first].evq.init(ucell, orb, this->mpi_comm, this->p_kv, this->lcaos, this->abfs, - settings_list.second.second, this->MGT, this->info.ccp_rmesh_times, this->info.kmesh_times); + settings_list.second.second, this->MGT, this->info.ccp_rmesh_times, this->info.kmesh_times, + this->abfs_Lmax_); } } @@ -130,7 +130,6 @@ void Exx_LRI::init_spencer( for (size_t T = 0; T != this->abfs.size(); ++T) { this->abfs_Lmax_ = std::max(this->abfs_Lmax_, static_cast(this->abfs[T].size()) - 1); - GlobalC::exx_info.info_ri.abfs_Lmax = this->abfs_Lmax_; } this->exx_objs.clear(); diff --git a/source/source_lcao/module_ri/RPA_LRI.hpp b/source/source_lcao/module_ri/RPA_LRI.hpp index 5abbc17073d..da1b3924ec6 100644 --- a/source/source_lcao/module_ri/RPA_LRI.hpp +++ b/source/source_lcao/module_ri/RPA_LRI.hpp @@ -128,7 +128,7 @@ void RPA_LRI::cal_postSCF_exx(const elecstate::DensityMatrix const auto& Rs = RI_Util::get_Born_von_Karmen_cells(period); symrot.find_irreducible_sector(ucell.symm, ucell.atoms, ucell.st, Rs, period, ucell.lat); // set Lmax of the rotation matrices to max(l_ao, l_abf), to support rotation under ABF - symrot.set_abfs_Lmax(GlobalC::exx_info.info_ri.abfs_Lmax); + symrot.set_abfs_Lmax(exx_cut_coulomb ? exx_cut_coulomb->abfs_Lmax() : this->info.abfs_Lmax); symrot.cal_Ms(kv, ucell, *dm.get_paraV_pointer()); // output Ts (symrot_R.txt) and Ms (symrot_k.txt) ModuleSymmetry::print_symrot_info_R(symrot, ucell.symm, ucell.lmax, Rs); diff --git a/source/source_lcao/module_ri/ewald_Vq.h b/source/source_lcao/module_ri/ewald_Vq.h index 7a125b4bcc3..505ae9b9022 100644 --- a/source/source_lcao/module_ri/ewald_Vq.h +++ b/source/source_lcao/module_ri/ewald_Vq.h @@ -56,7 +56,8 @@ class Ewald_Vq const std::map>> &coulomb_param_in, std::shared_ptr MGT_in, const double &ccp_rmesh_times_in, - const double &kmesh_times_in); + const double &kmesh_times_in, + const int abfs_Lmax_in = 0); void init_ions(const UnitCell& ucell, const std::array& period_Vs_NAO); @@ -81,6 +82,7 @@ class Ewald_Vq private: double ccp_rmesh_times; + int abfs_Lmax = 0; LRI_CV cv; Gaussian_Abfs gaussian_abfs; const K_Vectors* p_kv = nullptr; diff --git a/source/source_lcao/module_ri/ewald_Vq.hpp b/source/source_lcao/module_ri/ewald_Vq.hpp index 7d357945b52..5dd3a2d1ea0 100644 --- a/source/source_lcao/module_ri/ewald_Vq.hpp +++ b/source/source_lcao/module_ri/ewald_Vq.hpp @@ -40,7 +40,8 @@ void Ewald_Vq::init(const UnitCell& ucell, const std::map>> &coulomb_param_in, std::shared_ptr MGT_in, const double &ccp_rmesh_times_in, - const double &kmesh_times_in) + const double &kmesh_times_in, + const int abfs_Lmax_in) { ModuleBase::TITLE("Ewald_Vq", "init"); ModuleBase::timer::start("Ewald_Vq", "init"); @@ -50,6 +51,7 @@ void Ewald_Vq::init(const UnitCell& ucell, this->nks0 = this->p_kv->get_nkstot_full(); this->kvec_c.resize(this->nks0); this->ccp_rmesh_times = ccp_rmesh_times_in; + this->abfs_Lmax = abfs_Lmax_in; this->coulomb_param = coulomb_param_in; this->g_lcaos = this->init_gauss(lcaos_in); @@ -123,7 +125,7 @@ void Ewald_Vq::init_ions(const UnitCell& ucell, const std::arraykvec_c.end(), neg_kvec.begin(), [](ModuleBase::Vector3& vec) -> ModuleBase::Vector3 { return -vec; }); - this->gaussian_abfs.init(ucell, 2 * GlobalC::exx_info.info_ri.abfs_Lmax + 1, neg_kvec, ucell.G, this->ewald_lambda); + this->gaussian_abfs.init(ucell, 2 * this->abfs_Lmax + 1, neg_kvec, ucell.G, this->ewald_lambda); ModuleBase::timer::end("Ewald_Vq", "init_ions"); } From fb9393692ba7cde00bc8576f7eb9437c3f6ef454 Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Mon, 13 Jul 2026 22:44:06 +0800 Subject: [PATCH 07/13] Phase 7: Replace ccp_rmesh_times global tampering with local copy Replace 3 places in RPA_LRI that tamper with GlobalC::exx_info.info_ri.ccp_rmesh_times: use local Exx_Info_RI copy instead. This eliminates the dangerous 'save-modify-use-restore' pattern. --- source/source_lcao/module_ri/RPA_LRI.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/source/source_lcao/module_ri/RPA_LRI.hpp b/source/source_lcao/module_ri/RPA_LRI.hpp index da1b3924ec6..e3e583c46fb 100644 --- a/source/source_lcao/module_ri/RPA_LRI.hpp +++ b/source/source_lcao/module_ri/RPA_LRI.hpp @@ -151,11 +151,12 @@ void RPA_LRI::cal_postSCF_exx(const elecstate::DensityMatrix GlobalC::exx_info.info_global.hybrid_alpha = 1; GlobalC::exx_info.sync_from_global(); // reserve exx_ccp_rmesh_times to calculate full Coulomb - this->ccp_rmesh_times_ewald = GlobalC::exx_info.info_ri.ccp_rmesh_times; - // Using this->info.ccp_rmesh_times to calculate cut Coulomb this->Vs_period - GlobalC::exx_info.info_ri.ccp_rmesh_times = PARAM.inp.rpa_ccp_rmesh_times; + this->ccp_rmesh_times_ewald = this->info.ccp_rmesh_times; + // Using rpa_ccp_rmesh_times to calculate cut Coulomb this->Vs_period + Exx_Info_RI local_info = this->info; + local_info.ccp_rmesh_times = PARAM.inp.rpa_ccp_rmesh_times; if (!exx_cut_coulomb) - exx_cut_coulomb = new Exx_LRI(GlobalC::exx_info.info_ri); + exx_cut_coulomb = new Exx_LRI(local_info); if (this->info.shrink_abfs_pca_thr >= 0.0) { @@ -259,9 +260,10 @@ void RPA_LRI::output_ewald_coulomb(const UnitCell& ucell, const K_Vect ModuleBase::TITLE("RPA_LRI", "output_ewald_coulomb"); ModuleBase::timer::start("RPA_LRI", "output_ewald_coulomb"); - GlobalC::exx_info.info_ri.ccp_rmesh_times = this->ccp_rmesh_times_ewald; + Exx_Info_RI local_info = this->info; + local_info.ccp_rmesh_times = this->ccp_rmesh_times_ewald; if (!exx_full_coulomb) - exx_full_coulomb = new Exx_LRI(GlobalC::exx_info.info_ri); + exx_full_coulomb = new Exx_LRI(local_info); if (this->info.shrink_abfs_pca_thr >= 0.0) exx_full_coulomb->init(mpi_comm, ucell, kv, orb, this->abfs_shrink); @@ -316,7 +318,7 @@ void RPA_LRI::cal_large_Cs(const UnitCell& ucell, const LCAO_Orbitals& ModuleBase::TITLE("RPA_LRI", "cal_large_Cs"); ModuleBase::timer::start("RPA_LRI", "cal_large_Cs"); if (!exx_cut_coulomb) - exx_cut_coulomb = new Exx_LRI(GlobalC::exx_info.info_ri); + exx_cut_coulomb = new Exx_LRI(this->info); exx_cut_coulomb->init_spencer(this->mpi_comm, ucell, kv, orb); ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "exx_cut_coulomb->init"); this->abfs = exx_cut_coulomb->abfs; From 22aafd6e6594ac96cb61771acf034ec18bf51236 Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Tue, 14 Jul 2026 07:19:23 +0800 Subject: [PATCH 08/13] Phase 8: Cache info_global in Exx_LRI_Interface constructor Add Exx_Info_Global as constructor parameter and store as member. Replace all 18 GlobalC::exx_info.info_global reads with this->info_global. Change hybrid_step write from global to member variable. --- .../source_lcao/module_ri/Exx_LRI_interface.h | 7 ++-- .../module_ri/Exx_LRI_interface.hpp | 32 +++++++++---------- source/source_lcao/setup_exx.cpp | 4 +-- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/source/source_lcao/module_ri/Exx_LRI_interface.h b/source/source_lcao/module_ri/Exx_LRI_interface.h index c9f66b4e333..c8536b44eb1 100644 --- a/source/source_lcao/module_ri/Exx_LRI_interface.h +++ b/source/source_lcao/module_ri/Exx_LRI_interface.h @@ -7,6 +7,7 @@ #include "source_lcao/module_ri/module_exx_symmetry/symmetry_rotation.h" #include "source_estate/module_dm/density_matrix.h" // mohan add 2025-11-04 #include "source_hamilt/hamilt.h" +#include "source_hamilt/module_xc/exx_info_global.h" #include class LCAO_Matrix; @@ -39,9 +40,10 @@ class Exx_LRI_Interface using TAC = std::pair; /// @brief Constructor for Exx_LRI_Interface - Exx_LRI_Interface(const Exx_Info_RI& info) + Exx_LRI_Interface(const Exx_Info_RI& info_ri, const Exx_Info_Global& info_global) { - this->exx_ptr = std::make_shared>(info); + this->exx_ptr = std::make_shared>(info_ri); + this->info_global = info_global; } Exx_LRI_Interface() = delete; @@ -147,6 +149,7 @@ class Exx_LRI_Interface Mix_DMk_2D mix_DMk_2D; + Exx_Info_Global info_global; size_t hybrid_step_ = 1; bool exx_spacegroup_symmetry = false; diff --git a/source/source_lcao/module_ri/Exx_LRI_interface.hpp b/source/source_lcao/module_ri/Exx_LRI_interface.hpp index 47a9f7579f1..266f5abede2 100644 --- a/source/source_lcao/module_ri/Exx_LRI_interface.hpp +++ b/source/source_lcao/module_ri/Exx_LRI_interface.hpp @@ -136,7 +136,7 @@ void Exx_LRI_Interface::exx_beforescf(const int istep, { ModuleBase::TITLE("Exx_LRI_Interface","exx_beforescf"); #ifdef __MPI - if (GlobalC::exx_info.info_global.cal_exx) + if (this->info_global.cal_exx) { if ((GlobalC::restart.info_load.load_H_finish && !GlobalC::restart.info_load.restart_exx) || (istep > 0) @@ -153,15 +153,15 @@ void Exx_LRI_Interface::exx_beforescf(const int istep, } // set initial parameter for mix_DMk_2D - if(GlobalC::exx_info.info_global.cal_exx) + if(this->info_global.cal_exx) { if (this->exx_spacegroup_symmetry) { this->mix_DMk_2D.set_nks(kv.get_nkstot_full() * (PARAM.inp.nspin == 2 ? 2 : 1)); } else { this->mix_DMk_2D.set_nks(kv.get_nks()); } - if (GlobalC::exx_info.info_global.separate_loop) - { this->mix_DMk_2D.set_mixing_plain(GlobalC::exx_info.info_global.mixing_beta_for_loop1); } + if (this->info_global.separate_loop) + { this->mix_DMk_2D.set_mixing_plain(this->info_global.mixing_beta_for_loop1); } else { this->mix_DMk_2D.set_mixing(chgmix.get_mixing()); } @@ -179,13 +179,13 @@ void Exx_LRI_Interface::exx_eachiterinit(const int istep, const int& iter) { ModuleBase::TITLE("Exx_LRI_Interface","exx_eachiterinit"); - if (GlobalC::exx_info.info_global.cal_exx) + if (this->info_global.cal_exx) { - if (!GlobalC::exx_info.info_global.separate_loop + if (!this->info_global.separate_loop && (this->two_level_step || istep > 0 || PARAM.inp.init_wfc == "file") // non separate loop case - || (GlobalC::exx_info.info_global.separate_loop + || (this->info_global.separate_loop && PARAM.inp.init_wfc == "file" && this->two_level_step == 0 && iter == 1) @@ -241,10 +241,10 @@ void Exx_LRI_Interface::exx_hamilt2rho(elecstate::ElecState& elec, con { std::cout << "WARNING: Cannot read Eexx from disk, the energy of the 1st loop will be wrong, sbut it does not influence the subsequent loops." << std::endl; } } Parallel_Common::bcast_double(this->exx_ptr->Eexx); - this->exx_ptr->Eexx /= GlobalC::exx_info.info_global.hybrid_alpha; + this->exx_ptr->Eexx /= this->info_global.hybrid_alpha; } - bool cal_exx = GlobalC::exx_info.info_global.cal_exx; - double hybrid_alpha = GlobalC::exx_info.info_global.hybrid_alpha; + bool cal_exx = this->info_global.cal_exx; + double hybrid_alpha = this->info_global.hybrid_alpha; elec.set_exx(this->get_Eexx(), cal_exx, hybrid_alpha); } else @@ -267,7 +267,7 @@ void Exx_LRI_Interface::exx_iter_finish(const K_Vectors& kv, { ModuleBase::TITLE("Exx_LRI_Interface","exx_iter_finish"); if (GlobalC::restart.info_save.save_H && (this->two_level_step > 0 || istep > 0) - && (!GlobalC::exx_info.info_global.separate_loop || iter == 1)) // to avoid saving the same value repeatedly + && (!this->info_global.separate_loop || iter == 1)) // to avoid saving the same value repeatedly { ////////// for Add_Hexx_Type::k /* @@ -296,13 +296,13 @@ void Exx_LRI_Interface::exx_iter_finish(const K_Vectors& kv, } } - if (GlobalC::exx_info.info_global.cal_exx && conv_esolver) + if (this->info_global.cal_exx && conv_esolver) { // Kerker mixing does not work for the density matrix. // In the separate loop case, it can still work in the subsequent inner loops where Hexx(DM) is fixed. // In the non-separate loop case where Hexx(DM) is updated in every iteration of the 2nd loop, it should be // closed. - if (!GlobalC::exx_info.info_global.separate_loop) + if (!this->info_global.separate_loop) { chgmix.close_kerker_gg0(); } @@ -342,9 +342,9 @@ bool Exx_LRI_Interface::exx_after_converge( }; // no separate_loop case - if (!GlobalC::exx_info.info_global.separate_loop) + if (!this->info_global.separate_loop) { - GlobalC::exx_info.info_global.hybrid_step = 1; + this->hybrid_step_ = 1; // in no_separate_loop case, scf loop only did twice // in first scf loop, exx updated once in beginning, @@ -371,7 +371,7 @@ bool Exx_LRI_Interface::exx_after_converge( if (two_level_step) { std::cout << FmtCore::format(" deltaE (eV) from outer loop: %.8e \n", ediff); } // exx converged or get max exx steps - if (this->two_level_step == GlobalC::exx_info.info_global.hybrid_step + if (this->two_level_step == this->hybrid_step_ || (iter == 1 && this->two_level_step != 0) // density convergence of outer loop || (ediff < scf_ene_thr && this->two_level_step != 0)) //energy convergence of outer loop { diff --git a/source/source_lcao/setup_exx.cpp b/source/source_lcao/setup_exx.cpp index 5734f47addd..d6bcc97d5c3 100644 --- a/source/source_lcao/setup_exx.cpp +++ b/source/source_lcao/setup_exx.cpp @@ -22,11 +22,11 @@ void Exx_NAO::init() // because some members like two_level_step are used outside if(cal_exx) if (GlobalC::exx_info.info_ri.real_number) { - this->exd = std::make_shared>(GlobalC::exx_info.info_ri); + this->exd = std::make_shared>(GlobalC::exx_info.info_ri, GlobalC::exx_info.info_global); } else { - this->exc = std::make_shared>>(GlobalC::exx_info.info_ri); + this->exc = std::make_shared>>(GlobalC::exx_info.info_ri, GlobalC::exx_info.info_global); } #endif } From a7798e8d5a79ae96c2673d7f4b0dec0a6dddd7eb Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Tue, 14 Jul 2026 07:25:30 +0800 Subject: [PATCH 09/13] Phase 9: Remove info_global writes and sync_from_global in RPA_LRI Remove 3 lines that write ccp_type/hybrid_alpha to GlobalC and call sync_from_global(). This->info already has correct coulomb_param from construction. Also replace shrink_LU_inv_thr read with this->info. --- source/source_lcao/module_ri/RPA_LRI.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/source_lcao/module_ri/RPA_LRI.hpp b/source/source_lcao/module_ri/RPA_LRI.hpp index e3e583c46fb..b1492d8dac1 100644 --- a/source/source_lcao/module_ri/RPA_LRI.hpp +++ b/source/source_lcao/module_ri/RPA_LRI.hpp @@ -146,11 +146,10 @@ void RPA_LRI::cal_postSCF_exx(const elecstate::DensityMatrix PARAM.inp.nspin, exx_spacegroup_symmetry); - // set parameters for bare Coulomb potential - GlobalC::exx_info.info_global.ccp_type = Conv_Coulomb_Pot_K::Ccp_Type::Hf; // not used now, Hf/Ccp -> singularity_correction, see conv_coulomb_pot_k.cpp - GlobalC::exx_info.info_global.hybrid_alpha = 1; - GlobalC::exx_info.sync_from_global(); // reserve exx_ccp_rmesh_times to calculate full Coulomb + // Note: ccp_type=Hf and hybrid_alpha=1 were previously set on GlobalC::exx_info.info_global + // and sync_from_global() was called, but this->info (value copy) already has the correct + // coulomb_param from construction time, so the global writes are redundant and removed. this->ccp_rmesh_times_ewald = this->info.ccp_rmesh_times; // Using rpa_ccp_rmesh_times to calculate cut Coulomb this->Vs_period Exx_Info_RI local_info = this->info; @@ -802,7 +801,7 @@ void RPA_LRI::inverse_olp(const UnitCell& ucell, // out_pure_ri_tensor("olp_all.dat", olp_all, 0.); auto olp_inv = LRI_CV_Tools::cal_I(olp_all, Inverse_Matrix>::Method::syev, - GlobalC::exx_info.info_ri.shrink_LU_inv_thr); + this->info.shrink_LU_inv_thr); for (int ir = 0; ir < all_mu_s; ir++) { for (int ic = ir; ic < all_mu_s; ic++) From b6630b2f52e1523f1d1f8d830cbc3a330a0dab4a Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Tue, 14 Jul 2026 08:23:16 +0800 Subject: [PATCH 10/13] Phase 10: Final cleanup - remove GlobalC::exx_info references and includes Delete global static object exx_lri_rpa in RPA_LRI.h. Update exx_rotate_abfs.h comment. Clean up includes in LRI_CV.hpp, exx_lip.hpp, and Exx_LRI_interface.hpp. Remove GlobalC::exx_info fallback in LRI_CV. After this phase, GlobalC::exx_info is no longer used in module_ri. --- source/source_lcao/module_ri/Exx_LRI_interface.hpp | 5 ++--- source/source_lcao/module_ri/LRI_CV.hpp | 6 +++--- source/source_lcao/module_ri/RPA_LRI.h | 1 - source/source_lcao/module_ri/exx_lip.hpp | 2 +- source/source_lcao/module_ri/exx_rotate_abfs.h | 4 ++-- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/source/source_lcao/module_ri/Exx_LRI_interface.hpp b/source/source_lcao/module_ri/Exx_LRI_interface.hpp index 266f5abede2..479d4c1691f 100644 --- a/source/source_lcao/module_ri/Exx_LRI_interface.hpp +++ b/source/source_lcao/module_ri/Exx_LRI_interface.hpp @@ -4,7 +4,6 @@ #include "source_base/formatter.h" #include "source_base/parallel_common.h" #include "source_estate/elecstate_lcao.h" -#include "source_hamilt/module_xc/exx_info.h" // use GlobalC::exx_info #include "source_hamilt/module_xc/xc_functional.h" #include "source_io/module_hs/write_HS_sparse.h" #include "source_io/module_output/csr_reader.h" @@ -333,7 +332,7 @@ bool Exx_LRI_Interface::exx_after_converge( const int& istep, const double& etot, const double& scf_ene_thr) -{ // only called if (GlobalC::exx_info.info_global.cal_exx) +{ // only called if (this->info_global.cal_exx) ModuleBase::TITLE("Exx_LRI_Interface","exx_after_converge"); auto restart_reset = [this]() { // avoid calling restart related procedure in the subsequent ion steps @@ -418,7 +417,7 @@ bool Exx_LRI_Interface::exx_after_converge( << std::defaultfloat << " (s)" << std::endl; return false; } - } // if(GlobalC::exx_info.info_global.separate_loop) + } // if(this->info_global.separate_loop) restart_reset(); return true; } diff --git a/source/source_lcao/module_ri/LRI_CV.hpp b/source/source_lcao/module_ri/LRI_CV.hpp index 53212a7b149..d30a78cc752 100644 --- a/source/source_lcao/module_ri/LRI_CV.hpp +++ b/source/source_lcao/module_ri/LRI_CV.hpp @@ -13,7 +13,7 @@ #include "../../source_basis/module_ao/element_basis_index-ORB.h" #include "../../source_base/tool_title.h" #include "../../source_base/timer.h" -#include "source_hamilt/module_xc/exx_info.h" // use GlobalC::exx_info +#include "source_hamilt/module_xc/exx_info_ri.h" #include #include @@ -353,7 +353,7 @@ LRI_CV::DPcal_C_dC( Matrix_Orbs21::Matrix_Order::A1A2B); const RI::Tensor V = this->DPcal_V(it0, it0, {0, 0, 0}, {{"writable_Vws", true}}); RI::Tensor L; - const double cs_inv_thr = this->p_info_ri != nullptr ? this->p_info_ri->Cs_inv_thr : GlobalC::exx_info.info_ri.Cs_inv_thr; + const double cs_inv_thr = this->p_info_ri != nullptr ? this->p_info_ri->Cs_inv_thr : 0.0; if (cs_inv_thr > 0) L = LRI_CV_Tools::cal_I(V, Inverse_Matrix::Method::syev, cs_inv_thr); else @@ -406,7 +406,7 @@ LRI_CV::DPcal_C_dC( DPcal_V(it1, it1, {0,0,0}, {{"writable_Vws",true}})}}; std::vector>> L; - const double cs_inv_thr = this->p_info_ri != nullptr ? this->p_info_ri->Cs_inv_thr : GlobalC::exx_info.info_ri.Cs_inv_thr; + const double cs_inv_thr = this->p_info_ri != nullptr ? this->p_info_ri->Cs_inv_thr : 0.0; if (cs_inv_thr > 0) L = LRI_CV_Tools::cal_I(V, Inverse_Matrix::Method::syev, cs_inv_thr); else diff --git a/source/source_lcao/module_ri/RPA_LRI.h b/source/source_lcao/module_ri/RPA_LRI.h index 36548003448..36b4c5fd577 100644 --- a/source/source_lcao/module_ri/RPA_LRI.h +++ b/source/source_lcao/module_ri/RPA_LRI.h @@ -107,7 +107,6 @@ template class RPA_LRI Exx_LRI* exx_cut_coulomb = nullptr; Exx_LRI* exx_full_coulomb = nullptr; }; -Exx_LRI exx_lri_rpa(GlobalC::exx_info.info_ri); #include "RPA_LRI.hpp" #endif diff --git a/source/source_lcao/module_ri/exx_lip.hpp b/source/source_lcao/module_ri/exx_lip.hpp index fb84383825d..5a86681c21b 100644 --- a/source/source_lcao/module_ri/exx_lip.hpp +++ b/source/source_lcao/module_ri/exx_lip.hpp @@ -23,7 +23,7 @@ #include "source_pw/module_pwdft/structure_factor.h" #include "source_base/tool_title.h" #include "source_base/timer.h" -#include "source_hamilt/module_xc/exx_info.h" // use GlobalC::exx_info +#include "source_hamilt/module_xc/exx_info_lip.h" #include #include diff --git a/source/source_lcao/module_ri/exx_rotate_abfs.h b/source/source_lcao/module_ri/exx_rotate_abfs.h index e96d109c893..dde8dd8ae62 100644 --- a/source/source_lcao/module_ri/exx_rotate_abfs.h +++ b/source/source_lcao/module_ri/exx_rotate_abfs.h @@ -68,8 +68,8 @@ class Moment_abfs private: // std::map>> VR; - // WARNING: reference to Exx_Info_RI, which holds references into Exx_Info_Global. - // Must not outlive GlobalC::exx_info. See exx_info.h for details. + // WARNING: reference to Exx_Info_RI. + // Must not outlive the Exx_Info_RI passed to the constructor. Exx_Info_RI& info; }; #include "exx_rotate_abfs.hpp" From f118e39e09eec4387c9ed396809043a5abf17f3b Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Tue, 14 Jul 2026 08:46:47 +0800 Subject: [PATCH 11/13] update the code --- source/source_lcao/module_ri/Exx_LRI.hpp | 3 ++- source/source_lcao/module_ri/ewald_Vq.h | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/source_lcao/module_ri/Exx_LRI.hpp b/source/source_lcao/module_ri/Exx_LRI.hpp index 98551878662..2d22ae1ef23 100644 --- a/source/source_lcao/module_ri/Exx_LRI.hpp +++ b/source/source_lcao/module_ri/Exx_LRI.hpp @@ -82,10 +82,11 @@ void Exx_LRI::init(const MPI_Comm &mpi_comm_in, this->exx_objs[settings_list.first].cv.set_info_ri(&this->info); if (settings_list.first == Conv_Coulomb_Pot_K::Coulomb_Method::Ewald) { + const int evq_abfs_Lmax = this->abfs_Lmax_; this->exx_objs[settings_list.first].evq.init(ucell, orb, this->mpi_comm, this->p_kv, this->lcaos, this->abfs, settings_list.second.second, this->MGT, this->info.ccp_rmesh_times, this->info.kmesh_times, - this->abfs_Lmax_); + evq_abfs_Lmax); } } diff --git a/source/source_lcao/module_ri/ewald_Vq.h b/source/source_lcao/module_ri/ewald_Vq.h index 505ae9b9022..b134c8cd264 100644 --- a/source/source_lcao/module_ri/ewald_Vq.h +++ b/source/source_lcao/module_ri/ewald_Vq.h @@ -57,7 +57,7 @@ class Ewald_Vq std::shared_ptr MGT_in, const double &ccp_rmesh_times_in, const double &kmesh_times_in, - const int abfs_Lmax_in = 0); + const int abfs_Lmax_in); void init_ions(const UnitCell& ucell, const std::array& period_Vs_NAO); @@ -101,7 +101,6 @@ class Ewald_Vq std::vector g_abfs_ccp_rcut; std::map>> coulomb_param; - const int nspin0 = std::map{{1, 1}, {2, 2}, {4, 1}}.at(PARAM.inp.nspin); int nks0; std::vector atoms_vec; From c895eea44c1dfa6c60f1198ab0810ac3176f8889 Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Wed, 15 Jul 2026 09:35:58 +0800 Subject: [PATCH 12/13] Fix: HSE energy deviation caused by stale info_global cache in Exx_LRI_Interface --- source/source_lcao/module_ri/Exx_LRI_interface.h | 5 +++++ source/source_lcao/setup_exx.cpp | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/source/source_lcao/module_ri/Exx_LRI_interface.h b/source/source_lcao/module_ri/Exx_LRI_interface.h index c8536b44eb1..d44440c0420 100644 --- a/source/source_lcao/module_ri/Exx_LRI_interface.h +++ b/source/source_lcao/module_ri/Exx_LRI_interface.h @@ -143,6 +143,11 @@ class Exx_LRI_Interface size_t hybrid_step() const { return hybrid_step_; } void set_hybrid_step(size_t s) { hybrid_step_ = s; } + void update_info_global(const Exx_Info_Global& info_global_in) + { + this->info_global = info_global_in; + } + std::shared_ptr> exx_ptr; private: diff --git a/source/source_lcao/setup_exx.cpp b/source/source_lcao/setup_exx.cpp index d6bcc97d5c3..40ccc13b7a4 100644 --- a/source/source_lcao/setup_exx.cpp +++ b/source/source_lcao/setup_exx.cpp @@ -45,6 +45,15 @@ void Exx_NAO::before_runner( { if (GlobalC::exx_info.info_global.cal_exx) { + if (GlobalC::exx_info.info_ri.real_number) + { + this->exd->update_info_global(GlobalC::exx_info.info_global); + } + else + { + this->exc->update_info_global(GlobalC::exx_info.info_global); + } + if (inp.init_wfc != "file") { // if init_wfc==file, directly enter the EXX loop XC_Functional::set_xc_first_loop(ucell); From 5e94b38edd2fe478ba9504c181149824348c6d5b Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Wed, 15 Jul 2026 11:38:52 +0800 Subject: [PATCH 13/13] =?UTF-8?q?fix=20bug=20because=20hybrid=5Fstep=5F=20?= =?UTF-8?q?=E5=9C=A8=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0=E4=B8=AD=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E4=BB=8E=20info=5Fglobal.hybrid=5Fstep=20=E5=88=9D?= =?UTF-8?q?=E5=A7=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/source_esolver/esolver_ks_lcao.cpp | 10 ++++++---- source/source_lcao/module_ri/Exx_LRI_interface.h | 6 +----- source/source_lcao/setup_exx.cpp | 9 --------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/source/source_esolver/esolver_ks_lcao.cpp b/source/source_esolver/esolver_ks_lcao.cpp index 09e1b4b1177..094c8ee4940 100644 --- a/source/source_esolver/esolver_ks_lcao.cpp +++ b/source/source_esolver/esolver_ks_lcao.cpp @@ -35,15 +35,14 @@ ESolver_KS_LCAO::ESolver_KS_LCAO() { this->classname = "ESolver_KS_LCAO"; this->basisname = "LCAO"; - this->exx_nao.init(); // mohan add 20251008 } template ESolver_KS_LCAO::~ESolver_KS_LCAO() { - //**************************************************** - // do not add any codes in this deconstructor funcion - //**************************************************** + //**************************************************** + // do not add any codes in this deconstructor funcion + //**************************************************** Setup_Psi::deallocate_psi(this->psi); } @@ -53,6 +52,9 @@ void ESolver_KS_LCAO::before_all_runners(UnitCell& ucell, const Input_pa ModuleBase::TITLE("ESolver_KS_LCAO", "before_all_runners"); ModuleBase::timer::start("ESolver_KS_LCAO", "before_all_runners"); + // 0) init EXX - moved from constructor to ensure GlobalC::exx_info.info_global is already set + this->exx_nao.init(); + // 1) before_all_runners in ESolver_KS ESolver_KS::before_all_runners(ucell, inp); diff --git a/source/source_lcao/module_ri/Exx_LRI_interface.h b/source/source_lcao/module_ri/Exx_LRI_interface.h index d44440c0420..810a3090771 100644 --- a/source/source_lcao/module_ri/Exx_LRI_interface.h +++ b/source/source_lcao/module_ri/Exx_LRI_interface.h @@ -44,6 +44,7 @@ class Exx_LRI_Interface { this->exx_ptr = std::make_shared>(info_ri); this->info_global = info_global; + this->hybrid_step_ = info_global.hybrid_step; } Exx_LRI_Interface() = delete; @@ -143,11 +144,6 @@ class Exx_LRI_Interface size_t hybrid_step() const { return hybrid_step_; } void set_hybrid_step(size_t s) { hybrid_step_ = s; } - void update_info_global(const Exx_Info_Global& info_global_in) - { - this->info_global = info_global_in; - } - std::shared_ptr> exx_ptr; private: diff --git a/source/source_lcao/setup_exx.cpp b/source/source_lcao/setup_exx.cpp index 40ccc13b7a4..d6bcc97d5c3 100644 --- a/source/source_lcao/setup_exx.cpp +++ b/source/source_lcao/setup_exx.cpp @@ -45,15 +45,6 @@ void Exx_NAO::before_runner( { if (GlobalC::exx_info.info_global.cal_exx) { - if (GlobalC::exx_info.info_ri.real_number) - { - this->exd->update_info_global(GlobalC::exx_info.info_global); - } - else - { - this->exc->update_info_global(GlobalC::exx_info.info_global); - } - if (inp.init_wfc != "file") { // if init_wfc==file, directly enter the EXX loop XC_Functional::set_xc_first_loop(ucell);