Skip to content

Refactor DFT+U onsite Hamiltonian assembly - #8195

Merged
mohanchen merged 3 commits into
deepmodeling:developfrom
lanshuyue:codex/refactor-dftu-nao-op
Oct 22, 2026
Merged

mohanchen merged 3 commits into
deepmodeling:developfrom
lanshuyue:codex/refactor-dftu-nao-op

Conversation

@lanshuyue

Copy link
Copy Markdown
Collaborator

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

No linked issue: this is a behavior-preserving maintainability refactor prompted by the code-quality report for dftu_nao_op.cpp.

Unit Tests and/or Case Tests for my changes

  • Commands run:
    • cmake --build build --target MODULE_DFTU_op abacus_basic_para -j2
    • OMP_NUM_THREADS=1 ctest --test-dir build --output-on-failure -R '^MODULE_DFTU_op$'
    • OMP_NUM_THREADS=1 ../integrate/Autotest.sh -a <new-binary> -f /tmp/dftu_refactor_cases.txt -n 4 -o 1 -j 1
    • The same integration command with the saved pre-refactor binary for an A/B comparison.
    • python3 tools/03_code_analysis/code_quality_score.py --format json source/source_lcao/module_dftu/dftu_nao_op.cpp
    • python3 tools/03_code_analysis/agent_governance_check.py --staged
    • git diff --check
  • Result summary:
    • Focused unit-test target and the main abacus_basic_para executable compiled successfully.
    • MODULE_DFTU_op passed (1/1).
    • The refactored and saved pre-refactor executables produced identical energies for both symmetry=1, kpar=4 A/B cases:
      • 03_LCAO_DFTU_S2_Z: -6771.69033022 eV with both binaries.
      • 04_LCAO_DFTU_S4_XY: -6763.40685034 eV with both binaries.
    • The integration harness still reports the same pre-existing reference deviations for both binaries. Case 04 is already disabled in CASES_CPU.txt for convergence/numerical-stability reasons. The A/B comparison confirms this refactor introduces no numerical change.
    • Code-quality score improved from 82 to 96. The only remaining deduction is the existing 11-parameter constructor, intentionally left unchanged to avoid an interface-level refactor.
    • Governance and whitespace checks completed without blocking findings.
  • Checks not run, with reason:
    • pre-commit was unavailable in the local environment (pre-commit: command not found). Equivalent staged governance and whitespace checks were run directly.

What's changed?

  • Split DFTU_onsite::contributeHR() into focused helpers for symmetry decisions, rotation setup, full-BZ k-vector construction, Hubbard-atom accumulation, and spin post-processing.
  • Keep the temporary symmetry-restored density matrix on the stack and consume it within its owning helper, removing the raw new allocation.
  • Wrap lines longer than 120 characters.
  • Preserve the constructor and all external interfaces.

Governance Notes

  • INPUT/docs changes: none; this refactor does not change user-visible behavior or INPUT parameters.
  • Core module impact: limited to the LCAO DFT+U onsite operator implementation. Hamiltonian assembly order, occupation handling, symmetry restoration, spin handling, and numerical results are unchanged.
  • Exceptions requested: none.

@lanshuyue lanshuyue added DFT+U Issues related to DFT plus U function Refactor Refactor ABACUS codes labels Oct 21, 2026
@lanshuyue

Copy link
Copy Markdown
Collaborator Author

@ABACUS-PR-BOT

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review of eb03771c, including an independent pass, found no new correctness defects in this extraction. One non-blocking memory-lifetime suggestion is inline. Static governance and whitespace checks passed; builds, numerical/MPI tests, and CI were not independently verified.

Comment thread source/source_lcao/module_dftu/dftu_nao_op.cpp Outdated
@lanshuyue
lanshuyue requested a review from mohanchen October 21, 2026 14:58
@mohanchen
mohanchen merged commit 8635b9c into deepmodeling:develop Oct 22, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DFT+U Issues related to DFT plus U function Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants