Commit 0808bd4c authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@1292 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent b4fabf0d
Loading
Loading
Loading
Loading
+150 −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 "math.h"
#include "string.h"
#include "compute_displace_atom.h"
#include "atom.h"
#include "domain.h"
#include "modify.h"
#include "fix.h"
#include "memory.h"
#include "error.h"

using namespace LAMMPS_NS;

#define INVOKED_PERATOM 4

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

ComputeDisplaceAtom::ComputeDisplaceAtom(LAMMPS *lmp, int narg, char **arg) :
  Compute(lmp, narg, arg)
{
  if (narg != 4) error->all("Illegal compute displace/atom command");

  peratom_flag = 1;
  size_peratom = 4;

  // store fix ID which stores original atom coords

  int n = strlen(arg[3]) + 1;
  id_fix = new char[n];
  strcpy(id_fix,arg[3]);

  int ifix = modify->find_fix(id_fix);
  if (ifix < 0) error->all("Could not find compute displace/atom fix ID");

  nmax = 0;
  displace = NULL;
}

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

ComputeDisplaceAtom::~ComputeDisplaceAtom()
{
  delete [] id_fix;
  memory->destroy_2d_double_array(displace);
}

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

void ComputeDisplaceAtom::init()
{
  // set fix which stores original atom coords
  // check if is correct style

  int ifix = modify->find_fix(id_fix);
  if (ifix < 0) error->all("Could not find compute displace/atom fix ID");
  fix = modify->fix[ifix];

  if (strcmp(fix->style,"coord/original") != 0)
    error->all("Invalid fix style used in compute displace/atom command");
}

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

void ComputeDisplaceAtom::compute_peratom()
{
  invoked |= INVOKED_PERATOM;

  // grow local displacement array if necessary

  if (atom->nmax > nmax) {
    memory->destroy_2d_double_array(displace);
    nmax = atom->nmax;
    displace =
      memory->create_2d_double_array(nmax,4,"compute/displace/atom:displace");
    vector_atom = displace;
  }

  // dx,dy,dz = displacement of atom from original position
  // original unwrapped position is stored by fix
  // for triclinic, need to unwrap current atom coord via h matrix

  double **xoriginal = fix->vector_atom;

  double **x = atom->x;
  int *mask = atom->mask;
  int *image = atom->image;
  int nlocal = atom->nlocal;

  double *h = domain->h;
  double xprd = domain->xprd;
  double yprd = domain->yprd;
  double zprd = domain->zprd;
  int xbox,ybox,zbox;
  double dx,dy,dz;

  if (domain->triclinic == 0) {
    for (int i = 0; i < nlocal; i++)
      if (mask[i] & groupbit) {
	xbox = (image[i] & 1023) - 512;
	ybox = (image[i] >> 10 & 1023) - 512;
	zbox = (image[i] >> 20) - 512;
	dx = x[i][0] + xbox*xprd - xoriginal[i][0];
	dy = x[i][1] + ybox*yprd - xoriginal[i][1];
	dz = x[i][2] + zbox*zprd - xoriginal[i][2];
	displace[i][0] = dx;
	displace[i][1] = dy;
	displace[i][2] = dz;
	displace[i][3] = sqrt(dx*dx + dy*dy + dz*dz);
      } else displace[i][0] = displace[i][1] =
	       displace[i][2] = displace[i][3] = 0.0;

  } else {
    for (int i = 0; i < nlocal; i++)
      if (mask[i] & groupbit) {
	xbox = (image[i] & 1023) - 512;
	ybox = (image[i] >> 10 & 1023) - 512;
	zbox = (image[i] >> 20) - 512;
	dx = x[i][0] + h[0]*xbox + h[5]*ybox + h[4]*zbox - xoriginal[i][0];
	dy = x[i][1] + h[1]*ybox + h[3]*zbox - xoriginal[i][1];
	dz = x[i][2] + h[2]*zbox - xoriginal[i][2];
	displace[i][0] = dx;
	displace[i][1] = dy;
	displace[i][2] = dz;
	displace[i][3] = sqrt(dx*dx + dy*dy + dz*dz);
      } else displace[i][0] = displace[i][1] =
	       displace[i][2] = displace[i][3] = 0.0;
  }
}

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

double ComputeDisplaceAtom::memory_usage()
{
  double bytes = nmax*4 * sizeof(double);
  return bytes;
}
+38 −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.
------------------------------------------------------------------------- */

#ifndef COMPUTE_DISPLACE_ATOM_H
#define COMPUTE_DISPLACE_ATOM_H

#include "compute.h"

namespace LAMMPS_NS {

class ComputeDisplaceAtom : public Compute {
 public:
  ComputeDisplaceAtom(class LAMMPS *, int, char **);
  ~ComputeDisplaceAtom();
  void init();
  void compute_peratom();
  double memory_usage();

 private:
  int nmax;
  double **displace;
  char *id_fix;
  class Fix *fix;
};

}

#endif
+184 −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 "string.h"
#include "fix_coord_original.h"
#include "atom.h"
#include "domain.h"
#include "group.h"
#include "memory.h"
#include "error.h"

using namespace LAMMPS_NS;

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

FixCoordOriginal::FixCoordOriginal(LAMMPS *lmp, int narg, char **arg) :
  Fix(lmp, narg, arg)
{
  if (narg != 3) error->all("Illegal fix coord/original command");

  restart_peratom = 1;
  peratom_flag = 1;
  size_peratom = 3;
  peratom_freq = 1;

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

  xoriginal = NULL;
  grow_arrays(atom->nmax);
  atom->add_callback(0);
  atom->add_callback(1);

  // xoriginal = initial unwrapped positions of atoms
  
  double **x = atom->x;
  int *mask = atom->mask;
  int *image = atom->image;
  int nlocal = atom->nlocal;

  for (int i = 0; i < nlocal; i++) {
    if (mask[i] & groupbit) domain->unmap(x[i],image[i],xoriginal[i]);
    else xoriginal[i][0] = xoriginal[i][1] = xoriginal[i][2] = 0.0;
  }
}

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

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

  // delete locally stored array

  memory->destroy_2d_double_array(xoriginal);
}

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

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

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

double FixCoordOriginal::memory_usage()
{
  double bytes = atom->nmax*3 * sizeof(double);
  return bytes;
}

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

void FixCoordOriginal::grow_arrays(int nmax)
{
  xoriginal =
    memory->grow_2d_double_array(xoriginal,nmax,3,"fix_msd:xoriginal");
  vector_atom = xoriginal;
}

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

void FixCoordOriginal::copy_arrays(int i, int j)
{
  xoriginal[j][0] = xoriginal[i][0];
  xoriginal[j][1] = xoriginal[i][1];
  xoriginal[j][2] = xoriginal[i][2];
}

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

int FixCoordOriginal::pack_exchange(int i, double *buf)
{
  buf[0] = xoriginal[i][0];
  buf[1] = xoriginal[i][1];
  buf[2] = xoriginal[i][2];
  return 3;
}

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

int FixCoordOriginal::unpack_exchange(int nlocal, double *buf)
{
  xoriginal[nlocal][0] = buf[0];
  xoriginal[nlocal][1] = buf[1];
  xoriginal[nlocal][2] = buf[2];
  return 3;
}

/* ----------------------------------------------------------------------
   pack values in local atom-based arrays for restart file
------------------------------------------------------------------------- */

int FixCoordOriginal::pack_restart(int i, double *buf)
{
  buf[0] = 4;
  buf[1] = xoriginal[i][0];
  buf[2] = xoriginal[i][1];
  buf[3] = xoriginal[i][2];
  return 4;
}

/* ----------------------------------------------------------------------
   unpack values from atom->extra array to restart the fix
------------------------------------------------------------------------- */

void FixCoordOriginal::unpack_restart(int nlocal, int nth)
{
  double **extra = atom->extra;

  // skip to Nth set of extra values

  int m = 0;
  for (int i = 0; i < nth; i++) m += static_cast<int> (extra[nlocal][m]);
  m++;

  xoriginal[nlocal][0] = extra[nlocal][m++];
  xoriginal[nlocal][1] = extra[nlocal][m++];
  xoriginal[nlocal][2] = extra[nlocal][m++];
}

/* ----------------------------------------------------------------------
   maxsize of any atom's restart data
------------------------------------------------------------------------- */

int FixCoordOriginal::maxsize_restart()
{
  return 4;
}

/* ----------------------------------------------------------------------
   size of atom nlocal's restart data
------------------------------------------------------------------------- */

int FixCoordOriginal::size_restart(int nlocal)
{
  return 4;
}
+43 −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.
------------------------------------------------------------------------- */

#ifndef FIX_COORD_ORIGINAL_H
#define FIX_COORD_ORIGINAL_H

#include "fix.h"

namespace LAMMPS_NS {

class FixCoordOriginal : public Fix {
 public:
  FixCoordOriginal(class LAMMPS *, int, char **);
  ~FixCoordOriginal();
  int setmask();

  double memory_usage();
  void grow_arrays(int);
  void copy_arrays(int, int);
  int pack_exchange(int, double *);
  int unpack_exchange(int, double *);
  int pack_restart(int, double *);
  void unpack_restart(int, int);
  int size_restart(int);
  int maxsize_restart();

 private:
  double **xoriginal;         // original coords of atoms
};

}

#endif
+4 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ CommandStyle(write_restart,WriteRestart)
#ifdef ComputeInclude
#include "compute_centro_atom.h"
#include "compute_coord_atom.h"
#include "compute_displace_atom.h"
#include "compute_ke_atom.h"
#include "compute_pe.h"
#include "compute_pe_atom.h"
@@ -96,6 +97,7 @@ CommandStyle(write_restart,WriteRestart)
#ifdef ComputeClass
ComputeStyle(centro/atom,ComputeCentroAtom)
ComputeStyle(coord/atom,ComputeCoordAtom)
ComputeStyle(displace/atom,ComputeDisplaceAtom)
ComputeStyle(ke/atom,ComputeKEAtom)
ComputeStyle(pe,ComputePE)
ComputeStyle(pe/atom,ComputePEAtom)
@@ -138,6 +140,7 @@ DumpStyle(xyz,DumpXYZ)
#include "fix_ave_spatial.h"
#include "fix_ave_time.h"
#include "fix_com.h"
#include "fix_coord_original.h"
#include "fix_deform.h"
#include "fix_deposit.h"
#include "fix_drag.h"
@@ -190,6 +193,7 @@ FixStyle(aveforce,FixAveForce)
FixStyle(ave/spatial,FixAveSpatial)
FixStyle(ave/time,FixAveTime)
FixStyle(com,FixCOM)
FixStyle(coord/original,FixCoordOriginal)
FixStyle(deform,FixDeform)
FixStyle(deposit,FixDeposit)
FixStyle(drag,FixDrag)