use new bitmap accessor function and simplify code

This commit is contained in:
Axel Kohlmeyer
2024-06-01 17:57:31 -04:00
parent 5f2c81804d
commit a0939c4fcc
11 changed files with 23 additions and 50 deletions

View File

@ -2284,7 +2284,7 @@ void Atom::first_reorder()
// nfirst = index of first atom not in firstgroup // nfirst = index of first atom not in firstgroup
// when find firstgroup atom out of place, swap it with atom nfirst // when find firstgroup atom out of place, swap it with atom nfirst
int bitmask = group->bitmask[firstgroup]; const int bitmask = group->get_bitmask_by_id(FLERR, firstgroupname, "Atom::first_reorder");
nfirst = 0; nfirst = 0;
while (nfirst < nlocal && mask[nfirst] & bitmask) nfirst++; while (nfirst < nlocal && mask[nfirst] & bitmask) nfirst++;

View File

@ -52,9 +52,7 @@ void ChangeBox::command(int narg, char **arg)
// group // group
int igroup = group->find(arg[0]); int groupbit = group->get_bitmask_by_id(FLERR, arg[0], "change_box");
if (igroup == -1) error->all(FLERR,"Could not find change_box group ID {}", arg[0]);
int groupbit = group->bitmask[igroup];
// parse operation arguments // parse operation arguments
// allocate ops to max possible length // allocate ops to max possible length

View File

@ -48,11 +48,11 @@ Compute::Compute(LAMMPS *lmp, int narg, char **arg) :
id = utils::strdup(arg[0]); id = utils::strdup(arg[0]);
if (!utils::is_id(id)) if (!utils::is_id(id))
error->all(FLERR,"Compute ID must be alphanumeric or underscore characters"); error->all(FLERR,"Compute ID {} must only have alphanumeric or underscore characters", id);
groupbit = group->get_bitmask_by_id(FLERR, arg[1], fmt::format("compute {}", arg[2]));
igroup = group->find(arg[1]); igroup = group->find(arg[1]);
if (igroup == -1) error->all(FLERR,"Could not find compute group ID"); if (igroup == -1) error->all(FLERR,"Could not find compute group ID {}", arg[1]);
groupbit = group->bitmask[igroup];
style = utils::strdup(arg[2]); style = utils::strdup(arg[2]);

View File

@ -39,8 +39,7 @@ ComputeCoordAtom::ComputeCoordAtom(LAMMPS *lmp, int narg, char **arg) :
{ {
if (narg < 5) error->all(FLERR, "Illegal compute coord/atom command"); if (narg < 5) error->all(FLERR, "Illegal compute coord/atom command");
jgroup = group->find("all"); jgroupbit = group->get_bitmask_by_id(FLERR, "all", "compute coord/atom");
jgroupbit = group->bitmask[jgroup];
cstyle = NONE; cstyle = NONE;
if (strcmp(arg[3], "cutoff") == 0) { if (strcmp(arg[3], "cutoff") == 0) {
@ -50,11 +49,10 @@ ComputeCoordAtom::ComputeCoordAtom(LAMMPS *lmp, int narg, char **arg) :
int iarg = 5; int iarg = 5;
if ((narg > 6) && (strcmp(arg[5], "group") == 0)) { if ((narg > 6) && (strcmp(arg[5], "group") == 0)) {
delete[] group2;
group2 = utils::strdup(arg[6]); group2 = utils::strdup(arg[6]);
iarg += 2; iarg += 2;
jgroup = group->find(group2); jgroupbit = group->get_bitmask_by_id(FLERR, group2, "compute coord/atom");
if (jgroup == -1) error->all(FLERR, "Compute coord/atom group2 ID does not exist");
jgroupbit = group->bitmask[jgroup];
} }
ncol = narg - iarg + 1; ncol = narg - iarg + 1;

View File

@ -46,7 +46,7 @@ class ComputeCoordAtom : public Compute {
double **carray; double **carray;
char *group2; char *group2;
int jgroup, jgroupbit; int jgroupbit;
class ComputeOrientOrderAtom *c_orientorder; class ComputeOrientOrderAtom *c_orientorder;
char *id_orientorder; char *id_orientorder;

View File

@ -54,9 +54,7 @@ ComputeGroupGroup::ComputeGroupGroup(LAMMPS *lmp, int narg, char **arg) :
extvector = 1; extvector = 1;
group2 = utils::strdup(arg[3]); group2 = utils::strdup(arg[3]);
jgroup = group->find(group2); jgroupbit = group->get_bitmask_by_id(FLERR, group2, "compute group/group");
if (jgroup == -1) error->all(FLERR, "Compute group/group group ID does not exist");
jgroupbit = group->bitmask[jgroup];
pairflag = 1; pairflag = 1;
kspaceflag = 0; kspaceflag = 0;
@ -147,9 +145,7 @@ void ComputeGroupGroup::init()
// recheck that group 2 has not been deleted // recheck that group 2 has not been deleted
jgroup = group->find(group2); jgroupbit = group->get_bitmask_by_id(FLERR, group2, "compute group/group");
if (jgroup == -1) error->all(FLERR, "Compute group/group group ID does not exist");
jgroupbit = group->bitmask[jgroup];
// need an occasional half neighbor list // need an occasional half neighbor list

View File

@ -35,7 +35,7 @@ class ComputeGroupGroup : public Compute {
private: private:
char *group2; char *group2;
int jgroup, jgroupbit, othergroupbit; int jgroupbit;
double **cutsq; double **cutsq;
double e_self, e_correction; double e_self, e_correction;
int pairflag, kspaceflag, boundaryflag, molflag; int pairflag, kspaceflag, boundaryflag, molflag;

View File

@ -59,12 +59,8 @@ void CreateBonds::command(int narg, char **arg)
if (strcmp(arg[0], "many") == 0) { if (strcmp(arg[0], "many") == 0) {
style = MANY; style = MANY;
if (narg != 6) error->all(FLERR, "No optional keywords allowed with create_bonds many"); if (narg != 6) error->all(FLERR, "No optional keywords allowed with create_bonds many");
igroup = group->find(arg[1]); group1bit = group->get_bitmask_by_id(FLERR, arg[1], "create_bonds");
if (igroup == -1) error->all(FLERR, "Cannot find create_bonds first group ID {}", arg[1]); group2bit = group->get_bitmask_by_id(FLERR, arg[2], "create_bonds");
group1bit = group->bitmask[igroup];
igroup = group->find(arg[2]);
if (igroup == -1) error->all(FLERR, "Cannot find create_bonds second group ID {}", arg[2]);
group2bit = group->bitmask[igroup];
btype = utils::inumeric(FLERR, arg[3], false, lmp); btype = utils::inumeric(FLERR, arg[3], false, lmp);
rmin = utils::numeric(FLERR, arg[4], false, lmp); rmin = utils::numeric(FLERR, arg[4], false, lmp);
rmax = utils::numeric(FLERR, arg[5], false, lmp); rmax = utils::numeric(FLERR, arg[5], false, lmp);

View File

@ -30,7 +30,7 @@ class CreateBonds : public Command {
void command(int, char **) override; void command(int, char **) override;
private: private:
int igroup, group1bit, group2bit; int group1bit, group2bit;
int btype, atype, dtype; int btype, atype, dtype;
tagint batom1, batom2, aatom1, aatom2, aatom3, datom1, datom2, datom3, datom4; tagint batom1, batom2, aatom1, aatom2, aatom3, datom1, datom2, datom3, datom4;
double rmin, rmax; double rmin, rmax;

View File

@ -86,8 +86,8 @@ void DeleteAtoms::command(int narg, char **arg)
error->all(FLERR, "Unknown delete_atoms sub-command: {}", arg[0]); error->all(FLERR, "Unknown delete_atoms sub-command: {}", arg[0]);
if (allflag) { if (allflag) {
int igroup = group->find("all"); int igroupbit = group->get_bitmask_by_id(FLERR, "all", "delete_atoms");
if ((igroup >= 0) && modify->check_rigid_group_overlap(group->bitmask[igroup])) if (modify->check_rigid_group_overlap(igroupbit))
error->warning(FLERR, "Attempting to delete atoms in rigid bodies"); error->warning(FLERR, "Attempting to delete atoms in rigid bodies");
} else { } else {
if (modify->check_rigid_list_overlap(dlist)) if (modify->check_rigid_list_overlap(dlist))
@ -215,8 +215,7 @@ void DeleteAtoms::delete_group(int narg, char **arg)
{ {
if (narg < 2) utils::missing_cmd_args(FLERR, "delete_atoms group", error); if (narg < 2) utils::missing_cmd_args(FLERR, "delete_atoms group", error);
int igroup = group->find(arg[1]); int groupbit = group->get_bitmask_by_id(FLERR, arg[1], "delete_atoms");
if (igroup == -1) error->all(FLERR, "Could not find delete_atoms group ID {}", arg[1]);
options(narg - 2, &arg[2]); options(narg - 2, &arg[2]);
// check for special case of group = all // check for special case of group = all
@ -233,8 +232,6 @@ void DeleteAtoms::delete_group(int narg, char **arg)
for (int i = 0; i < nlocal; i++) dlist[i] = 0; for (int i = 0; i < nlocal; i++) dlist[i] = 0;
int *mask = atom->mask; int *mask = atom->mask;
int groupbit = group->bitmask[igroup];
for (int i = 0; i < nlocal; i++) for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) dlist[i] = 1; if (mask[i] & groupbit) dlist[i] = 1;
} }
@ -280,18 +277,11 @@ void DeleteAtoms::delete_overlap(int narg, char **arg)
const double cut = utils::numeric(FLERR, arg[1], false, lmp); const double cut = utils::numeric(FLERR, arg[1], false, lmp);
const double cutsq = cut * cut; const double cutsq = cut * cut;
const int group1bit = group->get_bitmask_by_id(FLERR, arg[2], "delete_atoms");
const int group2bit = group->get_bitmask_by_id(FLERR, arg[3], "delete_atoms");
int igroup1 = group->find(arg[2]);
if (igroup1 < 0)
error->all(FLERR, "Could not find delete_atoms overlap first group ID {}", arg[2]);
int igroup2 = group->find(arg[3]);
if (igroup2 < 0)
error->all(FLERR, "Could not find delete_atoms overlap second group ID {}", arg[3]);
options(narg - 4, &arg[4]); options(narg - 4, &arg[4]);
const int group1bit = group->bitmask[igroup1];
const int group2bit = group->bitmask[igroup2];
if (comm->me == 0) utils::logmesg(lmp, "System init for delete_atoms ...\n"); if (comm->me == 0) utils::logmesg(lmp, "System init for delete_atoms ...\n");
// request a full neighbor list for use by this command // request a full neighbor list for use by this command
@ -453,9 +443,7 @@ void DeleteAtoms::delete_random(int narg, char **arg)
error->all(FLERR, "Unknown delete_atoms random style: {}", arg[1]); error->all(FLERR, "Unknown delete_atoms random style: {}", arg[1]);
} }
int igroup = group->find(arg[4]); int groupbit = group->get_bitmask_by_id(FLERR, arg[4], "delete_atoms");
if (igroup == -1) error->all(FLERR, "Could not find delete_atoms random group ID {}", arg[4]);
auto region = domain->get_region_by_id(arg[5]); auto region = domain->get_region_by_id(arg[5]);
if (!region && (strcmp(arg[5], "NULL") != 0)) if (!region && (strcmp(arg[5], "NULL") != 0))
error->all(FLERR, "Could not find delete_atoms random region ID {}", arg[5]); error->all(FLERR, "Could not find delete_atoms random region ID {}", arg[5]);
@ -476,7 +464,6 @@ void DeleteAtoms::delete_random(int narg, char **arg)
double **x = atom->x; double **x = atom->x;
int *mask = atom->mask; int *mask = atom->mask;
int groupbit = group->bitmask[igroup];
if (region) region->prematch(); if (region) region->prematch();
// delete approximate fraction of atoms in both group and region // delete approximate fraction of atoms in both group and region

View File

@ -56,11 +56,9 @@ void DeleteBonds::command(int narg, char **arg)
if (comm->me == 0) utils::logmesg(lmp,"Deleting bonds ...\n"); if (comm->me == 0) utils::logmesg(lmp,"Deleting bonds ...\n");
// identify group // get group bitmask
int igroup = group->find(arg[0]); int groupbit = group->get_bitmask_by_id(FLERR, arg[0], "delete_bonds");
if (igroup == -1) error->all(FLERR,"Cannot find delete_bonds group ID");
int groupbit = group->bitmask[igroup];
// set style and which = type value // set style and which = type value