Skip to content

Commit eef959d

Browse files
authored
Optimize: Compilation time of vdwd3_autoset_xcparam.cpp (#6042)
The compilation time of the vdwd3_autoset_xcparam.cpp file is reduced from 250 seconds to just 5 seconds in my machine. Thanks to the suggestion from DeepSeek: replacing dynamic initialization with a static array for constructing the std::map
1 parent 7e4d663 commit eef959d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

source/module_hamilt_general/module_vdw/vdwd3_autoset_xcparam.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
#include "module_hamilt_general/module_vdw/vdwd3_parameters.h"
7070

7171
// DFT-D3(BJ)
72-
const std::map<std::string, std::vector<double>> bj = {
72+
const std::pair<const char*, std::vector<double>> bj_data[] = {
7373
{"__default__", {1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 14.0, 0.0}},
7474
{"bp", {1.0, 0.3946, 0.3946, 3.2822, 4.8516, 4.8516, 1.0, 14.0, 0.0}},
7575
{"blyp", {1.0, 0.4298, 0.4298, 2.6996, 4.2359, 4.2359, 1.0, 14.0, 0.0}},
@@ -230,8 +230,10 @@ const std::map<std::string, std::vector<double>> bj = {
230230
{"dodhsep86", {0.69, 0.0, 0.0, 0.0, 5.4, 5.4, 1.0, 14.0, 0.0}},
231231
{"dodpbehb95", {0.67, 0.0, 0.0, 0.0, 6.0, 6.0, 1.0, 14.0, 0.0}},
232232
};
233+
const std::map<std::string, std::vector<double>> bj = {std::begin(bj_data), std::end(bj_data)};
234+
233235
// DFT-D3(0)
234-
const std::map<std::string, std::vector<double>> zero = {
236+
const std::pair<const char*, std::vector<double>> zero_data[] = {
235237
{"__default__", {1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 14.0, 0.0}},
236238
{"slaterdirac", {1.0, 0.999, 0.999, -1.957, 0.697, 0.697, 1.0, 14.0, 0.0}},
237239
{"bp", {1.0, 1.139, 1.139, 1.683, 1.0, 1.0, 1.0, 14.0, 0.0}},
@@ -318,8 +320,10 @@ const std::map<std::string, std::vector<double>> zero = {
318320
{"mn15l", {1.0, 3.3388, 3.3388, 0.0, 1.0, 1.0, 1.0, 14.0, 0.0}},
319321
{"pwp", {1.0, 2.104, 2.104, 0.8747, 1.0, 1.0, 1.0, 14.0, 0.0}},
320322
};
323+
const std::map<std::string, std::vector<double>> zero = {std::begin(zero_data), std::end(zero_data)};
324+
321325
// DFT-D3M(BJ): not implemented for beta
322-
const std::map<std::string, std::vector<double>> bjm = {
326+
const std::pair<const char*, std::vector<double>> bjm_data[] = {
323327
{"__default__", {1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 14.0, 0.0}},
324328
{"bp", {1.0, 0.82185, 0.82185, 3.140281, 2.728151, 2.728151, 1.0, 14.0, 0.0}},
325329
{"blyp", {1.0, 0.448486, 0.448486, 1.875007, 3.610679, 3.610679, 1.0, 14.0, 0.0}},
@@ -330,8 +334,10 @@ const std::map<std::string, std::vector<double>> bjm = {
330334
{"b2plyp", {0.64, 0.486434, 0.486434, 0.67282, 3.656466, 3.656466, 1.0, 14.0, 0.0}},
331335
{"lcwpbe", {1.0, 0.563761, 0.563761, 0.906564, 3.59368, 3.59368, 1.0, 14.0, 0.0}},
332336
};
337+
const std::map<std::string, std::vector<double>> bjm = {std::begin(bjm_data), std::end(bjm_data)};
338+
333339
// DFT-D3M(0): not implemented for beta
334-
const std::map<std::string, std::vector<double>> zerom = {
340+
const std::pair<const char*, std::vector<double>> zerom_data[] = {
335341
{"__default__", {1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 14.0, 0.0}},
336342
{"bp", {1.0, 1.23346, 1.23346, 1.945174, 1.0, 1.0, 1.0, 14.0, 0.0}},
337343
{"blyp", {1.0, 1.279637, 1.279637, 1.841686, 1.0, 1.0, 1.0, 14.0, 0.01437}},
@@ -342,8 +348,10 @@ const std::map<std::string, std::vector<double>> zerom = {
342348
{"b2plyp", {0.64, 1.313134, 1.313134, 0.717543, 1.0, 1.0, 1.0, 14.0, 0.016035}},
343349
{"lcwpbe", {1.0, 1.366361, 1.366361, 1.280619, 1.0, 1.0, 1.0, 14.0, 0.00316}},
344350
};
351+
const std::map<std::string, std::vector<double>> zerom = {std::begin(zerom_data), std::end(zerom_data)};
352+
345353
// DFT-D3(OptimizedPower)
346-
const std::map<std::string, std::vector<double>> op = {
354+
const std::pair<const char*, std::vector<double>> op_data[] = {
347355
// {'s6', 'rs6', 'a1', 's8', 'rs8', 'a2', 's9', 'alp', 'bet'}
348356
{"__default__", {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 14.0, 0.0}},
349357
{"blyp", {1.0, 0.425, 0.425, 1.31867, 3.5, 3.5, 1.0, 14.0, 2.0}},
@@ -361,6 +369,7 @@ const std::map<std::string, std::vector<double>> op = {
361369
{"ms2", {1.0, 0.7, 0.7, 0.90743, 4.0, 4.0, 1.0, 14.0, 2.0}},
362370
{"ms2h", {1.0, 0.65, 0.65, 1.69464, 4.75, 4.75, 1.0, 14.0, 0.0}},
363371
};
372+
const std::map<std::string, std::vector<double>> op = {std::begin(op_data), std::end(op_data)};
364373

365374
std::vector<double> _search_impl(const std::string& xc,
366375
const std::map<std::string, std::vector<double>>& dict)

0 commit comments

Comments
 (0)