diff --git a/src/balance.cpp b/src/balance.cpp index af142f404d..feb5eae708 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -499,8 +499,7 @@ void Balance::weight_storage(char *prefix) int ifix = modify->find_fix(cmd); if (ifix < 1) { cmd += " all STORE peratom 0 1"; - modify->add_fix(cmd); - fixstore = (FixStore *) modify->fix[modify->nfix-1]; + fixstore = (FixStore *) modify->add_fix(cmd); } else fixstore = (FixStore *) modify->fix[ifix]; // do not carry weights with atoms during normal atom migration diff --git a/src/compute_chunk_atom.cpp b/src/compute_chunk_atom.cpp index 81eafcf8d6..5d789f722a 100644 --- a/src/compute_chunk_atom.cpp +++ b/src/compute_chunk_atom.cpp @@ -562,13 +562,9 @@ void ComputeChunkAtom::init() // fixstore initializes all values to 0.0 if ((idsflag == ONCE || lockcount) && !fixstore) { - 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 1", group->names[igroup]); - modify->add_fix(cmd); - fixstore = (FixStore *) modify->fix[modify->nfix-1]; + id_fix = utils::strdup(id + std::string("_COMPUTE_STORE")); + fixstore = (FixStore *) modify->add_fix(fmt::format("{} {} STORE peratom 1 1", + id_fix, group->names[igroup])); } if ((idsflag != ONCE && !lockcount) && fixstore) { diff --git a/src/compute_displace_atom.cpp b/src/compute_displace_atom.cpp index 68776c1936..821525c53a 100644 --- a/src/compute_displace_atom.cpp +++ b/src/compute_displace_atom.cpp @@ -74,10 +74,8 @@ ComputeDisplaceAtom::ComputeDisplaceAtom(LAMMPS *lmp, int narg, char **arg) : // id = compute-ID + COMPUTE_STORE, fix group = compute group 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]; + fix = (FixStore *) modify->add_fix(fmt::format("{} {} STORE peratom 1 3", + id_fix, group->names[igroup])); // calculate xu,yu,zu for fix store array // skip if reset from restart file diff --git a/src/compute_msd.cpp b/src/compute_msd.cpp index ce9e10304e..209eec2810 100644 --- a/src/compute_msd.cpp +++ b/src/compute_msd.cpp @@ -14,16 +14,15 @@ #include "compute_msd.h" -#include - #include "atom.h" -#include "update.h" -#include "group.h" #include "domain.h" -#include "modify.h" -#include "fix_store.h" #include "error.h" +#include "fix_store.h" +#include "group.h" +#include "modify.h" +#include "update.h" +#include using namespace LAMMPS_NS; @@ -66,13 +65,9 @@ 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 - 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 peratom 1 3",group->names[igroup]); - modify->add_fix(fixcmd); - fix = (FixStore *) modify->fix[modify->nfix-1]; + id_fix = utils::strdup(id + std::string("_COMPUTE_STORE")); + fix = (FixStore *) modify->add_fix(fmt::format("{} {} STORE peratom 1 3", + id_fix, group->names[igroup])); // 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 74528da2f6..0d5b146338 100644 --- a/src/compute_msd_chunk.cpp +++ b/src/compute_msd_chunk.cpp @@ -14,18 +14,17 @@ #include "compute_msd_chunk.h" -#include - #include "atom.h" -#include "group.h" -#include "update.h" -#include "modify.h" #include "compute_chunk_atom.h" #include "domain.h" -#include "fix_store.h" -#include "memory.h" #include "error.h" +#include "fix_store.h" +#include "group.h" +#include "memory.h" +#include "modify.h" +#include "update.h" +#include using namespace LAMMPS_NS; @@ -52,16 +51,14 @@ ComputeMSDChunk::ComputeMSDChunk(LAMMPS *lmp, int narg, char **arg) : // create a new fix STORE style for reference positions // id = compute-ID + COMPUTE_STORE, fix group = compute group - // do not know size of array at this point, just allocate 1x3 array + // do not know size of array at this point, just allocate 1x1 array // fix creation must be done now so that a restart run can // potentially re-populate the fix array (and change it to correct size) // otherwise size reset and init will be done in setup() 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]; + fix = (FixStore *) modify->add_fix(fmt::format("{} {} STORE global 1 1", + id_fix,group->names[igroup])); } /* ---------------------------------------------------------------------- */ diff --git a/src/compute_vacf.cpp b/src/compute_vacf.cpp index ba88c6d2c1..90dcbf8d4f 100644 --- a/src/compute_vacf.cpp +++ b/src/compute_vacf.cpp @@ -14,8 +14,6 @@ #include "compute_vacf.h" -#include - #include "atom.h" #include "update.h" #include "group.h" @@ -23,6 +21,7 @@ #include "fix_store.h" #include "error.h" +#include using namespace LAMMPS_NS; @@ -42,12 +41,9 @@ ComputeVACF::ComputeVACF(LAMMPS *lmp, int narg, char **arg) : // create a new fix STORE style // id = compute-ID + COMPUTE_STORE, fix group = compute group - 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 peratom 1 3", group->names[igroup]); - modify->add_fix(fixcmd); - fix = (FixStore *) modify->fix[modify->nfix-1]; + id_fix = utils::strdup(id + std::string("_COMPUTE_STORE")); + fix = (FixStore *) modify->add_fix(fmt::format("{} {} STORE peratom 1 3", + id_fix, group->names[igroup])); // store current velocities in fix store array // skip if reset from restart file diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 6c417026ca..6bb7653e3b 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -1960,18 +1960,15 @@ int DumpCustom::modify_param(int narg, char **arg) thresh_last[nthresh] = -1; } else { thresh_fix = (FixStore **) - memory->srealloc(thresh_fix,(nthreshlast+1)*sizeof(FixStore *), - "dump:thresh_fix"); + memory->srealloc(thresh_fix,(nthreshlast+1)*sizeof(FixStore *),"dump:thresh_fix"); thresh_fixID = (char **) - memory->srealloc(thresh_fixID,(nthreshlast+1)*sizeof(char *), - "dump:thresh_fixID"); + 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); - modify->add_fix(fmt::format("{} {} STORE peratom 1 1",threshid, - group->names[igroup])); - thresh_fix[nthreshlast] = (FixStore *) modify->fix[modify->nfix-1]; + 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; diff --git a/src/fix_adapt.cpp b/src/fix_adapt.cpp index 670c0dc4be..e5c2c3dece 100644 --- a/src/fix_adapt.cpp +++ b/src/fix_adapt.cpp @@ -252,12 +252,9 @@ void FixAdapt::post_constructor() id_fix_chg = nullptr; if (diamflag && atom->radius_flag) { - std::string fixcmd = id + std::string("_FIX_STORE_DIAM"); - id_fix_diam = utils::strdup(fixcmd); - fixcmd += fmt::format(" {} STORE peratom 1 1",group->names[igroup]); - modify->add_fix(fixcmd); - fix_diam = (FixStore *) modify->fix[modify->nfix-1]; - + id_fix_diam = utils::strdup(id + std::string("_FIX_STORE_DIAM")); + fix_diam = (FixStore *) modify->add_fix(fmt::format("{} {} STORE peratom 1 1", + id_fix_diam,group->names[igroup])); if (fix_diam->restart_reset) fix_diam->restart_reset = 0; else { double *vec = fix_diam->vstore; @@ -273,12 +270,9 @@ void FixAdapt::post_constructor() } if (chgflag && atom->q_flag) { - std::string fixcmd = id + std::string("_FIX_STORE_CHG"); - id_fix_chg = utils::strdup(fixcmd); - fixcmd += fmt::format(" {} STORE peratom 1 1",group->names[igroup]); - modify->add_fix(fixcmd); - fix_chg = (FixStore *) modify->fix[modify->nfix-1]; - + id_fix_chg = utils::strdup(id + std::string("_FIX_STORE_CHG")); + fix_chg = (FixStore *) modify->add_fix(fmt::format("{} {} STORE peratom 1 1", + id_fix_chg,group->names[igroup])); if (fix_chg->restart_reset) fix_chg->restart_reset = 0; else { double *vec = fix_chg->vstore; diff --git a/src/min.cpp b/src/min.cpp index 8fe73dc9e1..69e24a541f 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -121,8 +121,7 @@ void Min::init() // create fix needed for storing atom-based quantities // will delete it at end of run - modify->add_fix("MINIMIZE all MINIMIZE"); - fix_minimize = (FixMinimize *) modify->fix[modify->nfix-1]; + fix_minimize = (FixMinimize *) modify->add_fix("MINIMIZE all MINIMIZE"); // clear out extra global and per-atom dof // will receive requests for new per-atom dof during pair init() diff --git a/src/respa.cpp b/src/respa.cpp index c51ec04131..5190441994 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -302,9 +302,8 @@ void Respa::init() // if supported, we also store torques on a per-level basis std::string cmd = fmt::format("RESPA all RESPA {}",nlevels); - if (atom->torque_flag) modify->add_fix(cmd + " torque"); - else modify->add_fix(cmd); - fix_respa = (FixRespa *) modify->fix[modify->nfix-1]; + if (atom->torque_flag) cmd += " torque"; + fix_respa = (FixRespa *) modify->add_fix(cmd); // insure respa inner/middle/outer is using Pair class that supports it diff --git a/src/variable.cpp b/src/variable.cpp index 2ef1957a09..a7b2955b33 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -5065,16 +5065,10 @@ VarReader::VarReader(LAMMPS *lmp, char *name, char *file, int flag) : if (style == Variable::ATOMFILE) { if (atom->map_style == Atom::MAP_NONE) - error->all(FLERR,"Cannot use atomfile-style " - "variable unless an atom map exists"); - - std::string cmd = name + std::string("_VARIABLE_STORE"); - id_fix = utils::strdup(cmd); - - cmd += " all STORE peratom 0 1"; - modify->add_fix(cmd); - fixstore = (FixStore *) modify->fix[modify->nfix-1]; + error->all(FLERR,"Cannot use atomfile-style variable unless an atom map exists"); + id_fix = utils::strdup(std::string(name) + "_VARIABLE_STORE"); + fixstore = (FixStore *) modify->add_fix(std::string(id_fix) + " all STORE peratom 0 1"); buffer = new char[CHUNK*MAXLINE]; } }