Skip to content

Commit 8493b5e

Browse files
Fix: Tests
1 parent 8a41e6e commit 8493b5e

File tree

4 files changed

+92
-73
lines changed

4 files changed

+92
-73
lines changed

source/module_cell/k_vector_utils.cpp

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,19 @@ void set_both_kvec(K_Vectors& kv, const ModuleBase::Matrix3& G, const ModuleBase
8181
{
8282
if (true) // Originally GlobalV::FINAL_SCF, but we don't have this variable in the new code.
8383
{
84-
if (kv.k_nkstot == 0)
84+
if (kv.get_k_nkstot() == 0)
8585
{
8686
kv.kd_done = true;
8787
kv.kc_done = false;
8888
}
8989
else
9090
{
91-
if (kv.k_kword == "Cartesian" || kv.k_kword == "C")
91+
if (kv.get_k_kword() == "Cartesian" || kv.get_k_kword() == "C")
9292
{
9393
kv.kc_done = true;
9494
kv.kd_done = false;
9595
}
96-
else if (kv.k_kword == "Direct" || kv.k_kword == "D")
96+
else if (kv.get_k_kword() == "Direct" || kv.get_k_kword() == "D")
9797
{
9898
kv.kd_done = true;
9999
kv.kc_done = false;
@@ -145,8 +145,9 @@ void set_both_kvec(K_Vectors& kv, const ModuleBase::Matrix3& G, const ModuleBase
145145
void set_after_vc(K_Vectors& kv, const int& nspin_in, const ModuleBase::Matrix3& reciprocal_vec)
146146
{
147147
GlobalV::ofs_running << "\n SETUP K-POINTS" << std::endl;
148-
kv.nspin = nspin_in;
149-
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "nspin", kv.nspin);
148+
// kv.nspin = nspin_in;
149+
kv.set_nspin(nspin_in);
150+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "nspin", kv.get_nspin());
150151

151152
// set cartesian k vectors.
152153
KVectorUtils::k_vec_d2c(kv, reciprocal_vec);
@@ -168,6 +169,48 @@ void set_after_vc(K_Vectors& kv, const int& nspin_in, const ModuleBase::Matrix3&
168169
kv.kd_done = true;
169170
kv.kc_done = true;
170171

171-
kv.print_klists(GlobalV::ofs_running);
172+
print_klists(kv, GlobalV::ofs_running);
173+
}
174+
175+
void print_klists(const K_Vectors& kv, std::ofstream& ofs)
176+
{
177+
ModuleBase::TITLE("KVectorUtils", "print_klists");
178+
int nks = kv.get_nks();
179+
int nkstot = kv.get_nkstot();
180+
181+
if (nkstot < nks)
182+
{
183+
std::cout << "\n nkstot=" << nkstot;
184+
std::cout << "\n nks=" << nks;
185+
ModuleBase::WARNING_QUIT("print_klists", "nkstot < nks");
186+
}
187+
std::string table;
188+
table += " K-POINTS CARTESIAN COORDINATES\n";
189+
table += FmtCore::format("%8s%12s%12s%12s%8s\n", "KPOINTS", "CARTESIAN_X", "CARTESIAN_Y", "CARTESIAN_Z", "WEIGHT");
190+
for (int i = 0; i < nks; i++)
191+
{
192+
table += FmtCore::format("%8d%12.8f%12.8f%12.8f%8.4f\n",
193+
i + 1,
194+
kv.kvec_c[i].x,
195+
kv.kvec_c[i].y,
196+
kv.kvec_c[i].z,
197+
kv.wk[i]);
198+
}
199+
GlobalV::ofs_running << "\n" << table << std::endl;
200+
201+
table.clear();
202+
table += " K-POINTS DIRECT COORDINATES\n";
203+
table += FmtCore::format("%8s%12s%12s%12s%8s\n", "KPOINTS", "DIRECT_X", "DIRECT_Y", "DIRECT_Z", "WEIGHT");
204+
for (int i = 0; i < nks; i++)
205+
{
206+
table += FmtCore::format("%8d%12.8f%12.8f%12.8f%8.4f\n",
207+
i + 1,
208+
kv.kvec_d[i].x,
209+
kv.kvec_d[i].y,
210+
kv.kvec_d[i].z,
211+
kv.wk[i]);
212+
}
213+
GlobalV::ofs_running << "\n" << table << std::endl;
214+
return;
172215
}
173216
} // namespace KVectorUtils

source/module_cell/k_vector_utils.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ void set_both_kvec(K_Vectors& kv, const ModuleBase::Matrix3& G, const ModuleBase
5959
* coordinates.
6060
*/
6161
void set_after_vc(K_Vectors& kv, const int& nspin, const ModuleBase::Matrix3& G);
62+
63+
/**
64+
* @brief Prints the k-points in both Cartesian and direct coordinates.
65+
*
66+
* This function prints the k-points in both Cartesian and direct coordinates to the output file stream.
67+
* The output includes the index, x, y, and z coordinates, and the weight of each k-point.
68+
*
69+
* @param ofs The output file stream to which the k-points are printed.
70+
*
71+
* @return void
72+
*
73+
* @note The function first checks if the total number of k-points (nkstot) is less than the number of k-points for
74+
* the current spin (nks). If so, it prints an error message and quits.
75+
* @note The function prints the k-points in a table format, with separate tables for Cartesian and direct
76+
* coordinates.
77+
* @note The function uses the FmtCore::format function to format the output.
78+
*/
79+
void print_klists(const K_Vectors& kv, std::ofstream& ofs);
6280
} // namespace KVectorUtils
6381

6482
#endif // K_VECTOR_UTILS_H

source/module_cell/klist.cpp

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void K_Vectors::set(const UnitCell& ucell,
163163
// get ik2iktot
164164
this->cal_ik_global();
165165

166-
this->print_klists(ofs);
166+
KVectorUtils::print_klists(*this, ofs);
167167

168168
// std::cout << " NUMBER OF K-POINTS : " << nkstot << std::endl;
169169

@@ -1202,44 +1202,4 @@ void K_Vectors::set_kup_and_kdw()
12021202
}
12031203

12041204
return;
1205-
} // end subroutine set_kup_and_kdw
1206-
1207-
void K_Vectors::print_klists(std::ofstream& ofs)
1208-
{
1209-
ModuleBase::TITLE("K_Vectors", "print_klists");
1210-
1211-
if (nkstot < nks)
1212-
{
1213-
std::cout << "\n nkstot=" << nkstot;
1214-
std::cout << "\n nks=" << nks;
1215-
ModuleBase::WARNING_QUIT("print_klists", "nkstot < nks");
1216-
}
1217-
std::string table;
1218-
table += " K-POINTS CARTESIAN COORDINATES\n";
1219-
table += FmtCore::format("%8s%12s%12s%12s%8s\n", "KPOINTS", "CARTESIAN_X", "CARTESIAN_Y", "CARTESIAN_Z", "WEIGHT");
1220-
for (int i = 0; i < nks; i++)
1221-
{
1222-
table += FmtCore::format("%8d%12.8f%12.8f%12.8f%8.4f\n",
1223-
i + 1,
1224-
this->kvec_c[i].x,
1225-
this->kvec_c[i].y,
1226-
this->kvec_c[i].z,
1227-
this->wk[i]);
1228-
}
1229-
GlobalV::ofs_running << "\n" << table << std::endl;
1230-
1231-
table.clear();
1232-
table += " K-POINTS DIRECT COORDINATES\n";
1233-
table += FmtCore::format("%8s%12s%12s%12s%8s\n", "KPOINTS", "DIRECT_X", "DIRECT_Y", "DIRECT_Z", "WEIGHT");
1234-
for (int i = 0; i < nks; i++)
1235-
{
1236-
table += FmtCore::format("%8d%12.8f%12.8f%12.8f%8.4f\n",
1237-
i + 1,
1238-
this->kvec_d[i].x,
1239-
this->kvec_d[i].y,
1240-
this->kvec_d[i].z,
1241-
this->wk[i]);
1242-
}
1243-
GlobalV::ofs_running << "\n" << table << std::endl;
1244-
return;
1245-
}
1205+
} // end subroutine set_kup_and_kdw

source/module_cell/klist.h

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class K_Vectors
2727
/// dim: [iks_ibz][(isym, kvec_d)]
2828
std::vector<std::map<int, ModuleBase::Vector3<double>>> kstars;
2929

30+
bool kc_done = false;
31+
bool kd_done = false;
32+
3033
K_Vectors(){};
3134
~K_Vectors(){};
3235
K_Vectors& operator=(const K_Vectors&) = default;
@@ -103,6 +106,21 @@ class K_Vectors
103106
return this->koffset[i];
104107
}
105108

109+
int get_k_nkstot() const
110+
{
111+
return this->k_nkstot;
112+
}
113+
114+
int get_nspin() const
115+
{
116+
return this->nspin;
117+
}
118+
119+
std::string get_k_kword() const
120+
{
121+
return this->k_kword;
122+
}
123+
106124
void set_nks(int value)
107125
{
108126
this->nks = value;
@@ -118,6 +136,11 @@ class K_Vectors
118136
this->nkstot_full = value;
119137
}
120138

139+
void set_nspin(int value)
140+
{
141+
this->nspin = value;
142+
}
143+
121144
bool get_is_mp() const
122145
{
123146
return is_mp;
@@ -131,8 +154,6 @@ class K_Vectors
131154
int nkstot_full = 0; ///< number of k points before symmetry reduction in full k mesh
132155

133156
int nspin = 0;
134-
bool kc_done = false;
135-
bool kd_done = false;
136157
double koffset[3] = {0.0}; // used only in automatic k-points.
137158
std::string k_kword; // LiuXh add 20180619
138159
int k_nkstot = 0; // LiuXh add 20180619 // WHAT IS THIS?????
@@ -322,34 +343,11 @@ class K_Vectors
322343
*/
323344
void set_kup_and_kdw();
324345

325-
// step 5
326-
// print k lists.
327-
328-
/**
329-
* @brief Prints the k-points in both Cartesian and direct coordinates.
330-
*
331-
* This function prints the k-points in both Cartesian and direct coordinates to the output file stream.
332-
* The output includes the index, x, y, and z coordinates, and the weight of each k-point.
333-
*
334-
* @param ofs The output file stream to which the k-points are printed.
335-
*
336-
* @return void
337-
*
338-
* @note The function first checks if the total number of k-points (nkstot) is less than the number of k-points for
339-
* the current spin (nks). If so, it prints an error message and quits.
340-
* @note The function prints the k-points in a table format, with separate tables for Cartesian and direct
341-
* coordinates.
342-
* @note The function uses the FmtCore::format function to format the output.
343-
*/
344-
void print_klists(std::ofstream& fn);
345-
346346
/**
347347
* @brief Gets the global index of a k-point.
348348
* @return this->ik2iktot[ik]
349349
*/
350350
void cal_ik_global();
351351

352-
friend void KVectorUtils::set_both_kvec(K_Vectors& kv, const ModuleBase::Matrix3& G, const ModuleBase::Matrix3& R, std::string& skpt);
353-
friend void KVectorUtils::set_after_vc(K_Vectors& kv, const int& nspin_in, const ModuleBase::Matrix3& reciprocal_vec);
354352
};
355353
#endif // KVECT_H

0 commit comments

Comments
 (0)