Skip to content

Fix: directly enter exx loop when init_wfc=="file" #6019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions source/module_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
@@ -185,7 +185,11 @@ void ESolver_KS_LCAO<TK, TR>::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<TK, TR>::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;

Original file line number Diff line number Diff line change
@@ -251,7 +251,14 @@ void OperatorEXX<OperatorLCAO<TK, TR>>::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)
18 changes: 12 additions & 6 deletions source/module_ri/Exx_LRI_interface.hpp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've add a cout for printing "iter=" in this file. Is this a feature required or just for temporary check? I found that this message will be printed even if the calculation type is not HSE.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it's a debugging message that I forgot to delete. I will fix it in a new PR.

Original file line number Diff line number Diff line change
@@ -62,10 +62,12 @@ void Exx_LRI_Interface<T, Tdata>::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<T, Tdata>::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<T, double>& dm_in)
{
@@ -313,7 +318,8 @@ bool Exx_LRI_Interface<T, Tdata>::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);}