Skip to content

Commit 815c370

Browse files
authored
Fix: refresh v_eff again after updating XC type (deepmodeling#7840)
* Fix: refresh v_eff again after updating XC type, to correct H and eigenpairs in the 1st iter of the EXX loop. * update test references
1 parent cd270a7 commit 815c370

18 files changed

Lines changed: 69 additions & 38 deletions

File tree

source/source_esolver/esolver_ks_lcaopw.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ namespace ModuleESolver
168168
#ifdef __EXX
169169
if (GlobalC::exx_info.info_global.cal_exx && conv_esolver)
170170
{
171+
const int two_level_step_before = this->two_level_step;
172+
171173
// no separate_loop case
172174
if (!GlobalC::exx_info.info_global.separate_loop)
173175
{
@@ -218,6 +220,20 @@ namespace ModuleESolver
218220
<< std::defaultfloat << " (s)" << std::endl;
219221
conv_esolver = false;
220222
}
223+
224+
// On the 0->1 transition, exx_after_converge switches the XC functional (PBE->hybrid),
225+
// but v_eff was already set for this (converged) iteration under the OLD functional.
226+
// Without this refresh, the 1st iteration of the EXX loop builds H from the stale GGA v_eff
227+
// and then adds Hexx on top of it, double-counting exchange.
228+
// Usually only that one iteration is affected and the loop washes it out;
229+
// but when the 2nd loop converges immediately (density already exact, e.g. a minimal basis fixed by symmetry)
230+
// the polluted H is the final one -- it gets diagonalized and written out by out_mat_hs.
231+
// cal_converged() is used rather than a bare update_from_charge() so that vnew (used
232+
// by force_scc) and descf stay consistent with the refreshed v_eff.
233+
if (!conv_esolver && two_level_step_before == 0 && this->two_level_step == 1)
234+
{
235+
this->pelec->cal_converged();
236+
}
221237
}
222238
#endif
223239
}

source/source_lcao/module_ri/exx_lri_interface.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ void Exx_LRI_Interface<T, Tdata>::exx_iter_finish(const K_Vectors& kv,
326326
}
327327
// mohan update 2025-11-04
328328
this->dm_last_step = dm;
329+
const int two_level_step_before = this->two_level_step;
329330
conv_esolver = this->exx_after_converge(
330331
ucell,
331332
hamilt,
@@ -336,6 +337,20 @@ void Exx_LRI_Interface<T, Tdata>::exx_iter_finish(const K_Vectors& kv,
336337
istep,
337338
elec.f_en.etot,
338339
scf_ene_thr);
340+
341+
// On the 0->1 transition, exx_after_converge switches the XC functional (PBE->hybrid),
342+
// but v_eff was already set for this (converged) iteration under the OLD functional.
343+
// Without this refresh, the 1st iteration of the EXX loop builds H from the stale GGA v_eff
344+
// and then adds Hexx on top of it, double-counting exchange.
345+
// Usually only that one iteration is affected and the loop washes it out;
346+
// but when the 2nd loop converges immediately (density already exact, e.g. a minimal basis fixed by symmetry)
347+
// the polluted H is the final one -- it gets diagonalized and written out by out_mat_hs.
348+
// cal_converged() is used rather than a bare update_from_charge() so that vnew (used
349+
// by force_scc) and descf stay consistent with the refreshed v_eff.
350+
if (!conv_esolver && two_level_step_before == 0 && this->two_level_step == 1)
351+
{
352+
elec.cal_converged();
353+
}
339354
}
340355
//else if ( PARAM.inp.rdmft && two_level_step ) { conv_esolver = true; } // for RDMFT in the future to quit after the first iter of the exx-loop
341356
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -428.9942827110014605
2-
etotperatomref -142.9980942370
1+
etotref -428.9942827105964511
2+
etotperatomref -142.9980942369
33
totalforceref 30.937113
4-
totalstressref 256.779922
4+
totalstressref 256.779921
55
totaltimeref 2.76
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -448.7146661013188691
2-
etotperatomref -149.5715553671
3-
totalforceref 33.612992
4-
totalstressref 825.537129
1+
etotref -448.7146661094475348
2+
etotperatomref -149.5715553698
3+
totalforceref 33.613002
4+
totalstressref 825.537122
55
totaltimeref 2.91
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -448.3614595740453979
2-
etotperatomref -149.4538198580
3-
totalforceref 33.668064
4-
totalstressref 813.488523
1+
etotref -448.3614595745778502
2+
etotperatomref -149.4538198582
3+
totalforceref 33.668068
4+
totalstressref 813.488522
55
totaltimeref 3.18
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
etotref -428.9946798906369
2-
etotperatomref -142.9982266302
1+
etotref -428.9946799664623
2+
etotperatomref -142.9982266555
33
totaltimeref 2.02
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
etotref -461.2147367084566
2-
etotperatomref -153.7382455695
1+
etotref -461.2147366408772
2+
etotperatomref -153.7382455470
33
totaltimeref 3.20
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
etotref -467.2676785054572
2-
etotperatomref -155.7558928352
1+
etotref -467.2676788578187
2+
etotperatomref -155.7558929526
33
totaltimeref 3.40
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
etotref -463.4113534766316889
2-
etotperatomref -154.4704511589
1+
etotref -463.4113534713501963
2+
etotperatomref -154.4704511571
33
totaltimeref 5.46

tests/08_EXX/08_KP_HSE_symm/result.ref

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -189.4277005989405893
2-
etotperatomref -94.7138502995
1+
etotref -189.4277005988057567
2+
etotperatomref -94.7138502994
33
totalforceref 0.000000
44
totalstressref 2155.899405
55
pointgroupref D_3d

0 commit comments

Comments
 (0)