From bf6007fd78342f7a31c34097dd8305660f561e46 Mon Sep 17 00:00:00 2001
From: sjplimp <sjplimp@f3b2605a-c512-4ea7-a41b-209d697bcdaa>
Date: Mon, 22 Oct 2007 17:45:06 +0000
Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@1070
 f3b2605a-c512-4ea7-a41b-209d697bcdaa

---
 src/neigh_list.cpp |  2 +-
 src/neighbor.cpp   | 18 ++++++++++++++----
 src/neighbor.h     |  2 +-
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/neigh_list.cpp b/src/neigh_list.cpp
index ed58a114e5..93d8289541 100644
--- a/src/neigh_list.cpp
+++ b/src/neigh_list.cpp
@@ -105,7 +105,7 @@ NeighList::~NeighList()
 
 void NeighList::grow(int nmax)
 {
-  // skip if grow not needed (don't think this should happen)
+  // skip if grow not needed
 
   if (nmax <= maxlocal) return;
   maxlocal = nmax;
diff --git a/src/neighbor.cpp b/src/neighbor.cpp
index 6f0d193f51..7ed8315211 100644
--- a/src/neighbor.cpp
+++ b/src/neighbor.cpp
@@ -548,6 +548,7 @@ void Neighbor::init()
 
     // allocate atom arrays and 1st pages of lists that store them
 
+    maxlocal = atom->nmax;
     for (i = 0; i < nlist; i++)
       if (lists[i]->growflag) {
 	lists[i]->grow(maxlocal);
@@ -962,7 +963,7 @@ void Neighbor::build()
   }
 
   // if necessary, extend atom arrays in pairwise lists
-  // only done for lists with growflag set which are used every reneighbor
+  // only for lists with growflag set and which are used every reneighbor
 
   if (atom->nlocal > maxlocal) {
     maxlocal = atom->nmax;
@@ -978,7 +979,7 @@ void Neighbor::build()
   }
 
   // invoke building of pair and molecular neighbor lists
-  // only done for pairwise lists with buildflag set
+  // only for pairwise lists with buildflag set
 
   for (i = 0; i < nblist; i++)
     (this->*pair_build[blist[i]])(lists[blist[i]]);
@@ -998,14 +999,23 @@ void Neighbor::build()
 
 void Neighbor::build_one(int i)
 {
-  // grow atom arrays and update stencils depending on growflag & stencilflag
+  // update stencils and grow atom arrays and bins
+  // only for relevant settings of stencilflag and growflag
+  // do not reset maxlocal to atom->nmax, since not all lists are being grown
 
-  if (lists[i]->growflag) lists[i]->grow(maxlocal);
   if (lists[i]->stencilflag) {
     lists[i]->stencil_allocate(smax,style);
     (this->*stencil_create[i])(lists[i],sx,sy,sz);
   }
 
+  if (lists[i]->growflag) lists[i]->grow(maxlocal);
+
+  if (style != NSQ && atom->nmax > maxbin) {
+    maxbin = atom->nmax;
+    memory->sfree(bins);
+    bins = (int *) memory->smalloc(maxbin*sizeof(int),"bins");
+  }
+
   (this->*pair_build[i])(lists[i]);
 }
 
diff --git a/src/neighbor.h b/src/neighbor.h
index 6a3ff2f6fa..e48e326352 100644
--- a/src/neighbor.h
+++ b/src/neighbor.h
@@ -72,7 +72,7 @@ class Neighbor : protected Pointers {
  private:
   int me,nprocs;
 
-  int maxlocal;                    // size of numneigh, firstneigh arrays
+  int maxlocal;                    // size of atom-based NeighList arrays
   int maxbond,maxangle,maxdihedral,maximproper;   // size of bond lists
 
   int must_check;                  // 1 if must check other classes to reneigh
-- 
GitLab