Skip to content

Commit 64c4580

Browse files
committed
directly enter exx loop when init_wfc=file
1 parent 7838569 commit 64c4580

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

Diff for: source/module_esolver/esolver_ks_lcao.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
185185
{
186186
if (GlobalC::exx_info.info_global.cal_exx)
187187
{
188-
XC_Functional::set_xc_first_loop(ucell);
188+
if (PARAM.inp.init_wfc != "file")
189+
{ // if init_wfc==file, directly enter the EXX loop
190+
XC_Functional::set_xc_first_loop(ucell);
191+
}
192+
189193
// initialize 2-center radial tables for EXX-LRI
190194
if (GlobalC::exx_info.info_ri.real_number)
191195
{
@@ -607,7 +611,17 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
607611
// electrons number.
608612
if (istep == 0 && PARAM.inp.init_wfc == "file")
609613
{
610-
if (iter == 1)
614+
int exx_two_level_step = 0;
615+
#ifdef __EXX
616+
if (GlobalC::exx_info.info_global.cal_exx)
617+
{
618+
// the following steps are only needed in the first outer exx loop
619+
exx_two_level_step = GlobalC::exx_info.info_ri.real_number ?
620+
this->exd->two_level_step
621+
: this->exc->two_level_step;
622+
}
623+
#endif
624+
if (iter == 1 && exx_two_level_step == 0)
611625
{
612626
std::cout << " WAVEFUN -> CHARGE " << std::endl;
613627

Diff for: source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,14 @@ void OperatorEXX<OperatorLCAO<TK, TR>>::contributeHR()
251251
{
252252
ModuleBase::TITLE("OperatorEXX", "contributeHR");
253253
// Peize Lin add 2016-12-03
254-
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
254+
if (this->istep == 0
255+
&& PARAM.inp.calculation != "nscf"
256+
&& this->two_level_step != nullptr && *this->two_level_step == 0
257+
&& PARAM.inp.init_wfc != "file"
258+
&& !this->restart)
259+
{
260+
return;
261+
} //in the non-exx loop, do nothing
255262
if (this->add_hexx_type == Add_Hexx_Type::k) { return; }
256263

257264
if (XC_Functional::get_func_type() == 4 || XC_Functional::get_func_type() == 5)

Diff for: source/module_ri/Exx_LRI_interface.hpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ void Exx_LRI_Interface<T, Tdata>::exx_beforescf(const int istep,
6262
#ifdef __MPI
6363
if (GlobalC::exx_info.info_global.cal_exx)
6464
{
65-
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);
66-
}
67-
else if (istep > 0) { XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
68-
}
65+
if ((GlobalC::restart.info_load.load_H_finish && !GlobalC::restart.info_load.restart_exx)
66+
|| (istep > 0)
67+
|| (PARAM.inp.init_wfc == "file"))
68+
{
69+
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
70+
}
6971
else
7072
{
7173
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,
120122
const K_Vectors& kv,
121123
const int& iter)
122124
{
125+
std::cout << "iter=" << iter << std::endl;
123126
if (GlobalC::exx_info.info_global.cal_exx)
124127
{
125-
if (!GlobalC::exx_info.info_global.separate_loop && (this->two_level_step || istep > 0))
128+
if (!GlobalC::exx_info.info_global.separate_loop && (this->two_level_step || istep > 0 || PARAM.inp.init_wfc == "file") // non separate loop case
129+
|| (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
126130
{
131+
std::cout << "update exx" << std::endl;
127132
const bool flag_restart = (iter == 1) ? true : false;
128133
auto cal = [this, &ucell,&kv, &flag_restart](const elecstate::DensityMatrix<T, double>& dm_in)
129134
{
@@ -313,7 +318,8 @@ bool Exx_LRI_Interface<T, Tdata>::exx_after_converge(
313318
std::cout << " Updating EXX " << std::flush;
314319
timeval t_start; gettimeofday(&t_start, nullptr);
315320

316-
const bool flag_restart = (this->two_level_step == 0) ? true : false;
321+
// if init_wfc == "file", DM is calculated in the 1st iter of the 1st two-level step, so we mix it here
322+
const bool flag_restart = (this->two_level_step == 0 && PARAM.inp.init_wfc != "file") ? true : false;
317323

318324
if (this->exx_spacegroup_symmetry)
319325
{this->mix_DMk_2D.mix(symrot_.restore_dm(kv, dm.get_DMK_vector(), *dm.get_paraV_pointer()), flag_restart);}

0 commit comments

Comments
 (0)