Skip to content

Commit a9c12d2

Browse files
author
abacus_fixer
committed
refactor(module_dftu): drop Plus_U npol/nlocal/ks_solver members
Remove the Plus_U private members `npol`, `nlocal`, `ks_solver` and their read-only accessors `get_npol()`, `get_nlocal()`, `get_ks_solver()`. All read sites now take these values from sources already in scope: - nlocal: Parallel_Orbitals::get_global_row_size() (matches the GEMM global matrix dimension the member was initialized from in init()) - npol: UnitCell::get_npol(), or the existing npol parameter of DFTU_LCAO::force_stress (which previously shadowed it with dftu) - ks_solver: PARAM.inp.ks_solver (dftu_force.cpp now includes source_io/module_parameter/parameter.h) No function signature changes; the PW path is untouched (Plus_U_Base::init_base uses its local parameter, not these members). Pure refactor, no behavior change. No INPUT parameter affected. Verification: - make -j4 (full build): 100%, linked abacus_basic_para - python3 tools/03_code_analysis/agent_governance_check.py --staged: no findings - grep: no residual Plus_U npol/nlocal/ks_solver member or accessor uses Signed-off-by: Abacus Agent <abacus@example.com>
1 parent 374204e commit a9c12d2

6 files changed

Lines changed: 21 additions & 27 deletions

File tree

source/source_lcao/module_dftu/dftu_force.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "source_base/global_function.h"
77
#include "source_base/module_external/scalapack_connector.h"
88
#include "source_base/parallel_reduce.h"
9+
#include "source_io/module_parameter/parameter.h"
910
#include "source_base/timer.h"
1011

1112
#include <complex>
@@ -84,14 +85,14 @@ void force_stress(Plus_U& dftu,
8485
// validation are column-major today; abort loudly instead of silently
8586
// producing wrong forces/stresses if that assumption ever changes.
8687
if ((cal_force || cal_stress)
87-
&& !ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(dftu.get_ks_solver()))
88+
&& !ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.inp.ks_solver))
8889
{
8990
ModuleBase::WARNING_QUIT("DFTU_LCAO::force_stress",
9091
"non column-major ks_solver is not supported for DFT+U force/stress; "
9192
"the folded matrix layout assumption would be violated");
9293
}
9394

94-
const int nlocal = dftu.get_nlocal();
95+
const int nlocal = pv.get_global_row_size();
9596

9697
if (cal_force)
9798
{
@@ -133,16 +134,16 @@ void force_stress(Plus_U& dftu,
133134

134135
if (cal_force)
135136
{
136-
cal_force_gamma(dftu.get_nlocal(), dftu.get_npol(),
137+
cal_force_gamma(nlocal, npol,
137138
dftu.get_orbital_corr_vec(), dftu.get_iatlnmipol2iwt(),
138139
ucell, &rho_pot_onsite[0], pv,
139140
fsr.DSloc_x, fsr.DSloc_y, fsr.DSloc_z, force_dftu);
140141
}
141142

142143
if (cal_stress)
143144
{
144-
cal_stress_gamma(dftu.get_nlocal(), dftu.get_npol(),
145-
dftu.get_ks_solver(), dftu.get_orb_cutoff(),
145+
cal_stress_gamma(nlocal, npol,
146+
PARAM.inp.ks_solver, dftu.get_orb_cutoff(),
146147
ucell, pv, &gd,
147148
fsr.DSloc_x, fsr.DSloc_y, fsr.DSloc_z, fsr.DH_r,
148149
&rho_pot_onsite[0], stress_dftu);
@@ -179,15 +180,15 @@ void force_stress(Plus_U& dftu,
179180

180181
if (cal_force)
181182
{
182-
cal_force_k(dftu.get_nlocal(), dftu.get_npol(),
183-
dftu.get_ks_solver(), dftu.get_orb_cutoff(),
183+
cal_force_k(nlocal, npol,
184+
PARAM.inp.ks_solver, dftu.get_orb_cutoff(),
184185
dftu.get_orbital_corr_vec(), dftu.get_iatlnmipol2iwt(),
185186
ucell, gd, fsr, pv, ik, &rho_pot_onsite[0], force_dftu, kv.kvec_d[ik]);
186187
}
187188
if (cal_stress)
188189
{
189-
cal_stress_k(dftu.get_nlocal(), dftu.get_npol(),
190-
dftu.get_ks_solver(), dftu.get_orb_cutoff(),
190+
cal_stress_k(nlocal, npol,
191+
PARAM.inp.ks_solver, dftu.get_orb_cutoff(),
191192
ucell, gd, fsr, pv, ik, &rho_pot_onsite[0], stress_dftu, kv.kvec_d[ik]);
192193
}
193194
} // ik

source/source_lcao/module_dftu/dftu_hamilt.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void pot_uterm_complex(Plus_U& dftu,
2727

2828
int spin = isk[ik];
2929

30-
const int nlocal = dftu.get_nlocal();
30+
const int nlocal = pv->get_global_row_size();
3131
ModuleBase::GlobalFunc::ZEROS(pot_uterm, pv->nloc);
3232

3333
//=============================================================
@@ -87,7 +87,7 @@ void pot_uterm_real(Plus_U& dftu,
8787

8888
int spin = isk[ik];
8989

90-
const int nlocal = dftu.get_nlocal();
90+
const int nlocal = pv->get_global_row_size();
9191
ModuleBase::GlobalFunc::ZEROS(pot_uterm, pv->nloc);
9292

9393
//=============================================================
@@ -132,21 +132,22 @@ void Plus_U::cal_eff_pot_mat_R_double(const UnitCell& ucell, const Parallel_Orbi
132132
const char transN = 'N', transT = 'T';
133133
const int one_int = 1;
134134
const double alpha = 1.0, beta = 0.0, one = 1.0, half = 0.5;
135+
const int nlocal = pv->get_global_row_size();
135136

136137
std::vector<double> pot_onsite(pv->nloc);
137138
DFTU_LCAO::pot_onsite_real(*this, ucell, pv, ispin, true, &pot_onsite[0], npol);
138139

139140
#ifdef __MPI
140141
ScalapackConnector::gemm(transN, transN,
141-
this->nlocal, this->nlocal, this->nlocal,
142+
nlocal, nlocal, nlocal,
142143
half,
143144
ModuleBase::GlobalFunc::VECTOR_TO_PTR(pot_onsite), 1, 1, pv->desc,
144145
SR, 1, 1, pv->desc,
145146
beta,
146147
HR, 1, 1, pv->desc);
147148

148149
ScalapackConnector::gemm(transN, transN,
149-
this->nlocal, this->nlocal, this->nlocal,
150+
nlocal, nlocal, nlocal,
150151
half,
151152
SR, 1, 1, pv->desc,
152153
ModuleBase::GlobalFunc::VECTOR_TO_PTR(pot_onsite), 1, 1, pv->desc,
@@ -162,21 +163,22 @@ void Plus_U::cal_eff_pot_mat_R_complex_double(const UnitCell& ucell, const Paral
162163
const char transN = 'N', transT = 'T';
163164
const int one_int = 1;
164165
const std::complex<double> zero = 0.0, one = 1.0, half = 0.5;
166+
const int nlocal = pv->get_global_row_size();
165167

166168
std::vector<std::complex<double>> pot_onsite(pv->nloc);
167169
DFTU_LCAO::pot_onsite_complex(*this, ucell, pv, ispin, true, &pot_onsite[0], npol);
168170

169171
#ifdef __MPI
170172
ScalapackConnector::gemm(transN, transN,
171-
this->nlocal, this->nlocal, this->nlocal,
173+
nlocal, nlocal, nlocal,
172174
half,
173175
ModuleBase::GlobalFunc::VECTOR_TO_PTR(pot_onsite), one_int, one_int, pv->desc,
174176
SR, one_int, one_int, pv->desc,
175177
zero,
176178
HR, one_int, one_int, pv->desc);
177179

178180
ScalapackConnector::gemm(transN, transN,
179-
this->nlocal, this->nlocal, this->nlocal,
181+
nlocal, nlocal, nlocal,
180182
half,
181183
SR, one_int, one_int, pv->desc,
182184
ModuleBase::GlobalFunc::VECTOR_TO_PTR(pot_onsite), one_int, one_int, pv->desc,

source/source_lcao/module_dftu/dftu_lcao.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ void Plus_U::init(UnitCell& cell,
3939
ModuleBase::TITLE("Plus_U", "init");
4040

4141
this->yukawa_lambda = yukawa_lambda;
42-
this->npol = npol;
43-
this->nlocal = nlocal;
44-
this->ks_solver = ks_solver;
4542

4643
#ifdef __LCAO
4744
ptr_orb_ = orb;

source/source_lcao/module_dftu/dftu_lcao.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class Plus_U : public Plus_U_Base
5050
private:
5151

5252
double yukawa_lambda = 0.0;
53-
int npol = 1;
54-
int nlocal = 0;
55-
std::string ks_solver;
5653

5754
#ifdef __LCAO
5855
const LCAO_Orbitals* ptr_orb_ = nullptr;
@@ -92,9 +89,6 @@ class Plus_U : public Plus_U_Base
9289
void set_dmr(const elecstate::DensityMatrix<std::complex<double>, double>* dm_in_dftu_cd);
9390

9491
/// read-only accessors for state needed by DFTU_LCAO free functions
95-
int get_npol() const { return npol; }
96-
int get_nlocal() const { return nlocal; }
97-
const std::string& get_ks_solver() const { return ks_solver; }
9892
const std::vector<double>& get_orb_cutoff() const { return orb_cutoff_; }
9993
double get_yukawa_lambda() const { return yukawa_lambda; }
10094
const LCAO_Orbitals* get_ptr_orb() const { return ptr_orb_; }

source/source_lcao/module_dftu/dftu_lcao_energy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void DFTU_LCAO::cal_energy_correction(Plus_U& dftu, const UnitCell& ucell)
2424
// read from the global PARAM.inp.nspin instead of a Plus_U member;
2525
// the member indirection is being removed during the refactor
2626
const int nspin = PARAM.inp.nspin;
27-
const int npol = dftu.get_npol();
27+
const int npol = ucell.get_npol();
2828

2929
for (int T = 0; T < ucell.ntype; T++)
3030
{

source/source_lcao/module_dftu/dftu_lcao_occ.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ void cal_occ_mat(const Parallel_Orbitals* pv,
586586
{
587587
bool occ_mat_initialized = dftu.get_occ_mat_initialized();
588588
DFTU_LCAO::cal_occ_mat_gamma(pv, iter, ucell, dm, mixing_beta, p_ham, nspin,
589-
dftu.get_npol(), dftu.get_nlocal(), dftu.get_iatlnmipol2iwt(),
589+
ucell.get_npol(), pv->get_global_row_size(), dftu.get_iatlnmipol2iwt(),
590590
dftu.get_orbital_corr_vec(),
591591
dftu.get_occ_mat_data(), dftu.get_occ_mat_save_data(),
592592
occ_mat_initialized);
@@ -608,7 +608,7 @@ void cal_occ_mat(const Parallel_Orbitals* pv,
608608
{
609609
bool occ_mat_initialized = dftu.get_occ_mat_initialized();
610610
DFTU_LCAO::cal_occ_mat_k(pv, iter, ucell, dm, kv, mixing_beta, p_ham, gamma_only_local, nspin,
611-
dftu.get_npol(), dftu.get_nlocal(), dftu.get_ks_solver(), dftu.get_iatlnmipol2iwt(),
611+
ucell.get_npol(), pv->get_global_row_size(), PARAM.inp.ks_solver, dftu.get_iatlnmipol2iwt(),
612612
dftu.get_orbital_corr_vec(),
613613
dftu.get_occ_mat_data(), dftu.get_occ_mat_save_data(),
614614
occ_mat_initialized);

0 commit comments

Comments
 (0)