Skip to content

Commit 89f2cc1

Browse files
Refactor
1 parent a9e9ecd commit 89f2cc1

File tree

3 files changed

+20
-83
lines changed

3 files changed

+20
-83
lines changed

examples/hse/pw_Si2/INPUT

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pseudo_dir ../../../tests/PP_ORB
33
orbital_dir ../../../tests/PP_ORB
44
nbands 4
55
nspin 1
6-
calculation scf
6+
calculation cell-relax
77
basis_type pw
88
ks_solver dav
99
ecutwfc 50
@@ -15,7 +15,7 @@ smearing_method fixed
1515
mixing_type broyden
1616
mixing_beta 0.7
1717

18-
dft_functional hse
18+
# dft_functional hse
1919

2020
# init_wfc file
2121
# init_chg file
@@ -30,3 +30,4 @@ exx_hybrid_alpha 0.25
3030

3131
cal_stress 1
3232
# cal_force 1
33+
kpar 2

source/module_cell/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ add_library(
2525
read_stru.cpp
2626
print_cell.cpp
2727
read_atom_species.cpp
28+
k_vector_utils.cpp
2829
)
2930

3031
if(ENABLE_COVERAGE)

source/module_cell/klist.cpp

Lines changed: 16 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "klist.h"
22

3+
#include "k_vector_utils.h"
34
#include "module_base/formatter.h"
45
#include "module_base/memory.h"
56
#include "module_base/parallel_common.h"
@@ -127,6 +128,12 @@ void K_Vectors::set(const UnitCell& ucell,
127128
// Complement the coordinates of k point
128129
this->set_both_kvec(reciprocal_vec, latvec, skpt2);
129130

131+
std::cout << "after set_both_kvec" << std::endl;
132+
std::cout << "nks: " << nks << std::endl;
133+
std::cout << "nkstot: " << nkstot << std::endl;
134+
std::cout << "size of kvec_d: " << kvec_d.size() << std::endl;
135+
std::cout << "size of kvec_c: " << kvec_c.size() << std::endl;
136+
130137
if (GlobalV::MY_RANK == 0)
131138
{
132139
// output kpoints file
@@ -163,6 +170,12 @@ void K_Vectors::set(const UnitCell& ucell,
163170

164171
this->print_klists(ofs);
165172

173+
std::cout << "after print_klists" << std::endl;
174+
std::cout << "nks: " << nks << std::endl;
175+
std::cout << "nkstot: " << nkstot << std::endl;
176+
std::cout << "size of kvec_d: " << kvec_d.size() << std::endl;
177+
std::cout << "size of kvec_c: " << kvec_c.size() << std::endl;
178+
166179
// std::cout << " NUMBER OF K-POINTS : " << nkstot << std::endl;
167180

168181
return;
@@ -1034,50 +1047,14 @@ void K_Vectors::set_both_kvec(const ModuleBase::Matrix3& G, const ModuleBase::Ma
10341047
// set cartesian k vectors.
10351048
if (!kc_done && kd_done)
10361049
{
1037-
for (int i = 0; i < nkstot; i++)
1038-
{
1039-
// wrong!! kvec_c[i] = G * kvec_d[i];
1040-
// mohan fixed bug 2010-1-10
1041-
if (std::abs(kvec_d[i].x) < 1.0e-10) {
1042-
kvec_d[i].x = 0.0;
1043-
}
1044-
if (std::abs(kvec_d[i].y) < 1.0e-10) {
1045-
kvec_d[i].y = 0.0;
1046-
}
1047-
if (std::abs(kvec_d[i].z) < 1.0e-10) {
1048-
kvec_d[i].z = 0.0;
1049-
}
1050-
1051-
kvec_c[i] = kvec_d[i] * G;
1052-
1053-
// mohan add2012-06-10
1054-
if (std::abs(kvec_c[i].x) < 1.0e-10) {
1055-
kvec_c[i].x = 0.0;
1056-
}
1057-
if (std::abs(kvec_c[i].y) < 1.0e-10) {
1058-
kvec_c[i].y = 0.0;
1059-
}
1060-
if (std::abs(kvec_c[i].z) < 1.0e-10) {
1061-
kvec_c[i].z = 0.0;
1062-
}
1063-
}
1050+
KVectorUtils::k_vec_d2c(*this, G);
10641051
kc_done = true;
10651052
}
10661053

10671054
// set direct k vectors
10681055
else if (kc_done && !kd_done)
10691056
{
1070-
ModuleBase::Matrix3 RT = R.Transpose();
1071-
for (int i = 0; i < nkstot; i++)
1072-
{
1073-
// std::cout << " ik=" << i
1074-
// << " kvec.x=" << kvec_c[i].x
1075-
// << " kvec.y=" << kvec_c[i].y
1076-
// << " kvec.z=" << kvec_c[i].z << std::endl;
1077-
// wrong! kvec_d[i] = RT * kvec_c[i];
1078-
// mohan fixed bug 2011-03-07
1079-
kvec_d[i] = kvec_c[i] * RT;
1080-
}
1057+
KVectorUtils::k_vec_c2d(*this, R);
10811058
kd_done = true;
10821059
}
10831060
std::string table;
@@ -1360,50 +1337,8 @@ void K_Vectors::set_after_vc(const int& nspin_in,
13601337
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "nspin", nspin);
13611338

13621339
// set cartesian k vectors.
1363-
kd_done = true;
1364-
kc_done = false;
1365-
if (!kc_done && kd_done)
1366-
{
1367-
for (int i = 0; i < nks; i++)
1368-
{
1369-
// wrong!! kvec_c[i] = G * kvec_d[i];
1370-
// mohan fixed bug 2010-1-10
1371-
if (std::abs(kvec_d[i].x) < 1.0e-10) {
1372-
kvec_d[i].x = 0.0;
1373-
}
1374-
if (std::abs(kvec_d[i].y) < 1.0e-10) {
1375-
kvec_d[i].y = 0.0;
1376-
}
1377-
if (std::abs(kvec_d[i].z) < 1.0e-10) {
1378-
kvec_d[i].z = 0.0;
1379-
}
1380-
1381-
kvec_c[i] = kvec_d[i] * reciprocal_vec;
1340+
KVectorUtils::k_vec_d2c(*this, reciprocal_vec);
13821341

1383-
// mohan add2012-06-10
1384-
if (std::abs(kvec_c[i].x) < 1.0e-10) {
1385-
kvec_c[i].x = 0.0;
1386-
}
1387-
if (std::abs(kvec_c[i].y) < 1.0e-10) {
1388-
kvec_c[i].y = 0.0;
1389-
}
1390-
if (std::abs(kvec_c[i].z) < 1.0e-10) {
1391-
kvec_c[i].z = 0.0;
1392-
}
1393-
}
1394-
kc_done = true;
1395-
}
1396-
1397-
// set direct k vectors
1398-
else if (kc_done && !kd_done)
1399-
{
1400-
ModuleBase::Matrix3 RT = latvec.Transpose();
1401-
for (int i = 0; i < nks; i++)
1402-
{
1403-
kvec_d[i] = kvec_c[i] * RT;
1404-
}
1405-
kd_done = true;
1406-
}
14071342
std::string table;
14081343
table += "K-POINTS DIRECT COORDINATES\n";
14091344
table += FmtCore::format("%8s%12s%12s%12s%8s\n", "KPOINTS", "DIRECT_X", "DIRECT_Y", "DIRECT_Z", "WEIGHT");

0 commit comments

Comments
 (0)