From c57da0661df76c58177d1b981cc57dc78e36976f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 12:49:16 -0400 Subject: [PATCH 01/13] update package name --- doc/src/compute_property_atom.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/compute_property_atom.rst b/doc/src/compute_property_atom.rst index 60e8c5f167..c4657ce82c 100644 --- a/doc/src/compute_property_atom.rst +++ b/doc/src/compute_property_atom.rst @@ -92,8 +92,8 @@ Syntax .. parsed-literal:: - USER-MESONT package per-atom properties: - buckling = buckling flag used in mesoscopic simulation of nanotubes + MESONT package per-atom properties: + buckling = buckling flag used in mesoscopic simulation of nanotubes Examples """""""" From c6819e30cf82e1214feaacb3a5b82dbe6cb46dd2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 12:58:39 -0400 Subject: [PATCH 02/13] simplify --- src/KOKKOS/pair_table_rx_kokkos.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/KOKKOS/pair_table_rx_kokkos.cpp b/src/KOKKOS/pair_table_rx_kokkos.cpp index 6603d8d88b..b7b9560bc1 100644 --- a/src/KOKKOS/pair_table_rx_kokkos.cpp +++ b/src/KOKKOS/pair_table_rx_kokkos.cpp @@ -1054,14 +1054,10 @@ void PairTableRXKokkos::coeff(int narg, char **arg) if (ispecies == nspecies && strcmp(site1,"1fluid") != 0) error->all(FLERR,"Site1 name not recognized in pair coefficients"); + site2 = utils::strdup(arg[5]); - n = strlen(arg[5]) + 1; - site2 = new char[n]; - strcpy(site2,arg[5]); - - for (ispecies = 0; ispecies < nspecies; ispecies++) { + for (ispecies = 0; ispecies < nspecies; ispecies++) if (strcmp(site2,&atom->dvname[ispecies][0]) == 0) break; - } if (ispecies == nspecies && strcmp(site2,"1fluid") != 0) error->all(FLERR,"Site2 name not recognized in pair coefficients"); From c50abed92b6db7041fcb404d19b157e1c8f6df92 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 12:59:31 -0400 Subject: [PATCH 03/13] recover compilation --- src/REACTION/fix_bond_react.cpp | 4 +-- src/fix_property_atom.cpp | 2 +- unittest/formats/test_atom_styles.cpp | 39 +++++++++++++++++---------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/REACTION/fix_bond_react.cpp b/src/REACTION/fix_bond_react.cpp index e6828b24ab..0c309b9ead 100644 --- a/src/REACTION/fix_bond_react.cpp +++ b/src/REACTION/fix_bond_react.cpp @@ -2625,8 +2625,8 @@ void FixBondReact::unlimit_bond() // let's now unlimit in terms of i_limit_tags // we just run through all nlocal, looking for > limit_duration // then we return i_limit_tag to 0 (which removes from dynamic group) - int flag,cols - int index1 = atom->find_custom("limit_tags",flag,cols); + int flag, cols; + int index1 = atom->find_custom("limit_tags",flag,cols); int *i_limit_tags = atom->ivector[index1]; int *i_statted_tags; diff --git a/src/fix_property_atom.cpp b/src/fix_property_atom.cpp index 47c7475524..0ca8a75632 100644 --- a/src/fix_property_atom.cpp +++ b/src/fix_property_atom.cpp @@ -250,7 +250,7 @@ void FixPropertyAtom::init() void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, tagint id_offset) { - int j,k,m,iword,ncol,nv; + int j,k,m,ncol; tagint itag; char *next; diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index d416074b81..b091360170 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -11,6 +11,7 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +#include "../testing/core.h" #include "atom.h" #include "atom_vec_body.h" #include "atom_vec_ellipsoid.h" @@ -24,7 +25,6 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "../testing/core.h" #include #include @@ -48,7 +48,7 @@ using LAMMPS_NS::utils::split_words; -static void create_molecule_files(const std::string & h2o_filename, const std::string & co2_filename) +static void create_molecule_files(const std::string &h2o_filename, const std::string &co2_filename) { // create molecule files const char h2o_file[] = "# Water molecule. SPC/E model.\n\n3 atoms\n2 bonds\n1 angles\n\n" @@ -95,11 +95,10 @@ using ::testing::Eq; class AtomStyleTest : public LAMMPSTest { protected: - static void SetUpTestSuite() { - create_molecule_files("h2o.mol", "co2.mol"); - } + static void SetUpTestSuite() { create_molecule_files("h2o.mol", "co2.mol"); } - static void TearDownTestSuite() { + static void TearDownTestSuite() + { remove("h2o.mol"); remove("co2.mol"); } @@ -237,8 +236,10 @@ struct AtomState { bool has_dihedral = false; bool has_improper = false; - bool has_iname = false; - bool has_dname = false; + bool has_ivname = false; + bool has_dvname = false; + bool has_ianame = false; + bool has_daname = false; bool has_mass = false; bool has_mass_setflag = false; @@ -444,8 +445,10 @@ void ASSERT_ATOM_STATE_EQ(Atom *atom, const AtomState &expected) ASSERT_EQ(atom->nivector, expected.nivector); ASSERT_EQ(atom->ndvector, expected.ndvector); - ASSERT_ARRAY_ALLOCATED(atom->iname, expected.has_iname); - ASSERT_ARRAY_ALLOCATED(atom->dname, expected.has_dname); + ASSERT_ARRAY_ALLOCATED(atom->ivname, expected.has_ivname); + ASSERT_ARRAY_ALLOCATED(atom->dvname, expected.has_dvname); + ASSERT_ARRAY_ALLOCATED(atom->ianame, expected.has_ianame); + ASSERT_ARRAY_ALLOCATED(atom->daname, expected.has_daname); ASSERT_ARRAY_ALLOCATED(atom->mass, expected.has_mass); ASSERT_ARRAY_ALLOCATED(atom->mass_setflag, expected.has_mass_setflag); @@ -4555,7 +4558,8 @@ TEST_F(AtomStyleTest, property_atom) { BEGIN_HIDE_OUTPUT(); command("atom_modify map array"); - command("fix Properties all property/atom i_one d_two mol d_three q rmass ghost yes"); + command("fix Properties all property/atom " + "i_one d_two mol d_three q rmass i2_four 2 d2_five 3 ghost yes"); END_HIDE_OUTPUT(); AtomState expected; @@ -4570,8 +4574,10 @@ TEST_F(AtomStyleTest, property_atom) expected.has_x = true; expected.has_v = true; expected.has_f = true; - expected.has_iname = true; - expected.has_dname = true; + expected.has_ivname = true; + expected.has_dvname = true; + expected.has_ianame = true; + expected.has_daname = true; expected.has_extra_grow = true; expected.has_extra_restart = true; expected.has_extra_border = true; @@ -4614,7 +4620,12 @@ TEST_F(AtomStyleTest, property_atom) command("set atom 2 d_three -1.0"); command("set atom 3 d_three 0.5"); command("set atom 4 d_three 2.0"); - + command("set atom * d2_five[1] -5.9"); + command("set atom * d2_five[2] 1.1e-2"); + command("set atom * d2_five[3] .1"); + command("set atom 1*2 i2_four[1] -2"); + command("set atom 3*4 i2_four[1] -1"); + command("set atom * i2_four[2] 2"); END_HIDE_OUTPUT(); expected.natoms = 4; expected.nlocal = 4; From 300fee043745a890f976aedcd98364e018b75768 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 12:59:56 -0400 Subject: [PATCH 04/13] add some more checks for typical string matches for references to fixes and alike --- unittest/utils/test_utils.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/unittest/utils/test_utils.cpp b/unittest/utils/test_utils.cpp index 08922e648f..44cd865a21 100644 --- a/unittest/utils/test_utils.cpp +++ b/unittest/utils/test_utils.cpp @@ -478,6 +478,17 @@ TEST(Utils, strmatch_opt_char) { ASSERT_TRUE(utils::strmatch("rigid", "^r?igid")); ASSERT_TRUE(utils::strmatch("igid", "^r?igid")); + ASSERT_TRUE(utils::strmatch("c_name","^[cfvid]2?_name")); + ASSERT_TRUE(utils::strmatch("f_name","^[cfvid]2?_name")); + ASSERT_TRUE(utils::strmatch("v_name","^[cfvid]2?_name")); + ASSERT_TRUE(utils::strmatch("i_name","^[cfvid]2?_name")); + ASSERT_TRUE(utils::strmatch("d_name","^[cfvid]2?_name")); + ASSERT_TRUE(utils::strmatch("i2_name","^[cfvid]2?_name")); + ASSERT_TRUE(utils::strmatch("d2_name","^[cfvid]2?_name")); + ASSERT_FALSE(utils::strmatch("d2name","^[cfvid]2?_name")); + ASSERT_FALSE(utils::strmatch("i1_name","^[cfvid]2?_name")); + ASSERT_FALSE(utils::strmatch("V_name","^[cfvid]2?_name")); + ASSERT_FALSE(utils::strmatch("x_name","^[cfvid]2?_name")); } TEST(Utils, strmatch_dot) From f9b32f0eef356e28bc7b19edc36e7834ad54d78c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 13:00:32 -0400 Subject: [PATCH 05/13] use ArgInfo class to process references to custom vectors and arrays --- src/set.cpp | 112 +++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 58 deletions(-) diff --git a/src/set.cpp b/src/set.cpp index 1aa9a479e6..2a36874c8b 100644 --- a/src/set.cpp +++ b/src/set.cpp @@ -14,6 +14,7 @@ #include "set.h" +#include "arg_info.h" #include "atom.h" #include "atom_vec.h" #include "atom_vec_body.h" @@ -570,69 +571,64 @@ void Set::command(int narg, char **arg) set(DPDTHETA); iarg += 2; - // custom per-atom vector + } else { - } else if (utils::strmatch(arg[iarg],"^i_")) { - 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,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; - - } else if (utils::strmatch(arg[iarg],"^d_")) { - 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,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; - - // custom per-atom array, must include bracketed index - // OLDSTYLE code - - } else if (strstr(arg[iarg],"i2_") == arg[iarg] || - strstr(arg[iarg],"d2_") == arg[iarg]) { - if (iarg+2 > narg) error->all(FLERR,"Illegal set command"); - int which = 0; - if (arg[iarg][0] == 'd') which = 1; - if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) varparse(arg[iarg+1],1); - else if (!which) ivalue = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - else dvalue = utils::numeric(FLERR,arg[iarg+1],false,lmp); - - 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"); - icol_custom = atoi(ptr+1); - *ptr = '\0'; - } else error->all(FLERR,"Set command per-atom custom array is not indexed"); + // set custom per-atom vector or array or error out int flag,cols; - index_custom = atom->find_custom(suffix,flag,cols); - delete [] suffix; + ArgInfo argi(arg[iarg],ArgInfo::DNAME|ArgInfo::INAME); + const char *pname = argi.get_name(); + if (iarg+2 > narg) error->all(FLERR,"Illegal set command"); + index_custom = atom->find_custom(argi.get_name(),flag,cols); + if (index_custom < 0) error->all(FLERR,"Custom property {} does not exist",pname); - if ((!which && (index_custom < 0 || flag || !cols)) || - (which && (index_custom < 0 || !flag || !cols))) - error->all(FLERR,"Set command per-atom custom array does not exist"); - if (icol_custom <= 0 || icol_custom > cols) - error->all(FLERR,"Set command per-atom custom array is accessed out-of-range"); + switch (argi.get_type()) { - if (!which) set(IARRAY); - else set(DARRAY); + case ArgInfo::INAME: + if (utils::strmatch(arg[iarg+1],"^v_")) varparse(arg[iarg+1],1); + else ivalue = utils::inumeric(FLERR,arg[iarg+1],false,lmp); + if (flag != 0) error->all(FLERR,"Custom property {} is not integer",pname); + + if (argi.get_dim() == 0) { + if (cols > 0) + error->all(FLERR,"Set command custom integer property {} is not a vector",pname); + set(IVEC); + } else if (argi.get_dim() == 1) { + if (cols == 0) + error->all(FLERR,"Set command custom integer property {} is not an array",pname); + icol_custom = argi.get_index1(); + if (icol_custom <= 0 || icol_custom > cols) + error->all(FLERR,"Set command per-atom custom integer array {} is accessed " + "out-of-range",pname); + set(IARRAY); + } else error->all(FLERR,"Illegal set command"); + break; + + case ArgInfo::DNAME: + if (utils::strmatch(arg[iarg+1],"^v_")) varparse(arg[iarg+1],1); + else dvalue = utils::numeric(FLERR,arg[iarg+1],false,lmp); + if (flag != 1) error->all(FLERR,"Custom property {} is not floating-point",argi.get_name()); + + if (argi.get_dim() == 0) { + if (cols > 0) + error->all(FLERR,"Set command custom floating-point property is not a vector"); + set(DVEC); + } else if (argi.get_dim() == 1) { + if (cols == 0) + error->all(FLERR,"Set command custom floating-point property is not an array"); + icol_custom = argi.get_index1(); + if (icol_custom <= 0 || icol_custom > cols) + error->all(FLERR,"Set command per-atom custom integer array is accessed out-of-range"); + set(DARRAY); + } else error->all(FLERR,"Illegal set command"); + break; + + default: + error->all(FLERR,"Illegal set command"); + break; + } iarg += 2; - - } else error->all(FLERR,"Illegal set command"); + } // statistics // for CC option, include species index @@ -1007,7 +1003,7 @@ void Set::set(int keyword) (((imageint) (zbox + IMGMAX) & IMGMASK) << IMG2BITS); } - // set value for custom vector or array + // set value for custom property vector or array else if (keyword == IVEC) { atom->ivector[index_custom][i] = ivalue; From 4fed16fe8b526434d19c69691beaea865e5440cc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 13:00:40 -0400 Subject: [PATCH 06/13] pretty --- src/fix_store_state.cpp | 49 ++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/src/fix_store_state.cpp b/src/fix_store_state.cpp index 0d54d2727e..1f302b4ca3 100644 --- a/src/fix_store_state.cpp +++ b/src/fix_store_state.cpp @@ -142,88 +142,71 @@ FixStoreState::FixStoreState(LAMMPS *lmp, int narg, char **arg) : } else if (strcmp(arg[iarg],"q") == 0) { if (!atom->q_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_q; } else if (strcmp(arg[iarg],"mux") == 0) { if (!atom->mu_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_mux; } else if (strcmp(arg[iarg],"muy") == 0) { if (!atom->mu_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_muy; } else if (strcmp(arg[iarg],"muz") == 0) { if (!atom->mu_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_muz; } else if (strcmp(arg[iarg],"mu") == 0) { if (!atom->mu_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_mu; } else if (strcmp(arg[iarg],"radius") == 0) { if (!atom->radius_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_radius; } else if (strcmp(arg[iarg],"diameter") == 0) { if (!atom->radius_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_diameter; } else if (strcmp(arg[iarg],"omegax") == 0) { if (!atom->omega_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_omegax; } else if (strcmp(arg[iarg],"omegay") == 0) { if (!atom->omega_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_omegay; } else if (strcmp(arg[iarg],"omegaz") == 0) { if (!atom->omega_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_omegaz; } else if (strcmp(arg[iarg],"angmomx") == 0) { if (!atom->angmom_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_angmomx; } else if (strcmp(arg[iarg],"angmomy") == 0) { if (!atom->angmom_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_angmomy; } else if (strcmp(arg[iarg],"angmomz") == 0) { if (!atom->angmom_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_angmomz; } else if (strcmp(arg[iarg],"tqx") == 0) { if (!atom->torque_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_tqx; } else if (strcmp(arg[iarg],"tqy") == 0) { if (!atom->torque_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_tqy; } else if (strcmp(arg[iarg],"tqz") == 0) { if (!atom->torque_flag) - error->all(FLERR, - "Fix store/state for atom property that isn't allocated"); + error->all(FLERR,"Fix store/state for atom property that isn't allocated"); pack_choice[nvalues++] = &FixStoreState::pack_tqz; // compute or fix or variable or custom per-atom vector or array - // NEWSTYLE code } else { ArgInfo argi(arg[iarg],ArgInfo::COMPUTE|ArgInfo::FIX|ArgInfo::VARIABLE From e08c4abb4b3bfa5534b40d03ea0e97376be8f56e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 13:06:00 -0400 Subject: [PATCH 07/13] whitespace fixes --- doc/src/compute_property_atom.rst | 2 +- src/KOKKOS/atom_kokkos.cpp | 12 +++---- src/VTK/dump_vtk.cpp | 6 ++-- src/atom.cpp | 24 +++++++------- src/compute_property_atom.cpp | 14 ++++---- src/compute_property_atom.h | 2 +- src/dump_custom.cpp | 20 ++++++------ src/fix_group.cpp | 8 ++--- src/fix_property_atom.cpp | 22 ++++++------- src/fix_store_state.cpp | 6 ++-- src/library.cpp | 54 +++++++++++++++---------------- src/set.cpp | 4 +-- src/utils.cpp | 6 ++-- 13 files changed, 90 insertions(+), 90 deletions(-) diff --git a/doc/src/compute_property_atom.rst b/doc/src/compute_property_atom.rst index c4657ce82c..fee859d96e 100644 --- a/doc/src/compute_property_atom.rst +++ b/doc/src/compute_property_atom.rst @@ -136,7 +136,7 @@ When that command is used specific names are given to each attribute which are the "name" portion of these attributes. For arrays *i2_name* and *d2_name*, the column of the array must also be included following the name in brackets: e.g. d2_xyz[2], i2_mySpin[3]. - + The additional quantities only accessible via this command, and not directly via the :doc:`dump custom ` command, are as follows. diff --git a/src/KOKKOS/atom_kokkos.cpp b/src/KOKKOS/atom_kokkos.cpp index 3304d638ce..f40b9c324a 100644 --- a/src/KOKKOS/atom_kokkos.cpp +++ b/src/KOKKOS/atom_kokkos.cpp @@ -272,7 +272,7 @@ int AtomKokkos::add_custom(const char *name, int flag, int cols) ivector = (int **) memory->srealloc(ivector,nivector*sizeof(int *), "atom:ivector"); memory->create(ivector[index],nmax,"atom:ivector"); - + } else if (flag == 1 && cols == 0) { index = ndvector; ndvector++; @@ -299,10 +299,10 @@ int AtomKokkos::add_custom(const char *name, int flag, int cols) iarray = (int ***) memory->srealloc(iarray,niarray*sizeof(int **), "atom:iarray"); memory->create(iarray[index],nmax,cols,"atom:iarray"); - + icols = (int *) memory->srealloc(icols,niarray*sizeof(int),"atom:icols"); icols[index] = cols; - + } else if (flag == 1 && cols) { index = ndarray; ndarray++; @@ -318,7 +318,7 @@ int AtomKokkos::add_custom(const char *name, int flag, int cols) dcols = (int *) memory->srealloc(dcols,ndarray*sizeof(int),"atom:dcols"); dcols[index] = cols; } - + return index; } @@ -335,7 +335,7 @@ void AtomKokkos::remove_custom(int index, int flag, int cols) ivector[index] = NULL; delete [] ivname[index]; ivname[index] = NULL; - + } else if (flag == 1 && cols == 0) { dvector[index] = NULL; delete [] dvname[index]; @@ -346,7 +346,7 @@ void AtomKokkos::remove_custom(int index, int flag, int cols) iarray[index] = NULL; delete [] ianame[index]; ianame[index] = NULL; - + } else if (flag == 1 && cols) { memory->destroy(darray[index]); darray[index] = NULL; diff --git a/src/VTK/dump_vtk.cpp b/src/VTK/dump_vtk.cpp index 75092ff204..f94a6957fb 100644 --- a/src/VTK/dump_vtk.cpp +++ b/src/VTK/dump_vtk.cpp @@ -757,7 +757,7 @@ int DumpVTK::count() i = ATTRIBUTES + nfield + ithresh; iwhich = atom->find_custom(id_custom[field2index[i]],flag,cols); int *ivector = atom->ivector[iwhich]; - for (i = 0; i < nlocal; i++) + for (i = 0; i < nlocal; i++) dchoose[i] = ivector[i]; ptr = dchoose; nstride = 1; @@ -775,7 +775,7 @@ int DumpVTK::count() iwhich = atom->find_custom(id_custom[field2index[i]],flag,cols); int **iarray = atom->iarray[iwhich]; int icol = argindex[i] - 1; - for (i = 0; i < nlocal; i++) + for (i = 0; i < nlocal; i++) dchoose[i] = iarray[i][icol]; ptr = dchoose; nstride = 1; @@ -1827,7 +1827,7 @@ int DumpVTK::parse_fields(int narg, char **arg) field2index[ATTRIBUTES+i] = add_variable(argi.get_name()); name[ATTRIBUTES+i] = arg[iarg]; break; - + // custom per-atom integer vector = i_ID case ArgInfo::INAME: diff --git a/src/atom.cpp b/src/atom.cpp index 760aba5845..c1cb9e011b 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -2481,7 +2481,7 @@ int Atom::add_custom(const char *name, int flag, int cols) ivector = (int **) memory->srealloc(ivector,nivector*sizeof(int *), "atom:ivector"); memory->create(ivector[index],nmax,"atom:ivector"); - + } else if (flag == 1 && cols == 0) { index = ndvector; ndvector++; @@ -2501,10 +2501,10 @@ int Atom::add_custom(const char *name, int flag, int cols) iarray = (int ***) memory->srealloc(iarray,niarray*sizeof(int **), "atom:iarray"); memory->create(iarray[index],nmax,cols,"atom:iarray"); - + icols = (int *) memory->srealloc(icols,niarray*sizeof(int),"atom:icols"); icols[index] = cols; - + } else if (flag == 1 && cols) { index = ndarray; ndarray++; @@ -2518,7 +2518,7 @@ int Atom::add_custom(const char *name, int flag, int cols) dcols = (int *) memory->srealloc(dcols,ndarray*sizeof(int),"atom:dcols"); dcols[index] = cols; } - + return index; } @@ -2542,7 +2542,7 @@ void Atom::remove_custom(int index, int flag, int cols) ivector[index] = NULL; delete [] ivname[index]; ivname[index] = NULL; - + } else if (flag == 1 && cols == 0) { memory->destroy(dvector[index]); dvector[index] = NULL; @@ -2554,7 +2554,7 @@ void Atom::remove_custom(int index, int flag, int cols) iarray[index] = NULL; delete [] ianame[index]; ianame[index] = NULL; - + } else if (flag == 1 && cols) { memory->destroy(darray[index]); darray[index] = NULL; @@ -2762,7 +2762,7 @@ void *Atom::extract(const char *name) if (strcmp(name, "damage") == 0) return (void *) damage; // DPD-REACT pakage - + if (strcmp(name,"dpdTheta") == 0) return (void *) dpdTheta; // DPD-MESO package @@ -2790,15 +2790,15 @@ void *Atom::extract(const char *name) if (name[0] == 'd') which = 1; int array = 0; if (name[1] == '2') array = 1; - + int index,flag,cols; if (!array) index = find_custom(&name[2],flag,cols); else index = find_custom(&name[3],flag,cols); - + if (index < 0) return NULL; if (which != flag) return NULL; if ((!array && cols) || (array && !cols)) return NULL; - + if (!which && !array) return (void *) ivector[index]; if (which && !array) return (void *) dvector[index]; if (!which && array) return (void *) iarray[index]; @@ -2906,14 +2906,14 @@ 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 (name[0] == 'd') which = 1; int array = 0; if (name[1] == '2') array = 1; - + int index,flag,cols; if (!array) index = find_custom(&name[2],flag,cols); else index = find_custom(&name[3],flag,cols); diff --git a/src/compute_property_atom.cpp b/src/compute_property_atom.cpp index a7eb4bf144..e8e1293e28 100644 --- a/src/compute_property_atom.cpp +++ b/src/compute_property_atom.cpp @@ -147,8 +147,8 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : pack_choice[i] = &ComputePropertyAtom::pack_mu; // pack magnetic variables - - } else if (strcmp(arg[iarg],"spx") == 0) { + + } else if (strcmp(arg[iarg],"spx") == 0) { if (!atom->sp_flag) error->all(FLERR,"Compute property/atom for " "atom property that isn't allocated"); @@ -185,7 +185,7 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : pack_choice[i] = &ComputePropertyAtom::pack_fmz; // bond count - + } else if (strcmp(arg[iarg],"nbonds") == 0) { if (!atom->molecule_flag) error->all(FLERR,"Compute property/atom for " @@ -193,7 +193,7 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : pack_choice[i] = &ComputePropertyAtom::pack_nbonds; // finite-size particles - + } else if (strcmp(arg[iarg],"radius") == 0) { if (!atom->radius_flag) error->all(FLERR,"Compute property/atom for " @@ -401,11 +401,11 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : // custom per-atom arrays, must include bracketed index // OLDSTYLE code - } else if (strstr(arg[iarg],"i2_") == arg[iarg] || + } else if (strstr(arg[iarg],"i2_") == arg[iarg] || strstr(arg[iarg],"d2_") == arg[iarg]) { int which = 0; if (arg[iarg][0] == 'd') which = 1; - + int n = strlen(arg[iarg]); char *suffix = new char[n]; strcpy(suffix,&arg[iarg][3]); @@ -418,7 +418,7 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : 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; diff --git a/src/compute_property_atom.h b/src/compute_property_atom.h index 19f8b73451..d8b1cae449 100644 --- a/src/compute_property_atom.h +++ b/src/compute_property_atom.h @@ -109,7 +109,7 @@ class ComputePropertyAtom : public Compute { void pack_tqx(int); void pack_tqy(int); void pack_tqz(int); - + void pack_end1x(int); void pack_end1y(int); void pack_end1z(int); diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 68a2ab4a57..3aac7a3e79 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -1046,7 +1046,7 @@ int DumpCustom::count() int iwhich = custom[field2index[i]]; ptr = atom->dvector[iwhich]; nstride = 1; - + } else if (thresh_array[ithresh] == IARRAY) { i = nfield + ithresh; int iwhich = custom[field2index[i]]; @@ -1977,12 +1977,12 @@ int DumpCustom::modify_param(int narg, char **arg) "Dump custom property array is accessed out-of-range"); thresh_array[nthresh] = DARRAY; } - + field2index[nfield+nthresh] = add_custom(name,0); break; // custom per atom integer vector or array - + case ArgInfo::INAME: n = atom->find_custom(name,flag,cols); @@ -2015,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; @@ -2024,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; @@ -2038,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; } @@ -2135,7 +2135,7 @@ void DumpCustom::pack_custom(int n) int flag = custom_flag[field2index[n]]; int iwhich = custom[field2index[n]]; int index = argindex[n]; - + if (flag == IVEC) { int *ivector = atom->ivector[iwhich]; for (int i = 0; i < nchoose; i++) { diff --git a/src/fix_group.cpp b/src/fix_group.cpp index 03a046d3bf..c15f2590c5 100644 --- a/src/fix_group.cpp +++ b/src/fix_group.cpp @@ -61,7 +61,7 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) delete [] idregion; idregion = utils::strdup(arg[iarg+1]); iarg += 2; - + } else if (strcmp(arg[iarg],"var") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal group command"); if (input->variable->find(arg[iarg+1]) < 0) @@ -70,19 +70,19 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) delete [] idvar; idvar = utils::strdup(arg[iarg+1]); iarg += 2; - + } else if (strcmp(arg[iarg],"property") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal group command"); int flag,cols; iprop = atom->find_custom(arg[iarg+1],flag,cols); - if (iprop < 1 || cols) + if (iprop < 1 || cols) error->all(FLERR,"Custom per-atom vector for group dynamic " "does not exist"); propflag = 1; delete [] idprop; idprop = utils::strdup(arg[iarg+1]); iarg += 2; - + } else if (strcmp(arg[iarg],"every") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal group command"); nevery = utils::inumeric(FLERR,arg[iarg+1],false,lmp); diff --git a/src/fix_property_atom.cpp b/src/fix_property_atom.cpp index 0ca8a75632..7ec30025bc 100644 --- a/src/fix_property_atom.cpp +++ b/src/fix_property_atom.cpp @@ -50,7 +50,7 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) : nvalue = 0; values_peratom = 0; - + while (iarg < narg) { if (strcmp(arg[iarg],"mol") == 0) { if (atom->molecule_flag) @@ -114,7 +114,7 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) : // custom atom array // OLDSTYLE code - } else if (strstr(arg[iarg],"i2_") == arg[iarg] || + } else if (strstr(arg[iarg],"i2_") == arg[iarg] || strstr(arg[iarg],"d2_") == arg[iarg]) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix property/atom command"); int which = 0; @@ -539,7 +539,7 @@ void FixPropertyAtom::grow_arrays(int nmax) void FixPropertyAtom::copy_arrays(int i, int j, int /*delflag*/) { int k,ncol; - + for (int nv = 0; nv < nvalue; nv++) { if (style[nv] == MOLECULE) atom->molecule[j] = atom->molecule[i]; @@ -697,15 +697,15 @@ int FixPropertyAtom::pack_exchange(int i, double *buf) else if (style[nv] == DVEC) buf[m++] = atom->dvector[index[nv]][i]; else if (style[nv] == IARRAY) { ncol = cols[nv]; - for (k = 0; k < ncol; k++) + for (k = 0; k < ncol; k++) buf[m++] = ubuf(atom->iarray[index[nv]][i][k]).d; } else if (style[nv] == DARRAY) { ncol = cols[nv]; - for (k = 0; k < ncol; k++) + for (k = 0; k < ncol; k++) buf[m++] = atom->darray[index[nv]][i][k]; } } - + return m; } @@ -731,15 +731,15 @@ int FixPropertyAtom::unpack_exchange(int nlocal, double *buf) atom->dvector[index[nv]][nlocal] = buf[m++]; else if (style[nv] == IARRAY) { ncol = cols[nv]; - for (k = 0; k < ncol; k++) + for (k = 0; k < ncol; k++) atom->iarray[index[nv]][nlocal][k] = (int) ubuf(buf[m++]).i; } else if (style[nv] == DARRAY) { ncol = cols[nv]; - for (k = 0; k < ncol; k++) + for (k = 0; k < ncol; k++) atom->darray[index[nv]][nlocal][k] = buf[m++]; } } - + return m; } @@ -750,9 +750,9 @@ int FixPropertyAtom::unpack_exchange(int nlocal, double *buf) int FixPropertyAtom::pack_restart(int i, double *buf) { int k,ncol; - + // pack buf[0] this way because other fixes unpack it - + buf[0] = values_peratom+1; int m = 1; diff --git a/src/fix_store_state.cpp b/src/fix_store_state.cpp index 1f302b4ca3..1d3d48a06b 100644 --- a/src/fix_store_state.cpp +++ b/src/fix_store_state.cpp @@ -293,7 +293,7 @@ FixStoreState::FixStoreState(LAMMPS *lmp, int narg, char **arg) : } else if (which[i] == ArgInfo::DNAME) { int icustom,iflag,icol; icustom = atom->find_custom(ids[i],iflag,icol); - if (icustom < 0) + if (icustom < 0) error->all(FLERR,"Custom vector/array for fix store/state does not exist"); if (argindex[i] == 0) { if (!iflag || icol) @@ -311,7 +311,7 @@ FixStoreState::FixStoreState(LAMMPS *lmp, int narg, char **arg) : } else if (which[i] == ArgInfo::INAME) { int icustom,iflag,icol; icustom = atom->find_custom(ids[i],iflag,icol); - if (icustom < 0) + if (icustom < 0) error->all(FLERR,"Custom vector/array for fix store/state does not exist"); if (argindex[i] == 0) { if (iflag || icol) @@ -417,7 +417,7 @@ void FixStoreState::init() } 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) + if (icustom < 0) error->all(FLERR,"Custom vector/array for fix store/state does not exist"); value2index[m] = icustom; } diff --git a/src/library.cpp b/src/library.cpp index b6cdd02e9f..1397cf889e 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -2834,7 +2834,7 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) int i,j,offset,fcid,ltype,icol; // error if tags are not defined or not consecutive - + int flag = 0; if (lmp->atom->tag_enable == 0 || lmp->atom->tag_consecutive() == 0) flag = 1; @@ -2849,7 +2849,7 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) void *vptr = lmp->atom->extract(name); // fix - + if (vptr==nullptr && utils::strmatch(name,"^f_")) { fcid = lmp->modify->find_fix(&name[2]); @@ -2884,7 +2884,7 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) } // compute - + if (vptr==nullptr && utils::strmatch(name,"^c_")) { fcid = lmp->modify->find_compute(&name[2]); @@ -2913,7 +2913,7 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) if (count==1) vptr = (void *) lmp->modify->compute[fcid]->vector_atom; else vptr = (void *) lmp->modify->compute[fcid]->array_atom; } - + // custom fix property/atom vector or array // OLDSTYLE code @@ -2930,7 +2930,7 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) lmp->error->warning(FLERR,"lammps_gather: unknown property/atom id"); return; } - + if (ltype != type) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather: mismatch property/atom type"); @@ -2950,7 +2950,7 @@ 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]; - } else { + } else { if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; else vptr = (void *) lmp->atom->darray[fcid]; } @@ -2963,11 +2963,11 @@ void lammps_gather(void *handle, char *name, int type, int count, void *data) lmp->error->warning(FLERR,"lammps_gather: undefined property name"); return; } - + // copy = Natom length vector of per-atom values // use atom ID to insert each atom's values into copy // MPI_Allreduce with MPI_SUM to merge into data, ordered by atom ID - + if (type==0) { int *vector = nullptr; int **array = nullptr; @@ -3078,7 +3078,7 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d int i,offset,fcid,ltype,icol; // error if tags are not defined or not consecutive - + int flag = 0; if (lmp->atom->tag_enable == 0) flag = 1; if (lmp->atom->natoms > MAXSMALLINT) flag = 1; @@ -3126,7 +3126,7 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d } // compute - + if (vptr==nullptr && utils::strmatch(name,"^c_")) { fcid = lmp->modify->find_compute(&name[2]); @@ -3162,7 +3162,7 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d if ((vptr==nullptr) && ((strstr(name,"d_") == name) || (strstr(name,"i_") == name) || (strstr(name,"d2_") == name) || (strstr(name,"i2_") == name))) { - + if ((strstr(name,"d_") == name) || (strstr(name,"i_") == name)) fcid = lmp->atom->find_custom(&name[2],ltype,icol); else fcid = lmp->atom->find_custom(&name[3],ltype,icol); @@ -3173,7 +3173,7 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d "unknown property/atom id"); return; } - + if (ltype != type) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_concat: " @@ -3221,7 +3221,7 @@ void lammps_gather_concat(void *handle, char *name, int type, int count, void *d if (type == 0) { int *vector = nullptr; int **array = nullptr; - + const int imgunpack = (count == 3) && (strcmp(name,"image") == 0); if ((count == 1) || imgunpack) vector = (int *) vptr; @@ -3345,7 +3345,7 @@ void lammps_gather_subset(void *handle, char *name, tagint id; // error if tags are not defined or not consecutive - + int flag = 0; if (lmp->atom->tag_enable == 0) flag = 1; if (lmp->atom->natoms > MAXSMALLINT) flag = 1; @@ -3358,7 +3358,7 @@ void lammps_gather_subset(void *handle, char *name, void *vptr = lmp->atom->extract(name); // fix - + if (vptr==nullptr && utils::strmatch(name,"^f_")) { fcid = lmp->modify->find_fix(&name[2]); @@ -3391,7 +3391,7 @@ void lammps_gather_subset(void *handle, char *name, } // compute - + if (vptr==nullptr && utils::strmatch(name,"^c_")) { fcid = lmp->modify->find_compute(&name[2]); @@ -3438,7 +3438,7 @@ void lammps_gather_subset(void *handle, char *name, "unknown property/atom id"); return; } - + if (ltype != type) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_gather_subset: " @@ -3529,7 +3529,7 @@ void lammps_gather_subset(void *handle, char *name, } else { double *vector = nullptr; double **array = nullptr; - + if (count == 1) vector = (double *) vptr; else array = (double **) vptr; @@ -3619,7 +3619,7 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data) void *vptr = lmp->atom->extract(name); // fix - + if (vptr==nullptr && utils::strmatch(name,"^f_")) { fcid = lmp->modify->find_fix(&name[2]); @@ -3647,7 +3647,7 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data) } // compute - + if (vptr==nullptr && utils::strmatch(name,"^c_")) { fcid = lmp->modify->find_compute(&name[2]); @@ -3679,7 +3679,7 @@ 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))) { @@ -3693,7 +3693,7 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data) lmp->error->warning(FLERR,"lammps_scatter: unknown property/atom id"); return; } - + if (ltype != type) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter: mismatch property/atom type"); @@ -3713,7 +3713,7 @@ 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]; - } else { + } else { if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; else vptr = (void *) lmp->atom->darray[fcid]; } @@ -3843,7 +3843,7 @@ void lammps_scatter_subset(void *handle, char *name,int type, int count, void *vptr = lmp->atom->extract(name); // fix - + if (vptr==nullptr && utils::strmatch(name,"^f_")) { fcid = lmp->modify->find_fix(&name[2]); @@ -3903,7 +3903,7 @@ 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))) { @@ -3918,7 +3918,7 @@ void lammps_scatter_subset(void *handle, char *name,int type, int count, "unknown property/atom id"); return; } - + if (ltype != type) { if (lmp->comm->me == 0) lmp->error->warning(FLERR,"lammps_scatter_subset: " @@ -3939,7 +3939,7 @@ 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]; - } else { + } else { if (ltype==0) vptr = (void *) lmp->atom->iarray[fcid]; else vptr = (void *) lmp->atom->darray[fcid]; } diff --git a/src/set.cpp b/src/set.cpp index 2a36874c8b..2966106345 100644 --- a/src/set.cpp +++ b/src/set.cpp @@ -581,7 +581,7 @@ void Set::command(int narg, char **arg) if (iarg+2 > narg) error->all(FLERR,"Illegal set command"); index_custom = atom->find_custom(argi.get_name(),flag,cols); if (index_custom < 0) error->all(FLERR,"Custom property {} does not exist",pname); - + switch (argi.get_type()) { case ArgInfo::INAME: @@ -1025,7 +1025,7 @@ void Set::set(int keyword) } // update bonus data numbers - + if (keyword == SHAPE) { bigint nlocal_bonus = avec_ellipsoid->nlocal_bonus; MPI_Allreduce(&nlocal_bonus,&atom->nellipsoids,1, diff --git a/src/utils.cpp b/src/utils.cpp index fd3170859b..5be2b37c34 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -633,15 +633,15 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod expandflag = 1; } } - + } else if (arg[iarg][0] == 'd') { *ptr1 = '\0'; int flag,cols; int icustom = lmp->atom->find_custom(&arg[iarg][3],flag,cols); *ptr1 = '['; - + // check for custom per-atom floating point array - + if (icustom >= 0) { if (mode == 1 && flag && cols) { nmax = cols; From 1e37d1ad7ff2a9beb8d9247072b2577d988315b4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 14:34:03 -0400 Subject: [PATCH 08/13] pretty --- src/atom.cpp | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index c1cb9e011b..a0f7099319 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -2472,47 +2472,39 @@ int Atom::add_custom(const char *name, int flag, int cols) { int index; - if (flag == 0 && cols == 0) { + if ((flag == 0) && (cols == 0)) { index = nivector; nivector++; - ivname = (char **) memory->srealloc(ivname,nivector*sizeof(char *), - "atom:ivname"); + ivname = (char **) memory->srealloc(ivname,nivector*sizeof(char *),"atom:ivname"); ivname[index] = utils::strdup(name); - ivector = (int **) memory->srealloc(ivector,nivector*sizeof(int *), - "atom:ivector"); + ivector = (int **) memory->srealloc(ivector,nivector*sizeof(int *),"atom:ivector"); memory->create(ivector[index],nmax,"atom:ivector"); - } else if (flag == 1 && cols == 0) { + } else if ((flag == 1) && (cols == 0)) { index = ndvector; ndvector++; - dvname = (char **) memory->srealloc(dvname,ndvector*sizeof(char *), - "atom:dvname"); + dvname = (char **) memory->srealloc(dvname,ndvector*sizeof(char *),"atom:dvname"); dvname[index] = utils::strdup(name); - dvector = (double **) memory->srealloc(dvector,ndvector*sizeof(double *), - "atom:dvector"); + dvector = (double **) memory->srealloc(dvector,ndvector*sizeof(double *),"atom:dvector"); memory->create(dvector[index],nmax,"atom:dvector"); - } else if (flag == 0 && cols) { + } else if ((flag == 0) && (cols > 0)) { index = niarray; niarray++; - ianame = (char **) memory->srealloc(ianame,niarray*sizeof(char *), - "atom:ianame"); + ianame = (char **) memory->srealloc(ianame,niarray*sizeof(char *),"atom:ianame"); ianame[index] = utils::strdup(name); - iarray = (int ***) memory->srealloc(iarray,niarray*sizeof(int **), - "atom:iarray"); + iarray = (int ***) memory->srealloc(iarray,niarray*sizeof(int **),"atom:iarray"); memory->create(iarray[index],nmax,cols,"atom:iarray"); icols = (int *) memory->srealloc(icols,niarray*sizeof(int),"atom:icols"); icols[index] = cols; - } else if (flag == 1 && cols) { + } else if ((flag == 1) && (cols > 0)) { index = ndarray; ndarray++; - daname = (char **) memory->srealloc(daname,ndarray*sizeof(char *), - "atom:daname"); + daname = (char **) memory->srealloc(daname,ndarray*sizeof(char *),"atom:daname"); daname[index] = utils::strdup(name); - darray = (double ***) memory->srealloc(darray,ndarray*sizeof(double **), - "atom:darray"); + darray = (double ***) memory->srealloc(darray,ndarray*sizeof(double **),"atom:darray"); memory->create(darray[index],nmax,cols,"atom:darray"); dcols = (int *) memory->srealloc(dcols,ndarray*sizeof(int),"atom:dcols"); From 0a99d338f21b6cebee425a60feae9fc3427ab559 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 14:35:02 -0400 Subject: [PATCH 09/13] update argument parsing --- src/fix_property_atom.cpp | 45 ++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/fix_property_atom.cpp b/src/fix_property_atom.cpp index 7ec30025bc..2d122e9b03 100644 --- a/src/fix_property_atom.cpp +++ b/src/fix_property_atom.cpp @@ -112,24 +112,29 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) : iarg++; // custom atom array - // OLDSTYLE code - } else if (strstr(arg[iarg],"i2_") == arg[iarg] || - strstr(arg[iarg],"d2_") == arg[iarg]) { + } else if (utils::strmatch(arg[iarg],"^[id]2_")) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix property/atom command"); - int which = 0; - if (arg[iarg][0] == 'd') which = 1; - if (which == 0) style[nvalue] = IARRAY; - else style[nvalue] = DARRAY; - 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); - if (cols[nvalue] < 1) - error->all(FLERR,"Invalid array columns in fix property/atom"); - index[nvalue] = atom->add_custom(&arg[iarg][3],which,cols[nvalue]); - values_peratom += cols[nvalue]; + + int which,flag,ncols; + which = atom->find_custom(&arg[iarg][3],flag,ncols); + if (which >= 0) + error->all(FLERR,"Fix property/atom array name {} already exists", &arg[iarg][3]); + + ncols = utils::inumeric(FLERR,arg[iarg+1],true,lmp); + if (ncols < 1) + error->all(FLERR,"Invalid array columns number {} in fix property/atom", ncols); + + if (arg[iarg][0] == 'i') { + which = 0; + style[nvalue] = IARRAY; + } else { + which = 1; + style[nvalue] = DARRAY; + } + index[nvalue] = atom->add_custom(&arg[iarg][3],which,ncols); + cols[nvalue] = ncols; + values_peratom += ncols; nvalue++; iarg += 2; @@ -386,15 +391,15 @@ void FixPropertyAtom::write_data_section_pack(int /*mth*/, double **buf) int **iarray = atom->iarray[index[nv]]; ncol = cols[nv]; for (i = 0; i < nlocal; i++) - for (k = 0; k < ncol; k++) - buf[i][icol+k] = ubuf(iarray[i][k]).d; + for (k = 0; k < ncol; k++) + buf[i][icol+k] = ubuf(iarray[i][k]).d; icol += ncol; } else if (style[nv] == DARRAY) { double **darray = atom->darray[index[nv]]; ncol = cols[nv]; for (i = 0; i < nlocal; i++) - for (k = 0; k < ncol; k++) - buf[i][icol+k] = ubuf(darray[i][k]).d; + for (k = 0; k < ncol; k++) + buf[i][icol+k] = darray[i][k]; icol += ncol; } } From de61b3a547fa0267841e0548877339d26359b7a9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 14:35:27 -0400 Subject: [PATCH 10/13] update utils::expand_args --- src/utils.cpp | 79 ++++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 55 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index 5be2b37c34..66d5bf2af2 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -214,7 +214,7 @@ char *utils::fgets_trunc(char *buf, int size, FILE *fp) void utils::sfgets(const char *srcname, int srcline, char *s, int size, FILE *fp, const char *filename, Error *error) { - constexpr int MAXPATHLENBUF=1024; + constexpr int MAXPATHLENBUF = 1024; char *rv = fgets(s, size, fp); if (rv == nullptr) { // something went wrong char buf[MAXPATHLENBUF]; @@ -243,7 +243,7 @@ void utils::sfgets(const char *srcname, int srcline, char *s, int size, FILE *fp void utils::sfread(const char *srcname, int srcline, void *s, size_t size, size_t num, FILE *fp, const char *filename, Error *error) { - constexpr int MAXPATHLENBUF=1024; + constexpr int MAXPATHLENBUF = 1024; size_t rv = fread(s, size, num, fp); if (rv != num) { // something went wrong char buf[MAXPATHLENBUF]; @@ -543,16 +543,21 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod std::string word(arg[iarg]); expandflag = 0; - // only match compute/fix reference with a '*' wildcard + // match compute, fix, or custom property array reference with a '*' wildcard // number range in the first pair of square brackets - if (strmatch(word, "^[cf]_\\w+\\[\\d*\\*\\d*\\]")) { + if (strmatch(word, "^[cf]_\\w+\\[\\d*\\*\\d*\\]") || + strmatch(word, "^[id]2_\\w+\\[\\d*\\*\\d*\\]")) { - // split off the compute/fix ID, the wildcard and trailing text + // split off the compute/fix/property ID, the wildcard and trailing text size_t first = word.find("["); size_t second = word.find("]", first + 1); - id = word.substr(2, first - 2); + if (word[1] == '2') + id = word.substr(3, first - 3); + else + id = word.substr(2, first - 2); + wc = word.substr(first + 1, second - first - 1); tail = word.substr(second + 1); @@ -580,7 +585,7 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod } } - // fix + // fix } else if (word[0] == 'f') { int ifix = lmp->modify->find_fix(id); @@ -609,59 +614,20 @@ 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) { - char *ptr1 = strchr(arg[iarg],'['); - if (ptr1) { - char *ptr2 = strchr(ptr1,']'); - if (ptr2) { - *ptr2 = '\0'; - if (strchr(ptr1,'*')) { + if ((word[0] == 'i') || (word[0] == 'd')) { + int flag, cols; + int icustom = lmp->atom->find_custom(id.c_str(), flag, cols); - if (arg[iarg][0] == 'i') { - *ptr1 = '\0'; - int flag,cols; - int icustom = lmp->atom->find_custom(&arg[iarg][3],flag,cols); - *ptr1 = '['; + if ((icustom >= 0) && (mode == 1) && (cols > 0)) { - // check for custom per-atom integer array + // check for custom per-atom array - if (icustom >= 0) { - if (mode == 1 && !flag && cols) { - nmax = cols; - expandflag = 1; - } - } - - } else if (arg[iarg][0] == 'd') { - *ptr1 = '\0'; - int flag,cols; - int icustom = lmp->atom->find_custom(&arg[iarg][3],flag,cols); - *ptr1 = '['; - - // check for custom per-atom floating point array - - if (icustom >= 0) { - if (mode == 1 && flag && cols) { - nmax = cols; - expandflag = 1; - } - } - } - } + if (((word[0] == 'i') && (flag == 0)) || ((word[0] == 'i') && (flag == 1))) { + nmax = cols; + expandflag = 1; } } - - // split off the array name ID, the wildcard and trailing text - - if (expandflag) { - size_t first = word.find("["); - size_t second = word.find("]", first + 1); - id = word.substr(2, first - 2); - wc = word.substr(first + 1, second - first - 1); - tail = word.substr(second + 1); - } } // expansion will take place @@ -678,7 +644,10 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod for (int index = nlo; index <= nhi; index++) { // assemble and duplicate expanded string - earg[newarg] = utils::strdup(fmt::format("{}_{}[{}]{}", word[0], id, index, tail)); + if (word[1] == '2') + earg[newarg] = utils::strdup(fmt::format("{}2_{}[{}]{}", word[0], id, index, tail)); + else + earg[newarg] = utils::strdup(fmt::format("{}_{}[{}]{}", word[0], id, index, tail)); newarg++; } From 104fa4624ec4cfa4dc9357ce976009d20e670b63 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 18:04:44 -0400 Subject: [PATCH 11/13] correct utils::expand_args() --- src/utils.cpp | 70 +++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index 66d5bf2af2..949d6d7793 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -609,56 +609,54 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod expandflag = 1; } } - } - } - // only match custom array reference with a '*' wildcard - // number range in the first pair of square brackets + // only match custom array reference with a '*' wildcard + // number range in the first pair of square brackets - if ((word[0] == 'i') || (word[0] == 'd')) { - int flag, cols; - int icustom = lmp->atom->find_custom(id.c_str(), flag, cols); + } else if ((word[0] == 'i') || (word[0] == 'd')) { + int flag, cols; + int icustom = lmp->atom->find_custom(id.c_str(), flag, cols); - if ((icustom >= 0) && (mode == 1) && (cols > 0)) { + if ((icustom >= 0) && (mode == 1) && (cols > 0)) { - // check for custom per-atom array + // check for custom per-atom array - if (((word[0] == 'i') && (flag == 0)) || ((word[0] == 'i') && (flag == 1))) { - nmax = cols; - expandflag = 1; + if (((word[0] == 'i') && (flag == 0)) || ((word[0] == 'd') && (flag == 1))) { + nmax = cols; + expandflag = 1; + } } } - } - // expansion will take place + // expansion will take place - if (expandflag) { + if (expandflag) { - // expand wild card string to nlo/nhi numbers - utils::bounds(file, line, wc, 1, nmax, nlo, nhi, lmp->error); + // expand wild card string to nlo/nhi numbers + utils::bounds(file, line, wc, 1, nmax, nlo, nhi, lmp->error); - if (newarg + nhi - nlo + 1 > maxarg) { - maxarg += nhi - nlo + 1; - earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg"); - } + if (newarg + nhi - nlo + 1 > maxarg) { + maxarg += nhi - nlo + 1; + earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg"); + } - for (int index = nlo; index <= nhi; index++) { - // assemble and duplicate expanded string - if (word[1] == '2') - earg[newarg] = utils::strdup(fmt::format("{}2_{}[{}]{}", word[0], id, index, tail)); - else - earg[newarg] = utils::strdup(fmt::format("{}_{}[{}]{}", word[0], id, index, tail)); + for (int index = nlo; index <= nhi; index++) { + // assemble and duplicate expanded string + if (word[1] == '2') + earg[newarg] = utils::strdup(fmt::format("{}2_{}[{}]{}", word[0], id, index, tail)); + else + earg[newarg] = utils::strdup(fmt::format("{}_{}[{}]{}", word[0], id, index, tail)); + newarg++; + } + } else { + // no expansion: duplicate original string + if (newarg == maxarg) { + maxarg++; + earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg"); + } + earg[newarg] = utils::strdup(word); newarg++; } - - } else { - // no expansion: duplicate original string - if (newarg == maxarg) { - maxarg++; - earg = (char **) lmp->memory->srealloc(earg, maxarg * sizeof(char *), "input:earg"); - } - earg[newarg] = utils::strdup(word); - newarg++; } } From f6874af7e5cd21b2958bba3219a26e69334765fe Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 18:05:36 -0400 Subject: [PATCH 12/13] pretty --- src/VTK/dump_vtk.cpp | 4 +- src/compute_property_atom.cpp | 141 ++++++++++++---------------------- src/modify.cpp | 15 ++-- 3 files changed, 54 insertions(+), 106 deletions(-) diff --git a/src/VTK/dump_vtk.cpp b/src/VTK/dump_vtk.cpp index f94a6957fb..f323ce820f 100644 --- a/src/VTK/dump_vtk.cpp +++ b/src/VTK/dump_vtk.cpp @@ -785,8 +785,8 @@ int DumpVTK::count() i = ATTRIBUTES + nfield + ithresh; iwhich = atom->find_custom(id_custom[field2index[i]],flag,cols) double **darray = atom->darray[iwhich]; - ptr = &darray[0][argindex[i]-1]; - nstride = atom->dcols[iwhich]; + ptr = &darray[0][argindex[i]-1]; + nstride = atom->dcols[iwhich]; } // unselect atoms that don't meet threshold criterion diff --git a/src/compute_property_atom.cpp b/src/compute_property_atom.cpp index e8e1293e28..190168db4b 100644 --- a/src/compute_property_atom.cpp +++ b/src/compute_property_atom.cpp @@ -122,262 +122,215 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : } else if (strcmp(arg[iarg],"q") == 0) { if (!atom->q_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_q; } else if (strcmp(arg[iarg],"mux") == 0) { if (!atom->mu_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_mux; } else if (strcmp(arg[iarg],"muy") == 0) { if (!atom->mu_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_muy; } else if (strcmp(arg[iarg],"muz") == 0) { if (!atom->mu_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_muz; } else if (strcmp(arg[iarg],"mu") == 0) { if (!atom->mu_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_mu; // pack magnetic variables } else if (strcmp(arg[iarg],"spx") == 0) { if (!atom->sp_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_spx; } else if (strcmp(arg[iarg],"spy") == 0) { if (!atom->sp_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_spy; } else if (strcmp(arg[iarg],"spz") == 0) { if (!atom->sp_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_spz; } else if (strcmp(arg[iarg],"sp") == 0) { if (!atom->sp_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_sp; } else if (strcmp(arg[iarg],"fmx") == 0) { if (!atom->sp_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_fmx; } else if (strcmp(arg[iarg],"fmy") == 0) { if (!atom->sp_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_fmy; } else if (strcmp(arg[iarg],"fmz") == 0) { if (!atom->sp_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_fmz; // bond count } else if (strcmp(arg[iarg],"nbonds") == 0) { if (!atom->molecule_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_nbonds; // finite-size particles } else if (strcmp(arg[iarg],"radius") == 0) { if (!atom->radius_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_radius; } else if (strcmp(arg[iarg],"diameter") == 0) { if (!atom->radius_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_diameter; } else if (strcmp(arg[iarg],"omegax") == 0) { if (!atom->omega_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_omegax; } else if (strcmp(arg[iarg],"omegay") == 0) { if (!atom->omega_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_omegay; } else if (strcmp(arg[iarg],"omegaz") == 0) { if (!atom->omega_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_omegaz; } else if (strcmp(arg[iarg],"angmomx") == 0) { if (!atom->angmom_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_angmomx; } else if (strcmp(arg[iarg],"angmomy") == 0) { if (!atom->angmom_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_angmomy; } else if (strcmp(arg[iarg],"angmomz") == 0) { if (!atom->angmom_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_angmomz; } else if (strcmp(arg[iarg],"shapex") == 0) { avec_ellipsoid = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); - if (!avec_ellipsoid) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_ellipsoid) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_shapex; } else if (strcmp(arg[iarg],"shapey") == 0) { avec_ellipsoid = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); - if (!avec_ellipsoid) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_ellipsoid) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_shapey; } else if (strcmp(arg[iarg],"shapez") == 0) { avec_ellipsoid = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); - if (!avec_ellipsoid) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_ellipsoid) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_shapez; } else if (strcmp(arg[iarg],"quatw") == 0) { avec_ellipsoid = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); avec_body = (AtomVecBody *) atom->style_match("body"); if (!avec_ellipsoid && !avec_body) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_quatw; } else if (strcmp(arg[iarg],"quati") == 0) { avec_ellipsoid = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); avec_body = (AtomVecBody *) atom->style_match("body"); if (!avec_ellipsoid && !avec_body) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_quati; } else if (strcmp(arg[iarg],"quatj") == 0) { avec_ellipsoid = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); avec_body = (AtomVecBody *) atom->style_match("body"); if (!avec_ellipsoid && !avec_body) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_quatj; } else if (strcmp(arg[iarg],"quatk") == 0) { avec_ellipsoid = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); avec_body = (AtomVecBody *) atom->style_match("body"); if (!avec_ellipsoid && !avec_body) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_quatk; } else if (strcmp(arg[iarg],"tqx") == 0) { if (!atom->torque_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_tqx; } else if (strcmp(arg[iarg],"tqy") == 0) { if (!atom->torque_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_tqy; } else if (strcmp(arg[iarg],"tqz") == 0) { if (!atom->torque_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_tqz; } else if (strcmp(arg[iarg],"end1x") == 0) { avec_line = (AtomVecLine *) atom->style_match("line"); - if (!avec_line) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_line) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_end1x; } else if (strcmp(arg[iarg],"end1y") == 0) { avec_line = (AtomVecLine *) atom->style_match("line"); - if (!avec_line) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_line) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_end1y; } else if (strcmp(arg[iarg],"end1z") == 0) { avec_line = (AtomVecLine *) atom->style_match("line"); - if (!avec_line) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_line) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_end1z; } else if (strcmp(arg[iarg],"end2x") == 0) { avec_line = (AtomVecLine *) atom->style_match("line"); - if (!avec_line) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_line) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_end2x; } else if (strcmp(arg[iarg],"end2y") == 0) { avec_line = (AtomVecLine *) atom->style_match("line"); - if (!avec_line) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_line) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_end2y; } else if (strcmp(arg[iarg],"end2z") == 0) { avec_line = (AtomVecLine *) atom->style_match("line"); - if (!avec_line) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_line) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_end2z; } else if (strcmp(arg[iarg],"corner1x") == 0) { avec_tri = (AtomVecTri *) atom->style_match("tri"); - if (!avec_tri) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_tri) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_corner1x; } else if (strcmp(arg[iarg],"corner1y") == 0) { avec_tri = (AtomVecTri *) atom->style_match("tri"); - if (!avec_tri) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_tri) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_corner1y; } else if (strcmp(arg[iarg],"corner1z") == 0) { avec_tri = (AtomVecTri *) atom->style_match("tri"); - if (!avec_tri) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_tri) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_corner1z; } else if (strcmp(arg[iarg],"corner2x") == 0) { avec_tri = (AtomVecTri *) atom->style_match("tri"); - if (!avec_tri) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_tri) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_corner2x; } else if (strcmp(arg[iarg],"corner2y") == 0) { avec_tri = (AtomVecTri *) atom->style_match("tri"); - if (!avec_tri) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_tri) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_corner2y; } else if (strcmp(arg[iarg],"corner2z") == 0) { avec_tri = (AtomVecTri *) atom->style_match("tri"); - if (!avec_tri) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_tri) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_corner2z; } else if (strcmp(arg[iarg],"corner3x") == 0) { avec_tri = (AtomVecTri *) atom->style_match("tri"); - if (!avec_tri) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_tri) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_corner3x; } else if (strcmp(arg[iarg],"corner3y") == 0) { avec_tri = (AtomVecTri *) atom->style_match("tri"); - if (!avec_tri) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_tri) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_corner3y; } else if (strcmp(arg[iarg],"corner3z") == 0) { avec_tri = (AtomVecTri *) atom->style_match("tri"); - if (!avec_tri) error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + if (!avec_tri) error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_corner3z; } else if (strcmp(arg[iarg],"nbonds") == 0) { if (!atom->molecule_flag) - error->all(FLERR,"Compute property/atom for " - "atom property that isn't allocated"); + error->all(FLERR,"Compute property/atom for atom property that isn't allocated"); pack_choice[i] = &ComputePropertyAtom::pack_nbonds; // custom per-atom vector diff --git a/src/modify.cpp b/src/modify.cpp index 995b3b82ac..eff6ea8337 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -223,16 +223,11 @@ void Modify::init() list_init_energy_global(n_energy_global,list_energy_global); list_init_energy_atom(n_energy_atom,list_energy_atom); - list_init(INITIAL_INTEGRATE_RESPA, - n_initial_integrate_respa,list_initial_integrate_respa); - list_init(POST_INTEGRATE_RESPA, - n_post_integrate_respa,list_post_integrate_respa); - list_init(POST_FORCE_RESPA, - n_post_force_respa,list_post_force_respa); - list_init(PRE_FORCE_RESPA, - n_pre_force_respa,list_pre_force_respa); - list_init(FINAL_INTEGRATE_RESPA, - n_final_integrate_respa,list_final_integrate_respa); + list_init(INITIAL_INTEGRATE_RESPA,n_initial_integrate_respa,list_initial_integrate_respa); + list_init(POST_INTEGRATE_RESPA,n_post_integrate_respa,list_post_integrate_respa); + list_init(POST_FORCE_RESPA,n_post_force_respa,list_post_force_respa); + list_init(PRE_FORCE_RESPA,n_pre_force_respa,list_pre_force_respa); + list_init(FINAL_INTEGRATE_RESPA,n_final_integrate_respa,list_final_integrate_respa); list_init(MIN_PRE_EXCHANGE,n_min_pre_exchange,list_min_pre_exchange); list_init(MIN_PRE_NEIGHBOR,n_min_pre_neighbor,list_min_pre_neighbor); From b19a211d701685390d33e4603f9f06dd674d91ee Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 18 Aug 2021 18:06:21 -0400 Subject: [PATCH 13/13] 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]; } }