From a3d101ffdd6f69847fe4671cd20fbac373c6c8a4 Mon Sep 17 00:00:00 2001 From: hans Date: Fri, 28 Aug 2026 17:31:08 +0800 Subject: [PATCH 1/2] Fix electrode charge sync for split K-space --- src/lmp/verlet_split_kspace.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/lmp/verlet_split_kspace.cpp b/src/lmp/verlet_split_kspace.cpp index 37616c3..5240d5a 100755 --- a/src/lmp/verlet_split_kspace.cpp +++ b/src/lmp/verlet_split_kspace.cpp @@ -466,7 +466,8 @@ void VerletSplitKSpace::run(int n) /* ---------------------------------------------------------------------- setup params for Rspace <-> Kspace communication called initially and after every reneighbor - also communcicate atom charges from Rspace to KSpace since static + Per-step dynamic state (coordinates and charges) is synchronized by + r2k_comm() after PRE_FORCE. ------------------------------------------------------------------------- */ void VerletSplitKSpace::rk_setup() @@ -512,11 +513,13 @@ void VerletSplitKSpace::rk_setup() atom->nghost = 0; }*/ - // one-time scatter of Rspace atom charges to Kspace proc - int n; - n = atom->nlocal; - MPI_Scatterv(master ? atom->q : nullptr, qsize, qdisp, MPI_DOUBLE, - atom->q, n, MPI_DOUBLE, 0, block); + // ARCHIVED: one-time scatter of Rspace atom charges to Kspace proc. + // int n; + // n = atom->nlocal; + // MPI_Scatterv(master ? atom->q : nullptr, qsize, qdisp, MPI_DOUBLE, + // atom->q, n, MPI_DOUBLE, 0, block); + // Disabled because electrode fixes may update atom->q every PRE_FORCE; + // transferring only at reneighbouring leaves K-space PPPM with stale charges. } @@ -583,8 +586,8 @@ void VerletSplitKSpace::neigh_comm(int nflag,int n_pre_exchange,int n_pre_neighb } /* ---------------------------------------------------------------------- - communicate Rspace atom coords to Kspace - also eflag,vflag and box bounds if needed + Synchronize current R-space electrostatic state to K-space. + Called after PRE_FORCE, so q includes charges updated by electrode fixes. ------------------------------------------------------------------------- */ @@ -596,6 +599,11 @@ void VerletSplitKSpace::r2k_comm() MPI_Scatterv(master ? atom->x[0] : nullptr, xsize, xdisp, MPI_DOUBLE, atom->x[0], n * 3, MPI_DOUBLE, 0, block); + // qsize/qdisp are per-K-space-partition atom counts/displacements. + // This q must correspond exactly to the coordinates transferred above. + MPI_Scatterv(master ? atom->q : nullptr, qsize, qdisp, MPI_DOUBLE, + atom->q, n, MPI_DOUBLE, 0, block); + if (domain->box_change && !master) force->kspace->setup(); } From 7cc9012087761e8ce902b18360e0eb60439662f6 Mon Sep 17 00:00:00 2001 From: hans Date: Sat, 29 Aug 2026 15:20:52 +0800 Subject: [PATCH 2/2] Initialize split K-space charges before setup --- src/lmp/verlet_split_kspace.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lmp/verlet_split_kspace.cpp b/src/lmp/verlet_split_kspace.cpp index 5240d5a..e1ac50f 100755 --- a/src/lmp/verlet_split_kspace.cpp +++ b/src/lmp/verlet_split_kspace.cpp @@ -513,13 +513,12 @@ void VerletSplitKSpace::rk_setup() atom->nghost = 0; }*/ - // ARCHIVED: one-time scatter of Rspace atom charges to Kspace proc. - // int n; - // n = atom->nlocal; - // MPI_Scatterv(master ? atom->q : nullptr, qsize, qdisp, MPI_DOUBLE, - // atom->q, n, MPI_DOUBLE, 0, block); - // Disabled because electrode fixes may update atom->q every PRE_FORCE; - // transferring only at reneighbouring leaves K-space PPPM with stale charges. + // Initialize K-space q before its first setup/thermo evaluation. This also + // provides a valid state after reneighboring; r2k_comm() refreshes it again + // after every subsequent PRE_FORCE charge update. + int n = atom->nlocal; + MPI_Scatterv(master ? atom->q : nullptr, qsize, qdisp, MPI_DOUBLE, + atom->q, n, MPI_DOUBLE, 0, block); }