support offsets for molecule IDs (if available) in read_data similar to atomIDs

suggested by felipe perez in https://sourceforge.net/p/lammps/mailman/message/36236631/
This commit is contained in:
Axel Kohlmeyer
2018-02-23 18:02:05 -05:00
parent 0003bb6766
commit bba4bd1489
5 changed files with 47 additions and 25 deletions

View File

@ -124,7 +124,7 @@ void ReadData::command(int narg, char **arg)
addflag = NONE;
coeffflag = 1;
id_offset = 0;
id_offset = mol_offset = 0;
offsetflag = shiftflag = 0;
toffset = boffset = aoffset = doffset = ioffset = 0;
shift[0] = shift[1] = shift[2] = 0.0;
@ -145,11 +145,21 @@ void ReadData::command(int narg, char **arg)
if (strcmp(arg[iarg+1],"append") == 0) addflag = APPEND;
else if (strcmp(arg[iarg+1],"merge") == 0) addflag = MERGE;
else {
if (atom->molecule_flag && (iarg+3 > narg))
error->all(FLERR,"Illegal read_data command");
addflag = VALUE;
bigint offset = force->bnumeric(FLERR,arg[iarg+1]);
if (offset > MAXTAGINT)
error->all(FLERR,"Read data add offset is too big");
error->all(FLERR,"Read data add atomID offset is too big");
id_offset = offset;
if (atom->molecule_flag) {
offset = force->bnumeric(FLERR,arg[iarg+2]);
if (offset > MAXTAGINT)
error->all(FLERR,"Read data add molID offset is too big");
mol_offset = offset;
iarg++;
}
}
iarg += 2;
} else if (strcmp(arg[iarg],"offset") == 0) {
@ -310,14 +320,18 @@ void ReadData::command(int narg, char **arg)
update->ntimestep = 0;
}
// compute atomID offset for addflag = MERGE
// compute atomID and optionally moleculeID offset for addflag = APPEND
if (addflag == APPEND) {
tagint *tag = atom->tag;
tagint *molecule = atom->molecule;
int nlocal = atom->nlocal;
tagint max = 0;
for (int i = 0; i < nlocal; i++) max = MAX(max,tag[i]);
MPI_Allreduce(&max,&id_offset,1,MPI_LMP_TAGINT,MPI_MAX,world);
tagint maxid = 0, maxmol = 0;
for (int i = 0; i < nlocal; i++) maxid = MAX(maxid,tag[i]);
if (atom->molecule_flag)
for (int i = 0; i < nlocal; i++) maxmol = MAX(maxmol,molecule[i]);
MPI_Allreduce(&maxid,&id_offset,1,MPI_LMP_TAGINT,MPI_MAX,world);
MPI_Allreduce(&maxmol,&mol_offset,1,MPI_LMP_TAGINT,MPI_MAX,world);
}
// set up pointer to hold original styles while we replace them with "zero"
@ -1137,7 +1151,7 @@ void ReadData::atoms()
nchunk = MIN(natoms-nread,CHUNK);
eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer);
if (eof) error->all(FLERR,"Unexpected end of data file");
atom->data_atoms(nchunk,buffer,id_offset,toffset,shiftflag,shift);
atom->data_atoms(nchunk,buffer,id_offset,mol_offset,toffset,shiftflag,shift);
nread += nchunk;
}