make more use of convenience functions for adding fixes and computes

This commit is contained in:
Axel Kohlmeyer
2020-06-28 18:40:48 -04:00
parent df29364be8
commit 3cd1341e64
8 changed files with 40 additions and 98 deletions

View File

@ -494,7 +494,7 @@ void Balance::weight_storage(char *prefix)
if (prefix) cmd = prefix; if (prefix) cmd = prefix;
cmd += "IMBALANCE_WEIGHTS"; cmd += "IMBALANCE_WEIGHTS";
int ifix = modify->find_fix(cmd.c_str()); int ifix = modify->find_fix(cmd);
if (ifix < 1) { if (ifix < 1) {
cmd += " all STORE peratom 0 1"; cmd += " all STORE peratom 0 1";
modify->add_fix(cmd); modify->add_fix(cmd);

View File

@ -14,12 +14,14 @@
#include "compute_vacf.h" #include "compute_vacf.h"
#include <mpi.h> #include <mpi.h>
#include <cstring> #include <cstring>
#include <string>
#include "atom.h" #include "atom.h"
#include "update.h" #include "update.h"
#include "group.h" #include "group.h"
#include "modify.h" #include "modify.h"
#include "fix_store.h" #include "fix_store.h"
#include "error.h" #include "error.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -39,21 +41,12 @@ ComputeVACF::ComputeVACF(LAMMPS *lmp, int narg, char **arg) :
// create a new fix STORE style // create a new fix STORE style
// id = compute-ID + COMPUTE_STORE, fix group = compute group // id = compute-ID + COMPUTE_STORE, fix group = compute group
int n = strlen(id) + strlen("_COMPUTE_STORE") + 1; std::string fixcmd = id + std::string("_COMPUTE_STORE");
id_fix = new char[n]; id_fix = new char[fixcmd.size()+1];
strcpy(id_fix,id); strcpy(id_fix,fixcmd.c_str());
strcat(id_fix,"_COMPUTE_STORE"); fixcmd += fmt::format(" {} STORE peratom 1 3", group->names[igroup]);
modify->add_fix(fixcmd);
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);
fix = (FixStore *) modify->fix[modify->nfix-1]; fix = (FixStore *) modify->fix[modify->nfix-1];
delete [] newarg;
// store current velocities in fix store array // store current velocities in fix store array
// skip if reset from restart file // skip if reset from restart file

View File

@ -31,6 +31,7 @@
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "utils.h" #include "utils.h"
#include "fmt/format.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace FixConst; using namespace FixConst;
@ -265,20 +266,12 @@ void FixAdapt::post_constructor()
id_fix_diam = NULL; id_fix_diam = NULL;
id_fix_chg = NULL; id_fix_chg = NULL;
char **newarg = new char*[6];
newarg[1] = group->names[igroup];
newarg[2] = (char *) "STORE";
newarg[3] = (char *) "peratom";
newarg[4] = (char *) "1";
newarg[5] = (char *) "1";
if (diamflag && atom->radius_flag) { if (diamflag && atom->radius_flag) {
int n = strlen(id) + strlen("_FIX_STORE_DIAM") + 1; std::string fixcmd = id + std::string("_FIX_STORE_DIAM");
id_fix_diam = new char[n]; id_fix_diam = new char[fixcmd.size()+1];
strcpy(id_fix_diam,id); strcpy(id_fix_diam,fixcmd.c_str());
strcat(id_fix_diam,"_FIX_STORE_DIAM"); fixcmd += fmt::format(" {} STORE peratom 1 1",group->names[igroup]);
newarg[0] = id_fix_diam; modify->add_fix(fixcmd);
modify->add_fix(6,newarg);
fix_diam = (FixStore *) modify->fix[modify->nfix-1]; fix_diam = (FixStore *) modify->fix[modify->nfix-1];
if (fix_diam->restart_reset) fix_diam->restart_reset = 0; if (fix_diam->restart_reset) fix_diam->restart_reset = 0;
@ -296,12 +289,11 @@ void FixAdapt::post_constructor()
} }
if (chgflag && atom->q_flag) { if (chgflag && atom->q_flag) {
int n = strlen(id) + strlen("_FIX_STORE_CHG") + 1; std::string fixcmd = id + std::string("_FIX_STORE_CHG");
id_fix_chg = new char[n]; id_fix_chg = new char[fixcmd.size()+1];
strcpy(id_fix_chg,id); strcpy(id_fix_chg,fixcmd.c_str());
strcat(id_fix_chg,"_FIX_STORE_CHG"); fixcmd += fmt::format(" {} STORE peratom 1 1",group->names[igroup]);
newarg[0] = id_fix_chg; modify->add_fix(fixcmd);
modify->add_fix(6,newarg);
fix_chg = (FixStore *) modify->fix[modify->nfix-1]; fix_chg = (FixStore *) modify->fix[modify->nfix-1];
if (fix_chg->restart_reset) fix_chg->restart_reset = 0; if (fix_chg->restart_reset) fix_chg->restart_reset = 0;
@ -317,8 +309,6 @@ void FixAdapt::post_constructor()
} }
} }
} }
delete [] newarg;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -124,11 +124,8 @@ void Group::assign(int narg, char **arg)
int bits = inversemask[igroup]; int bits = inversemask[igroup];
for (i = 0; i < nlocal; i++) mask[i] &= bits; for (i = 0; i < nlocal; i++) mask[i] &= bits;
if (dynamic[igroup]) { if (dynamic[igroup])
std::string fixID = "GROUP_"; modify->delete_fix(std::string("GROUP_") + names[igroup]);
fixID += names[igroup];
modify->delete_fix(fixID.c_str());
}
delete [] names[igroup]; delete [] names[igroup];
names[igroup] = NULL; names[igroup] = NULL;
@ -491,24 +488,15 @@ void Group::assign(int narg, char **arg)
// if group is already dynamic, delete existing FixGroup // if group is already dynamic, delete existing FixGroup
if (dynamic[igroup]) { if (dynamic[igroup])
std::string fixID = "GROUP_"; modify->delete_fix(std::string("GROUP_") + names[igroup]);
fixID += names[igroup];
modify->delete_fix(fixID.c_str());
}
dynamic[igroup] = 1; dynamic[igroup] = 1;
std::string fixID = "GROUP_"; std::string fixcmd = "GROUP_";
fixID += names[igroup]; fixcmd += fmt::format("{} {} GROUP",names[igroup],arg[2]);
for (int i = 3; i < narg; i++) fixcmd += std::string(" ") + arg[i];
char **newarg = new char*[narg]; modify->add_fix(fixcmd);
newarg[0] = (char *)fixID.c_str();
newarg[1] = arg[2];
newarg[2] = (char *) "GROUP";
for (int i = 3; i < narg; i++) newarg[i] = arg[i];
modify->add_fix(narg,newarg);
delete [] newarg;
// style = static // style = static
// remove dynamic FixGroup if necessary // remove dynamic FixGroup if necessary
@ -517,11 +505,8 @@ void Group::assign(int narg, char **arg)
if (narg != 2) error->all(FLERR,"Illegal group command"); if (narg != 2) error->all(FLERR,"Illegal group command");
if (dynamic[igroup]) { if (dynamic[igroup])
std::string fixID = "GROUP_"; modify->delete_fix(std::string("GROUP_") + names[igroup]);
fixID += names[igroup];
modify->delete_fix(fixID.c_str());
}
dynamic[igroup] = 0; dynamic[igroup] = 0;

View File

@ -113,18 +113,13 @@ Min::~Min()
void Min::init() void Min::init()
{ {
if (lmp->kokkos && !kokkosable) if (lmp->kokkos && !kokkosable)
error->all(FLERR,"Must use a Kokkos-enabled min style (e.g. min_style cg/kk) " error->all(FLERR,"Must use a Kokkos-enabled min style "
"with Kokkos minimize"); "(e.g. min_style cg/kk) with Kokkos minimize");
// create fix needed for storing atom-based quantities // create fix needed for storing atom-based quantities
// will delete it at end of run // will delete it at end of run
char **fixarg = new char*[3]; modify->add_fix("MINIMIZE all MINIMIZE");
fixarg[0] = (char *) "MINIMIZE";
fixarg[1] = (char *) "all";
fixarg[2] = (char *) "MINIMIZE";
modify->add_fix(3,fixarg);
delete [] fixarg;
fix_minimize = (FixMinimize *) modify->fix[modify->nfix-1]; fix_minimize = (FixMinimize *) modify->fix[modify->nfix-1];
// clear out extra global and per-atom dof // clear out extra global and per-atom dof

View File

@ -423,19 +423,9 @@ void ReadRestart::command(int narg, char **arg)
// create a temporary fix to hold and migrate extra atom info // create a temporary fix to hold and migrate extra atom info
// necessary b/c irregular will migrate atoms // necessary b/c irregular will migrate atoms
if (nextra) { if (nextra)
char cextra[8],fixextra[8]; modify->add_fix(fmt::format("_read_restart all READ_RESTART {} {}",
sprintf(cextra,"%d",nextra); nextra,modify->nfix_restart_peratom));
sprintf(fixextra,"%d",modify->nfix_restart_peratom);
char **newarg = new char*[5];
newarg[0] = (char *) "_read_restart";
newarg[1] = (char *) "all";
newarg[2] = (char *) "READ_RESTART";
newarg[3] = cextra;
newarg[4] = fixextra;
modify->add_fix(5,newarg);
delete [] newarg;
}
// move atoms to new processors via irregular() // move atoms to new processors via irregular()
// turn sorting on in migrate_atoms() to avoid non-reproducible restarts // turn sorting on in migrate_atoms() to avoid non-reproducible restarts

View File

@ -299,22 +299,11 @@ void Respa::init()
// create fix needed for storing atom-based respa level forces // create fix needed for storing atom-based respa level forces
// will delete it at end of run // will delete it at end of run
char **fixarg = new char*[5];
fixarg[0] = (char *) "RESPA";
fixarg[1] = (char *) "all";
fixarg[2] = (char *) "RESPA";
fixarg[3] = new char[8];
sprintf(fixarg[3],"%d",nlevels);
// if supported, we also store torques on a per-level basis // if supported, we also store torques on a per-level basis
if (atom->torque_flag) {
fixarg[4] = (char *) "torque"; std::string cmd = fmt::format("RESPA all RESPA {}",nlevels);
modify->add_fix(5,fixarg); if (atom->torque_flag) modify->add_fix(cmd + " torque");
} else { else modify->add_fix(cmd);
modify->add_fix(4,fixarg);
}
delete [] fixarg[3];
delete [] fixarg;
fix_respa = (FixRespa *) modify->fix[modify->nfix-1]; fix_respa = (FixRespa *) modify->fix[modify->nfix-1];
// insure respa inner/middle/outer is using Pair class that supports it // insure respa inner/middle/outer is using Pair class that supports it

View File

@ -483,7 +483,7 @@ void Thermo::modify_params(int narg, char **arg)
icompute = modify->find_compute(id_compute[index_press_vector]); icompute = modify->find_compute(id_compute[index_press_vector]);
if (icompute < 0) error->all(FLERR, if (icompute < 0) error->all(FLERR,
"Pressure ID for thermo does not exist"); "Pressure ID for thermo does not exist");
} else icompute = modify->find_compute((char *) "thermo_press"); } else icompute = modify->find_compute("thermo_press");
modify->compute[icompute]->reset_extra_compute_fix(arg[iarg+1]); modify->compute[icompute]->reset_extra_compute_fix(arg[iarg+1]);