Skip to content

Commit 7fab21a

Browse files
committed
update get ucell oemga
1 parent 82411c6 commit 7fab21a

File tree

10 files changed

+21
-35
lines changed

10 files changed

+21
-35
lines changed

source/module_elecstate/elecstate_getters.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
namespace elecstate
99
{
1010

11-
double get_ucell_omega()
12-
{
13-
return GlobalC::ucell.omega;
14-
}
15-
16-
1711
int get_xc_func_type()
1812
{
1913
return XC_Functional::get_func_type();

source/module_elecstate/elecstate_getters.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
namespace elecstate
88
{
99

10-
/// @brief get the value of GlobalC::ucell.omega
11-
double get_ucell_omega();
1210
/// @brief get the value of XC_Functional::func_type
1311
int get_xc_func_type();
1412

source/module_elecstate/elecstate_pw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void ElecStatePW<T, Device>::rhoBandK(const psi::Psi<T, Device>& psi)
176176

177177
this->basis->recip_to_real(this->ctx, &psi(ibnd,npwx), this->wfcr_another_spin, ik);
178178

179-
const auto w1 = static_cast<Real>(this->wg(ik, ibnd) / get_ucell_omega());
179+
const auto w1 = static_cast<Real>(this->wg(ik, ibnd) / ucell->omega);
180180

181181
if (w1 != 0.0)
182182
{
@@ -202,7 +202,7 @@ void ElecStatePW<T, Device>::rhoBandK(const psi::Psi<T, Device>& psi)
202202

203203
this->basis->recip_to_real(this->ctx, &psi(ibnd,0), this->wfcr, ik);
204204

205-
const auto w1 = static_cast<Real>(this->wg(ik, ibnd) / get_ucell_omega());
205+
const auto w1 = static_cast<Real>(this->wg(ik, ibnd) / ucell->omega);
206206

207207
if (w1 != 0.0)
208208
{

source/module_elecstate/elecstate_pw_cal_tau.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void ElecStatePW<T, Device>::cal_tau(const psi::Psi<T, Device>& psi)
2626
{
2727
this->basis->recip_to_real(this->ctx, &psi(ibnd,0), this->wfcr, ik);
2828

29-
const auto w1 = static_cast<Real>(this->wg(ik, ibnd) / get_ucell_omega());
29+
const auto w1 = static_cast<Real>(this->wg(ik, ibnd) / ucell->omega);
3030

3131
// kinetic energy density
3232
for (int j = 0; j < 3; j++)

source/module_elecstate/magnetism.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ Magnetism::~Magnetism()
1515
delete[] this->start_magnetization;
1616
}
1717

18-
void Magnetism::compute_magnetization(const int& nrxx, const int& nxyz, const double* const * rho, double* nelec_spin)
18+
void Magnetism::compute_magnetization(const double& omega,
19+
const int& nrxx,
20+
const int& nxyz,
21+
const double* const * rho,
22+
double* nelec_spin)
1923
{
2024
if (PARAM.inp.nspin==2)
2125
{
@@ -32,8 +36,8 @@ void Magnetism::compute_magnetization(const int& nrxx, const int& nxyz, const do
3236
Parallel_Reduce::reduce_pool(this->tot_magnetization);
3337
Parallel_Reduce::reduce_pool(this->abs_magnetization);
3438
#endif
35-
this->tot_magnetization *= elecstate::get_ucell_omega() / nxyz;
36-
this->abs_magnetization *= elecstate::get_ucell_omega() / nxyz;
39+
this->tot_magnetization *= omega / nxyz;
40+
this->abs_magnetization *= omega / nxyz;
3741

3842
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"total magnetism (Bohr mag/cell)",this->tot_magnetization);
3943
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"absolute magnetism (Bohr mag/cell)",this->abs_magnetization);

source/module_elecstate/magnetism.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ class Magnetism
2121
double tot_magnetization_nc[3];
2222
double abs_magnetization;
2323

24-
void compute_magnetization(const int& nrxx, const int& nxyz, const double* const * rho, double* nelec_spin = nullptr);
24+
void compute_magnetization(const double& omega,
25+
const int& nrxx,
26+
const int& nxyz,
27+
const double* const * rho,
28+
29+
double* nelec_spin = nullptr);
2530

2631
ModuleBase::Vector3<double> *m_loc_; //magnetization for each element along c-axis
2732
double *angle1_; //angle between c-axis and real spin std::vector

source/module_elecstate/test/charge_test.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ int get_xc_func_type()
3939
return tmp_xc_func_type;
4040
}
4141
double tmp_ucell_omega = 500.0;
42-
double get_ucell_omega()
43-
{
44-
return tmp_ucell_omega;
45-
}
4642
double tmp_gridecut = 80.0;
4743
void Set_GlobalV_Default()
4844
{

source/module_elecstate/test/elecstate_magnetism_test.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ Charge::~Charge()
3131
{
3232
}
3333

34-
double elecstate::get_ucell_omega()
35-
{
36-
return 500.0;
37-
}
3834

3935
class MagnetismTest : public ::testing::Test
4036
{
@@ -57,11 +53,6 @@ TEST_F(MagnetismTest, Magnetism)
5753
EXPECT_EQ(nullptr, magnetism->start_magnetization);
5854
}
5955

60-
TEST_F(MagnetismTest, GlobalInfo)
61-
{
62-
EXPECT_EQ(500.0, elecstate::get_ucell_omega());
63-
}
64-
6556
TEST_F(MagnetismTest, JudgeParallel)
6657
{
6758
double a[3] = {1.0, 0.0, 0.0};
@@ -91,7 +82,7 @@ TEST_F(MagnetismTest, ComputeMagnetizationS2)
9182
chr->rho[1][ir] = 1.01;
9283
}
9384
double* nelec_spin = new double[2];
94-
magnetism->compute_magnetization(chr->nrxx, chr->nxyz, chr->rho, nelec_spin);
85+
magnetism->compute_magnetization(500.0,chr->nrxx, chr->nxyz, chr->rho, nelec_spin);
9586
EXPECT_DOUBLE_EQ(-0.5, magnetism->tot_magnetization);
9687
EXPECT_DOUBLE_EQ(0.5, magnetism->abs_magnetization);
9788
EXPECT_DOUBLE_EQ(4.75, nelec_spin[0]);
@@ -125,7 +116,7 @@ TEST_F(MagnetismTest, ComputeMagnetizationS4)
125116
chr->rho[3][ir] = 1.00;
126117
}
127118
double* nelec_spin = new double[4];
128-
magnetism->compute_magnetization(chr->nrxx, chr->nxyz, chr->rho, nelec_spin);
119+
magnetism->compute_magnetization(500.0,chr->nrxx, chr->nxyz, chr->rho, nelec_spin);
129120
EXPECT_DOUBLE_EQ(100.0, magnetism->abs_magnetization);
130121
EXPECT_DOUBLE_EQ(50.0*std::sqrt(2.0), magnetism->tot_magnetization_nc[0]);
131122
EXPECT_DOUBLE_EQ(50.0, magnetism->tot_magnetization_nc[1]);

source/module_elecstate/test/elecstate_pw_test.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
// mock functions for testing
1212
namespace elecstate
1313
{
14-
double get_ucell_omega()
15-
{
16-
return 500.0;
17-
}
1814
int tmp_xc_func_type = 1;
1915
int get_xc_func_type()
2016
{
@@ -218,6 +214,7 @@ class ElecStatePWTest : public ::testing::Test
218214
klist = new K_Vectors;
219215
klist->set_nks(5);
220216
ucell = new UnitCell;
217+
ucell->omega = 500.0;
221218
ucell->tpiba = 2.0;
222219
ppcell = new pseudopot_cell_vnl;
223220
rhodpw = new ModulePW::PW_Basis;

source/module_esolver/esolver_ks.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,8 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
551551
ucell.magnet.compute_magnetization(this->pelec->charge->nrxx,
552552
this->pelec->charge->nxyz,
553553
this->pelec->charge->rho,
554-
this->pelec->nelec_spin.data());
554+
this->pelec->nelec_spin.data(),
555+
ucell.omega);
555556

556557
if (GlobalV::MY_STOGROUP == 0)
557558
{

0 commit comments

Comments
 (0)