/* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator www.cs.sandia.gov/~sjplimp/lammps.html Steve Plimpton, sjplimp@sandia.gov, Sandia National Laboratories 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. ------------------------------------------------------------------------- */ /* * dump_neighbors.cpp * lammps-3Jun05 * * Created by Craig Maloney on 9/29/05. * Copyright 2005 __MyCompanyName__. All rights reserved. * */ #include "string.h" #include "dump_neighbors.h" #include "atom.h" #include "domain.h" #include "update.h" #include "error.h" #include "modify.h" #include "neighbor.h" using namespace std; /* ---------------------------------------------------------------------- */ // Similar to DumpBond DumpNeighbors::DumpNeighbors(int narg, char **arg) : Dump(narg, arg) { if (narg != 5) error->all("Illegal dump neighbors command"); size_one = 4; char *str = "%d %d %d %d %d"; int n = strlen(str) + 1; format_default = new char[n]; strcpy(format_default,str); // one-time file open if (multifile == 0) openfile(); } DumpNeighbors::~DumpNeighbors(){ } /* ---------------------------------------------------------------------- */ // Identical to DumpBond void DumpNeighbors::init() { delete [] format; char *str; if (format_user) str = format_user; else str = format_default; int n = strlen(str) + 2; format = new char[n]; strcpy(format,str); strcat(format,"\n"); } /* ---------------------------------------------------------------------- */ // Identical to DumpBond void DumpNeighbors::write_header(int ndump) { fprintf(fp,"ITEM: TIMESTEP\n"); fprintf(fp,"%d\n",update->ntimestep); fprintf(fp,"ITEM: NUMBER OF PAIRS\n"); fprintf(fp,"%d\n",ndump); fprintf(fp,"ITEM: PAIRS\n"); } /* ---------------------------------------------------------------------- */ int DumpNeighbors::count() { int c=0; int *tag = atom->tag; int *mask = atom->mask; int *type = atom->type; int nlocal = atom->nlocal; int nall = atom->nlocal + atom->nghost; int i,j,k; for (i = 0; i < nlocal; i++) { if (!(mask[i] & groupbit)) continue; int numneigh = neighbor->numneigh[i]; int *neighs = neighbor->firstneigh[i]; for (k = 0; k < numneigh; k++) { j = neighs[k]; if (j >= nall) j = j % nall; if (!(mask[j]&groupbit)) continue; c++; } } return c; } /* ---------------------------------------------------------------------- */ int DumpNeighbors::pack() { // cem // We need to discuss the 1nn bonds... not the static (molecular) // bonds stored in atom_bond. //cem int *tag = atom->tag; int *mask = atom->mask; int *type = atom->type; int nlocal = atom->nlocal; int i,j,k; int nall = atom->nlocal + atom->nghost; int m = 0; for (i = 0; i < nlocal; i++) { if (!(mask[i] & groupbit)) continue; int numneigh = neighbor->numneigh[i]; int *neighs = neighbor->firstneigh[i]; for (k = 0; k < numneigh; k++) { j = neighs[k]; if (j >= nall) j = j % nall; if (!(mask[j]&groupbit)) continue; buf[m++] = tag[i]; buf[m++] = tag[j]; buf[m++] = type[i]; buf[m++] = type[j]; } } return m; } /* ---------------------------------------------------------------------- */ // Identical to DumpBond void DumpNeighbors::write_data(int n, double *buf) { int m = 0; for (int i = 0; i < n; i++) { index++; fprintf(fp,format, index, static_cast (buf[m]), static_cast (buf[m+1]), static_cast (buf[m+2]), static_cast (buf[m+3])); m += size_one; } }