diff --git a/doc/src/delete_atoms.rst b/doc/src/delete_atoms.rst index f78f295011..ee1273239d 100644 --- a/doc/src/delete_atoms.rst +++ b/doc/src/delete_atoms.rst @@ -10,7 +10,7 @@ Syntax delete_atoms style args keyword value ... -* style = *group* or *region* or *overlap* or *porosity* +* style = *group* or *region* or *overlap* or *porosity* or *variable* .. parsed-literal:: @@ -26,6 +26,7 @@ Syntax or NULL to only impose the group criterion fraction = delete this fraction of atoms seed = random number seed (positive integer) + *variable* args = variable-name * zero or more keyword/value pairs may be appended * keyword = *compress* or *bond* or *mol* @@ -47,6 +48,7 @@ Examples delete_atoms overlap 0.5 solvent colloid delete_atoms porosity all cube 0.1 482793 bond yes delete_atoms porosity polymer cube 0.1 482793 bond yes + detele_atoms variable checkers Description """"""""""" @@ -91,6 +93,13 @@ guarantee that the exact fraction of atoms will be deleted, or that the same atoms will be deleted when running on different numbers of processors. +For style *variable*, all atoms for which the atom-style variable with +the given name evaluates to non-zero will be deleted. Additional atoms +can be deleted if they are in a molecule for which one or more atoms +were deleted within the region; see the *mol* keyword discussion below. +This options allows to apply complex selections of atoms not covered +by the options listed above. + If the *compress* keyword is set to *yes*, then after atoms are deleted, then atom IDs are re-assigned so that they run from 1 to the number of atoms in the system. Note that this is not done for diff --git a/src/delete_atoms.cpp b/src/delete_atoms.cpp index 8524d44b07..42b5b2cc62 100644 --- a/src/delete_atoms.cpp +++ b/src/delete_atoms.cpp @@ -24,6 +24,8 @@ #include "domain.h" #include "error.h" #include "force.h" +#include "input.h" +#include "variable.h" #include "group.h" #include "memory.h" #include "modify.h" @@ -69,7 +71,8 @@ void DeleteAtoms::command(int narg, char **arg) else if (strcmp(arg[0],"region") == 0) delete_region(narg,arg); else if (strcmp(arg[0],"overlap") == 0) delete_overlap(narg,arg); else if (strcmp(arg[0],"porosity") == 0) delete_porosity(narg,arg); - else error->all(FLERR,"Illegal delete_atoms command"); + else if (strcmp(arg[0],"variable") == 0) delete_variable(narg,arg); + else error->all(FLERR,"Unknown delete_atoms sub-command: {}", arg[0]); if (allflag) { int igroup = group->find("all"); @@ -453,6 +456,38 @@ void DeleteAtoms::delete_porosity(int narg, char **arg) delete random; } +/* ---------------------------------------------------------------------- + delete all as flagged by non-zero atom style variable +------------------------------------------------------------------------- */ + +void DeleteAtoms::delete_variable(int narg, char **arg) +{ + if (narg < 2) utils::missing_cmd_args(FLERR,"delete_atoms variable", error); + + int ivar = input->variable->find(arg[1]); + if (ivar < 0) error->all(FLERR, "Variable name {} for delete_atoms does not exist", arg[1]); + if (!input->variable->atomstyle(ivar)) + error->all(FLERR,"Variable {} for delete_atoms is invalid style", arg[1]); + + // consume remaining options + + options(narg-2,&arg[2]); + + // aflag = evaluation of per-atom variable + + const int nlocal = atom->nlocal; + double *aflag; + memory->create(dlist,nlocal,"delete_atoms:dlist"); + memory->create(aflag,nlocal,"group:aflag"); + input->variable->compute_atom(ivar,0,aflag,1,0); + + // delete if per-atom variable evaluated to non-zero + + for (int i = 0; i < nlocal; i++) dlist[i] = (aflag[i] == 0.0) ? 0 : 1; + + memory->destroy(aflag); +} + /* ---------------------------------------------------------------------- delete all topology interactions that include deleted atoms ------------------------------------------------------------------------- */ diff --git a/src/delete_atoms.h b/src/delete_atoms.h index 33333a1ff4..633cb5a9a0 100644 --- a/src/delete_atoms.h +++ b/src/delete_atoms.h @@ -39,6 +39,7 @@ class DeleteAtoms : public Command { void delete_region(int, char **); void delete_overlap(int, char **); void delete_porosity(int, char **); + void delete_variable(int, char **); void delete_bond(); void delete_molecule();