restore original delete_atoms implementation. new version spun off as PR #4492

This commit is contained in:
Axel Kohlmeyer
2025-03-08 17:52:26 -05:00
parent 388f279633
commit e3cf1dec27
3 changed files with 23 additions and 87 deletions

View File

@ -35,12 +35,11 @@ Syntax
*variable* args = variable-name
* zero or more keyword/value pairs may be appended
* keyword = *compress* or *condense* or *bond* or *mol*
* keyword = *compress* or *bond* or *mol*
.. parsed-literal::
*compress* value = *no* or *yes*
*condense* value = *no* or *yes*
*bond* value = *no* or *yes*
*mol* value = *no* or *yes*
@ -51,7 +50,6 @@ Examples
delete_atoms group edge
delete_atoms region sphere compress no
delete_atoms region sphere condense yes
delete_atoms overlap 0.3 all all
delete_atoms overlap 0.5 solvent colloid
delete_atoms random fraction 0.1 yes all cube 482793 bond yes
@ -131,31 +129,21 @@ other options listed above.
Here is the meaning of the optional keywords.
If the *compress* keyword is set to *yes* (which is the default), then
after atoms are deleted, the 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 molecular systems (see the :doc:`atom_style <atom_style>` command),
regardless of the *compress* setting, since it would corrupt the bond
connectivity information that has already been assigned. However, the
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
molecular systems (see the :doc:`atom_style <atom_style>` command),
regardless of the *compress* setting, since it would foul up the bond
connectivity that has already been assigned. However, the
:doc:`reset_atoms id <reset_atoms>` command can be used after this
command to accomplish the same thing.
Note that this re-assignment of IDs is not really a compression, where
Note that the re-assignment of IDs is not really a compression, where
gaps in atom IDs are removed by decrementing atom IDs that are larger.
Instead the IDs for all atoms are erased, and new IDs are assigned so
that the atoms owned by individual processors have consecutive IDs, as
the :doc:`create_atoms <create_atoms>` command explains.
.. versionadded:: TBD
If the *condense* keyword set to *yes*, then after atoms are deleted,
the atom IDs are re-assigned in a way such that the order of atom-IDs is
preserved. This process is not efficient and cannot be used for very
large systems and requires local storage that scales with the number of
total atoms in the system. Also, the *compress* and the *condense*
keywords cannot be used at the same time. Whichever of the two is used
last will be applied.
A molecular system with fixed bonds, angles, dihedrals, or improper
interactions, is one where the topology of the interactions is
typically defined in the data file read by the :doc:`read_data

View File

@ -35,7 +35,6 @@
#include "region.h"
#include "variable.h"
#include <algorithm>
#include <cstring>
#include <map>
#include <utility>
@ -53,9 +52,9 @@ DeleteAtoms::DeleteAtoms(LAMMPS *lmp) : Command(lmp) {}
void DeleteAtoms::command(int narg, char **arg)
{
if (domain->box_exist == 0)
error->all(FLERR, -1, "Delete_atoms command before simulation box is defined");
error->all(FLERR, "Delete_atoms command before simulation box is defined");
if (narg < 1) utils::missing_cmd_args(FLERR, "delete_atoms", error);
if (atom->tag_enable == 0) error->all(FLERR, -1, "Cannot use delete_atoms unless atoms have IDs");
if (atom->tag_enable == 0) error->all(FLERR, "Cannot use delete_atoms unless atoms have IDs");
// store state before delete
@ -79,21 +78,21 @@ void DeleteAtoms::command(int narg, char **arg)
delete_random(narg, arg);
// deprecated porosity option, now included in new partial option
else if (strcmp(arg[0], "porosity") == 0) {
error->all(FLERR, Error::ARGZERO,
error->all(FLERR,
"The delete_atoms 'porosity' keyword has been removed.\n"
"Please use: delete_atoms random fraction frac exact group-ID region-ID seed\n");
} else if (strcmp(arg[0], "variable") == 0)
delete_variable(narg, arg);
else
error->all(FLERR, Error::ARGZERO, "Unknown delete_atoms sub-command: {}", arg[0]);
error->all(FLERR, "Unknown delete_atoms sub-command: {}", arg[0]);
if (allflag) {
int igroup = group->find("all");
if ((igroup >= 0) && modify->check_rigid_group_overlap(group->bitmask[igroup]))
if (comm->me == 0) error->warning(FLERR, "Attempting to delete atoms in rigid bodies");
error->warning(FLERR, "Attempting to delete atoms in rigid bodies");
} else {
if (modify->check_rigid_list_overlap(dlist))
if (comm->me == 0) error->warning(FLERR, "Attempting to delete atoms in rigid bodies");
error->warning(FLERR, "Attempting to delete atoms in rigid bodies");
}
// if allflag = 1, just reset atom->nlocal
@ -131,9 +130,6 @@ void DeleteAtoms::command(int narg, char **arg)
// if non-molecular system and compress flag set:
// reset atom tags to be contiguous
// set all atom IDs to 0, call tag_extend()
// if condense flag set, collect atom IDs for all atoms in replicated global array.
// sort array according to tag value, skip over tags that are zero and determine new tag.
// build new array with tags for all local atoms.
if (compress_flag) {
if (atom->molecular == Atom::ATOMIC) {
@ -143,47 +139,6 @@ void DeleteAtoms::command(int narg, char **arg)
atom->tag_extend();
} else if (comm->me == 0)
error->warning(FLERR, "Ignoring 'compress yes' for molecular system");
} else if (condense_flag) {
if (atom->molecular == Atom::ATOMIC) {
if (atom->map_style == Atom::MAP_NONE)
error->all(FLERR, Error::NOLASTLINE, "Using 'condense yes' option requires an atom map");
if (atom->map_tag_max + 1 > MAXSMALLINT)
error->all(FLERR, Error::NOLASTLINE, "Too many atoms for using 'condense yes' option");
tagint *tag = atom->tag;
int nlocal = atom->nlocal;
int nall = nlocal + atom->nghost;
tagint maxtag = atom->map_tag_max + 1;
auto mytags = std::vector<tagint>(maxtag, 0);
auto alltags = std::vector<tagint>(maxtag, 0);
for (int i = 0; i < nlocal; i++) mytags[tag[i]] = tag[i];
MPI_Allreduce(mytags.data(), alltags.data(), maxtag, MPI_LMP_TAGINT, MPI_SUM, world);
std::sort(alltags.begin(), alltags.end());
tagint newtag = 0;
int localidx;
mytags.resize(nall);
for (int i = 0; i < nall; ++i) mytags[i] = 0;
// update atom map
atom->map_init(0);
atom->nghost = 0;
atom->map_set();
for (auto t : alltags) {
// skip over unset tags
if (!t) continue;
++newtag;
localidx = atom->map(t);
if ((localidx < 0)) continue;
mytags[localidx] = newtag;
}
for (int i = 0; i < nall; ++i) tag[i] = mytags[i];
// recreate atom map again
atom->map_tag_max = -1;
atom->map_style_set();
atom->map_init(0);
atom->nghost = 0;
atom->map_set();
} else if (comm->me == 0)
error->warning(FLERR, "Ignoring 'condense yes' for molecular system");
}
// reset atom->natoms and also topology counts
@ -354,7 +309,7 @@ void DeleteAtoms::delete_overlap(int narg, char **arg)
if (force->pair == nullptr) error->all(FLERR, "Delete_atoms requires a pair style be defined");
if (cut > neighbor->cutneighmax) error->all(FLERR, "Delete_atoms cutoff > max neighbor cutoff");
if ((cut > neighbor->cutneighmin) && comm->me == 0)
if (cut > neighbor->cutneighmin && comm->me == 0)
error->warning(FLERR, "Delete_atoms cutoff > minimum neighbor cutoff");
// setup domain, communication and neighboring
@ -925,35 +880,28 @@ void DeleteAtoms::options(int narg, char **arg)
{
compress_flag = 1;
bond_flag = mol_flag = 0;
condense_flag = 0;
int iarg = 0;
while (iarg < narg) {
if (strcmp(arg[iarg], "compress") == 0) {
if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "delete_atoms compress", error);
compress_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp);
if (condense_flag && compress_flag) condense_flag = 0;
iarg += 2;
} else if (strcmp(arg[iarg], "condense") == 0) {
if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "delete_atoms condense", error);
condense_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp);
if (compress_flag && condense_flag) compress_flag = 0;
iarg += 2;
} else if (strcmp(arg[iarg], "bond") == 0) {
if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "delete_atoms bond", error);
if (atom->molecular == Atom::ATOMIC)
error->all(FLERR, "Cannot use delete_atoms bond yes for non-molecular systems");
if (atom->molecular == Atom::TEMPLATE)
error->all(FLERR, "Cannot use delete_atoms bond yes with atom_style template");
bond_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp);
if (bond_flag && (atom->molecular == Atom::ATOMIC))
error->all(FLERR, iarg, "Cannot use delete_atoms bond yes for non-molecular systems");
if (bond_flag && (atom->molecular == Atom::TEMPLATE))
error->all(FLERR, iarg, "Cannot use delete_atoms bond yes with atom_style template");
iarg += 2;
} else if (strcmp(arg[iarg], "mol") == 0) {
if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "delete_atoms mol", error);
if (atom->molecule_flag == 0)
error->all(FLERR, "Delete_atoms mol yes requires atom attribute molecule");
mol_flag = utils::logical(FLERR, arg[iarg + 1], false, lmp);
if (mol_flag && (atom->molecule_flag == 0))
error->all(FLERR, iarg, "Delete_atoms mol yes requires atom attribute molecule");
iarg += 2;
} else
error->all(FLERR, iarg, "Unknown delete_atoms option: {}", arg[iarg]);
error->all(FLERR, "Unknown delete_atoms option: {}", arg[iarg]);
}
}

View File

@ -32,7 +32,7 @@ class DeleteAtoms : public Command {
protected:
int *dlist;
int allflag, compress_flag, condense_flag, bond_flag, mol_flag;
int allflag, compress_flag, bond_flag, mol_flag;
std::map<tagint, int> *hash;
void delete_group(int, char **);