From a1c0b78a3a6a8d2f0f536991816b5d66c46b8783 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 28 Jun 2020 23:25:37 -0400 Subject: [PATCH] final set of styles in the src folder to be simplified --- src/compute_msd.cpp | 20 +++++++------------- src/compute_msd_chunk.cpp | 20 +++++++------------- src/dump_custom.cpp | 22 +++++++--------------- 3 files changed, 21 insertions(+), 41 deletions(-) diff --git a/src/compute_msd.cpp b/src/compute_msd.cpp index b15bb8e875..930f979bf0 100644 --- a/src/compute_msd.cpp +++ b/src/compute_msd.cpp @@ -14,6 +14,7 @@ #include "compute_msd.h" #include #include +#include #include "atom.h" #include "update.h" #include "group.h" @@ -21,6 +22,7 @@ #include "modify.h" #include "fix_store.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -63,21 +65,13 @@ ComputeMSD::ComputeMSD(LAMMPS *lmp, int narg, char **arg) : // create a new fix STORE style for reference positions // id = compute-ID + COMPUTE_STORE, fix group = compute group - int n = strlen(id) + strlen("_COMPUTE_STORE") + 1; - id_fix = new char[n]; - strcpy(id_fix,id); - strcat(id_fix,"_COMPUTE_STORE"); + std::string fixcmd = id + std::string("_COMPUTE_STORE"); + id_fix = new char[fixcmd.size()+1]; + strcpy(id_fix,fixcmd.c_str()); - char **newarg = new char*[6]; - newarg[0] = id_fix; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "1"; - newarg[5] = (char *) "3"; - modify->add_fix(6,newarg); + fixcmd += fmt::format(" {} STORE peratom 1 3",group->names[igroup]); + modify->add_fix(fixcmd); fix = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; // calculate xu,yu,zu for fix store array // skip if reset from restart file diff --git a/src/compute_msd_chunk.cpp b/src/compute_msd_chunk.cpp index 8039a4fcd5..dda921ef42 100644 --- a/src/compute_msd_chunk.cpp +++ b/src/compute_msd_chunk.cpp @@ -14,6 +14,7 @@ #include "compute_msd_chunk.h" #include #include +#include #include "atom.h" #include "group.h" #include "update.h" @@ -23,6 +24,7 @@ #include "fix_store.h" #include "memory.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -56,21 +58,13 @@ 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() - n = strlen(id) + strlen("_COMPUTE_STORE") + 1; - id_fix = new char[n]; - strcpy(id_fix,id); - strcat(id_fix,"_COMPUTE_STORE"); + std::string fixcmd = id + std::string("_COMPUTE_STORE"); + id_fix = new char[fixcmd.size()+1]; + strcpy(id_fix,fixcmd.c_str()); - char **newarg = new char*[6]; - newarg[0] = id_fix; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "global"; - newarg[4] = (char *) "1"; - newarg[5] = (char *) "1"; - modify->add_fix(6,newarg); + fixcmd += fmt::format(" {} STORE global 1 1",group->names[igroup]); + modify->add_fix(fixcmd); fix = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; } /* ---------------------------------------------------------------------- */ diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 4b25896d79..e82636efac 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -14,6 +14,7 @@ #include "dump_custom.h" #include #include +#include #include "atom.h" #include "force.h" #include "domain.h" @@ -28,6 +29,7 @@ #include "error.h" #include "update.h" #include "variable.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -1981,22 +1983,12 @@ int DumpCustom::modify_param(int narg, char **arg) "dump:thresh_fixID"); memory->grow(thresh_first,(nthreshlast+1),"dump:thresh_first"); - int n = strlen(id) + strlen("_DUMP_STORE") + 8; - thresh_fixID[nthreshlast] = new char[n]; - strcpy(thresh_fixID[nthreshlast],id); - sprintf(&thresh_fixID[nthreshlast][strlen(id)],"%d",nthreshlast); - strcat(thresh_fixID[nthreshlast],"_DUMP_STORE"); - - char **newarg = new char*[6]; - newarg[0] = thresh_fixID[nthreshlast]; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "1"; - newarg[5] = (char *) "1"; - modify->add_fix(6,newarg); + std::string threshid = fmt::format("{}{}_DUMP_STORE",id,nthreshlast); + thresh_fixID[nthreshlast] = new char[threshid.size()+1]; + strcpy(thresh_fixID[nthreshlast],threshid.c_str()); + modify->add_fix(fmt::format("{} {} STORE peratom 1 1",threshid, + group->names[igroup])); thresh_fix[nthreshlast] = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; thresh_last[nthreshlast] = nthreshlast; thresh_first[nthreshlast] = 1;