diff --git a/src/ASPHERE/compute_temp_asphere.cpp b/src/ASPHERE/compute_temp_asphere.cpp index 2fe2e9699c..9afae4d2d9 100644 --- a/src/ASPHERE/compute_temp_asphere.cpp +++ b/src/ASPHERE/compute_temp_asphere.cpp @@ -58,9 +58,7 @@ ComputeTempAsphere::ComputeTempAsphere(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal compute temp/asphere 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/BODY/compute_temp_body.cpp b/src/BODY/compute_temp_body.cpp index 730a857aec..fb16723b23 100644 --- a/src/BODY/compute_temp_body.cpp +++ b/src/BODY/compute_temp_body.cpp @@ -56,9 +56,7 @@ ComputeTempBody::ComputeTempBody(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal compute temp/body 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/GPU/fix_npt_gpu.cpp b/src/GPU/fix_npt_gpu.cpp index 2ba0be29e0..073d5dc6c1 100644 --- a/src/GPU/fix_npt_gpu.cpp +++ b/src/GPU/fix_npt_gpu.cpp @@ -25,44 +25,24 @@ FixNPTGPU::FixNPTGPU(LAMMPS *lmp, int narg, char **arg) : FixNHGPU(lmp, narg, arg) { if (!tstat_flag) - error->all(FLERR,"Temperature control must be used with fix npt/omp"); + error->all(FLERR,"Temperature control must be used with fix npt/gpu"); if (!pstat_flag) - error->all(FLERR,"Pressure control must be used with fix npt/omp"); + error->all(FLERR,"Pressure control must be used with fix npt/gpu"); // create a new compute temp style // id = fix-ID + temp // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(id_temp+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(std::string(id_press)+" all pressure "+id_temp); pcomputeflag = 1; } diff --git a/src/GPU/fix_nvt_gpu.cpp b/src/GPU/fix_nvt_gpu.cpp index 7d7826b6bf..6858c26497 100644 --- a/src/GPU/fix_nvt_gpu.cpp +++ b/src/GPU/fix_nvt_gpu.cpp @@ -26,25 +26,14 @@ FixNVTGPU::FixNVTGPU(LAMMPS *lmp, int narg, char **arg) : FixNHGPU(lmp, narg, arg) { if (!tstat_flag) - error->all(FLERR,"Temperature control must be used with fix nvt"); + error->all(FLERR,"Temperature control must be used with fix nvt/gpu"); if (pstat_flag) - error->all(FLERR,"Pressure control can not be used with fix nvt"); + error->all(FLERR,"Pressure control can not be used with fix nvt/gpu"); // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } - diff --git a/src/USER-OMP/fix_npt_omp.cpp b/src/USER-OMP/fix_npt_omp.cpp index f3f08c15c2..54328803f4 100644 --- a/src/USER-OMP/fix_npt_omp.cpp +++ b/src/USER-OMP/fix_npt_omp.cpp @@ -34,35 +34,16 @@ FixNPTOMP::FixNPTOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(std::string(id_press)+" all pressure "+id_temp); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nvt_omp.cpp b/src/USER-OMP/fix_nvt_omp.cpp index bfa2dcbe49..127876b4e8 100644 --- a/src/USER-OMP/fix_nvt_omp.cpp +++ b/src/USER-OMP/fix_nvt_omp.cpp @@ -33,17 +33,7 @@ FixNVTOMP::FixNVTOMP(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; }