From a76a8eae59354f28c07a8c752393f86886abfd50 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 16 Mar 2021 23:41:18 -0400 Subject: [PATCH 01/11] fix segfault when processing empty lines --- src/library.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index aefc28801f..8de36a299f 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -444,12 +444,11 @@ is passed to :cpp:func:`lammps_commands_string` for processing. void lammps_commands_list(void *handle, int ncmd, const char **cmds) { - LAMMPS *lmp = (LAMMPS *) handle; std::string allcmds; for (int i = 0; i < ncmd; i++) { allcmds.append(cmds[i]); - if (allcmds.back() != '\n') allcmds.append(1,'\n'); + if (allcmds.empty() || (allcmds.back() != '\n')) allcmds.append(1,'\n'); } lammps_commands_string(handle,allcmds.c_str()); From 2dc0b705755393d14f70e01981458208755f5335 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 17 Mar 2021 00:10:01 -0400 Subject: [PATCH 02/11] simplify some more code by using utils::strdup() --- src/force.cpp | 20 ++++++-------------- src/imbalance_store.cpp | 5 +---- src/imbalance_var.cpp | 5 +---- src/input.cpp | 15 ++++----------- 4 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/force.cpp b/src/force.cpp index 0073366c27..e56e250ffc 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -61,20 +61,12 @@ Force::Force(LAMMPS *lmp) : Pointers(lmp) improper = nullptr; kspace = nullptr; - char *str = (char *) "none"; - int n = strlen(str) + 1; - pair_style = new char[n]; - strcpy(pair_style,str); - bond_style = new char[n]; - strcpy(bond_style,str); - angle_style = new char[n]; - strcpy(angle_style,str); - dihedral_style = new char[n]; - strcpy(dihedral_style,str); - improper_style = new char[n]; - strcpy(improper_style,str); - kspace_style = new char[n]; - strcpy(kspace_style,str); + pair_style = utils::strdup("none"); + bond_style = utils::strdup("none"); + angle_style = utils::strdup("none"); + dihedral_style = utils::strdup("none"); + improper_style = utils::strdup("none"); + kspace_style = utils::strdup("none"); pair_restart = nullptr; create_factories(); diff --git a/src/imbalance_store.cpp b/src/imbalance_store.cpp index 9815744b2d..879b434bfd 100644 --- a/src/imbalance_store.cpp +++ b/src/imbalance_store.cpp @@ -36,10 +36,7 @@ ImbalanceStore::~ImbalanceStore() int ImbalanceStore::options(int narg, char **arg) { if (narg < 1) error->all(FLERR,"Illegal balance weight command"); - - int len = strlen(arg[0]) + 1; - name = new char[len]; - memcpy(name,arg[0],len); + name = utils::strdup(arg[0]); return 1; } diff --git a/src/imbalance_var.cpp b/src/imbalance_var.cpp index 2265e6e4c0..d2a4f0d691 100644 --- a/src/imbalance_var.cpp +++ b/src/imbalance_var.cpp @@ -40,10 +40,7 @@ ImbalanceVar::~ImbalanceVar() int ImbalanceVar::options(int narg, char **arg) { if (narg < 1) error->all(FLERR,"Illegal balance weight command"); - - int len = strlen(arg[0]) + 1; - name = new char[len]; - memcpy(name,arg[0],len); + name = utils::strdup(arg[0]); init(0); return 1; diff --git a/src/input.cpp b/src/input.cpp index eeb211a6d1..9ac140753a 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1013,9 +1013,7 @@ void Input::jump() if (narg == 2) { label_active = 1; if (labelstr) delete [] labelstr; - int n = strlen(arg[1]) + 1; - labelstr = new char[n]; - strcpy(labelstr,arg[1]); + labelstr = utils::strdup(arg[1]); } } @@ -1840,17 +1838,12 @@ void Input::suffix() if (strcmp(arg[0],"hybrid") == 0) { if (narg != 3) error->all(FLERR,"Illegal suffix command"); - int n = strlen(arg[1]) + 1; - lmp->suffix = new char[n]; - strcpy(lmp->suffix,arg[1]); + lmp->suffix = utils::strdup(arg[1]); n = strlen(arg[2]) + 1; - lmp->suffix2 = new char[n]; - strcpy(lmp->suffix2,arg[2]); + lmp->suffix2 = utils::strdup(arg[2]); } else { if (narg != 1) error->all(FLERR,"Illegal suffix command"); - int n = strlen(arg[0]) + 1; - lmp->suffix = new char[n]; - strcpy(lmp->suffix,arg[0]); + lmp->suffix = utils::strdup(arg[0]); } } } From 5ba57fdd446be186e82ef9cb5b818575caaa534c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 17 Mar 2021 00:21:40 -0400 Subject: [PATCH 03/11] forgot to delete this line --- src/input.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/input.cpp b/src/input.cpp index 9ac140753a..53fcc606db 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1839,7 +1839,6 @@ void Input::suffix() if (strcmp(arg[0],"hybrid") == 0) { if (narg != 3) error->all(FLERR,"Illegal suffix command"); lmp->suffix = utils::strdup(arg[1]); - n = strlen(arg[2]) + 1; lmp->suffix2 = utils::strdup(arg[2]); } else { if (narg != 1) error->all(FLERR,"Illegal suffix command"); From c5ab2becd790649e14845cd8dee45bfa7190e49d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 12:25:31 -0400 Subject: [PATCH 04/11] fix bug in utils::expand_args() --- src/utils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils.cpp b/src/utils.cpp index 3754a9886f..b5576b9f27 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -473,6 +473,7 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, for (iarg = 0; iarg < narg; iarg++) { std::string word(arg[iarg]); + expandflag = 0; // only match compute/fix reference with a '*' wildcard // number range in the first pair of square brackets From 59c0325f0884fc11618967b06c5f52db4c21b843 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 19:58:04 -0400 Subject: [PATCH 05/11] simplify by using utils::strdup() --- src/compute.cpp | 15 ++++----------- src/compute_angle_local.cpp | 8 ++------ src/compute_angmom_chunk.cpp | 4 +--- src/compute_bond_local.cpp | 8 ++------ src/compute_centroid_stress_atom.cpp | 4 +--- src/compute_chunk_atom.cpp | 4 +--- src/compute_chunk_spread_atom.cpp | 4 +--- src/compute_com_chunk.cpp | 4 +--- src/compute_coord_atom.cpp | 4 +--- src/compute_dihedral_local.cpp | 8 ++------ src/compute_dipole_chunk.cpp | 4 +--- src/compute_displace_atom.cpp | 12 ++++-------- src/compute_group_group.cpp | 5 +---- src/compute_gyration_chunk.cpp | 4 +--- src/compute_heat_flux.cpp | 14 +++----------- src/compute_inertia_chunk.cpp | 4 +--- src/compute_msd_chunk.cpp | 12 ++++-------- src/compute_omega_chunk.cpp | 4 +--- src/compute_pair.cpp | 11 +++++------ src/compute_pressure.cpp | 15 ++++++--------- src/compute_property_chunk.cpp | 4 +--- src/compute_reduce.cpp | 4 +--- src/compute_reduce_chunk.cpp | 4 +--- src/compute_stress_atom.cpp | 4 +--- src/compute_temp_chunk.cpp | 8 ++------ src/compute_temp_region.cpp | 4 +--- src/compute_temp_sphere.cpp | 4 +--- src/compute_torque_chunk.cpp | 4 +--- src/compute_vcm_chunk.cpp | 4 +--- 29 files changed, 53 insertions(+), 135 deletions(-) diff --git a/src/compute.cpp b/src/compute.cpp index df2bf9429c..81e317076c 100644 --- a/src/compute.cpp +++ b/src/compute.cpp @@ -49,22 +49,15 @@ Compute::Compute(LAMMPS *lmp, int narg, char **arg) : // compute ID, group, and style // ID must be all alphanumeric chars or underscores - int n = strlen(arg[0]) + 1; - id = new char[n]; - strcpy(id,arg[0]); - - for (int i = 0; i < n-1; i++) - if (!isalnum(id[i]) && id[i] != '_') - error->all(FLERR, - "Compute ID must be alphanumeric or underscore characters"); + id = utils::strdup(arg[0]); + if (!utils::is_id(id)) + error->all(FLERR,"Compute ID must be alphanumeric or underscore characters"); igroup = group->find(arg[1]); if (igroup == -1) error->all(FLERR,"Could not find compute group ID"); groupbit = group->bitmask[igroup]; - n = strlen(arg[2]) + 1; - style = new char[n]; - strcpy(style,arg[2]); + style = utils::strdup(arg[2]); // set child class defaults diff --git a/src/compute_angle_local.cpp b/src/compute_angle_local.cpp index 8e24eccf01..d0630f07eb 100644 --- a/src/compute_angle_local.cpp +++ b/src/compute_angle_local.cpp @@ -67,9 +67,7 @@ ComputeAngleLocal::ComputeAngleLocal(LAMMPS *lmp, int narg, char **arg) : bstyle[nvalues++] = ENG; } else if (strncmp(arg[iarg],"v_",2) == 0) { bstyle[nvalues++] = VARIABLE; - int n = strlen(arg[iarg]); - vstr[nvar] = new char[n]; - strcpy(vstr[nvar],&arg[iarg][2]); + vstr[nvar] = utils::strdup(&arg[iarg][2]); nvar++; } else break; } @@ -85,9 +83,7 @@ ComputeAngleLocal::ComputeAngleLocal(LAMMPS *lmp, int narg, char **arg) : if (iarg+3 > narg) error->all(FLERR,"Illegal compute angle/local command"); if (strcmp(arg[iarg+1],"theta") == 0) { delete [] tstr; - int n = strlen(arg[iarg+2]) + 1; - tstr = new char[n]; - strcpy(tstr,arg[iarg+2]); + tstr = utils::strdup(arg[iarg+2]); tflag = 1; } else error->all(FLERR,"Illegal compute angle/local command"); iarg += 3; diff --git a/src/compute_angmom_chunk.cpp b/src/compute_angmom_chunk.cpp index d35f274d7a..39cae07503 100644 --- a/src/compute_angmom_chunk.cpp +++ b/src/compute_angmom_chunk.cpp @@ -41,9 +41,7 @@ ComputeAngmomChunk::ComputeAngmomChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_bond_local.cpp b/src/compute_bond_local.cpp index d13f313aea..053c4c83dc 100644 --- a/src/compute_bond_local.cpp +++ b/src/compute_bond_local.cpp @@ -74,9 +74,7 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) : else if (strcmp(arg[iarg],"velvib") == 0) bstyle[nvalues++] = VELVIB; else if (strncmp(arg[iarg],"v_",2) == 0) { bstyle[nvalues++] = VARIABLE; - int n = strlen(arg[iarg]); - vstr[nvar] = new char[n]; - strcpy(vstr[nvar],&arg[iarg][2]); + vstr[nvar] = utils::strdup(&arg[iarg][2]); nvar++; } else break; } @@ -92,9 +90,7 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) : if (iarg+3 > narg) error->all(FLERR,"Illegal compute bond/local command"); if (strcmp(arg[iarg+1],"dist") == 0) { delete [] dstr; - int n = strlen(arg[iarg+2]) + 1; - dstr = new char[n]; - strcpy(dstr,arg[iarg+2]); + dstr = utils::strdup(arg[iarg+2]); } else error->all(FLERR,"Illegal compute bond/local command"); iarg += 3; } else error->all(FLERR,"Illegal compute bond/local command"); diff --git a/src/compute_centroid_stress_atom.cpp b/src/compute_centroid_stress_atom.cpp index 9ad871382c..a0abbe8406 100644 --- a/src/compute_centroid_stress_atom.cpp +++ b/src/compute_centroid_stress_atom.cpp @@ -51,9 +51,7 @@ ComputeCentroidStressAtom::ComputeCentroidStressAtom(LAMMPS *lmp, int narg, char if (strcmp(arg[3],"NULL") == 0) id_temp = nullptr; else { - int n = strlen(arg[3]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[3]); + id_temp = utils::strdup(arg[3]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/compute_chunk_atom.cpp b/src/compute_chunk_atom.cpp index 2800c9129b..be1e1e1035 100644 --- a/src/compute_chunk_atom.cpp +++ b/src/compute_chunk_atom.cpp @@ -185,9 +185,7 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : int iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) error->all(FLERR,"Region ID for compute chunk/atom does not exist"); - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); regionflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"nchunk") == 0) { diff --git a/src/compute_chunk_spread_atom.cpp b/src/compute_chunk_spread_atom.cpp index 257e5d0960..d817141064 100644 --- a/src/compute_chunk_spread_atom.cpp +++ b/src/compute_chunk_spread_atom.cpp @@ -36,9 +36,7 @@ ComputeChunkSpreadAtom(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init_chunk(); // expand args if any have wildcard character "*" diff --git a/src/compute_com_chunk.cpp b/src/compute_com_chunk.cpp index 54b2354d26..a67b412b9e 100644 --- a/src/compute_com_chunk.cpp +++ b/src/compute_com_chunk.cpp @@ -43,9 +43,7 @@ ComputeCOMChunk::ComputeCOMChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_coord_atom.cpp b/src/compute_coord_atom.cpp index 51a3618d5a..1c56466b36 100644 --- a/src/compute_coord_atom.cpp +++ b/src/compute_coord_atom.cpp @@ -85,9 +85,7 @@ ComputeCoordAtom::ComputeCoordAtom(LAMMPS *lmp, int narg, char **arg) : cstyle = ORIENT; if (narg != 6) error->all(FLERR,"Illegal compute coord/atom command"); - int n = strlen(arg[4]) + 1; - id_orientorder = new char[n]; - strcpy(id_orientorder,arg[4]); + id_orientorder = utils::strdup(arg[4]); int iorientorder = modify->find_compute(id_orientorder); if (iorientorder < 0) diff --git a/src/compute_dihedral_local.cpp b/src/compute_dihedral_local.cpp index d6fa722e26..908acff98c 100644 --- a/src/compute_dihedral_local.cpp +++ b/src/compute_dihedral_local.cpp @@ -64,9 +64,7 @@ ComputeDihedralLocal::ComputeDihedralLocal(LAMMPS *lmp, int narg, char **arg) : bstyle[nvalues++] = PHI; } else if (strncmp(arg[iarg],"v_",2) == 0) { bstyle[nvalues++] = VARIABLE; - int n = strlen(arg[iarg]); - vstr[nvar] = new char[n]; - strcpy(vstr[nvar],&arg[iarg][2]); + vstr[nvar] = utils::strdup(&arg[iarg][2]); nvar++; } else break; } @@ -83,9 +81,7 @@ ComputeDihedralLocal::ComputeDihedralLocal(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Illegal compute dihedral/local command"); if (strcmp(arg[iarg+1],"phi") == 0) { delete [] pstr; - int n = strlen(arg[iarg+2]) + 1; - pstr = new char[n]; - strcpy(pstr,arg[iarg+2]); + pstr = utils::strdup(arg[iarg+2]); } else error->all(FLERR,"Illegal compute dihedral/local command"); iarg += 3; } else error->all(FLERR,"Illegal compute dihedral/local command"); diff --git a/src/compute_dipole_chunk.cpp b/src/compute_dipole_chunk.cpp index 540e533727..708ea3f755 100644 --- a/src/compute_dipole_chunk.cpp +++ b/src/compute_dipole_chunk.cpp @@ -49,9 +49,7 @@ ComputeDipoleChunk::ComputeDipoleChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); usecenter = MASSCENTER; diff --git a/src/compute_displace_atom.cpp b/src/compute_displace_atom.cpp index 445caa15dc..4e4b87f99c 100644 --- a/src/compute_displace_atom.cpp +++ b/src/compute_displace_atom.cpp @@ -53,9 +53,7 @@ ComputeDisplaceAtom::ComputeDisplaceAtom(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Illegal compute displace/atom command"); refreshflag = 1; delete [] rvar; - int n = strlen(arg[iarg+1]) + 1; - rvar = new char[n]; - strcpy(rvar,arg[iarg+1]); + rvar = utils::strdup(arg[iarg+1]); iarg += 2; } else error->all(FLERR,"Illegal compute displace/atom command"); } @@ -74,11 +72,9 @@ ComputeDisplaceAtom::ComputeDisplaceAtom(LAMMPS *lmp, int narg, char **arg) : // create a new fix STORE style // id = compute-ID + COMPUTE_STORE, fix group = compute group - std::string cmd = id + std::string("_COMPUTE_STORE"); - id_fix = new char[cmd.size()+1]; - strcpy(id_fix,cmd.c_str()); - - cmd += fmt::format(" {} STORE peratom 1 3", group->names[igroup]); + id_fix = utils::strdup(std::string(id) + "_COMPUTE_STORE"); + std::string cmd = id_fix + fmt::format(" {} STORE peratom 1 3", + group->names[igroup]); modify->add_fix(cmd); fix = (FixStore *) modify->fix[modify->nfix-1]; diff --git a/src/compute_group_group.cpp b/src/compute_group_group.cpp index be670332de..7912b4e031 100644 --- a/src/compute_group_group.cpp +++ b/src/compute_group_group.cpp @@ -54,10 +54,7 @@ ComputeGroupGroup::ComputeGroupGroup(LAMMPS *lmp, int narg, char **arg) : extscalar = 1; extvector = 1; - int n = strlen(arg[3]) + 1; - group2 = new char[n]; - strcpy(group2,arg[3]); - + group2 = utils::strdup(arg[3]); jgroup = group->find(group2); if (jgroup == -1) error->all(FLERR,"Compute group/group group ID does not exist"); diff --git a/src/compute_gyration_chunk.cpp b/src/compute_gyration_chunk.cpp index d2af181eaf..c2db9fa855 100644 --- a/src/compute_gyration_chunk.cpp +++ b/src/compute_gyration_chunk.cpp @@ -36,9 +36,7 @@ ComputeGyrationChunk::ComputeGyrationChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_heat_flux.cpp b/src/compute_heat_flux.cpp index 91019aef28..b2e5662a6b 100644 --- a/src/compute_heat_flux.cpp +++ b/src/compute_heat_flux.cpp @@ -43,17 +43,9 @@ ComputeHeatFlux::ComputeHeatFlux(LAMMPS *lmp, int narg, char **arg) : // store ke/atom, pe/atom, stress/atom IDs used by heat flux computation // insure they are valid for these computations - int n = strlen(arg[3]) + 1; - id_ke = new char[n]; - strcpy(id_ke,arg[3]); - - n = strlen(arg[4]) + 1; - id_pe = new char[n]; - strcpy(id_pe,arg[4]); - - n = strlen(arg[5]) + 1; - id_stress = new char[n]; - strcpy(id_stress,arg[5]); + id_ke = utils::strdup(arg[3]); + id_pe = utils::strdup(arg[4]); + id_stress = utils::strdup(arg[5]); int ike = modify->find_compute(id_ke); int ipe = modify->find_compute(id_pe); diff --git a/src/compute_inertia_chunk.cpp b/src/compute_inertia_chunk.cpp index d2c6d345ce..9e0084acfb 100644 --- a/src/compute_inertia_chunk.cpp +++ b/src/compute_inertia_chunk.cpp @@ -41,9 +41,7 @@ ComputeInertiaChunk::ComputeInertiaChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_msd_chunk.cpp b/src/compute_msd_chunk.cpp index 9dc3281b78..39ed9d1f1c 100644 --- a/src/compute_msd_chunk.cpp +++ b/src/compute_msd_chunk.cpp @@ -44,9 +44,7 @@ ComputeMSDChunk::ComputeMSDChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); firstflag = 1; init(); @@ -58,11 +56,9 @@ ComputeMSDChunk::ComputeMSDChunk(LAMMPS *lmp, int narg, char **arg) : // potentially re-populate the fix array (and change it to correct size) // otherwise size reset and init will be done in setup() - std::string fixcmd = id + std::string("_COMPUTE_STORE"); - id_fix = new char[fixcmd.size()+1]; - strcpy(id_fix,fixcmd.c_str()); - - fixcmd += fmt::format(" {} STORE global 1 1",group->names[igroup]); + id_fix = utils::strdup(std::string(id) + "_COMPUTE_STORE"); + std::string fixcmd = id_fix + + fmt::format(" {} STORE global 1 1",group->names[igroup]); modify->add_fix(fixcmd); fix = (FixStore *) modify->fix[modify->nfix-1]; } diff --git a/src/compute_omega_chunk.cpp b/src/compute_omega_chunk.cpp index b721f0efb5..da3b482341 100644 --- a/src/compute_omega_chunk.cpp +++ b/src/compute_omega_chunk.cpp @@ -45,9 +45,7 @@ ComputeOmegaChunk::ComputeOmegaChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_pair.cpp b/src/compute_pair.cpp index 4fd7de736d..aa9df260b1 100644 --- a/src/compute_pair.cpp +++ b/src/compute_pair.cpp @@ -37,10 +37,10 @@ ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) : peflag = 1; timeflag = 1; - int n = strlen(arg[3]) + 1; - if (lmp->suffix) n += strlen(lmp->suffix) + 1; - pstyle = new char[n]; - strcpy(pstyle,arg[3]); + // copy with suffix so we can later chop it off, if needed + if (lmp->suffix) + pstyle = utils::strdup(fmt::format("{}/{}",arg[3],lmp->suffix)); + else pstyle = utils::strdup(arg[3]); int iarg = 4; nsub = 0; @@ -67,8 +67,7 @@ ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) : pair = force->pair_match(pstyle,1,nsub); if (!pair && lmp->suffix) { - strcat(pstyle,"/"); - strcat(pstyle,lmp->suffix); + pstyle[strlen(pstyle) - strlen(lmp->suffix) - 1] = '\0'; pair = force->pair_match(pstyle,1,nsub); } diff --git a/src/compute_pressure.cpp b/src/compute_pressure.cpp index 82ddbbb5c5..3bf66f42ce 100644 --- a/src/compute_pressure.cpp +++ b/src/compute_pressure.cpp @@ -53,9 +53,7 @@ ComputePressure::ComputePressure(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[3],"NULL") == 0) id_temp = nullptr; else { - int n = strlen(arg[3]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[3]); + id_temp = utils::strdup(arg[3]); int icompute = modify->find_compute(id_temp); if (icompute < 0) @@ -82,10 +80,10 @@ ComputePressure::ComputePressure(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"ke") == 0) keflag = 1; else if (strcmp(arg[iarg],"pair/hybrid") == 0) { - int n = strlen(arg[++iarg]) + 1; - if (lmp->suffix) n += strlen(lmp->suffix) + 1; - pstyle = new char[n]; - strcpy(pstyle,arg[iarg++]); + if (lmp->suffix) + pstyle = utils::strdup(fmt::format("{}/{}",arg[++iarg],lmp->suffix)); + else + pstyle = utils::strdup(arg[++iarg]); nsub = 0; @@ -102,8 +100,7 @@ ComputePressure::ComputePressure(LAMMPS *lmp, int narg, char **arg) : pairhybrid = (Pair *) force->pair_match(pstyle,1,nsub); if (!pairhybrid && lmp->suffix) { - strcat(pstyle,"/"); - strcat(pstyle,lmp->suffix); + pstyle[strlen(pstyle) - strlen(lmp->suffix) - 1] = '\0'; pairhybrid = (Pair *) force->pair_match(pstyle,1,nsub); } diff --git a/src/compute_property_chunk.cpp b/src/compute_property_chunk.cpp index d1588b61a3..72e9831b0c 100644 --- a/src/compute_property_chunk.cpp +++ b/src/compute_property_chunk.cpp @@ -33,9 +33,7 @@ ComputePropertyChunk::ComputePropertyChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_reduce.cpp b/src/compute_reduce.cpp index bc9aeefe7b..30b4fcb98a 100644 --- a/src/compute_reduce.cpp +++ b/src/compute_reduce.cpp @@ -47,9 +47,7 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : iregion = domain->find_region(arg[3]); if (iregion == -1) error->all(FLERR,"Region ID for compute reduce/region does not exist"); - int n = strlen(arg[3]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[3]); + idregion = utils::strdup(arg[3]); iarg = 4; } diff --git a/src/compute_reduce_chunk.cpp b/src/compute_reduce_chunk.cpp index a09d37b9d8..e895a13b18 100644 --- a/src/compute_reduce_chunk.cpp +++ b/src/compute_reduce_chunk.cpp @@ -45,9 +45,7 @@ ComputeReduceChunk::ComputeReduceChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init_chunk(); // mode diff --git a/src/compute_stress_atom.cpp b/src/compute_stress_atom.cpp index 28abc13453..0d27031326 100644 --- a/src/compute_stress_atom.cpp +++ b/src/compute_stress_atom.cpp @@ -51,9 +51,7 @@ ComputeStressAtom::ComputeStressAtom(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[3],"NULL") == 0) id_temp = nullptr; else { - int n = strlen(arg[3]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[3]); + id_temp = utils::strdup(arg[3]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/compute_temp_chunk.cpp b/src/compute_temp_chunk.cpp index 765effa6c0..31f955fcb5 100644 --- a/src/compute_temp_chunk.cpp +++ b/src/compute_temp_chunk.cpp @@ -44,9 +44,7 @@ ComputeTempChunk::ComputeTempChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); biasflag = 0; init(); @@ -87,9 +85,7 @@ ComputeTempChunk::ComputeTempChunk(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal compute temp/chunk command"); biasflag = 1; - int n = strlen(arg[iarg+1]) + 1; - id_bias = new char[n]; - strcpy(id_bias,arg[iarg+1]); + id_bias = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"adof") == 0) { if (iarg+2 > narg) diff --git a/src/compute_temp_region.cpp b/src/compute_temp_region.cpp index e1ce4e024b..036f118a30 100644 --- a/src/compute_temp_region.cpp +++ b/src/compute_temp_region.cpp @@ -36,9 +36,7 @@ ComputeTempRegion::ComputeTempRegion(LAMMPS *lmp, int narg, char **arg) : iregion = domain->find_region(arg[3]); if (iregion == -1) error->all(FLERR,"Region ID for compute temp/region does not exist"); - int n = strlen(arg[3]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[3]); + idregion = utils::strdup(arg[3]); scalar_flag = vector_flag = 1; size_vector = 6; diff --git a/src/compute_temp_sphere.cpp b/src/compute_temp_sphere.cpp index 8ffb1b2d6f..b8ac7cf566 100644 --- a/src/compute_temp_sphere.cpp +++ b/src/compute_temp_sphere.cpp @@ -51,9 +51,7 @@ ComputeTempSphere::ComputeTempSphere(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal compute temp/sphere command"); tempbias = 1; - int n = strlen(arg[iarg+1]) + 1; - id_bias = new char[n]; - strcpy(id_bias,arg[iarg+1]); + id_bias = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"dof") == 0) { if (iarg+2 > narg) diff --git a/src/compute_torque_chunk.cpp b/src/compute_torque_chunk.cpp index d961c914e8..9aea024114 100644 --- a/src/compute_torque_chunk.cpp +++ b/src/compute_torque_chunk.cpp @@ -40,9 +40,7 @@ ComputeTorqueChunk::ComputeTorqueChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_vcm_chunk.cpp b/src/compute_vcm_chunk.cpp index 182e8191cb..dd4bac208f 100644 --- a/src/compute_vcm_chunk.cpp +++ b/src/compute_vcm_chunk.cpp @@ -41,9 +41,7 @@ ComputeVCMChunk::ComputeVCMChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); From 1710fb86d392eb84696f021589dad8b621e3ea5f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 20:33:36 -0400 Subject: [PATCH 06/11] when using INTEL_LR_THREADS from C++11 we must add the threads library --- cmake/Modules/Packages/USER-INTEL.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/Packages/USER-INTEL.cmake b/cmake/Modules/Packages/USER-INTEL.cmake index ff0858f0ff..90ab6167a3 100644 --- a/cmake/Modules/Packages/USER-INTEL.cmake +++ b/cmake/Modules/Packages/USER-INTEL.cmake @@ -30,7 +30,12 @@ if(INTEL_LRT_MODE STREQUAL "THREADS") endif() endif() if(INTEL_LRT_MODE STREQUAL "C++11") - target_compile_definitions(lammps PRIVATE -DLMP_INTEL_USELRT -DLMP_INTEL_LRT11) + if(Threads_FOUND) + target_compile_definitions(lammps PRIVATE -DLMP_INTEL_USELRT -DLMP_INTEL_LRT11) + target_link_libraries(lammps PRIVATE Threads::Threads) + else() + message(FATAL_ERROR "Must have working threads library for Long-range thread support") + endif() endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") From a5563e8d0445f48b0ea4fd3ab4268d71bf9c86ad Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 20:56:04 -0400 Subject: [PATCH 07/11] simplify using utils::strdup() --- src/fix.cpp | 14 ++++---------- src/fix_ave_chunk.cpp | 24 ++++++------------------ src/fix_ave_correlate.cpp | 12 +++--------- src/fix_ave_histo.cpp | 12 +++--------- src/fix_ave_time.cpp | 16 ++++------------ src/fix_box_relax.cpp | 8 ++------ src/fix_controller.cpp | 4 +--- src/fix_deform.cpp | 16 ++++------------ src/fix_group.cpp | 23 +++++++---------------- src/fix_nh.cpp | 12 +++--------- src/fix_press_berendsen.cpp | 8 ++------ src/fix_spring.cpp | 4 +--- src/fix_spring_chunk.cpp | 9 ++------- src/fix_temp_berendsen.cpp | 4 +--- src/fix_temp_csld.cpp | 4 +--- src/fix_temp_csvr.cpp | 4 +--- src/fix_temp_rescale.cpp | 4 +--- src/fix_wall_region.cpp | 4 +--- 18 files changed, 47 insertions(+), 135 deletions(-) diff --git a/src/fix.cpp b/src/fix.cpp index 8cf13f6f1d..b9d9fb3969 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -42,21 +42,15 @@ Fix::Fix(LAMMPS *lmp, int /*narg*/, char **arg) : // fix ID, group, and style // ID must be all alphanumeric chars or underscores - int n = strlen(arg[0]) + 1; - id = new char[n]; - strcpy(id,arg[0]); - - for (int i = 0; i < n-1; i++) - if (!isalnum(id[i]) && id[i] != '_') - error->all(FLERR,"Fix ID must be alphanumeric or underscore characters"); + id = utils::strdup(arg[0]); + if (!utils::is_id(id)) + error->all(FLERR,"Fix ID must be alphanumeric or underscore characters"); igroup = group->find(arg[1]); if (igroup == -1) error->all(FLERR,"Could not find fix group ID"); groupbit = group->bitmask[igroup]; - n = strlen(arg[2]) + 1; - style = new char[n]; - strcpy(style,arg[2]); + style = utils::strdup(arg[2]); restart_global = restart_peratom = restart_file = 0; force_reneighbor = 0; diff --git a/src/fix_ave_chunk.cpp b/src/fix_ave_chunk.cpp index 3b612aeb73..d3220dd9df 100644 --- a/src/fix_ave_chunk.cpp +++ b/src/fix_ave_chunk.cpp @@ -57,9 +57,7 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) : nrepeat = utils::inumeric(FLERR,arg[4],false,lmp); nfreq = utils::inumeric(FLERR,arg[5],false,lmp); - int n = strlen(arg[6]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[6]); + idchunk = utils::strdup(arg[6]); global_freq = nfreq; no_change_box = 1; @@ -190,9 +188,7 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command"); biasflag = 1; - int n = strlen(arg[iarg+1]) + 1; - id_bias = new char[n]; - strcpy(id_bias,arg[iarg+1]); + id_bias = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"adof") == 0) { if (iarg+2 > narg) @@ -220,31 +216,23 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) : } else if (strcmp(arg[iarg],"format") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command"); delete [] format_user; - int n = strlen(arg[iarg+1]) + 2; - format_user = new char[n]; - sprintf(format_user," %s",arg[iarg+1]); + format_user = utils::strdup(arg[iarg+1]); format = format_user; iarg += 2; } else if (strcmp(arg[iarg],"title1") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command"); delete [] title1; - int n = strlen(arg[iarg+1]) + 1; - title1 = new char[n]; - strcpy(title1,arg[iarg+1]); + title1 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title2") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command"); delete [] title2; - int n = strlen(arg[iarg+1]) + 1; - title2 = new char[n]; - strcpy(title2,arg[iarg+1]); + title2 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title3") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command"); delete [] title3; - int n = strlen(arg[iarg+1]) + 1; - title3 = new char[n]; - strcpy(title3,arg[iarg+1]); + title3 = utils::strdup(arg[iarg+1]); iarg += 2; } else error->all(FLERR,"Illegal fix ave/chunk command"); } diff --git a/src/fix_ave_correlate.cpp b/src/fix_ave_correlate.cpp index efd06a182a..81ca94cdc8 100644 --- a/src/fix_ave_correlate.cpp +++ b/src/fix_ave_correlate.cpp @@ -139,23 +139,17 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg): } else if (strcmp(arg[iarg],"title1") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command"); delete [] title1; - int n = strlen(arg[iarg+1]) + 1; - title1 = new char[n]; - strcpy(title1,arg[iarg+1]); + title1 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title2") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command"); delete [] title2; - int n = strlen(arg[iarg+1]) + 1; - title2 = new char[n]; - strcpy(title2,arg[iarg+1]); + title2 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title3") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command"); delete [] title3; - int n = strlen(arg[iarg+1]) + 1; - title3 = new char[n]; - strcpy(title3,arg[iarg+1]); + title3 = utils::strdup(arg[iarg+1]); iarg += 2; } else error->all(FLERR,"Illegal fix ave/correlate command"); } diff --git a/src/fix_ave_histo.cpp b/src/fix_ave_histo.cpp index 0d82fd6b04..0f6943ac31 100644 --- a/src/fix_ave_histo.cpp +++ b/src/fix_ave_histo.cpp @@ -993,23 +993,17 @@ void FixAveHisto::options(int iarg, int narg, char **arg) } else if (strcmp(arg[iarg],"title1") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command"); delete [] title1; - int n = strlen(arg[iarg+1]) + 1; - title1 = new char[n]; - strcpy(title1,arg[iarg+1]); + title1 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title2") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command"); delete [] title2; - int n = strlen(arg[iarg+1]) + 1; - title2 = new char[n]; - strcpy(title2,arg[iarg+1]); + title2 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title3") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command"); delete [] title3; - int n = strlen(arg[iarg+1]) + 1; - title3 = new char[n]; - strcpy(title3,arg[iarg+1]); + title3 = utils::strdup(arg[iarg+1]); iarg += 2; } else error->all(FLERR,"Illegal fix ave/histo command"); } diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index e51c86a5e1..7ecb88ddab 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -1067,31 +1067,23 @@ void FixAveTime::options(int iarg, int narg, char **arg) } else if (strcmp(arg[iarg],"format") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/time command"); delete [] format_user; - int n = strlen(arg[iarg+1]) + 2; - format_user = new char[n]; - sprintf(format_user," %s",arg[iarg+1]); + format_user = utils::strdup(arg[iarg+1]); format = format_user; iarg += 2; } else if (strcmp(arg[iarg],"title1") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command"); delete [] title1; - int n = strlen(arg[iarg+1]) + 1; - title1 = new char[n]; - strcpy(title1,arg[iarg+1]); + title1 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title2") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command"); delete [] title2; - int n = strlen(arg[iarg+1]) + 1; - title2 = new char[n]; - strcpy(title2,arg[iarg+1]); + title2 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title3") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command"); delete [] title3; - int n = strlen(arg[iarg+1]) + 1; - title3 = new char[n]; - strcpy(title3,arg[iarg+1]); + title3 = utils::strdup(arg[iarg+1]); iarg += 2; } else error->all(FLERR,"Illegal fix ave/time command"); } diff --git a/src/fix_box_relax.cpp b/src/fix_box_relax.cpp index ef3032fe0c..ef576e96f6 100644 --- a/src/fix_box_relax.cpp +++ b/src/fix_box_relax.cpp @@ -761,9 +761,7 @@ int FixBoxRelax::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) @@ -792,9 +790,7 @@ int FixBoxRelax::modify_param(int narg, char **arg) pflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/fix_controller.cpp b/src/fix_controller.cpp index 0e2530de41..21d1ccf751 100644 --- a/src/fix_controller.cpp +++ b/src/fix_controller.cpp @@ -67,9 +67,7 @@ FixController::FixController(LAMMPS *lmp, int narg, char **arg) : // control variable arg - int n = strlen(arg[iarg]) + 1; - cvID = new char[n]; - strcpy(cvID,arg[iarg]); + cvID = utils::strdup(arg[iarg]); // error check diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 4aec94fc32..b3e5722ee1 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -126,12 +126,8 @@ rfix(nullptr), irregular(nullptr), set(nullptr) error->all(FLERR,"Illegal fix deform command"); delete [] set[index].hstr; delete [] set[index].hratestr; - int n = strlen(&arg[iarg+2][2]) + 1; - set[index].hstr = new char[n]; - strcpy(set[index].hstr,&arg[iarg+2][2]); - n = strlen(&arg[iarg+3][2]) + 1; - set[index].hratestr = new char[n]; - strcpy(set[index].hratestr,&arg[iarg+3][2]); + set[index].hstr = utils::strdup(&arg[iarg+2][2]); + set[index].hratestr = utils::strdup(&arg[iarg+3][2]); iarg += 4; } else error->all(FLERR,"Illegal fix deform command"); @@ -188,12 +184,8 @@ rfix(nullptr), irregular(nullptr), set(nullptr) error->all(FLERR,"Illegal fix deform command"); delete [] set[index].hstr; delete [] set[index].hratestr; - int n = strlen(&arg[iarg+2][2]) + 1; - set[index].hstr = new char[n]; - strcpy(set[index].hstr,&arg[iarg+2][2]); - n = strlen(&arg[iarg+3][2]) + 1; - set[index].hratestr = new char[n]; - strcpy(set[index].hratestr,&arg[iarg+3][2]); + set[index].hstr = utils::strdup(&arg[iarg+2][2]); + set[index].hratestr = utils::strdup(&arg[iarg+3][2]); iarg += 4; } else error->all(FLERR,"Illegal fix deform command"); diff --git a/src/fix_group.cpp b/src/fix_group.cpp index 903eb1b23b..ebd729c737 100644 --- a/src/fix_group.cpp +++ b/src/fix_group.cpp @@ -39,12 +39,9 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) // dgroupbit = bitmask of dynamic group // group ID is last part of fix ID - int n = strlen(id) - strlen("GROUP_") + 1; - char *dgroup = new char[n]; - strcpy(dgroup,&id[strlen("GROUP_")]); - gbit = group->bitmask[group->find(dgroup)]; - gbitinverse = group->inversemask[group->find(dgroup)]; - delete [] dgroup; + auto dgroupid = std::string(id).substr(strlen("GROUP_")); + gbit = group->bitmask[group->find(dgroupid)]; + gbitinverse = group->inversemask[group->find(dgroupid)]; // process optional args @@ -61,9 +58,7 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) error->all(FLERR,"Region ID for group dynamic does not exist"); regionflag = 1; delete [] idregion; - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + 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"); @@ -71,9 +66,7 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) error->all(FLERR,"Variable name for group dynamic does not exist"); varflag = 1; delete [] idvar; - int n = strlen(arg[iarg+1]) + 1; - idvar = new char[n]; - strcpy(idvar,arg[iarg+1]); + 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"); @@ -81,9 +74,7 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) error->all(FLERR,"Per atom property for group dynamic does not exist"); propflag = 1; delete [] idprop; - int n = strlen(arg[iarg+1]) + 1; - idprop = new char[n]; - strcpy(idprop,arg[iarg+1]); + 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"); @@ -123,7 +114,7 @@ void FixGroup::init() if (group->dynamic[igroup]) error->all(FLERR,"Group dynamic parent group cannot be dynamic"); - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; // set current indices for region and variable diff --git a/src/fix_nh.cpp b/src/fix_nh.cpp index 49a469d296..120aeeb7de 100644 --- a/src/fix_nh.cpp +++ b/src/fix_nh.cpp @@ -275,9 +275,7 @@ FixNH::FixNH(LAMMPS *lmp, int narg, char **arg) : else { allremap = 0; delete [] id_dilate; - int n = strlen(arg[iarg+1]) + 1; - id_dilate = new char[n]; - strcpy(id_dilate,arg[iarg+1]); + id_dilate = utils::strdup(arg[iarg+1]); int idilate = group->find(id_dilate); if (idilate == -1) error->all(FLERR,"Fix nvt/npt/nph dilate group ID does not exist"); @@ -1414,9 +1412,7 @@ int FixNH::modify_param(int narg, char **arg) tcomputeflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) @@ -1448,9 +1444,7 @@ int FixNH::modify_param(int narg, char **arg) pcomputeflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/fix_press_berendsen.cpp b/src/fix_press_berendsen.cpp index d83262e9dd..d929ca6f28 100644 --- a/src/fix_press_berendsen.cpp +++ b/src/fix_press_berendsen.cpp @@ -467,9 +467,7 @@ int FixPressBerendsen::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify temperature ID"); @@ -496,9 +494,7 @@ int FixPressBerendsen::modify_param(int narg, char **arg) pflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/fix_spring.cpp b/src/fix_spring.cpp index 4bbaf594bd..89d569fc8b 100644 --- a/src/fix_spring.cpp +++ b/src/fix_spring.cpp @@ -70,9 +70,7 @@ FixSpring::FixSpring(LAMMPS *lmp, int narg, char **arg) : if (narg != 10) error->all(FLERR,"Illegal fix spring command"); styleflag = COUPLE; - int n = strlen(arg[4]) + 1; - group2 = new char[n]; - strcpy(group2,arg[4]); + group2 = utils::strdup(arg[4]); igroup2 = group->find(arg[4]); if (igroup2 == -1) error->all(FLERR,"Fix spring couple group ID does not exist"); diff --git a/src/fix_spring_chunk.cpp b/src/fix_spring_chunk.cpp index 9ae4ee4632..8eb35e74aa 100644 --- a/src/fix_spring_chunk.cpp +++ b/src/fix_spring_chunk.cpp @@ -49,13 +49,8 @@ FixSpringChunk::FixSpringChunk(LAMMPS *lmp, int narg, char **arg) : k_spring = utils::numeric(FLERR,arg[3],false,lmp); - int n = strlen(arg[4]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[4]); - - n = strlen(arg[5]) + 1; - idcom = new char[n]; - strcpy(idcom,arg[5]); + idchunk = utils::strdup(arg[4]); + idcom = utils::strdup(arg[5]); esprings = 0.0; nchunk = 0; diff --git a/src/fix_temp_berendsen.cpp b/src/fix_temp_berendsen.cpp index f951975937..39b8a5fefd 100644 --- a/src/fix_temp_berendsen.cpp +++ b/src/fix_temp_berendsen.cpp @@ -205,9 +205,7 @@ int FixTempBerendsen::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/fix_temp_csld.cpp b/src/fix_temp_csld.cpp index 2ee2044639..787b4dd34e 100644 --- a/src/fix_temp_csld.cpp +++ b/src/fix_temp_csld.cpp @@ -261,9 +261,7 @@ int FixTempCSLD::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/fix_temp_csvr.cpp b/src/fix_temp_csvr.cpp index cdce9175d6..525cf5b74a 100644 --- a/src/fix_temp_csvr.cpp +++ b/src/fix_temp_csvr.cpp @@ -216,9 +216,7 @@ int FixTempCSVR::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/fix_temp_rescale.cpp b/src/fix_temp_rescale.cpp index fa4c87a256..b57f6c238c 100644 --- a/src/fix_temp_rescale.cpp +++ b/src/fix_temp_rescale.cpp @@ -202,9 +202,7 @@ int FixTempRescale::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/fix_wall_region.cpp b/src/fix_wall_region.cpp index 4d976373a5..7e30fe2361 100644 --- a/src/fix_wall_region.cpp +++ b/src/fix_wall_region.cpp @@ -54,9 +54,7 @@ FixWallRegion::FixWallRegion(LAMMPS *lmp, int narg, char **arg) : iregion = domain->find_region(arg[3]); if (iregion == -1) error->all(FLERR,"Region ID for fix wall/region does not exist"); - int n = strlen(arg[3]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[3]); + idregion = utils::strdup(arg[3]); if (strcmp(arg[4],"lj93") == 0) style = LJ93; else if (strcmp(arg[4],"lj126") == 0) style = LJ126; From 2e7e5aeac4b90ad13d034c34771e170863ad532e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 19 Mar 2021 10:04:28 -0400 Subject: [PATCH 08/11] make fix gcmc and fix widom compatible with USER-INTEL this fixes #2672 --- src/MC/fix_gcmc.cpp | 2 ++ src/MC/fix_widom.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index e8087f1344..b8eecf95ca 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -2330,7 +2330,9 @@ double FixGCMC::energy_full() // unlike Verlet, not performing a reverse_comm() or forces here // b/c GCMC does not care about forces // don't think it will mess up energy due to any post_force() fixes + // but Modify::pre_reverse() is needed for USER-INTEL + if (modify->n_pre_reverse) modify->pre_reverse(eflag,vflag); if (modify->n_post_force) modify->post_force(vflag); if (modify->n_end_of_step) modify->end_of_step(); diff --git a/src/MC/fix_widom.cpp b/src/MC/fix_widom.cpp index 4a06dbafbd..a1bdc32515 100644 --- a/src/MC/fix_widom.cpp +++ b/src/MC/fix_widom.cpp @@ -1057,7 +1057,9 @@ double FixWidom::energy_full() // unlike Verlet, not performing a reverse_comm() or forces here // b/c Widom does not care about forces // don't think it will mess up energy due to any post_force() fixes + // but Modify::pre_reverse() is needed for USER-INTEL + if (modify->n_pre_reverse) modify->pre_reverse(eflag,vflag); if (modify->n_pre_force) modify->pre_force(vflag); if (modify->n_end_of_step) modify->end_of_step(); From b9bc226e391b7e35f412a2813507979f11a685cb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 19 Mar 2021 10:06:02 -0400 Subject: [PATCH 09/11] save style names alongside the classes when using read_data nocoeff this fixes #2673 --- src/neighbor.cpp | 3 ++- src/read_data.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/neighbor.cpp b/src/neighbor.cpp index a76bf78c24..0055678f41 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -1479,7 +1479,8 @@ void Neighbor::print_pairwise_info() rq = requests[i]; if (rq->pair) { char *pname = force->pair_match_ptr((Pair *) rq->requestor); - out += fmt::format(" ({}) pair {}",i+1,pname); + if (pname) out += fmt::format(" ({}) pair {}",i+1,pname); + else out += fmt::format(" ({}) pair (none)",i+1); } else if (rq->fix) { out += fmt::format(" ({}) fix {}",i+1,((Fix *) rq->requestor)->style); } else if (rq->compute) { diff --git a/src/read_data.cpp b/src/read_data.cpp index 1d8b7a516a..90aafd4b98 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -337,6 +337,12 @@ void ReadData::command(int narg, char **arg) Dihedral *saved_dihedral = nullptr; Improper *saved_improper = nullptr; KSpace *saved_kspace = nullptr; + char *saved_pair_style = nullptr; + char *saved_bond_style = nullptr; + char *saved_angle_style = nullptr; + char *saved_dihedral_style = nullptr; + char *saved_improper_style = nullptr; + char *saved_kspace_style = nullptr; if (coeffflag == 0) { char *coeffs[2]; @@ -344,33 +350,45 @@ void ReadData::command(int narg, char **arg) coeffs[1] = (char *) "nocoeff"; saved_pair = force->pair; + saved_pair_style = force->pair_style; force->pair = nullptr; + force->pair_style = nullptr; force->create_pair("zero",0); if (force->pair) force->pair->settings(2,coeffs); coeffs[0] = coeffs[1]; saved_bond = force->bond; + saved_bond_style = force->bond_style; force->bond = nullptr; + force->bond_style = nullptr; force->create_bond("zero",0); if (force->bond) force->bond->settings(1,coeffs); saved_angle = force->angle; + saved_angle_style = force->angle_style; force->angle = nullptr; + force->angle_style = nullptr; force->create_angle("zero",0); if (force->angle) force->angle->settings(1,coeffs); saved_dihedral = force->dihedral; + saved_dihedral_style = force->dihedral_style; force->dihedral = nullptr; + force->dihedral_style = nullptr; force->create_dihedral("zero",0); if (force->dihedral) force->dihedral->settings(1,coeffs); saved_improper = force->improper; + saved_improper_style = force->improper_style; force->improper = nullptr; + force->improper_style = nullptr; force->create_improper("zero",0); if (force->improper) force->improper->settings(1,coeffs); saved_kspace = force->kspace; + saved_kspace_style = force->kspace_style; force->kspace = nullptr; + force->kspace_style = nullptr; } // ----------------------------------------------------------------- @@ -873,20 +891,26 @@ void ReadData::command(int narg, char **arg) if (coeffflag == 0) { if (force->pair) delete force->pair; force->pair = saved_pair; + force->pair_style = saved_pair_style; if (force->bond) delete force->bond; force->bond = saved_bond; + force->bond_style = saved_bond_style; if (force->angle) delete force->angle; force->angle = saved_angle; + force->angle_style = saved_angle_style; if (force->dihedral) delete force->dihedral; force->dihedral = saved_dihedral; + force->dihedral_style = saved_dihedral_style; if (force->improper) delete force->improper; force->improper = saved_improper; + force->improper_style = saved_improper_style; force->kspace = saved_kspace; + force->kspace_style = saved_kspace_style; } // total time From ca102e4920ac288539a6908555765d9d0285f52c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 19 Mar 2021 11:20:32 -0400 Subject: [PATCH 10/11] remove dead code --- src/tokenizer.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 18ed64e0ac..8467d07b95 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -201,7 +201,6 @@ std::string ValueTokenizer::next_string() { std::string value = tokens.next(); return value; } throw TokenizerException("Not enough tokens",""); - return ""; } /*! Retrieve next token and convert to int @@ -217,7 +216,6 @@ int ValueTokenizer::next_int() { int value = atoi(current.c_str()); return value; } throw TokenizerException("Not enough tokens",""); - return 0; } /*! Retrieve next token and convert to bigint @@ -233,7 +231,6 @@ bigint ValueTokenizer::next_bigint() { bigint value = ATOBIGINT(current.c_str()); return value; } throw TokenizerException("Not enough tokens",""); - return 0; } /*! Retrieve next token and convert to tagint @@ -249,7 +246,6 @@ tagint ValueTokenizer::next_tagint() { tagint value = ATOTAGINT(current.c_str()); return value; } throw TokenizerException("Not enough tokens",""); - return 0; } /*! Retrieve next token and convert to double @@ -265,7 +261,6 @@ double ValueTokenizer::next_double() { double value = atof(current.c_str()); return value; } throw TokenizerException("Not enough tokens",""); - return 0.0; } /*! Skip over a given number of tokens From 154b8cb4012653787d19b3c4ef40b76b2c91de7f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 19 Mar 2021 11:33:32 -0400 Subject: [PATCH 11/11] remove dead code --- src/USER-OMP/pair_comb_omp.cpp | 8 ++++---- unittest/commands/test_reset_ids.cpp | 4 ---- unittest/force-styles/test_angle_style.cpp | 2 -- unittest/force-styles/test_bond_style.cpp | 2 -- unittest/force-styles/test_dihedral_style.cpp | 2 -- unittest/force-styles/test_improper_style.cpp | 2 -- unittest/force-styles/test_pair_style.cpp | 2 -- 7 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/USER-OMP/pair_comb_omp.cpp b/src/USER-OMP/pair_comb_omp.cpp index ea8307eda7..cfde8ff905 100644 --- a/src/USER-OMP/pair_comb_omp.cpp +++ b/src/USER-OMP/pair_comb_omp.cpp @@ -88,7 +88,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) int i,j,k,ii,jj,kk,jnum,iparam_i; tagint itag,jtag; int itype,jtype,ktype,iparam_ij,iparam_ijk; - double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; double rsq,rsq1,rsq2; double delr1[3],delr2[3],fi[3],fj[3],fk[3]; double zeta_ij,prefactor; @@ -102,7 +102,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) double vionij,fvionij,sr1,sr2,sr3,Eov,Fov; int sht_jnum, *sht_jlist, nj; - evdwl = ecoul = 0.0; + evdwl = 0.0; const double * const * const x = atom->x; double * const * const f = thr->get_f(); @@ -419,7 +419,7 @@ double PairCombOMP::yasu_char(double *qf_fix, int &igroup) #pragma omp parallel for private(ii) LMP_DEFAULT_NONE LMP_SHARED(potal,fac11e) #endif for (ii = 0; ii < inum; ii ++) { - double fqi,fqj,fqij,fqji,fqjj,delr1[3]; + double fqi,fqij,fqji,fqjj,delr1[3]; double sr1,sr2,sr3; int mr1,mr2,mr3; @@ -428,7 +428,7 @@ double PairCombOMP::yasu_char(double *qf_fix, int &igroup) int nj = 0; if (mask[i] & groupbit) { - fqi = fqj = fqij = fqji = fqjj = 0.0; // should not be needed. + fqi = fqij = fqji = fqjj = 0.0; // should not be needed. int itype = map[type[i]]; const double xtmp = x[i][0]; const double ytmp = x[i][1]; diff --git a/unittest/commands/test_reset_ids.cpp b/unittest/commands/test_reset_ids.cpp index 71a68a0a00..3ea2f26cef 100644 --- a/unittest/commands/test_reset_ids.cpp +++ b/unittest/commands/test_reset_ids.cpp @@ -482,8 +482,6 @@ TEST_F(ResetIDsTest, TopologyData) auto num_bond = lmp->atom->num_bond; auto num_angle = lmp->atom->num_angle; - auto num_dihedral = lmp->atom->num_dihedral; - auto num_improper = lmp->atom->num_improper; auto bond_atom = lmp->atom->bond_atom; auto angle_atom1 = lmp->atom->angle_atom1; auto angle_atom2 = lmp->atom->angle_atom2; @@ -568,8 +566,6 @@ TEST_F(ResetIDsTest, TopologyData) num_bond = lmp->atom->num_bond; num_angle = lmp->atom->num_angle; - num_dihedral = lmp->atom->num_dihedral; - num_improper = lmp->atom->num_improper; bond_atom = lmp->atom->bond_atom; angle_atom1 = lmp->atom->angle_atom1; angle_atom2 = lmp->atom->angle_atom2; diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index 833aa69174..7f07052b3d 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -308,7 +308,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); auto f = lmp->atom->f; - auto tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -329,7 +328,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) block.clear(); f = lmp->atom->f; - tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index 0d20a0bb62..a4956006f5 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -308,7 +308,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); auto f = lmp->atom->f; - auto tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -329,7 +328,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) block.clear(); f = lmp->atom->f; - tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index e60968bb0a..6dd6a3f205 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -311,7 +311,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); auto f = lmp->atom->f; - auto tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -332,7 +331,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) block.clear(); f = lmp->atom->f; - tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index 858db0fb65..1b97f38faf 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -302,7 +302,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); auto f = lmp->atom->f; - auto tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -323,7 +322,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) block.clear(); f = lmp->atom->f; - tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index c5d1c1b42a..fd8d306538 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -308,7 +308,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); auto f = lmp->atom->f; - auto tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -332,7 +331,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) block.clear(); f = lmp->atom->f; - tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]);