add group::assign convenience version

This commit is contained in:
Jacob Gissinger
2020-06-26 21:36:12 -06:00
parent 77a6c7b7dc
commit 7f05c578f5
2 changed files with 17 additions and 0 deletions

View File

@ -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 &fixcmd)
{
std::vector<std::string> args = utils::split_words(fixcmd);
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
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */

View File

@ -30,6 +30,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