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

Merge pull request #2195 from jrgissing/bond/react-reformat

Bond/react reformat
parents 51174d4a 3044d83c
Loading
Loading
Loading
Loading
+27 −62
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ Contributing Author: Jacob Gissinger (jacob.gissinger@colorado.edu)
#include <mpi.h>
#include <mpi.h>
#include <cmath>
#include <cmath>
#include <cstring>
#include <cstring>
#include <string>
#include "update.h"
#include "update.h"
#include "modify.h"
#include "modify.h"
#include "respa.h"
#include "respa.h"
@@ -41,6 +42,7 @@ Contributing Author: Jacob Gissinger (jacob.gissinger@colorado.edu)
#include "error.h"
#include "error.h"
#include "input.h"
#include "input.h"
#include "variable.h"
#include "variable.h"
#include "fmt/format.h"


#include <algorithm>
#include <algorithm>


@@ -575,17 +577,11 @@ FixBondReact::~FixBondReact()
  delete [] set;
  delete [] set;


  if (group) {
  if (group) {
    char **newarg;
    group->assign(std::string(master_group) + " delete");
    newarg = new char*[2];
    newarg[0] = master_group;
    newarg[1] = (char *) "delete";
    group->assign(2,newarg);
    if (stabilization_flag == 1) {
    if (stabilization_flag == 1) {
      newarg[0] = exclude_group;
      group->assign(std::string(exclude_group) + " delete");
      group->assign(2,newarg);
      delete [] exclude_group;
      delete [] exclude_group;
    }
    }
    delete [] newarg;
  }
  }
}
}


@@ -608,59 +604,38 @@ it will have the name 'i_limit_tags' and will be intitialized to 0 (not in group


void FixBondReact::post_constructor()
void FixBondReact::post_constructor()
{
{
  int len;
  // let's add the limit_tags per-atom property fix
  // let's add the limit_tags per-atom property fix
  int len = strlen("bond_react_props_internal") + 1;
  std::string cmd = std::string("bond_react_props_internal");
  id_fix2 = new char[len];
  id_fix2 = new char[cmd.size()+1];
  strcpy(id_fix2,"bond_react_props_internal");
  strcpy(id_fix2,cmd.c_str());


  int ifix = modify->find_fix(id_fix2);
  int ifix = modify->find_fix(id_fix2);
  if (ifix == -1) {
  if (ifix == -1) {
    char **newarg = new char*[7];
    cmd += std::string(" all property/atom i_limit_tags i_react_tags ghost yes");
    newarg[0] = (char *) "bond_react_props_internal";
    modify->add_fix(cmd);
    newarg[1] = (char *) "all"; // group ID is ignored
    newarg[2] = (char *) "property/atom";
    newarg[3] = (char *) "i_limit_tags";
    newarg[4] = (char *) "i_react_tags";
    newarg[5] = (char *) "ghost";
    newarg[6] = (char *) "yes";
    modify->add_fix(7,newarg);
    delete [] newarg;
  }
  }


  // create master_group if not already existing
  // create master_group if not already existing
  // NOTE: limit_tags and react_tags automaticaly intitialized to zero (unless read from restart)
  // NOTE: limit_tags and react_tags automaticaly intitialized to zero (unless read from restart)
  group->find_or_create(master_group);
  group->find_or_create(master_group);
  char **newarg;
  cmd = fmt::format("{} dynamic all property limit_tags",master_group);
  newarg = new char*[5];
  group->assign(cmd);
  newarg[0] = master_group;
  newarg[1] = (char *) "dynamic";
  newarg[2] = (char *) "all";
  newarg[3] = (char *) "property";
  newarg[4] = (char *) "limit_tags";
  group->assign(5,newarg);
  delete [] newarg;


  if (stabilization_flag == 1) {
  if (stabilization_flag == 1) {
    int igroup = group->find(exclude_group);
    int igroup = group->find(exclude_group);
    // create exclude_group if not already existing, or use as parent group if static
    // create exclude_group if not already existing, or use as parent group if static
    if (igroup == -1 || group->dynamic[igroup] == 0) {
    if (igroup == -1 || group->dynamic[igroup] == 0) {
      // create stabilization per-atom property
      // create stabilization per-atom property
      len = strlen("bond_react_stabilization_internal") + 1;
      cmd = std::string("bond_react_stabilization_internal");
      id_fix3 = new char[len];
      id_fix3 = new char[cmd.size()+1];
      strcpy(id_fix3,"bond_react_stabilization_internal");
      strcpy(id_fix3,cmd.c_str());


      ifix = modify->find_fix(id_fix3);
      ifix = modify->find_fix(id_fix3);
      if (ifix == -1) {
      if (ifix == -1) {
        char **newarg = new char*[6];
        cmd += std::string(" all property/atom i_statted_tags ghost yes");
        newarg[0] = (char *) id_fix3;
        modify->add_fix(cmd);
        newarg[1] = (char *) "all"; // group ID is ignored
        newarg[2] = (char *) "property/atom";
        newarg[3] = (char *) "i_statted_tags";
        newarg[4] = (char *) "ghost";
        newarg[5] = (char *) "yes";
        modify->add_fix(6,newarg);
        fix3 = modify->fix[modify->nfix-1];
        fix3 = modify->fix[modify->nfix-1];
        delete [] newarg;
      }
      }


      len = strlen("statted_tags") + 1;
      len = strlen("statted_tags") + 1;
@@ -680,16 +655,11 @@ void FixBondReact::post_constructor()
      strcat(exclude_group,"_REACT");
      strcat(exclude_group,"_REACT");


      group->find_or_create(exclude_group);
      group->find_or_create(exclude_group);
      char **newarg;
      if (igroup == -1)
      newarg = new char*[5];
        cmd = fmt::format("{} dynamic all property statted_tags",exclude_group);
      newarg[0] = exclude_group;
      else
      newarg[1] = (char *) "dynamic";
        cmd = fmt::format("{} dynamic {} property statted_tags",exclude_group,exclude_PARENT_group);
      if (igroup == -1) newarg[2] = (char *) "all";
      group->assign(cmd);
      else newarg[2] = (char *) exclude_PARENT_group;
      newarg[3] = (char *) "property";
      newarg[4] = (char *) "statted_tags";
      group->assign(5,newarg);
      delete [] newarg;
      delete [] exclude_PARENT_group;
      delete [] exclude_PARENT_group;


      // on to statted_tags (system-wide thermostat)
      // on to statted_tags (system-wide thermostat)
@@ -737,21 +707,16 @@ void FixBondReact::post_constructor()




    // let's create a new nve/limit fix to limit newly reacted atoms
    // let's create a new nve/limit fix to limit newly reacted atoms
    len = strlen("bond_react_MASTER_nve_limit") + 1;
    cmd = std::string("bond_react_MASTER_nve_limit");
    id_fix1 = new char[len];
    id_fix1 = new char[cmd.size()+1];
    strcpy(id_fix1,"bond_react_MASTER_nve_limit");
    strcpy(id_fix1,cmd.c_str());


    ifix = modify->find_fix(id_fix1);
    ifix = modify->find_fix(id_fix1);


    if (ifix == -1) {
    if (ifix == -1) {
      char **newarg = new char*[4];
      cmd += fmt::format(" {} nve/limit  {}",master_group,nve_limit_xmax);
      newarg[0] = id_fix1;
      modify->add_fix(cmd);
      newarg[1] = master_group;
      newarg[2] = (char *) "nve/limit";
      newarg[3] = nve_limit_xmax;
      modify->add_fix(4,newarg);
      fix1 = modify->fix[modify->nfix-1];
      fix1 = modify->fix[modify->nfix-1];
      delete [] newarg;
    }
    }
  }
  }
}
}
+16 −0
Original line number Original line Diff line number Diff line
@@ -547,6 +547,22 @@ void Group::assign(int narg, char **arg)
  }
  }
}
}


/* ----------------------------------------------------------------------
   convenience function to allow assigning to groups from a single string
------------------------------------------------------------------------- */

void Group::assign(const std::string &groupcmd)
{
  std::vector<std::string> args = utils::split_words(groupcmd);
  char **newarg = new char*[args.size()];
  int i=0;
  for (const auto &arg : args) {
    newarg[i++] = (char *)arg.c_str();
  }
  assign(args.size(),newarg);
  delete[] newarg;
}

/* ----------------------------------------------------------------------
/* ----------------------------------------------------------------------
   add flagged atoms to a new or existing group
   add flagged atoms to a new or existing group
------------------------------------------------------------------------- */
------------------------------------------------------------------------- */
+2 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


#include "pointers.h"
#include "pointers.h"
#include <map>
#include <map>
#include <string>


namespace LAMMPS_NS {
namespace LAMMPS_NS {


@@ -30,6 +31,7 @@ class Group : protected Pointers {
  Group(class LAMMPS *);
  Group(class LAMMPS *);
  ~Group();
  ~Group();
  void assign(int, char **);         // assign atoms to a group
  void assign(int, char **);         // assign atoms to a group
  void assign(const std::string &);  // convenience function
  void create(char *, int *);        // add flagged atoms to a group
  void create(char *, int *);        // add flagged atoms to a group
  int find(const char *);            // lookup name in list of groups
  int find(const char *);            // lookup name in list of groups
  int find_or_create(const char *);  // lookup name or create new group
  int find_or_create(const char *);  // lookup name or create new group