Skip to content

Commit 4d2366c

Browse files
Feature: move scf_ene_thr before mix_rho (#5375)
* add the energy threshold for SCF before mix_rho * delete the energy threshold in iter_finish() * calculate the energy of output density every iteration and output it * only update_pot for scf_ene_thr>0
1 parent 4294ee7 commit 4d2366c

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

source/module_esolver/esolver_ks.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,24 @@ void ESolver_KS<T, Device>::runner(const int istep, UnitCell& ucell)
547547

548548
this->conv_esolver = (drho < this->scf_thr && not_restart_step && is_U_converged);
549549

550+
// add energy threshold for SCF convergence
551+
if (this->scf_ene_thr > 0.0)
552+
{
553+
// calculate energy of output charge density
554+
this->update_pot(istep, iter);
555+
this->pelec->cal_energies(2); // 2 means Kohn-Sham functional
556+
// now, etot_old is the energy of input density, while etot is the energy of output density
557+
this->pelec->f_en.etot_delta = this->pelec->f_en.etot - this->pelec->f_en.etot_old;
558+
// output etot_delta
559+
GlobalV::ofs_running << " DeltaE_womix = " << this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV << " eV" << std::endl;
560+
if (iter > 1 && this->conv_esolver == 1) // only check when density is converged
561+
{
562+
// update the convergence flag
563+
this->conv_esolver
564+
= (std::abs(this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV) < this->scf_ene_thr);
565+
}
566+
}
567+
550568
// If drho < hsolver_error in the first iter or drho < scf_thr, we
551569
// do not change rho.
552570
if (drho < hsolver_error || this->conv_esolver)
@@ -669,13 +687,6 @@ void ESolver_KS<T, Device>::iter_finish(int& iter)
669687
}
670688
this->pelec->f_en.etot_delta = this->pelec->f_en.etot - this->pelec->f_en.etot_old;
671689
this->pelec->f_en.etot_old = this->pelec->f_en.etot;
672-
673-
// add a energy threshold for SCF convergence
674-
if (this->scf_ene_thr > 0.0 && this->conv_esolver == 1) // only check when density is converged
675-
{
676-
this->conv_esolver
677-
= (std::abs(this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV) < this->scf_ene_thr);
678-
}
679690
}
680691

681692
//! Something to do after SCF iterations when SCF is converged or comes to the max iter step.

0 commit comments

Comments
 (0)