|
4 | 4 | */ |
5 | 5 | #include "klist.h" |
6 | 6 |
|
| 7 | +#include "klist_io.h" |
7 | 8 | #include "source_base/formatter.h" |
8 | 9 | #include "source_base/parallel_common.h" |
9 | 10 | #include "source_base/parallel_global.h" |
10 | 11 | #include "source_base/parallel_reduce.h" |
11 | 12 | #include "source_cell/module_symmetry/symmetry.h" |
12 | 13 |
|
13 | | -// Free formatting helpers for the IBZ reduction tables. Defined in this |
14 | | -// file (not in a separate TU) because many test targets across the tree |
15 | | -// compile klist.cpp alone; a separate TU would need registering everywhere. |
16 | | -// Deliberately not static and not in an anonymous namespace. |
17 | | -namespace KListSymm |
18 | | -{ |
19 | | - |
20 | | -std::string ibz_kpt_table(const int nkstot, |
21 | | - const std::vector<ModuleBase::Vector3<double>>& kvec_d, |
22 | | - const std::vector<int>& ibz_index, |
23 | | - const std::vector<ModuleBase::Vector3<double>>& kvec_d_ibz) |
24 | | -{ |
25 | | - std::stringstream ss; |
26 | | - ss << " " << std::setw(40) << "nkstot" |
27 | | - << " = " << nkstot << std::setw(66) << "ibzkpt" << std::endl; |
28 | | - std::string table; |
29 | | - table += "K-POINTS REDUCTION ACCORDING TO SYMMETRY\n"; |
30 | | - table += FmtCore::format("%8s%12s%12s%12s%8s%12s%12s%12s\n", |
31 | | - "KPT", |
32 | | - "DIRECT_X", |
33 | | - "DIRECT_Y", |
34 | | - "DIRECT_Z", |
35 | | - "IBZ", |
36 | | - "DIRECT_X", |
37 | | - "DIRECT_Y", |
38 | | - "DIRECT_Z"); |
39 | | - for (int i = 0; i < nkstot; ++i) |
40 | | - { |
41 | | - table += FmtCore::format("%8d%12.8f%12.8f%12.8f%8d%12.8f%12.8f%12.8f\n", |
42 | | - i + 1, |
43 | | - kvec_d[i].x, |
44 | | - kvec_d[i].y, |
45 | | - kvec_d[i].z, |
46 | | - ibz_index[i] + 1, |
47 | | - kvec_d_ibz[ibz_index[i]].x, |
48 | | - kvec_d_ibz[ibz_index[i]].y, |
49 | | - kvec_d_ibz[ibz_index[i]].z); |
50 | | - } |
51 | | - ss << table << std::endl; |
52 | | - return ss.str(); |
53 | | -} |
54 | | - |
55 | | -std::string ibz_wk_table(const int nkstot_ibz, |
56 | | - const std::vector<ModuleBase::Vector3<double>>& kvec_d_ibz, |
57 | | - const std::vector<double>& wk_ibz, |
58 | | - const std::vector<int>& ibz2bz) |
59 | | -{ |
60 | | - std::string table; |
61 | | - table += "\n K-POINTS REDUCTION ACCORDING TO SYMMETRY\n"; |
62 | | - table += FmtCore::format("%8s%12s%12s%12s%8s%8s\n", "IBZ", "DIRECT_X", "DIRECT_Y", "DIRECT_Z", "WEIGHT", "ibz2bz"); |
63 | | - for (int ik = 0; ik < nkstot_ibz; ik++) |
64 | | - { |
65 | | - table += FmtCore::format("%8d%12.8f%12.8f%12.8f%8.4f%8d\n", |
66 | | - ik + 1, |
67 | | - kvec_d_ibz[ik].x, |
68 | | - kvec_d_ibz[ik].y, |
69 | | - kvec_d_ibz[ik].z, |
70 | | - wk_ibz[ik], |
71 | | - ibz2bz[ik]); |
72 | | - } |
73 | | - return table; |
74 | | -} |
75 | | - |
76 | | -} // namespace KListSymm |
77 | | - |
78 | 14 | void K_Vectors::cal_ik_global() |
79 | 15 | { |
80 | 16 | const int my_pool = this->para_k.my_pool; |
@@ -509,75 +445,18 @@ bool K_Vectors::parse_kfile(const std::string& fn, std::ofstream& ofs_running) |
509 | 445 |
|
510 | 446 | void K_Vectors::interpolate_k_between(std::ifstream& ifk, std::vector<ModuleBase::Vector3<double>>& kvec) |
511 | 447 | { |
512 | | - // how many special points. |
513 | | - int nks_special = this->nkstot; |
514 | | - |
515 | | - // number of points to the next k points |
516 | | - std::vector<int> nkl(nks_special, 0); |
517 | | - |
518 | | - // coordinates of special points. |
519 | | - std::vector<ModuleBase::Vector3<double>> ks(nks_special); |
520 | | - |
521 | | - // recalculate nkstot. |
522 | | - nkstot = 0; |
523 | | - /* ISSUE#3482: to distinguish different kline segments */ |
524 | | - std::vector<int> kpt_segids; |
525 | | - kl_segids.clear(); |
526 | | - kl_segids.shrink_to_fit(); |
527 | | - int kpt_segid = 0; |
528 | | - for (int iks = 0; iks < nks_special; iks++) |
529 | | - { |
530 | | - ifk >> ks[iks].x; |
531 | | - ifk >> ks[iks].y; |
532 | | - ifk >> ks[iks].z; |
533 | | - ModuleBase::GlobalFunc::READ_VALUE(ifk, nkl[iks]); |
534 | | - |
535 | | - if (nkl[iks] <= 0) |
536 | | - { |
537 | | - ModuleBase::WARNING_QUIT("K_Vectors::interpolate_k_between", |
538 | | - "Line-mode interpolation counts must be positive."); |
539 | | - } |
540 | | - nkstot += nkl[iks]; |
541 | | - /* ISSUE#3482: to distinguish different kline segments */ |
542 | | - if ((nkl[iks] == 1) && (iks != (nks_special - 1))) { |
543 | | - kpt_segid++; |
544 | | - } |
545 | | - kpt_segids.push_back(kpt_segid); |
546 | | - } |
547 | | - if (nkl[nks_special - 1] != 1) |
548 | | - { |
549 | | - ModuleBase::WARNING_QUIT("K_Vectors::interpolate_k_between", |
550 | | - "The final line-mode k-point must have an interpolation count of 1."); |
551 | | - } |
| 448 | + // Thin wrapper: the interpolation itself is the this-free KListIO::interp_line; |
| 449 | + // here we only size the member containers and copy the results back. |
| 450 | + const KListIO::LineK line = KListIO::interp_line(ifk, this->nkstot); |
552 | 451 |
|
553 | | - // std::cout << " nkstot = " << nkstot << std::endl; |
554 | | - this->renew(nkstot * this->spin_mult); // mohan fix bug 2009-09-01 |
| 452 | + this->nkstot = line.nks_total; |
| 453 | + this->renew(this->nkstot * this->spin_mult); // mohan fix bug 2009-09-01 |
555 | 454 |
|
556 | | - int count = 0; |
557 | | - for (int iks = 1; iks < nks_special; iks++) |
| 455 | + for (int i = 0; i < this->nkstot; i++) |
558 | 456 | { |
559 | | - double dxs = (ks[iks].x - ks[iks - 1].x) / nkl[iks - 1]; |
560 | | - double dys = (ks[iks].y - ks[iks - 1].y) / nkl[iks - 1]; |
561 | | - double dzs = (ks[iks].z - ks[iks - 1].z) / nkl[iks - 1]; |
562 | | - for (int is = 0; is < nkl[iks - 1]; is++) |
563 | | - { |
564 | | - kvec[count].x = ks[iks - 1].x + is * dxs; |
565 | | - kvec[count].y = ks[iks - 1].y + is * dys; |
566 | | - kvec[count].z = ks[iks - 1].z + is * dzs; |
567 | | - kl_segids.push_back(kpt_segids[iks - 1]); /* ISSUE#3482: to distinguish different kline segments */ |
568 | | - ++count; |
569 | | - } |
| 457 | + kvec[i] = line.kpts[i]; |
570 | 458 | } |
571 | | - |
572 | | - // deal with the last special k point. |
573 | | - kvec[count].x = ks[nks_special - 1].x; |
574 | | - kvec[count].y = ks[nks_special - 1].y; |
575 | | - kvec[count].z = ks[nks_special - 1].z; |
576 | | - kl_segids.push_back(kpt_segids[nks_special - 1]); /* ISSUE#3482: to distinguish different kline segments */ |
577 | | - ++count; |
578 | | - |
579 | | - assert(count == nkstot); |
580 | | - assert(kl_segids.size() == nkstot); /* ISSUE#3482: to distinguish different kline segments */ |
| 459 | + this->kl_segids = line.segids; /* ISSUE#3482: to distinguish different kline segments */ |
581 | 460 | } |
582 | 461 |
|
583 | 462 | void K_Vectors::update_use_ibz(const int& nkstot_ibz, |
@@ -776,10 +655,10 @@ void K_Vectors::reduce_by_symmetry(const UnitCell& ucell, |
776 | 655 | #endif |
777 | 656 |
|
778 | 657 | // output in kpoints file |
779 | | - skpt = KListSymm::ibz_kpt_table(this->nkstot, this->kvec_d, this->ibz_index, kvec_d_ibz); |
| 658 | + skpt = KListIO::ibz_kpt_table(this->nkstot, this->kvec_d, this->ibz_index, kvec_d_ibz); |
780 | 659 | ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Number of irreducible k-points", nkstot_ibz); |
781 | 660 |
|
782 | | - GlobalV::ofs_running << KListSymm::ibz_wk_table(nkstot_ibz, kvec_d_ibz, wk_ibz, ibz2bz) << std::endl; |
| 661 | + GlobalV::ofs_running << KListIO::ibz_wk_table(nkstot_ibz, kvec_d_ibz, wk_ibz, ibz2bz) << std::endl; |
783 | 662 |
|
784 | 663 | // resize the kpoint container according to nkstot_ibz |
785 | 664 | if (use_symm || this->get_is_mp()) |
|
0 commit comments