Unverified Commit 3cd1341e authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

make more use of convenience functions for adding fixes and computes

parent df29364b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
+7 −14
Original line number Diff line number Diff line
@@ -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
+11 −21
Original line number Diff line number Diff line
@@ -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;
}

/* ---------------------------------------------------------------------- */
+10 −25
Original line number Diff line number Diff line
@@ -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;

+3 −8
Original line number Diff line number Diff line
@@ -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
Loading