Skip to content

Commit 4afb72a

Browse files
author
abacus_fixer
committed
refactor(dftu): rename flat/state funcs + fix initialed_locale spelling (Step 3/5)
Rename Plus_U_Base flat-conversion and state-management APIs: get_locale_flat -> get_occ_mat_flat set_locale_flat -> set_occ_mat_flat is_locale_initialized -> is_occ_mat_initialized mark_locale_initialized-> mark_occ_mat_initialized mark_locale_dirty -> mark_occ_mat_dirty Also fix a long-standing spelling bug: the member variable bool initialed_locale was renamed to bool occ_mat_initialized (initialed -> initialized + naming aligned with occ_mat_* convention). Header declarations updated in dftu_base.h, plus definitions and all call sites updated across: * dftu_base.cpp (defs + mark_locale_initialized calls in init_base) * dftu_lcao.cpp (~16 call sites + doc comments) * dftu_fs.cpp (1 get_occ_mat_flat call) * dftu_hamilt.cpp (2 is_occ_mat_initialized calls) * setup_dftu_lcao.cpp (1 mark_occ_mat_initialized call) * dftu_occup.cpp (is/mark calls in cal_occup_m_*) * dftu.cpp (1 is_occ_mat_initialized call in cal_energy_correction) 8 files changed, 36 insertions(+), 36 deletions(-).
1 parent 66b2fcd commit 4afb72a

8 files changed

Lines changed: 36 additions & 36 deletions

File tree

source/source_lcao/module_dftu/dftu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void Plus_U::cal_energy_correction(const UnitCell& ucell,
105105
{
106106
ModuleBase::TITLE("Plus_U", "cal_energy_correction");
107107
ModuleBase::timer::start("Plus_U", "cal_energy_correction");
108-
if (!is_locale_initialized())
108+
if (!is_occ_mat_initialized())
109109
{
110110
ModuleBase::timer::end("Plus_U", "cal_energy_correction");
111111
return;

source/source_lcao/module_dftu/dftu_hamilt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void Plus_U::cal_eff_pot_mat_complex(const int ik,
1212
const int npol)
1313
{
1414
ModuleBase::TITLE("Plus_U", "cal_eff_pot_c");
15-
if (!is_locale_initialized())
15+
if (!is_occ_mat_initialized())
1616
{
1717
return;
1818
}
@@ -65,7 +65,7 @@ void Plus_U::cal_eff_pot_mat_complex(const int ik,
6565
void Plus_U::cal_eff_pot_mat_real(const int ik, double* eff_pot, const std::vector<int>& isk, const double* sk, const int npol)
6666
{
6767
ModuleBase::TITLE("Plus_U", "cal_eff_pot_r");
68-
if (!is_locale_initialized())
68+
if (!is_occ_mat_initialized())
6969
{
7070
return;
7171
}

source/source_lcao/module_dftu/dftu_occup.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ void Plus_U::cal_occup_m_k(const int iter,
236236
} // end ia
237237
} // end it
238238

239-
if(is_mixing_enabled() && is_locale_initialized())
239+
if(is_mixing_enabled() && is_occ_mat_initialized())
240240
{
241241
this->mix_locale(ucell,mixing_beta);
242242
}
243243

244-
mark_locale_initialized();
244+
mark_occ_mat_initialized();
245245
ModuleBase::timer::end("Plus_U", "cal_occup_m_k");
246246
return;
247247
}
@@ -393,12 +393,12 @@ void Plus_U::cal_occup_m_gamma(const int iter,
393393
} // it
394394
} // is
395395

396-
if(is_mixing_enabled() && is_locale_initialized())
396+
if(is_mixing_enabled() && is_occ_mat_initialized())
397397
{
398398
this->mix_locale(ucell,mixing_beta);
399399
}
400400

401-
mark_locale_initialized();
401+
mark_occ_mat_initialized();
402402
ModuleBase::timer::end("Plus_U", "cal_occup_m_gamma");
403403
return;
404404
}

source/source_lcao/module_operator_lcao/dftu_fs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void DFTU<OperatorLCAO<TK, TR>>::cal_force_stress(const bool cal_force,
138138
}
139139
// first iteration to calculate occupation matrix
140140
std::vector<double> occ(tlp1 * tlp1 * this->nspin, 0);
141-
this->dftu->get_locale_flat(iat0, target_L, occ);
141+
this->dftu->get_occ_mat_flat(iat0, target_L, occ);
142142

143143
// calculate VU
144144
const double u_value = this->dftu->U[T0];

source/source_lcao/module_operator_lcao/dftu_lcao.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,25 @@ void hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::cal_nlm_all(const Parallel_Orbi
177177
* @brief Contribute DFT+U Hamiltonian to real-space HR matrix
178178
*
179179
* @details This function handles different scenarios based on:
180-
* 1. Whether locale (occupation matrix) is read from file (is_locale_initialized)
180+
* 1. Whether locale (occupation matrix) is read from file (is_occ_mat_initialized)
181181
* 2. Spin configuration (nspin=1, 2, or 4)
182182
* 3. SCF iteration stage (first vs subsequent iterations)
183183
*
184-
* Case 1: Locale NOT initialized (!is_locale_initialized)
184+
* Case 1: Locale NOT initialized (!is_occ_mat_initialized)
185185
* - First electronic iteration: calculates occupation matrix from density matrix (DMR)
186186
* * Uses get_dmr(current_spin) to get real-space density matrix
187187
* * Accumulates contributions from all atom pairs via cal_occ()
188188
* * Performs MPI reduction to sum occ across processes
189-
* * Stores result via set_locale_flat() for use in VU calculation
189+
* * Stores result via set_occ_mat_flat() for use in VU calculation
190190
* * For nspin=1: occ is scaled by 0.5 (since only one spin channel computed)
191191
* - Subsequent iterations: locale is computed fresh each iteration from updated DMR
192192
*
193-
* Case 2: Locale IS initialized (is_locale_initialized, i.e., read from dm_onsite.txt file)
193+
* Case 2: Locale IS initialized (is_occ_mat_initialized, i.e., read from dm_onsite.txt file)
194194
* - First electronic iteration: uses pre-read locale directly without DMR calculation
195195
* * Skips DMR-based occ calculation entirely
196196
* * Reads locale from stored data via get_locale()
197197
* * Different indexing for nspin=4 vs nspin=1/2 (see below)
198-
* - After first iteration: mark_locale_dirty() is called to force recomputation
198+
* - After first iteration: mark_occ_mat_dirty() is called to force recomputation
199199
*
200200
* Spin configurations:
201201
* nspin=1 (non-spin-polarized):
@@ -206,14 +206,14 @@ void hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::cal_nlm_all(const Parallel_Orbi
206206
* nspin=2 (collinear spin-polarized):
207207
* - Two separate spin channels (spin-up: 0, spin-down: 1)
208208
* - current_spin toggles between 0 and 1 across iterations
209-
* - mark_locale_dirty() called when current_spin == 1 (last spin)
209+
* - mark_occ_mat_dirty() called when current_spin == 1 (last spin)
210210
* - HR accumulated separately for each spin
211211
*
212212
* nspin=4 (non-collinear/SOC):
213213
* - Single 4x4 Pauli matrix representation per atom
214214
* - occ has 4*(2l+1)^2 elements (spin_fold=4)
215215
* - get_locale uses spin=0, ipol indices for Pauli blocks
216-
* - mark_locale_dirty() always called (current_spin check always true)
216+
* - mark_occ_mat_dirty() always called (current_spin check always true)
217217
* - No current_spin toggling (all spins handled simultaneously)
218218
*
219219
* @warning THREAD SAFETY: cal_HR_IJR() updates shared HR matrix entries.
@@ -228,10 +228,10 @@ void hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
228228
ModuleBase::TITLE("DFTU", "contributeHR");
229229
// Early exit conditions:
230230
// - get_dmr(0) == nullptr: DMR not available (typical in first iteration without file input)
231-
// - !is_locale_initialized(): locale not read from file AND not yet computed from DMR
231+
// - !is_occ_mat_initialized(): locale not read from file AND not yet computed from DMR
232232
// When both true, skip DFT+U contribution entirely (first iteration, no file input)
233233
const bool dmr_null = (this->dftu->get_dmr(0) == nullptr);
234-
const bool locale_not_init = !this->dftu->is_locale_initialized();
234+
const bool locale_not_init = !this->dftu->is_occ_mat_initialized();
235235

236236
if (dmr_null && locale_not_init)
237237
{
@@ -280,10 +280,10 @@ void hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
280280
// BRANCH 1: Locale NOT initialized (compute from DMR)
281281
// ============================================================
282282
// This branch is taken when:
283-
// - is_locale_initialized() == false (no file read or omc != 0)
283+
// - is_occ_mat_initialized() == false (no file read or omc != 0)
284284
// - DMR is available (get_dmr() != nullptr)
285285
// Typical scenario: normal SCF iterations after first step
286-
if (!this->dftu->is_locale_initialized())
286+
if (!this->dftu->is_occ_mat_initialized())
287287
{
288288
// TODO: UNSAFE - get_dmr(current_spin) assumes DMR has correct spin indexing.
289289
// For nspin=2, current_spin must be correctly toggled (0 then 1).
@@ -328,13 +328,13 @@ void hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
328328
{
329329
for (auto& v : occ) { v *= 0.5; }
330330
}
331-
this->dftu->set_locale_flat(iat0, target_L, this->current_spin, occ);
331+
this->dftu->set_occ_mat_flat(iat0, target_L, this->current_spin, occ);
332332
}
333333
// ============================================================
334334
// BRANCH 2: Locale IS initialized (use pre-read data)
335335
// ============================================================
336336
// This branch is taken when:
337-
// - is_locale_initialized() == true (locale read from dm_onsite.txt file)
337+
// - is_occ_mat_initialized() == true (locale read from dm_onsite.txt file)
338338
// - OR omc != 0 (occupation matrix control with dm_onsite_ini.txt)
339339
// Typical scenario: first SCF iteration with file input, or restart calculation
340340
else
@@ -346,8 +346,8 @@ void hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
346346
{
347347
// For nspin=4, locale is stored as 4 stacked tlp1^2 blocks
348348
// at offsets 0, tlp1^2, 2*tlp1^2, 3*tlp1^2 for the 4 Pauli channels.
349-
// Use get_locale_flat to read the stacked blocks directly
350-
this->dftu->get_locale_flat(iat0, target_L, occ);
349+
// Use get_occ_mat_flat to read the stacked blocks directly
350+
this->dftu->get_occ_mat_flat(iat0, target_L, occ);
351351
}
352352
// nspin=1 or nspin=2: Collinear spin case
353353
// Locale stored separately for each spin channel
@@ -447,7 +447,7 @@ void hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
447447
// TODO: This logic is confusing. Consider explicit variable like `is_last_spin_channel`.
448448
if (this->current_spin == this->nspin - 1 || this->nspin == 4)
449449
{
450-
this->dftu->mark_locale_dirty();
450+
this->dftu->mark_occ_mat_dirty();
451451
}
452452

453453
// 8. Spin channel toggling for nspin=2

source/source_lcao/setup_dftu_lcao.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void finish_dftu_lcao(const int iter,
7373
/// use the converged occupation matrix for next MD/Relax SCF calculation
7474
if (conv_esolver)
7575
{
76-
dftu_ptr->mark_locale_initialized();
76+
dftu_ptr->mark_occ_mat_initialized();
7777
}
7878
}
7979

source/source_pw/module_pwdft/dftu_base.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ void Plus_U_Base::init_base(UnitCell& cell,
238238
this->local_occup_bcast(cell, nspin, npol);
239239
#endif
240240

241-
mark_locale_initialized();
241+
mark_occ_mat_initialized();
242242
this->copy_locale(cell);
243243
}
244244
else
@@ -251,7 +251,7 @@ void Plus_U_Base::init_base(UnitCell& cell,
251251
#ifdef __MPI
252252
this->local_occup_bcast(cell, nspin, npol);
253253
#endif
254-
mark_locale_initialized();
254+
mark_occ_mat_initialized();
255255
}
256256
else
257257
{
@@ -487,7 +487,7 @@ void Plus_U_Base::set_locale(const UnitCell& ucell)
487487
}
488488

489489

490-
void Plus_U_Base::get_locale_flat(const int iat, const int l, std::vector<double>& occ) const
490+
void Plus_U_Base::get_occ_mat_flat(const int iat, const int l, std::vector<double>& occ) const
491491
{
492492
const int tlp1 = 2 * l + 1;
493493
const int size = tlp1 * tlp1;
@@ -511,7 +511,7 @@ void Plus_U_Base::get_locale_flat(const int iat, const int l, std::vector<double
511511
}
512512

513513

514-
void Plus_U_Base::set_locale_flat(const int iat, const int l, const int spin,
514+
void Plus_U_Base::set_occ_mat_flat(const int iat, const int l, const int spin,
515515
const std::vector<double>& occ)
516516
{
517517
for (int i = 0; i < static_cast<int>(occ.size()); i++)

source/source_pw/module_pwdft/dftu_base.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ class Plus_U_Base
134134
return eff_pot_pw.size();
135135
}
136136

137-
// dftu can be calculated only after locale has been initialed
138-
bool initialed_locale = false;
137+
// dftu can be calculated only after occ_mat has been initialized
138+
bool occ_mat_initialized = false;
139139

140-
bool is_locale_initialized() const { return initialed_locale; }
141-
void mark_locale_initialized() { initialed_locale = true; }
142-
void mark_locale_dirty() { initialed_locale = false; }
140+
bool is_occ_mat_initialized() const { return occ_mat_initialized; }
141+
void mark_occ_mat_initialized() { occ_mat_initialized = true; }
142+
void mark_occ_mat_dirty() { occ_mat_initialized = false; }
143143

144144
static bool is_mixing_enabled() { return mixing_dftu != 0; }
145145
static void enable_mixing() { mixing_dftu = 1; }
@@ -180,10 +180,10 @@ class Plus_U_Base
180180
/// nspin=1: fills occ with occ_mat[iat][l][0][0] data
181181
/// nspin=2: fills occ with interleaved occ_mat[iat][l][0][0] and [1] data
182182
/// nspin=4: fills occ with occ_mat[iat][l][0][0] data (all 4 Pauli blocks)
183-
void get_locale_flat(const int iat, const int l, std::vector<double>& occ) const;
183+
void get_occ_mat_flat(const int iat, const int l, std::vector<double>& occ) const;
184184

185185
/// set flat occupation matrix for an atom's correlated orbital (write-back)
186-
void set_locale_flat(const int iat, const int l, const int spin,
186+
void set_occ_mat_flat(const int iat, const int l, const int spin,
187187
const std::vector<double>& occ);
188188

189189
// local occupancy matrix of the correlated subspace

0 commit comments

Comments
 (0)