Skip to content

Commit b63aad4

Browse files
fix the conficit between mixing_restart and scf_os_stop (#5440)
1 parent 2d3bf57 commit b63aad4

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

source/module_elecstate/module_charge/charge_mixing.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,11 +1708,6 @@ bool Charge_Mixing::if_scf_oscillate(const int iteration, const double drho, con
17081708
ModuleBase::TITLE("Charge_Mixing", "if_scf_oscillate");
17091709
ModuleBase::timer::tick("Charge_Mixing", "if_scf_oscillate");
17101710

1711-
if(threshold >= 0) // close the function
1712-
{
1713-
return false;
1714-
}
1715-
17161711
if(this->_drho_history.size() == 0)
17171712
{
17181713
this->_drho_history.resize(PARAM.inp.scf_nmax);
@@ -1721,8 +1716,13 @@ bool Charge_Mixing::if_scf_oscillate(const int iteration, const double drho, con
17211716
// add drho into history
17221717
this->_drho_history[iteration - 1] = drho;
17231718

1719+
if(threshold >= 0) // close the function
1720+
{
1721+
return false;
1722+
}
1723+
17241724
// check if the history is long enough
1725-
if(iteration < iternum_used)
1725+
if(iteration < iternum_used + this->mixing_restart_last)
17261726
{
17271727
return false;
17281728
}

source/module_elecstate/module_charge/charge_mixing.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ class Charge_Mixing
102102
Base_Mixing::Mixing* get_mixing() const {return mixing;}
103103

104104
// for mixing restart
105-
int mixing_restart_step = 0; //which step to restart mixing during SCF
105+
int mixing_restart_step = 0; //which step to restart mixing during SCF, always equal to scf_namx except for the mixing restart
106106
int mixing_restart_count = 0; // the number of restart mixing during SCF. Do not set mixing_restart_count as bool since I want to keep some flexibility in the future
107+
int mixing_restart_last = 0; // the label of mixing restart step, store the step number of the last mixing restart
107108

108109
// to calculate the slope of drho curve during SCF, which is used to determine if SCF oscillate
109110
bool if_scf_oscillate(const int iteration, const double drho, const int iternum_used, const double threshold);

source/module_esolver/esolver_ks.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ void ESolver_KS<T, Device>::iter_finish(const int istep, int& iter)
681681
// notice for restart
682682
if (PARAM.inp.mixing_restart > 0 && iter == this->p_chgmix->mixing_restart_step - 1 && iter != PARAM.inp.scf_nmax)
683683
{
684+
this->p_chgmix->mixing_restart_last = iter;
684685
std::cout << " SCF restart after this step!" << std::endl;
685686
}
686687
}

0 commit comments

Comments
 (0)