Skip to content

refactor(cell): replace raw pointer members with std::vector in Symmetry - #8113

Merged
mohanchen merged 1 commit into
deepmodeling:developfrom
DanielZhao0432:261010-task2-cell-symm-vector
Oct 10, 2026
Merged

mohanchen merged 1 commit into
deepmodeling:developfrom
DanielZhao0432:261010-task2-cell-symm-vector

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 small internal refactor with no behavior change.

Unit Tests and/or Case Tests for my changes

  • Commands run:
    • cmake --build build -j30 (full build with BUILD_TESTING=ON, ENABLE_MPI=ON)
    • OMP_NUM_THREADS=1 ctest --test-dir build -R MODULE_CELL_SYMMETRY (covers analy_sys/pricell/getgroup and density symmetrization)
    • OMP_NUM_THREADS=1 ctest --test-dir build -R "MODULE_CELL_(klist|qlist|little_group)" (regression: these tests call analy_sys indirectly)
    • python3 tools/03_code_analysis/agent_governance_check.py --staged
  • Result summary: build succeeded; MODULE_CELL_SYMMETRY 4/4 passed; klist/qlist/little_group 5/5 passed; governance check reported only non-blocking warnings (addressed in Governance Notes).
  • Checks not run, with reason: no new tests added — no behavior change; the existing symmetry unit tests already exercise the modified lifecycle (analy_sys allocates/fills/releases these arrays every call).

What's changed?

  • Replaced the five raw-pointer members of ModuleSymmetry::Symmetry with std::vector: int* na, int* istart -> std::vector<int>; double* newpos, double* rotpos -> std::vector<double>; int* index -> std::vector<int>.
  • In analy_sys (symm_analysis.cpp): merged the new[] + ModuleBase::GlobalFunc::ZEROS pairs into assign(n, 0) calls (keeping the exact sizes, including nat + 2 for index), which also re-zeroes correctly when analy_sys is called repeatedly (e.g. each ionic step of cell-relax); removed the five delete[] at the end of the function.
  • Member-to-function call sites now pass .data(): lattice_type, pricell, getgroup in symm_analysis.cpp; getgroup in symm_magnetic.cpp; two pointer-arithmetic call sites of atom_ordering_new in symm_pricell.cpp (index.data() + istart[it], rotpos.data() + istart[it] * 3).
  • In set_atom_map (symmetry.cpp): replaced ZEROS(pos, nat*3) with std::fill(this->newpos.begin(), this->newpos.end(), 0.0) per the AGENTS.md rule on vector buffers, and the local aliases use .data().
  • Function signatures of getgroup/checksym/pricell/lattice_type are unchanged: they still take raw pointers because irred_sec_bvk.cpp and symm_magnetic.cpp pass non-member local buffers, and lattice_type's newpos argument is nullptr in 4 of its 5 call sites.

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/module_symmetry; a tree-wide search confirms no code outside the module accesses these five members, and no test or mock defines the Symmetry constructor/destructor.
  • The GlobalV warning on symm_magnetic.cpp:73 is migration-neutral (net_delta=0): the edited getgroup call line merely re-wraps the existing GlobalV::ofs_running reference.
  • The header-include warning on symmetry.h (#include <vector>) is acceptable: the class holds std::vector value members, which require the complete type.
  • 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 added the Symmetry This issue is related to symmetry label Oct 10, 2026
@mohanchen
mohanchen merged commit e9424f2 into deepmodeling:develop Oct 10, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes Symmetry This issue is related to symmetry 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