@@ -17,7 +17,11 @@ void Stress_PW<FPTYPE, Device>::stress_exx(ModuleBase::matrix& sigma,
1717 {
1818 gamma_extrapolation = false ;
1919 }
20- auto isint = [](double x) { return std::abs (x - std::round (x)) < 1e-6 ; };
20+ auto isint = [](double x)
21+ {
22+ double epsilon = 1e-6 ; // this follows the isint judgement in q-e
23+ return std::abs (x - std::round (x)) < epsilon;
24+ };
2125
2226 // T is complex of FPTYPE, if FPTYPE is double, T is std::complex<double>
2327 // but if FPTYPE is std::complex<double>, T is still std::complex<double>
@@ -80,7 +84,11 @@ void Stress_PW<FPTYPE, Device>::stress_exx(ModuleBase::matrix& sigma,
8084 const ModuleBase::Vector3<double > q_c = k_c + rhopw->gcar [ig];
8185 const ModuleBase::Vector3<double > q_d = k_d + rhopw->gdirect [ig];
8286 double qq = q_c.norm2 ();
87+ // For gamma_extrapolation (https://doi.org/10.1103/PhysRevB.79.205114)
88+ // 7/8 of the points in the grid are "activated" and 1/8 are disabled.
89+ // grid_factor is designed for the 7/8 of the grid to function like all of the points
8390 double grid_factor = 1 ;
91+ double extrapolate_grid = 8.0 /7.0 ;
8492 if (gamma_extrapolation)
8593 {
8694 if (isint (q_d[0 ] * nqs_half1) &&
@@ -91,10 +99,11 @@ void Stress_PW<FPTYPE, Device>::stress_exx(ModuleBase::matrix& sigma,
9199 }
92100 else
93101 {
94- grid_factor = 8.0 / 7.0 ;
102+ grid_factor = extrapolate_grid ;
95103 }
96104 }
97105
106+
98107 if (qq <= 1e-8 ) continue ;
99108 else if (GlobalC::exx_info.info_global .ccp_type == Conv_Coulomb_Pot_K::Ccp_Type::Erfc)
100109 {
@@ -174,9 +183,14 @@ void Stress_PW<FPTYPE, Device>::stress_exx(ModuleBase::matrix& sigma,
174183 {
175184 const ModuleBase::Vector3<double > g_d = rhopw->gdirect [ig];
176185 const ModuleBase::Vector3<double > kqg_d = k_d - q_d + g_d;
186+
187+ // For gamma_extrapolation (https://doi.org/10.1103/PhysRevB.79.205114)
188+ // 7/8 of the points in the grid are "activated" and 1/8 are disabled.
189+ // grid_factor is designed for the 7/8 of the grid to function like all of the points
177190 Real grid_factor = 1 ;
178191 if (gamma_extrapolation)
179192 {
193+ double extrapolate_grid = 8.0 /7.0 ;
180194 if (isint (kqg_d[0 ] * nqs_half1) &&
181195 isint (kqg_d[1 ] * nqs_half2) &&
182196 isint (kqg_d[2 ] * nqs_half3))
@@ -185,7 +199,7 @@ void Stress_PW<FPTYPE, Device>::stress_exx(ModuleBase::matrix& sigma,
185199 }
186200 else
187201 {
188- grid_factor = 8.0 / 7.0 ;
202+ grid_factor = extrapolate_grid ;
189203 }
190204 }
191205
@@ -289,13 +303,7 @@ void Stress_PW<FPTYPE, Device>::stress_exx(ModuleBase::matrix& sigma,
289303 const int idx = ig + iq * rhopw->npw + ik * rhopw->npw * nqs;
290304 double pot_local = pot[idx];
291305 double pot_stress_local = pot_stress[idx];
292- // if (GlobalC::exx_info.info_global.ccp_type == Conv_Coulomb_Pot_K::Ccp_Type::Hf)
293- // {
294- sigma_ab_loc += density_recip2 * pot_local * (kqg_alpha * kqg_beta * pot_stress_local - delta_ab) ;
295- // }
296-
297- // double grid_factor = gamma_extrapolation ? 8.0/7.0 : 1.0;
298- // sigma_ab_loc += density_recip2 * pot_local * (kqg_alpha * kqg_beta * (-pot_local) / grid_factor / _4pi_e2 - delta_ab) ;
306+ sigma_ab_loc += density_recip2 * pot_local * (kqg_alpha * kqg_beta * pot_stress_local - delta_ab) ;
299307
300308 }
301309
@@ -320,17 +328,6 @@ void Stress_PW<FPTYPE, Device>::stress_exx(ModuleBase::matrix& sigma,
320328
321329 Parallel_Reduce::reduce_all (sigma.c , sigma.nr * sigma.nc );
322330
323- // // print sigma
324- // for (int i = 0; i < 3; i++)
325- // {
326- // for (int j = 0; j < 3; j++)
327- // {
328- // std::cout << sigma(i, j) * ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8 << " ";
329- // sigma(i, j) = 0;
330- // }
331- // std::cout << std::endl;
332- // }
333-
334331
335332 delmem_complex_op ()(psi_nk_real);
336333 delmem_complex_op ()(psi_mq_real);
0 commit comments