From 6394161a7cd66e3058a0cd3eb6f67a4ab456228d Mon Sep 17 00:00:00 2001
From: sjplimp <sjplimp@f3b2605a-c512-4ea7-a41b-209d697bcdaa>
Date: Tue, 23 Oct 2012 15:51:01 +0000
Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8992
 f3b2605a-c512-4ea7-a41b-209d697bcdaa

---
 src/atom.cpp      |  1 -
 src/atom.h        |  4 ++--
 src/atom_map.cpp  |  8 +++++++-
 src/read_dump.cpp | 27 +++++++++++++++++++++------
 src/rerun.cpp     |  4 ++--
 5 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/src/atom.cpp b/src/atom.cpp
index c7067abc16..0eee4269e0 100644
--- a/src/atom.cpp
+++ b/src/atom.cpp
@@ -237,7 +237,6 @@ Atom::~Atom()
 
   // delete mapping data structures
 
-  memory->destroy(sametag);
   map_delete();
 }
 
diff --git a/src/atom.h b/src/atom.h
index 33ab918af2..bc49b11382 100644
--- a/src/atom.h
+++ b/src/atom.h
@@ -116,6 +116,7 @@ class Atom : protected Pointers {
 
   int map_style;                  // default or user-specified style of map
                                   // 0 = none, 1 = array, 2 = hash
+  int map_tag_max;                // max atom ID that map() is setup for
 
   // spatial sorting of atoms
 
@@ -198,8 +199,7 @@ class Atom : protected Pointers {
 
   // global to local ID mapping
 
-  int map_tag_max;      // size of map_array
-  int *map_array;       // direct map of length max atom ID + 1
+  int *map_array;       // direct map of length map_tag_max + 1
   int smax;             // max size of sametag
 
   struct HashElem {
diff --git a/src/atom_map.cpp b/src/atom_map.cpp
index 33caa87062..93c377b81e 100644
--- a/src/atom_map.cpp
+++ b/src/atom_map.cpp
@@ -244,12 +244,18 @@ void Atom::map_one(int global, int local)
 
 void Atom::map_delete()
 {
+  memory->destroy(sametag);
+  sametag = NULL;
+
   if (map_style == 1) {
-    if (map_tag_max) memory->destroy(map_array);
+    memory->destroy(map_array);
+    map_array = NULL;
   } else {
     if (map_nhash) {
       delete [] map_bucket;
       delete [] map_hash;
+      map_bucket = NULL;
+      map_hash = NULL;
     }
     map_nhash = 0;
   }
diff --git a/src/read_dump.cpp b/src/read_dump.cpp
index f1691ab443..268165c17e 100644
--- a/src/read_dump.cpp
+++ b/src/read_dump.cpp
@@ -86,6 +86,9 @@ ReadDump::~ReadDump()
 
 void ReadDump::command(int narg, char **arg)
 {
+  if (domain->box_exist == 0)
+    error->all(FLERR,"Read_dump command before simulation box is defined");
+
   if (narg < 2) error->all(FLERR,"Illegal read_dump command");
 
   store_files(1,&arg[0]);
@@ -321,14 +324,24 @@ void ReadDump::header(int fieldinfo)
   yhi = box[1][1];
   zlo = box[2][0];
   zhi = box[2][1];
-  xprd = xhi - xlo;
-  yprd = yhi - ylo;
-  zprd = zhi - zlo;
   if (triclinic_snap) {
     xy = box[0][2];
     xz = box[1][2];
     yz = box[2][2];
+    double xdelta = MIN(0.0,xy);
+    xdelta = MIN(xdelta,xz);
+    xdelta = MIN(xdelta,xy+xz);
+    xlo = xlo - xdelta;
+    xdelta = MAX(0.0,xy);
+    xdelta = MAX(xdelta,xz);
+    xdelta = MAX(xdelta,xy+xz);
+    xhi = xhi - xdelta;
+    ylo = ylo - MIN(0.0,yz);
+    yhi = yhi - MAX(0.0,yz);
   }
+  xprd = xhi - xlo;
+  yprd = yhi - ylo;
+  zprd = zhi - zlo;
 
   // done if not checking fields
 
@@ -662,21 +675,23 @@ int ReadDump::fields_and_keywords(int narg, char **arg)
 
 void ReadDump::process_atoms(int n)
 {
-  int i,m,ifield,itype;
+  int i,m,ifield,itype,itag;;
   int xbox,ybox,zbox;
 
   double **x = atom->x;
   double **v = atom->v;
   tagint *image = atom->image;
   int nlocal = atom->nlocal;
+  int map_tag_max = atom->map_tag_max;
 
   for (i = 0; i < n; i++) {
     ucflag[i] = 0;
 
-    // map() call is invalid if purged all atoms
+    // check if new atom matches one I own
     // setting m = -1 forces new atom not to match
 
-    if (!purgeflag) m = atom->map(static_cast<int> (fields[i][0]));
+    itag = static_cast<int> (fields[i][0]);
+    if (itag <= map_tag_max) m = atom->map(static_cast<int> (fields[i][0]));
     else m = -1;
     if (m < 0 || m >= nlocal) continue;
 
diff --git a/src/rerun.cpp b/src/rerun.cpp
index 38078e7626..4edcd70676 100644
--- a/src/rerun.cpp
+++ b/src/rerun.cpp
@@ -35,11 +35,11 @@ Rerun::Rerun(LAMMPS *lmp) : Pointers(lmp) {}
 
 void Rerun::command(int narg, char **arg)
 {
-  if (narg < 2) error->all(FLERR,"Illegal rerun command");
-
   if (domain->box_exist == 0)
     error->all(FLERR,"Rerun command before simulation box is defined");
 
+  if (narg < 2) error->all(FLERR,"Illegal rerun command");
+
   // list of dump files = args until a keyword
 
   int iarg = 0;
-- 
GitLab