Skip to content
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

Fix: add energy_stable_count to ensure energy threshold is really achieved #5012

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions source/module_esolver/esolver_fp.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ namespace ModuleESolver

bool conv_elec; // If electron density is converged in scf.

int energy_stable_count = 0; // Counter for stable energy convergence.

protected:
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
virtual void after_scf(const int istep);
Expand Down
15 changes: 13 additions & 2 deletions source/module_esolver/esolver_ks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
bool firstscf = true;
this->conv_elec = false;
this->niter = this->maxniter;
this->energy_stable_count = 0;

// 4) SCF iterations
double diag_ethr = PARAM.inp.pw_diag_thr;
Expand Down Expand Up @@ -668,8 +669,18 @@ void ESolver_KS<T, Device>::iter_finish(int& iter)
// add a energy threshold for SCF convergence
if (this->conv_elec == 0) // only check when density is not converged
{
this->conv_elec
= (iter != 1 && std::abs(this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV) < this->scf_ene_thr);
if (iter != 1 && std::abs(this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV) < this->scf_ene_thr)
{
this->energy_stable_count++;
}
else
{
this->energy_stable_count = 0;
}
if (this->energy_stable_count >= 2) // energy stable for 2 steps
{
this->conv_elec = true;
}
}
}

Expand Down
Loading