From 8f69fa2259bcd462e4057cd92d91e70d2aa7f7fb Mon Sep 17 00:00:00 2001 From: Weiqing Zhou Date: Thu, 31 Oct 2024 11:04:42 +0800 Subject: [PATCH 1/4] add the energy threshold for SCF before mix_rho --- source/module_esolver/esolver_ks.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index 215182775d..a878935bcb 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -547,6 +547,18 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) this->conv_esolver = (drho < this->scf_thr && not_restart_step && is_U_converged); + // add energy threshold for SCF convergence + if (this->scf_ene_thr > 0.0 && iter > 1 && this->conv_esolver == 1) // only check when density is converged + { + // only calculate energy when density is converged to reduce the time cost + this->pelec->cal_energies(2); // 2 means Kohn-Sham functional + // now, etot_old is the energy of input density, while etot is the energy of output density + this->pelec->f_en.etot_delta = this->pelec->f_en.etot - this->pelec->f_en.etot_old; + // update the convergence flag + this->conv_esolver + = (std::abs(this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV) < this->scf_ene_thr); + } + // If drho < hsolver_error in the first iter or drho < scf_thr, we // do not change rho. if (drho < hsolver_error || this->conv_esolver) From d4540f05e019ed379caf001cd00062990aea6fb1 Mon Sep 17 00:00:00 2001 From: Weiqing Zhou Date: Thu, 31 Oct 2024 11:06:11 +0800 Subject: [PATCH 2/4] delete the energy threshold in iter_finish() --- source/module_esolver/esolver_ks.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index a878935bcb..cff70d3184 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -681,13 +681,6 @@ void ESolver_KS::iter_finish(int& iter) } this->pelec->f_en.etot_delta = this->pelec->f_en.etot - this->pelec->f_en.etot_old; this->pelec->f_en.etot_old = this->pelec->f_en.etot; - - // add a energy threshold for SCF convergence - if (this->scf_ene_thr > 0.0 && this->conv_esolver == 1) // only check when density is converged - { - this->conv_esolver - = (std::abs(this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV) < this->scf_ene_thr); - } } //! Something to do after SCF iterations when SCF is converged or comes to the max iter step. From e291ed02e4ce5254381afb767c673abfed4408b4 Mon Sep 17 00:00:00 2001 From: Weiqing Zhou Date: Thu, 31 Oct 2024 11:19:36 +0800 Subject: [PATCH 3/4] calculate the energy of output density every iteration and output it --- source/module_esolver/esolver_ks.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index cff70d3184..86ba60b03e 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -547,13 +547,15 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) this->conv_esolver = (drho < this->scf_thr && not_restart_step && is_U_converged); + // calculate energy of output charge density + this->pelec->cal_energies(2); // 2 means Kohn-Sham functional + // now, etot_old is the energy of input density, while etot is the energy of output density + this->pelec->f_en.etot_delta = this->pelec->f_en.etot - this->pelec->f_en.etot_old; + // output etot_delta + GlobalV::ofs_running << " DeltaE_womix = " << this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV << " eV" << std::endl; // add energy threshold for SCF convergence if (this->scf_ene_thr > 0.0 && iter > 1 && this->conv_esolver == 1) // only check when density is converged { - // only calculate energy when density is converged to reduce the time cost - this->pelec->cal_energies(2); // 2 means Kohn-Sham functional - // now, etot_old is the energy of input density, while etot is the energy of output density - this->pelec->f_en.etot_delta = this->pelec->f_en.etot - this->pelec->f_en.etot_old; // update the convergence flag this->conv_esolver = (std::abs(this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV) < this->scf_ene_thr); From 70e5b877409974554e596e3722e157d30b991470 Mon Sep 17 00:00:00 2001 From: Weiqing Zhou Date: Thu, 31 Oct 2024 11:40:58 +0800 Subject: [PATCH 4/4] only update_pot for scf_ene_thr>0 --- source/module_esolver/esolver_ks.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index 86ba60b03e..bbbe1bb4ad 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -547,18 +547,22 @@ void ESolver_KS::runner(const int istep, UnitCell& ucell) this->conv_esolver = (drho < this->scf_thr && not_restart_step && is_U_converged); - // calculate energy of output charge density - this->pelec->cal_energies(2); // 2 means Kohn-Sham functional - // now, etot_old is the energy of input density, while etot is the energy of output density - this->pelec->f_en.etot_delta = this->pelec->f_en.etot - this->pelec->f_en.etot_old; - // output etot_delta - GlobalV::ofs_running << " DeltaE_womix = " << this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV << " eV" << std::endl; // add energy threshold for SCF convergence - if (this->scf_ene_thr > 0.0 && iter > 1 && this->conv_esolver == 1) // only check when density is converged + if (this->scf_ene_thr > 0.0) { - // update the convergence flag - this->conv_esolver - = (std::abs(this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV) < this->scf_ene_thr); + // calculate energy of output charge density + this->update_pot(istep, iter); + this->pelec->cal_energies(2); // 2 means Kohn-Sham functional + // now, etot_old is the energy of input density, while etot is the energy of output density + this->pelec->f_en.etot_delta = this->pelec->f_en.etot - this->pelec->f_en.etot_old; + // output etot_delta + GlobalV::ofs_running << " DeltaE_womix = " << this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV << " eV" << std::endl; + if (iter > 1 && this->conv_esolver == 1) // only check when density is converged + { + // update the convergence flag + this->conv_esolver + = (std::abs(this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV) < this->scf_ene_thr); + } } // If drho < hsolver_error in the first iter or drho < scf_thr, we