Skip to content

Commit 6cb5965

Browse files
A-006Fisherd99
authored andcommitted
Refactor:Remove GlobalC::ucell in module_cell (deepmodeling#5626)
* modify the cell_index.h * update the ucell in set func * update the ucell test * update the build in print_info * update the postion of UnitCell * update file in the print_info
1 parent d17e1e0 commit 6cb5965

File tree

10 files changed

+120
-111
lines changed

10 files changed

+120
-111
lines changed

source/module_cell/cell_index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* the maximum L of a given atom, the number of chi of a given atom and a given L, the atom label of a given atom,
1313
* etc. The class provides the interface to get the information of the atoms and orbitals indices in the unit cell. It
1414
* also provides the interface to write the orbital information into a file. It is now used only in the Output_Mulliken
15-
* class. However, it is supposed to be able to replace GlobalC::ucell in LCAO codes where only cell indices are needed.
15+
* class. However, it is supposed to be able to replace ucell in LCAO codes where only cell indices are needed.
1616
* Take care that the three key vectors atomCounts, lnchiCounts, and atomLabels should be set from the UnitCell class.
1717
* It depends on nspin because the functions get_nw() and get_iwt() are related to nspin, and can
1818
* be used in the LCAO Hamiltonian construction.

source/module_cell/klist.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ int K_Vectors::get_ik_global(const int& ik, const int& nkstot)
5959
}
6060
}
6161

62-
void K_Vectors::set(const ModuleSymmetry::Symmetry& symm,
62+
void K_Vectors::set(const UnitCell& ucell,
63+
const ModuleSymmetry::Symmetry& symm,
6364
const std::string& k_file_name,
6465
const int& nspin_in,
6566
const ModuleBase::Matrix3& reciprocal_vec,
@@ -93,7 +94,7 @@ void K_Vectors::set(const ModuleSymmetry::Symmetry& symm,
9394
this->nspin = (this->nspin == 4) ? 1 : this->nspin;
9495

9596
// read KPT file and generate K-point grid
96-
bool read_succesfully = this->read_kpoints(k_file_name);
97+
bool read_succesfully = this->read_kpoints(ucell,k_file_name);
9798
#ifdef __MPI
9899
Parallel_Common::bcast_bool(read_succesfully);
99100
#endif
@@ -113,7 +114,7 @@ void K_Vectors::set(const ModuleSymmetry::Symmetry& symm,
113114
{
114115
bool match = true;
115116
// calculate kpoints in IBZ and reduce kpoints according to symmetry
116-
this->ibz_kpoint(symm, ModuleSymmetry::Symmetry::symm_flag, skpt1, GlobalC::ucell, match);
117+
this->ibz_kpoint(symm, ModuleSymmetry::Symmetry::symm_flag, skpt1, ucell, match);
117118
#ifdef __MPI
118119
Parallel_Common::bcast_bool(match);
119120
#endif
@@ -128,7 +129,7 @@ void K_Vectors::set(const ModuleSymmetry::Symmetry& symm,
128129
std::cout << "Automatically set symmetry to 0 and continue ..." << std::endl;
129130
ModuleSymmetry::Symmetry::symm_flag = 0;
130131
match = true;
131-
this->ibz_kpoint(symm, ModuleSymmetry::Symmetry::symm_flag, skpt1, GlobalC::ucell, match);
132+
this->ibz_kpoint(symm, ModuleSymmetry::Symmetry::symm_flag, skpt1, ucell, match);
132133
} else {
133134
ModuleBase::WARNING_QUIT("K_Vectors::ibz_kpoint",
134135
"Possible solutions: \n \
@@ -209,7 +210,8 @@ void K_Vectors::renew(const int& kpoint_number)
209210

210211
// Read the KPT file, which contains K-point coordinates, weights, and grid size information
211212
// Generate K-point grid according to different parameters of the KPT file
212-
bool K_Vectors::read_kpoints(const std::string& fn)
213+
bool K_Vectors::read_kpoints(const UnitCell& ucell,
214+
const std::string& fn)
213215
{
214216
ModuleBase::TITLE("K_Vectors", "read_kpoints");
215217
if (GlobalV::MY_RANK != 0)
@@ -236,16 +238,16 @@ bool K_Vectors::read_kpoints(const std::string& fn)
236238
ModuleBase::WARNING_QUIT("K_Vectors", "kspacing should > 0");
237239
};
238240
// number of K points = max(1,int(|bi|/KSPACING+1))
239-
ModuleBase::Matrix3 btmp = GlobalC::ucell.G;
241+
ModuleBase::Matrix3 btmp = ucell.G;
240242
double b1 = sqrt(btmp.e11 * btmp.e11 + btmp.e12 * btmp.e12 + btmp.e13 * btmp.e13);
241243
double b2 = sqrt(btmp.e21 * btmp.e21 + btmp.e22 * btmp.e22 + btmp.e23 * btmp.e23);
242244
double b3 = sqrt(btmp.e31 * btmp.e31 + btmp.e32 * btmp.e32 + btmp.e33 * btmp.e33);
243245
int nk1
244-
= std::max(1, static_cast<int>(b1 * ModuleBase::TWO_PI / PARAM.inp.kspacing[0] / GlobalC::ucell.lat0 + 1));
246+
= std::max(1, static_cast<int>(b1 * ModuleBase::TWO_PI / PARAM.inp.kspacing[0] / ucell.lat0 + 1));
245247
int nk2
246-
= std::max(1, static_cast<int>(b2 * ModuleBase::TWO_PI / PARAM.inp.kspacing[1] / GlobalC::ucell.lat0 + 1));
248+
= std::max(1, static_cast<int>(b2 * ModuleBase::TWO_PI / PARAM.inp.kspacing[1] / ucell.lat0 + 1));
247249
int nk3
248-
= std::max(1, static_cast<int>(b3 * ModuleBase::TWO_PI / PARAM.inp.kspacing[2] / GlobalC::ucell.lat0 + 1));
250+
= std::max(1, static_cast<int>(b3 * ModuleBase::TWO_PI / PARAM.inp.kspacing[2] / ucell.lat0 + 1));
249251

250252
GlobalV::ofs_warning << " Generate k-points file according to KSPACING: " << fn << std::endl;
251253
std::ofstream ofs(fn.c_str());

source/module_cell/klist.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class K_Vectors
5050
* it will output a warning and suggest possible solutions.
5151
* @note Only available for nspin = 1 or 2 or 4.
5252
*/
53-
void set(const ModuleSymmetry::Symmetry& symm,
53+
void set(const UnitCell& ucell,
54+
const ModuleSymmetry::Symmetry& symm,
5455
const std::string& k_file_name,
5556
const int& nspin,
5657
const ModuleBase::Matrix3& reciprocal_vec,
@@ -204,7 +205,8 @@ class K_Vectors
204205
* @note If the k-points type is Line mode and the symmetry flag is 1, it will quit with a warning.
205206
* @note If the number of k-points is greater than 100000, it will quit with a warning.
206207
*/
207-
bool read_kpoints(const std::string& fn); // return 0: something wrong.
208+
bool read_kpoints(const UnitCell& ucell,
209+
const std::string& fn); // return 0: something wrong.
208210

209211
/**
210212
* @brief Adds k-points linearly between special points.

0 commit comments

Comments
 (0)