@@ -18,6 +18,9 @@ double H_TDDFT_pw::amp;
18
18
double H_TDDFT_pw::bmod;
19
19
double H_TDDFT_pw::bvec[3 ];
20
20
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
+
21
24
int H_TDDFT_pw::stype; // 0 : length gauge 1: velocity gauge
22
25
23
26
std::vector<int > H_TDDFT_pw::ttype;
@@ -121,11 +124,29 @@ void H_TDDFT_pw::cal_fixed_v(double* vl_pseudo)
121
124
trigo_count = 0 ;
122
125
heavi_count = 0 ;
123
126
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
+
124
143
for (auto direc: PARAM.inp .td_vext_dire )
125
144
{
126
145
std::vector<double > vext_space (this ->rho_basis_ ->nrxx , 0.0 );
127
146
double vext_time = cal_v_time (ttype[count], true );
128
147
148
+ global_vext_time[direc - 1 ] += vext_time;
149
+
129
150
if (PARAM.inp .out_efield && GlobalV::MY_RANK == 0 )
130
151
{
131
152
std::stringstream as;
@@ -479,7 +500,7 @@ void H_TDDFT_pw::prepare(const ModuleBase::Matrix3& G, int& dir)
479
500
bmod = sqrt (pow (bvec[0 ], 2 ) + pow (bvec[1 ], 2 ) + pow (bvec[2 ], 2 ));
480
501
}
481
502
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)
483
504
{
484
505
int iat = 0 ;
485
506
for (int it = 0 ; it < cell.ntype ; ++it)
@@ -488,7 +509,9 @@ void H_TDDFT_pw ::compute_force(const UnitCell& cell, ModuleBase::matrix& fe)
488
509
{
489
510
for (int jj = 0 ; jj < 3 ; ++jj)
490
511
{
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 );
492
515
}
493
516
++iat;
494
517
}
0 commit comments