From ec6b267a138d298e00e65107c1abffd3b4ab9777 Mon Sep 17 00:00:00 2001 From: AsTonyshment Date: Sat, 7 Feb 2026 15:53:01 +0800 Subject: [PATCH] Fix RT-TDDFT segfault when initial SCF fails to converge --- source/source_esolver/esolver_ks_lcao_tddft.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/source_esolver/esolver_ks_lcao_tddft.cpp b/source/source_esolver/esolver_ks_lcao_tddft.cpp index 1ab68926d5..dbb001fa65 100644 --- a/source/source_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/source_esolver/esolver_ks_lcao_tddft.cpp @@ -1,11 +1,11 @@ #include "esolver_ks_lcao_tddft.h" //----------------IO----------------- -#include "source_io/module_ctrl/ctrl_output_td.h" #include "source_io/dipole_io.h" +#include "source_io/module_ctrl/ctrl_output_td.h" +#include "source_io/module_current/td_current_io.h" #include "source_io/module_output/output_log.h" #include "source_io/module_wf/read_wfc_nao.h" -#include "source_io/module_current/td_current_io.h" //------LCAO HSolver ElecState------- #include "source_estate/elecstate_tools.h" #include "source_estate/module_charge/symmetry_rho.h" @@ -203,7 +203,7 @@ void ESolver_KS_LCAO_TDDFT::runner(UnitCell& ucell, const int istep) } } - if(PARAM.inp.td_stype != 1 && TD_info::out_current == 1) + if (PARAM.inp.td_stype != 1 && TD_info::out_current == 1) { delete velocity_mat; } @@ -336,7 +336,9 @@ void ESolver_KS_LCAO_TDDFT::iter_finish(UnitCell& ucell, ESolver_KS_LCAO, TR>::iter_finish(ucell, istep, iter, conv_esolver); // Store wave function, Hamiltonian and Overlap matrix, to be used in next time step - this->store_h_s_psi(ucell, istep, iter, conv_esolver); + // Store when converged or reach max iteration + bool force_save = conv_esolver || (iter == this->maxniter); + this->store_h_s_psi(ucell, istep, iter, force_save); // Calculate energy-density matrix for RT-TDDFT if (conv_esolver && estep == estep_max - 1 && istep >= (PARAM.inp.init_wfc == "file" ? 0 : 1) @@ -496,8 +498,7 @@ void ESolver_KS_LCAO_TDDFT::after_scf(UnitCell& ucell, const int ist hamilt_lcao, this->RA, this->td_p, - this->exx_nao - ); + this->exx_nao); ModuleBase::timer::tick(this->classname, "after_scf"); }