refactor/simplify code due to changes in Modify

This commit is contained in:
Axel Kohlmeyer
2021-08-06 21:30:32 -04:00
parent f23b04f9b6
commit 68c15ebf04
11 changed files with 43 additions and 79 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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

View File

@ -14,16 +14,15 @@
#include "compute_msd.h"
#include <cstring>
#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 <cstring>
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

View File

@ -14,18 +14,17 @@
#include "compute_msd_chunk.h"
#include <cstring>
#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 <cstring>
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]));
}
/* ---------------------------------------------------------------------- */

View File

@ -14,8 +14,6 @@
#include "compute_vacf.h"
#include <cstring>
#include "atom.h"
#include "update.h"
#include "group.h"
@ -23,6 +21,7 @@
#include "fix_store.h"
#include "error.h"
#include <cstring>
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

View File

@ -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;

View File

@ -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;

View File

@ -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()

View File

@ -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

View File

@ -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];
}
}