@@ -27,6 +27,7 @@ heat transport, Phys. Rev. B. 104, 104309 (2021).
2727#include " utilities/error.cuh"
2828#include " utilities/gpu_macro.cuh"
2929#include " utilities/nep_utilities.cuh"
30+ #include < chrono>
3031#include < cmath>
3132#include < cstring>
3233#include < fstream>
@@ -74,6 +75,12 @@ void NEP_Charge::initialize_dftd3()
7475
7576NEP_Charge::NEP_Charge (const char * file_potential, const int num_atoms)
7677{
78+ #ifdef DEBUG
79+ rng = std::mt19937 (12345678 );
80+ #else
81+ rng = std::mt19937 (std::chrono::system_clock::now ().time_since_epoch ().count ());
82+ #endif
83+
7784 std::ifstream input (file_potential);
7885 if (!input.is_open ()) {
7986 std::cout << " Failed to open " << file_potential << std::endl;
@@ -1259,6 +1266,40 @@ void NEP_Charge::find_k_and_G(const double* box)
12591266 std::vector<float > cpu_kz;
12601267 std::vector<float > cpu_G;
12611268
1269+ #ifdef USE_RBE
1270+ std::uniform_real_distribution<float > rand_number (0 .0f , 1 .0f );
1271+ float normalization_factor = 0 .0f ;
1272+ for (int n1 = 0 ; n1 <= n1_max; ++n1) {
1273+ for (int n2 = - n2_max; n2 <= n2_max; ++n2) {
1274+ for (int n3 = - n3_max; n3 <= n3_max; ++n3) {
1275+ const int nsq = n1 * n1 + n2 * n2 + n3 * n3;
1276+ if (nsq == 0 || (n1 == 0 && n2 < 0 ) || (n1 == 0 && n2 == 0 && n3 < 0 )) continue ;
1277+ const float kx = n1 * b1[0 ] + n2 * b2[0 ] + n3 * b3[0 ];
1278+ const float ky = n1 * b1[1 ] + n2 * b2[1 ] + n3 * b3[1 ];
1279+ const float kz = n1 * b1[2 ] + n2 * b2[2 ] + n3 * b3[2 ];
1280+ const float ksq = kx * kx + ky * ky + kz * kz;
1281+ if (ksq < ksq_max) {
1282+ float exp_factor = exp (-ksq * charge_para.alpha_factor );
1283+ normalization_factor += exp_factor;
1284+ if (rand_number (rng) < exp_factor) {
1285+ cpu_kx.emplace_back (kx);
1286+ cpu_ky.emplace_back (ky);
1287+ cpu_kz.emplace_back (kz);
1288+ float G = abs (two_pi_over_det) / ksq;
1289+ cpu_G.emplace_back (2 .0f * G);
1290+ }
1291+ }
1292+ }
1293+ }
1294+ }
1295+
1296+ int num_kpoints = int (cpu_kx.size ());
1297+ for (int n = 0 ; n < num_kpoints; ++n) {
1298+ cpu_G[n] *= normalization_factor / num_kpoints;
1299+ }
1300+
1301+ #else
1302+
12621303 for (int n1 = 0 ; n1 <= n1_max; ++n1) {
12631304 for (int n2 = - n2_max; n2 <= n2_max; ++n2) {
12641305 for (int n3 = - n3_max; n3 <= n3_max; ++n3) {
@@ -1280,6 +1321,8 @@ void NEP_Charge::find_k_and_G(const double* box)
12801321 }
12811322
12821323 int num_kpoints = int (cpu_kx.size ());
1324+ #endif
1325+
12831326 if (num_kpoints > charge_para.num_kpoints_max ) {
12841327 charge_para.num_kpoints_max = num_kpoints;
12851328 nep_data.kx .resize (charge_para.num_kpoints_max );
0 commit comments