diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index da425394f0..554be9a3c0 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -185,7 +185,11 @@ void ESolver_KS_LCAO::before_all_runners(UnitCell& ucell, const Input_pa { if (GlobalC::exx_info.info_global.cal_exx) { - XC_Functional::set_xc_first_loop(ucell); + if (PARAM.inp.init_wfc != "file") + { // if init_wfc==file, directly enter the EXX loop + XC_Functional::set_xc_first_loop(ucell); + } + // initialize 2-center radial tables for EXX-LRI if (GlobalC::exx_info.info_ri.real_number) { @@ -607,7 +611,17 @@ void ESolver_KS_LCAO::iter_init(UnitCell& ucell, const int istep, const // electrons number. if (istep == 0 && PARAM.inp.init_wfc == "file") { - if (iter == 1) + int exx_two_level_step = 0; +#ifdef __EXX + if (GlobalC::exx_info.info_global.cal_exx) + { + // the following steps are only needed in the first outer exx loop + exx_two_level_step = GlobalC::exx_info.info_ri.real_number ? + this->exd->two_level_step + : this->exc->two_level_step; + } +#endif + if (iter == 1 && exx_two_level_step == 0) { std::cout << " WAVEFUN -> CHARGE " << std::endl; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp index e20ca09b6e..5c4af43f40 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp @@ -251,7 +251,14 @@ void OperatorEXX>::contributeHR() { ModuleBase::TITLE("OperatorEXX", "contributeHR"); // Peize Lin add 2016-12-03 - if (this->istep == 0 && PARAM.inp.calculation != "nscf" && this->two_level_step != nullptr && *this->two_level_step == 0 && !this->restart) { return; } //in the non-exx loop, do nothing + if (this->istep == 0 + && PARAM.inp.calculation != "nscf" + && this->two_level_step != nullptr && *this->two_level_step == 0 + && PARAM.inp.init_wfc != "file" + && !this->restart) + { + return; + } //in the non-exx loop, do nothing if (this->add_hexx_type == Add_Hexx_Type::k) { return; } if (XC_Functional::get_func_type() == 4 || XC_Functional::get_func_type() == 5) diff --git a/source/module_ri/Exx_LRI_interface.hpp b/source/module_ri/Exx_LRI_interface.hpp index cdf3b219c9..8eecf44cc9 100644 --- a/source/module_ri/Exx_LRI_interface.hpp +++ b/source/module_ri/Exx_LRI_interface.hpp @@ -62,10 +62,12 @@ void Exx_LRI_Interface::exx_beforescf(const int istep, #ifdef __MPI if (GlobalC::exx_info.info_global.cal_exx) { - if (GlobalC::restart.info_load.load_H_finish && !GlobalC::restart.info_load.restart_exx) { XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func); - } - else if (istep > 0) { XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func); - } + if ((GlobalC::restart.info_load.load_H_finish && !GlobalC::restart.info_load.restart_exx) + || (istep > 0) + || (PARAM.inp.init_wfc == "file")) + { + XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func); + } else { if (ucell.atoms[0].ncpp.xc_func == "HF" || ucell.atoms[0].ncpp.xc_func == "PBE0" || ucell.atoms[0].ncpp.xc_func == "HSE") @@ -120,10 +122,13 @@ void Exx_LRI_Interface::exx_eachiterinit(const int istep, const K_Vectors& kv, const int& iter) { + std::cout << "iter=" << iter << std::endl; if (GlobalC::exx_info.info_global.cal_exx) { - if (!GlobalC::exx_info.info_global.separate_loop && (this->two_level_step || istep > 0)) + if (!GlobalC::exx_info.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 && PARAM.inp.init_wfc == "file" && this->two_level_step == 0 && iter == 1)) // the first iter in separate loop case { + std::cout << "update exx" << std::endl; const bool flag_restart = (iter == 1) ? true : false; auto cal = [this, &ucell,&kv, &flag_restart](const elecstate::DensityMatrix& dm_in) { @@ -313,7 +318,8 @@ bool Exx_LRI_Interface::exx_after_converge( std::cout << " Updating EXX " << std::flush; timeval t_start; gettimeofday(&t_start, nullptr); - const bool flag_restart = (this->two_level_step == 0) ? true : false; + // if init_wfc == "file", DM is calculated in the 1st iter of the 1st two-level step, so we mix it here + const bool flag_restart = (this->two_level_step == 0 && PARAM.inp.init_wfc != "file") ? true : false; if (this->exx_spacegroup_symmetry) {this->mix_DMk_2D.mix(symrot_.restore_dm(kv, dm.get_DMK_vector(), *dm.get_paraV_pointer()), flag_restart);}