git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@12157 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
#include "domain.h"
|
||||
#include "atom.h"
|
||||
#include "force.h"
|
||||
#include "comm.h"
|
||||
#include "region.h"
|
||||
#include "modify.h"
|
||||
#include "fix.h"
|
||||
@ -31,6 +32,8 @@
|
||||
#include "memory.h"
|
||||
#include "error.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
#define MAX_GROUP 32
|
||||
@ -40,6 +43,10 @@ enum{LT,LE,GT,GE,EQ,NEQ,BETWEEN};
|
||||
|
||||
#define BIG 1.0e20
|
||||
|
||||
// allocate space for static class variable
|
||||
|
||||
Group *Group::cptr;
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
initialize group memory
|
||||
------------------------------------------------------------------------- */
|
||||
@ -133,6 +140,21 @@ void Group::assign(int narg, char **arg)
|
||||
return;
|
||||
}
|
||||
|
||||
// clear the group
|
||||
|
||||
if (strcmp(arg[1],"clear") == 0) {
|
||||
int igroup = find(arg[0]);
|
||||
if (igroup == -1) error->all (FLERR,"Could not find group clear group ID");
|
||||
if (igroup == 0) error->all (FLERR,"Cannot clear group all");
|
||||
|
||||
int *mask = atom->mask;
|
||||
int nlocal = atom->nlocal;
|
||||
int bits = inversemask[igroup];
|
||||
for (i = 0; i < nlocal; i++) mask[i] &= bits;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// find group in existing list
|
||||
// add a new group if igroup = -1
|
||||
|
||||
@ -330,6 +352,16 @@ void Group::assign(int narg, char **arg)
|
||||
|
||||
memory->destroy(aflag);
|
||||
|
||||
// style = include
|
||||
|
||||
} else if (strcmp(arg[1],"include") == 0) {
|
||||
|
||||
if (narg != 3) error->all(FLERR,"Illegal group command");
|
||||
if (strcmp(arg[2],"molecule") != 0)
|
||||
error->all(FLERR,"Illegal group command");
|
||||
|
||||
add_molecules(igroup,bit);
|
||||
|
||||
// style = subtract
|
||||
|
||||
} else if (strcmp(arg[1],"subtract") == 0) {
|
||||
@ -567,6 +599,69 @@ int Group::find_unused()
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
add atoms to group that are in same molecules as atoms already in group
|
||||
do not include molID = 0
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Group::add_molecules(int igroup, int bit)
|
||||
{
|
||||
// hash = unique molecule IDs of atoms already in group
|
||||
|
||||
hash = new std::map<tagint,int>();
|
||||
|
||||
tagint *molecule = atom->molecule;
|
||||
int *mask = atom->mask;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & bit) {
|
||||
if (molecule[i] == 0) continue;
|
||||
if (hash->find(molecule[i]) == hash->end()) (*hash)[molecule[i]] = 1;
|
||||
}
|
||||
|
||||
// list = set of unique molecule IDs for atoms to add
|
||||
// pass list to all other procs via comm->ring()
|
||||
|
||||
int n = hash->size();
|
||||
tagint *list;
|
||||
memory->create(list,n,"group:list");
|
||||
|
||||
n = 0;
|
||||
std::map<tagint,int>::iterator pos;
|
||||
for (pos = hash->begin(); pos != hash->end(); ++pos) list[n++] = pos->first;
|
||||
|
||||
cptr = this;
|
||||
molbit = bit;
|
||||
comm->ring(n,sizeof(tagint),list,1,molring,NULL);
|
||||
|
||||
delete hash;
|
||||
memory->destroy(list);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
callback from comm->ring()
|
||||
cbuf = list of N molecule IDs, put them in hash
|
||||
loop over my atoms, if matches molecule ID in hash,
|
||||
add atom to group flagged by molbit
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Group::molring(int n, char *cbuf)
|
||||
{
|
||||
tagint *list = (tagint *) cbuf;
|
||||
std::map<tagint,int> *hash = cptr->hash;
|
||||
int nlocal = cptr->atom->nlocal;
|
||||
tagint *molecule = cptr->atom->molecule;
|
||||
int *mask = cptr->atom->mask;
|
||||
int molbit = cptr->molbit;
|
||||
|
||||
hash->clear();
|
||||
for (int i = 0; i < n; i++) (*hash)[list[i]] = 1;
|
||||
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (hash->find(molecule[i]) != hash->end()) mask[i] |= molbit;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
write group info to a restart file
|
||||
only called by proc 0
|
||||
|
||||
Reference in New Issue
Block a user