add delete_atoms "variable" option

This commit is contained in:
Axel Kohlmeyer
2022-04-29 21:53:38 -04:00
parent 87b0939fe7
commit 31d6af6114
3 changed files with 47 additions and 2 deletions

View File

@ -10,7 +10,7 @@ Syntax
delete_atoms style args keyword value ... 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:: .. parsed-literal::
@ -26,6 +26,7 @@ Syntax
or NULL to only impose the group criterion or NULL to only impose the group criterion
fraction = delete this fraction of atoms fraction = delete this fraction of atoms
seed = random number seed (positive integer) seed = random number seed (positive integer)
*variable* args = variable-name
* zero or more keyword/value pairs may be appended * zero or more keyword/value pairs may be appended
* keyword = *compress* or *bond* or *mol* * keyword = *compress* or *bond* or *mol*
@ -47,6 +48,7 @@ Examples
delete_atoms overlap 0.5 solvent colloid delete_atoms overlap 0.5 solvent colloid
delete_atoms porosity all cube 0.1 482793 bond yes delete_atoms porosity all cube 0.1 482793 bond yes
delete_atoms porosity polymer cube 0.1 482793 bond yes delete_atoms porosity polymer cube 0.1 482793 bond yes
detele_atoms variable checkers
Description 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 the same atoms will be deleted when running on different numbers of
processors. 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 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 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 number of atoms in the system. Note that this is not done for

View File

@ -24,6 +24,8 @@
#include "domain.h" #include "domain.h"
#include "error.h" #include "error.h"
#include "force.h" #include "force.h"
#include "input.h"
#include "variable.h"
#include "group.h" #include "group.h"
#include "memory.h" #include "memory.h"
#include "modify.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],"region") == 0) delete_region(narg,arg);
else if (strcmp(arg[0],"overlap") == 0) delete_overlap(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 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) { if (allflag) {
int igroup = group->find("all"); int igroup = group->find("all");
@ -453,6 +456,38 @@ void DeleteAtoms::delete_porosity(int narg, char **arg)
delete random; 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 delete all topology interactions that include deleted atoms
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */

View File

@ -39,6 +39,7 @@ class DeleteAtoms : public Command {
void delete_region(int, char **); void delete_region(int, char **);
void delete_overlap(int, char **); void delete_overlap(int, char **);
void delete_porosity(int, char **); void delete_porosity(int, char **);
void delete_variable(int, char **);
void delete_bond(); void delete_bond();
void delete_molecule(); void delete_molecule();