|
| 1 | +// |
| 2 | +// Created by rhx on 25-6-3. |
| 3 | +// |
| 4 | +#include "k_vector_utils.h" |
| 5 | + |
| 6 | +#include "klist.h" |
| 7 | +#include "module_base/global_variable.h" |
| 8 | +#include "module_base/matrix3.h" |
| 9 | + |
| 10 | +#include <module_base/formatter.h> |
| 11 | +#include <module_parameter/parameter.h> |
| 12 | + |
| 13 | +namespace KVectorUtils |
| 14 | +{ |
| 15 | +void k_vec_d2c(K_Vectors& kv, const ModuleBase::Matrix3& reciprocal_vec) |
| 16 | +{ |
| 17 | + for (int i = 0; i < kv.get_nks(); i++) |
| 18 | + { |
| 19 | + // wrong!! kvec_c[i] = G * kvec_d[i]; |
| 20 | + // mohan fixed bug 2010-1-10 |
| 21 | + if (std::abs(kv.kvec_d[i].x) < 1.0e-10) |
| 22 | + { |
| 23 | + kv.kvec_d[i].x = 0.0; |
| 24 | + } |
| 25 | + if (std::abs(kv.kvec_d[i].y) < 1.0e-10) |
| 26 | + { |
| 27 | + kv.kvec_d[i].y = 0.0; |
| 28 | + } |
| 29 | + if (std::abs(kv.kvec_d[i].z) < 1.0e-10) |
| 30 | + { |
| 31 | + kv.kvec_d[i].z = 0.0; |
| 32 | + } |
| 33 | + |
| 34 | + kv.kvec_c[i] = kv.kvec_d[i] * reciprocal_vec; |
| 35 | + |
| 36 | + // mohan add2012-06-10 |
| 37 | + if (std::abs(kv.kvec_c[i].x) < 1.0e-10) |
| 38 | + { |
| 39 | + kv.kvec_c[i].x = 0.0; |
| 40 | + } |
| 41 | + if (std::abs(kv.kvec_c[i].y) < 1.0e-10) |
| 42 | + { |
| 43 | + kv.kvec_c[i].y = 0.0; |
| 44 | + } |
| 45 | + if (std::abs(kv.kvec_c[i].z) < 1.0e-10) |
| 46 | + { |
| 47 | + kv.kvec_c[i].z = 0.0; |
| 48 | + } |
| 49 | + } |
| 50 | +} |
| 51 | +void k_vec_c2d(K_Vectors& kv, const ModuleBase::Matrix3& latvec) |
| 52 | +{ |
| 53 | + ModuleBase::Matrix3 RT = latvec.Transpose(); |
| 54 | + for (int i = 0; i < kv.get_nks(); i++) |
| 55 | + { |
| 56 | + // std::cout << " ik=" << i |
| 57 | + // << " kvec.x=" << kvec_c[i].x |
| 58 | + // << " kvec.y=" << kvec_c[i].y |
| 59 | + // << " kvec.z=" << kvec_c[i].z << std::endl; |
| 60 | + // wrong! kvec_d[i] = RT * kvec_c[i]; |
| 61 | + // mohan fixed bug 2011-03-07 |
| 62 | + kv.kvec_d[i] = kv.kvec_c[i] * RT; |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +void set_both_kvec(K_Vectors& kv, const ModuleBase::Matrix3& G, const ModuleBase::Matrix3& R, std::string& skpt) |
| 67 | +{ |
| 68 | + if (PARAM.inp.final_scf) // Todo: Any way to avoid directly using input variables? |
| 69 | + { |
| 70 | + if (kv.k_nkstot == 0) |
| 71 | + { |
| 72 | + kv.kd_done = true; |
| 73 | + kv.kc_done = false; |
| 74 | + } |
| 75 | + else |
| 76 | + { |
| 77 | + if (kv.k_kword == "Cartesian" || kv.k_kword == "C") |
| 78 | + { |
| 79 | + kv.kc_done = true; |
| 80 | + kv.kd_done = false; |
| 81 | + } |
| 82 | + else if (kv.k_kword == "Direct" || kv.k_kword == "D") |
| 83 | + { |
| 84 | + kv.kd_done = true; |
| 85 | + kv.kc_done = false; |
| 86 | + } |
| 87 | + else |
| 88 | + { |
| 89 | + GlobalV::ofs_warning << " Error : neither Cartesian nor Direct kpoint." << std::endl; |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + // set cartesian k vectors. |
| 95 | + if (!kv.kc_done && kv.kd_done) |
| 96 | + { |
| 97 | + KVectorUtils::k_vec_d2c(kv, G); |
| 98 | + kv.kc_done = true; |
| 99 | + } |
| 100 | + |
| 101 | + // set direct k vectors |
| 102 | + else if (kv.kc_done && !kv.kd_done) |
| 103 | + { |
| 104 | + KVectorUtils::k_vec_c2d(kv, R); |
| 105 | + kv.kd_done = true; |
| 106 | + } |
| 107 | + std::string table; |
| 108 | + table += " K-POINTS DIRECT COORDINATES\n"; |
| 109 | + table += FmtCore::format("%8s%12s%12s%12s%8s\n", "KPOINTS", "DIRECT_X", "DIRECT_Y", "DIRECT_Z", "WEIGHT"); |
| 110 | + for (int i = 0; i < kv.get_nkstot(); i++) |
| 111 | + { |
| 112 | + table += FmtCore::format("%8d%12.8f%12.8f%12.8f%8.4f\n", |
| 113 | + i + 1, |
| 114 | + kv.kvec_d[i].x, |
| 115 | + kv.kvec_d[i].y, |
| 116 | + kv.kvec_d[i].z, |
| 117 | + kv.wk[i]); |
| 118 | + } |
| 119 | + GlobalV::ofs_running << table << std::endl; |
| 120 | + if (GlobalV::MY_RANK == 0) |
| 121 | + { |
| 122 | + std::stringstream ss; |
| 123 | + ss << " " << std::setw(40) << "nkstot now" |
| 124 | + << " = " << kv.get_nkstot() << std::endl; |
| 125 | + ss << table << std::endl; |
| 126 | + skpt = ss.str(); |
| 127 | + } |
| 128 | + return; |
| 129 | +} |
| 130 | + |
| 131 | +void set_after_vc(K_Vectors& kv, |
| 132 | + const int& nspin_in, |
| 133 | + const ModuleBase::Matrix3& reciprocal_vec) |
| 134 | +{ |
| 135 | + GlobalV::ofs_running << "\n SETUP K-POINTS" << std::endl; |
| 136 | + kv.nspin = nspin_in; |
| 137 | + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "nspin", kv.nspin); |
| 138 | + |
| 139 | + // set cartesian k vectors. |
| 140 | + KVectorUtils::k_vec_d2c(kv, reciprocal_vec); |
| 141 | + |
| 142 | + std::string table; |
| 143 | + table += "K-POINTS DIRECT COORDINATES\n"; |
| 144 | + table += FmtCore::format("%8s%12s%12s%12s%8s\n", "KPOINTS", "DIRECT_X", "DIRECT_Y", "DIRECT_Z", "WEIGHT"); |
| 145 | + for (int i = 0; i < kv.get_nks(); i++) |
| 146 | + { |
| 147 | + table += FmtCore::format("%8d%12.8f%12.8f%12.8f%8.4f\n", |
| 148 | + i + 1, |
| 149 | + kv.kvec_d[i].x, |
| 150 | + kv.kvec_d[i].y, |
| 151 | + kv.kvec_d[i].z, |
| 152 | + kv.wk[i]); |
| 153 | + } |
| 154 | + GlobalV::ofs_running << table << std::endl; |
| 155 | + |
| 156 | + kv.print_klists(GlobalV::ofs_running); |
| 157 | +} |
| 158 | +} // namespace KVectorUtils |
0 commit comments