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;
cmd += "IMBALANCE_WEIGHTS";
int ifix = modify->find_fix(cmd.c_str());
int ifix = modify->find_fix(cmd);
if (ifix < 1) {
cmd += " all STORE peratom 0 1";
modify->add_fix(cmd);

View File

@ -14,12 +14,14 @@
#include "compute_vacf.h"
#include <mpi.h>
#include <cstring>
#include <string>
#include "atom.h"
#include "update.h"
#include "group.h"
#include "modify.h"
#include "fix_store.h"
#include "error.h"
#include "fmt/format.h"
using namespace LAMMPS_NS;
@ -39,21 +41,12 @@ ComputeVACF::ComputeVACF(LAMMPS *lmp, int narg, char **arg) :
// create a new fix STORE style
// 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");
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);
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];
delete [] newarg;
// store current velocities in fix store array
// skip if reset from restart file

View File

@ -31,6 +31,7 @@
#include "memory.h"
#include "error.h"
#include "utils.h"
#include "fmt/format.h"
using namespace LAMMPS_NS;
using namespace FixConst;
@ -265,20 +266,12 @@ void FixAdapt::post_constructor()
id_fix_diam = 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) {
int n = strlen(id) + strlen("_FIX_STORE_DIAM") + 1;
id_fix_diam = new char[n];
strcpy(id_fix_diam,id);
strcat(id_fix_diam,"_FIX_STORE_DIAM");
newarg[0] = id_fix_diam;
modify->add_fix(6,newarg);
std::string fixcmd = id + std::string("_FIX_STORE_DIAM");
id_fix_diam = new char[fixcmd.size()+1];
strcpy(id_fix_diam,fixcmd.c_str());
fixcmd += fmt::format(" {} STORE peratom 1 1",group->names[igroup]);
modify->add_fix(fixcmd);
fix_diam = (FixStore *) modify->fix[modify->nfix-1];
if (fix_diam->restart_reset) fix_diam->restart_reset = 0;
@ -296,12 +289,11 @@ void FixAdapt::post_constructor()
}
if (chgflag && atom->q_flag) {
int n = strlen(id) + strlen("_FIX_STORE_CHG") + 1;
id_fix_chg = new char[n];
strcpy(id_fix_chg,id);
strcat(id_fix_chg,"_FIX_STORE_CHG");
newarg[0] = id_fix_chg;
modify->add_fix(6,newarg);
std::string fixcmd = id + std::string("_FIX_STORE_CHG");
id_fix_chg = new char[fixcmd.size()+1];
strcpy(id_fix_chg,fixcmd.c_str());
fixcmd += fmt::format(" {} STORE peratom 1 1",group->names[igroup]);
modify->add_fix(fixcmd);
fix_chg = (FixStore *) modify->fix[modify->nfix-1];
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];
for (i = 0; i < nlocal; i++) mask[i] &= bits;
if (dynamic[igroup]) {
std::string fixID = "GROUP_";
fixID += names[igroup];
modify->delete_fix(fixID.c_str());
}
if (dynamic[igroup])
modify->delete_fix(std::string("GROUP_") + names[igroup]);
delete [] names[igroup];
names[igroup] = NULL;
@ -491,24 +488,15 @@ void Group::assign(int narg, char **arg)
// if group is already dynamic, delete existing FixGroup
if (dynamic[igroup]) {
std::string fixID = "GROUP_";
fixID += names[igroup];
modify->delete_fix(fixID.c_str());
}
if (dynamic[igroup])
modify->delete_fix(std::string("GROUP_") + names[igroup]);
dynamic[igroup] = 1;
std::string fixID = "GROUP_";
fixID += names[igroup];
char **newarg = new char*[narg];
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;
std::string fixcmd = "GROUP_";
fixcmd += fmt::format("{} {} GROUP",names[igroup],arg[2]);
for (int i = 3; i < narg; i++) fixcmd += std::string(" ") + arg[i];
modify->add_fix(fixcmd);
// style = static
// 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 (dynamic[igroup]) {
std::string fixID = "GROUP_";
fixID += names[igroup];
modify->delete_fix(fixID.c_str());
}
if (dynamic[igroup])
modify->delete_fix(std::string("GROUP_") + names[igroup]);
dynamic[igroup] = 0;

View File

@ -113,18 +113,13 @@ Min::~Min()
void Min::init()
{
if (lmp->kokkos && !kokkosable)
error->all(FLERR,"Must use a Kokkos-enabled min style (e.g. min_style cg/kk) "
"with Kokkos minimize");
error->all(FLERR,"Must use a Kokkos-enabled min style "
"(e.g. min_style cg/kk) with Kokkos minimize");
// create fix needed for storing atom-based quantities
// will delete it at end of run
char **fixarg = new char*[3];
fixarg[0] = (char *) "MINIMIZE";
fixarg[1] = (char *) "all";
fixarg[2] = (char *) "MINIMIZE";
modify->add_fix(3,fixarg);
delete [] fixarg;
modify->add_fix("MINIMIZE all MINIMIZE");
fix_minimize = (FixMinimize *) modify->fix[modify->nfix-1];
// 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
// necessary b/c irregular will migrate atoms
if (nextra) {
char cextra[8],fixextra[8];
sprintf(cextra,"%d",nextra);
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;
}
if (nextra)
modify->add_fix(fmt::format("_read_restart all READ_RESTART {} {}",
nextra,modify->nfix_restart_peratom));
// move atoms to new processors via irregular()
// 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
// 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 (atom->torque_flag) {
fixarg[4] = (char *) "torque";
modify->add_fix(5,fixarg);
} else {
modify->add_fix(4,fixarg);
}
delete [] fixarg[3];
delete [] fixarg;
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];
// 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]);
if (icompute < 0) error->all(FLERR,
"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]);