From d9804d7590050c8b7d2b7ec96ed0fb8aed700366 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Thu, 16 Nov 2023 16:21:59 -0700 Subject: [PATCH] Fix issues with sorting neigh list by cutoff distance --- src/neighbor.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/neighbor.cpp b/src/neighbor.cpp index df1547e5eb..741b469750 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -1126,15 +1126,14 @@ int Neighbor::init_pair() } /* ---------------------------------------------------------------------- - sort NeighRequests by cutoff distance - to find smallest list for trimming + sort NeighRequests by cutoff distance for trimming ------------------------------------------------------------------------- */ void Neighbor::sort_requests() { - NeighRequest *jrq; + NeighRequest *irq,*jrq; int i,j,jmin; - double jcut; + double icut,jcut; delete[] j_sorted; j_sorted = new int[nrequest]; @@ -1142,20 +1141,24 @@ void Neighbor::sort_requests() for (i = 0; i < nrequest; i++) j_sorted[i] = i; - for (i = 0; i < nrequest; i++) { - double cutoff_min = cutneighmax; + for (i = 0; i < nrequest-1; i++) { + irq = requests[j_sorted[i]]; + if (irq->cut) icut = irq->cutoff; + else icut = cutneighmax; + double cutoff_min = icut; jmin = i; - for (j = i; j < nrequest-1; j++) { + for (j = i+1; j < nrequest; j++) { jrq = requests[j_sorted[j]]; if (jrq->cut) jcut = jrq->cutoff; else jcut = cutneighmax; - if (jcut <= cutoff_min) { + if (jcut < cutoff_min) { cutoff_min = jcut; jmin = j; } } + int tmp = j_sorted[i]; j_sorted[i] = j_sorted[jmin]; j_sorted[jmin] = tmp;