Test: separate from #7304 for test cases only - #7382
Merged
Merged
Conversation
…ntial spin constraints
Add the 17_DS_DFTU test suite for DeltaSpin and DFT+U functionality: - 47 test cases covering LCAO/PW basis, collinear/noncollinear spin, DFT+U, DeltaSpin, and their combinations - Comment out tests in tests/CMakeLists.txt and tests/17_DS_DFTU/CMakeLists.txt to prevent CI failure until DeltaSpin code is merged into develop - Add single-line README to each test directory (printed during Autotest.sh) - Rewrite CASES_CPU.txt with clear English comments explaining disabled tests
dyzheng
pushed a commit
to dyzheng/abacus-develop
that referenced
this pull request
Sep 16, 2026
The result.ref of these five PW DeltaSpin cases predates the DeltaSpin PW rework (they were last written in deepmodeling#7382) and no longer matched the code: 12/18 were off by 2.6/4.6 eV, while 19/21/41 differed only at the 1e-4-1e-7 eV level. Regenerate all five with the current code so the 17_DS_DFTU suite passes again. 12_PW_DS_S2_Z now agrees with the dedicated 01_PW/scf_deltaspin2 reference (-6369.19826815 eV), confirming the new value is the intended one.
mohanchen
pushed a commit
that referenced
this pull request
Sep 18, 2026
* Fix(deltaspin): propagate current_spin through LCAO operator chain HamiltLCAO::updateHk() sets current_spin on the root operator via set_current_spin(isk[ik]), but the value was never forwarded to child operators. DeltaSpin did not toggle its own current_spin, so it always saw current_spin == 0 for nspin=2 and applied the same +lambda_z coefficient to both spin channels instead of +lambda_z/-lambda_z. The constraint therefore acted as a spin-independent potential and produced wrong magnetic moments and total energies. Propagate current_spin to the next operator in OperatorLCAO::init() before processing the current node, so every node in the chain shares the spin state set by the k-point loop. Regenerate tests/03_NAO_multik/scf_deltaspin2/result.ref, whose previous values encoded the buggy result. * Fix(pw): correct nspin=2 DeltaSpin occupation output and per-atom labels cal_occupations() read the becp layout with the npol=2 stride (ib*2*nkb) and ignored the spin channel for nspin=2 (npol=1), so the projected atomic magnetization printed by print_orb_chg() was wrong for nspin=2. Index by the psi npol and store the spin-up/down occupancy in the up-up/down-down Pauli blocks so that Charge = occ[0]+occ[3] and Mag(z) = occ[0]-occ[3] print correctly; nspin=1 keeps a zero magnetization; nspin=4 keeps the interleaved spinor layout. Also build per-atom labels (Fe1, Fe2, ...) for the Total Magnetism / Magnetic force tables in print_orb_chg(), print_Mi() and print_Mag_Force(), instead of passing the per-type label vector (size ntype) to tables with nat rows. get_iat() is made const so the label helpers can read it from a const SpinConstrain reference. * Test: refresh stale DeltaSpin PW reference values The result.ref of these five PW DeltaSpin cases predates the DeltaSpin PW rework (they were last written in #7382) and no longer matched the code: 12/18 were off by 2.6/4.6 eV, while 19/21/41 differed only at the 1e-4-1e-7 eV level. Regenerate all five with the current code so the 17_DS_DFTU suite passes again. 12_PW_DS_S2_Z now agrees with the dedicated 01_PW/scf_deltaspin2 reference (-6369.19826815 eV), confirming the new value is the intended one. * Refactor(pw): pass nspin explicitly to cal_occupations The governance checker blocks PRs that increase GlobalV/GlobalC/PARAM usage. cal_occupations() read PARAM.inp.nspin twice; pass it as an explicit argument from ctrl_scf_pw() (which already holds the parsed Input_para) instead. Also keep the print_orb_chg() header line using the existing atom_label variable so the GlobalV::ofs_running line stays untouched. --------- Co-authored-by: dyzheng <zhengdy@bjaisi.com>
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.
Reminder
Linked Issue
Fix #...
Unit Tests and/or Case Tests for my changes
What's changed?
Any changes of core modules? (ignore if not applicable)