Skip to content

Commit 0317267

Browse files
committed
Only calculate EDM in RT-TDDFT when the electronic step ends
1 parent 9671f5e commit 0317267

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

source/source_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::runner(UnitCell& ucell, const int istep)
157157
this->hamilt2rho(ucell, totstep, iter, this->diag_ethr); // From ESolver_KS
158158

159159
// 5) Finish SCF iterations
160-
this->iter_finish(ucell, totstep, iter, conv_esolver);
160+
this->iter_finish(ucell, totstep, estep, estep_max, iter, conv_esolver);
161161

162162
// 6) Check convergence
163163
if (conv_esolver || this->oscillate_esolver)
@@ -283,7 +283,12 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::hamilt2rho_single(UnitCell& ucell,
283283
}
284284

285285
template <typename TR, typename Device>
286-
void ESolver_KS_LCAO_TDDFT<TR, Device>::iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver)
286+
void ESolver_KS_LCAO_TDDFT<TR, Device>::iter_finish(UnitCell& ucell,
287+
const int istep,
288+
const int estep,
289+
const int estep_max,
290+
int& iter,
291+
bool& conv_esolver)
287292
{
288293
// Print occupation of each band
289294
if (iter == 1 && istep <= 2)
@@ -307,6 +312,13 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::iter_finish(UnitCell& ucell, const int i
307312

308313
// Store wave function, Hamiltonian and Overlap matrix, to be used in next time step
309314
this->store_h_s_psi(ucell, istep, iter, conv_esolver);
315+
316+
// Calculate energy-density matrix for RT-TDDFT
317+
if (conv_esolver && estep == estep_max - 1 && istep >= (PARAM.inp.init_wfc == "file" ? 0 : 1)
318+
&& PARAM.inp.td_edm == 0)
319+
{
320+
elecstate::cal_edm_tddft(this->pv, this->pelec, this->kv, this->p_hamilt);
321+
}
310322
}
311323

312324
template <typename TR, typename Device>
@@ -421,12 +433,6 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::store_h_s_psi(UnitCell& ucell,
421433
1);
422434
}
423435
}
424-
425-
// Calculate energy-density matrix for RT-TDDFT
426-
if (istep >= (PARAM.inp.init_wfc == "file" ? 0 : 1) && PARAM.inp.td_edm == 0)
427-
{
428-
elecstate::cal_edm_tddft(this->pv, this->pelec, this->kv, this->p_hamilt);
429-
}
430436
}
431437
}
432438

source/source_esolver/esolver_ks_lcao_tddft.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO<std::complex<double>, TR>
2727

2828
void store_h_s_psi(UnitCell& ucell, const int istep, const int iter, const bool conv_esolver);
2929

30-
virtual void iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver) override;
30+
void iter_finish(UnitCell& ucell,
31+
const int istep,
32+
const int estep,
33+
const int estep_max,
34+
int& iter,
35+
bool& conv_esolver);
3136

3237
virtual void after_scf(UnitCell& ucell, const int istep, const bool conv_esolver) override;
3338

0 commit comments

Comments
 (0)