From c76178f38f0acb0c7a21ea3e3f9fd3dad90c135b Mon Sep 17 00:00:00 2001 From: sjplimp Date: Thu, 2 Nov 2006 18:34:47 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@114 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/neighbor.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 932195bf77..13491e9ea7 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -15,6 +15,7 @@ #include "math.h" #include "stdlib.h" #include "string.h" +#include "limits.h" #include "neighbor.h" #include "atom.h" #include "force.h" @@ -831,13 +832,22 @@ void Neighbor::build_full() void Neighbor::setup_bins() { + double cutneighinv = 1.0/cutneigh; + + // test for too many global bins in any dimension due to huge domain + + if (2.0*domain->xprd*cutneighinv > INT_MAX || + 2.0*domain->yprd*cutneighinv > INT_MAX || + 2.0*domain->zprd*cutneighinv > INT_MAX) + error->all("Domain too large for neighbor bins"); + // divide box into bins // optimal size is roughly 1/2 the cutoff - nbinx = static_cast (2.0 * domain->xprd / cutneigh); - nbiny = static_cast (2.0 * domain->yprd / cutneigh); + nbinx = static_cast (2.0*domain->xprd*cutneighinv); + nbiny = static_cast (2.0*domain->yprd*cutneighinv); if (force->dimension == 3) - nbinz = static_cast (2.0 * domain->zprd / cutneigh); + nbinz = static_cast (2.0*domain->zprd*cutneighinv); else nbinz = 1; if (nbinx == 0) nbinx = 1; @@ -891,6 +901,11 @@ void Neighbor::setup_bins() mbinzhi = mbinzhi + 1; mbinz = mbinzhi - mbinzlo + 1; + // test for too many total local bins due to huge domain + + if (1.0*mbinx*mbiny*mbinz > INT_MAX) + error->all("Domain too large for neighbor bins"); + // memory for bin ptrs mbins = mbinx*mbiny*mbinz;