@@ -18,6 +18,9 @@ double H_TDDFT_pw::amp;
1818double H_TDDFT_pw::bmod;
1919double H_TDDFT_pw::bvec[3 ];
2020
21+ // Used for calculating electric field force on ions
22+ vector<double > H_TDDFT_pw::global_vext_time = {0.0 , 0.0 , 0.0 };
23+
2124int H_TDDFT_pw::stype; // 0 : length gauge 1: velocity gauge
2225
2326std::vector<int > H_TDDFT_pw::ttype;
@@ -121,11 +124,29 @@ void H_TDDFT_pw::cal_fixed_v(double* vl_pseudo)
121124 trigo_count = 0 ;
122125 heavi_count = 0 ;
123126
127+ global_vext_time = {0.0 , 0.0 , 0.0 };
128+
129+ if (PARAM.inp .td_vext_dire .size () != 1 )
130+ {
131+ ModuleBase::WARNING (" H_TDDFT_pw::cal_fixed_v" ,
132+ " Multiple electric fields detected. This feature may have potential issues and is not "
133+ " recommended for use!" );
134+ }
135+ if (PARAM.inp .td_vext_dire .size () > 2 )
136+ {
137+ // To avoid breaking the integration test 601_NO_TDDFT_H2_len_hhg, a maximum of 2 electric fields are allowed
138+ ModuleBase::WARNING_QUIT (" H_TDDFT_pw::cal_fixed_v" ,
139+ " For the sake of program stability, the feature of applying multiple electric fields "
140+ " simultaneously has been temporarily disabled. Thank you for your understanding!" );
141+ }
142+
124143 for (auto direc: PARAM.inp .td_vext_dire )
125144 {
126145 std::vector<double > vext_space (this ->rho_basis_ ->nrxx , 0.0 );
127146 double vext_time = cal_v_time (ttype[count], true );
128147
148+ global_vext_time[direc - 1 ] += vext_time;
149+
129150 if (PARAM.inp .out_efield && GlobalV::MY_RANK == 0 )
130151 {
131152 std::stringstream as;
@@ -479,7 +500,7 @@ void H_TDDFT_pw::prepare(const ModuleBase::Matrix3& G, int& dir)
479500 bmod = sqrt (pow (bvec[0 ], 2 ) + pow (bvec[1 ], 2 ) + pow (bvec[2 ], 2 ));
480501}
481502
482- void H_TDDFT_pw ::compute_force (const UnitCell& cell, ModuleBase::matrix& fe)
503+ void H_TDDFT_pw::compute_force (const UnitCell& cell, ModuleBase::matrix& fe)
483504{
484505 int iat = 0 ;
485506 for (int it = 0 ; it < cell.ntype ; ++it)
@@ -488,7 +509,9 @@ void H_TDDFT_pw ::compute_force(const UnitCell& cell, ModuleBase::matrix& fe)
488509 {
489510 for (int jj = 0 ; jj < 3 ; ++jj)
490511 {
491- fe (iat, jj) = ModuleBase::e2 * amp * cell.atoms [it].ncpp .zv * bvec[jj] / bmod;
512+ // No need to multiply ModuleBase::e2, since the unit of force is Ry/Bohr
513+ fe (iat, jj)
514+ = (std::abs (bmod) > 1e-10 ? global_vext_time[jj] * cell.atoms [it].ncpp .zv * bvec[jj] / bmod : 0 );
492515 }
493516 ++iat;
494517 }
0 commit comments