From 2bf9fa91dba1c91866f5933c1e657c16211e28fb Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Tue, 17 Aug 2021 14:03:58 -0600 Subject: [PATCH] more changes to merge with current master --- src/compute_property_atom.cpp | 50 ++++---- src/compute_property_atom.h | 4 +- src/dump_custom.cpp | 228 +++++++++++++--------------------- src/fix_property_atom.cpp | 24 ++-- src/fix_store_state.cpp | 175 ++++++++++---------------- src/library.cpp | 4 +- src/set.cpp | 12 +- src/utils.cpp | 5 +- 8 files changed, 202 insertions(+), 300 deletions(-) diff --git a/src/compute_property_atom.cpp b/src/compute_property_atom.cpp index 3c695ab303..a7eb4bf144 100644 --- a/src/compute_property_atom.cpp +++ b/src/compute_property_atom.cpp @@ -380,29 +380,23 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : "atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_nbonds; - } else if (strcmp(arg[iarg],"buckling") == 0) { - if (!atom->mesont_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); - pack_choice[i] = &ComputePropertyAtom::pack_buckling; - // custom per-atom vector } else if (utils::strmatch(arg[iarg],"^i_")) { - int flag,icol; - index[i] = atom->find_custom(&arg[iarg][2],flag,icol); - if (index[i] < 0 || flag || icol) + int flag,cols; + index[i] = atom->find_custom(&arg[iarg][2],flag,cols); + if (index[i] < 0 || flag || cols) error->all(FLERR,"Compute property/atom integer " "vector does not exist"); pack_choice[i] = &ComputePropertyAtom::pack_iname; + } else if (utils::strmatch(arg[iarg],"^d_")) { - int flag; - index[i] = atom->find_custom(&arg[iarg][2],flag,icol); - if (index[i] < 0 || flag || icol1) + int flag,cols; + index[i] = atom->find_custom(&arg[iarg][2],flag,cols); + if (index[i] < 0 || flag || cols) error->all(FLERR,"Compute property/atom floating point " "vector does not exist"); pack_choice[i] = &ComputePropertyAtom::pack_dname; - } // custom per-atom arrays, must include bracketed index // OLDSTYLE code @@ -1203,21 +1197,6 @@ void ComputePropertyAtom::pack_fmz(int n) /* ---------------------------------------------------------------------- */ -void ComputePropertyAtom::pack_nbonds(int n) -{ - int *num_bond = atom->num_bond; - int *mask = atom->mask; - int nlocal = atom->nlocal; - - for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) buf[n] = num_bond[i]; - else buf[n] = 0.0; - n += nvalues; - } -} - -/* ---------------------------------------------------------------------- */ - void ComputePropertyAtom::pack_radius(int n) { double *radius = atom->radius; @@ -1853,6 +1832,21 @@ void ComputePropertyAtom::pack_corner3z(int n) /* ---------------------------------------------------------------------- */ +void ComputePropertyAtom::pack_nbonds(int n) +{ + int *num_bond = atom->num_bond; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = num_bond[i]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + void ComputePropertyAtom::pack_iname(int n) { int *ivector = atom->ivector[index[n]]; diff --git a/src/compute_property_atom.h b/src/compute_property_atom.h index 810a12b680..19f8b73451 100644 --- a/src/compute_property_atom.h +++ b/src/compute_property_atom.h @@ -90,8 +90,6 @@ class ComputePropertyAtom : public Compute { void pack_fmy(int); void pack_fmz(int); - void pack_nbonds(int); - void pack_radius(int); void pack_diameter(int); void pack_omegax(int); @@ -129,6 +127,8 @@ class ComputePropertyAtom : public Compute { void pack_corner3y(int); void pack_corner3z(int); + void pack_nbonds(int); + void pack_iname(int); void pack_dname(int); void pack_i2name(int); diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 4a2778e981..68a2ab4a57 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -1444,54 +1444,15 @@ int DumpCustom::parse_fields(int narg, char **arg) } else if (strcmp(arg[iarg],"tqz") == 0) { if (!atom->torque_flag) error->all(FLERR,"Dumping an atom property that isn't allocated"); - pack_choice[i] = &DumpCustom::pack_tqz; - vtype[i] = Dump::DOUBLE; - - // custom per-atom array = i2_ID or d2_ID, must include bracketed index - // OLDSTYLE code - remove this after extend ArgInfo for i2/d2 arrays - - } else if (strncmp(arg[iarg],"i2_",3) == 0 || - strncmp(arg[iarg],"d2_",3) == 0) { - int which = 0; - if (arg[iarg][0] == 'd') which = 1; - - pack_choice[i] = &DumpCustom::pack_custom; - if (!which) vtype[i] = Dump::INT; - else vtype[i] = Dump::DOUBLE; - - int n = strlen(arg[iarg]); - char *suffix = new char[n]; - strcpy(suffix,&arg[iarg][3]); - - char *ptr = strchr(suffix,'['); - if (ptr) { - if (suffix[strlen(suffix)-1] != ']') - error->all(FLERR,"Invalid attribute in dump custom command"); - suffix[strlen(suffix)-1] = '\0'; - argindex[i] = utils::inumeric(FLERR,ptr+1,true,lmp); - *ptr = '\0'; - } else error->all(FLERR,"Dump custom per-atom custom array is not indexed"); - - int flag,cols; - n = atom->find_custom(suffix,flag,cols); - - if ((!which && (n < 0 || flag || !cols)) || - (which && (n < 0 || !flag || !cols))) - error->all(FLERR,"Dump custom per-atom custom array does not exist"); - if (argindex[i] <= 0 || argindex[i] > cols) - error->all(FLERR, - "Dump custom per-atom custom array is accessed out-of-range"); - - field2index[i] = add_custom(suffix,which); - delete [] suffix; + pack_choice[iarg] = &DumpCustom::pack_tqz; + vtype[iarg] = Dump::DOUBLE; // compute or fix or variable or custom vector/array - // NEWSTYLE code - add ArgInfo returns for IVEC, DVEC, IARRAY, DARRAY } else { - int n,tmp; + int n,flag,cols; ArgInfo argi(arg[iarg],ArgInfo::COMPUTE|ArgInfo::FIX|ArgInfo::VARIABLE - |ArgInfo::DVEC|ArgInfo::IVEC); + |ArgInfo::DNAME|ArgInfo::INAME); argindex[iarg] = argi.get_index1(); auto name = argi.get_name(); @@ -1559,50 +1520,58 @@ int DumpCustom::parse_fields(int narg, char **arg) field2index[iarg] = add_variable(name); break; - // custom per-atom floating point vector = d_ID + // custom per-atom floating point vector or array - case ArgInfo::DVEC: + case ArgInfo::DNAME: pack_choice[iarg] = &DumpCustom::pack_custom; vtype[iarg] = Dump::DOUBLE; - tmp = -1; - n = atom->find_custom(name,tmp); + n = atom->find_custom(name,flag,cols); + if (n < 0) error->all(FLERR,"Could not find custom per-atom property ID: {}", name); - - if (tmp != 1) - error->all(FLERR,"Custom per-atom property ID {} is not floating point", name); + if (argindex[iarg] == 0) { + if (!flag || cols) + error->all(FLERR, + "Property double vector for dump custom does not exist"); + } else { + if (!flag || !cols) + error->all(FLERR, + "Property double array for dump custom does not exist"); + if (argindex[iarg] > atom->dcols[n]) + error->all(FLERR, + "Dump custom property array is accessed out-of-range"); + } field2index[iarg] = add_custom(name,1); break; - // custom per-atom integer vector = i_ID + // custom per-atom integer vector or array - case ArgInfo::IVEC: + case ArgInfo::INAME: pack_choice[iarg] = &DumpCustom::pack_custom; vtype[iarg] = Dump::INT; - tmp = -1; - n = atom->find_custom(name,tmp); + n = atom->find_custom(name,flag,cols); + if (n < 0) error->all(FLERR,"Could not find custom per-atom property ID: {}", name); - - if (tmp != 0) - error->all(FLERR,"Custom per-atom property ID {} is not integer", name); + if (argindex[iarg] == 0) { + if (flag || cols) + error->all(FLERR, + "Property integer vector for dump custom does not exist"); + } else { + if (flag || !cols) + error->all(FLERR, + "Property integer array for dump custom does not exist"); + if (argindex[iarg] > atom->icols[n]) + error->all(FLERR, + "Dump custom property array is accessed out-of-range"); + } field2index[iarg] = add_custom(name,0); break; - // custom per-atom floating point array = d2_ID - - case ArgInfo::DARRAY: - return iarg; - - // custom per-atom integer array = i2_ID - - case ArgInfo::IARRAY: - return iarg; - // no match default: @@ -1915,55 +1884,16 @@ int DumpCustom::modify_param(int narg, char **arg) else if (strcmp(arg[1],"tqy") == 0) thresh_array[nthresh] = TQY; else if (strcmp(arg[1],"tqz") == 0) thresh_array[nthresh] = TQZ; - // custom per-atom array = i2_ID or d2_ID, must include bracketed index - // OLDSTYLE code - remove this after extend ArgInfo for i2/d2 arrays - - else if (strncmp(arg[1],"i2_",3) == 0 || strncmp(arg[1],"d2_",3) == 0) { - int which = 0; - if (arg[1][0] == 'd') which = 1; - - if (!which) thresh_array[nthresh] = IARRAY; - else thresh_array[nthresh] = DARRAY; - 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][3]); - - char *ptr = strchr(suffix,'['); - if (ptr) { - if (suffix[strlen(suffix)-1] != ']') - error->all(FLERR,"Invalid attribute in dump custom command"); - suffix[strlen(suffix)-1] = '\0'; - argindex[nfield+nthresh] = utils::inumeric(FLERR,ptr+1,true,lmp); - *ptr = '\0'; - } else error->all(FLERR,"Dump_modify per-atom custom array is not indexed"); - - int flag,cols; - n = atom->find_custom(suffix,flag,cols); - - if ((!which && (n < 0 || flag || !cols)) || - (which && (n < 0 || !flag || !cols))) - error->all(FLERR,"Could not find dump_modify per-atom custom array"); - if (argindex[nfield+nthresh] <= 0 || argindex[nfield+nthresh] > cols) - error->all(FLERR, - "Dump_modify per-atom custom array is accessed out-of-range"); - - field2index[nfield+nthresh] = add_custom(suffix,which); - delete [] suffix; - // compute or fix or variable or custom vector/array - // NEWSTYLE code - add ArgInfo returns for IVEC, DVEC, IARRAY, DARRAY // must grow field2index and argindex arrays, since access is beyond nfield - } else { + else { memory->grow(field2index,nfield+nthresh+1,"dump:field2index"); memory->grow(argindex,nfield+nthresh+1,"dump:argindex"); - int n,tmp; + int n,flag,cols; ArgInfo argi(arg[1],ArgInfo::COMPUTE|ArgInfo::FIX|ArgInfo::VARIABLE - |ArgInfo::DVEC|ArgInfo::IVEC); + |ArgInfo::DNAME|ArgInfo::INAME); argindex[nfield+nthresh] = argi.get_index1(); auto name = argi.get_name(); @@ -2026,39 +1956,55 @@ int DumpCustom::modify_param(int narg, char **arg) field2index[nfield+nthresh] = add_variable(name); break; - // custom per atom floating point value = d_ID + // custom per atom floating point vector or array - case ArgInfo::DVEC: - thresh_array[nthresh] = DVEC; - tmp = -1; - n = atom->find_custom(name,tmp); - if ((n < 0) || (tmp != 1)) - error->all(FLERR,"Could not find dump modify custom atom floating point property ID: {}",name); - - field2index[nfield+nthresh] = add_custom(name,1); - break; - - // custom per atom integer value = i_ID - - case ArgInfo::IVEC: - thresh_array[nthresh] = IVEC; - tmp = -1; - n = atom->find_custom(name,tmp); - if ((n < 0) || (tmp != 0)) - error->all(FLERR,"Could not find dump modify custom atom integer property ID: {}",name); + case ArgInfo::DNAME: + n = atom->find_custom(name,flag,cols); + if (n < 0) + error->all(FLERR,"Could not find custom per-atom property ID: {}", name); + if (argindex[nfield+nthresh] == 0) { + if (flag || cols) + error->all(FLERR, + "Property double vector for dump custom does not exist"); + thresh_array[nthresh] = DVEC; + } else { + if (flag || !cols) + error->all(FLERR, + "Property double array for dump custom does not exist"); + if (argindex[nfield+nthresh] > atom->dcols[n]) + error->all(FLERR, + "Dump custom property array is accessed out-of-range"); + thresh_array[nthresh] = DARRAY; + } + field2index[nfield+nthresh] = add_custom(name,0); break; - // custom per-atom floating point array = d2_ID + // custom per atom integer vector or array + + case ArgInfo::INAME: + n = atom->find_custom(name,flag,cols); - case ArgInfo::DARRAY: - return iarg; + if (n < 0) + error->all(FLERR,"Could not find custom per-atom property ID: {}", name); + if (argindex[nfield+nthresh] == 0) { + if (flag || cols) + error->all(FLERR, + "Property integer vector for dump custom does not exist"); + thresh_array[nthresh] = IVEC; + } else { + if (flag || !cols) + error->all(FLERR, + "Property integer array for dump custom does not exist"); + if (argindex[nfield+nthresh] > atom->icols[n]) + error->all(FLERR, + "Dump custom property array is accessed out-of-range"); + thresh_array[nthresh] = IARRAY; + } - // custom per-atom integer array = i2_ID - - case ArgInfo::IARRAY: - return iarg; + field2index[nfield+nthresh] = add_custom(name,0); + break; // no match @@ -2069,7 +2015,7 @@ int DumpCustom::modify_param(int narg, char **arg) } // set operation type of threshold - + if (strcmp(arg[2],"<") == 0) thresh_op[nthresh] = LT; else if (strcmp(arg[2],"<=") == 0) thresh_op[nthresh] = LE; else if (strcmp(arg[2],">") == 0) thresh_op[nthresh] = GT; @@ -2078,11 +2024,11 @@ int DumpCustom::modify_param(int narg, char **arg) else if (strcmp(arg[2],"!=") == 0) thresh_op[nthresh] = NEQ; else if (strcmp(arg[2],"|^") == 0) thresh_op[nthresh] = XOR; else error->all(FLERR,"Invalid dump_modify thresh operator"); - + // set threshold value as number or special LAST keyword // create FixStore to hold LAST values, should work with restart // id = dump-ID + nthreshlast + DUMP_STORE, fix group = dump group - + if (strcmp(arg[3],"LAST") != 0) { thresh_value[nthresh] = utils::numeric(FLERR,arg[3],false,lmp); thresh_last[nthresh] = -1; @@ -2092,17 +2038,17 @@ int DumpCustom::modify_param(int narg, char **arg) thresh_fixID = (char **) memory->srealloc(thresh_fixID,(nthreshlast+1)*sizeof(char *),"dump:thresh_fixID"); memory->grow(thresh_first,(nthreshlast+1),"dump:thresh_first"); - + std::string threshid = fmt::format("{}{}_DUMP_STORE",id,nthreshlast); thresh_fixID[nthreshlast] = utils::strdup(threshid); threshid += fmt::format(" {} STORE peratom 1 1", group->names[igroup]); thresh_fix[nthreshlast] = (FixStore *) modify->add_fix(threshid); - + thresh_last[nthreshlast] = nthreshlast; thresh_first[nthreshlast] = 1; nthreshlast++; } - + nthresh++; return 4; } diff --git a/src/fix_property_atom.cpp b/src/fix_property_atom.cpp index a45b4768be..47c7475524 100644 --- a/src/fix_property_atom.cpp +++ b/src/fix_property_atom.cpp @@ -93,21 +93,21 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) : } else if (utils::strmatch(arg[iarg],"^i_")) { style[nvalue] = IVEC; - int tmp; - index[nvalue] = atom->find_custom(&arg[iarg][2],tmp); + int flag,cols; + index[nvalue] = atom->find_custom(&arg[iarg][2],flag,cols); if (index[nvalue] >= 0) error->all(FLERR,"Fix property/atom vector name already exists"); - index[nvalue] = atom->add_custom(&arg[iarg][2],0); + index[nvalue] = atom->add_custom(&arg[iarg][2],0,0); nvalue++; - iarg++ + iarg++; } else if (utils::strmatch(arg[iarg],"^d_")) { style[nvalue] = DVEC; - int tmp; - index[nvalue] = atom->find_custom(&arg[iarg][2],tmp); + int flag,ncols; + index[nvalue] = atom->find_custom(&arg[iarg][2],flag,ncols); if (index[nvalue] >= 0) error->all(FLERR,"Fix property/atom vector name already exists"); - index[nvalue] = atom->add_custom(&arg[iarg][2],1); + index[nvalue] = atom->add_custom(&arg[iarg][2],1,0); nvalue++; iarg++; @@ -121,8 +121,8 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) : if (arg[iarg][0] == 'd') which = 1; if (which == 0) style[nvalue] = IARRAY; else style[nvalue] = DARRAY; - int tmp1,tmp2; - index[nvalue] = atom->find_custom(&arg[iarg][3],tmp1,tmp2); + int flag,ncols; + index[nvalue] = atom->find_custom(&arg[iarg][3],flag,ncols); if (index[nvalue] >= 0) error->all(FLERR,"Fix property/atom array name already exists"); cols[nvalue] = utils::inumeric(FLERR,arg[iarg+1],true,lmp); @@ -418,8 +418,10 @@ void FixPropertyAtom::write_data_section_keyword(int /*mth*/, FILE *fp) if (style[i] == MOLECULE) fputs(" mol",fp); else if (style[i] == CHARGE) fputs(" q",fp); else if (style[i] == RMASS) fputs(" rmass",fp); - else if (style[i] == INTEGER) fprintf(fp," i_%s", atom->iname[index[i]]); - else if (style[i] == DOUBLE) fprintf(fp, " d_%s", atom->dname[index[i]]); + else if (style[i] == IVEC) fprintf(fp," i_%s", atom->ivname[index[i]]); + else if (style[i] == DVEC) fprintf(fp, " d_%s", atom->dvname[index[i]]); + else if (style[i] == IARRAY) fprintf(fp, " i_%s", atom->ianame[index[i]]); + else if (style[i] == DARRAY) fprintf(fp, " d_%s", atom->daname[index[i]]); } fputs("\n\n",fp); } diff --git a/src/fix_store_state.cpp b/src/fix_store_state.cpp index df082f92f6..0d54d2727e 100644 --- a/src/fix_store_state.cpp +++ b/src/fix_store_state.cpp @@ -222,33 +222,6 @@ FixStoreState::FixStoreState(LAMMPS *lmp, int narg, char **arg) : "Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_tqz; - // custom per-atom array - // OLDSTYLE code - - } else if (strncmp(arg[iarg],"i2_",3) == 0 || - strncmp(arg[iarg],"d2_",3) == 0) { - if (strncmp(arg[iarg],"i2_",3) == 0) which[nvalues] = IARRAY; - else if (strncmp(arg[iarg],"d2_",3) == 0) which[nvalues] = DARRAY; - - int n = strlen(arg[iarg]); - char *suffix = new char[n]; - strcpy(suffix,&arg[iarg][3]); - - char *ptr = strchr(suffix,'['); - if (!ptr) error->all(FLERR,"Illegal fix store/state command"); - - if (suffix[strlen(suffix)-1] != ']') - error->all(FLERR,"Illegal fix store/state command"); - suffix[strlen(suffix)-1] = '\0'; - argindex[nvalues] = utils::inumeric(FLERR,ptr+1,true,lmp); - *ptr = '\0'; - - n = strlen(suffix) + 1; - ids[nvalues] = new char[n]; - strcpy(ids[nvalues],suffix); - nvalues++; - delete [] suffix; - // compute or fix or variable or custom per-atom vector or array // NEWSTYLE code @@ -293,16 +266,16 @@ FixStoreState::FixStoreState(LAMMPS *lmp, int narg, char **arg) : if (modify->compute[icompute]->peratom_flag == 0) error->all(FLERR,"Fix store/state compute " "does not calculate per-atom values"); - if (argindex[m] == 0 && + if (argindex[i] == 0 && modify->compute[icompute]->size_peratom_cols != 0) error->all(FLERR,"Fix store/state compute does not " "calculate a per-atom vector"); - if (argindex[m] && modify->compute[icompute]->size_peratom_cols == 0) + if (argindex[i] && modify->compute[icompute]->size_peratom_cols == 0) error->all(FLERR, "Fix store/state compute does not " "calculate a per-atom array"); - if (argindex[m] && - argindex[m] > modify->compute[icompute]->size_peratom_cols) + if (argindex[i] && + argindex[i] > modify->compute[icompute]->size_peratom_cols) error->all(FLERR, "Fix store/state compute array is accessed out-of-range"); @@ -314,13 +287,13 @@ FixStoreState::FixStoreState(LAMMPS *lmp, int narg, char **arg) : if (modify->fix[ifix]->peratom_flag == 0) error->all(FLERR, "Fix store/state fix does not calculate per-atom values"); - if (argindex[m] == 0 && modify->fix[ifix]->size_peratom_cols != 0) + if (argindex[i] == 0 && modify->fix[ifix]->size_peratom_cols != 0) error->all(FLERR, "Fix store/state fix does not calculate a per-atom vector"); - if (argindex[m] && modify->fix[ifix]->size_peratom_cols == 0) + if (argindex[i] && modify->fix[ifix]->size_peratom_cols == 0) error->all(FLERR, "Fix store/state fix does not calculate a per-atom array"); - if (argindex[m] && argindex[m] > modify->fix[ifix]->size_peratom_cols) + if (argindex[i] && argindex[i] > modify->fix[ifix]->size_peratom_cols) error->all(FLERR, "Fix store/state fix array is accessed out-of-range"); if (nevery % modify->fix[ifix]->peratom_freq) @@ -334,33 +307,41 @@ FixStoreState::FixStoreState(LAMMPS *lmp, int narg, char **arg) : if (input->variable->atomstyle(ivariable) == 0) error->all(FLERR,"Fix store/state variable is not atom-style variable"); - } else if (which[i] == ArgInfo::INAME) { - int icustom,iflag,cols; - icustom = atom->find_custom(ids[i],iflag,cols); - if ((icustom < 0) || iflag ||,cols) - error->all(FLERR, - "Custom integer vector for fix store/state does not exist"); - } else if (which[i] == ArgInfo::DNAME) { - int icustom,iflag,cols; - icustom = atom->find_custom(ids[i],iflag,cols); - if ((icustom < 0) || iflag ||,cols) - error->all(FLERR, - "Custom floating point vector for fix store/state does not exist"); + int icustom,iflag,icol; + icustom = atom->find_custom(ids[i],iflag,icol); + if (icustom < 0) + error->all(FLERR,"Custom vector/array for fix store/state does not exist"); + if (argindex[i] == 0) { + if (!iflag || icol) + error->all(FLERR, + "Custom double vector for fix store/state does not exist"); + } else { + if (!iflag || !icol) + error->all(FLERR, + "Custom double array for fix store/state does not exist"); + if (argindex[i] > atom->dcols[icustom]) + error->all(FLERR, + "Fix store/state custom array is accessed out-of-range"); + } - } else if (which[i] == ArgInfo::IARRAY) { - int icustom,flag,cols; - icustom = atom->find_custom(ids[i],flag,cols); - if ((icustom < 0) || flag || !cols) - error->all(FLERR, - "Custom integer array for fix store/state does not exist"); - - } else if (which[m] == Arginfo::DARRAY) { - int icustom,flag,cols; - icustom = atom->find_custom(ids[i],flag,cols); - if ((icustom < 0) || !flag || !cols) - error->all(FLERR, - "Custom floating point array for fix store/state does not exist"); + } else if (which[i] == ArgInfo::INAME) { + int icustom,iflag,icol; + icustom = atom->find_custom(ids[i],iflag,icol); + if (icustom < 0) + error->all(FLERR,"Custom vector/array for fix store/state does not exist"); + if (argindex[i] == 0) { + if (iflag || icol) + error->all(FLERR, + "Custom integer vector for fix store/state does not exist"); + } else { + if (iflag || !icol) + error->all(FLERR, + "Custom integer array for fix store/state does not exist"); + if (argindex[i] > atom->icols[icustom]) + error->all(FLERR, + "Fix store/state custom array is accessed out-of-range"); + } } } @@ -450,36 +431,13 @@ void FixStoreState::init() error->all(FLERR,"Variable name for fix store/state does not exist"); value2index[m] = ivariable; - } else if (which[m] == ArgInfo::IVEC) { + } else if (which[m] == ArgInfo::INAME || which[m] == ArgInfo::DNAME) { int icustom,iflag,cols; icustom = atom->find_custom(ids[m],iflag,cols); - if ((icustom < 0) || iflag || cols) - error->all(FLERR, - "Custom integer vector for fix store/state does not exist"); + if (icustom < 0) + error->all(FLERR,"Custom vector/array for fix store/state does not exist"); value2index[m] = icustom; - - } else if (which[m] == ArgInfo::DVEC) { - int icustom,iflag,cols; - icustom = atom->find_custom(ids[m],iflag,cols); - if ((icustom < 0) || iflag || cols) - error->all(FLERR, - "Custom floating point vector for fix store/state does not exist"); - value2index[m] = icustom; - - } else if (which[m] == ArgInfo::IARRAY) { - int icustom,iflag,cols; - icustom = atom->find_custom(ids[m],iflag,cols); - if ((icustom < 0) || iflag || !cols) - error->all(FLERR, - "Custom integer array for fix store/state does not exist"); - value2index[m] = icustom; - - } else if (which[m] == ArgInfo::DARRAY) { - int icustom,iflag,cols; - icustom = atom->find_custom(ids[m],iflag,cols); - if ((icustom < 0) || iflag || !cols) - error->all(FLERR, - "Custom floating point array for fix store/state does not exist"); value2index[m] = icustom; + } } } @@ -566,32 +524,35 @@ void FixStoreState::end_of_step() // evaluate atom-style variable - } else if (which[m] == VARIABLE) { + } else if (which[m] == ArgInfo::VARIABLE) { input->variable->compute_atom(n,igroup,&values[0][m],nvalues,0); - // access custom atom property fields + // access custom atom vector/array fields - } else if (which[m] == ArgInfo::IVEC) { - int *ivector = atom->ivector[n]; - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) values[i][m] = ivector[i]; + } else if (which[m] == ArgInfo::DNAME) { + if (j == 0) { + double *dvector = atom->dvector[n]; + for (i = 0; i < nlocal; i++) + if (mask[i] & groupbit) values[i][m] = dvector[i]; + } else { + double **darray = atom->darray[n]; + int jm1 = j - 1; + for (i = 0; i < nlocal; i++) + if (mask[i] & groupbit) values[i][m] = darray[i][jm1]; + } - } else if (which[m] == ArgInfo::DVEC) { - double *dvector = atom->dvector[n]; - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) values[i][m] = dvector[i]; - - } else if (which[m] == ArgInfo::IARRAY) { - int **iarray = atom->iarray[n]; - int jm1 = j - 1; - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) values[i][m] = iarray[i][jm1]; - } else if (which[m] == ArgInfo::DARRAY) { - double **darray = atom->darray[n]; - int jm1 = j - 1; - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) values[i][m] = darray[i][jm1]; + } else if (which[m] == ArgInfo::INAME) { + if (j == 0) { + int *ivector = atom->ivector[n]; + for (i = 0; i < nlocal; i++) + if (mask[i] & groupbit) values[i][m] = ivector[i]; + } else { + int **iarray = atom->iarray[n]; + int jm1 = j - 1; + for (i = 0; i < nlocal; i++) + if (mask[i] & groupbit) values[i][m] = iarray[i][jm1]; + } } } } diff --git a/src/library.cpp b/src/library.cpp index d0f5b2b9fb..b6cdd02e9f 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -3127,7 +3127,7 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d // compute - if (vptr==nullptr && utils::strmatch(name,"^c_")) + if (vptr==nullptr && utils::strmatch(name,"^c_")) { fcid = lmp->modify->find_compute(&name[2]); if (fcid < 0) { @@ -3156,7 +3156,7 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d else vptr = (void *) lmp->modify->compute[fcid]->array_atom; } - // custom fix property/atom vector or array + // custom per-atom vector or array // OLDSTYLE code if ((vptr==nullptr) && diff --git a/src/set.cpp b/src/set.cpp index c5021120c1..1aa9a479e6 100644 --- a/src/set.cpp +++ b/src/set.cpp @@ -576,9 +576,9 @@ void Set::command(int narg, char **arg) if (iarg+2 > narg) error->all(FLERR,"Illegal set command"); if (utils::strmatch(arg[iarg+1],"^v_")) varparse(arg[iarg+1],1); else ivalue = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - int flag; - index_custom = atom->find_custom(&arg[iarg][2],flag); - if (index_custom < 0 || flag != 0) + int flag,cols; + index_custom = atom->find_custom(&arg[iarg][2],flag,cols); + if (index_custom < 0 || flag || cols) error->all(FLERR,"Set command integer vector does not exist"); set(IVEC); iarg += 2; @@ -587,9 +587,9 @@ void Set::command(int narg, char **arg) if (iarg+2 > narg) error->all(FLERR,"Illegal set command"); if (utils::strmatch(arg[iarg+1],"^v_")) varparse(arg[iarg+1],1); else dvalue = utils::numeric(FLERR,arg[iarg+1],false,lmp); - int flag; - index_custom = atom->find_custom(&arg[iarg][2],flag); - if (index_custom < 0 || flag != 1) + int flag,cols; + index_custom = atom->find_custom(&arg[iarg][2],flag,cols); + if (index_custom < 0 || flag || cols) error->all(FLERR,"Set command floating point vector does not exist"); set(DVEC); iarg += 2; diff --git a/src/utils.cpp b/src/utils.cpp index 8da2efd03d..fd3170859b 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -609,13 +609,12 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod // only match custom array reference with a '*' wildcard // number range in the first pair of square brackets - // OLDSTYLE code if (strncmp(arg[iarg],"i2_",3) == 0 || strncmp(arg[iarg],"d2_",3) == 0) { - ptr1 = strchr(arg[iarg],'['); + char *ptr1 = strchr(arg[iarg],'['); if (ptr1) { - ptr2 = strchr(ptr1,']'); + char *ptr2 = strchr(ptr1,']'); if (ptr2) { *ptr2 = '\0'; if (strchr(ptr1,'*')) {