diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index f1acab2934..941e4e6087 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -63,6 +63,23 @@ ESolver_KS_LCAO::ESolver_KS_LCAO() { this->classname = "ESolver_KS_LCAO"; this->basisname = "LCAO"; +#ifdef __EXX + // 1. currently this initialization must be put in constructor rather than `before_all_runners()` + // because the latter is not reused by ESolver_LCAO_TDDFT, + // which cause the failure of the subsequent procedure reused by ESolver_LCAO_TDDFT + // 2. always construct but only initialize when if(cal_exx) is true + // because some members like two_level_step are used outside if(cal_exx) + if (GlobalC::exx_info.info_ri.real_number) + { + this->exx_lri_double = std::make_shared>(GlobalC::exx_info.info_ri); + this->exd = std::make_shared>(exx_lri_double); + } + else + { + this->exx_lri_complex = std::make_shared>>(GlobalC::exx_info.info_ri); + this->exc = std::make_shared>>(exx_lri_complex); + } +#endif } //------------------------------------------------------------------------------ @@ -173,16 +190,8 @@ void ESolver_KS_LCAO::before_all_runners(Input& inp, UnitCell& ucell) { XC_Functional::set_xc_first_loop(ucell); // initialize 2-center radial tables for EXX-LRI - if (GlobalC::exx_info.info_ri.real_number) - { - this->exx_lri_double = std::make_shared>(GlobalC::exx_info.info_ri); - this->exx_lri_double->init(MPI_COMM_WORLD, this->kv); - } - else - { - this->exx_lri_complex = std::make_shared>>(GlobalC::exx_info.info_ri); - this->exx_lri_complex->init(MPI_COMM_WORLD, this->kv); - } + if (GlobalC::exx_info.info_ri.real_number) { this->exx_lri_double->init(MPI_COMM_WORLD, this->kv); } + else { this->exx_lri_complex->init(MPI_COMM_WORLD, this->kv); } } } #endif diff --git a/source/module_esolver/esolver_ks_lcao_elec.cpp b/source/module_esolver/esolver_ks_lcao_elec.cpp index 0bed54ff71..3699a53c7a 100644 --- a/source/module_esolver/esolver_ks_lcao_elec.cpp +++ b/source/module_esolver/esolver_ks_lcao_elec.cpp @@ -284,12 +284,10 @@ void ESolver_KS_LCAO::before_scf(const int istep) #ifdef __EXX // set xc type before the first cal of xc in pelec->init_scf if (GlobalC::exx_info.info_ri.real_number) { - this->exd = std::make_shared>(exx_lri_double); this->exd->exx_beforescf(this->kv, *this->p_chgmix); } else { - this->exc = std::make_shared>>(exx_lri_complex); this->exc->exx_beforescf(this->kv, *this->p_chgmix); } #endif // __EXX diff --git a/source/module_ri/Exx_LRI_interface.hpp b/source/module_ri/Exx_LRI_interface.hpp index 5dba84664d..def1417b55 100644 --- a/source/module_ri/Exx_LRI_interface.hpp +++ b/source/module_ri/Exx_LRI_interface.hpp @@ -72,10 +72,10 @@ void Exx_LRI_Interface::exx_beforescf(const K_Vectors& kv, const Charg this->mix_DMk_2D.set_mixing(nullptr); } else { this->mix_DMk_2D.set_mixing(chgmix.get_mixing()); -} + } + // for exx two_level scf + this->two_level_step = 0; } - // for exx two_level scf - this->two_level_step = 0; #endif // __MPI }