Skip to content

Commit 669fa7b

Browse files
Refactor
1 parent 9381f8c commit 669fa7b

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

source/source_esolver/esolver_ks_pw.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,17 +594,15 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
594594
{
595595
dexx = exx_helper.cal_exx_energy(this->kspw_psi);
596596
}
597-
exx_helper.set_psi(this->kspw_psi);
597+
exx_helper.set_psi(this->kspw_psi);
598598
if (PARAM.inp.exx_thr_type == "energy")
599599
{
600600
dexx -= exx_helper.cal_exx_energy(this->kspw_psi);
601-
conv_esolver = std::abs(dexx) < PARAM.inp.exx_ene_thr || exx_helper.exx_after_converge(iter);
602601
// std::cout << "dexx = " << dexx << std::endl;
603602
}
604-
else if (PARAM.inp.exx_thr_type == "density")
605-
{
606-
conv_esolver = exx_helper.exx_after_converge(iter);
607-
}
603+
bool conv_ene = std::abs(dexx) < PARAM.inp.exx_ene_thr;
604+
605+
conv_esolver = exx_helper.exx_after_converge(iter, conv_ene);
608606
if (!conv_esolver)
609607
{
610608
auto duration = std::chrono::high_resolution_clock::now() - start;
@@ -614,6 +612,7 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
614612
exx_helper.op_exx->first_iter = false;
615613
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
616614
update_pot(ucell, istep, iter, conv_esolver);
615+
exx_helper.iter_inc();
617616
}
618617
}
619618
}

source/source_pw/module_pwdft/module_exx_helper/exx_helper.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ double Exx_Helper<T, Device>::cal_exx_energy(psi::Psi<T, Device> *psi_)
88
}
99

1010
template <typename T, typename Device>
11-
bool Exx_Helper<T, Device>::exx_after_converge(int &iter)
11+
bool Exx_Helper<T, Device>::exx_after_converge(int &iter, bool ene_conv)
1212
{
1313
if (op_exx->first_iter)
1414
{
@@ -18,10 +18,20 @@ bool Exx_Helper<T, Device>::exx_after_converge(int &iter)
1818
{
1919
return true;
2020
}
21-
else if (iter == 1)
21+
else if (PARAM.inp.exx_thr_type == "energy" && ene_conv)
2222
{
2323
return true;
2424
}
25+
else if (PARAM.inp.exx_thr_type == "density" && iter == 1)
26+
{
27+
return true;
28+
}
29+
else if (iter >= PARAM.inp.exx_hybrid_step)
30+
{
31+
GlobalV::ofs_running << " !!EXX IS NOT CONVERGED!!" << std::endl;
32+
std::cout << " !!EXX IS NOT CONVERGED!!" << std::endl;
33+
return true;
34+
}
2535
GlobalV::ofs_running << "Updating EXX and rerun SCF" << std::endl;
2636
iter = 0;
2737
return false;

source/source_pw/module_pwdft/module_exx_helper/exx_helper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct Exx_Helper
2121
void set_firstiter(bool flag = true) { first_iter = flag; }
2222
void set_wg(const ModuleBase::matrix *wg_) { wg = wg_; }
2323
void set_psi(psi::Psi<T, Device> *psi_);
24+
void iter_inc() { exx_iter++; }
2425

2526
void set_op()
2627
{
@@ -29,14 +30,15 @@ struct Exx_Helper
2930
op_exx->set_wg(wg);
3031
}
3132

32-
bool exx_after_converge(int &iter);
33+
bool exx_after_converge(int &iter, bool ene_conv);
3334

3435
double cal_exx_energy(psi::Psi<T, Device> *psi_);
3536

3637
private:
3738
bool first_iter = false;
3839
psi::Psi<T, Device> *psi = nullptr;
3940
const ModuleBase::matrix *wg = nullptr;
41+
int exx_iter = 0;
4042

4143
};
4244
#endif // EXX_HELPER_H

0 commit comments

Comments
 (0)