Skip to content

refactor(cell): split unitcell.cpp into index/stats/setup files - #8115

Merged
mohanchen merged 3 commits into
deepmodeling:developfrom
DanielZhao0432:261010-task3-cell-unitcell-split
Oct 10, 2026
Merged

mohanchen merged 3 commits into
deepmodeling:developfrom
DanielZhao0432:261010-task3-cell-unitcell-split

Conversation

@DanielZhao0432

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 pure code-motion refactor plus new unit tests, with no behavior change.

Unit Tests and/or Case Tests for my changes

  • Commands run:
    • cmake -B build -DBUILD_TESTING=ON -DENABLE_MPI=ON ... && cmake --build build -j30
    • OMP_NUM_THREADS=1 ctest --test-dir build -V -R MODULE_CELL_unitcell_index_test
    • OMP_NUM_THREADS=1 ctest --test-dir build -R MODULE_CELL
    • python3 tools/03_code_analysis/agent_governance_check.py --base upstream/develop --head HEAD --format text
    • python3 tools/03_code_analysis/code_quality_score.py <changed cpp/h files>
  • Result summary: full build succeeded; new MODULE_CELL_unitcell_index_test 4/4 passed; all MODULE_CELL* tests 47/47 passed; governance check reported only non-blocking warnings (see Governance Notes); quality score 5/5 files passing (average 91.6, minimum 67 >= 60 pass line).
  • New tests: source/source_cell/test/test_unitcell_index.cpp (named per the test_<module_name>.cpp rule), 4 TEST_F cases covering set_iat2itia (including the delete[]+new[] re-entry path) and set_iat2iwt with npol=1 and npol=2. The fixture uses a stack UnitCell with set_atom_flag=true; it does not manually free atoms (owned by ~UnitCell()) or iat2it/iat2ia (owned by the internal Statistics member), per AGENTS.md.

What's changed?

  • Split source/source_cell/unitcell.cpp (349 lines) by functionality, code motion only, no logic changes:
    • unitcell.cpp keeps the constructor/destructor.
    • unitcell_index.cpp holds the indexing helpers set_iat2itia() and set_iat2iwt().
    • unitcell_stats.cpp holds the per-species counting helpers get_atom_Counts(), get_orbital_Counts(), get_lnchi_Counts().
    • unitcell_setup.cpp holds the setup routines setup_cell() and setup_from_input().
  • CMake updated accordingly: the cell OBJECT library and the six test CMakeLists that compile unitcell.cpp directly (cell_simple_srcs, MODULE_CELL_read_atoms_helper_test, test_pw, source_md/test, module_deepks/test, module_pwdft/test x2) now register the three new files, so no target loses symbols.
  • Added the unit test target MODULE_CELL_unitcell_index_test (links cell_info, plus ../magnetism.cpp for the Magnetism ctor/dtor symbols).

Governance Notes

  • INPUT/docs changes: none; no INPUT parameter or user-visible behavior changed, so docs/parameters.yaml and docs/advanced/input_files/input-main.md do not require updates.
  • Core module impact: confined to source_cell; all public interfaces (declarations in unitcell.h) are unchanged, so callers and existing mocks (e.g. test/support/mock_unitcell.cpp) are unaffected.
  • The seven GlobalV warnings on unitcell_setup.cpp are migration-neutral (net_delta=0): the lines were moved verbatim from unitcell.cpp.
  • Quality-score deductions on unitcell_setup.cpp (17-parameter setup_cell, GlobalV uses) are pre-existing debt carried by the moved code, not introduced by this PR.
  • Exceptions requested: none.

@DanielZhao0432 DanielZhao0432 added Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0 labels Oct 10, 2026
@mohanchen
mohanchen merged commit 1988c0a into deepmodeling:develop Oct 10, 2026
17 checks passed
Critsium-xy added a commit to mohanchen/abacus-mc that referenced this pull request Oct 10, 2026
Resolve the conflict with deepmodeling#8115, which split unitcell.cpp into
unitcell_index.cpp, unitcell_stats.cpp and unitcell_setup.cpp: take the
upstream unitcell.cpp and port this branch's std::vector resize() change
for iat2it/iat2ia into unitcell_index.cpp. Update the stale ownership
comments in test_unitcell_index.cpp accordingly.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants