Unverified Commit fd66f32a authored by Axel Kohlmeyer's avatar Axel Kohlmeyer Committed by GitHub
Browse files

Merge pull request #2191 from akohlmey/simpler-add-fix-compute

Simplify adding fixes and computes from inside LAMMPS
parents 66271448 2c815bf3
Loading
Loading
Loading
Loading
+8 −19
Original line number Diff line number Diff line
@@ -489,32 +489,21 @@ void Balance::options(int iarg, int narg, char **arg)

void Balance::weight_storage(char *prefix)
{
  char *fixargs[6];

  if (prefix) {
    int n = strlen(prefix) + 32;
    fixargs[0] = new char[n];
    strcpy(fixargs[0],prefix);
    strcat(fixargs[0],"IMBALANCE_WEIGHTS");
  } else fixargs[0] = (char *) "IMBALANCE_WEIGHTS";

  fixargs[1] = (char *) "all";
  fixargs[2] = (char *) "STORE";
  fixargs[3] = (char *) "peratom";
  fixargs[4] = (char *) "0";
  fixargs[5] = (char *) "1";

  int ifix = modify->find_fix(fixargs[0]);
  std::string cmd = "";

  if (prefix) cmd = prefix;
  cmd += "IMBALANCE_WEIGHTS";

  int ifix = modify->find_fix(cmd.c_str());
  if (ifix < 1) {
    modify->add_fix(6,fixargs);
    cmd += " all STORE peratom 0 1";
    modify->add_fix(cmd);
    fixstore = (FixStore *) modify->fix[modify->nfix-1];
  } else fixstore = (FixStore *) modify->fix[ifix];

  // do not carry weights with atoms during normal atom migration

  fixstore->disable = 1;

  if (prefix) delete [] fixargs[0];
}

/* ----------------------------------------------------------------------
+7 −14
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include "math_const.h"
#include "memory.h"
#include "error.h"
#include "fmt/format.h"

using namespace LAMMPS_NS;
using namespace MathConst;
@@ -581,21 +582,13 @@ void ComputeChunkAtom::init()
  // fixstore initializes all values to 0.0

  if ((idsflag == ONCE || lockcount) && !fixstore) {
    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 *) "1";
    modify->add_fix(6,newarg);
    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];
    delete [] newarg;
  }

  if ((idsflag != ONCE && !lockcount) && fixstore) {
+7 −14
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include "variable.h"
#include "memory.h"
#include "error.h"
#include "fmt/format.h"

using namespace LAMMPS_NS;

@@ -72,21 +73,13 @@ ComputeDisplaceAtom::ComputeDisplaceAtom(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 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 3", group->names[igroup]);
  modify->add_fix(cmd);
  fix = (FixStore *) modify->fix[modify->nfix-1];
  delete [] newarg;

  // calculate xu,yu,zu for fix store array
  // skip if reset from restart file
+14 −24
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "fix_box_relax.h"
#include <cmath>
#include <cstring>
#include <string>
#include "atom.h"
#include "domain.h"
#include "update.h"
@@ -28,6 +29,7 @@
#include "compute.h"
#include "error.h"
#include "math_extra.h"
#include "fmt/format.h"

using namespace LAMMPS_NS;
using namespace FixConst;
@@ -317,36 +319,24 @@ FixBoxRelax::FixBoxRelax(LAMMPS *lmp, int narg, char **arg) :
  // compute group = all since pressure is always global (group all)
  //   and thus its KE/temperature contribution should use group all

  int n = strlen(id) + 6;
  id_temp = new char[n];
  strcpy(id_temp,id);
  strcat(id_temp,"_temp");

  char **newarg = new char*[3];
  newarg[0] = id_temp;
  newarg[1] = (char *) "all";
  newarg[2] = (char *) "temp";
  modify->add_compute(3,newarg);
  delete [] newarg;
  std::string tcmd = id + std::string("_temp");
  id_temp = new char[tcmd.size()+1];
  strcpy(id_temp,tcmd.c_str());

  tcmd += " all temp";
  modify->add_compute(tcmd);
  tflag = 1;

  // create a new compute pressure style (virial only)
  // id = fix-ID + press, compute group = all
  // pass id_temp as 4th arg to pressure constructor

  n = strlen(id) + 7;
  id_press = new char[n];
  strcpy(id_press,id);
  strcat(id_press,"_press");

  newarg = new char*[5];
  newarg[0] = id_press;
  newarg[1] = (char *) "all";
  newarg[2] = (char *) "pressure";
  newarg[3] = id_temp;
  newarg[4] = (char *) "virial";
  modify->add_compute(5,newarg);
  delete [] newarg;
  std::string pcmd = id + std::string("_press");
  id_press = new char[pcmd.size()+1];
  strcpy(id_press,pcmd.c_str());

  pcmd += " all pressure " + std::string(id_temp) + " virial";
  modify->add_compute(pcmd);
  pflag = 1;

  dimension = domain->dimension;
+11 −22
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@

#include "fix_nph.h"
#include <cstring>
#include <string>
#include "modify.h"
#include "error.h"

@@ -34,35 +35,23 @@ FixNPH::FixNPH(LAMMPS *lmp, int narg, char **arg) :
  // compute group = all since pressure is always global (group all)
  // and thus its KE/temperature contribution should use group all

  int n = strlen(id) + 6;
  id_temp = new char[n];
  strcpy(id_temp,id);
  strcat(id_temp,"_temp");
  std::string tcmd = id + std::string("_temp");
  id_temp = new char[tcmd.size()+1];
  strcpy(id_temp,tcmd.c_str());

  char **newarg = new char*[3];
  newarg[0] = id_temp;
  newarg[1] = (char *) "all";
  newarg[2] = (char *) "temp";

  modify->add_compute(3,newarg);
  delete [] newarg;
  tcmd += " all temp";
  modify->add_compute(tcmd);
  tcomputeflag = 1;

  // create a new compute pressure style
  // id = fix-ID + press, compute group = all
  // pass id_temp as 4th arg to pressure constructor

  n = strlen(id) + 7;
  id_press = new char[n];
  strcpy(id_press,id);
  strcat(id_press,"_press");
  std::string pcmd = id + std::string("_press");
  id_press = new char[pcmd.size()+1];
  strcpy(id_press,pcmd.c_str());

  newarg = new char*[4];
  newarg[0] = id_press;
  newarg[1] = (char *) "all";
  newarg[2] = (char *) "pressure";
  newarg[3] = id_temp;
  modify->add_compute(4,newarg);
  delete [] newarg;
  pcmd += " all pressure " + std::string(id_temp);
  modify->add_compute(pcmd);
  pcomputeflag = 1;
}
Loading