Commit 823cbd55 authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@3551 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent 664fa437
Loading
Loading
Loading
Loading

src/compute_rdf.cpp

0 → 100644
+202 −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.
------------------------------------------------------------------------- */

/* ----------------------------------------------------------------------
   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);
}
+16 −12
Original line number Diff line number Diff line
@@ -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
};

}

src/fix_com.cpp

deleted100644 → 0
+0 −92
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_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);
  }
}

src/fix_gyration.cpp

deleted100644 → 0
+0 −93
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_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);
  }
}

src/fix_gyration.h

deleted100644 → 0
+0 −39
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_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
Loading