Skip to content

Commit 53792cb

Browse files
Format
1 parent 4fd697c commit 53792cb

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

source/module_hamilt_pw/hamilt_pwdft/operator_pw/op_exx_pw.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,19 @@ void OperatorEXXPW<T, Device>::get_potential() const
610610
{
611611
const ModuleBase::Vector3<double> g_d = rhopw->gdirect[ig];
612612
const ModuleBase::Vector3<double> kqg_d = k_d - q_d + g_d;
613+
// For gamma_extrapolation (https://doi.org/10.1103/PhysRevB.79.205114)
614+
// 7/8 of the points in the grid are "activated" and 1/8 are disabled.
615+
// grid_factor is designed for the 7/8 of the grid to function like all of the points
613616
Real grid_factor = 1;
617+
double extrapolate_grid = 8.0/7.0;
614618
if (gamma_extrapolation)
615619
{
616620
// if isint(kqg_d[0] * nqs_half1) && isint(kqg_d[1] * nqs_half2) && isint(kqg_d[2] * nqs_half3)
617-
auto isint = [](double x) { return std::abs(x - std::round(x)) < 1e-6; };
621+
auto isint = [](double x)
622+
{
623+
double epsilon = 1e-6; // this follows the isint judgement in q-e
624+
return std::abs(x - std::round(x)) < epsilon;
625+
};
618626
if (isint(kqg_d[0] * nqs_half1) &&
619627
isint(kqg_d[1] * nqs_half2) &&
620628
isint(kqg_d[2] * nqs_half3))
@@ -623,7 +631,7 @@ void OperatorEXXPW<T, Device>::get_potential() const
623631
}
624632
else
625633
{
626-
grid_factor = 8.0/7.0;
634+
grid_factor = extrapolate_grid;
627635
}
628636
}
629637

@@ -700,10 +708,18 @@ void OperatorEXXPW<T, Device>::exx_divergence()
700708
const ModuleBase::Vector3<double> q_c = k_c + rhopw->gcar[ig];
701709
const ModuleBase::Vector3<double> q_d = k_d + rhopw->gdirect[ig];
702710
double qq = q_c.norm2();
711+
// For gamma_extrapolation (https://doi.org/10.1103/PhysRevB.79.205114)
712+
// 7/8 of the points in the grid are "activated" and 1/8 are disabled.
713+
// grid_factor is designed for the 7/8 of the grid to function like all of the points
703714
Real grid_factor = 1;
715+
double extrapolate_grid = 8.0/7.0;
704716
if (gamma_extrapolation)
705717
{
706-
auto isint = [](double x) { return std::abs(x - std::round(x)) < 1e-6; };
718+
auto isint = [](double x)
719+
{
720+
double epsilon = 1e-6; // this follows the isint judgement in q-e
721+
return std::abs(x - std::round(x)) < epsilon;
722+
};
707723
if (isint(q_d[0] * nqs_half1) &&
708724
isint(q_d[1] * nqs_half2) &&
709725
isint(q_d[2] * nqs_half3))
@@ -712,7 +728,7 @@ void OperatorEXXPW<T, Device>::exx_divergence()
712728
}
713729
else
714730
{
715-
grid_factor = 8.0/7.0;
731+
grid_factor = extrapolate_grid;
716732
}
717733
}
718734

source/module_hamilt_pw/hamilt_pwdft/stress_func_exx.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)