From b63aad45ce56e6d9d8d49695a325b2800055e872 Mon Sep 17 00:00:00 2001 From: wqzhou <33364058+WHUweiqingzhou@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:34:49 +0800 Subject: [PATCH] fix the conficit between mixing_restart and scf_os_stop (#5440) --- .../module_elecstate/module_charge/charge_mixing.cpp | 12 ++++++------ .../module_elecstate/module_charge/charge_mixing.h | 3 ++- source/module_esolver/esolver_ks.cpp | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/source/module_elecstate/module_charge/charge_mixing.cpp b/source/module_elecstate/module_charge/charge_mixing.cpp index 8f346d3b3d..f8e7a826d4 100644 --- a/source/module_elecstate/module_charge/charge_mixing.cpp +++ b/source/module_elecstate/module_charge/charge_mixing.cpp @@ -1708,11 +1708,6 @@ bool Charge_Mixing::if_scf_oscillate(const int iteration, const double drho, con ModuleBase::TITLE("Charge_Mixing", "if_scf_oscillate"); ModuleBase::timer::tick("Charge_Mixing", "if_scf_oscillate"); - if(threshold >= 0) // close the function - { - return false; - } - if(this->_drho_history.size() == 0) { 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 // add drho into history this->_drho_history[iteration - 1] = drho; + if(threshold >= 0) // close the function + { + return false; + } + // check if the history is long enough - if(iteration < iternum_used) + if(iteration < iternum_used + this->mixing_restart_last) { return false; } diff --git a/source/module_elecstate/module_charge/charge_mixing.h b/source/module_elecstate/module_charge/charge_mixing.h index a863865987..1b80911f46 100644 --- a/source/module_elecstate/module_charge/charge_mixing.h +++ b/source/module_elecstate/module_charge/charge_mixing.h @@ -102,8 +102,9 @@ class Charge_Mixing Base_Mixing::Mixing* get_mixing() const {return mixing;} // for mixing restart - int mixing_restart_step = 0; //which step to restart mixing during SCF + int mixing_restart_step = 0; //which step to restart mixing during SCF, always equal to scf_namx except for the mixing restart 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 + int mixing_restart_last = 0; // the label of mixing restart step, store the step number of the last mixing restart // to calculate the slope of drho curve during SCF, which is used to determine if SCF oscillate bool if_scf_oscillate(const int iteration, const double drho, const int iternum_used, const double threshold); diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index 45b228ed6c..4d3121a904 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -681,6 +681,7 @@ void ESolver_KS::iter_finish(const int istep, int& iter) // notice for restart if (PARAM.inp.mixing_restart > 0 && iter == this->p_chgmix->mixing_restart_step - 1 && iter != PARAM.inp.scf_nmax) { + this->p_chgmix->mixing_restart_last = iter; std::cout << " SCF restart after this step!" << std::endl; } }