Commit d8ff3fb
Fix: DeltaSpin energy fix (#7748)
* Fix(deltaspin): enable DeltaSpin constraint energy calculation for PW basis
- cal_escon(): replace is_Mi_converged gate with lambda_/Mi_ empty check
to prevent segfault when uninitialized
- elecstate_pw: add get_spin_constrain_energy() override so PW basis
computes DeltaSpin constraint energy (previously returned 0.0)
- elecstate_pw.h: declare get_spin_constrain_energy() override
Note: this fix enables escon computation for PW DeltaSpin but
lambda values from BFGS optimizer may differ from accel branch
due to energy functional convention differences. Full convergence
with accel requires lambda_loop.cpp migration.
* Fix(deltaspin): enable PW DeltaSpin constraint energy and update test refs
Source changes:
- cal_escon(): replace is_Mi_converged guard with lambda_/Mi_ empty check
to prevent segfault when uninitialized (matching accel convention)
- elecstate_pw: add get_spin_constrain_energy() override so PW basis
includes DeltaSpin constraint energy in total energy (was always 0)
Test refs regenerated for 7 cases with significant energy changes:
- 14_PW_DS_S4_XYZ, 15_PW_DS_S4_Z, 16_PW_DS_S4_XY
- 18_PW_DFTU_DS_S2_Z, 19_PW_DFTU_DS_S4_XY, 21_PW_DFTU_DS_S4_Z
- 41_PW_DS_S4_Thr10_XY
nspin=2 tests and ReadLam/Thr1e10 tests unchanged.
* Fix(deltaspin): fix pauli_to_moment My sign convention and enable PW escon
Source fixes:
- spin_constrain.h: fix My = -Im(occ1-occ2) → Im(occ1-occ2)
The magnetic moment y-component had the wrong sign in the Pauli matrix
transformation, causing incorrect Mi computation for nspin=4 DeltaSpin.
- cal_escon(): replace is_Mi_converged guard with lambda_/Mi_ empty check
- elecstate_pw: add get_spin_constrain_energy() for PW basis DeltaSpin
Refs regenerated for nspin=4 DeltaSpin cases: 14, 15, 16, 19, 21, 41
Test 18 unchanged, nspin=2 tests unchanged.
* Fix(build): link deltaspin sources into MODULE_ESTATE_elecstate_pw test
elecstate_pw.cpp now calls spinconstrain::SpinConstrain<
std::complex<double>>::getScInstance()/cal_escon() via the new
get_spin_constrain_energy() override. The MODULE_ESTATE_elecstate_pw
unit test compiles elecstate_pw.cpp directly but did not link the
deltaspin module, causing undefined-reference link errors in
BUILD_TESTING builds (test.yml and cuda.yml CI jobs).
Add spin_constrain.cpp to the test SOURCES, mirroring the existing
MODULE_LCAO_deltaspin_spin_constrain_test pattern.
* fix: add get_spin_constrain_energy stub to hsolver supplementary mock
ElecStatePW::get_spin_constrain_energy() is a new virtual override
that needs a definition in the vtable. Test targets (MODULE_HSOLVER_base,
MODULE_HSOLVER_pw, MODULE_HSOLVER_sdft) compile a mock implementation
of ElecStatePW methods instead of linking elecstate_pw.cpp, and were
missing a stub for this new method, causing:
undefined reference to ElecStatePW::get_spin_constrain_energy()
---------
Co-authored-by: dyzheng <zhengdy@bjaisi.com>1 parent 4261f5e commit d8ff3fb
12 files changed
Lines changed: 38 additions & 20 deletions
File tree
- source
- source_estate
- test
- source_hsolver/test
- source_lcao/module_deltaspin
- tests/17_DS_DFTU
- 14_PW_DS_S4_XYZ
- 15_PW_DS_S4_Z
- 16_PW_DS_S4_XY
- 19_PW_DFTU_DS_S4_XY
- 21_PW_DFTU_DS_S4_Z
- 41_PW_DS_S4_Thr10_XY
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
59 | 68 | | |
60 | 69 | | |
61 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
62 | 68 | | |
63 | 69 | | |
64 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments