From b19a211d701685390d33e4603f9f06dd674d91ee Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 18:06:21 -0400 Subject: [PATCH] update code --- src/atom.cpp | 14 +--- src/compute_property_atom.cpp | 84 ++++++++++--------- src/library.cpp | 148 +++++++++++++--------------------- 3 files changed, 101 insertions(+), 145 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index a0f7099319..ab044b6c47 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -2774,13 +2774,10 @@ void *Atom::extract(const char *name) // -------------------------------------------------------------------- // custom vectors and arrays - // OLDSTYLE code - if (strstr(name,"i_") == name || strstr(name,"d_") == name || - strstr(name,"i2_") == name || strstr(name,"d2_") == name) { - int which = 0; + if (utils::strmatch(name,"^[id]2?_")) { + int which = 0, array = 0; if (name[0] == 'd') which = 1; - int array = 0; if (name[1] == '2') array = 1; int index,flag,cols; @@ -2897,13 +2894,10 @@ int Atom::extract_datatype(const char *name) // -------------------------------------------------------------------- // custom vectors and arrays - // OLDSTYLE code - if (strstr(name,"i_") == name || strstr(name,"d_") == name || - strstr(name,"i2_") == name || strstr(name,"d2_") == name) { - int which = 0; + if (utils::strmatch(name,"^[id]2?_")) { + int which = 0, array = 0; if (name[0] == 'd') which = 1; - int array = 0; if (name[1] == '2') array = 1; int index,flag,cols; diff --git a/src/compute_property_atom.cpp b/src/compute_property_atom.cpp index 190168db4b..d4cec70fe4 100644 --- a/src/compute_property_atom.cpp +++ b/src/compute_property_atom.cpp @@ -14,6 +14,7 @@ #include "compute_property_atom.h" +#include "arg_info.h" #include "atom.h" #include "atom_vec.h" #include "atom_vec_body.h" @@ -333,55 +334,52 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_nbonds; - // custom per-atom vector + // custom per-atom vector or array - } else if (utils::strmatch(arg[iarg],"^i_")) { + } else if (utils::strmatch(arg[iarg],"^[id]2?_")) { 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; + ArgInfo argi(arg[iarg], ArgInfo::INAME| ArgInfo::DNAME); + const char *pname = argi.get_name(); - } else if (utils::strmatch(arg[iarg],"^d_")) { - 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; + index[i] = atom->find_custom(pname,flag,cols); + if (index[i] < 0) + error->all(FLERR,"Compute property/atom property {} does not exist", pname); - // custom per-atom arrays, must include bracketed index - // OLDSTYLE code + // handle vectors + if ((cols == 0) && (arg[iarg][1] == '_')) { + if (argi.get_dim() != 0) + error->all(FLERR,"Compute property/atom custom vector {} is incorrectly indexed",pname); - } else if (strstr(arg[iarg],"i2_") == arg[iarg] || - strstr(arg[iarg],"d2_") == arg[iarg]) { - int which = 0; - if (arg[iarg][0] == 'd') which = 1; + if (arg[iarg][0] == 'i') { + if (argi.get_type() == ArgInfo::INAME) + pack_choice[i] = &ComputePropertyAtom::pack_iname; + else + error->all(FLERR,"Compute property/atom integer vector {} does not exist",pname); + } else if (arg[iarg][0] == 'd') { + if (argi.get_type() == ArgInfo::DNAME) + pack_choice[i] = &ComputePropertyAtom::pack_dname; + else + error->all(FLERR,"Compute property/atom floating-point vector {} does not exist",pname); + } + } + // handle arrays + else if ((cols > 0) && (arg[iarg][1] == '2')) { + if (argi.get_dim() != 1) + error->all(FLERR,"Compute property/atom custom array {} is not indexed",pname); + colindex[i] = argi.get_index1(); - 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 set command"); - suffix[strlen(suffix)-1] = '\0'; - colindex[i] = utils::inumeric(FLERR,ptr+1,true,lmp); - *ptr = '\0'; - } else error->all(FLERR,"Compute property/atom custom array is not indexed"); - - int flag,cols; - index[i] = atom->find_custom(suffix,flag,cols); - delete [] suffix; - - if ((!which && (index[i] < 0 || flag || !cols)) || - (which && (index[i] < 0 || !flag || !cols))) - error->all(FLERR,"Compute property/atom custom array does not exist"); - - if (!which) pack_choice[i] = &ComputePropertyAtom::pack_i2name; - else pack_choice[i] = &ComputePropertyAtom::pack_d2name; + if (arg[iarg][0] == 'i') { + if (argi.get_type() == ArgInfo::INAME) + pack_choice[i] = &ComputePropertyAtom::pack_i2name; + else + error->all(FLERR,"Compute property/atom integer array {} does not exist",pname); + } else if (arg[iarg][0] == 'd') { + if (argi.get_type() == ArgInfo::DNAME) + pack_choice[i] = &ComputePropertyAtom::pack_d2name; + else + error->all(FLERR,"Compute property/atom floating-point array {} does not exist",pname); + } + } else error->all(FLERR,"Inconsistent request for custom property {}", pname); // anything else must be recognized by atom style diff --git a/src/library.cpp b/src/library.cpp index 1397cf889e..db609351f7 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -2829,7 +2829,7 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) { #if defined(LAMMPS_BIGBIG) lmp->error->all(FLERR,"Library function lammps_gather" - " not compatible with -DLAMMPS_BIGBIG"); + " not compatible with -DLAMMPS_BIGBIG"); #else int i,j,offset,fcid,ltype,icol; @@ -2915,14 +2915,10 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) } // custom fix property/atom vector or array - // OLDSTYLE code - if ((vptr == nullptr) && - ((strstr(name,"d_") == name) || (strstr(name,"i_") == name) || - (strstr(name,"d2_") == name) || (strstr(name,"i2_") == name))) { + if ((vptr == nullptr) && utils::strmatch(name,"^[id]2?_")) { - if ((strstr(name,"d_") == name) || (strstr(name,"i_") == name)) - fcid = lmp->atom->find_custom(&name[2],ltype,icol); + if (utils::strmatch(name,"^[id]_")) fcid = lmp->atom->find_custom(&name[2],ltype,icol); else fcid = lmp->atom->find_custom(&name[3],ltype,icol); if (fcid < 0) { @@ -2948,11 +2944,11 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; + else vptr = (void *) lmp->atom->dvector[fcid]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; + else vptr = (void *) lmp->atom->darray[fcid]; } } @@ -2960,7 +2956,7 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) if (vptr == nullptr) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather: undefined property name"); + lmp->error->warning(FLERR,"lammps_gather: undefined property name"); return; } @@ -3104,20 +3100,17 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d if (lmp->modify->fix[fcid]->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_concat:" - " fix does not return peratom data"); + lmp->error->warning(FLERR,"lammps_gather_concat: fix does not return peratom data"); return; } if (count>1 && lmp->modify->fix[fcid]->size_peratom_cols != count) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_concat:" - " count != values peratom for fix"); + lmp->error->warning(FLERR,"lammps_gather_concat: count != values peratom for fix"); return; } if (lmp->update->ntimestep % lmp->modify->fix[fcid]->peratom_freq) { if (lmp->comm->me == 0) - lmp->error->all(FLERR,"lammps_gather_concat:" - " fix not computed at compatible time"); + lmp->error->all(FLERR,"lammps_gather_concat: fix not computed at compatible time"); return; } @@ -3138,14 +3131,12 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d if (lmp->modify->compute[fcid]->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_concat:" - " compute does not return peratom data"); + lmp->error->warning(FLERR,"lammps_gather_concat: compute does not return peratom data"); return; } if (count>1 && lmp->modify->compute[fcid]->size_peratom_cols != count) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_concat:" - " count != values peratom for compute"); + lmp->error->warning(FLERR,"lammps_gather_concat: count != values peratom for compute"); return; } @@ -3157,48 +3148,40 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d } // custom per-atom vector or array - // OLDSTYLE code - if ((vptr==nullptr) && - ((strstr(name,"d_") == name) || (strstr(name,"i_") == name) || - (strstr(name,"d2_") == name) || (strstr(name,"i2_") == name))) { + if ((vptr==nullptr) && utils::strmatch(name,"^[id]2?_")) { - if ((strstr(name,"d_") == name) || (strstr(name,"i_") == name)) - fcid = lmp->atom->find_custom(&name[2],ltype,icol); + if (utils::strmatch(name,"^[id]_")) fcid = lmp->atom->find_custom(&name[2],ltype,icol); else fcid = lmp->atom->find_custom(&name[3],ltype,icol); if (fcid < 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_concat: " - "unknown property/atom id"); + lmp->error->warning(FLERR,"lammps_gather_concat: unknown property/atom id"); return; } if (ltype != type) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_concat: " - "mismatch property/atom type"); + lmp->error->warning(FLERR,"lammps_gather_concat: mismatch property/atom type"); return; } if (count == 1 && icol != 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_concat: " - "mismatch property/atom count"); + lmp->error->warning(FLERR,"lammps_gather_concat: mismatch property/atom count"); return; } if (count > 1 && icol != count) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_concat: " - "mismatch property/atom count"); + lmp->error->warning(FLERR,"lammps_gather_concat: mismatch property/atom count"); return; } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; + else vptr = (void *) lmp->atom->dvector[fcid]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; + else vptr = (void *) lmp->atom->darray[fcid]; } } @@ -3206,7 +3189,7 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d if (vptr == nullptr) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_concat: undefined property name"); + lmp->error->warning(FLERR,"lammps_gather_concat: undefined property name"); return; } @@ -3375,14 +3358,12 @@ void lammps_gather_subset(void *handle, char *name, return; } if (count>1 && lmp->modify->fix[fcid]->size_peratom_cols != count) { - lmp->error->warning(FLERR,"lammps_gather_subset:" - " count != values peratom for fix"); + lmp->error->warning(FLERR,"lammps_gather_subset: count != values peratom for fix"); return; } if (lmp->update->ntimestep % lmp->modify->fix[fcid]->peratom_freq) { if (lmp->comm->me == 0) - lmp->error->all(FLERR,"lammps_gather_subset:" - " fix not computed at compatible time"); + lmp->error->all(FLERR,"lammps_gather_subset: fix not computed at compatible time"); return; } @@ -3403,14 +3384,12 @@ void lammps_gather_subset(void *handle, char *name, if (lmp->modify->compute[fcid]->peratom_flag == 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_subset:" - " compute does not return peratom data"); + lmp->error->warning(FLERR,"lammps_gather_subset: compute does not return peratom data"); return; } if (count>1 && lmp->modify->compute[fcid]->size_peratom_cols != count) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_subset:" - " count != values peratom for compute"); + lmp->error->warning(FLERR,"lammps_gather_subset: count != values peratom for compute"); return; } @@ -3422,48 +3401,41 @@ void lammps_gather_subset(void *handle, char *name, } // custom fix property/atom vector or array - // OLDSTYLE code - if ((vptr == nullptr) && - ((strstr(name,"d_") == name) || (strstr(name,"i_") == name) || - (strstr(name,"d2_") == name) || (strstr(name,"i2_") == name))) { + if ((vptr == nullptr) && utils::strmatch(name,"^[id]2?_")) { - if ((strstr(name,"d_") == name) || (strstr(name,"i_") == name)) - fcid = lmp->atom->find_custom(&name[2],ltype,icol); + if (utils::strmatch(name,"^[id]_")) + fcid = lmp->atom->find_custom(&name[2],ltype,icol); else fcid = lmp->atom->find_custom(&name[3],ltype,icol); if (fcid < 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_subset: " - "unknown property/atom id"); + lmp->error->warning(FLERR,"lammps_gather_subset: unknown property/atom id"); return; } if (ltype != type) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_subset: " - "mismatch property/atom type"); + lmp->error->warning(FLERR,"lammps_gather_subset: mismatch property/atom type"); return; } if (count == 1 && icol != 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_subset: " - "mismatch property/atom count"); + lmp->error->warning(FLERR,"lammps_gather_subset: mismatch property/atom count"); return; } if (count > 1 && icol != count) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_subset: " - "mismatch property/atom count"); + lmp->error->warning(FLERR,"lammps_gather_subset: mismatch property/atom count"); return; } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; + else vptr = (void *) lmp->atom->dvector[fcid]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; + else vptr = (void *) lmp->atom->darray[fcid]; } } @@ -3471,7 +3443,7 @@ void lammps_gather_subset(void *handle, char *name, if (vptr == nullptr) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_gather_subset: undefined property name"); + lmp->error->warning(FLERR,"lammps_gather_subset: undefined property name"); return; } @@ -3678,14 +3650,11 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data) } // custom fix property/atom vector or array - // OLDSTYLE code - if ((vptr == nullptr) && - ((strstr(name,"d_") == name) || (strstr(name,"i_") == name) || - (strstr(name,"d2_") == name) || (strstr(name,"i2_") == name))) { + if ((vptr == nullptr) && utils::strmatch(name,"^[id]2?_")) { - if ((strstr(name,"d_") == name) || (strstr(name,"i_") == name)) - fcid = lmp->atom->find_custom(&name[2],ltype,icol); + if (utils::strmatch(name,"^[id]_")) + fcid = lmp->atom->find_custom(&name[2],ltype,icol); else fcid = lmp->atom->find_custom(&name[3],ltype,icol); if (fcid < 0) { @@ -3711,11 +3680,11 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data) } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; + else vptr = (void *) lmp->atom->dvector[fcid]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; + else vptr = (void *) lmp->atom->darray[fcid]; } } @@ -3902,27 +3871,22 @@ void lammps_scatter_subset(void *handle, char *name,int type, int count, } // custom fix property/atom vector or array - // OLDSTYLE code - if ((vptr == nullptr) && - ((strstr(name,"d_") == name) || (strstr(name,"i_") == name) || - (strstr(name,"d2_") == name) || (strstr(name,"i2_") == name))) { + if ((vptr == nullptr) && utils::strmatch(name,"^[id]2?_")) { - if ((strstr(name,"d_") == name) || (strstr(name,"i_") == name)) - fcid = lmp->atom->find_custom(&name[2],ltype,icol); + if (utils::strmatch(name,"^[id]_")) + fcid = lmp->atom->find_custom(&name[2],ltype,icol); else fcid = lmp->atom->find_custom(&name[3],ltype,icol); if (fcid < 0) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter_subset: " - "unknown property/atom id"); + lmp->error->warning(FLERR,"lammps_scatter_subset: unknown property/atom id"); return; } if (ltype != type) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,"lammps_scatter_subset: " - "mismatch property/atom type"); + lmp->error->warning(FLERR,"lammps_scatter_subset: mismatch property/atom type"); return; } if (count == 1 && icol != 0) { @@ -3937,11 +3901,11 @@ void lammps_scatter_subset(void *handle, char *name,int type, int count, } if (count == 1) { - if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; - else vptr = (void *) lmp->atom->dvector[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->ivector[fcid]; + else vptr = (void *) lmp->atom->dvector[fcid]; } else { - if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; - else vptr = (void *) lmp->atom->darray[fcid]; + if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; + else vptr = (void *) lmp->atom->darray[fcid]; } }