diff --git a/src/atom.cpp b/src/atom.cpp index 6486f2a323..06c919fb3b 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -233,14 +233,19 @@ Atom::~Atom() // delete custom atom arrays for (int i = 0; i < nivector; i++) { - memory->destroy(ivector[i]); delete [] iname[i]; + memory->destroy(ivector[i]); } for (int i = 0; i < ndvector; i++) { - memory->destroy(dvector[i]); delete [] dname[i]; + memory->destroy(dvector[i]); } + memory->sfree(iname); + memory->sfree(dname); + memory->sfree(ivector); + memory->sfree(dvector); + // delete per-type arrays delete [] mass; diff --git a/src/compute_property_atom.cpp b/src/compute_property_atom.cpp index 382286fec6..6ffa1a0794 100644 --- a/src/compute_property_atom.cpp +++ b/src/compute_property_atom.cpp @@ -43,6 +43,7 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : // customize a new keyword by adding to if statement pack_choice = new FnPtrPack[nvalues]; + index = new int[nvalues]; int i; for (int iarg = 3; iarg < narg; iarg++) { @@ -336,6 +337,21 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : "atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_corner3z; + } else if (strstr(arg[iarg],"i_") == arg[iarg]) { + int flag; + index[i] = atom->find_custom(&arg[iarg][2],flag); + if (index[i] < 0 || flag != 0) + error->all(FLERR,"Compute property/atom floating point " + "vector does not exist"); + pack_choice[i] = &ComputePropertyAtom::pack_iname; + } else if (strstr(arg[iarg],"d_") == arg[iarg]) { + int flag; + index[i] = atom->find_custom(&arg[iarg][2],flag); + if (index[i] < 0 || flag != 1) + error->all(FLERR,"Compute property/atom integer " + "vector does not exist"); + pack_choice[i] = &ComputePropertyAtom::pack_dname; + } else error->all(FLERR,"Invalid keyword in compute property/atom command"); } @@ -349,6 +365,7 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : ComputePropertyAtom::~ComputePropertyAtom() { delete [] pack_choice; + delete [] index; memory->destroy(vector); memory->destroy(array); } @@ -1667,3 +1684,33 @@ void ComputePropertyAtom::pack_corner3z(int n) n += nvalues; } } + +/* ---------------------------------------------------------------------- */ + +void ComputePropertyAtom::pack_iname(int n) +{ + int *ivector = atom->ivector[index[n]]; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = ivector[i]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void ComputePropertyAtom::pack_dname(int n) +{ + double *dvector = atom->dvector[index[n]]; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = dvector[i]; + else buf[n] = 0.0; + n += nvalues; + } +} diff --git a/src/compute_property_atom.h b/src/compute_property_atom.h index bc8a4b0528..933fa2051a 100644 --- a/src/compute_property_atom.h +++ b/src/compute_property_atom.h @@ -35,6 +35,7 @@ class ComputePropertyAtom : public Compute { private: int nvalues; int nmax; + int *index; double *vector; double **array; double *buf; @@ -119,6 +120,9 @@ class ComputePropertyAtom : public Compute { void pack_corner3x(int); void pack_corner3y(int); void pack_corner3z(int); + + void pack_iname(int); + void pack_dname(int); }; } diff --git a/src/set.cpp b/src/set.cpp index f4f71942d7..0a3833741c 100644 --- a/src/set.cpp +++ b/src/set.cpp @@ -43,7 +43,7 @@ enum{ATOM_SELECT,MOL_SELECT,TYPE_SELECT,GROUP_SELECT,REGION_SELECT}; enum{TYPE,TYPE_FRACTION,MOLECULE,X,Y,Z,CHARGE,MASS,SHAPE,LENGTH,TRI, DIPOLE,DIPOLE_RANDOM,QUAT,QUAT_RANDOM,THETA,ANGMOM, DIAMETER,DENSITY,VOLUME,IMAGE,BOND,ANGLE,DIHEDRAL,IMPROPER, - MESO_E,MESO_CV,MESO_RHO}; + MESO_E,MESO_CV,MESO_RHO,INAME,DNAME}; #define BIG INT_MAX @@ -384,6 +384,28 @@ void Set::command(int narg, char **arg) set(MESO_RHO); iarg += 2; + } else if (strstr(arg[iarg],"i_") == arg[iarg]) { + if (iarg+2 > narg) error->all(FLERR,"Illegal set command"); + if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) varparse(arg[iarg+1],1); + else ivalue = force->numeric(FLERR,arg[iarg+1]); + int flag; + index_custom = atom->find_custom(&arg[iarg][2],flag); + if (index_custom < 0 || flag != 0) + error->all(FLERR,"Set command integer vector does not exist"); + set(INAME); + iarg += 2; + + } else if (strstr(arg[iarg],"i_") == arg[iarg]) { + if (iarg+2 > narg) error->all(FLERR,"Illegal set command"); + if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) varparse(arg[iarg+1],1); + else dvalue = force->numeric(FLERR,arg[iarg+1]); + int flag; + index_custom = atom->find_custom(&arg[iarg][2],flag); + if (index_custom < 0 || flag != 1) + error->all(FLERR,"Set command floating point vector does not exist"); + set(DNAME); + iarg += 2; + } else error->all(FLERR,"Illegal set command"); // statistics @@ -652,6 +674,16 @@ void Set::set(int keyword) atom->angmom[i][2] = zvalue; } + // set value for custom integer or double vector + + else if (keyword == INAME) { + atom->ivector[index_custom][i] = ivalue; + } + + else if (keyword == DNAME) { + atom->dvector[index_custom][i] = dvalue; + } + count++; } diff --git a/src/set.h b/src/set.h index 4873a2c0b4..1c31ec5110 100644 --- a/src/set.h +++ b/src/set.h @@ -32,7 +32,7 @@ class Set : protected Pointers { private: char *id; int *select; - int style,ivalue,newtype,count; + int style,ivalue,newtype,count,index_custom; int ximage,yimage,zimage,ximageflag,yimageflag,zimageflag; double dvalue,xvalue,yvalue,zvalue,wvalue,fraction;