Skip to content

Commit 815bff5

Browse files
Refactor:remove GlobalC::ucell in module_elesctate (#5730)
* change ucell in elecstate_energy * fix bug in elesctate_energy * change ucell in set-rho_core * change ucell in elecstate.cpp * change ucell in charge_mixing * change ucell in prepare in H_TDDFT_pw.cpp * change ucell in set_nonlocal.cpp * change ucell in ucell_getters.cpp * change elecstate_getter * change PARAM.inp.vdw_method in the elecstate_print * change ucell in charge_mixing * change get ucell tpiba in getters * [pre-commit.ci lite] apply automatic fixes * change ucell test file * update value of omega and tpiba in charge_mixing * update get ucell oemga * change ucell in the charge * fix bug in charge * fix bug in set_omega --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 5c815a1 commit 815bff5

37 files changed

+288
-255
lines changed

source/module_cell/setup_nonlocal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void InfoNonlocal::Set_NonLocal(const int& it,
3434
ModuleBase::TITLE("InfoNonlocal", "Set_NonLocal");
3535

3636
// set a pointer
37-
// Atom* atom = &GlobalC::ucell.atoms[it];
37+
// Atom* atom = &ucell.atoms[it];
3838

3939
// get the number of non-local projectors
4040
n_projectors = atom->ncpp.nbeta;

source/module_elecstate/elecstate.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ void ElecState::calEBand()
207207

208208

209209
void ElecState::init_scf(const int istep,
210+
const UnitCell& ucell,
210211
const ModuleBase::ComplexMatrix& strucfac,
211212
const bool* numeric,
212213
ModuleSymmetry::Symmetry& symm,
@@ -215,7 +216,7 @@ void ElecState::init_scf(const int istep,
215216
//! core correction potential.
216217
if (!PARAM.inp.use_paw)
217218
{
218-
this->charge->set_rho_core(strucfac, numeric);
219+
this->charge->set_rho_core(ucell,strucfac, numeric);
219220
}
220221
else
221222
{
@@ -226,7 +227,7 @@ void ElecState::init_scf(const int istep,
226227
// choose charge density from ionic step 0.
227228
if (istep == 0)
228229
{
229-
this->charge->init_rho(this->eferm, strucfac, symm, (const void*)this->klist, wfcpw);
230+
this->charge->init_rho(this->eferm,ucell, strucfac, symm, (const void*)this->klist, wfcpw);
230231
this->charge->check_rho(); // check the rho
231232
}
232233

source/module_elecstate/elecstate.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,13 @@ class ElecState
104104
* @brief Init rho_core, init rho, renormalize rho, init pot
105105
*
106106
* @param istep i-th step
107+
* @param ucell unit cell
107108
* @param strucfac structure factor
108109
* @param symm symmetry
109110
* @param wfcpw PW basis for wave function if needed
110111
*/
111112
void init_scf(const int istep,
113+
const UnitCell& ucell,
112114
const ModuleBase::ComplexMatrix& strucfac,
113115
const bool* numeric,
114116
ModuleSymmetry::Symmetry& symm,
@@ -126,7 +128,7 @@ class ElecState
126128
void cal_bandgap();
127129
void cal_bandgap_updw();
128130

129-
double cal_delta_eband() const;
131+
double cal_delta_eband(const UnitCell& ucell) const;
130132
double cal_delta_escf() const;
131133

132134
ModuleBase::matrix vnew;
@@ -171,7 +173,8 @@ class ElecState
171173
ModuleBase::matrix wg; ///< occupation weight for each k-point and band
172174

173175
public: // print something. See elecstate_print.cpp
174-
void print_etot(const bool converged,
176+
void print_etot(const Magnetism& magnet,
177+
const bool converged,
175178
const int& iter,
176179
const double& scf_thr,
177180
const double& scf_thr_kin,

source/module_elecstate/elecstate_energy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void ElecState::cal_bandgap_updw()
9090
}
9191

9292
/// @brief calculate deband
93-
double ElecState::cal_delta_eband() const
93+
double ElecState::cal_delta_eband(const UnitCell& ucell) const
9494
{
9595
// out potentials from potential mixing
9696
// total energy and band energy corrections
@@ -109,7 +109,7 @@ double ElecState::cal_delta_eband() const
109109
{
110110
ModuleBase::matrix v_xc;
111111
const std::tuple<double, double, ModuleBase::matrix> etxc_vtxc_v
112-
= XC_Functional::v_xc(this->charge->nrxx, this->charge, &GlobalC::ucell);
112+
= XC_Functional::v_xc(this->charge->nrxx, this->charge, &ucell);
113113
v_xc = std::get<2>(etxc_vtxc_v);
114114

115115
for (int ir = 0; ir < this->charge->rhopw->nrxx; ir++)

source/module_elecstate/elecstate_getters.cpp

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

11-
double get_ucell_omega()
12-
{
13-
return GlobalC::ucell.omega;
14-
}
15-
16-
double get_ucell_tpiba()
17-
{
18-
return GlobalC::ucell.tpiba;
19-
}
20-
2111
int get_xc_func_type()
2212
{
2313
return XC_Functional::get_func_type();
2414
}
2515

26-
std::string get_input_vdw_method()
27-
{
28-
return PARAM.inp.vdw_method;
29-
}
30-
31-
double get_ucell_tot_magnetization()
32-
{
33-
return GlobalC::ucell.magnet.tot_magnetization;
34-
}
35-
36-
double get_ucell_abs_magnetization()
37-
{
38-
return GlobalC::ucell.magnet.abs_magnetization;
39-
}
40-
41-
double get_ucell_tot_magnetization_nc_x()
42-
{
43-
return GlobalC::ucell.magnet.tot_magnetization_nc[0];
44-
}
45-
46-
double get_ucell_tot_magnetization_nc_y()
47-
{
48-
return GlobalC::ucell.magnet.tot_magnetization_nc[1];
49-
}
50-
51-
double get_ucell_tot_magnetization_nc_z()
52-
{
53-
return GlobalC::ucell.magnet.tot_magnetization_nc[2];
54-
}
55-
56-
std::string get_ks_solver_type()
57-
{
58-
return PARAM.inp.ks_solver;
59-
}
6016

6117
} // namespace elecstate

source/module_elecstate/elecstate_getters.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,9 @@
77
namespace elecstate
88
{
99

10-
/// @brief get the value of GlobalC::ucell.omega
11-
double get_ucell_omega();
12-
/// @brief get the value of GlobalC::ucell.tpiba
13-
double get_ucell_tpiba();
1410
/// @brief get the value of XC_Functional::func_type
1511
int get_xc_func_type();
16-
/// @brief get the value of INPUT.vdw_method
17-
std::string get_input_vdw_method();
18-
/// @brief get the value of GlobalC::ucell.magnet.tot_magnetization
19-
double get_ucell_tot_magnetization();
20-
/// @brief get the value of GlobalC::ucell.magnet.abs_magnetization
21-
double get_ucell_abs_magnetization();
22-
/// @brief get the value of GlobalC::ucell.magnet.tot_magnetization_nc[0]
23-
double get_ucell_tot_magnetization_nc_x();
24-
/// @brief get the value of GlobalC::ucell.magnet.tot_magnetization_nc[1]
25-
double get_ucell_tot_magnetization_nc_y();
26-
/// @brief get the value of GlobalC::ucell.magnet.tot_magnetization_nc[2]
27-
double get_ucell_tot_magnetization_nc_z();
28-
/// @brief get the type of KS_SOLVER
29-
std::string get_ks_solver_type();
12+
3013

3114
} // namespace elecstate
3215

source/module_elecstate/elecstate_print.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,16 @@ void ElecState::print_band(const int& ik, const int& printe, const int& iter)
282282
}
283283

284284
/// @brief print total free energy and other energies
285+
/// @param ucell: unit cell
285286
/// @param converged: if converged
286287
/// @param iter_in: iter
287288
/// @param scf_thr: threshold for scf
288289
/// @param duration: time of each iteration
289290
/// @param pw_diag_thr: threshold for diagonalization
290291
/// @param avg_iter: averaged diagonalization iteration of each scf iteration
291292
/// @param print: if print to screen
292-
void ElecState::print_etot(const bool converged,
293+
void ElecState::print_etot(const Magnetism& magnet,
294+
const bool converged,
293295
const int& iter_in,
294296
const double& scf_thr,
295297
const double& scf_thr_kin,
@@ -339,7 +341,7 @@ void ElecState::print_etot(const bool converged,
339341
energies_Ry.push_back(this->f_en.demet);
340342
titles.push_back("E_descf");
341343
energies_Ry.push_back(this->f_en.descf);
342-
std::string vdw_method = get_input_vdw_method();
344+
std::string vdw_method = PARAM.inp.vdw_method;
343345
if (vdw_method == "d2") // Peize Lin add 2014-04, update 2021-03-09
344346
{
345347
titles.push_back("E_vdwD2");
@@ -429,13 +431,13 @@ void ElecState::print_etot(const bool converged,
429431
switch (PARAM.inp.nspin)
430432
{
431433
case 2:
432-
mag = {get_ucell_tot_magnetization(), get_ucell_abs_magnetization()};
434+
mag = {magnet.tot_magnetization, magnet.abs_magnetization};
433435
break;
434436
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()};
437+
mag = {magnet.tot_magnetization_nc[0],
438+
magnet.tot_magnetization_nc[1],
439+
magnet.tot_magnetization_nc[2],
440+
magnet.abs_magnetization};
439441
break;
440442
default:
441443
mag = {};
@@ -446,7 +448,7 @@ void ElecState::print_etot(const bool converged,
446448
{
447449
drho.push_back(scf_thr_kin);
448450
}
449-
elecstate::print_scf_iterinfo(get_ks_solver_type(),
451+
elecstate::print_scf_iterinfo(PARAM.inp.ks_solver,
450452
iter,
451453
6,
452454
mag,

source/module_elecstate/elecstate_pw.cpp

Lines changed: 3 additions & 3 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
{
@@ -222,7 +222,7 @@ void ElecStatePW<T, Device>::rhoBandK(const psi::Psi<T, Device>& psi)
222222
j,
223223
npw,
224224
this->basis->npwk_max,
225-
static_cast<Real>(get_ucell_tpiba()),
225+
static_cast<Real>(ucell->tpiba),
226226
this->basis->template get_gcar_data<Real>(),
227227
this->basis->template get_kvec_c_data<Real>(),
228228
&psi(ibnd, 0),

source/module_elecstate/elecstate_pw_cal_tau.cpp

Lines changed: 2 additions & 2 deletions
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++)
@@ -38,7 +38,7 @@ void ElecStatePW<T, Device>::cal_tau(const psi::Psi<T, Device>& psi)
3838
j,
3939
npw,
4040
this->basis->npwk_max,
41-
static_cast<Real>(get_ucell_tpiba()),
41+
static_cast<Real>(ucell->tpiba),
4242
this->basis->template get_gcar_data<Real>(),
4343
this->basis->template get_kvec_c_data<Real>(),
4444
&psi(ibnd, 0),

source/module_elecstate/magnetism.cpp

Lines changed: 9 additions & 5 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);
@@ -65,8 +69,8 @@ void Magnetism::compute_magnetization(const int& nrxx, const int& nxyz, const do
6569
Parallel_Reduce::reduce_pool(this->tot_magnetization_nc, 3);
6670
Parallel_Reduce::reduce_pool(this->abs_magnetization);
6771
#endif
68-
for(int i=0;i<3;i++)this->tot_magnetization_nc[i] *= elecstate::get_ucell_omega() / nxyz;
69-
this->abs_magnetization *= elecstate::get_ucell_omega() / nxyz;
72+
for(int i=0;i<3;i++)this->tot_magnetization_nc[i] *= omega/ nxyz;
73+
this->abs_magnetization *= omega/ nxyz;
7074
GlobalV::ofs_running<<"total magnetism (Bohr mag/cell)"<<'\t'<<this->tot_magnetization_nc[0]<<'\t'<<this->tot_magnetization_nc[1]<<'\t'<<this->tot_magnetization_nc[2]<<'\n';
7175
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"absolute magnetism (Bohr mag/cell)",this->abs_magnetization);
7276
}

0 commit comments

Comments
 (0)