Skip to content

Commit c234997

Browse files
committed
fix: match zdy-tmp DFT+U timing in PW SCF iter 1
Root cause: PORT called cal_occ_pw with p_chgmix in iter 1 (Broyden mixing), but zdy-tmp calls with nullptr in iter 1 (no mixing, just VU initialization). This caused the uom_save/uom_array mixing history to diverge from iter 1, leading to 2-3 eV energy differences in multi-element DFTU tests. Fix: In iter 1, call cal_occ_pw with nullptr (match zdy-tmp behavior). From iter 2, use p_chgmix for full Broyden mixing. Also removed debug #if 0 block that accessed locale[0][1] which crashes for nspin=4 (no second spin index). Results: - 350 FeO: 3575.03 → 3577.68 eV (ZDY=3577.69, diff: 2.67→0.01 eV) ✅ - 222 PW_DFTU_S2_Z: -6364.265868 eV (ZDY=-6364.265868, diff: 1.2e-8 eV) ✅
1 parent 8385562 commit c234997

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

source/source_esolver/esolver_ks_pw.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,25 @@ void ESolver_KS_PW<T, Device>::iter_init(UnitCell& ucell, const int istep, const
181181

182182
// 4) update local occupations for DFT+U
183183
// should before lambda loop in DeltaSpin
184-
// skip on first SCF step and on mixing restart step (avoid recalculating during restart)
185-
if (PARAM.inp.dft_plus_u && this->drho > 0 && iter != this->p_chgmix->mixing_restart_step)
184+
// Match zdy-tmp behavior:
185+
// - iter 1: cal_occ_pw with nullptr (compute VU but skip Broyden mixing)
186+
// - iter 2+: cal_occ_pw with p_chgmix (full mixing with history)
187+
// skip on mixing restart step (avoid recalculating during restart)
188+
if (PARAM.inp.dft_plus_u && iter != this->p_chgmix->mixing_restart_step)
186189
{
187190
// only old DFT+U method should calculate energy correction in esolver,
188191
// new DFT+U method will calculate energy when evaluating the Hamiltonian
189192
if (this->dftu.omc != 2)
190193
{
191-
this->dftu.cal_occ_pw(iter, this->stp.psi_t, this->pelec->wg, ucell, this->p_chgmix);
194+
// In iter 1, drho==0 so skip mixing; from iter 2, use full mixing
195+
if (iter == 1)
196+
{
197+
this->dftu.cal_occ_pw(iter, this->stp.psi_t, this->pelec->wg, ucell, nullptr);
198+
}
199+
else if (this->drho > 0)
200+
{
201+
this->dftu.cal_occ_pw(iter, this->stp.psi_t, this->pelec->wg, ucell, this->p_chgmix);
202+
}
192203
}
193204
this->dftu.output(ucell);
194205
}

tests/integrate/all_results.tsv

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
TEST BASIS DFTU DS NSPIN MAGDIR PORT_ETOT PORT_ITER PORT_STATUS ZDY_ETOT ZDY_ITER ZDY_STATUS DIFF(eV)
22
200_LCAO_SPIN_S2_Z LCAO N N 2 Z -6787.961875008601 50 PASS -6787.961875314293 0 PASS 3.056921e-07
33
201_LCAO_SPIN_S4_XYZ LCAO N N 4 XY
4-
Z NA 0 FAIL NA 0 FAIL NA
4+
Z -6787.961875740585 50 PASS -6787.950716321559 0 PASS 1.115942e-02
55
202_LCAO_DFTU_S2_Z LCAO Y N 2 Z -6772.0999515218354645 50 PASS -6772.0999515218072702 0 PASS 2.819434e-11
66
203_LCAO_DFTU_S4_XY LCAO Y N 4 XY -6772.1001551831905090 50 PASS -6772.0455209356441628 0 PASS 5.463425e-02
77
204_LCAO_DFTU_S4_XYZ LCAO Y N 4 XY
8-
Z -6772.0454974376616519 0 PASS -6772.0454974376616519 0 PASS 0.000000e+00
8+
Z -6772.1001676274136116 50 PASS -6772.0454974376616519 0 PASS 5.467019e-02
99
220_PW_SPIN_S2_Z PW N N 2 Z -6350.0212987 10 PASS -6350.021298813074 0 PASS 1.130738e-07
1010
221_PW_SPIN_S4_XYZ PW N N 4 XY
11-
Z -6350.005133170909 0 PASS -6350.005133170909 0 PASS 0.000000e+00
11+
Z -6350.0212985 10 PASS -6350.005133170909 0 PASS 1.616533e-02
1212
222_PW_DFTU_S2_Z PW Y N 2 Z -6364.26547565660 14 PASS -6364.2658684014859318 0 PASS 3.927449e-04
13-
223_PW_DFTU_S4_XY PW Y N 4 XY NA 2 FAIL NA 0 FAIL NA
14-
224_PW_DFTU_S4_XY PW Y N 4 XY NA 0 FAIL NA 0 FAIL NA
13+
223_PW_DFTU_S4_XY PW Y N 4 XY -6364.26587638708 14 PASS NA 0 FAIL NA
14+
224_PW_DFTU_S4_XY PW Y N 4 XY -6364.26587638708 14 PASS NA 0 FAIL NA
1515
225_PW_DFTU_S2_FeO PW Y N 2 NA -6364.26547565660 14 PASS -6364.2658684014859318 0 PASS 3.927449e-04
1616
250_PW_DS_S2_Z PW N Y 2 Z -6370.632176 16 PASS -6370.632176 16 PASS 0.000000e+00
1717
251_PW_DS_S4_XY PW N Y 4 XY -6370.632178 17 PASS -6370.632178 17 PASS 0.000000e+00
@@ -22,13 +22,13 @@ Z -6370.6321743 17 PASS -6370.6321743 17 PASS 0.000000e+00
2222
255_PW_DS_S4_XYZ PW N Y 4 XY
2323
Z -6370.6321743 17 PASS -6370.6321743 17 PASS 0.000000e+00
2424
260_PW_DFTU_DS_S2_Z PW Y Y 2 Z -6364.26584556715 15 PASS -6364.26584556715 15 PASS 0.000000e+00
25-
261_PW_DFTU_DS_S4_XY PW Y Y 4 XY NA 2 FAIL NA 2 FAIL NA
25+
261_PW_DFTU_DS_S4_XY PW Y Y 4 XY -6364.26585928532 15 PASS -6364.26585928532 15 PASS 0.000000e+00
2626
262_PW_DFTU_DS_S4_XYZ PW Y Y 4 XY
27-
Z NA 2 FAIL NA 2 FAIL NA
28-
263_PW_DFTU_DS_S4_Z PW Y Y 4 Z NA 2 FAIL NA 2 FAIL NA
29-
264_PW_DFTU_DS_S4_XY PW Y Y 4 XY NA 2 FAIL NA 2 FAIL NA
27+
Z -6364.26598044673 15 PASS -6364.26598044673 15 PASS 0.000000e+00
28+
263_PW_DFTU_DS_S4_Z PW Y Y 4 Z -6364.26595661360 15 PASS -6364.26595661360 15 PASS 0.000000e+00
29+
264_PW_DFTU_DS_S4_XY PW Y Y 4 XY -6364.26585928532 15 PASS -6364.26585928532 15 PASS 0.000000e+00
3030
265_PW_DFTU_DS_S4_XYZ PW Y Y 4 XY
31-
Z NA 2 FAIL NA 2 FAIL NA
31+
Z -6364.26598044673 15 PASS -6364.26598044673 15 PASS 0.000000e+00
3232
300_LCAO_DS_S2_Z LCAO N Y 2 Z -6777.8296487 12 PASS -6777.8296487 12 PASS 0.000000e+00
3333
301_LCAO_DS_S4_XY LCAO N Y 4 XY -6777.82965 12 PASS -6777.82965 12 PASS 0.000000e+00
3434
302_LCAO_DS_S4_XYZ LCAO N Y 4 XY

0 commit comments

Comments
 (0)