diff --git a/source/source_esolver/esolver_ks_lcao.cpp b/source/source_esolver/esolver_ks_lcao.cpp index 09e1b4b117..094c8ee494 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_hcontainer/test/test_add_value.cpp b/source/source_lcao/module_hcontainer/test/test_add_value.cpp index 2bdd1529f4..201df363a3 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]; diff --git a/source/source_lcao/module_ri/Exx_LRI.h b/source/source_lcao/module_ri/Exx_LRI.h index 2b97552c47..d4332cf968 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.hpp b/source/source_lcao/module_ri/Exx_LRI.hpp index e4f8a6dbd0..2d22ae1ef2 100644 --- a/source/source_lcao/module_ri/Exx_LRI.hpp +++ b/source/source_lcao/module_ri/Exx_LRI.hpp @@ -65,7 +65,9 @@ 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); + } this->exx_objs.clear(); this->coulomb_settings = RI_Util::update_coulomb_settings(this->info.coulomb_param, ucell, this->p_kv); @@ -77,11 +79,14 @@ 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) { + 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); + settings_list.second.second, this->MGT, this->info.ccp_rmesh_times, this->info.kmesh_times, + evq_abfs_Lmax); } } @@ -125,8 +130,7 @@ 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); } this->exx_objs.clear(); @@ -152,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/Exx_LRI_interface.h b/source/source_lcao/module_ri/Exx_LRI_interface.h index 66fe9cab06..810a309077 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,11 @@ 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; + this->hybrid_step_ = info_global.hybrid_step; } Exx_LRI_Interface() = delete; @@ -138,12 +141,18 @@ 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; + Exx_Info_Global info_global; + size_t hybrid_step_ = 1; + bool exx_spacegroup_symmetry = false; ModuleSymmetry::Symmetry_rotation symrot_; diff --git a/source/source_lcao/module_ri/Exx_LRI_interface.hpp b/source/source_lcao/module_ri/Exx_LRI_interface.hpp index 0172fb4d56..479d4c1691 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" @@ -136,7 +135,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 +152,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 +178,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) @@ -207,7 +206,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()); } @@ -241,10 +240,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 +266,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 +295,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(); } @@ -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 @@ -342,9 +341,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 +370,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 { @@ -403,7 +402,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 @@ -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.h b/source/source_lcao/module_ri/LRI_CV.h index c23f1e5c61..7e64961fdd 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/LRI_CV.hpp b/source/source_lcao/module_ri/LRI_CV.hpp index d429904f14..d30a78cc75 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,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 : 0.0; + 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 : 0.0; + 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/RPA_LRI.h b/source/source_lcao/module_ri/RPA_LRI.h index ccadf8d038..36b4c5fd57 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_; @@ -109,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/RPA_LRI.hpp b/source/source_lcao/module_ri/RPA_LRI.hpp index 31b6181850..b1492d8dac 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; } @@ -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); @@ -146,18 +146,18 @@ 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 - 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; + // 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; + 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 (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_"); @@ -259,11 +259,12 @@ 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 (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); @@ -316,7 +317,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; @@ -800,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++) diff --git a/source/source_lcao/module_ri/ewald_Vq.h b/source/source_lcao/module_ri/ewald_Vq.h index 7a125b4bcc..b134c8cd26 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); 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; @@ -99,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; diff --git a/source/source_lcao/module_ri/ewald_Vq.hpp b/source/source_lcao/module_ri/ewald_Vq.hpp index 7d357945b5..5dd3a2d1ea 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"); } diff --git a/source/source_lcao/module_ri/exx_lip.hpp b/source/source_lcao/module_ri/exx_lip.hpp index fb84383825..5a86681c21 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 e96d109c89..dde8dd8ae6 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" diff --git a/source/source_lcao/module_ri/exx_rotate_abfs.hpp b/source/source_lcao/module_ri/exx_rotate_abfs.hpp index ec5650f498..b324394d78 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) { diff --git a/source/source_lcao/setup_exx.cpp b/source/source_lcao/setup_exx.cpp index 5734f47add..d6bcc97d5c 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 }