Skip to content

Commit 66c4e58

Browse files
authored
Refatcor:Use PARAM instead of GlobalV::NBAND,NLocal (#5193)
* Modify param nlocal in the hsolver * Modify param nlocal in the io * fix param nlocal bug in the io * fix param nlocal in the ri * fix param nlocal * fix param nlocal in the test file * fix param nbands in the elecstate * fix param nbands in the module_esolver * fix param nbands in the module_hamilt * fix param nbands in the module_hsolver * fix param nbands in the module_io * fix param nbands in the module_ri * fix param nbands * fix param nbands in test file * change the variable file * fix compile error * fix input_conv.cpp compile bug * fix bug in test hasSubstr * fix para in cal_atoms * change device in cpp file * change device in test file * change param.globalv.device_flag * change param.sys.device_flag
1 parent 72b1d7c commit 66c4e58

File tree

140 files changed

+867
-922
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+867
-922
lines changed

source/module_base/global_variable.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,6 @@
1212
#include <vector>
1313
namespace GlobalV
1414
{
15-
16-
//----------------------------------------------------------
17-
// EXPLAIN : Basic Global Variables
18-
// In practice calculation, these values are set in
19-
// input.cpp.
20-
//----------------------------------------------------------
21-
int NBANDS = 0;
22-
int NLOCAL = 0; // total number of local basis.
23-
24-
double nupdown = 0.0;
25-
26-
bool use_uspp = false;
27-
std::string KS_SOLVER = "cg"; // xiaohui add 2013-09-01
28-
double SEARCH_RADIUS = -1.0;
29-
30-
int NB2D = 1;
31-
32-
3315
//----------------------------------------------------------
3416
// EXPLAIN : Parallel information
3517
//----------------------------------------------------------
@@ -52,21 +34,11 @@ int GRANK = MY_RANK;
5234
int GSIZE = DSIZE;
5335

5436
//----------------------------------------------------------
55-
// EXPLAIN : The input file name and directory
37+
// EXPLAIN : ofstream for output
5638
//----------------------------------------------------------
5739
std::ofstream ofs_running;
5840
std::ofstream ofs_warning;
5941
std::ofstream ofs_info; // output math lib info
6042
std::ofstream ofs_device; // output device info
6143

62-
63-
//==========================================================
64-
// device flags added by denghui
65-
//==========================================================
66-
std::string device_flag = "unknown";
67-
68-
double nelec = 0;
69-
70-
71-
// on-site orbitals
7244
} // namespace GlobalV

source/module_base/global_variable.h

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,6 @@
1313

1414
namespace GlobalV
1515
{
16-
//==========================================================
17-
// EXPLAIN : Basic Global Variables
18-
//==========================================================
19-
20-
extern int NBANDS;
21-
extern int NLOCAL; // 1.1 // mohan add 2009-05-29
22-
23-
extern double nupdown;
24-
extern bool use_uspp;
25-
26-
extern std::string KS_SOLVER; // xiaohui add 2013-09-01
27-
extern double SEARCH_RADIUS; // 11.1 // mohan add 2011-03-10
28-
29-
30-
extern int NB2D; // 16.5 dividsion of 2D_matrix.
31-
32-
// pw, 2: real drho for lcao
33-
34-
3516
//========================================================================
3617
// EXPLAIN : Parallel information
3718
// GLOBAL VARIABLES :
@@ -84,30 +65,5 @@ extern std::ofstream ofs_running;
8465
extern std::ofstream ofs_warning;
8566
extern std::ofstream ofs_info;
8667
extern std::ofstream ofs_device;
87-
88-
89-
// mixing parameters
90-
91-
//==========================================================
92-
// device flags added by denghui
93-
//==========================================================
94-
extern std::string device_flag;
95-
//==========================================================
96-
// precision flags added by denghui
97-
//==========================================================
98-
99-
// "out_chg" elec step.
100-
/// @brief method to initialize wavefunction
101-
/// @author kirk0830, 20230920
102-
/// @brief whether use the new psi initializer to initialize psi
103-
/// @author ykhuang, 20230920
104-
105-
extern double nelec;
106-
107-
// Deltaspin related
108-
109-
// Quasiatomic orbital related
110-
111-
// radius of on-site orbitals
11268
} // namespace GlobalV
11369
#endif

source/module_base/module_device/device.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,12 @@ int set_device_by_rank(const MPI_Comm mpi_comm) {
148148
#endif
149149

150150
std::string get_device_flag(const std::string &device,
151-
const std::string &ks_solver,
152151
const std::string &basis_type) {
153152
if (device == "cpu") {
154153
return "cpu"; // no extra checks required
155154
}
156155
std::string error_message;
157-
if (device != "" and device != "gpu")
156+
if (device != "auto" and device != "gpu")
158157
{
159158
error_message += "Parameter \"device\" can only be set to \"cpu\" or \"gpu\"!";
160159
ModuleBase::WARNING_QUIT("device", error_message);

source/module_base/module_device/device.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ int get_device_kpar(const int& kpar);
4444

4545
/**
4646
* @brief Get the device flag object
47-
* for module_io PARAM.globalv.device_flag
47+
* for module_io PARAM.inp.device
4848
*/
4949
std::string get_device_flag(const std::string& device,
50-
const std::string& ks_solver,
5150
const std::string& basis_type);
5251

5352
#if __MPI

source/module_cell/cal_atoms_info.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class CalAtomsInfo
2424
{
2525
for (int ia = 0; ia < atoms[it].na; ++ia)
2626
{
27-
GlobalV::nupdown += atoms[it].mag[ia];
27+
para.input.nupdown += atoms[it].mag[ia];
2828
}
2929
}
30-
GlobalV::ofs_running << " The readin total magnetization is " << GlobalV::nupdown << std::endl;
30+
GlobalV::ofs_running << " The readin total magnetization is " << para.inp.nupdown << std::endl;
3131
}
3232

3333
if (!para.inp.use_paw)
@@ -37,38 +37,37 @@ class CalAtomsInfo
3737
{
3838
if (atoms[it].ncpp.tvanp)
3939
{
40-
GlobalV::use_uspp = true;
40+
para.sys.use_uspp = true;
4141
}
4242
}
4343

4444
// calculate the total number of local basis
45-
GlobalV::NLOCAL = 0;
45+
para.sys.nlocal = 0;
4646
for (int it = 0; it < ntype; ++it)
4747
{
4848
const int nlocal_it = atoms[it].nw * atoms[it].na;
4949
if (para.inp.nspin != 4)
5050
{
51-
GlobalV::NLOCAL += nlocal_it;
51+
para.sys.nlocal += nlocal_it;
5252
}
5353
else
5454
{
55-
GlobalV::NLOCAL += nlocal_it * 2; // zhengdy-soc
55+
para.sys.nlocal += nlocal_it * 2; // zhengdy-soc
5656
}
5757
}
5858
}
5959

6060
// calculate the total number of electrons
61-
cal_nelec(atoms, ntype, GlobalV::nelec);
61+
cal_nelec(atoms, ntype, para.input.nelec);
6262

6363
// autoset and check GlobalV::NBANDS
6464
std::vector<double> nelec_spin(2, 0.0);
6565
if (para.inp.nspin == 2)
6666
{
67-
nelec_spin[0] = (GlobalV::nelec + GlobalV::nupdown) / 2.0;
68-
nelec_spin[1] = (GlobalV::nelec - GlobalV::nupdown) / 2.0;
67+
nelec_spin[0] = (para.inp.nelec + para.inp.nupdown ) / 2.0;
68+
nelec_spin[1] = (para.inp.nelec - para.inp.nupdown ) / 2.0;
6969
}
70-
cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS);
71-
70+
cal_nbands(para.inp.nelec, para.sys.nlocal, nelec_spin, para.input.nbands);
7271
return;
7372
}
7473
};

0 commit comments

Comments
 (0)