From 3082fd0bbbcda25e1dc636df6cd40f39e00b0ad6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 24 Jul 2014 17:23:50 -0400 Subject: [PATCH] add support for custom properties to dump custom --- doc/dump.txt | 8 ++- src/dump_custom.cpp | 159 +++++++++++++++++++++++++++++++++++++++++++- src/dump_custom.h | 6 ++ 3 files changed, 171 insertions(+), 2 deletions(-) diff --git a/doc/dump.txt b/doc/dump.txt index 0497358018..3f83f217ca 100644 --- a/doc/dump.txt +++ b/doc/dump.txt @@ -77,7 +77,9 @@ args = list of arguments for a particular style :l c_ID\[N\] = Nth column of per-atom array calculated by a compute with ID f_ID = per-atom vector calculated by a fix with ID f_ID\[N\] = Nth column of per-atom array calculated by a fix with ID - v_name = per-atom vector calculated by an atom-style variable with name :pre + v_name = per-atom vector calculated by an atom-style variable with name + d_name = per-atom floating point vector with name managed by fix property/atom + i_name = per-atom integer vector with name managed by fix property/atom :pre :ule [Examples:] @@ -549,6 +551,10 @@ invoke other computes, fixes, or variables when they are evaluated, so this is a very general means of creating quantities to output to a dump file. +The {d_name} and {i_name} attributes allow to output custom per atom +floating point or integer properties that are managed by +"fix property/atom"_fix_property_atom.html. + See "Section_modify"_Section_modify.html of the manual for information on how to add new compute and fix styles to LAMMPS to calculate per-atom quantities which could then be output into dump files. diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index a65485883b..3f60b89de2 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -42,7 +42,7 @@ enum{ID,MOL,PROC,TYPE,ELEMENT,MASS, Q,MUX,MUY,MUZ,MU,RADIUS,DIAMETER, OMEGAX,OMEGAY,OMEGAZ,ANGMOMX,ANGMOMY,ANGMOMZ, TQX,TQY,TQZ, - COMPUTE,FIX,VARIABLE}; + COMPUTE,FIX,VARIABLE,INAME,DNAME}; enum{LT,LE,GT,GE,EQ,NEQ}; enum{INT,DOUBLE,STRING,BIGINT}; // same as in DumpCFG @@ -94,6 +94,10 @@ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) : variable = NULL; vbuf = NULL; + ncustom = 0; + id_custom = NULL; + flag_custom = NULL; + // process attributes // ioptional = start of additional optional args // only dump image and dump movie styles process optional args @@ -172,6 +176,10 @@ DumpCustom::~DumpCustom() for (int i = 0; i < nvariable; i++) memory->destroy(vbuf[i]); delete [] vbuf; + for (int i = 0; i < ncustom; i++) delete [] id_custom[i]; + memory->sfree(id_custom); + delete [] flag_custom; + memory->destroy(choose); memory->destroy(dchoose); memory->destroy(clist); @@ -269,6 +277,13 @@ void DumpCustom::init_style() variable[i] = ivariable; } + int icustom; + for (int i = 0; i < ncustom; i++) { + icustom = atom->find_custom(id_custom[i],flag_custom[i]); + if (icustom < 0) + error->all(FLERR,"Could not find custom per-atom property ID"); + } + // set index and check validity of region if (iregion >= 0) { @@ -1241,6 +1256,50 @@ int DumpCustom::parse_fields(int narg, char **arg) field2index[i] = add_variable(suffix); delete [] suffix; + // custom per-atom floating point value = d_ID + + } else if (strncmp(arg[iarg],"d_",2) == 0) { + pack_choice[i] = &DumpCustom::pack_custom; + vtype[i] = DOUBLE; + + int n = strlen(arg[iarg]); + char *suffix = new char[n]; + strcpy(suffix,&arg[iarg][2]); + argindex[i] = 0; + + int tmp = -1; + n = atom->find_custom(suffix,tmp); + if (n < 0) + error->all(FLERR,"Could not find custom per-atom property ID"); + + if (tmp != 1) + error->all(FLERR,"Custom per-atom property ID is not floating point"); + + field2index[i] = add_custom(suffix,1); + delete [] suffix; + + // custom per-atom integer value = i_ID + + } else if (strncmp(arg[iarg],"i_",2) == 0) { + pack_choice[i] = &DumpCustom::pack_custom; + vtype[i] = INT; + + int n = strlen(arg[iarg]); + char *suffix = new char[n]; + strcpy(suffix,&arg[iarg][2]); + argindex[i] = 0; + + int tmp = -1; + n = atom->find_custom(suffix,tmp); + if (n < 0) + error->all(FLERR,"Could not find custom per-atom property ID"); + + if (tmp != 0) + error->all(FLERR,"Custom per-atom property ID is not integer"); + + field2index[i] = add_custom(suffix,0); + delete [] suffix; + } else return iarg; } @@ -1326,6 +1385,34 @@ int DumpCustom::add_variable(char *id) return nvariable-1; } +/* ---------------------------------------------------------------------- + add custom atom property to list used by dump + return index of where this property is in list + if already in list, do not add, just return index, else add to list +------------------------------------------------------------------------- */ + +int DumpCustom::add_custom(char *id, int flag) +{ + int icustom; + for (icustom = 0; icustom < ncustom; icustom++) + if ((strcmp(id,id_custom[icustom]) == 0) + && (flag == flag_custom[icustom])) break; + if (icustom < ncustom) return icustom; + + id_custom = (char **) + memory->srealloc(id_custom,(ncustom+1)*sizeof(char *),"dump:id_custom"); + flag_custom = (int *) + memory->srealloc(flag_custom,(ncustom+1)*sizeof(int),"dump:flag_custom"); + + int n = strlen(id) + 1; + id_custom[ncustom] = new char[n]; + strcpy(id_custom[ncustom],id); + flag_custom[ncustom] = flag; + + ncustom++; + return ncustom-1; +} + /* ---------------------------------------------------------------------- */ int DumpCustom::modify_param(int narg, char **arg) @@ -1566,6 +1653,48 @@ int DumpCustom::modify_param(int narg, char **arg) field2index[nfield+nthresh] = add_variable(suffix); delete [] suffix; + // custom per atom floating point value = d_ID + // must grow field2index and argindex arrays, since access is beyond nfield + + } else if (strncmp(arg[1],"d_",2) == 0) { + thresh_array[nthresh] = DNAME; + memory->grow(field2index,nfield+nthresh+1,"dump:field2index"); + memory->grow(argindex,nfield+nthresh+1,"dump:argindex"); + int n = strlen(arg[1]); + char *suffix = new char[n]; + strcpy(suffix,&arg[1][2]); + argindex[nfield+nthresh] = 0; + + int tmp = -1; + n = atom->find_custom(suffix,tmp); + if ((n < 0) || (tmp != 1)) + error->all(FLERR,"Could not find dump modify " + "custom atom floating point property ID"); + + field2index[nfield+nthresh] = add_custom(suffix,1); + delete [] suffix; + + // custom per atom integer value = i_ID + // must grow field2index and argindex arrays, since access is beyond nfield + + } else if (strncmp(arg[1],"i_",2) == 0) { + thresh_array[nthresh] = INAME; + memory->grow(field2index,nfield+nthresh+1,"dump:field2index"); + memory->grow(argindex,nfield+nthresh+1,"dump:argindex"); + int n = strlen(arg[1]); + char *suffix = new char[n]; + strcpy(suffix,&arg[1][2]); + argindex[nfield+nthresh] = 0; + + int tmp = -1; + n = atom->find_custom(suffix,tmp); + if ((n < 0) || (tmp != 0)) + error->all(FLERR,"Could not find dump modify " + "custom atom integer property ID"); + + field2index[nfield+nthresh] = add_custom(suffix,0); + delete [] suffix; + } else error->all(FLERR,"Invalid dump_modify threshhold operator"); // set operation type of threshhold @@ -1661,6 +1790,34 @@ void DumpCustom::pack_variable(int n) } } +/* ---------------------------------------------------------------------- */ + +void DumpCustom::pack_custom(int n) +{ + + int index = field2index[n]; + + if (flag_custom[index] == 0) { // integer + int iwhich,tmp; + iwhich = atom->find_custom(id_custom[index],tmp); + + int *ivector = atom->ivector[iwhich]; + for (int i = 0; i < nchoose; i++) { + buf[n] = ivector[clist[i]]; + n += size_one; + } + } else if (flag_custom[index] == 1) { // double + int iwhich,tmp; + iwhich = atom->find_custom(id_custom[index],tmp); + + double *dvector = atom->dvector[iwhich]; + for (int i = 0; i < nchoose; i++) { + buf[n] = dvector[clist[i]]; + n += size_one; + } + } +} + /* ---------------------------------------------------------------------- one method for every attribute dump custom can output the atom property is packed into buf starting at n with stride size_one diff --git a/src/dump_custom.h b/src/dump_custom.h index b7dc788356..c483d5b7e1 100644 --- a/src/dump_custom.h +++ b/src/dump_custom.h @@ -69,6 +69,10 @@ class DumpCustom : public Dump { int *variable; // list of indices for the Variables double **vbuf; // local storage for variable evaluation + int ncustom; // # of custom atom properties + char **id_custom; // their names + int *flag_custom; // their data type + int ntypes; // # of atom types char **typenames; // array of element names for each type @@ -86,6 +90,7 @@ class DumpCustom : public Dump { int add_compute(char *); int add_fix(char *); int add_variable(char *); + int add_custom(char *, int); virtual int modify_param(int, char **); typedef void (DumpCustom::*FnPtrHeader)(bigint); @@ -114,6 +119,7 @@ class DumpCustom : public Dump { void pack_compute(int); void pack_fix(int); void pack_variable(int); + void pack_custom(int); void pack_id(int); void pack_molecule(int);