Commit 0a8ca112 authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@4774 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent 3b4a8b53
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -466,6 +466,11 @@ double PairGranHookeHistory::init_one(int i, int j)
void PairGranHookeHistory::write_restart(FILE *fp)
{
  write_restart_settings(fp);

  int i,j;
  for (i = 1; i <= atom->ntypes; i++)
    for (j = i; j <= atom->ntypes; j++)
      fwrite(&setflag[i][j],sizeof(int),1,fp);
}

/* ----------------------------------------------------------------------
@@ -476,6 +481,14 @@ void PairGranHookeHistory::read_restart(FILE *fp)
{
  read_restart_settings(fp);
  allocate();

  int i,j;
  int me = comm->me;
  for (i = 1; i <= atom->ntypes; i++)
    for (j = i; j <= atom->ntypes; j++) {
      if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
      MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
    }
}

/* ----------------------------------------------------------------------
+126 −0
Original line number Diff line number Diff line
/* ----------------------------------------------------------------------
   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
   http://lammps.sandia.gov, Sandia National Laboratories
   Steve Plimpton, sjplimp@sandia.gov

   Copyright (2003) Sandia Corporation.  Under the terms of Contract
   DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
   certain rights in this software.  This software is distributed under 
   the GNU General Public License.

   See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */

#include "stdlib.h"
#include "fix_read_restart.h"
#include "atom.h"
#include "memory.h"

using namespace LAMMPS_NS;

/* ---------------------------------------------------------------------- */

FixReadRestart::FixReadRestart(LAMMPS *lmp, int narg, char **arg) :
  Fix(lmp, narg, arg)
{
  nextra = atoi(arg[3]);
  int nfix = atoi(arg[4]);

  // perform initial allocation of atom-based array
  // register with Atom class

  count = NULL;
  extra = NULL;
  grow_arrays(atom->nmax);
  atom->add_callback(0);

  // extra = copy of atom->extra

  double **atom_extra = atom->extra;
  int nlocal = atom->nlocal;
  int i,j,m;

  for (i = 0; i < nlocal; i++) {
    m = 0;
    for (j = 0; j < nfix; j++) m += static_cast<int> (atom_extra[i][m]);
    count[i] = m;
    for (j = 0; j < m; j++) extra[i][j] = atom_extra[i][j];
  }
}

/* ---------------------------------------------------------------------- */

FixReadRestart::~FixReadRestart()
{
  // unregister callback to this fix from Atom class
 
  atom->delete_callback(id,0);

  // delete locally stored arrays

  memory->sfree(count);
  memory->destroy_2d_double_array(extra);
}

/* ---------------------------------------------------------------------- */

int FixReadRestart::setmask()
{
  int mask = 0;
  return mask;
}

/* ----------------------------------------------------------------------
   memory usage of local atom-based array
------------------------------------------------------------------------- */

double FixReadRestart::memory_usage()
{
  double bytes = atom->nmax*nextra * sizeof(double);
  bytes += atom->nmax * sizeof(int);
  return bytes;
}

/* ----------------------------------------------------------------------
   allocate atom-based array
------------------------------------------------------------------------- */

void FixReadRestart::grow_arrays(int nmax)
{
  count =
    (int *) memory->srealloc(count,nmax*sizeof(int),"read_restart:count");
  extra =
    memory->grow_2d_double_array(extra,nmax,nextra,"read_restart:extra");
}

/* ----------------------------------------------------------------------
   copy values within local atom-based array
------------------------------------------------------------------------- */

void FixReadRestart::copy_arrays(int i, int j)
{
  count[j] = count[i];
  for (int m = 0; m < count[i]; m++) extra[j][m] = extra[i][m];
}

/* ----------------------------------------------------------------------
   pack values in local atom-based array for exchange with another proc
------------------------------------------------------------------------- */

int FixReadRestart::pack_exchange(int i, double *buf)
{
  buf[0] = count[i];
  for (int m = 0; m < count[i]; m++) buf[m+1] = extra[i][m];
  return count[i]+1;
}

/* ----------------------------------------------------------------------
   unpack values in local atom-based array from exchange with another proc
------------------------------------------------------------------------- */

int FixReadRestart::unpack_exchange(int nlocal, double *buf)
{
  count[nlocal] = static_cast<int> (buf[0]);
  for (int m = 0; m < count[nlocal]; m++) extra[nlocal][m] = buf[m+1];
  return count[nlocal]+1;
}

src/fix_read_restart.h

0 → 100644
+49 −0
Original line number Diff line number Diff line
/* ----------------------------------------------------------------------
   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
   http://lammps.sandia.gov, Sandia National Laboratories
   Steve Plimpton, sjplimp@sandia.gov

   Copyright (2003) Sandia Corporation.  Under the terms of Contract
   DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
   certain rights in this software.  This software is distributed under 
   the GNU General Public License.

   See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */

#ifdef FIX_CLASS

FixStyle(READ_RESTART,FixReadRestart)

#else

#ifndef LMP_FIX_READ_RESTART_H
#define LMP_FIX_READ_RESTART_H

#include "fix.h"

namespace LAMMPS_NS {

class FixReadRestart : public Fix {
 public:
  int *count;
  double **extra;

  FixReadRestart(class LAMMPS *, int, char **);
  ~FixReadRestart();
  int setmask();

  double memory_usage();
  void grow_arrays(int);
  void copy_arrays(int, int);
  int pack_exchange(int, double *);
  int unpack_exchange(int, double *);

 private:
  int nextra;          // max number of extra values for any atom
};

}

#endif
#endif
+3 −1
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ Modify::Modify(LAMMPS *lmp) : Pointers(lmp)
  nfix_restart_peratom = 0;
  id_restart_peratom = style_restart_peratom = NULL;
  index_restart_peratom = NULL;
  nfix_restart_save = 0;

  ncompute = maxcompute = 0;
  compute = NULL;
@@ -146,8 +147,9 @@ void Modify::init()
  int i,j;

  // delete storage of restart info since it is not valid after 1st run
  // read_restart sets nfix_restart_save so will persist to actual 1st run

  restart_deallocate();
  if (!nfix_restart_save) restart_deallocate();

  // create lists of fixes to call at each stage of run

+2 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ class Modify : protected Pointers {
  int restart_pbc_any;       // 1 if any fix sets restart_pbc
  int nfix_restart_global;   // stored fix global info from restart file
  int nfix_restart_peratom;  // stored fix peratom info from restart file
  int nfix_restart_save;     // 1 if init() should not whack restart info

  class Fix **fix;           // list of fixes
  int *fmask;                // bit mask for when each fix is applied
Loading