Skip to content

Commit 8929b2d

Browse files
authored
Fix RT-TDDFT segfault when initial SCF fails to converge (#6954)
1 parent cccea3e commit 8929b2d

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

source/source_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "esolver_ks_lcao_tddft.h"
22

33
//----------------IO-----------------
4-
#include "source_io/module_ctrl/ctrl_output_td.h"
54
#include "source_io/dipole_io.h"
5+
#include "source_io/module_ctrl/ctrl_output_td.h"
6+
#include "source_io/module_current/td_current_io.h"
67
#include "source_io/module_output/output_log.h"
78
#include "source_io/module_wf/read_wfc_nao.h"
8-
#include "source_io/module_current/td_current_io.h"
99
//------LCAO HSolver ElecState-------
1010
#include "source_estate/elecstate_tools.h"
1111
#include "source_estate/module_charge/symmetry_rho.h"
@@ -203,7 +203,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::runner(UnitCell& ucell, const int istep)
203203
}
204204
}
205205

206-
if(PARAM.inp.td_stype != 1 && TD_info::out_current == 1)
206+
if (PARAM.inp.td_stype != 1 && TD_info::out_current == 1)
207207
{
208208
delete velocity_mat;
209209
}
@@ -336,7 +336,9 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::iter_finish(UnitCell& ucell,
336336
ESolver_KS_LCAO<std::complex<double>, TR>::iter_finish(ucell, istep, iter, conv_esolver);
337337

338338
// Store wave function, Hamiltonian and Overlap matrix, to be used in next time step
339-
this->store_h_s_psi(ucell, istep, iter, conv_esolver);
339+
// Store when converged or reach max iteration
340+
bool force_save = conv_esolver || (iter == this->maxniter);
341+
this->store_h_s_psi(ucell, istep, iter, force_save);
340342

341343
// Calculate energy-density matrix for RT-TDDFT
342344
if (conv_esolver && estep == estep_max - 1 && istep >= (PARAM.inp.init_wfc == "file" ? 0 : 1)
@@ -496,8 +498,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::after_scf(UnitCell& ucell, const int ist
496498
hamilt_lcao,
497499
this->RA,
498500
this->td_p,
499-
this->exx_nao
500-
);
501+
this->exx_nao);
501502

502503
ModuleBase::timer::tick(this->classname, "after_scf");
503504
}

0 commit comments

Comments
 (0)