Skip to content

Commit 4c65f65

Browse files
maki49claude
andcommitted
fix: preserve public k-point reader contracts and kvec_c_full after aa6fc43
- read_listed_kpoints (Cartesian/Direct) and interpolate_k_between are public, independently-usable readers (KlistTest.ReadKpointsCartesian, ReadKpointsLineCartesian) that must produce spin-doubled containers immediately, without requiring a later set_kup_and_kdw() call; revert their allocation back to nkstot*spin_mult. Only Monkhorst_Pack (which triggered the original build_kstars crash and has no such contract) keeps the deferred, undoubled allocation. - set_kup_and_kdw() now resizes only kvec_c/kvec_d/wk/ngk/isk for the down-spin copy it is about to append, instead of calling renew() (which also resizes kvec_c_full). kvec_c_full must keep holding the original, un-reduced full-BZ mesh for later consumers (e.g. Ewald_Vq); renew() was truncating it to the symmetry-reduced, spin-doubled size. Verified: MODULE_CELL_klist_test (34/34), MODULE_CELL_reciprocal_grid_test (10/10), MODULE_CELL_qlist_test (16/16), MODULE_CELL_klist_test_para1 (2/2) all pass; 17_DS_DFTU/03_LCAO_DFTU_S2_Z with symmetry=1 still produces the same energy as before this fix. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019omhQohPCePyJnLiWnG6Fa
1 parent 156b725 commit 4c65f65

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

‎source/source_cell/klist.cpp‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,14 @@ bool K_Vectors::read_listed_kpoints(std::ifstream& ifk, const std::string& kword
335335
{
336336
if (kword == "Cartesian" || kword == "C") // Cartesian coordinates
337337
{
338-
this->renew(nkstot); // mohan fix bug 2009-09-01; spin_mult doubling done later by set_kup_and_kdw()
338+
this->renew(nkstot * this->spin_mult); // mohan fix bug 2009-09-01
339339
KListIO::read_kpt_list(ifk, nkstot, this->kvec_c, this->wk);
340340
this->kc_done = true;
341341
return true;
342342
}
343343
if (kword == "Direct" || kword == "D") // Direct coordinates
344344
{
345-
this->renew(nkstot); // mohan fix bug 2009-09-01; spin_mult doubling done later by set_kup_and_kdw()
345+
this->renew(nkstot * this->spin_mult); // mohan fix bug 2009-09-01
346346
KListIO::read_kpt_list(ifk, nkstot, this->kvec_d, this->wk);
347347
this->kd_done = true;
348348
return true;
@@ -395,7 +395,7 @@ void K_Vectors::interpolate_k_between(std::ifstream& ifk, std::vector<ModuleBase
395395
const KListIO::LineK line = KListIO::interp_line(ifk, this->nkstot);
396396

397397
this->nkstot = line.nks_total;
398-
this->renew(this->nkstot); // mohan fix bug 2009-09-01; spin_mult doubling done later by set_kup_and_kdw()
398+
this->renew(this->nkstot * this->spin_mult); // mohan fix bug 2009-09-01
399399

400400
for (int i = 0; i < this->nkstot; i++)
401401
{
@@ -446,11 +446,17 @@ void K_Vectors::set_kup_and_kdw(std::ofstream& ofs_running)
446446
{
447447
ModuleBase::TITLE("K_Vectors", "setup_kup_and_kdw");
448448

449-
// grow the containers to make room for the down-spin copy expand_spin_kpoints()
450-
// is about to append (indices [nkstot, 2*nkstot)); done here, on demand, rather
451-
// than speculatively reserved earlier, so nothing upstream of this point ever
452-
// sees kvec_d/kvec_c/wk/isk padded with not-yet-meaningful placeholder entries.
453-
this->renew(this->nkstot * this->spin_mult);
449+
// grow the containers expand_spin_kpoints() is about to append the down-spin
450+
// copy into (indices [nkstot, 2*nkstot)). Resize only these; NOT via renew(),
451+
// which would also resize kvec_c_full -- that one must keep holding the
452+
// original, un-doubled, un-symmetry-reduced full-BZ mesh for later consumers
453+
// (e.g. Ewald_Vq) regardless of what nkstot has become by this point.
454+
const int nkstot_spin = this->nkstot * this->spin_mult;
455+
this->kvec_c.resize(nkstot_spin);
456+
this->kvec_d.resize(nkstot_spin);
457+
this->wk.resize(nkstot_spin);
458+
this->ngk.resize(nkstot_spin);
459+
this->isk.resize(nkstot_spin);
454460

455461
KListIO::expand_spin_kpoints(this->spin_mult,
456462
this->kvec_c,

0 commit comments

Comments
 (0)