Commit cf83ce67 authored by Jacob Gissinger's avatar Jacob Gissinger
Browse files

reset_mol_ids->reset() version

parent 295d75f2
Loading
Loading
Loading
Loading
+2 −9
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ Syntax
       *compress* value = *yes* or *no*
       *offset* value = *Noffset* >= -1
       *single* value = *yes* or *no* to treat single atoms (no bonds) as molecules
       *verbose* value = *yes* or *no*

Examples
""""""""
@@ -96,12 +95,6 @@ is not *all* there may be collisions with the molecule IDs of other atoms.
   does not perform a full update of the bond topology data structures
   within LAMMPS.

The *verbose* keyword determines if this command outputs run-time
information to the screen and log file. If the setting is *yes*
(the default), the command prints out information including the number
of new molecule IDs and CPU time used by the command. If the setting
is *no*, no information is printed.

Restrictions
""""""""""""
none
@@ -119,5 +112,5 @@ Related commands
Default
"""""""

The default keyword settings are compress = yes, single = no,
verbose = yes, and offset = -1.
The default keyword settings are compress = yes, single = no, and
offset = -1.
+10 −3
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ Contributing Author: Jacob Gissinger (jacob.gissinger@colorado.edu)
#include "neigh_list.h"
#include "neigh_request.h"
#include "random_mars.h"
#include "reset_mol_ids.h"
#include "molecule.h"
#include "group.h"
#include "citeme.h"
@@ -92,6 +93,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) :
  fix1 = NULL;
  fix2 = NULL;
  fix3 = NULL;
  reset_mol_ids = NULL;

  if (narg < 8) error->all(FLERR,"Illegal fix bond/react command: "
                           "too few arguments");
@@ -166,7 +168,11 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) :
    } else if (strcmp(arg[iarg],"reset_mol_ids") == 0) {
      if (iarg+2 > narg) error->all(FLERR,"Illegal fix bond/react command: "
                                    "'reset_mol_ids' keyword has too few arguments");
      if (strcmp(arg[iarg+1],"yes") == 0) iarg += 2; //default
      if (strcmp(arg[iarg+1],"yes") == 0) { // default
        delete reset_mol_ids;
        reset_mol_ids = new ResetMolIDs(lmp);
        iarg += 2;
      }
      if (strcmp(arg[iarg+1],"no") == 0) {
        reset_mol_ids_flag = 0;
        iarg += 2;
@@ -508,6 +514,8 @@ FixBondReact::~FixBondReact()
  }
  delete [] random;

  delete reset_mol_ids;

  memory->destroy(partner);
  memory->destroy(finalpartner);
  memory->destroy(ncreate);
@@ -3052,8 +3060,7 @@ void FixBondReact::update_everything()
  // done deleting atoms

  // reset mol ids
  if (reset_mol_ids_flag)
    input->one("reset_mol_ids " + std::string(group->names[igroup]) + " verbose no");
  if (reset_mol_ids_flag) reset_mol_ids->reset(group->names[igroup]);

  // something to think about: this could done much more concisely if
  // all atom-level info (bond,angles, etc...) were kinda inherited from a common data struct --JG
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ class FixBondReact : public Fix {
  class RanMars **random; // random number for 'prob' keyword
  class RanMars **rrhandom; // random number for Arrhenius constraint
  class NeighList *list;
  class ResetMolIDs *reset_mol_ids; // class for resetting mol IDs

  int *reacted_mol,*unreacted_mol;
  int *limit_duration; // indicates how long to relax
+46 −38
Original line number Diff line number Diff line
@@ -33,9 +33,15 @@ using namespace LAMMPS_NS;

/* ---------------------------------------------------------------------- */

ResetMolIDs::ResetMolIDs(LAMMPS *lmp) : Pointers(lmp) {}
ResetMolIDs::ResetMolIDs(LAMMPS *lmp) : Pointers(lmp) {
  compressflag = 1;
  singleflag = 0;
  offset = -1;
}

/* ---------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
   called as reset_mol_ids command in input script
------------------------------------------------------------------------- */

void ResetMolIDs::command(int narg, char **arg)
{
@@ -49,14 +55,7 @@ void ResetMolIDs::command(int narg, char **arg)
  // process args

  if (narg < 1) error->all(FLERR,"Illegal reset_mol_ids command");
  int igroup = group->find(arg[0]);
  if (igroup == -1) error->all(FLERR,"Could not find reset_mol_ids group ID");
  int groupbit = group->bitmask[igroup];

  int compressflag = 1;
  int singleflag = 0;
  tagint offset = -1;
  int verbose = 1;
  char *groupid = arg[0];

  int iarg = 1;
  while (iarg < narg) {
@@ -77,39 +76,61 @@ void ResetMolIDs::command(int narg, char **arg)
      offset = utils::tnumeric(FLERR,arg[iarg+1],1,lmp);
      if (offset < -1) error->all(FLERR,"Illegal reset_mol_ids command");
      iarg += 2;
    } else if (strcmp(arg[iarg],"verbose") == 0) {
      if (iarg+2 > narg) error->all(FLERR,"Illegal reset_mol_ids command");
      if (strcmp(arg[iarg+1],"yes") == 0) verbose = 1;
      else if (strcmp(arg[iarg+1],"no") == 0) verbose = 0;
      else error->all(FLERR,"Illegal reset_mol_ids command");
      iarg += 2;
    } else error->all(FLERR,"Illegal reset_mol_ids command");
  }

  if (verbose && (comm->me == 0)) utils::logmesg(lmp,"Resetting molecule IDs ...\n");
  if (comm->me == 0) utils::logmesg(lmp,"Resetting molecule IDs ...\n");

  // record wall time for resetting molecule IDs

  MPI_Barrier(world);
  double time1 = MPI_Wtime();

  // initialize system since comm->borders() will be invoked

  lmp->init();

  // reset molecule IDs

  reset(groupid);

  // total time

  MPI_Barrier(world);

  if (comm->me == 0) {
    if (nchunk < 0)
      utils::logmesg(lmp,fmt::format("  number of new molecule IDs = unknown\n"));
    else
      utils::logmesg(lmp,fmt::format("  number of new molecule IDs = {}\n",nchunk));
    utils::logmesg(lmp,fmt::format("  reset_mol_ids CPU = {:.3f} seconds\n",
                                   MPI_Wtime()-time1));
  }
}

/* ----------------------------------------------------------------------
   called from command() and directly from fixes that update molecules
------------------------------------------------------------------------- */

void ResetMolIDs::reset(char *groupid)
{
  int igroup = group->find(groupid);
  if (igroup == -1) error->all(FLERR,"Could not find reset_mol_ids group ID");
  int groupbit = group->bitmask[igroup];

  // create instances of compute fragment/atom, compute reduce (if needed),
  // and compute chunk/atom.  all use the group-ID for this command

  const std::string idfrag = "reset_mol_ids_FRAGMENT_ATOM";
  if (singleflag)
    modify->add_compute(fmt::format("{} {} fragment/atom single yes",idfrag,arg[0]));
    modify->add_compute(fmt::format("{} {} fragment/atom single yes",idfrag,groupid));
  else
    modify->add_compute(fmt::format("{} {} fragment/atom single no",idfrag,arg[0]));
    modify->add_compute(fmt::format("{} {} fragment/atom single no",idfrag,groupid));

  const std::string idchunk = "reset_mol_ids_CHUNK_ATOM";
  if (compressflag)
    modify->add_compute(fmt::format("{} {} chunk/atom molecule compress yes",
                                    idchunk,arg[0]));

  // initialize system since comm->borders() will be invoked

  lmp->init();
                                    idchunk,groupid));

  // setup domain, communication
  // exchange will clear map, borders will reset
@@ -145,7 +166,7 @@ void ResetMolIDs::command(int narg, char **arg)
  // if compressflag = 0, done
  // set nchunk = -1 since cannot easily determine # of new molecule IDs

  int nchunk = -1;
  nchunk = -1;

  // if compressflag = 1, invoke peratom method of compute chunk/atom
  // will compress new molecule IDs to be contiguous 1 to Nmol
@@ -205,17 +226,4 @@ void ResetMolIDs::command(int narg, char **arg)

  modify->delete_compute(idfrag);
  if (compressflag) modify->delete_compute(idchunk);

  // total time

  MPI_Barrier(world);

  if (verbose && (comm->me == 0)) {
    if (nchunk < 0)
      utils::logmesg(lmp,fmt::format("  number of new molecule IDs = unknown\n"));
    else
      utils::logmesg(lmp,fmt::format("  number of new molecule IDs = {}\n",nchunk));
    utils::logmesg(lmp,fmt::format("  reset_mol_ids CPU = {:.3f} seconds\n",
                                   MPI_Wtime()-time1));
  }
}
+7 −0
Original line number Diff line number Diff line
@@ -28,6 +28,13 @@ class ResetMolIDs : protected Pointers {
 public:
  ResetMolIDs(class LAMMPS *);
  void command(int, char **);
  void reset(char *);

private:
  int nchunk;
  int compressflag; // 1 = contiguous values for new IDs
  int singleflag; // 0 = mol IDs of single atoms set to 0
  tagint offset; // offset for contiguous mol ID values
};

}