Skip to content

Commit 55d8006

Browse files
author
abacus_fixer
committed
refactor(dftu): pass pv and gamma_only_local as function parameters
- Replace implicit Plus_U member access with an explicit `const Parallel_Orbitals* pv` argument for all module_dftu functions (pot_onsite_*, cal_occ_mat_*, cal_eff_pot_mat_R_*, pot_uterm_*, cal_nlm_all, cal_occ/cal_HR_IJR/cal_force_IJR/cal_stress_IJR, folding) - Thread the removed gamma_only_local member through explicit arguments: esolver_ks_lcao -> finish_dftu_lcao -> DFTU_LCAO::cal_occ_mat -> Plus_U::cal_occ_mat_k -> folding_matrix_k_new - Update call sites: spar_u.cpp, force_stress_lcao.cpp, lcao_set.cpp, setup_dftu_lcao.{h,cpp}, esolver_ks_lcao.cpp, dftu_lcao_op_legacy.cpp
1 parent d54aa8f commit 55d8006

19 files changed

Lines changed: 183 additions & 161 deletions

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
506506
const std::vector<std::vector<TK>>& dm_vec = this->dmat.dm->get_DMK_vector();
507507

508508
// 1) calculate the local occupation number matrix and energy correction in DFT+U
509-
finish_dftu_lcao<TK>(iter, conv_esolver, this->inp_->dft_plus_u, this->inp_->out_chg[0], &(this->dftu), ucell, dm_vec, this->kv, this->p_chgmix->get_mixing_beta(), hamilt_lcao, PARAM.globalv.global_out_dir, this->inp_->nspin, PARAM.globalv.npol);
509+
finish_dftu_lcao<TK>(iter, conv_esolver, this->inp_->dft_plus_u, this->inp_->out_chg[0], &(this->dftu), ucell, dm_vec, this->kv, this->p_chgmix->get_mixing_beta(), hamilt_lcao, PARAM.globalv.global_out_dir, this->inp_->nspin, PARAM.globalv.npol, PARAM.globalv.gamma_only_local);
510510

511511
// mohan add 2025-11: push DFT+U energy from Plus_U instance to ElecState.
512512
// Covers both dft_plus_u==1 (new method, energy accumulated by DFTU::contributeHR

source/source_lcao/force_stress_lcao.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
457457
std::vector<std::vector<double>>* dmk_d = nullptr;
458458
std::vector<std::vector<std::complex<double>>>* dmk_c = nullptr;
459459
assign_dmk_ptr<T>(dmat.dm, dmk_d, dmk_c, PARAM.globalv.gamma_only_local);
460-
DFTU_LCAO::force_stress(dftu, isforce, isstress, ucell, gd, dmk_d, dmk_c, pv, fsr_dftu, force_u, stress_u, kv, PARAM.globalv.npol);
460+
DFTU_LCAO::force_stress(dftu, isforce, isstress, ucell, gd, dmk_d, dmk_c, pv, fsr_dftu, force_u, stress_u, kv, PARAM.globalv.npol, PARAM.globalv.gamma_only_local);
461461
}
462462
else
463463
{

source/source_lcao/lcao_set.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ void LCAO_domain::set_pot(
8888
PARAM.globalv.global_out_dir,
8989
inp.init_chg,
9090
pv.get_global_row_size(),
91-
PARAM.globalv.gamma_only_local,
9291
inp.ks_solver,
9392
inp.device,
9493
inp.kpar,

source/source_lcao/module_dftu/dftu_force.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ void force_stress(Plus_U& dftu,
2525
ModuleBase::matrix& force_dftu,
2626
ModuleBase::matrix& stress_dftu,
2727
const K_Vectors& kv,
28-
const int npol)
28+
const int npol,
29+
const bool gamma_only_local)
2930
{
3031
ModuleBase::TITLE("DFTU_LCAO", "force_stress");
3132
ModuleBase::timer::start("DFTU_LCAO", "force_stress");
@@ -37,7 +38,7 @@ void force_stress(Plus_U& dftu,
3738
// fsr_dftu is created without allocation), we fail early with a clear
3839
// message instead of letting pdgemm_ dereference nullptr and crash.
3940
// See force_stress_lcao.cpp for the historical background.
40-
if (dftu.is_gamma_only_local())
41+
if (gamma_only_local)
4142
{
4243
if (cal_force
4344
&& (fsr.DSloc_x == nullptr || fsr.DSloc_y == nullptr || fsr.DSloc_z == nullptr))
@@ -100,7 +101,7 @@ void force_stress(Plus_U& dftu,
100101
stress_dftu.zero_out();
101102
}
102103

103-
if (dftu.is_gamma_only_local())
104+
if (gamma_only_local)
104105
{
105106
const char transN = 'N';
106107
const char transT = 'T';
@@ -117,7 +118,7 @@ void force_stress(Plus_U& dftu,
117118

118119
double* pot_onsite = new double[pv.nloc];
119120

120-
dftu.pot_onsite_real(spin, false, pot_onsite, npol);
121+
dftu.pot_onsite_real(&pv, spin, false, pot_onsite, npol);
121122

122123
#ifdef __MPI
123124
ScalapackConnector::gemm(transT, transN, nlocal, nlocal, nlocal,
@@ -163,7 +164,7 @@ void force_stress(Plus_U& dftu,
163164

164165
std::complex<double>* pot_onsite = new std::complex<double>[pv.nloc];
165166

166-
dftu.pot_onsite_complex(spin, false, pot_onsite, npol);
167+
dftu.pot_onsite_complex(&pv, spin, false, pot_onsite, npol);
167168

168169

169170
#ifdef __MPI

source/source_lcao/module_dftu/dftu_force.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ void force_stress(Plus_U& dftu,
4141
ModuleBase::matrix& force_dftu,
4242
ModuleBase::matrix& stress_dftu,
4343
const K_Vectors& kv,
44-
const int npol);
44+
const int npol,
45+
const bool gamma_only_local);
4546

4647
/// @brief Force contribution at a k-point (multik path).
4748
void cal_force_k(int nlocal,

source/source_lcao/module_dftu/dftu_fs.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void DFTU<OperatorLCAO<TK, TR>>::cal_force_stress(const bool cal_force,
3333
// begin the calculation of force and stress
3434
ModuleBase::timer::start("DFTU", "cal_force_stress");
3535

36-
const Parallel_Orbitals* paraV = dmR_tmp[0]->get_paraV();
36+
const Parallel_Orbitals* pv = dmR_tmp[0]->get_paraV();
3737
const int npol = this->ucell->get_npol();
3838
std::vector<double> stress_tmp(6, 0);
3939
if (cal_force)
@@ -89,8 +89,8 @@ void DFTU<OperatorLCAO<TK, TR>>::cal_force_stress(const bool cal_force,
8989
const ModuleBase::Vector3<double>& tau1 = adjs.adjacent_tau[ad];
9090
const Atom* atom1 = &ucell->atoms[T1];
9191

92-
auto all_indexes = paraV->get_indexes_row(iat1);
93-
auto col_indexes = paraV->get_indexes_col(iat1);
92+
auto all_indexes = pv->get_indexes_row(iat1);
93+
auto col_indexes = pv->get_indexes_col(iat1);
9494
// insert col_indexes into all_indexes to get universal set with no repeat elements
9595
all_indexes.insert(all_indexes.end(), col_indexes.begin(), col_indexes.end());
9696
std::sort(all_indexes.begin(), all_indexes.end());
@@ -187,7 +187,7 @@ void DFTU<OperatorLCAO<TK, TR>>::cal_force_stress(const bool cal_force,
187187
if (cal_force) {
188188
this->cal_force_IJR(iat1,
189189
iat2,
190-
paraV,
190+
pv,
191191
nlm_tot[ad1],
192192
nlm_tot[ad2],
193193
pot_onsite,
@@ -201,7 +201,7 @@ void DFTU<OperatorLCAO<TK, TR>>::cal_force_stress(const bool cal_force,
201201
if (cal_stress) {
202202
this->cal_stress_IJR(iat1,
203203
iat2,
204-
paraV,
204+
pv,
205205
nlm_tot[ad1],
206206
nlm_tot[ad2],
207207
pot_onsite,
@@ -272,7 +272,7 @@ void DFTU<OperatorLCAO<TK, TR>>::cal_force_stress(const bool cal_force,
272272
template <typename TK, typename TR>
273273
void DFTU<OperatorLCAO<TK, TR>>::cal_force_IJR(const int& iat1,
274274
const int& iat2,
275-
const Parallel_Orbitals* paraV,
275+
const Parallel_Orbitals* pv,
276276
const std::unordered_map<int, std::vector<double>>& nlm1_all,
277277
const std::unordered_map<int, std::vector<double>>& nlm2_all,
278278
const std::vector<double>& pot_onsite_in,
@@ -288,8 +288,8 @@ void DFTU<OperatorLCAO<TK, TR>>::cal_force_IJR(const int& iat1,
288288
// ---------------------------------------------
289289
// calculate the Nonlocal matrix for each pair of orbitals
290290
// ---------------------------------------------
291-
auto row_indexes = paraV->get_indexes_row(iat1);
292-
auto col_indexes = paraV->get_indexes_col(iat2);
291+
auto row_indexes = pv->get_indexes_row(iat1);
292+
auto col_indexes = pv->get_indexes_col(iat2);
293293
const int m_size = int(sqrt(pot_onsite_in.size() / nspin));
294294
const int m_size2 = m_size * m_size;
295295

@@ -349,7 +349,7 @@ void DFTU<OperatorLCAO<TK, TR>>::cal_force_IJR(const int& iat1,
349349
template <typename TK, typename TR>
350350
void DFTU<OperatorLCAO<TK, TR>>::cal_stress_IJR(const int& iat1,
351351
const int& iat2,
352-
const Parallel_Orbitals* paraV,
352+
const Parallel_Orbitals* pv,
353353
const std::unordered_map<int, std::vector<double>>& nlm1_all,
354354
const std::unordered_map<int, std::vector<double>>& nlm2_all,
355355
const std::vector<double>& pot_onsite_in,
@@ -366,8 +366,8 @@ void DFTU<OperatorLCAO<TK, TR>>::cal_stress_IJR(const int& iat1,
366366
// ---------------------------------------------
367367
// calculate the Nonlocal matrix for each pair of orbitals
368368
// ---------------------------------------------
369-
auto row_indexes = paraV->get_indexes_row(iat1);
370-
auto col_indexes = paraV->get_indexes_col(iat2);
369+
auto row_indexes = pv->get_indexes_row(iat1);
370+
auto col_indexes = pv->get_indexes_col(iat2);
371371
const int m_size = int(sqrt(pot_onsite_in.size() / nspin));
372372
const int m_size2 = m_size * m_size;
373373

@@ -438,7 +438,7 @@ template void DFTU<OperatorLCAO<std::complex<double>, std::complex<double>>>::ca
438438

439439
template void DFTU<OperatorLCAO<double, double>>::cal_force_IJR(
440440
const int& iat1, const int& iat2,
441-
const Parallel_Orbitals* paraV,
441+
const Parallel_Orbitals* pv,
442442
const std::unordered_map<int, std::vector<double>>& nlm1_all,
443443
const std::unordered_map<int, std::vector<double>>& nlm2_all,
444444
const std::vector<double>& pot_onsite_in,
@@ -447,7 +447,7 @@ template void DFTU<OperatorLCAO<double, double>>::cal_force_IJR(
447447
double* force1, double* force2);
448448
template void DFTU<OperatorLCAO<std::complex<double>, double>>::cal_force_IJR(
449449
const int& iat1, const int& iat2,
450-
const Parallel_Orbitals* paraV,
450+
const Parallel_Orbitals* pv,
451451
const std::unordered_map<int, std::vector<double>>& nlm1_all,
452452
const std::unordered_map<int, std::vector<double>>& nlm2_all,
453453
const std::vector<double>& pot_onsite_in,
@@ -456,7 +456,7 @@ template void DFTU<OperatorLCAO<std::complex<double>, double>>::cal_force_IJR(
456456
double* force1, double* force2);
457457
template void DFTU<OperatorLCAO<std::complex<double>, std::complex<double>>>::cal_force_IJR(
458458
const int& iat1, const int& iat2,
459-
const Parallel_Orbitals* paraV,
459+
const Parallel_Orbitals* pv,
460460
const std::unordered_map<int, std::vector<double>>& nlm1_all,
461461
const std::unordered_map<int, std::vector<double>>& nlm2_all,
462462
const std::vector<double>& pot_onsite_in,
@@ -466,7 +466,7 @@ template void DFTU<OperatorLCAO<std::complex<double>, std::complex<double>>>::ca
466466

467467
template void DFTU<OperatorLCAO<double, double>>::cal_stress_IJR(
468468
const int& iat1, const int& iat2,
469-
const Parallel_Orbitals* paraV,
469+
const Parallel_Orbitals* pv,
470470
const std::unordered_map<int, std::vector<double>>& nlm1_all,
471471
const std::unordered_map<int, std::vector<double>>& nlm2_all,
472472
const std::vector<double>& pot_onsite_in,
@@ -477,7 +477,7 @@ template void DFTU<OperatorLCAO<double, double>>::cal_stress_IJR(
477477
double* stress);
478478
template void DFTU<OperatorLCAO<std::complex<double>, double>>::cal_stress_IJR(
479479
const int& iat1, const int& iat2,
480-
const Parallel_Orbitals* paraV,
480+
const Parallel_Orbitals* pv,
481481
const std::unordered_map<int, std::vector<double>>& nlm1_all,
482482
const std::unordered_map<int, std::vector<double>>& nlm2_all,
483483
const std::vector<double>& pot_onsite_in,
@@ -488,7 +488,7 @@ template void DFTU<OperatorLCAO<std::complex<double>, double>>::cal_stress_IJR(
488488
double* stress);
489489
template void DFTU<OperatorLCAO<std::complex<double>, std::complex<double>>>::cal_stress_IJR(
490490
const int& iat1, const int& iat2,
491-
const Parallel_Orbitals* paraV,
491+
const Parallel_Orbitals* pv,
492492
const std::unordered_map<int, std::vector<double>>& nlm1_all,
493493
const std::unordered_map<int, std::vector<double>>& nlm2_all,
494494
const std::vector<double>& pot_onsite_in,

0 commit comments

Comments
 (0)