@@ -54,6 +54,12 @@ ESolver_KS_LCAO_TDDFT<TR, Device>::~ESolver_KS_LCAO_TDDFT()
5454 delete td_p;
5555 }
5656 TD_info::td_vel_op = nullptr ;
57+
58+ if (td_mg_ != nullptr )
59+ {
60+ delete td_mg_;
61+ td_mg_ = nullptr ;
62+ }
5763}
5864
5965template <typename TR, typename Device>
@@ -94,6 +100,16 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::runner(UnitCell& ucell, const int istep)
94100 // 1) before_scf (electronic iteration loops)
95101 // ----------------------------------------------------------------
96102 this ->before_scf (ucell, istep); // From ESolver_KS_LCAO
103+
104+ // Initialize the moving spatial gauge
105+ if (use_td_moving_gauge && this ->td_mg_ == nullptr )
106+ {
107+ this ->td_mg_ = new module_rt::TD_MovingGauge ();
108+ auto * hamilt_lcao = dynamic_cast <hamilt::HamiltLCAO<std::complex <double >, TR>*>(this ->p_hamilt );
109+ const hamilt::HContainer<TR>* sR_template = hamilt_lcao->getSR ();
110+ this ->td_mg_ ->init_DR (sR_template , &ucell, &this ->pv , this ->two_center_bundle_ .overlap_orb .get ());
111+ }
112+
97113 if (PARAM.inp .td_stype == 2 )
98114 {
99115 this ->dmat .dm ->cal_DMR_td (ucell, TD_info::cart_At);
@@ -242,6 +258,14 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::hamilt2rho_single(UnitCell& ucell,
242258 const int iter,
243259 const double ethr)
244260{
261+ // Update the moving spatial gauge
262+ if (use_td_moving_gauge)
263+ {
264+ auto * hamilt_lcao = dynamic_cast <hamilt::HamiltLCAO<std::complex <double >, TR>*>(this ->p_hamilt );
265+ const hamilt::HContainer<TR>* sR_template = hamilt_lcao->getSR ();
266+ this ->td_mg_ ->update_DR (sR_template , &ucell, &this ->pv , this ->two_center_bundle_ .overlap_orb .get ());
267+ }
268+
245269 if (PARAM.inp .init_wfc == " file" )
246270 {
247271 if (istep >= TD_info::estep_shift + 1 )
@@ -261,7 +285,11 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::hamilt2rho_single(UnitCell& ucell,
261285 GlobalV::ofs_running,
262286 PARAM.inp .propagator ,
263287 use_tensor,
264- use_lapack);
288+ use_lapack,
289+ this ->td_mg_ ,
290+ &ucell,
291+ this ->kv .kvec_d ,
292+ use_td_moving_gauge);
265293 }
266294 this ->weight_dm_rho (ucell);
267295 }
@@ -281,7 +309,11 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::hamilt2rho_single(UnitCell& ucell,
281309 GlobalV::ofs_running,
282310 PARAM.inp .propagator ,
283311 use_tensor,
284- use_lapack);
312+ use_lapack,
313+ this ->td_mg_ ,
314+ &ucell,
315+ this ->kv .kvec_d ,
316+ use_td_moving_gauge);
285317 this ->weight_dm_rho (ucell);
286318 }
287319 else
0 commit comments