forked from lijiext/lammps
git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@3551 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
parent
664fa43717
commit
823cbd55b3
|
@ -0,0 +1,202 @@
|
|||
/* ----------------------------------------------------------------------
|
||||
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.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing authors: Paul Crozier (SNL), Jeff Greathouse (SNL)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "mpi.h"
|
||||
#include "math.h"
|
||||
#include "stdlib.h"
|
||||
#include "compute_rdf.h"
|
||||
#include "atom.h"
|
||||
#include "update.h"
|
||||
#include "force.h"
|
||||
#include "pair.h"
|
||||
#include "neighbor.h"
|
||||
#include "neigh_request.h"
|
||||
#include "neigh_list.h"
|
||||
#include "group.h"
|
||||
#include "memory.h"
|
||||
#include "error.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
ComputeRDF::ComputeRDF(LAMMPS *lmp, int narg, char **arg) :
|
||||
Compute(lmp, narg, arg)
|
||||
{
|
||||
if (narg < 8 || (narg-6) % 2) error->all("Illegal compute rdf command");
|
||||
|
||||
array_flag = 1;
|
||||
size_array_rows = 1;
|
||||
size_array_cols = 1;
|
||||
extarray = 1;
|
||||
|
||||
maxbin = atoi(arg[5]);
|
||||
|
||||
npairs = 0;
|
||||
rdfpair = memory->create_2d_int_array(atom->ntypes+1,atom->ntypes+1,
|
||||
"rdf:rdfpair");
|
||||
|
||||
for (int i = 1; i <= atom->ntypes; i++)
|
||||
for (int j = 1; j <= atom->ntypes; j++)
|
||||
rdfpair[i][j] = 0;
|
||||
|
||||
int itype,jtype;
|
||||
for (int i = 6; i < narg; i += 2) {
|
||||
itype = atoi(arg[i]);
|
||||
jtype = atoi(arg[i+1]);
|
||||
if (itype < 1 || jtype < 1 || itype > atom->ntypes || jtype > atom->ntypes)
|
||||
error->all("Invalid atom type in compute rdf command");
|
||||
npairs++;
|
||||
rdfpair[itype][jtype] = npairs;
|
||||
}
|
||||
|
||||
hist = memory->create_2d_double_array(maxbin,npairs+1,"rdf:hist");
|
||||
array = memory->create_2d_double_array(maxbin,npairs+1,"rdf:array");
|
||||
|
||||
int *nrdfatom = new int[atom->ntypes+1];
|
||||
for (int i = 1; i <= atom->ntypes; i++) nrdfatom[i] = 0;
|
||||
|
||||
int *mask = atom->mask;
|
||||
int *type = atom->type;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) nrdfatom[type[i]]++;
|
||||
|
||||
nrdfatoms = new int[atom->ntypes+1];
|
||||
MPI_Allreduce(&nrdfatom[1],&nrdfatoms[1],atom->ntypes,MPI_INT,MPI_SUM,world);
|
||||
delete [] nrdfatom;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
ComputeRDF::~ComputeRDF()
|
||||
{
|
||||
memory->destroy_2d_int_array(rdfpair);
|
||||
memory->destroy_2d_double_array(hist);
|
||||
delete [] nrdfatoms;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void ComputeRDF::init()
|
||||
{
|
||||
if (force->pair) delr = force->pair->cutforce / maxbin;
|
||||
else error->all("Compute rdf requires a pair style be defined");
|
||||
delrinv = 1.0/delr;
|
||||
|
||||
// need an occasional half neighbor list
|
||||
|
||||
int irequest = neighbor->request((void *) this);
|
||||
neighbor->requests[irequest]->pair = 0;
|
||||
neighbor->requests[irequest]->compute = 1;
|
||||
neighbor->requests[irequest]->occasional = 1;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void ComputeRDF::init_list(int id, NeighList *ptr)
|
||||
{
|
||||
list = ptr;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void ComputeRDF::compute_array()
|
||||
{
|
||||
invoked_array = update->ntimestep;
|
||||
|
||||
double **x = atom->x;
|
||||
int *mask = atom->mask;
|
||||
int nlocal = atom->nlocal;
|
||||
int *type = atom->type;
|
||||
double *special_coul = force->special_coul;
|
||||
double *special_lj = force->special_lj;
|
||||
int nall = atom->nlocal + atom->nghost;
|
||||
int newton_pair = force->newton_pair;
|
||||
|
||||
int i,j,ii,jj,inum,jnum,itype,jtype,ipair,jpair,bin;
|
||||
double xtmp,ytmp,ztmp,delx,dely,delz,r;
|
||||
int *ilist,*jlist,*numneigh,**firstneigh;
|
||||
|
||||
// invoke half neighbor list (will copy or build if necessary)
|
||||
|
||||
neighbor->build_one(list->index);
|
||||
|
||||
inum = list->inum;
|
||||
ilist = list->ilist;
|
||||
numneigh = list->numneigh;
|
||||
firstneigh = list->firstneigh;
|
||||
|
||||
// zero the histogram counts
|
||||
|
||||
for (int i = 0; i < maxbin; i++)
|
||||
for (int j = 0; j < npairs; j++)
|
||||
hist[i][j] = 0;
|
||||
|
||||
// tally the RDF
|
||||
// both atom i and j must be in fix group
|
||||
// itype,jtype must have been specified by user
|
||||
// weighting factor must be != 0.0 for this pair
|
||||
// could be 0 and still be in neigh list for long-range Coulombics
|
||||
// count the interaction once even if neighbor pair is stored on 2 procs
|
||||
// if itype = jtype, count the interaction twice
|
||||
|
||||
for (ii = 0; ii < inum; ii++) {
|
||||
i = ilist[ii];
|
||||
if (mask[i] & groupbit) {
|
||||
xtmp = x[i][0];
|
||||
ytmp = x[i][1];
|
||||
ztmp = x[i][2];
|
||||
itype = type[i];
|
||||
jlist = firstneigh[i];
|
||||
jnum = numneigh[i];
|
||||
|
||||
for (jj = 0; jj < jnum; jj++) {
|
||||
j = jlist[jj];
|
||||
|
||||
if (j >= nall) {
|
||||
if (special_coul[j/nall] == 0.0 && special_lj[j/nall] == 0.0)
|
||||
continue;
|
||||
j %= nall;
|
||||
}
|
||||
|
||||
if (mask[j] & groupbit) {
|
||||
jtype = type[j];
|
||||
ipair = rdfpair[itype][jtype];
|
||||
jpair = rdfpair[jtype][itype];
|
||||
if (!ipair && !jpair) continue;
|
||||
|
||||
delx = xtmp - x[j][0];
|
||||
dely = ytmp - x[j][1];
|
||||
delz = ztmp - x[j][2];
|
||||
r = sqrt(delx*delx + dely*dely + delz*delz);
|
||||
bin = static_cast<int> (r*delrinv);
|
||||
if (bin >= maxbin) continue;
|
||||
|
||||
if (ipair) hist[bin][ipair-1]++;
|
||||
if (newton_pair || j < nlocal)
|
||||
if (jpair) hist[bin][jpair-1]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sum histogram across procs
|
||||
|
||||
MPI_Allreduce(hist[0],array[0],maxbin*npairs,MPI_DOUBLE,MPI_SUM,world);
|
||||
}
|
|
@ -11,27 +11,31 @@
|
|||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef FIX_COM_H
|
||||
#define FIX_COM_H
|
||||
#ifndef COMPUTE_RDF_H
|
||||
#define COMPUTE_RDF_H
|
||||
|
||||
#include "stdio.h"
|
||||
#include "fix.h"
|
||||
#include "compute.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class FixCOM : public Fix {
|
||||
class ComputeRDF : public Compute {
|
||||
public:
|
||||
FixCOM(class LAMMPS *, int, char **);
|
||||
~FixCOM();
|
||||
int setmask();
|
||||
ComputeRDF(class LAMMPS *, int, char **);
|
||||
~ComputeRDF();
|
||||
void init();
|
||||
void setup(int);
|
||||
void end_of_step();
|
||||
void init_list(int, class NeighList *);
|
||||
void compute_array();
|
||||
|
||||
private:
|
||||
int me,first;
|
||||
FILE *fp;
|
||||
double masstotal;
|
||||
int first;
|
||||
int maxbin; // # of rdf bins
|
||||
int npairs; // # of rdf pairs
|
||||
double delr,delrinv; // bin width and its inverse
|
||||
int **rdfpair; // mapping from 2 types to rdf pair
|
||||
double **hist; // histogram bins
|
||||
int *nrdfatoms; // # of atoms of each type in the group
|
||||
class NeighList *list; // half neighbor list
|
||||
};
|
||||
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/* ----------------------------------------------------------------------
|
||||
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_com.h"
|
||||
#include "atom.h"
|
||||
#include "update.h"
|
||||
#include "domain.h"
|
||||
#include "group.h"
|
||||
#include "error.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixCOM::FixCOM(LAMMPS *lmp, int narg, char **arg) :
|
||||
Fix(lmp, narg, arg)
|
||||
{
|
||||
if (narg != 5) error->all("Illegal fix com command");
|
||||
nevery = atoi(arg[3]);
|
||||
if (nevery <= 0) error->all("Illegal fix com command");
|
||||
first = 1;
|
||||
|
||||
MPI_Comm_rank(world,&me);
|
||||
if (me == 0) {
|
||||
fp = fopen(arg[4],"w");
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
sprintf(str,"Cannot open fix com file %s",arg[4]);
|
||||
error->one(str);
|
||||
}
|
||||
}
|
||||
|
||||
if (me == 0) {
|
||||
fprintf(fp,"# Center-of-mass for group %s\n",group->names[igroup]);
|
||||
fprintf(fp,"# TimeStep x y z\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixCOM::~FixCOM()
|
||||
{
|
||||
if (me == 0) fclose(fp);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
int FixCOM::setmask()
|
||||
{
|
||||
int mask = 0;
|
||||
mask |= END_OF_STEP;
|
||||
return mask;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixCOM::init()
|
||||
{
|
||||
masstotal = group->mass(igroup);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixCOM::setup(int vflag)
|
||||
{
|
||||
if (first) end_of_step();
|
||||
first = 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixCOM::end_of_step()
|
||||
{
|
||||
double xcm[3];
|
||||
group->xcm(igroup,masstotal,xcm);
|
||||
|
||||
if (me == 0) {
|
||||
fprintf(fp,"%d %g %g %g\n",update->ntimestep,xcm[0],xcm[1],xcm[2]);
|
||||
fflush(fp);
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/* ----------------------------------------------------------------------
|
||||
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_gyration.h"
|
||||
#include "atom.h"
|
||||
#include "update.h"
|
||||
#include "domain.h"
|
||||
#include "group.h"
|
||||
#include "error.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixGyration::FixGyration(LAMMPS *lmp, int narg, char **arg) :
|
||||
Fix(lmp, narg, arg)
|
||||
{
|
||||
if (narg != 5) error->all("Illegal fix gyration command");
|
||||
nevery = atoi(arg[3]);
|
||||
if (nevery <= 0) error->all("Illegal fix gyration command");
|
||||
first = 1;
|
||||
|
||||
MPI_Comm_rank(world,&me);
|
||||
if (me == 0) {
|
||||
fp = fopen(arg[4],"w");
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
sprintf(str,"Cannot open fix gyration file %s",arg[4]);
|
||||
error->one(str);
|
||||
}
|
||||
}
|
||||
|
||||
if (me == 0) {
|
||||
fprintf(fp,"# Radius-of-gyration for group %s\n",group->names[igroup]);
|
||||
fprintf(fp,"# TimeStep Rg\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixGyration::~FixGyration()
|
||||
{
|
||||
if (me == 0) fclose(fp);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
int FixGyration::setmask()
|
||||
{
|
||||
int mask = 0;
|
||||
mask |= END_OF_STEP;
|
||||
return mask;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixGyration::init()
|
||||
{
|
||||
masstotal = group->mass(igroup);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixGyration::setup(int vflag)
|
||||
{
|
||||
if (first) end_of_step();
|
||||
first = 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixGyration::end_of_step()
|
||||
{
|
||||
double xcm[3];
|
||||
group->xcm(igroup,masstotal,xcm);
|
||||
double rg = group->gyration(igroup,masstotal,xcm);
|
||||
|
||||
if (me == 0) {
|
||||
fprintf(fp,"%d %g\n",update->ntimestep,rg);
|
||||
fflush(fp);
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/* ----------------------------------------------------------------------
|
||||
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_GYRATION_H
|
||||
#define FIX_GYRATION_H
|
||||
|
||||
#include "stdio.h"
|
||||
#include "fix.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class FixGyration : public Fix {
|
||||
public:
|
||||
FixGyration(class LAMMPS *, int, char **);
|
||||
~FixGyration();
|
||||
int setmask();
|
||||
void init();
|
||||
void setup(int);
|
||||
void end_of_step();
|
||||
|
||||
private:
|
||||
int me,first;
|
||||
FILE *fp;
|
||||
double masstotal;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
355
src/fix_msd.cpp
355
src/fix_msd.cpp
|
@ -1,355 +0,0 @@
|
|||
/* ----------------------------------------------------------------------
|
||||
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_msd.h"
|
||||
#include "atom.h"
|
||||
#include "update.h"
|
||||
#include "domain.h"
|
||||
#include "group.h"
|
||||
#include "modify.h"
|
||||
#include "memory.h"
|
||||
#include "error.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixMSD::FixMSD(LAMMPS *lmp, int narg, char **arg) :
|
||||
Fix(lmp, narg, arg)
|
||||
{
|
||||
if (narg < 5) error->all("Illegal fix msd command");
|
||||
nevery = atoi(arg[3]);
|
||||
if (nevery <= 0) error->all("Illegal fix msd command");
|
||||
first = 1;
|
||||
restart_peratom = 1;
|
||||
|
||||
MPI_Comm_rank(world,&me);
|
||||
if (me == 0) {
|
||||
fp = fopen(arg[4],"w");
|
||||
if (fp == NULL) {
|
||||
char str[128];
|
||||
sprintf(str,"Cannot open fix msd file %s",arg[4]);
|
||||
error->one(str);
|
||||
}
|
||||
}
|
||||
|
||||
if (me == 0) {
|
||||
fprintf(fp,"# Mean-squared Displacement for group %s\n",
|
||||
group->names[igroup]);
|
||||
fprintf(fp,"# TimeStep x y z total\n");
|
||||
}
|
||||
|
||||
// optional args
|
||||
|
||||
comflag = 0;
|
||||
|
||||
int iarg = 5;
|
||||
while (iarg < narg) {
|
||||
if (strcmp(arg[iarg],"com") == 0) {
|
||||
if (iarg+2 > narg) error->all("Illegal fix msd command");
|
||||
if (strcmp(arg[iarg+1],"no") == 0) comflag = 0;
|
||||
else if (strcmp(arg[iarg+1],"yes") == 0) comflag = 1;
|
||||
else error->all("Illegal fix msd command");
|
||||
iarg += 2;
|
||||
} else error->all("Illegal fix msd command");
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// cm = original center of mass
|
||||
|
||||
double cm[3];
|
||||
|
||||
if (comflag) {
|
||||
masstotal = group->mass(igroup);
|
||||
group->xcm(igroup,masstotal,cm);
|
||||
}
|
||||
|
||||
// xoriginal = initial unwrapped positions of atoms
|
||||
// relative to center of mass if comflag is set
|
||||
|
||||
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]);
|
||||
if (comflag) {
|
||||
xoriginal[i][0] -= cm[0];
|
||||
xoriginal[i][1] -= cm[1];
|
||||
xoriginal[i][2] -= cm[2];
|
||||
}
|
||||
} else xoriginal[i][0] = xoriginal[i][1] = xoriginal[i][2] = 0.0;
|
||||
}
|
||||
|
||||
// nmsd = # of atoms in group
|
||||
|
||||
nmsd = 0;
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) nmsd++;
|
||||
|
||||
int nmsd_all;
|
||||
MPI_Allreduce(&nmsd,&nmsd_all,1,MPI_INT,MPI_SUM,world);
|
||||
nmsd = nmsd_all;
|
||||
|
||||
if (nmsd == 0) error->all("Fix msd group has no atoms");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixMSD::~FixMSD()
|
||||
{
|
||||
if (me == 0) fclose(fp);
|
||||
|
||||
// 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 FixMSD::setmask()
|
||||
{
|
||||
int mask = 0;
|
||||
mask |= END_OF_STEP;
|
||||
return mask;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixMSD::init()
|
||||
{
|
||||
// warn if more than one msd fix
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < modify->nfix; i++)
|
||||
if (strcmp(modify->fix[i]->style,"msd") == 0) count++;
|
||||
if (count > 1 && me == 0) error->warning("More than one fix msd");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixMSD::setup(int vflag)
|
||||
{
|
||||
if (first) end_of_step();
|
||||
first = 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixMSD::end_of_step()
|
||||
{
|
||||
// cm = current center of mass
|
||||
|
||||
double cm[3];
|
||||
|
||||
if (comflag) {
|
||||
group->mass(igroup);
|
||||
group->xcm(igroup,masstotal,cm);
|
||||
}
|
||||
|
||||
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;
|
||||
double msd[4];
|
||||
msd[0] = msd[1] = msd[2] = msd[3] = 0.0;
|
||||
|
||||
// dx,dy,dz = displacement of atom from original position
|
||||
// relative to center of mass if comflag is set
|
||||
// for triclinic, need to unwrap current atom coord via h matrix
|
||||
|
||||
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;
|
||||
if (comflag) {
|
||||
dx = x[i][0] + xbox*xprd - cm[0] - xoriginal[i][0];
|
||||
dy = x[i][1] + ybox*yprd - cm[1] - xoriginal[i][1];
|
||||
dz = x[i][2] + zbox*zprd - cm[2] - xoriginal[i][2];
|
||||
} else {
|
||||
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];
|
||||
}
|
||||
msd[0] += dx*dx;
|
||||
msd[1] += dy*dy;
|
||||
msd[2] += dz*dz;
|
||||
msd[3] += dx*dx + dy*dy + dz*dz;
|
||||
}
|
||||
|
||||
} 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;
|
||||
if (comflag) {
|
||||
dx = x[i][0] + h[0]*xbox + h[5]*ybox + h[4]*zbox -
|
||||
cm[0] - xoriginal[i][0];
|
||||
dy = x[i][1] + h[1]*ybox + h[3]*zbox - cm[1] - xoriginal[i][1];
|
||||
dz = x[i][2] + h[2]*zbox - cm[2] - xoriginal[i][2];
|
||||
} else {
|
||||
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];
|
||||
}
|
||||
msd[0] += dx*dx;
|
||||
msd[1] += dy*dy;
|
||||
msd[2] += dz*dz;
|
||||
msd[3] += dx*dx + dy*dy + dz*dz;
|
||||
}
|
||||
}
|
||||
|
||||
double msd_all[4];
|
||||
MPI_Allreduce(msd,msd_all,4,MPI_DOUBLE,MPI_SUM,world);
|
||||
msd_all[0] /= nmsd;
|
||||
msd_all[1] /= nmsd;
|
||||
msd_all[2] /= nmsd;
|
||||
msd_all[3] /= nmsd;
|
||||
|
||||
if (me == 0) {
|
||||
fprintf(fp,"%d %g %g %g %g\n",update->ntimestep,
|
||||
msd_all[0],msd_all[1],msd_all[2],msd_all[3]);
|
||||
fflush(fp);
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
memory usage of local atom-based array
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
double FixMSD::memory_usage()
|
||||
{
|
||||
double bytes = atom->nmax*3 * sizeof(double);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
allocate atom-based array
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void FixMSD::grow_arrays(int nmax)
|
||||
{
|
||||
xoriginal =
|
||||
memory->grow_2d_double_array(xoriginal,nmax,3,"msd:xoriginal");
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
copy values within local atom-based array
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void FixMSD::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 FixMSD::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 FixMSD::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 FixMSD::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 FixMSD::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 FixMSD::maxsize_restart()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
size of atom nlocal's restart data
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
int FixMSD::size_restart(int nlocal)
|
||||
{
|
||||
return 4;
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/* ----------------------------------------------------------------------
|
||||
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_MSD_H
|
||||
#define FIX_MSD_H
|
||||
|
||||
#include "stdio.h"
|
||||
#include "fix.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class FixMSD : public Fix {
|
||||
public:
|
||||
FixMSD(class LAMMPS *, int, char **);
|
||||
~FixMSD();
|
||||
int setmask();
|
||||
void init();
|
||||
void setup(int);
|
||||
void end_of_step();
|
||||
|
||||
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:
|
||||
int me,first,comflag;
|
||||
FILE *fp;
|
||||
double masstotal;
|
||||
|
||||
int nmsd; // # of atoms in group
|
||||
double **xoriginal; // original coords of atoms
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -90,6 +90,7 @@ CommandStyle(write_restart,WriteRestart)
|
|||
#include "compute_pe.h"
|
||||
#include "compute_pe_atom.h"
|
||||
#include "compute_pressure.h"
|
||||
#include "compute_rdf.h"
|
||||
#include "compute_reduce.h"
|
||||
#include "compute_reduce_region.h"
|
||||
#include "compute_erotate_sphere.h"
|
||||
|
@ -120,6 +121,7 @@ ComputeStyle(msd,ComputeMSD)
|
|||
ComputeStyle(pe,ComputePE)
|
||||
ComputeStyle(pe/atom,ComputePEAtom)
|
||||
ComputeStyle(pressure,ComputePressure)
|
||||
ComputeStyle(rdf,ComputeRDF)
|
||||
ComputeStyle(reduce,ComputeReduce)
|
||||
ComputeStyle(reduce/region,ComputeReduceRegion)
|
||||
ComputeStyle(erotate/sphere,ComputeERotateSphere)
|
||||
|
@ -165,7 +167,6 @@ DumpStyle(xyz,DumpXYZ)
|
|||
#include "fix_ave_spatial.h"
|
||||
#include "fix_ave_time.h"
|
||||
#include "fix_box_relax.h"
|
||||
#include "fix_com.h"
|
||||
#include "fix_coord_original.h"
|
||||
#include "fix_deform.h"
|
||||
#include "fix_deposit.h"
|
||||
|
@ -175,13 +176,11 @@ DumpStyle(xyz,DumpXYZ)
|
|||
#include "fix_enforce2d.h"
|
||||
#include "fix_evaporate.h"
|
||||
#include "fix_gravity.h"
|
||||
#include "fix_gyration.h"
|
||||
#include "fix_heat.h"
|
||||
#include "fix_indent.h"
|
||||
#include "fix_langevin.h"
|
||||
#include "fix_lineforce.h"
|
||||
#include "fix_minimize.h"
|
||||
#include "fix_msd.h"
|
||||
#include "fix_momentum.h"
|
||||
#include "fix_move.h"
|
||||
#include "fix_nph.h"
|
||||
|
@ -228,7 +227,6 @@ FixStyle(ave/histo,FixAveHisto)
|
|||
FixStyle(ave/spatial,FixAveSpatial)
|
||||
FixStyle(ave/time,FixAveTime)
|
||||
FixStyle(box/relax,FixBoxRelax)
|
||||
FixStyle(com,FixCOM)
|
||||
FixStyle(coord/original,FixCoordOriginal)
|
||||
FixStyle(deform,FixDeform)
|
||||
FixStyle(deposit,FixDeposit)
|
||||
|
@ -238,7 +236,6 @@ FixStyle(efield,FixEfield)
|
|||
FixStyle(enforce2d,FixEnforce2D)
|
||||
FixStyle(evaporate,FixEvaporate)
|
||||
FixStyle(gravity,FixGravity)
|
||||
FixStyle(gyration,FixGyration)
|
||||
FixStyle(heat,FixHeat)
|
||||
FixStyle(indent,FixIndent)
|
||||
FixStyle(langevin,FixLangevin)
|
||||
|
@ -246,7 +243,6 @@ FixStyle(lineforce,FixLineForce)
|
|||
FixStyle(MINIMIZE,FixMinimize)
|
||||
FixStyle(momentum,FixMomentum)
|
||||
FixStyle(move,FixMove)
|
||||
FixStyle(msd,FixMSD)
|
||||
FixStyle(nph,FixNPH)
|
||||
FixStyle(npt,FixNPT)
|
||||
FixStyle(npt/sphere,FixNPTSphere)
|
||||
|
|
Loading…
Reference in New Issue