Hi, LAMMPSians,
I tried to write a new fix to delete atoms out of defined region according to “fix_evaporate.cpp” as below:
//===================================
int nocount = 0;
for (i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
if (!domain->regions[oregion]->match(x[i][0],x[i][1],x[i][2])) {
olist[nocount++] = i;
omark[i] = 1;
}
else {
omark[i] = 0;
}
}
}
// nwhack = total number of atoms to delete
int nwhack;
MPI_Allreduce(&nocount,&nwhack,1,MPI_INT,MPI_SUM,world);
// delete my marked atoms
// loop in reverse order to avoid copying marked atoms
AtomVec *avec = atom->avec;
for (i = nlocal-1; i >= 0; i–) {
if (omark[i]) {
avec->copy(atom->nlocal-1,i);
atom->nlocal–;
}
}
// reset global natoms
// if global map exists, reset it now instead of waiting for comm
// since deleting atoms messes up ghosts
atom->natoms -= nwhack;
if (nwhack && atom->map_style) {
atom->nghost = 0;
atom->map_init();
atom->map_set();
}
// statistics
ndeleted += nwhack;
//============================
I want to copy the last atom information to the deleted atoms i position. However, it turn out an error about a xyz dump. The error message is “ERROR: Atom IDs must be consecutive for dump xyz”.
I wonder if i should change “avec->copy(atom->nlocal-1,i);” to “avec->copy(atom->nlocal,i);”?
I read the code about tag_consecutive in atom.cpp:
//===========================
int Atom::tag_consecutive()
{
int idmin = static_cast (natoms);
int idmax = 0;
for (int i = 0; i < nlocal; i++) {
idmin = MIN(idmin,tag[i]);
idmax = MAX(idmax,tag[i]);
}
int idminall,idmaxall;
MPI_Allreduce(&idmin,&idminall,1,MPI_INT,MPI_MIN,world);
MPI_Allreduce(&idmax,&idmaxall,1,MPI_INT,MPI_MAX,world);
if (idminall != 1 || idmaxall != static_cast (natoms)) return 0;
return 1;
}
//==============================
But i don’t quite understand. Does that mean the atom ID must be consecutive? How do i modify my code? Would you check for me or explain the meaning of tag_consecutive?
Thank you very much!
Wenpeng Zhu
2010-03-27