You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* resolve the wrong dependency between klist and berryphase
* remove useless things
* replace ucell.lc with vector<int>
* change the name of a variable
* remove dependency of PARAM
* move test of magnetism
* update magnetism
* update agent governance check
* update agent governance check
* refactor(cell): centralize Magnetism::start_mag initialization in setup() and read_atom_positions()
### Why
Previously `Magnetism::start_mag` had no well-defined single owner for memory
allocation. Even though `UnitCell::setup_cell()` happened to resize it, any
caller that invoked `unitcell::read_atom_positions()` directly (as most unit
tests did) was required to *externally* call
`ucell->magnet.start_mag.resize(ucell->ntype)` first. This undocumented
implicit contract produced dozens of scattered, copy-paste pre-conditions
throughout the test harness and made the API easy to misuse.
### What
1. Proactive initialization in `UnitCell::setup()`
- As soon as `ntype` is set, resize `start_mag` to `ntype_in` with value 0.0.
- This covers every test helper that already goes through `setup()` so the
callers no longer need to manually size and zero-initialize the vector.
2. Defensive auto-resize inside `unitcell::read_atom_positions()`
- Before any access to `start_mag[it]`, check that its size matches
`ucell.ntype` and resize if needed.
- This guards the remaining code paths that set `ntype` by hand and
guarantees the consumer owns its pre-conditions.
3. Removed the now-redundant explicit resize in `UnitCell::setup_cell()`.
Kept the `assert(ntype > 0)` validity check; renumbered the following
step comment from `(2)` to `(1)`.
4. Cleaned up ~20+ copies of the redundant preparatory lines across the
test suites:
- 7 `prepare_unitcell.h` helpers (source_cell, source_cell/module_neighbor,
source_estate, source_estate/module_dm, source_lcao/module_hcontainer,
source_io, source_io/test_serial): removed
`ucell->magnet.start_mag.resize(ntype)` and the loop body
`start_mag[it] = 0.0`.
- Unit tests `unitcell_test.cpp`, `unitcell_test_pw.cpp` and
`unitcell_test_setupcell.cpp`: removed the now-unnecessary "mandatory
preliminaries" resize block before `read_atom_positions`.
### Files touched (12)
source/source_cell/unitcell.cpp
source/source_cell/read_atoms.cpp
source/source_cell/module_neighbor/test/prepare_unitcell.h
source/source_cell/test/prepare_unitcell.h
source/source_cell/test/unitcell_test.cpp
source/source_cell/test/unitcell_test_setupcell.cpp
source/source_cell/test_pw/unitcell_test_pw.cpp
source/source_estate/test/prepare_unitcell.h
source/source_estate/module_dm/test/prepare_unitcell.h
source/source_io/test/prepare_unitcell.h
source/source_io/test_serial/prepare_unitcell.h
source/source_lcao/module_hcontainer/test/prepare_unitcell.h
Behavior change: none; resize is idempotent and every removed site defaulted
to the same zero value the new helpers already use.
* fix bugs
---------
Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
0 commit comments