Refactor DFT+U step 2 - #7858
Merged
Merged
Conversation
added 6 commits
August 25, 2026 07:49
…ave (Step 1/5)
- Rename Plus_U_Base data members: locale -> occ_mat, locale_save -> occ_mat_save
- Update all direct member access sites in:
* dftu_base.h inline get_locale/set_locale bodies and doc examples
* dftu_base.cpp (init allocation, copy/zero/mix/set internal, flat conv,
read_occup_m, local_occup_bcast MPI, Memory::record tag)
* dftu_pw.cpp (cal_occ_pw: becp accumulation, k-pool reduce, VU & energy)
* dftu.cpp (cal_energy_correction trace & double-counting terms)
* dftu_occup.cpp (LCAO cal_occup_m_k/_gamma S*DM accumulation, MPI
Allreduce, symmetrization via transpose)
* dftu_tools.cpp (get_onebody_eff_pot new/saved branches)
* test_dftu.cpp (setup resize/create, EXPECT assertions on values)
- Public API names (get_locale, set_locale, copy_locale, zero_locale,
mix_locale, set_locale_flat, is_locale_initialized, etc.) are kept
unchanged in this step to keep the change surface minimal.
7 files changed, 133 insertions(+), 133 deletions(-).
…at (Step 2/5) Rename the public single-element accessors of Plus_U_Base: get_locale(iat,l,n,spin,m1,m2) -> get_occ_mat(...) set_locale(iat,l,n,spin,m1,m2,val) -> set_occ_mat(...) Update all 5 direct call sites: * dftu_output.cpp (4 calls in dftu_io::write_occup_m for output) * dftu_lcao.cpp (1 call in DFTU cal_occ fallback branch) The protected batch overload set_locale(const UnitCell&) and the other state/flat helpers (copy_locale, zero_locale, mix_locale, get_locale_flat, set_locale_flat, is_locale_initialized, mark_*) are intentionally kept unchanged and will be renamed in the following steps. 3 files changed, 7 insertions(+), 7 deletions(-).
…ng (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(-).
…t (Step 4/5)
Rename the four protected internal helpers of Plus_U_Base and their
ModuleBase::TITLE / timer tag strings for consistency:
copy_locale(ucell) -> copy_occ_mat(ucell)
zero_locale(ucell) -> zero_occ_mat(ucell)
mix_locale(ucell, mixing_beta) -> mix_occ_mat(ucell, mixing_beta)
set_locale(ucell) -> set_occ_mat(ucell)
The single-argument batch setter set_occ_mat(const UnitCell&) now
overloads the public element-wise setter set_occ_mat(iat,l,n,spin,m1,m2,val)
with a different signature — no ambiguity, no change to callers.
Declarations (dftu_base.h), definitions + internal call sites in
dftu_base.cpp (init_base flow, also all TITLE/timer labels), and
call sites in cal_occ_pw (dftu_pw.cpp) and cal_occup_m_{k,gamma}
(dftu_occup.cpp) are all updated together.
4 files changed, 32 insertions(+), 32 deletions(-).
Final cleanup pass to align naming after the locale -> occ_mat rename:
* dftu_lcao.cpp (~40 lines):
- Replace identifier-style 'locale' / 'Locale' references in the
contributeHR() doc block and inline comments with 'occ_mat' /
'Occ_mat', including stale 'via get_locale()' / 'get_locale uses'
mentions that no longer match the API.
- Rename local bool flag locale_not_init -> occ_mat_not_init.
* dftu_pw.cpp (4 lines): Fix the 4 remaining comments that still
referred to 'locale matrix' / 'reduce locale' / 'locale reduced'
in the cal_occ_pw implementation notes.
* dftu_occup.cpp (2 lines): Update the top-of-file function inventory
comment: set_locale(ucell) -> set_occ_mat(ucell); get/set_locale_flat
-> get/set_occ_mat_flat.
* dftu_tools.cpp (12 lines): Rename bool parameter 'newlocale' ->
'new_occ_mat' and its 3 internal uses in cal_VU_pot_mat_{complex,real}
and get_onebody_eff_pot signatures/bodies, so the parameter name
matches the occ_mat naming convention.
* dftu_core_test.cpp (28 lines):
- copy_locale_to_flat -> copy_occ_mat_to_flat (def + 3 call sites)
- set_locale_from_flat -> set_occ_mat_from_flat (def + 3 call sites)
- LocaleRoundtripTest -> OccMatRoundtripTest (test fixture + 2 TEST_F)
- Related header comments: 'copy_locale <-> set_locale roundtrip',
'nested locale matrix' updated accordingly.
* dftu_pw_test.cpp (6 lines):
- 'Locale accumulation from becp' -> 'Occupation matrix accumulation
from becp' in the test description;
- 'set_locale is tested via integration tests.' -> 'set_occ_mat is
tested via integration tests.'
Not touched: pure semantic/mathematical local variable names inside
the test helpers (locale_up, locale_dn, locale_c, compute_vu(locale_val),
compute_energy(locale_flat), etc.) - these are local symbolic
placeholders independent of the Plus_U_Base member naming.
6 files changed, 49 insertions(+), 49 deletions(-).
…le_dftu Move DFTU/OperatorDFTU<OperatorLCAO> operator implementation files (dftu.hpp, dftu_lcao.h/cpp, dftu_fs.cpp, op_dftu_lcao.h/cpp) and the related unit test (test_dftu.cpp -> dftu_lcao_test.cpp) from module_operator_lcao to module_dftu. This is a step toward removing module_operator_lcao and grouping DFT+U code by physical domain. CMake changes: - module_dftu CMakeLists adds the 3 cpp files guarded by ENABLE_LCAO, since module_dftu is unconditionally added by source_lcao while these files depend on operator_lcao.h - module_operator_lcao CMakeLists drops the 3 cpp files - source_lcao CMakeLists drops the 3 cpp entries from the hamilt_lcao OBJECT library (now provided by the dftu OBJECT library) - New dftu_lcao_test target guarded by ENABLE_LCAO AND ENABLE_MPI matches the original MODULE_LCAO_operator_dftu_test build condition Include path updates in 5 external call sites plus op_dftu_lcao.h internal operator_lcao.h path (changed from same-directory relative to full path since the file is no longer co-located). Verified: cmake configure, make abacus_max_para + dftu_lcao_test, and ctest dftu_pw_test/dftu_core_test/dftu_operator_test/dftu_lcao_test all pass; agent_governance_check reports only include-path change warnings with no errors.
lanshuyue
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor DFT+U step 2