Skip to content

Commit 6a44de7

Browse files
committed
update manget func in the file
1 parent fceebf7 commit 6a44de7

File tree

6 files changed

+27
-48
lines changed

6 files changed

+27
-48
lines changed

source/module_elecstate/elecstate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ class ElecState
174174
ModuleBase::matrix wg; ///< occupation weight for each k-point and band
175175

176176
public: // print something. See elecstate_print.cpp
177-
void print_etot(const bool converged,
177+
void print_etot(const UnitCell& ucell,
178+
const bool converged,
178179
const int& iter,
179180
const double& scf_thr,
180181
const double& scf_thr_kin,

source/module_elecstate/elecstate_getters.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,6 @@ int get_xc_func_type()
2424
}
2525

2626

27-
double get_ucell_tot_magnetization()
28-
{
29-
return GlobalC::ucell.magnet.tot_magnetization;
30-
}
31-
32-
double get_ucell_abs_magnetization()
33-
{
34-
return GlobalC::ucell.magnet.abs_magnetization;
35-
}
36-
37-
double get_ucell_tot_magnetization_nc_x()
38-
{
39-
return GlobalC::ucell.magnet.tot_magnetization_nc[0];
40-
}
41-
42-
double get_ucell_tot_magnetization_nc_y()
43-
{
44-
return GlobalC::ucell.magnet.tot_magnetization_nc[1];
45-
}
46-
47-
double get_ucell_tot_magnetization_nc_z()
48-
{
49-
return GlobalC::ucell.magnet.tot_magnetization_nc[2];
50-
}
5127

5228
std::string get_ks_solver_type()
5329
{

source/module_elecstate/elecstate_getters.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ double get_ucell_omega();
1313
double get_ucell_tpiba();
1414
/// @brief get the value of XC_Functional::func_type
1515
int get_xc_func_type();
16-
/// @brief get the value of GlobalC::ucell.magnet.tot_magnetization
17-
double get_ucell_tot_magnetization();
18-
/// @brief get the value of GlobalC::ucell.magnet.abs_magnetization
19-
double get_ucell_abs_magnetization();
20-
/// @brief get the value of GlobalC::ucell.magnet.tot_magnetization_nc[0]
21-
double get_ucell_tot_magnetization_nc_x();
22-
/// @brief get the value of GlobalC::ucell.magnet.tot_magnetization_nc[1]
23-
double get_ucell_tot_magnetization_nc_y();
24-
/// @brief get the value of GlobalC::ucell.magnet.tot_magnetization_nc[2]
25-
double get_ucell_tot_magnetization_nc_z();
2616
/// @brief get the type of KS_SOLVER
2717
std::string get_ks_solver_type();
2818

source/module_elecstate/elecstate_print.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ void ElecState::print_band(const int& ik, const int& printe, const int& iter)
289289
/// @param pw_diag_thr: threshold for diagonalization
290290
/// @param avg_iter: averaged diagonalization iteration of each scf iteration
291291
/// @param print: if print to screen
292-
void ElecState::print_etot(const bool converged,
292+
void ElecState::print_etot(const UnitCell& ucell,
293+
const bool converged,
293294
const int& iter_in,
294295
const double& scf_thr,
295296
const double& scf_thr_kin,
@@ -429,13 +430,13 @@ void ElecState::print_etot(const bool converged,
429430
switch (PARAM.inp.nspin)
430431
{
431432
case 2:
432-
mag = {get_ucell_tot_magnetization(), get_ucell_abs_magnetization()};
433+
mag = {ucell.magnet.tot_magnetization, ucell.magnet.abs_magnetization};
433434
break;
434435
case 4:
435-
mag = {get_ucell_tot_magnetization_nc_x(),
436-
get_ucell_tot_magnetization_nc_y(),
437-
get_ucell_tot_magnetization_nc_z(),
438-
get_ucell_abs_magnetization()};
436+
mag = {ucell.magnet.tot_magnetization_nc[0],
437+
ucell.magnet.tot_magnetization_nc[1],
438+
ucell.magnet.tot_magnetization_nc[2],
439+
ucell.magnet.abs_magnetization};
439440
break;
440441
default:
441442
mag = {};

source/module_elecstate/test/elecstate_print_test.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ K_Vectors::K_Vectors()
1717
K_Vectors::~K_Vectors()
1818
{
1919
}
20-
20+
UnitCell::UnitCell(){}
21+
UnitCell::~UnitCell(){}
22+
Magnetism::Magnetism(){}
23+
Magnetism::~Magnetism(){}
24+
InfoNonlocal::InfoNonlocal(){}
25+
InfoNonlocal::~InfoNonlocal(){}
2126
/***************************************************************
2227
* mock functions
2328
****************************************************************/
@@ -89,6 +94,7 @@ class ElecStatePrintTest : public ::testing::Test
8994
std::ifstream ifs;
9095
std::ofstream ofs;
9196
K_Vectors* p_klist;
97+
UnitCell ucell;
9298
void SetUp()
9399
{
94100
p_klist = new K_Vectors;
@@ -112,6 +118,11 @@ class ElecStatePrintTest : public ::testing::Test
112118
elecstate.wg(0, 1) = 0.2;
113119
elecstate.wg(1, 0) = 0.3;
114120
elecstate.wg(1, 1) = 0.4;
121+
ucell.magnet.tot_magnetization = 1.1;
122+
ucell.magnet.abs_magnetization = 2.2;
123+
ucell.magnet.tot_magnetization_nc[0] = 3.3;
124+
ucell.magnet.tot_magnetization_nc[1] = 4.4;
125+
ucell.magnet.tot_magnetization_nc[2] = 5.5;
115126
}
116127
void TearDown()
117128
{
@@ -247,15 +258,15 @@ TEST_F(ElecStatePrintTest, PrintEtot)
247258
for (int i = 0; i < vdw_methods.size(); i++)
248259
{
249260
PARAM.input.vdw_method = vdw_methods[i];
250-
elecstate.print_etot(converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, false);
261+
elecstate.print_etot(ucell,converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, false);
251262
}
252263
// iteration of different ks_solver
253264
std::vector<std::string> ks_solvers = {"cg", "lapack", "genelpa", "dav", "scalapack_gvx", "cusolver"};
254265
for (int i = 0; i < ks_solvers.size(); i++)
255266
{
256267
elecstate::tmp_ks_solver = ks_solvers[i];
257268
testing::internal::CaptureStdout();
258-
elecstate.print_etot(converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print);
269+
elecstate.print_etot(ucell,converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print);
259270
output = testing::internal::GetCapturedStdout();
260271
if (elecstate::tmp_ks_solver == "cg")
261272
{
@@ -323,7 +334,7 @@ TEST_F(ElecStatePrintTest, PrintEtot2)
323334
PARAM.input.basis_type = "pw";
324335
PARAM.input.scf_nmax = 100;
325336

326-
elecstate.print_etot(converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print);
337+
elecstate.print_etot(ucell,converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print);
327338
GlobalV::ofs_running.close();
328339
ifs.open("test.dat", std::ios::in);
329340
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
@@ -359,7 +370,7 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS2)
359370
PARAM.input.out_bandgap = true;
360371
PARAM.input.nspin = 2;
361372
GlobalV::MY_RANK = 0;
362-
elecstate.print_etot(converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print);
373+
elecstate.print_etot(ucell,converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print);
363374
}
364375

365376
TEST_F(ElecStatePrintTest, PrintEtotColorS4)
@@ -384,5 +395,5 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS4)
384395
PARAM.input.nspin = 4;
385396
PARAM.input.noncolin = true;
386397
GlobalV::MY_RANK = 0;
387-
elecstate.print_etot(converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print);
398+
elecstate.print_etot(ucell,converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print);
388399
}

source/module_esolver/esolver_ks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
677677
{
678678
dkin = p_chgmix->get_dkin(pelec->charge, PARAM.inp.nelec,ucell.omega);
679679
}
680-
this->pelec->print_etot(this->conv_esolver, iter, drho, dkin, duration, PARAM.inp.printe, diag_ethr);
680+
this->pelec->print_etot(ucell,this->conv_esolver, iter, drho, dkin, duration, PARAM.inp.printe, diag_ethr);
681681

682682
// Json, need to be moved to somewhere else
683683
#ifdef __RAPIDJSON

0 commit comments

Comments
 (0)