From a1b082b37d79aba72ffe3a795a9bb647cb0a7798 Mon Sep 17 00:00:00 2001
From: sjplimp <sjplimp@f3b2605a-c512-4ea7-a41b-209d697bcdaa>
Date: Fri, 12 Oct 2007 17:34:53 +0000
Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@1034
 f3b2605a-c512-4ea7-a41b-209d697bcdaa

---
 src/fix_deposit.cpp | 40 ++++++++++++++++++++++++++++++++++++++++
 src/fix_deposit.h   |  2 ++
 src/random_park.cpp | 16 ++++++++++++++++
 src/random_park.h   |  2 ++
 4 files changed, 60 insertions(+)

diff --git a/src/fix_deposit.cpp b/src/fix_deposit.cpp
index fbaa5f4b81..396be0acb6 100644
--- a/src/fix_deposit.cpp
+++ b/src/fix_deposit.cpp
@@ -36,6 +36,8 @@ FixDeposit::FixDeposit(LAMMPS *lmp, int narg, char **arg) :
 {
   if (narg < 7) error->all("Illegal fix deposit command");
 
+  restart_global = 1;
+
   // required args
 
   ninsert = atoi(arg[3]);
@@ -315,6 +317,7 @@ void FixDeposit::pre_exchange()
   }
 
   // next timestep to insert
+  // next_reneighbor = 0 if done
 
   if (success) ninserted++;
   if (ninserted < ninsert) next_reneighbor += nfreq;
@@ -388,3 +391,40 @@ void FixDeposit::options(int narg, char **arg)
     } else error->all("Illegal fix deposit command");
   }
 }
+
+/* ----------------------------------------------------------------------
+   pack entire state of Fix into one write 
+------------------------------------------------------------------------- */
+
+void FixDeposit::write_restart(FILE *fp)
+{
+  int n = 0;
+  double list[4];
+  list[n++] = random->state();
+  list[n++] = ninserted;
+  list[n++] = nfirst;
+  list[n++] = next_reneighbor;
+
+  if (comm->me == 0) {
+    int size = n * sizeof(double);
+    fwrite(&size,sizeof(int),1,fp);
+    fwrite(&list,sizeof(double),n,fp);
+  }
+}
+
+/* ----------------------------------------------------------------------
+   use state info from restart file to restart the Fix 
+------------------------------------------------------------------------- */
+
+void FixDeposit::restart(char *buf)
+{
+  int n = 0;
+  double *list = (double *) buf;
+
+  seed = static_cast<int> (list[n++]);
+  ninserted = static_cast<int> (list[n++]);
+  nfirst = static_cast<int> (list[n++]);
+  next_reneighbor = static_cast<int> (list[n++]);
+
+  random->reset(seed);
+}
diff --git a/src/fix_deposit.h b/src/fix_deposit.h
index cb0b685474..211469c903 100644
--- a/src/fix_deposit.h
+++ b/src/fix_deposit.h
@@ -24,6 +24,8 @@ class FixDeposit : public Fix {
   ~FixDeposit();
   int setmask();
   void pre_exchange();
+  void write_restart(FILE *);
+  void restart(char *);
 
  private:
   int ninsert,ntype,nfreq,seed;
diff --git a/src/random_park.cpp b/src/random_park.cpp
index 0c01d1eb8c..385f65c3c1 100644
--- a/src/random_park.cpp
+++ b/src/random_park.cpp
@@ -85,6 +85,15 @@ double RanPark::gaussian()
   return first;
 }
 
+/* ---------------------------------------------------------------------- */
+
+void RanPark::reset(int seed_init)
+{
+  if (seed_init <= 0) error->all("Invalid seed for Park random # generator");
+  seed = seed_init;
+  save = 0;
+}
+
 /* ----------------------------------------------------------------------
    reset the seed based on atom position within box and ibase = caller seed
    combine 3 RNGs based on fractional position in box into one new seed
@@ -135,3 +144,10 @@ void RanPark::reset(int ibase, double *coord)
   uniform();
   uniform();
 }
+
+/* ---------------------------------------------------------------------- */
+
+int RanPark::state()
+{
+  return seed;
+}
diff --git a/src/random_park.h b/src/random_park.h
index e78b8c4f60..8df467000a 100644
--- a/src/random_park.h
+++ b/src/random_park.h
@@ -23,7 +23,9 @@ class RanPark : protected Pointers {
   RanPark(class LAMMPS *, int);
   double uniform();
   double gaussian();
+  void reset(int);
   void reset(int, double *);
+  int state();
 
  private:
   int seed,save;